mirror of
https://github.com/qilingframework/qiling.git
synced 2026-10-12 02:21:40 +00:00
Adjust all set_api usages
This commit is contained in:
@@ -133,7 +133,7 @@ def third_stage(keys):
|
||||
"rootfs/8086",
|
||||
console=False)
|
||||
ql.add_fs_mapper(0x80, QlDisk("rootfs/8086/doogie/doogie.DOS_MBR", 0x80))
|
||||
ql.set_api((0x1a, 4), set_required_datetime, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api((0x1a, 4), set_required_datetime, QL_INTERCEPT.EXIT)
|
||||
hk = ql.hook_code(stop, begin=0x8018, end=0x8018)
|
||||
ql.run()
|
||||
ql.hook_del(hk)
|
||||
@@ -187,7 +187,7 @@ def first_stage():
|
||||
console=False)
|
||||
ql.add_fs_mapper(0x80, QlDisk("rootfs/8086/doogie/doogie.DOS_MBR", 0x80))
|
||||
# Doogie suggests that the datetime should be 1990-02-06.
|
||||
ql.set_api((0x1a, 4), set_required_datetime, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api((0x1a, 4), set_required_datetime, QL_INTERCEPT.EXIT)
|
||||
# A workaround to stop the program.
|
||||
hk = ql.hook_code(stop, begin=0x8018, end=0x8018)
|
||||
ql.run()
|
||||
|
||||
@@ -28,7 +28,7 @@ def my_puts_onexit(ql: Qiling):
|
||||
|
||||
if __name__ == "__main__":
|
||||
ql = Qiling(["rootfs/arm_qnx/bin/hello_static"], "rootfs/arm_qnx")
|
||||
ql.set_api('puts', my_puts_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.set_api('printf', my_printf_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.set_api('puts', my_puts_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api('puts', my_puts_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api('printf', my_printf_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api('puts', my_puts_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.run()
|
||||
|
||||
@@ -23,7 +23,7 @@ def my_puts_onexit(ql: Qiling):
|
||||
if __name__ == "__main__":
|
||||
ql = Qiling(["rootfs/mips32el_linux/bin/mips32el_double_hello"], "rootfs/mips32el_linux", verbose=QL_VERBOSE.DEBUG)
|
||||
|
||||
ql.set_api('puts', my_puts_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.set_api('puts', my_puts_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api('puts', my_puts_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api('puts', my_puts_onexit, QL_INTERCEPT.EXIT)
|
||||
|
||||
ql.run()
|
||||
|
||||
@@ -16,5 +16,5 @@ def my_puts(ql: Qiling):
|
||||
|
||||
if __name__ == "__main__":
|
||||
ql = Qiling(["rootfs/x8664_linux/bin/x8664_hello"], "rootfs/x8664_linux", verbose=QL_VERBOSE.DEBUG)
|
||||
ql.set_api('puts', my_puts)
|
||||
ql.os.set_api('puts', my_puts)
|
||||
ql.run()
|
||||
|
||||
@@ -39,9 +39,9 @@ def my_onexit(ql: Qiling, address: int, params, retval: int):
|
||||
def my_sandbox(path, rootfs):
|
||||
ql = Qiling(path, rootfs, verbose=QL_VERBOSE.DEBUG)
|
||||
|
||||
ql.set_api("_cexit", my_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.set_api("puts", my_puts, QL_INTERCEPT.CALL)
|
||||
ql.set_api("atexit", my_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api("_cexit", my_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api("puts", my_puts, QL_INTERCEPT.CALL)
|
||||
ql.os.set_api("atexit", my_onexit, QL_INTERCEPT.EXIT)
|
||||
|
||||
ql.run()
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ def my_netgear(path, rootfs):
|
||||
|
||||
ql.add_fs_mapper('/proc', '/proc')
|
||||
ql.os.set_syscall(4004, my_syscall_write)
|
||||
ql.set_api('bind', my_bind, QL_INTERCEPT.ENTER) # intercepting the bind call on enter
|
||||
ql.os.set_api('bind', my_bind, QL_INTERCEPT.ENTER) # intercepting the bind call on enter
|
||||
|
||||
ql.run()
|
||||
|
||||
|
||||
+4
-4
@@ -181,10 +181,10 @@ if __name__ == "__main__":
|
||||
ql.amsint32_driver = None
|
||||
|
||||
# emulate some Windows API
|
||||
ql.set_api("CreateThread", hook_CreateThread)
|
||||
ql.set_api("CreateFileA", hook_CreateFileA)
|
||||
ql.set_api("WriteFile", hook_WriteFile)
|
||||
ql.set_api("StartServiceA", hook_StartServiceA)
|
||||
ql.os.set_api("CreateThread", hook_CreateThread)
|
||||
ql.os.set_api("CreateFileA", hook_CreateFileA)
|
||||
ql.os.set_api("WriteFile", hook_WriteFile)
|
||||
ql.os.set_api("StartServiceA", hook_StartServiceA)
|
||||
#init sality
|
||||
ql.hook_address(hook_stop_address, 0x40EFFB)
|
||||
ql.run()
|
||||
|
||||
@@ -40,7 +40,7 @@ if __name__ == "__main__":
|
||||
|
||||
ql = Qiling(["rootfs/x8664_efi/bin/TcgPlatformSetupPolicy"], "rootfs/x8664_efi", env=env, verbose=QL_VERBOSE.DEBUG)
|
||||
|
||||
ql.set_api("RegisterProtocolNotify", force_notify_RegisterProtocolNotify)
|
||||
ql.set_api("CopyMem", my_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api("RegisterProtocolNotify", force_notify_RegisterProtocolNotify)
|
||||
ql.os.set_api("CopyMem", my_onenter, QL_INTERCEPT.ENTER)
|
||||
|
||||
ql.run()
|
||||
|
||||
+2
-2
@@ -26,8 +26,8 @@ class DOSTest(unittest.TestCase):
|
||||
def onexit(ql: Qiling):
|
||||
ck.visited_onexit = True
|
||||
|
||||
ql.set_api((0x21, 0x09), onexit, QL_INTERCEPT.EXIT)
|
||||
ql.set_api((0x21, 0x4c), onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api((0x21, 0x09), onexit, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api((0x21, 0x4c), onenter, QL_INTERCEPT.ENTER)
|
||||
|
||||
ql.run()
|
||||
|
||||
|
||||
+6
-6
@@ -128,7 +128,7 @@ class ELFTest(unittest.TestCase):
|
||||
|
||||
ql = Qiling(["../examples/rootfs/x8664_linux/bin/x8664_args","1234test", "12345678", "bin/x8664_hello"], "../examples/rootfs/x8664_linux", verbose=QL_VERBOSE.DEBUG)
|
||||
ql.os.set_syscall(1, write_onEnter, QL_INTERCEPT.ENTER)
|
||||
ql.set_api('puts', my_puts)
|
||||
ql.os.set_api('puts', my_puts)
|
||||
ql.os.set_syscall(1, write_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.mem.map(0x1000, 0x1000)
|
||||
ql.mem.write(0x1000, b"\xFF\xFE\xFD\xFC\xFB\xFA\xFB\xFC\xFC\xFE\xFD")
|
||||
@@ -156,8 +156,8 @@ class ELFTest(unittest.TestCase):
|
||||
self.test_exit_rdi = ql.arch.regs.rdi
|
||||
|
||||
ql = Qiling(["../examples/rootfs/x8664_linux/bin/x8664_puts"], "../examples/rootfs/x8664_linux", verbose=QL_VERBOSE.DEBUG)
|
||||
ql.set_api('puts', my_puts_enter, QL_INTERCEPT.ENTER)
|
||||
ql.set_api('puts', my_puts_exit, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api('puts', my_puts_enter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api('puts', my_puts_exit, QL_INTERCEPT.EXIT)
|
||||
|
||||
ql.run()
|
||||
|
||||
@@ -187,7 +187,7 @@ class ELFTest(unittest.TestCase):
|
||||
|
||||
def hook_main(ql: Qiling):
|
||||
# set up fopen hook when reaching main
|
||||
ql.set_api('fopen', onenter_fopen, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api('fopen', onenter_fopen, QL_INTERCEPT.ENTER)
|
||||
|
||||
ql = Qiling(["../examples/rootfs/x8664_linux/bin/x8664_fetch_urandom"], "../examples/rootfs/x8664_linux", verbose=QL_VERBOSE.DEFAULT)
|
||||
|
||||
@@ -351,7 +351,7 @@ class ELFTest(unittest.TestCase):
|
||||
ql.mem.restore(all_mem)
|
||||
|
||||
ql = Qiling(["../examples/rootfs/arm_linux/bin/arm_hello"], "../examples/rootfs/arm_linux", verbose=QL_VERBOSE.DEBUG, profile='profiles/append_test.ql')
|
||||
ql.set_api('puts', my_puts)
|
||||
ql.os.set_api('puts', my_puts)
|
||||
ql.run()
|
||||
del ql
|
||||
|
||||
@@ -507,7 +507,7 @@ class ELFTest(unittest.TestCase):
|
||||
return 2
|
||||
|
||||
ql = Qiling(["../examples/rootfs/mips32el_linux/bin/mips32el_double_hello"], "../examples/rootfs/mips32el_linux")
|
||||
ql.set_api('puts', my_puts_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api('puts', my_puts_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.run()
|
||||
|
||||
self.assertEqual(4196680, self.my_puts_onenter_addr)
|
||||
|
||||
@@ -32,7 +32,7 @@ class ELF_KO_Test(unittest.TestCase):
|
||||
try:
|
||||
procfile_read_func_begin = ql.loader.load_address + 0x11e0
|
||||
procfile_read_func_end = ql.loader.load_address + 0x11fa
|
||||
ql.set_api("printk", my_printk)
|
||||
ql.os.set_api("printk", my_printk)
|
||||
ql.run(begin=procfile_read_func_begin, end=procfile_read_func_end)
|
||||
except UcError as e:
|
||||
print(e)
|
||||
@@ -55,7 +55,7 @@ class ELF_KO_Test(unittest.TestCase):
|
||||
try:
|
||||
procfile_read_func_begin = ql.loader.load_address + 0x1064
|
||||
procfile_read_func_end = ql.loader.load_address + 0x107e
|
||||
ql.set_api("printk", my_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api("printk", my_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.run(begin=procfile_read_func_begin, end=procfile_read_func_end)
|
||||
except UcError as e:
|
||||
print(e)
|
||||
@@ -76,7 +76,7 @@ class ELF_KO_Test(unittest.TestCase):
|
||||
ql = Qiling(["../examples/rootfs/mips32_linux/kernel/hello.ko"], "../examples/rootfs/mips32_linux", verbose=QL_VERBOSE.DEBUG)
|
||||
begin = ql.loader.load_address + 0x1060
|
||||
end = ql.loader.load_address + 0x1084
|
||||
ql.set_api("printk", my_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api("printk", my_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.run(begin=begin, end=end)
|
||||
|
||||
self.assertEqual("\x016Hello, World!\n", self.set_api_onexit)
|
||||
|
||||
@@ -82,9 +82,9 @@ class MACHOTest(unittest.TestCase):
|
||||
return
|
||||
|
||||
ql = Qiling(["../examples/rootfs/x8664_macos/kext/SuperRootkit.kext"], "../examples/rootfs/x8664_macos", verbose=QL_VERBOSE.DISASM)
|
||||
ql.set_api("_ipf_addv4", my_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.set_api("_strncmp", my_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.set_api("_strlen", my__strlen)
|
||||
ql.os.set_api("_ipf_addv4", my_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api("_strncmp", my_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api("_strlen", my__strlen)
|
||||
ql.hook_address(hook_stop, 0xffffff8000854800)
|
||||
|
||||
try:
|
||||
|
||||
+5
-5
@@ -221,7 +221,7 @@ class PETest(unittest.TestCase):
|
||||
return address, params
|
||||
|
||||
ql = Qiling(["../examples/rootfs/x86_windows/bin/MultiThread.exe"], "../examples/rootfs/x86_windows")
|
||||
ql.set_api("GetCurrentThreadId", ThreadId_onEnter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api("GetCurrentThreadId", ThreadId_onEnter, QL_INTERCEPT.ENTER)
|
||||
ql.run()
|
||||
|
||||
if not ( 1<= thread_id < 255):
|
||||
@@ -421,9 +421,9 @@ class PETest(unittest.TestCase):
|
||||
def my_sandbox(path, rootfs):
|
||||
nonlocal set_api, set_api_onenter, set_api_onexit
|
||||
ql = Qiling(path, rootfs, verbose=QL_VERBOSE.DEBUG)
|
||||
ql.set_api("puts", my_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.set_api("puts", my_puts64, QL_INTERCEPT.CALL)
|
||||
ql.set_api("puts", my_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api("puts", my_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api("puts", my_puts64, QL_INTERCEPT.CALL)
|
||||
ql.os.set_api("puts", my_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.run()
|
||||
|
||||
if 12 != set_api_onenter:
|
||||
@@ -474,7 +474,7 @@ class PETest(unittest.TestCase):
|
||||
return address, params
|
||||
|
||||
ql = Qiling(["../examples/rootfs/x86_windows/bin/argv.exe"], "../examples/rootfs/x86_windows")
|
||||
ql.set_api('__stdio_common_vfprintf', check_print, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api('__stdio_common_vfprintf', check_print, QL_INTERCEPT.ENTER)
|
||||
ql.run()
|
||||
|
||||
if target_txt.find("argv.exe"):
|
||||
|
||||
@@ -196,10 +196,10 @@ class PETest(unittest.TestCase):
|
||||
# for this module
|
||||
ql.amsint32_driver = None
|
||||
# emulate some Windows API
|
||||
ql.set_api("CreateThread", hook_CreateThread)
|
||||
ql.set_api("CreateFileA", hook_CreateFileA)
|
||||
ql.set_api("WriteFile", hook_WriteFile)
|
||||
ql.set_api("StartServiceA", hook_StartServiceA)
|
||||
ql.os.set_api("CreateThread", hook_CreateThread)
|
||||
ql.os.set_api("CreateFileA", hook_CreateFileA)
|
||||
ql.os.set_api("WriteFile", hook_WriteFile)
|
||||
ql.os.set_api("StartServiceA", hook_StartServiceA)
|
||||
#init sality
|
||||
ql.hook_address(hook_first_stop_address, 0x40EFFB)
|
||||
ql.run()
|
||||
|
||||
+5
-5
@@ -58,11 +58,11 @@ class QNXTest(unittest.TestCase):
|
||||
return QL_CALL_BLOCK
|
||||
|
||||
ql = Qiling(["../examples/rootfs/arm_qnx/bin/hello_sqrt"], "../examples/rootfs/arm_qnx", verbose=QL_VERBOSE.DEBUG)
|
||||
ql.set_api('puts', my_puts_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.set_api('printf', my_printf_onenter, QL_INTERCEPT.ENTER)
|
||||
|
||||
# ql.set_api('puts', my_puts_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.set_api('printf', my_printf_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api('puts', my_puts_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api('printf', my_printf_onenter, QL_INTERCEPT.ENTER)
|
||||
|
||||
# ql.os.set_api('puts', my_puts_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api('printf', my_printf_onexit, QL_INTERCEPT.EXIT)
|
||||
|
||||
ql.run()
|
||||
|
||||
|
||||
+3
-3
@@ -101,9 +101,9 @@ class Test_UEFI(unittest.TestCase):
|
||||
ql = Qiling([f'{ROOTFS_UEFI}/bin/TcgPlatformSetupPolicy'], ROOTFS_UEFI, env=env, verbose=QL_VERBOSE.DEBUG)
|
||||
self.ck = Checklist()
|
||||
|
||||
ql.set_api("RegisterProtocolNotify", force_notify_RegisterProtocolNotify)
|
||||
ql.set_api("CopyMem", my_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.set_api("LocateProtocol", my_onexit, QL_INTERCEPT.EXIT)
|
||||
ql.os.set_api("RegisterProtocolNotify", force_notify_RegisterProtocolNotify)
|
||||
ql.os.set_api("CopyMem", my_onenter, QL_INTERCEPT.ENTER)
|
||||
ql.os.set_api("LocateProtocol", my_onexit, QL_INTERCEPT.EXIT)
|
||||
|
||||
ql.run()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user