Skip to content

Commit

Permalink
Fix PackageParser
Browse files Browse the repository at this point in the history
Signed-off-by: utzcoz <utzcoz@outlook.com>
Signed-off-by: YOUNG HO CHA <ganachoco@linecorp.com>
  • Loading branch information
ganadist authored and utzcoz committed Mar 4, 2023
1 parent 42af661 commit ebffead
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Expand Up @@ -116,6 +116,9 @@ public ResTable_lib_header asResTable_lib_header() {
public ResTable_lib_entry asResTable_lib_entry() {
if (header_size() >= ResTable_lib_entry.SIZEOF) {
return new ResTable_lib_entry(device_chunk_.myBuf(), device_chunk_.myOffset());
} else if (header_size() > 0) {
return new ResTable_lib_entry(
device_chunk_.myBuf(), device_chunk_.myOffset() + header_size());
} else {
return null;
}
Expand Down
Expand Up @@ -733,11 +733,11 @@ static LoadedPackage Load(Chunk chunk,
// reinterpret_cast<ResTable_lib_entry*>(child_chunk.data_ptr());
ResTable_lib_entry entry_begin =
child_chunk.asResTable_lib_entry();
// ResTable_lib_entry entry_end = entry_begin + dtohl(lib.count);
// for (auto entry_iter = entry_begin; entry_iter != entry_end; ++entry_iter) {
for (ResTable_lib_entry entry_iter = entry_begin;
entry_iter.myOffset() != entry_begin.myOffset() + dtohl(lib.count);
entry_iter = new ResTable_lib_entry(entry_iter.myBuf(), entry_iter.myOffset() + ResTable_lib_entry.SIZEOF)) {
// ResTable_lib_entry entry_end = entry_begin + dtohl(lib.count);
// for (auto entry_iter = entry_begin; entry_iter != entry_end; ++entry_iter) {
for (ResTable_lib_entry entry_iter = entry_begin;
entry_iter.myOffset()
!= entry_begin.myOffset() + dtohl(lib.count) * ResTable_lib_entry.SIZEOF; ) {
String package_name =
Util.ReadUtf16StringFromDevice(entry_iter.packageName,
entry_iter.packageName.length);
Expand All @@ -753,6 +753,14 @@ static LoadedPackage Load(Chunk chunk,
// dtohl(entry_iter.packageId));
loaded_package.dynamic_package_map_.add(new DynamicPackageEntry(package_name,
dtohl(entry_iter.packageId)));
try {
entry_iter =
new ResTable_lib_entry(
entry_iter.myBuf(), entry_iter.myOffset() + ResTable_lib_entry.SIZEOF);
} catch (Exception e) {
System.err.println("failed to create new entry " + e.getMessage());
break;
}
}

} break;
Expand Down
Expand Up @@ -44,7 +44,16 @@ public static Package callParsePackage(Path apkFile) {
if (RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.Q) {
QHelper.setCallback(packageParser);
}
thePackage = packageParser.parsePackage(apkFile.toFile(), 0);
// thePackage = packageParser.parsePackage(apkFile.toFile(), flags);
thePackage = packageParser.parsePackage(apkFile.toFile().getParentFile(), 0);
System.out.println("Package : " + thePackage.toString());
System.out.println(" code : " + thePackage.baseCodePath);
for (int i = 0; i < thePackage.splitNames.length; i++) {
String splits = thePackage.splitNames[i];
String codepath = thePackage.splitCodePaths[i];
System.out.println("Split Package : " + splits);
System.out.println("Split code : " + codepath);
}
} else { // JB -> KK
thePackage =
reflector(_PackageParser_.class, packageParser)
Expand Down

0 comments on commit ebffead

Please sign in to comment.