어느 날 frida로 스크립트를 작성하고 후킹을 시도했지만 반갑지 않은 오류 메시지가 떴다.
{'type': 'error', 'description': "ReferenceError: 'Java' is not defined", 'stack': "ReferenceError: 'Java' is not defined\n at <eval> (/script1.js:1)", 'fileName': '/script1.js', 'lineNumber': 1, 'columnNumber': 1}
왜 이런 오류가 발생하나 해서 찾아보았더니, frida 17 버전 이후의 패치로 인해 기존에 Java를 사용하지 못하는 것이다.
이를 해결하기 위한 방안으론 두 가지가 있다.
1. 버전 다운그레이드
https://github.com/frida/frida/issues/3473
Java is not defiend · Issue #3473 · frida/frida
when i run js code everything go right but when i run python code this error appeae: {'type': 'error', 'description': "ReferenceError: 'Java' is not defined", 'stack': "ReferenceError: 'Java' is no...
github.com
Bridge라는 게 17에선 추가되어 그걸 사용해야 한다. 하지만 frida 17 아래로 다운그레이드한다면 이전처럼 사용이 가능하다.
2. Bridge 추가
https://github.com/frida/frida/issues/3460
17.0.1: ObjC is not defined · Issue #3460 · frida/frida
I have this issue in frida-node 17.0.1. I have this line in my script: console.log(ObjC.available) and it throws ReferenceError: 'ObjC' is not defined Is there a new way to use ObjC? This seems to ...
github.com
여기서 본 정보로 bridge를 사용하는 방법을 공유하고 계신다.
그중에서 필자는 파이썬 환경이므로 아래와 같은 코드를 사용했다. (AOS 분석)
import frida, sys
package_name = "패키지 명"
script_file = "스크립트 파일 경로"
def on_message(message, data):
print(message)
def load_bridge(lang):
import os
import importlib.util
# Calculate frida-tools module path without loading it (we don't need to)
frida_tools_path = os.path.dirname(importlib.util.find_spec('frida_tools').origin)
# Calculate the bridge location and load it
bridge_file = os.path.join(frida_tools_path, 'bridges', f'{lang.lower()}.js')
with open(bridge_file, 'r', encoding='utf-8') as f:
bridge_src = f.read()
# Wrap with the setter and return
return '(function() { ' + bridge_src + '; Object.defineProperty(globalThis, "' + lang + '", { value: bridge }); })();\n'
with open(script_file, 'r', encoding="UTF-8") as f:
script = load_bridge('Java') + f.read() # 브릿지 코드 추가
device = frida.get_usb_device()
target_process = device.spawn(package_name)
process_session = device.attach(target_process)
script = process_session.create_script(script)
script.on("message", on_message)
script.load()
device.resume(target_process)
sys.stdin.read()