Skip to content

Commit 71d907b

Browse files
committed
fix #2, updated NTSTATUS known values
1 parent 26b9b1e commit 71d907b

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

DriverBuddyReloaded.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,18 @@ def find_all_ioctls():
173173
f = idaapi.get_func(addr)
174174
fc = idaapi.FlowChart(f, flags=idaapi.FC_PREDS)
175175
for block in fc:
176-
# grab the last two instructions in the block
177-
last_inst = idc.prev_head(block.end_ea)
178-
penultimate_inst = idc.prev_head(last_inst)
179-
# If the penultimate instruction is cmp or sub against an immediate value immediately preceding a 'jz'
180-
# then it's a decent guess that it's an IOCTL code (if this is a dispatch function)
181-
if idc.print_insn_mnem(penultimate_inst) in ['cmp', 'sub'] and idc.get_operand_type(penultimate_inst, 1) == 5:
182-
if idc.print_insn_mnem(last_inst) == 'jz':
183-
value = get_operand_value(penultimate_inst)
176+
start = block.start_ea
177+
end = block.end_ea
178+
# print("Block: {} - {}".format(start, end))
179+
for instr in range(start, end):
180+
# if the penultimate instruction is cmp or sub or mov against an immediate value
181+
if idc.print_insn_mnem(instr) in ['cmp', 'sub', 'mov'] and idc.get_operand_type(instr, 1) == 5:
182+
value = get_operand_value(instr)
184183
digits = utils.check_digits(value)
185-
if digits == 10:
186-
if value not in utils.ntstatus_values:
187-
ioctls.append((penultimate_inst, value))
188-
ioctl_tracker.add_ioctl(penultimate_inst, value)
184+
# value has 10 digits and is not a known NTSTATUS value
185+
if digits == 10 and value not in utils.ntstatus_values:
186+
ioctls.append((instr, value))
187+
ioctl_tracker.add_ioctl(instr, value)
189188
return ioctls
190189

191190

@@ -228,8 +227,7 @@ def get_position_and_translate():
228227

229228
value = get_operand_value(pos)
230229
digits = utils.check_digits(value)
231-
if digits == 10:
232-
if value not in utils.ntstatus_values:
230+
if digits == 10 and value not in utils.ntstatus_values:
233231
ioctl_tracker.add_ioctl(pos, value)
234232
define = ioctl_decoder.get_define(value)
235233
make_comment(pos, define)

DriverBuddyReloaded/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
driver_map = {}
211211

212212
# List of known NTSTATUS values to filter out from possible IOCTL codes
213+
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55
213214
ntstatus_values = [
214215
0x00000000, 0x00000001, 0x00000002, 0x00000003, 0x0000003F, 0x00000080, 0x000000BF, 0x000000C0, 0x00000101,
215216
0x00000102, 0x00000103, 0x00000104, 0x00000105, 0x00000106, 0x00000107, 0x00000108, 0x00000109, 0x0000010A,
@@ -410,7 +411,7 @@
410411
0xC0232001, 0xC0232002, 0xC0232003, 0xC0232004, 0xC0360001, 0xC0360002, 0xC0360003, 0xC0360004, 0xC0360005,
411412
0xC0360006, 0xC0360007, 0xC0360008, 0xC0360009, 0xC0368000, 0xC0368001, 0xC0368002, 0xC0368003, 0xC0368004,
412413
0xC0368005, 0xC0368006, 0xC038005B, 0xC038005C, 0xC03A0014, 0xC03A0015, 0xC03A0016, 0xC03A0017, 0xC03A0018,
413-
0xC03A0019
414+
0xC03A0019, 0xE0000001, 0xE0000002, 0xE0000004
414415
]
415416

416417

0 commit comments

Comments
 (0)