Skip to content

Commit

Permalink
mkdex: Fix field item ordering (#322)
Browse files Browse the repository at this point in the history
To match what dex_file_verifier.cc does.

Fixes #296.
  • Loading branch information
eybisi authored Jun 6, 2024
1 parent 3dc627b commit a635d2d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit a635d2d

Please sign in to comment.