//一般写在app的私有目录里,不然会报错:failed to open file (Permission denied)(实际上就是权限不足) var file_path = "/data/user/0/com.zj.wuaipojie/test.txt"; var file_handle = new File(file_path, "wb"); if (file_handle && file_handle != null) { file_handle.write(data); //写入数据 file_handle.flush(); //刷新 file_handle.close(); //关闭 }
2.Frida_inlineHook与读写汇编
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
function inline_hook() { var soAddr = Module.findBaseAddress("lib52pojie.so"); if (soAddr) { var func_addr = soAddr.add(0x10428); Java.perform(function () { Interceptor.attach(func_addr, { onEnter: function (args) { console.log(this.context.x22); //注意此时就没有args概念了 this.context.x22 = ptr(1); //赋值方法参考上一节课 }, onLeave: function (retval) { } } ) }) } }
将地址的指令解析成汇编
1 2 3
var soAddr = Module.findBaseAddress("lib52pojie.so"); var codeAddr = Instruction.parse(soAddr.add(0x10428)); console.log(codeAddr.toString());
function patchCode(){ var soAddr = Module.findBaseAddress("lib52pojie.so"); var codeAddr = soAddr.add(0x10428); var codeasm = Instruction.parse(codeAddr); console.log(codeasm.toString()); Memory.patchCode(codeAddr, 4, function(code) { const writer = new Arm64Writer(code, { pc: codeAddr }); writer.putBytes(hexToBytes("20008052")); // MOV W0, 1 // writer.putBytes(hexToBytes("200080D2")); // MOV X0, 1 writer.flush(); }); }
function hexToBytes(str) { var pos = 0; var len = str.length; if (len % 2 != 0) { return null; } len /= 2; var hexA = new Array(); for (var i = 0; i < len; i++) { var s = str.substr(pos, 2); var v = parseInt(s, 16); hexA.push(v); pos += 2; } return hexA; }