Manually generate cd and eocd before sign
This commit is contained in:
parent
b44b06f268
commit
8c0fe5646b
|
|
@ -258,6 +258,25 @@ public class LSPatch {
|
||||||
|
|
||||||
dstZFile.realign();
|
dstZFile.realign();
|
||||||
|
|
||||||
|
// create zip link
|
||||||
|
if (verbose)
|
||||||
|
System.out.println("Creating nested apk link...");
|
||||||
|
|
||||||
|
NestedZipLink nestedZipLink = new NestedZipLink(dstZFile);
|
||||||
|
StoredEntry originalZipEntry = dstZFile.get(ORIGINAL_APK_ASSET_PATH);
|
||||||
|
NestedZip nestedZip = new NestedZip(srcZFile, originalZipEntry);
|
||||||
|
for (StoredEntry entry : srcZFile.entries()) {
|
||||||
|
String name = entry.getCentralDirectoryHeader().getName();
|
||||||
|
if (name.startsWith("classes") && name.endsWith(".dex")) continue;
|
||||||
|
if (dstZFile.get(name) != null) continue;
|
||||||
|
if (name.equals("AndroidManifest.xml")) continue;
|
||||||
|
if (name.startsWith("META-INF/CERT")) continue;
|
||||||
|
if (name.equals("META-INF/MANIFEST.MF")) continue;
|
||||||
|
nestedZip.addFileLink(name);
|
||||||
|
}
|
||||||
|
nestedZipLink.nestedZips.add(nestedZip);
|
||||||
|
dstZFile.addZFileExtension(nestedZipLink);
|
||||||
|
|
||||||
// sign apk
|
// sign apk
|
||||||
System.out.println("Signing apk...");
|
System.out.println("Signing apk...");
|
||||||
try {
|
try {
|
||||||
|
|
@ -278,22 +297,6 @@ public class LSPatch {
|
||||||
throw new PatchError("Failed to sign apk: " + e.getMessage());
|
throw new PatchError("Failed to sign apk: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// create zip link
|
|
||||||
if (verbose)
|
|
||||||
System.out.println("Creating nested apk link...");
|
|
||||||
|
|
||||||
NestedZipLink nestedZipLink = new NestedZipLink(dstZFile);
|
|
||||||
StoredEntry originalZipEntry = dstZFile.get(ORIGINAL_APK_ASSET_PATH);
|
|
||||||
NestedZip nestedZip = new NestedZip(srcZFile, originalZipEntry);
|
|
||||||
for (StoredEntry entry : srcZFile.entries()) {
|
|
||||||
String name = entry.getCentralDirectoryHeader().getName();
|
|
||||||
if (name.startsWith("classes") && name.endsWith(".dex")) continue;
|
|
||||||
if (name.equals("AndroidManifest.xml")) continue;
|
|
||||||
nestedZip.addFileLink(name);
|
|
||||||
}
|
|
||||||
nestedZipLink.nestedZips.add(nestedZip);
|
|
||||||
dstZFile.addZFileExtension(nestedZipLink);
|
|
||||||
|
|
||||||
dstZFile.update();
|
dstZFile.update();
|
||||||
FileUtils.copyFile(tmpApk, outputFile);
|
FileUtils.copyFile(tmpApk, outputFile);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,12 @@ public class NestedZipLink extends ZFileExtension {
|
||||||
deleteDirectoryAndEocd.setAccessible(true);
|
deleteDirectoryAndEocd.setAccessible(true);
|
||||||
deleteDirectoryAndEocd.invoke(zFile);
|
deleteDirectoryAndEocd.invoke(zFile);
|
||||||
appendEntries();
|
appendEntries();
|
||||||
|
Method computeCentralDirectory = ZFile.class.getDeclaredMethod("computeCentralDirectory");
|
||||||
|
computeCentralDirectory.setAccessible(true);
|
||||||
|
computeCentralDirectory.invoke(zFile);
|
||||||
|
Method computeEocd = ZFile.class.getDeclaredMethod("computeEocd");
|
||||||
|
computeEocd.setAccessible(true);
|
||||||
|
computeEocd.invoke(zFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
var ex = new IOException("Error when writing link entries");
|
var ex = new IOException("Error when writing link entries");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue