mirror of
https://github.com/qilingframework/qiling.git
synced 2026-10-12 02:21:40 +00:00
fix syscall location and revert windows
This commit is contained in:
@@ -21,6 +21,8 @@ examples/**/Windows/
|
||||
# test and logs
|
||||
jexamples/
|
||||
logs/
|
||||
test_qlog/
|
||||
qlog/
|
||||
test_syscall_*.txt
|
||||
*.no.py
|
||||
.gitkeep
|
||||
|
||||
@@ -24,6 +24,12 @@ from qiling.os.linux.utils import *
|
||||
from qiling.os.utils import *
|
||||
from qiling.const import *
|
||||
|
||||
from qiling.os.posix.syscall import *
|
||||
|
||||
|
||||
def ql_x8664_syscall_clone(ql, clone_flags, clone_child_stack, clone_parent_tidptr, clone_child_tidptr, clone_newtls, *args, **kw):
|
||||
ql_syscall_clone(ql, clone_flags, clone_child_stack, clone_parent_tidptr, clone_newtls, clone_child_tidptr, *args, **kw)
|
||||
|
||||
|
||||
def ql_x86_syscall_set_thread_area(ql, u_info_addr, *args, **kw):
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ from qiling.os.posix.filestruct import *
|
||||
from qiling.os.posix.const_mapping import *
|
||||
from qiling.utils import *
|
||||
|
||||
def ql_x8664_syscall_clone(ql, clone_flags, clone_child_stack, clone_parent_tidptr, clone_child_tidptr, clone_newtls, *args, **kw):
|
||||
ql_syscall_clone(ql, clone_flags, clone_child_stack, clone_parent_tidptr, clone_newtls, clone_child_tidptr, *args, **kw)
|
||||
# def ql_x8664_syscall_clone(ql, clone_flags, clone_child_stack, clone_parent_tidptr, clone_child_tidptr, clone_newtls, *args, **kw):
|
||||
# ql_syscall_clone(ql, clone_flags, clone_child_stack, clone_parent_tidptr, clone_newtls, clone_child_tidptr, *args, **kw)
|
||||
|
||||
def ql_syscall_clone(ql, clone_flags, clone_child_stack, clone_parent_tidptr, clone_newtls, clone_child_tidptr, *args, **kw):
|
||||
CSIGNAL = 0x000000ff
|
||||
|
||||
@@ -28,7 +28,8 @@ class Clipboard:
|
||||
If hWnd is null default to current thead id
|
||||
"""
|
||||
if h_wnd == 0:
|
||||
hWnd = self.ql.thread_manager.cur_thread.id
|
||||
# FIXME : self.ql.os this is ugly, should be self.os.thread_manager
|
||||
hWnd = self.ql.os.thread_manager.cur_thread.id
|
||||
|
||||
if self.locked_by != NOT_LOCKED and self.locked_by != h_wnd:
|
||||
return 0
|
||||
@@ -51,7 +52,8 @@ class Clipboard:
|
||||
return 1
|
||||
|
||||
def set_data(self, fmt, data):
|
||||
hWnd = self.ql.thread_manager.cur_thread.id
|
||||
# FIXME : self.ql.os this is ugly, should be self.os.thread_manager
|
||||
hWnd = self.ql.os.thread_manager.cur_thread.id
|
||||
|
||||
if self.locked_by != hWnd:
|
||||
self.last_error = 0x58A # ERROR_CLIPBOARD_NOT_OPEN
|
||||
@@ -65,8 +67,8 @@ class Clipboard:
|
||||
def get_data(self, fmt):
|
||||
if fmt not in self.formats:
|
||||
return 0
|
||||
|
||||
hWnd = self.ql.thread_manager.cur_thread.id
|
||||
# FIXME : self.ql.os this is ugly, should be self.os.thread_manager
|
||||
hWnd = self.ql.os.thread_manager.cur_thread.id
|
||||
|
||||
if self.locked_by != hWnd:
|
||||
self.last_error = 0x58A # ERROR_CLIPBOARD_NOT_OPEN
|
||||
|
||||
@@ -99,9 +99,9 @@ def hook_GetStartupInfoW(self, address, params):
|
||||
# DWORD TlsAlloc();
|
||||
@winapi(cc=STDCALL, params={})
|
||||
def hook_TlsAlloc(self, address, params):
|
||||
idx = self.ql.thread_manager.cur_thread.tls_index
|
||||
self.ql.thread_manager.cur_thread.tls_index += 1
|
||||
self.ql.thread_manager.cur_thread.tls[idx] = 0
|
||||
idx = self.thread_manager.cur_thread.tls_index
|
||||
self.thread_manager.cur_thread.tls_index += 1
|
||||
self.thread_manager.cur_thread.tls[idx] = 0
|
||||
return idx
|
||||
|
||||
|
||||
@@ -113,11 +113,11 @@ def hook_TlsAlloc(self, address, params):
|
||||
})
|
||||
def hook_TlsFree(self, address, params):
|
||||
idx = params['dwTlsIndex']
|
||||
if idx not in self.ql.thread_manager.cur_thread.tls:
|
||||
if idx not in self.thread_manager.cur_thread.tls:
|
||||
self.last_error = 0x57 # (ERROR_INVALID_PARAMETER)
|
||||
return 0
|
||||
else:
|
||||
del (self.ql.thread_manager.cur_thread.tls[idx])
|
||||
del (self.thread_manager.cur_thread.tls[idx])
|
||||
return 1
|
||||
|
||||
|
||||
@@ -128,14 +128,14 @@ def hook_TlsFree(self, address, params):
|
||||
"dwTlsIndex": UINT})
|
||||
def hook_TlsGetValue(self, address, params):
|
||||
idx = params['dwTlsIndex']
|
||||
if idx not in self.ql.thread_manager.cur_thread.tls:
|
||||
if idx not in self.thread_manager.cur_thread.tls:
|
||||
self.last_error = 0x57 # (ERROR_INVALID_PARAMETER)
|
||||
return 0
|
||||
else:
|
||||
# api explicity clears last error on success:
|
||||
# https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-tlsgetvalue
|
||||
self.last_error
|
||||
return self.ql.thread_manager.cur_thread.tls[idx]
|
||||
return self.thread_manager.cur_thread.tls[idx]
|
||||
|
||||
|
||||
# LPVOID TlsSetValue(
|
||||
@@ -147,11 +147,11 @@ def hook_TlsGetValue(self, address, params):
|
||||
})
|
||||
def hook_TlsSetValue(self, address, params):
|
||||
idx = params['dwTlsIndex']
|
||||
if idx not in self.ql.thread_manager.cur_thread.tls:
|
||||
if idx not in self.thread_manager.cur_thread.tls:
|
||||
self.last_error = 0x57 # (ERROR_INVALID_PARAMETER)
|
||||
return 0
|
||||
else:
|
||||
self.ql.thread_manager.cur_thread.tls[idx] = params['lpTlsValue']
|
||||
self.thread_manager.cur_thread.tls[idx] = params['lpTlsValue']
|
||||
return 1
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ def hook_TlsSetValue(self, address, params):
|
||||
# );
|
||||
@winapi(cc=STDCALL, params={})
|
||||
def hook_GetCurrentThreadId(self, address, params):
|
||||
ret = self.ql.thread_manager.cur_thread.id
|
||||
ret = self.thread_manager.cur_thread.id
|
||||
return ret
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ def hook_CreateThread(self, address, params):
|
||||
)
|
||||
|
||||
# append the new thread to ThreadManager
|
||||
self.ql.thread_manager.append(new_thread)
|
||||
self.thread_manager.append(new_thread)
|
||||
|
||||
# create thread handle
|
||||
new_handle = Handle(thread=new_thread)
|
||||
|
||||
@@ -107,7 +107,7 @@ def hook_WaitForSingleObject(self, address, params):
|
||||
|
||||
target_thread: Thread = self.handle_manager.get(hHandle).thread
|
||||
if not target_thread.fake:
|
||||
self.ql.thread_manager.cur_thread.waitfor(target_thread)
|
||||
self.thread_manager.cur_thread.waitfor(target_thread)
|
||||
|
||||
return ret
|
||||
|
||||
@@ -135,7 +135,7 @@ def hook_WaitForMultipleObjects(self, address, params):
|
||||
handle_value = self.ql.unpack(self.ql.mem.read(lpHandles + i * self.ql.pointersize, self.ql.pointersize))
|
||||
if handle_value != 0:
|
||||
thread = self.handle_manager.get(handle_value).thread
|
||||
self.ql.thread_manager.cur_thread.waitfor(thread)
|
||||
self.thread_manager.cur_thread.waitfor(thread)
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ class Token:
|
||||
sid = Sid(ql)
|
||||
handle = Handle(sid=sid)
|
||||
|
||||
# FIXME : self.ql.os this is ugly
|
||||
# FIXME : self.ql.os this is ugly, should be self.os.thread_manager
|
||||
self.ql.os.handle_manager.append(handle)
|
||||
|
||||
self.struct[Token.TokenInformationClass.TokenIntegrityLevel] = self.ql.pack(handle.id)
|
||||
|
||||
@@ -10,12 +10,12 @@ from qiling.os.windows.utils import *
|
||||
|
||||
|
||||
def thread_scheduler(ql, address, size):
|
||||
if ql.pc == ql.thread_manager.THREAD_RET_ADDR:
|
||||
ql.thread_manager.cur_thread.stop()
|
||||
ql.thread_manager.do_schedule()
|
||||
if ql.pc == ql.os.thread_manager.THREAD_RET_ADDR:
|
||||
ql.os.thread_manager.cur_thread.stop()
|
||||
ql.os.thread_manager.do_schedule()
|
||||
else:
|
||||
ql.thread_manager.ins_count += 1
|
||||
ql.thread_manager.do_schedule()
|
||||
ql.os.thread_manager.ins_count += 1
|
||||
ql.os.thread_manager.do_schedule()
|
||||
|
||||
|
||||
class Context():
|
||||
@@ -156,12 +156,13 @@ class QlWindowsThread(QlThread):
|
||||
# create new stack
|
||||
stack_size = 1024
|
||||
new_stack = self.ql.heap.mem_alloc(stack_size) + stack_size
|
||||
|
||||
|
||||
# FIXME : self.ql.os this is ugly, should be self.os.thread_manager
|
||||
if self.ql.archtype == QL_X86:
|
||||
self.ql.mem.write(new_stack - 4, self.ql.pack32(self.ql.thread_manager.THREAD_RET_ADDR))
|
||||
self.ql.mem.write(new_stack - 4, self.ql.pack32(self.ql.os.thread_manager.THREAD_RET_ADDR))
|
||||
self.ql.mem.write(new_stack, self.ql.pack32(func_params))
|
||||
elif self.ql.archtype == QL_X8664:
|
||||
self.ql.mem.write(new_stack - 8, self.ql.pack64(self.ql.thread_manager.THREAD_RET_ADDR))
|
||||
self.ql.mem.write(new_stack - 8, self.ql.pack64(self.ql.os.thread_manager.THREAD_RET_ADDR))
|
||||
self.ql.mem.write(new_stack, self.ql.pack64(func_params))
|
||||
|
||||
# set eip, ebp, esp
|
||||
|
||||
@@ -44,7 +44,7 @@ def setup(self):
|
||||
self.fiber_manager = FiberManager(self.ql)
|
||||
# thread manager
|
||||
main_thread = QlWindowsThread(self.ql)
|
||||
self.ql.thread_manager = QlWindowsThreadManagement(self.ql, main_thread)
|
||||
self.thread_manager = QlWindowsThreadManagement(self.ql, main_thread)
|
||||
|
||||
# more handle manager
|
||||
new_handle = Handle(thread=main_thread)
|
||||
|
||||
@@ -17,6 +17,14 @@ class ELFTest(unittest.TestCase):
|
||||
ql.multithread = True
|
||||
ql.run()
|
||||
|
||||
|
||||
def test_multithread_elf_linux_x8664(self):
|
||||
ql = Qiling(["../examples/rootfs/x8664_linux/bin/x8664_multithreading"], "../examples/rootfs/x8664_linux", log_dir= "multi_log")
|
||||
ql.log_split = True
|
||||
ql.multithread = True
|
||||
ql.run()
|
||||
|
||||
|
||||
def test_elf_freebsd_x8664(self):
|
||||
ql = Qiling(["../examples/rootfs/x8664_freebsd/bin/x8664_hello_asm"], "../examples/rootfs/x8664_freebsd", output = "disasm")
|
||||
ql.run()
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ def test_pe_win_x8664_hello():
|
||||
|
||||
def test_pe_win_x86_hello():
|
||||
ql = Qiling(["../examples/rootfs/x86_windows/bin/x86_hello.exe"], "../examples/rootfs/x86_windows",
|
||||
output="default", log_dir='/var/tmp/test_qlog', append="test")
|
||||
output="default", log_dir='test_qlog', append="test")
|
||||
ql.log_split = True
|
||||
ql.run()
|
||||
del ql
|
||||
|
||||
Reference in New Issue
Block a user