frida-java-bridge 7.0.9 → 7.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/android.js +74 -0
  2. package/package.json +1 -1
package/lib/android.js CHANGED
@@ -1866,6 +1866,31 @@ set_replacement_method (gpointer original_method,
1866
1866
  g_mutex_unlock (&lock);
1867
1867
  }
1868
1868
 
1869
+ void
1870
+ synchronize_replacement_methods (guint quick_code_offset,
1871
+ void * nterp_entrypoint,
1872
+ void * quick_to_interpreter_bridge)
1873
+ {
1874
+ GHashTableIter iter;
1875
+ gpointer hooked_method, replacement_method;
1876
+
1877
+ g_mutex_lock (&lock);
1878
+
1879
+ g_hash_table_iter_init (&iter, methods);
1880
+ while (g_hash_table_iter_next (&iter, &hooked_method, &replacement_method))
1881
+ {
1882
+ void ** quick_code;
1883
+
1884
+ *((uint32_t *) replacement_method) = *((uint32_t *) hooked_method);
1885
+
1886
+ quick_code = hooked_method + quick_code_offset;
1887
+ if (*quick_code == nterp_entrypoint)
1888
+ *quick_code = quick_to_interpreter_bridge;
1889
+ }
1890
+
1891
+ g_mutex_unlock (&lock);
1892
+ }
1893
+
1869
1894
  void
1870
1895
  delete_replacement_method (gpointer original_method)
1871
1896
  {
@@ -2024,6 +2049,7 @@ on_leave_gc_concurrent_copying_copying_phase (GumInvocationContext * ic)
2024
2049
  isReplacement: new NativeFunction(cm.is_replacement_method, 'bool', ['pointer'], fastOptions),
2025
2050
  get: new NativeFunction(cm.get_replacement_method, 'pointer', ['pointer'], fastOptions),
2026
2051
  set: new NativeFunction(cm.set_replacement_method, 'void', ['pointer', 'pointer'], fastOptions),
2052
+ synchronize: new NativeFunction(cm.synchronize_replacement_methods, 'void', ['uint', 'pointer', 'pointer'], fastOptions),
2027
2053
  delete: new NativeFunction(cm.delete_replacement_method, 'void', ['pointer'], fastOptions),
2028
2054
  translate: new NativeFunction(cm.translate_method, 'pointer', ['pointer'], fastOptions),
2029
2055
  findReplacementFromQuickCode: cm.find_replacement_method_from_quick_code
@@ -2057,6 +2083,8 @@ function ensureArtKnowsHowToHandleMethodInstrumentation (vm) {
2057
2083
 
2058
2084
  instrumentArtQuickEntrypoints(vm);
2059
2085
  instrumentArtMethodInvocationFromInterpreter();
2086
+ instrumentArtGarbageCollection();
2087
+ instrumentArtFixupStaticTrampolines();
2060
2088
  }
2061
2089
 
2062
2090
  function instrumentArtQuickEntrypoints (vm) {
@@ -2108,6 +2136,52 @@ function instrumentArtMethodInvocationFromInterpreter () {
2108
2136
  }
2109
2137
  }
2110
2138
 
2139
+ function instrumentArtGarbageCollection () {
2140
+ const api = getApi();
2141
+ const art = api.module;
2142
+
2143
+ const gc = art.findSymbolByName('_ZN3art2gc4Heap22CollectGarbageInternalENS0_9collector6GcTypeENS0_7GcCauseEbj');
2144
+ if (gc === null) {
2145
+ return;
2146
+ }
2147
+
2148
+ const { artNterpEntryPoint, artQuickToInterpreterBridge } = api;
2149
+ const quickCodeOffset = getArtMethodSpec(api.vm).offset.quickCode;
2150
+ Interceptor.attach(gc, {
2151
+ onLeave () {
2152
+ artController.replacedMethods.synchronize(quickCodeOffset, artNterpEntryPoint, artQuickToInterpreterBridge);
2153
+ }
2154
+ });
2155
+ }
2156
+
2157
+ function instrumentArtFixupStaticTrampolines () {
2158
+ const patterns = [
2159
+ ['_ZN3art11ClassLinker26VisiblyInitializedCallback22MarkVisiblyInitializedEPNS_6ThreadE', 'e90340f8 : ff0ff0ff'],
2160
+ ['_ZN3art11ClassLinker26VisiblyInitializedCallback29AdjustThreadVisibilityCounterEPNS_6ThreadEl', '7f0f00f9 : 1ffcffff'],
2161
+ ];
2162
+ const api = getApi();
2163
+ const art = api.module;
2164
+ for (const [name, pattern] of patterns) {
2165
+ const base = art.findSymbolByName(name);
2166
+ if (base === null) {
2167
+ continue;
2168
+ }
2169
+
2170
+ const matches = Memory.scanSync(base, 8192, pattern);
2171
+ if (matches.length === 0) {
2172
+ return;
2173
+ }
2174
+
2175
+ const { artNterpEntryPoint, artQuickToInterpreterBridge } = api;
2176
+ const quickCodeOffset = getArtMethodSpec(api.vm).offset.quickCode;
2177
+ Interceptor.attach(matches[0].address, function () {
2178
+ artController.replacedMethods.synchronize(quickCodeOffset, artNterpEntryPoint, artQuickToInterpreterBridge);
2179
+ });
2180
+
2181
+ return;
2182
+ }
2183
+ }
2184
+
2111
2185
  function ensureArtKnowsHowToHandleReplacementMethods (vm) {
2112
2186
  if (taughtArtAboutReplacementMethods) {
2113
2187
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frida-java-bridge",
3
- "version": "7.0.9",
3
+ "version": "7.0.10",
4
4
  "description": "Java runtime interop from Frida",
5
5
  "keywords": [
6
6
  "frida-gum",