AndroidNativeEmu icon indicating copy to clipboard operation
AndroidNativeEmu copied to clipboard

AttributeError: 'Emulator' object has no attribute 'uc'

Open gaplan opened this issue 3 years ago • 2 comments

when i try python3 example.py

here is the result.

OSAs-MacBook-Pro-2:examples osapoza$ python3 example.py 
2022-09-05 02:56:21,163   DEBUG        androidemu.internal.modules | Loading module 'example_binaries/32/libc.so'.
2022-09-05 02:56:21,175   DEBUG         androidemu.internal.memory | => Mapping memory page 0xcbbcb000 - 0xcbc57000, size 0x0008c000, prot 5
2022-09-05 02:56:21,176   DEBUG         androidemu.internal.memory | => Mapping memory page 0xcbc58000 - 0xcbc66000, size 0x0000e000, prot 3
2022-09-05 02:56:21,199   ERROR        androidemu.internal.modules | => Undefined external symbol: android_get_application_target_sdk_version
2022-09-05 02:56:21,199   ERROR        androidemu.internal.modules | => Undefined external symbol: dl_unwind_find_exidx
2022-09-05 02:56:21,989   ERROR        androidemu.internal.modules | => Undefined external symbol: android_get_application_target_sdk_version
2022-09-05 02:56:21,990   ERROR        androidemu.internal.modules | => Undefined external symbol: dl_unwind_find_exidx
2022-09-05 02:56:22,383   DEBUG        androidemu.internal.modules | Loading module 'example_binaries/32/libnative-lib.so'.
2022-09-05 02:56:22,386   DEBUG         androidemu.internal.memory | => Mapping memory page 0xcbc66000 - 0xcbc69000, size 0x00003000, prot 5
2022-09-05 02:56:22,386   DEBUG         androidemu.internal.memory | => Mapping memory page 0xcbc69000 - 0xcbc6b000, size 0x00002000, prot 3
2022-09-05 02:56:22,404    INFO                           __main__ | Loaded modules:
2022-09-05 02:56:22,404    INFO                           __main__ | [0xcbbcb000] example_binaries/32/libc.so
2022-09-05 02:56:22,404    INFO                           __main__ | [0xcbc66000] example_binaries/32/libnative-lib.so
Traceback (most recent call last):
  File "/Users/osapoza/Downloads/AndroidNativeEmu-master 2/examples/example.py", line 38, in <module>
    emulator.uc.hook_add(UC_HOOK_CODE, hook_code)
AttributeError: 'Emulator' object has no attribute 'uc'

python version : Python 3.9.0 (default, Nov 21 2020, 14:01:55)

gaplan avatar Sep 04 '22 23:09 gaplan

$ git diff
diff --git a/examples/example.py b/examples/example.py
index 0d29fc0..811dbc6 100644
--- a/examples/example.py
+++ b/examples/example.py
@@ -35,9 +35,9 @@ def hook_code(uc, address, size, user_data):
     print('# Tracing instruction at 0x%x, instruction size = 0x%x, instruction = %s' % (address, size, instruction_str))
 
 
-emulator.uc.hook_add(UC_HOOK_CODE, hook_code)
+emulator.mu.hook_add(UC_HOOK_CODE, hook_code)
 
 # Runs a method of "libnative-lib.so" that calls an imported function "strlen" from "libc.so".
 emulator.call_symbol(lib_module, '_Z4testv')
 
-print("String length is: %i" % emulator.uc.reg_read(UC_ARM_REG_R0))
+print("String length is: %i" % emulator.mu.reg_read(UC_ARM_REG_R0))

enovella avatar Nov 06 '22 17:11 enovella

$ git diff
diff --git a/examples/example.py b/examples/example.py
index 0d29fc0..811dbc6 100644
--- a/examples/example.py
+++ b/examples/example.py
@@ -35,9 +35,9 @@ def hook_code(uc, address, size, user_data):
     print('# Tracing instruction at 0x%x, instruction size = 0x%x, instruction = %s' % (address, size, instruction_str))
 
 
-emulator.uc.hook_add(UC_HOOK_CODE, hook_code)
+emulator.mu.hook_add(UC_HOOK_CODE, hook_code)
 
 # Runs a method of "libnative-lib.so" that calls an imported function "strlen" from "libc.so".
 emulator.call_symbol(lib_module, '_Z4testv')
 
-print("String length is: %i" % emulator.uc.reg_read(UC_ARM_REG_R0))
+print("String length is: %i" % emulator.mu.reg_read(UC_ARM_REG_R0))

it works.

TL;DR: replace all emulator.uc. by emulator.mu.

The reason for putting . at the end while replacing is to prevent incorrect substitution

taozhiyu avatar Jan 27 '23 18:01 taozhiyu