2 Star 5 Fork 4

龙腾四海/ExAndroidNativeEmu

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test_thread.py 2.96 KB
一键复制 编辑 原始数据 按行查看 历史
my 提交于 2022-01-27 23:57 +08:00 . add multi thread test
import logging
import posixpath
import sys
import unittest
from androidemu.const import emu_const
from androidemu.emulator import Emulator
from androidemu.native_hook_utils import FuncHooker
class TestThread(unittest.TestCase):
def __init__(self, methodName):
unittest.TestCase.__init__(self, methodName)
self.__is32_before_call = False
self.__is32_after_call = False
self.__is64_before_call = False
self.__is64_after_call = False
#
def __pthread_create32_before_hook(self, emu, *arg):
start_routine = arg[2]
logging.warning("pthread_create call thread:[0x%08X] attr:[0x%08X] start_routine:[0x%08X] arg:[0x%08X]"%(arg[0], arg[1], start_routine, arg[3]))
self.__is32_before_call = True
self.assertTrue(start_routine != 0)
return False
#
def __pthread_create32_after_hook(self, emu, r0, r1):
logging.warning("pthread_create return 0x%08X"%(r0,))
self.__is32_after_call = True
self.assertEqual(r0, 0)
return False
#
def test_thread32(self):
emulator = Emulator(
vfs_root="vfs",
muti_task=True
)
libcm = emulator.load_library("vfs/system/lib/libc.so")
sym = libcm.find_symbol("pthread_create")
h = FuncHooker(emulator)
h.fun_hook(sym, 4, self.__pthread_create32_before_hook, self.__pthread_create32_after_hook)
libdemo = emulator.load_library("tests/bin/libdemo.so")
r = emulator.call_symbol(libdemo, "test_thread", 3)
self.assertEqual(r, 3)
self.assertTrue(self.__is32_before_call)
self.assertTrue(self.__is32_after_call)
#
def __pthread_create64_before_hook(self, emu, *arg):
start_routine = arg[2]
logging.warning("pthread_create call thread:[0x%08X] attr:[0x%08X] start_routine:[0x%08X] arg:[0x%08X]"%(arg[0], arg[1], start_routine, arg[3]))
self.assertTrue(start_routine != 0)
self.__is64_before_call = True
return False
#
def __pthread_create64_after_hook(self, emu, r0, r1):
logging.warning("pthread_create 64 return 0x%08X"%(r0,))
self.__is64_after_call = True
self.assertEqual(r0, 0)
return False
#
def test_thread64(self):
emulator = Emulator(
vfs_root="vfs",
arch=emu_const.ARCH_ARM64,
muti_task=True
)
libcm = emulator.load_library("vfs/system/lib64/libc.so")
sym = libcm.find_symbol("pthread_create")
#print("sym : %s"%hex(sym))
h = FuncHooker(emulator)
h.fun_hook(sym, 4, self.__pthread_create64_before_hook, self.__pthread_create64_after_hook)
#emulator.mu.hook_add(UC_HOOK_CODE, hook_code, emulator)
libdemo = emulator.load_library("tests/bin64/libdemo.so")
r = emulator.call_symbol(libdemo, "test_thread", 3)
self.assertEqual(r, 3)
self.assertTrue(self.__is64_before_call)
self.assertTrue(self.__is64_after_call)
#
#
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/andy5201314/ExAndroidNativeEmu.git
git@gitee.com:andy5201314/ExAndroidNativeEmu.git
andy5201314
ExAndroidNativeEmu
ExAndroidNativeEmu
master

搜索帮助