sensepost / objection

📱 objection - runtime mobile exploration
GNU General Public License v3.0
7.41k stars 850 forks source link

TypeError: cannot read property '$className' of null when running the command 'android hooking get current_activity' #618

Open eitansha opened 1 year ago

eitansha commented 1 year ago

Hello,

I'm encountering an error while trying to retrieve the current activity using the command 'android hooking get current_activity.' The specific error message is as follows (I'm using the flag '--debug') Also, the application is running properly.

A Frida agent exception has occurred.
TypeError: cannot read property '$className' of null
    at <anonymous> (src/android/hooking.ts:235)
    at <anonymous> (src/android/lib/libjava.ts:9)
    at <anonymous> (frida/node_modules/frida-java-bridge/lib/vm.js:12)
    at perform (frida/node_modules/frida-java-bridge/index.js:205)
    at <anonymous> (src/android/lib/libjava.ts:13)
    at Promise (native)
    at wrapJavaPerform (src/android/lib/libjava.ts:14)
    at <anonymous> (src/android/hooking.ts:243)
    at androidHookingGetCurrentActivity (src/rpc/android.ts:41)
    at apply (native)
    at <anonymous> (frida/runtime/message-dispatcher.js:13)
    at c (frida/runtime/message-dispatcher.js:23)

Python stack trace: Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\objection\console\repl.py", line 371, in start_repl
    self.run_command(document)
  File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\objection\console\repl.py", line 185, in run_command
    exec_method(arguments)
  File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\objection\commands\android\hooking.py", line 235, in get_current_activity
    activity = api.android_hooking_get_current_activity()
  File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\frida\core.py", line 179, in method
    return script._rpc_request("call", js_name, args, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\frida\core.py", line 86, in wrapper
    return f(*args, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\frida\core.py", line 491, in _rpc_request
    raise result.error
frida.core.RPCException: TypeError: cannot read property '$className' of null
    at <anonymous> (src/android/hooking.ts:235)
    at <anonymous> (src/android/lib/libjava.ts:9)
    at <anonymous> (frida/node_modules/frida-java-bridge/lib/vm.js:12)
    at perform (frida/node_modules/frida-java-bridge/index.js:205)
    at <anonymous> (src/android/lib/libjava.ts:13)
    at Promise (native)
    at wrapJavaPerform (src/android/lib/libjava.ts:14)
    at <anonymous> (src/android/hooking.ts:243)
    at androidHookingGetCurrentActivity (src/rpc/android.ts:41)
    at apply (native)
    at <anonymous> (frida/runtime/message-dispatcher.js:13)
    at c (frida/runtime/message-dispatcher.js:23)

I would appreciate any assistance in resolving this issue.

limin05030 commented 1 year ago

edit your local file "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\objection\agent.js", find this lines:

return {
        activity: currentActivity.$className,
        fragment: fragment.$className,
};

modifiy to:

return {
        activity: currentActivity.$className,
        fragment: fragment?.$className ?? null,
};