RE env for inspecting APKs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.4 KiB

  1. /*
  2. * raptor_frida_android_enum.js - Java class/method enumerator
  3. * Copyright (c) 2017 Marco Ivaldi <raptor@0xdeadbeef.info>
  4. *
  5. * Frida.re JS functions to enumerate Java classes and methods
  6. * declared in an iOS app. See https://www.frida.re/ and
  7. * https://codeshare.frida.re/ for further information on this
  8. * powerful tool.
  9. *
  10. * "We want to help others achieve interop through reverse
  11. * engineering" -- @oleavr
  12. *
  13. * Example usage:
  14. * # frida -U -f com.target.app -l raptor_frida_android_enum.js --no-pause
  15. *
  16. * Get the latest version at:
  17. * https://github.com/0xdea/frida-scripts/
  18. */
  19. // enumerate all Java classes
  20. function enumAllClasses()
  21. {
  22. var allClasses = [];
  23. var classes = Java.enumerateLoadedClassesSync();
  24. classes.forEach(function(aClass) {
  25. try {
  26. var className = aClass.match(/[L](.*);/)[1].replace(/\//g, ".");
  27. }
  28. catch(err) {return;} // avoid TypeError: cannot read property 1 of null
  29. allClasses.push(className);
  30. });
  31. return allClasses;
  32. }
  33. // find all Java classes that match a pattern
  34. function findClasses(pattern)
  35. {
  36. var allClasses = enumAllClasses();
  37. var foundClasses = [];
  38. allClasses.forEach(function(aClass) {
  39. try {
  40. if (aClass.match(pattern)) {
  41. foundClasses.push(aClass);
  42. }
  43. }
  44. catch(err) {} // avoid TypeError: cannot read property 'match' of undefined
  45. });
  46. return foundClasses;
  47. }
  48. // enumerate all methods declared in a Java class
  49. function enumMethods(targetClass)
  50. {
  51. var hook = Java.use(targetClass);
  52. var ownMethods = hook.class.getDeclaredMethods();
  53. hook.$dispose;
  54. return ownMethods;
  55. }
  56. /*
  57. * The following functions were not implemented because deemed impractical:
  58. *
  59. * enumAllMethods() - enumerate all methods declared in all Java classes
  60. * findMethods(pattern) - find all Java methods that match a pattern
  61. *
  62. * See raptor_frida_ios_enum.js for a couple of ObjC implementation examples.
  63. */
  64. // usage examples
  65. setTimeout(function() { // avoid java.lang.ClassNotFoundException
  66. Java.perform(function() {
  67. // enumerate all classes
  68. ///*
  69. var a = enumAllClasses();
  70. a.forEach(function(s) {
  71. console.log(s);
  72. });
  73. //*/
  74. // find classes that match a pattern
  75. /*
  76. var a = findClasses(/password/i);
  77. a.forEach(function(s) {
  78. console.log(s);
  79. });
  80. */
  81. // enumerate all methods in a class
  82. /*
  83. var a = enumMethods("com.target.app.PasswordManager")
  84. a.forEach(function(s) {
  85. console.log(s);
  86. });
  87. */
  88. });
  89. }, 0);