728x90
    
    
  반응형
    
    
    
  frida로 안드로이드 분석시 "[object Object]" 읽는 방법
frida로 함수 등을 후킹해서 안드로이드에서 사용하는 변수의 값을 읽고자 할 때,
실제 byte, int 등의 자료형이 아닌 Object 자료형으로 분류되는 경우가 종종 있다.
이것 때문에 상당히 골치아팠는데, 해결책을 찾아서 정리.
1. bytes, byte array인데 frida로 출력시 Object라고 나오는 경우
/*
test = [41, 42]
return "AB"
*/
function buf2hex(buf) {
	var arrayBuffer = new Uint8Array(buf);
	var s = String.fromCharCode.apply(null, arrayBuffer);
	return s;
}
/*
test = "AB"
return [41, 42]
*/
function string2Bin(str) {
    var result = [];
    for (var i = 0; i < str.length; i++) {
      result.push(str.charCodeAt(i));
    }
    return result;
}
var test_package = "com.test.Crypto"
var test = Java.use(test_package);
    
test.func.implementation = function (x) {
    var a = buf2hex(Java.array('byte', x))
    a = string2Bin(a);
    a = Java.array('byte', a)
    var buf = Base64.encodeToString(a, 0);
    /*
    
    ~ ~ ~
    
    */
    new_x = Base64.decode(newBodyStr, 0);
    x = Java.array('byte', new_x)
        
    return  this.func(x)   
}
2. object나 class의 멤버 변수 값을 보고 싶을 경우
console.log(obj)
console.log(Object.keys(obj));
console.log(Java.array('byte', obj.m_szData))
var fields = obj.getClass().getDeclaredFields();
var data = fields[3].get(obj)
console.log(buf2hex(Java.array('byte', data)));
      
for (var i = 0; i < fields.length; i++) {
    var field = fields[i];
    field.setAccessible(true);
    console.log(field.getName() + ": " + field.get(x));
}
.
728x90
    
    
  반응형
    
    
    
  '리버싱 > frida' 카테고리의 다른 글
| how to call native function using frida (0) | 2024.08.22 | 
|---|---|
| anti anti frida (0) | 2023.02.02 | 
댓글