Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sort field items according to dex_file_verifier.cc #322

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/mkdex.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ function computeModel (classes) {
stringToIndex[fieldName]
];
});
fieldItems.sort(compareFieldItems);

const methodItems = methods.map(method => {
const [klass, protoId, name, annotationsId] = method;
Expand Down Expand Up @@ -744,7 +745,7 @@ function computeModel (classes) {
const instanceFields = fieldItems.reduce((result, field, index) => {
const [holder] = field;
if (holder === classIndex) {
result.push([index, kAccPublic]);
result.push([index > 0 ? 1 : 0, kAccPublic]);
}
return result;
}, []);
Expand Down Expand Up @@ -848,6 +849,21 @@ function compareProtoItems (a, b) {
return 0;
}

function compareFieldItems (a, b) {
const [aClass, aType, aName] = a;
const [bClass, bType, bName] = b;

if (aClass !== bClass) {
return aClass - bClass;
}

if (aName !== bName) {
return aName - bName;
}

return aType - bType;
}

function compareMethodItems (a, b) {
const [aClass, aProto, aName] = a;
const [bClass, bProto, bName] = b;
Expand Down
1 change: 1 addition & 0 deletions test/re/frida/ClassCreationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public void classWithUserDefinedFieldsCanBeImplemented() throws ClassNotFoundExc
" fields: {" +
" lastInt: 'int'," +
" lastStr: 'java.lang.String'," +
" lastByteArr: '[B'," +
" }," +
" methods: {" +
" format: [{" +
Expand Down
Loading