sensepost / objection

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

fix(agent):check and wait for the currentApplication is ready #623

Closed coderiderlin closed 1 month ago

coderiderlin commented 1 year ago

fix a bug that Java.use("android.app.ActivityThread").currentApplication() return null in the early stage of the application startup. just check and wait for it become ready at the frist time. the error log as follow:

$ objection -g com.tencent.mobileqq explore
Using USB device `IN2020`
Agent injected and responds ok!
Traceback (most recent call last):
  File "C:\Python311\Scripts\objection-script.py", line 33, in <module>
    sys.exit(load_entry_point('objection==1.11.0', 'console_scripts', 'objection')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\objection\console\cli.py", line 156, in explore
    device_info = get_device_info()
                  ^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\objection\commands\device.py", line 41, in get_device_info
    package_info = api.env_android()
                   ^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\frida\core.py", line 179, in method
    return script._rpc_request("call", js_name, args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\frida\core.py", line 86, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\frida\core.py", line 491, in _rpc_request
    raise result.error
frida.core.RPCException: TypeError: cannot read property 'getApplicationContext' of null
    at getApplicationContext (/script1.js:18857)
    at <anonymous> (/script1.js:19469)
    at <anonymous> (/script1.js:18835)
    at <anonymous> (frida/node_modules/frida-java-bridge/lib/vm.js:12)
    at _performPendingVmOps (frida/node_modules/frida-java-bridge/index.js:250)
    at <anonymous> (frida/node_modules/frida-java-bridge/index.js:242)
    at apply (native)
    at ne (frida/node_modules/frida-java-bridge/lib/class-factory.js:673)
    at <anonymous> (frida/node_modules/frida-java-bridge/lib/class-factory.js:651)
Asking jobs to stop...
Unloading objection agent...
leonjza commented 1 month ago

Thanks for the PR! I'm not going to pull this one in. After https://github.com/sensepost/objection/commit/865fb7dbe4a3150bfb57651157b0710ff075ed21 there is quite a bit of work going into refactoring some of the spawning logic, removing dependencies that would cause issues like this.

Appreciate you taking the time to contribute!