### Parse and Display Instructions Source: https://context7.com/apkunpacker/anti-frida/llms.txt Parses and displays a specified number of native instructions starting from a given memory address. Useful for inspecting code before and after instrumentation. ```javascript function Ins(nativePtr, instructionCount) { var instructionArr = []; for (var i = 0; i < instructionCount; i++) { var dissAsm = Instruction.parse(nativePtr); console.log(dissAsm); nativePtr = dissAsm.next; } } // Get address of libc 'open' function var Addr = Module.findExportByName("libc.so", "open"); // Parse first 3 instructions Ins(Addr, 3); ``` -------------------------------- ### Demonstrate Interceptor Attach and Instruction Changes Source: https://context7.com/apkunpacker/anti-frida/llms.txt Shows how Frida's Interceptor.attach modifies function instructions by hooking the 'open' system call. It logs file paths and then parses instructions to reveal the trampoline modifications made by Frida. ```javascript var Addr = Module.findExportByName("libc.so", "open"); // Instruction parser function function Ins(nativePtr, instructionCount) { var instructionArr = []; for (var i = 0; i < instructionCount; i++) { var dissAsm = Instruction.parse(nativePtr); console.log(dissAsm); nativePtr = dissAsm.next; } } // Attach interceptor to 'open' function Interceptor.attach(Module.findExportByName("libc.so", "open"), function (args) { console.warn(args[0].readCString()); }); // Parse instructions AFTER attaching hook // This reveals Frida's trampoline modifications Ins(Addr, 3); ``` -------------------------------- ### Parse Instructions After Frida Hook (JavaScript) Source: https://github.com/apkunpacker/anti-frida/blob/main/README.md Attaches a Frida interceptor to the 'open' function in libc.so and then parses its instructions. The output shows modified instructions due to Frida's trampoline. ```javascript var Addr = Module.findExportByName("libc.so","open"); function Ins(nativePtr, instructionCount) { var instructionArr = []; for (var i = 0; i < instructionCount; i++) { var dissAsm = Instruction.parse(nativePtr); console.log(dissAsm); nativePtr = dissAsm.next; } } Interceptor.attach(Module.findExportByName("libc.so","open"), function (args) { console.warn(args[0].readCString()); }) Ins(Addr,3); ``` -------------------------------- ### Parse Instructions of a Function (JavaScript) Source: https://github.com/apkunpacker/anti-frida/blob/main/README.md Parses and prints a specified number of instructions from a given native pointer. This is used to inspect the original state of a function before any hooking. ```javascript var Addr = Module.findExportByName("libc.so","open"); Ins(Addr,3); function Ins(nativePtr, instructionCount) { var instructionArr = []; for (var i = 0; i < instructionCount; i++) { var dissAsm = Instruction.parse(nativePtr); console.log(dissAsm); nativePtr = dissAsm.next; } } ``` -------------------------------- ### Detect Frida Hook on libc.so Functions (JavaScript) Source: https://github.com/apkunpacker/anti-frida/blob/main/README.md Checks for Frida's presence by parsing the first few instructions of critical libc.so functions ('open', 'access', 'stat', 'syscall') and looking for specific instruction patterns indicative of a hook. Displays a toast message if a hook is detected. ```javascript var open = Module.findExportByName("libc.so", 'open'); var access = Module.findExportByName("libc.so", 'access'); var stat = Module.findExportByName("libc.so", 'stat'); var syscall = Module.findExportByName("libc.so", 'syscall'); var O = Instruction.parse(open); var A = Instruction.parse(access); var S = Instruction.parse(stat) var SC = Instruction.parse(syscall); if(O.toString().indexOf("sub sp")<0) { hook("Detected Hook On Libc.so Open"); } if(A.toString().indexOf("mov r2")<0) { hook("Detected Hook On Libc.so Access"); } if(S.toString().indexOf("mov r2")<0) { hook("Detected Hook On Libc.so Stat"); } if(SC.toString().indexOf("mov ip")<0) { hook("Detected Hook On Libc.so Syscall"); } function hook(input) { if (Java.available) { Java.perform(function() { var context = Java.use('android.app.ActivityThread').currentApplication().getApplicationContext(); Java.scheduleOnMainThread(function() { var toast = Java.use("android.widget.Toast"); toast.makeText(Java.use("android.app.ActivityThread").currentApplication().getApplicationContext(), Java.use("java.lang.String").$new(input), 1).show(); }); }); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.