safeSelf.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. export let SafeSelf = {
  2. start: function () {
  3. let nativePointer = Module.findExportByName(null, "open");
  4. Interceptor.attach(nativePointer, {
  5. onEnter: function (args) {
  6. let path = args[0].readCString();
  7. // log("open path:"+path);
  8. }
  9. })
  10. let connect = Module.findExportByName(null, "connect");
  11. if (connect != null) {
  12. Interceptor.attach(connect, {
  13. onEnter: function (args) {
  14. let arg = args[1];
  15. let port = arg.add(0x2).readUShort();
  16. if (port === 41577
  17. || port === 35421) {
  18. //写值
  19. // logHHex(arg)
  20. arg.add(0x2).writeUShort(26151);
  21. }
  22. }
  23. })
  24. }
  25. },
  26. hook_dlopen: function (soName = '') {
  27. Interceptor.attach(Module.findExportByName(null, "android_dlopen_ext"),
  28. {
  29. onEnter: function (args) {
  30. var pathptr = args[0];
  31. if (pathptr !== undefined && pathptr != null) {
  32. var path = ptr(pathptr).readCString();
  33. if (path.indexOf(soName) >= 0) {
  34. locate_init()
  35. }
  36. }
  37. }
  38. }
  39. );
  40. }
  41. }
  42. function locate_init() {
  43. let secmodule = null
  44. Interceptor.attach(Module.findExportByName(null, "__system_property_get"),
  45. {
  46. // _system_property_get("ro.build.version.sdk", v1);
  47. onEnter: function (args) {
  48. secmodule = Process.findModuleByName("libmsaoaidsec.so")
  49. var name = args[0];
  50. if (secmodule != null && name !== undefined && name != null) {
  51. name = ptr(name).readCString();
  52. if (name.indexOf("ro.build.version.sdk") >= 0) {
  53. // 这是.init_proc刚开始执行的地方,是一个比较早的时机点
  54. // do something
  55. // hook_pthread_create()
  56. bypass()
  57. }
  58. }
  59. }
  60. }
  61. );
  62. }
  63. function hook_pthread_create() {
  64. console.log("libmsaoaidsec.so --- " + Process.findModuleByName("libmsaoaidsec.so").base)
  65. Interceptor.attach(Module.findExportByName("libc.so", "pthread_create"), {
  66. onEnter(args) {
  67. let func_addr = args[2]
  68. console.log("The thread function address is " + func_addr)
  69. }
  70. })
  71. }
  72. function bypass() {
  73. let module = Process.findModuleByName("libmsaoaidsec.so")
  74. if (module !== null) {
  75. console.log("找到libmsaoaidsec.so")
  76. nop(module.base.add(0x175F8))
  77. nop(module.base.add(0x16D30))
  78. }
  79. }
  80. function nop(addr) {
  81. Memory.patchCode(ptr(addr), 16, code => {
  82. //创建arm64指令集的操作对象
  83. const cw = new Arm64Writer(code, {pc: ptr(addr)});
  84. //nop指令
  85. cw.putNop();
  86. cw.putNop();
  87. cw.putNop();
  88. cw.putNop();
  89. console.log("nop at " + addr)
  90. //写入
  91. cw.flush();
  92. });
  93. }