-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathread_klog.lua
More file actions
74 lines (52 loc) · 1.53 KB
/
Copy pathread_klog.lua
File metadata and controls
74 lines (52 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
FD_SETSIZE = 1024
_NFDBITS = 64
function create_fd_set()
return memory.alloc(8 * 16)
end
function FD_ZERO(p)
for i=0,16-1 do
memory.write_qword(p + i*8, 0)
end
end
function FD_SET(n, p)
local idx = math.floor(n / _NFDBITS)
local cur = memory.read_qword(p + idx*8)
cur = bit64.bor(cur, bit64.lshift(1, n % _NFDBITS))
memory.write_qword(p + idx*8, cur)
end
function read_klog()
local data_size = PAGE_SIZE
local data_mem = memory.alloc(data_size)
local flags = bit32.bor(O_RDONLY, O_NONBLOCK)
local klog_fd = syscall.open("/dev/klog", flags):tonumber()
if klog_fd == -1 then
error("open() error: " .. get_error_string())
end
local readfds = create_fd_set()
local timeval = memory.alloc(0x10)
memory.write_dword(timeval, 0) -- tv_sec
memory.write_dword(timeval + 8, 1000*10) -- tv_usec (10ms)
FD_ZERO(readfds)
FD_SET(klog_fd, readfds)
while true do
local select_ret = syscall.select(FD_SETSIZE, readfds, nil, nil, timeval):tonumber()
if select_ret == -1 then -- error
error("select() error: " .. get_error_string())
break
elseif select_ret == 0 then -- time limit expires
break
else
local read_size = syscall.read(klog_fd, data_mem, data_size)
syscall.write(client_fd, data_mem, read_size)
end
end
syscall.close(klog_fd)
end
function main()
check_jailbroken()
syscall.resolve({
select = 0x5d
})
read_klog()
end
main()