-
-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
handle field / method name collision #21
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -669,9 +669,13 @@ function ClassFactory (vm) { | |
try { | ||
const fieldName = invokeObjectMethodNoArgs(env.handle, field, fieldGetName); | ||
try { | ||
const fieldjsName = env.stringFromJni(fieldName); | ||
var fieldjsName = env.stringFromJni(fieldName); | ||
const fieldHandle = env.newGlobalRef(field); | ||
fieldHandles.push(fieldHandle); | ||
// If we have a collided method, suffix the fieldName | ||
if(jsMethods.hasOwnProperty(fieldjsName)){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
fieldjsName = "_" + fieldjsName; | ||
} | ||
jsFields[fieldjsName] = fieldHandle; | ||
} finally { | ||
env.deleteLocalRef(fieldName); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,62 @@ public void genericsCanBeUsed() { | |
assertEquals("Badger", script.getNextMessage()); | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an extra blank line here. |
||
@Test | ||
public void fieldsThatCollideWithMethodsGetSuffixed() { | ||
loadScript("var Collider = Java.use('re.frida.Collider');" + | ||
"var collider = Collider.$new();" + | ||
"send(collider._Particle);"); | ||
assertEquals("1", script.getNextMessage()); | ||
} | ||
|
||
@Test | ||
public void methodsThatCollideWithFieldsKeepName() { | ||
loadScript("var Collider = Java.use('re.frida.Collider');" + | ||
"var collider = Collider.$new();" + | ||
"send(collider.Particle());"); | ||
assertEquals("3", script.getNextMessage()); | ||
} | ||
|
||
@Test | ||
public void fieldsThatCollideWithMethodsGetSuffixed2() { | ||
loadScript("var Collider = Java.use('re.frida.Collider');" + | ||
"var collider = Collider.$new();" + | ||
"send(collider._Particle2);"); | ||
assertEquals("2", script.getNextMessage()); | ||
} | ||
|
||
@Test | ||
public void methodsThatCollideWithFieldsKeepName2() { | ||
loadScript("var Collider = Java.use('re.frida.Collider');" + | ||
"var collider = Collider.$new();" + | ||
"send(collider.Particle2());"); | ||
assertEquals("4", script.getNextMessage()); | ||
} | ||
|
||
@Test | ||
public void collidedMethodsFieldsCanStillBeInstrumented() { | ||
loadScript("var Collider = Java.use('re.frida.Collider');" + | ||
"Collider._Particle.implementation = function () {" + | ||
"return 11;" + | ||
"};" + | ||
"Collider._Particle2.implementation = function () {" + | ||
"return 22;" + | ||
"};" + | ||
"Collider.Particle.implementation = function () {" + | ||
"return 33;" + | ||
"};" + | ||
"Collider.Particle2.implementation = function () {" + | ||
"return 44;" + | ||
"};"); | ||
|
||
Collider collider = new Collider(); | ||
assertEquals(11, Collider.Particle); | ||
assertEquals(22, collider.Particle2); | ||
assertEquals(33, collider.Particle()); | ||
assertEquals(44, Collider.Particle2()); | ||
} | ||
|
||
// @Test | ||
public void interfaceCanBeImplemented() { | ||
loadScript("var X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');" + | ||
|
@@ -118,3 +174,17 @@ public int returnZero() { | |
return 0; | ||
} | ||
} | ||
|
||
class Collider { | ||
static int Particle = 1; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace. |
||
int Particle2 = 2; | ||
|
||
int Particle() { | ||
return 3; | ||
} | ||
|
||
static int Particle2(){ | ||
return 4; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Field- and method-names should follow the coding style, i.e. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
let
here to allow re-assigning –var
is a legacy keyword from ES5.