Skip to content

Commit 628b75c

Browse files
committed
Refactored sysinfo
1 parent 86960c3 commit 628b75c

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

qiling/os/posix/syscall/sysinfo.py

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,31 @@
33
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
44
#
55

6-
import struct
6+
from qiling import Qiling
77

8+
def ql_syscall_sysinfo(ql: Qiling, info: int):
9+
# TODO: the packing method for 'long' fields is set to ql.pack even though
10+
# it is unclear whether it should match pointersize or be 64 bits anyway
811

9-
from qiling.const import *
10-
from qiling.os.linux.thread import *
11-
from qiling.const import *
12-
from qiling.os.posix.filestruct import *
13-
from qiling.os.filestruct import *
14-
from qiling.os.posix.const_mapping import *
15-
from qiling.exception import *
12+
fields = (
13+
(0x0000000000001234, ql.pack), # uptime
14+
(0x0000000000002000, ql.pack), # loads (1 min)
15+
(0x0000000000002000, ql.pack), # loads (5 min)
16+
(0x0000000000002000, ql.pack), # loads (15 min)
17+
(0x0000000010000000, ql.pack), # total ram
18+
(0x0000000010000000, ql.pack), # free ram
19+
(0x0000000010000000, ql.pack), # shared memory
20+
(0x0000000000000000, ql.pack), # memory used by buffers
21+
(0x0000000000000000, ql.pack), # total swap
22+
(0x0000000000000000, ql.pack), # free swap
23+
(0x0001, ql.pack16), # nb current processes
24+
(0x0000000000000000, ql.pack), # total high mem
25+
(0x0000000000000000, ql.pack), # available high mem
26+
(0x00000000, ql.pack32) # memory unit size
27+
)
1628

17-
def ql_syscall_sysinfo(ql, sysinfo_info, *args, **kw):
29+
data = b''.join(pmethod(val) for val, pmethod in fields)
1830

19-
data = b''
20-
data += struct.pack("QQQQQQQQQQHQQI",
21-
0x1234, # uptime
22-
0x2000, # loads (1 min)
23-
0x2000, # loads (5 min)
24-
0x2000, # loads (15 min)
25-
0x10000000, # total ram
26-
0x10000000, # free ram
27-
0x10000000, # shared memory
28-
0x0, # memory used by buffers
29-
0x0, # total swap
30-
0x0, # free swap
31-
0x1, # nb current processes
32-
0x0, # total high mem
33-
0x0, # available high mem
34-
0x1, # memory unit size
35-
)
31+
ql.mem.write(info, data.ljust(64, b'\x00'))
3632

37-
regreturn = 0
38-
#ql.mem.write(sysinfo_info, data)
39-
return regreturn
33+
return 0

0 commit comments

Comments
 (0)