Skip to content

Commit 114aaa2

Browse files
committed
Dummy implementation for a few syscalls
1 parent c1a5b2f commit 114aaa2

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

src/dumpulator/ntsyscalls.py

+44-6
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,29 @@ def ZwDeviceIoControlFile(dp: Dumpulator,
13621362
OutputBuffer: PVOID,
13631363
OutputBufferLength: ULONG
13641364
):
1365+
if FileHandle == dp.console_handle:
1366+
assert IoControlCode == 0x500016
1367+
data = InputBuffer.read(InputBufferLength)
1368+
print(f"InputBuffer: {data.hex()}")
1369+
1370+
# TODO: this is totally wrong, but seems to work?
1371+
if dp.ptr_size() == 4:
1372+
buf = InputBuffer.ptr
1373+
params = struct.unpack("<IIII", dp.read(buf, 4 * 4))
1374+
for i, p in enumerate(params):
1375+
print(f"params[{i}] = {p}")
1376+
1377+
length = dp.read_ptr(buf + 4 * 4)
1378+
buffer = dp.read_ptr(buf + 4 * 4 + dp.ptr_size())
1379+
1380+
ptr1 = dp.read_ptr(buf + 0x18)
1381+
ptr2 = dp.read_ptr(buf + 0x28)
1382+
print(f"ptr1: {ptr1:x}, ptr2: {ptr2:x}")
1383+
dp.write_ptr(ptr2, 0xffffffff)
1384+
print(f"{dp.read_ptr(ptr1):x}")
1385+
1386+
print(f"Length: {length}, Buffer: 0x{buffer:x}")
1387+
return STATUS_SUCCESS
13651388
raise NotImplementedError()
13661389

13671390
@syscall
@@ -2240,7 +2263,7 @@ def ZwOpenSection(dp: Dumpulator,
22402263
DesiredAccess: ACCESS_MASK,
22412264
ObjectAttributes: P(OBJECT_ATTRIBUTES)
22422265
):
2243-
raise NotImplementedError()
2266+
return STATUS_NOT_IMPLEMENTED
22442267

22452268
@syscall
22462269
def ZwOpenSemaphore(dp: Dumpulator,
@@ -2950,7 +2973,7 @@ def ZwQueryVirtualMemory(dp: Dumpulator,
29502973
MemoryInformationLength: SIZE_T,
29512974
ReturnLength: P(SIZE_T)
29522975
):
2953-
raise NotImplementedError()
2976+
return STATUS_NOT_IMPLEMENTED
29542977

29552978
@syscall
29562979
def ZwQueryVolumeInformationFile(dp: Dumpulator,
@@ -3035,6 +3058,19 @@ def ZwReadFile(dp: Dumpulator,
30353058
ByteOffset: P(LARGE_INTEGER),
30363059
Key: P(ULONG)
30373060
):
3061+
if FileHandle == dp.stdin_handle:
3062+
result = b"some console input"
3063+
3064+
assert Buffer != 0
3065+
assert len(result) <= Length
3066+
3067+
Buffer.write(result)
3068+
3069+
# https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_io_status_block
3070+
dp.write_ptr(IoStatusBlock.ptr, STATUS_SUCCESS)
3071+
dp.write_ptr(IoStatusBlock.ptr + dp.ptr_size(), len(result))
3072+
3073+
return STATUS_SUCCESS
30383074
raise NotImplementedError()
30393075

30403076
@syscall
@@ -3451,7 +3487,7 @@ def ZwSetEvent(dp: Dumpulator,
34513487
EventHandle: HANDLE,
34523488
PreviousState: P(LONG)
34533489
):
3454-
raise NotImplementedError()
3490+
return STATUS_NOT_IMPLEMENTED
34553491

34563492
@syscall
34573493
def ZwSetEventBoostPriority(dp: Dumpulator,
@@ -4145,9 +4181,11 @@ def ZwWriteFile(dp: Dumpulator,
41454181
ByteOffset: P(LARGE_INTEGER),
41464182
Key: P(ULONG)
41474183
):
4148-
data = Buffer.read_str(Length)
4149-
print(data)
4150-
return STATUS_SUCCESS
4184+
if FileHandle in [dp.stdout_handle, dp.stdin_handle]:
4185+
data = Buffer.read_str(Length)
4186+
print(data)
4187+
return STATUS_SUCCESS
4188+
raise NotImplementedError()
41514189

41524190
@syscall
41534191
def ZwWriteFileGather(dp: Dumpulator,

0 commit comments

Comments
 (0)