Skip to content
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

Merged
merged 4 commits into from
Mar 2, 2017
Merged

Conversation

olifozzy
Copy link
Contributor

@olifozzy olifozzy commented Mar 1, 2017

Allow interception when a field and a method have the same name.

note : I've added some unit tests that I wasn't able to run (no build env here)

Should fix #20 :)

Copy link
Member

@oleavr oleavr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w00t! Just some nitpicks:

@@ -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);
Copy link
Member

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.

const fieldHandle = env.newGlobalRef(field);
fieldHandles.push(fieldHandle);
// If we have a collided method, suffix the fieldName
if(jsMethods.hasOwnProperty(fieldjsName)){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Comment can be removed as it's already clear what the code is doing.
  • Missing space after if.
  • Theoretically there might be a method prefixed with _ having the same name, so using while here would be better.


static int Particle2(){
return 4;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field- and method-names should follow the coding style, i.e. camelCase, not CamelCase.

@olifozzy
Copy link
Contributor Author

olifozzy commented Mar 1, 2017

Ok, I have fixed according to your feedback.

@olifozzy olifozzy closed this Mar 1, 2017
@olifozzy olifozzy reopened this Mar 1, 2017
Copy link
Member

@oleavr oleavr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there

const fieldHandle = env.newGlobalRef(field);
fieldHandles.push(fieldHandle);
while (jsMethods.hasOwnProperty(fieldjsName)){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Let's move these 3 lines to right after the let, as they belong together. Then put a blank line between that and the fieldHandle stuff (those two lines), and then one blank line before assigning to jsFields. Just to make the code a bit more readable.
  • Missing a space before {.

return 3;
}

static int particle2(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before {.


class Collider {
static int particle = 1;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace.

@@ -65,6 +65,62 @@ public void genericsCanBeUsed() {
assertEquals("Badger", script.getNextMessage());
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an extra blank line here.

@olifozzy
Copy link
Contributor Author

olifozzy commented Mar 1, 2017

Damn I miss stylecop ^^ Should be good now :)

Copy link
Member

@oleavr oleavr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one :)


const fieldHandle = env.newGlobalRef(field);
fieldHandles.push(fieldHandle);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace.

@olifozzy
Copy link
Contributor Author

olifozzy commented Mar 1, 2017

Don't see any trailing whitespace :'( Do you mean the extra line ?
trailing

Maybe that's because I'm on windows :/ cr/lf vs lf ?

@oleavr
Copy link
Member

oleavr commented Mar 2, 2017

The last blank line isn't blank, it's got spaces before the CRLF.

@oleavr oleavr merged commit c25a339 into frida:master Mar 2, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Field and Method that have same names are collinding.
3 participants