frida-java-bridge 6.1.2 → 6.1.3

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 +48 -14
  2. package/package.json +1 -1
package/lib/android.js CHANGED
@@ -2786,7 +2786,7 @@ const artQuickCodeReplacementTrampolineWriters = {
2786
2786
  arm64: writeArtQuickCodeReplacementTrampolineArm64
2787
2787
  };
2788
2788
 
2789
- function writeArtQuickCodeReplacementTrampolineIA32 (trampoline, target, redirectSize, vm) {
2789
+ function writeArtQuickCodeReplacementTrampolineIA32 (trampoline, target, redirectSize, constraints, vm) {
2790
2790
  const threadOffsets = getArtThreadSpec(vm).offset;
2791
2791
  const artMethodOffsets = getArtMethodSpec(vm).offset;
2792
2792
 
@@ -2849,7 +2849,7 @@ function writeArtQuickCodeReplacementTrampolineIA32 (trampoline, target, redirec
2849
2849
  return offset;
2850
2850
  }
2851
2851
 
2852
- function writeArtQuickCodeReplacementTrampolineX64 (trampoline, target, redirectSize, vm) {
2852
+ function writeArtQuickCodeReplacementTrampolineX64 (trampoline, target, redirectSize, constraints, vm) {
2853
2853
  const threadOffsets = getArtThreadSpec(vm).offset;
2854
2854
  const artMethodOffsets = getArtMethodSpec(vm).offset;
2855
2855
 
@@ -2912,7 +2912,7 @@ function writeArtQuickCodeReplacementTrampolineX64 (trampoline, target, redirect
2912
2912
  return offset;
2913
2913
  }
2914
2914
 
2915
- function writeArtQuickCodeReplacementTrampolineArm (trampoline, target, redirectSize, vm) {
2915
+ function writeArtQuickCodeReplacementTrampolineArm (trampoline, target, redirectSize, constraints, vm) {
2916
2916
  const artMethodOffsets = getArtMethodSpec(vm).offset;
2917
2917
 
2918
2918
  const targetAddress = target.and(THUMB_BIT_REMOVAL_MASK);
@@ -2999,7 +2999,7 @@ function writeArtQuickCodeReplacementTrampolineArm (trampoline, target, redirect
2999
2999
  return offset;
3000
3000
  }
3001
3001
 
3002
- function writeArtQuickCodeReplacementTrampolineArm64 (trampoline, target, redirectSize, vm) {
3002
+ function writeArtQuickCodeReplacementTrampolineArm64 (trampoline, target, redirectSize, { availableScratchRegs }, vm) {
3003
3003
  const artMethodOffsets = getArtMethodSpec(vm).offset;
3004
3004
 
3005
3005
  let offset;
@@ -3068,8 +3068,9 @@ function writeArtQuickCodeReplacementTrampolineArm64 (trampoline, target, redire
3068
3068
  relocator.writeAll();
3069
3069
 
3070
3070
  if (!relocator.eoi) {
3071
- writer.putLdrRegAddress('x17', target.add(offset));
3072
- writer.putBrReg('x17');
3071
+ const scratchReg = Array.from(availableScratchRegs)[0];
3072
+ writer.putLdrRegAddress(scratchReg, target.add(offset));
3073
+ writer.putBrReg(scratchReg);
3073
3074
  }
3074
3075
 
3075
3076
  writer.putLabel('invoke_replacement');
@@ -3146,7 +3147,7 @@ class ArtQuickCodeInterceptor {
3146
3147
  this.overwrittenPrologueLength = 0;
3147
3148
  }
3148
3149
 
3149
- _canRelocateCode (relocationSize) {
3150
+ _canRelocateCode (relocationSize, constraints) {
3150
3151
  const Writer = thunkWriters[Process.arch];
3151
3152
  const Relocator = thunkRelocators[Process.arch];
3152
3153
 
@@ -3156,14 +3157,44 @@ class ArtQuickCodeInterceptor {
3156
3157
  const relocator = new Relocator(quickCodeAddress, writer);
3157
3158
 
3158
3159
  let offset;
3159
- do {
3160
- offset = relocator.readOne();
3161
- } while (offset < relocationSize && !relocator.eoi);
3160
+ if (Process.arch === 'arm64') {
3161
+ let availableScratchRegs = new Set(['x16', 'x17']);
3162
+
3163
+ do {
3164
+ const nextOffset = relocator.readOne();
3165
+
3166
+ const nextScratchRegs = new Set(availableScratchRegs);
3167
+ const { read, written } = relocator.input.regsAccessed;
3168
+ for (const regs of [read, written]) {
3169
+ for (const reg of regs) {
3170
+ let name;
3171
+ if (reg.startsWith('w')) {
3172
+ name = 'x' + reg.substring(1);
3173
+ } else {
3174
+ name = reg;
3175
+ }
3176
+ nextScratchRegs.delete(name);
3177
+ }
3178
+ }
3179
+ if (nextScratchRegs.size === 0) {
3180
+ break;
3181
+ }
3182
+
3183
+ offset = nextOffset;
3184
+ availableScratchRegs = nextScratchRegs;
3185
+ } while (offset < relocationSize && !relocator.eoi);
3186
+
3187
+ constraints.availableScratchRegs = availableScratchRegs;
3188
+ } else {
3189
+ do {
3190
+ offset = relocator.readOne();
3191
+ } while (offset < relocationSize && !relocator.eoi);
3192
+ }
3162
3193
 
3163
3194
  return offset >= relocationSize;
3164
3195
  }
3165
3196
 
3166
- _createTrampoline () {
3197
+ _allocateTrampoline () {
3167
3198
  if (trampolineAllocator === null) {
3168
3199
  const trampolineSize = (pointerSize === 4) ? 128 : 256;
3169
3200
  trampolineAllocator = makeCodeAllocator(trampolineSize);
@@ -3173,7 +3204,8 @@ class ArtQuickCodeInterceptor {
3173
3204
 
3174
3205
  let redirectSize, spec;
3175
3206
  let alignment = 1;
3176
- if (pointerSize === 4 || this._canRelocateCode(maxRedirectSize)) {
3207
+ const constraints = {};
3208
+ if (pointerSize === 4 || this._canRelocateCode(maxRedirectSize, constraints)) {
3177
3209
  redirectSize = maxRedirectSize;
3178
3210
 
3179
3211
  spec = {};
@@ -3193,6 +3225,8 @@ class ArtQuickCodeInterceptor {
3193
3225
 
3194
3226
  this.redirectSize = redirectSize;
3195
3227
  this.trampoline = trampolineAllocator.allocateSlice(spec, alignment);
3228
+
3229
+ return constraints;
3196
3230
  }
3197
3231
 
3198
3232
  _destroyTrampoline () {
@@ -3200,12 +3234,12 @@ class ArtQuickCodeInterceptor {
3200
3234
  }
3201
3235
 
3202
3236
  activate (vm) {
3203
- this._createTrampoline();
3237
+ const constraints = this._allocateTrampoline();
3204
3238
 
3205
3239
  const { trampoline, quickCode, redirectSize } = this;
3206
3240
 
3207
3241
  const writeTrampoline = artQuickCodeReplacementTrampolineWriters[Process.arch];
3208
- const prologueLength = writeTrampoline(trampoline, quickCode, redirectSize, vm);
3242
+ const prologueLength = writeTrampoline(trampoline, quickCode, redirectSize, constraints, vm);
3209
3243
  this.overwrittenPrologueLength = prologueLength;
3210
3244
 
3211
3245
  this.overwrittenPrologue = Memory.dup(this.quickCodeAddress, prologueLength);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frida-java-bridge",
3
- "version": "6.1.2",
3
+ "version": "6.1.3",
4
4
  "description": "Java runtime interop from Frida",
5
5
  "main": "index.js",
6
6
  "files": [