dex_dump.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding:utf-8 -*-
  2. import sys
  3. __author__ = 'Snow'
  4. import frida
  5. src = """
  6. var dex_count = 0
  7. Interceptor.attach(
  8. Module.findExportByName(
  9. 'libart.so',
  10. '_ZN3art7DexFile10OpenMemoryEPKhjRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEjPNS_6MemMapEPKNS_10OatDexFileEPS9_'
  11. ),
  12. {
  13. onEnter: function (args) {
  14. var begin = args[1]
  15. var address = parseInt(begin, 16) + 0x20
  16. var dex_size = Memory.readInt(ptr(address))
  17. dex_count++
  18. send('Dex' + dex_count + ' Size : ' + dex_size)
  19. var file = new File('/data/data/%s/classes' + (dex_count == 1 ? '' : dex_count) + '.dex', 'wb')
  20. file.write(Memory.readByteArray(begin, dex_size))
  21. file.flush()
  22. file.close()
  23. },
  24. onLeave: function (retval) {
  25. }
  26. }
  27. );
  28. """
  29. app = 'com.hytc.hxsg2.coolpad'
  30. def on_message(message,data):
  31. if message["type"] == "send":
  32. print("[+] {}".format(message["payload"]))
  33. else:
  34. print("[-] {}".format(message))
  35. dev = frida.get_remote_device()
  36. pid = dev.spawn(app)
  37. session = dev.attach(pid)
  38. script = session.create_script(src % app)
  39. script.on("message", on_message)
  40. script.load()
  41. dev.resume(app)
  42. sys.stdin.read()