Guest User

Untitled

a guest
Sep 16th, 2019
266
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from __future__ import print_function
  2. import frida
  3. import sys
  4.  
  5. def main(target_process):
  6. session = frida.attach(target_process)
  7. script = session.create_script("""
  8. const fastCallback = Memory.alloc(Process.pageSize);
  9. console.log(fastCallback);
  10. Memory.patchCode(fastCallback, 128, code => {
  11. const cw = new X86Writer(code, { pc: fastCallback });
  12. cw.putCmpRegI32('edi', 10);
  13. cw.putJccShortLabel('je', 'match', 'unlikely');
  14.  
  15. cw.putLabel('nomatch');
  16. cw.putMovRegU64('rax', 42);
  17. cw.putJmpShortLabel('done');
  18.  
  19. cw.putLabel('match');
  20. cw.putSubRegImm('rsp', 8);
  21. cw.putCallAddressWithAlignedArguments(slowCallback, ['edi']);
  22. cw.putAddRegImm('rsp', 8);
  23.  
  24. cw.putLabel('done');
  25. cw.putRet();
  26.  
  27. cw.flush();
  28. });
  29. });
  30. """)
  31. print("[!] Ctrl+D on UNIX, Ctrl+Z on Windows/cmd.exe to detach from instrumented program.\n\n")
  32. sys.stdin.read()
  33. session.detach()
  34.  
  35. if __name__ == '__main__':
  36. if len(sys.argv) != 2:
  37. print("Usage: %s <process name or PID>" % __file__)
  38. sys.exit(1)
  39.  
  40. try:
  41. target_process = int(sys.argv[1])
  42. except ValueError:
  43. target_process = sys.argv[1]
  44. main(target_process)
RAW Paste Data