Skip to content

Commit

Permalink
测试git工具
Browse files Browse the repository at this point in the history
  • Loading branch information
baikaishiuc committed Oct 4, 2022
1 parent 0915507 commit 1bc64a8
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions example_jni.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import posixpath
import sys
import os
import time

from unicorn import *
from unicorn.arm_const import *
Expand All @@ -15,17 +16,23 @@
import capstone
import traceback

def cur_ts():
return round(time.time() * 1000)

g_cfd = ChainLogger(sys.stdout, "./ins-jni.txt")
g_inst_count=0
g_inst_start_ts = cur_ts()
# Add debugging.
def hook_code(mu, address, size, user_data):
try:
emu = user_data
if (not emu.memory.check_addr(address, UC_PROT_EXEC)):
logger.error("addr 0x%08X out of range"%(address,))
sys.exit(-1)
#
#androidemu.utils.debug_utils.dump_registers(mu, sys.stdout)
androidemu.utils.debug_utils.dump_code(emu, address, size, g_cfd)
#androidemu.utils.debug_utils.dump_registers(emu, sys.stdout)
androidemu.utils.debug_utils.dump_code(emu, address, size, g_cfd, androidemu.utils.debug_utils.DUMP_REG_WRITE)
global g_inst_count
g_inst_count += 1
except Exception as e:
logger.exception("exception in hook_code")
sys.exit(-1)
Expand All @@ -34,7 +41,7 @@ def hook_code(mu, address, size, user_data):

def hook_mem_read(uc, access, address, size, value, user_data):
pc = uc.reg_read(UC_ARM_REG_PC)

if (address == 0xCBC80640):
logger.debug("read mutex")
data = uc.mem_read(address, size)
Expand Down Expand Up @@ -66,6 +73,8 @@ def test(self):

logger = logging.getLogger(__name__)

logging.basicConfig(level=logging.DEBUG, format='%(message)s')

# Initialize emulator
emulator = Emulator(
vfs_root=posixpath.join(posixpath.dirname(__file__), "vfs")
Expand All @@ -83,6 +92,8 @@ def test(self):

#androidemu.utils.debug_utils.dump_symbols(emulator, sys.stdout)

#logger.setLevel(5)

# Show loaded modules.
logger.info("Loaded modules:")

Expand All @@ -92,8 +103,12 @@ def test(self):
try:
# Run JNI_OnLoad.
# JNI_OnLoad will call 'RegisterNatives'.
g_inst_start_ts = cur_ts()
emulator.call_symbol(lib_module, 'JNI_OnLoad', emulator.java_vm.address_ptr, 0x00)

spent_ts = cur_ts() - g_inst_start_ts
print("***** %d instruction spent %fms, %d inst/s" % (g_inst_count, spent_ts, g_inst_count * 1000 / spent_ts))

# Do native stuff.
main_activity = MainActivity()
logger.info("Response from JNI call: %s" % main_activity.string_from_jni(emulator))
Expand Down

0 comments on commit 1bc64a8

Please sign in to comment.