Skip to content

Commit 83dc6f4

Browse files
committed
update ARSCLib with preserve signature block #3
1 parent 4d33b3a commit 83dc6f4

File tree

8 files changed

+19
-22
lines changed

8 files changed

+19
-22
lines changed

libs/ARSCLib.jar

38.9 KB
Binary file not shown.

src/main/java/com/reandroid/apkeditor/Options.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (C) 2022 github.com/REAndroid
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -131,6 +131,6 @@ protected boolean containsArg(String argSwitch, boolean ignore_case, String[] ar
131131
protected static final String ARG_DESC_validate_res_dir="validate resources dir name\n(eg. if a drawable resource file path is 'res/abc.png' then\nit will be moved to 'res/drawable/abc.png')";
132132
protected static final String ARG_force="-f";
133133
protected static final String ARG_DESC_force="force delete output path";
134-
protected static final String ARG_keepMeta = "-keep-meta";
135-
protected static final String ARG_DESC_keepMeta = "keeps META-INF directory";
134+
protected static final String ARG_cleanMeta = "-clean-meta";
135+
protected static final String ARG_DESC_cleanMeta = "cleans META-INF directory along with signature block";
136136
}

src/main/java/com/reandroid/apkeditor/compile/Builder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (C) 2022 github.com/REAndroid
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,7 +29,6 @@
2929

3030
import java.io.File;
3131
import java.io.IOException;
32-
import java.util.zip.ZipEntry;
3332

3433
public class Builder implements WriteProgress {
3534
private final BuildOptions options;
@@ -47,6 +46,7 @@ public void run() throws IOException {
4746
public void buildJson() throws IOException {
4847
log("Scanning JSON directory ...");
4948
ApkJsonEncoder encoder=new ApkJsonEncoder();
49+
encoder.setAPKLogger(getAPKLogger());
5050
ApkModule loadedModule=encoder.scanDirectory(options.inputFile);
5151
loadedModule.setAPKLogger(getAPKLogger());
5252
if(options.resDirName!=null){
@@ -79,8 +79,6 @@ public void buildXml() throws IOException {
7979
log("Writing apk...");
8080
loadedModule.getApkArchive().sortApkFiles();
8181
loadedModule.writeApk(options.outputFile, null);
82-
log("Zip align ...");
83-
ZipAlign.align4(options.outputFile);
8482
log("Built to: "+options.outputFile);
8583
log("Done");
8684
}

src/main/java/com/reandroid/apkeditor/decompile/DecompileOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (C) 2022 github.com/REAndroid
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");

src/main/java/com/reandroid/apkeditor/decompile/Decompiler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (C) 2022 github.com/REAndroid
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -59,6 +59,7 @@ public void run() throws IOException {
5959
}else{
6060
log("Decompiling to XML ...");
6161
ApkModuleXmlDecoder xmlDecoder=new ApkModuleXmlDecoder(apkModule);
62+
xmlDecoder.setUseAndroidSerializer(true);
6263
xmlDecoder.sanitizeFilePaths();
6364
try {
6465
xmlDecoder.decodeTo(options.outputFile);

src/main/java/com/reandroid/apkeditor/merge/Merger.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.reandroid.apkeditor.common.AndroidManifestHelper;
2121
import com.reandroid.archive.APKArchive;
2222
import com.reandroid.archive.WriteProgress;
23-
import com.reandroid.archive.ZipAlign;
2423
import com.reandroid.archive2.Archive;
2524
import com.reandroid.arsc.value.ResTableEntry;
2625
import com.reandroid.arsc.value.ResValue;
@@ -78,9 +77,10 @@ public void run() throws IOException {
7877
log("Validating resources dir ...");
7978
mergedModule.validateResourcesDir();
8079
}
81-
if(!options.keepMeta){
80+
if(options.cleanMeta){
8281
log("Clearing META-INF ...");
8382
removeSignature(mergedModule);
83+
mergedModule.setApkSignatureBlock(null);
8484
}
8585
if(mergedModule.hasAndroidManifestBlock()){
8686
sanitizeManifest(mergedModule);
@@ -91,8 +91,6 @@ public void run() throws IOException {
9191
if(extracted){
9292
Util.deleteDir(dir);
9393
}
94-
log("Zip align ...");
95-
ZipAlign.align4(options.outputFile);
9694
log("Saved to: "+options.outputFile);
9795
log("Done");
9896
}

src/main/java/com/reandroid/apkeditor/merge/MergerOptions.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (C) 2022 github.com/REAndroid
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,7 @@
2424

2525
public class MergerOptions extends Options {
2626
public boolean validateResDir;
27-
public boolean keepMeta;
27+
public boolean cleanMeta;
2828
public String resDirName;
2929
public MergerOptions(){
3030
super();
@@ -35,14 +35,14 @@ public void parse(String[] args) throws ARGException {
3535
parseOutput(args);
3636
parseResDirName(args);
3737
parseValidateResDir(args);
38-
parseKeepMeta(args);
38+
parseCleanMeta(args);
3939
super.parse(args);
4040
}
4141
private void parseValidateResDir(String[] args) throws ARGException {
4242
validateResDir=containsArg(ARG_validate_res_dir, true, args);
4343
}
44-
private void parseKeepMeta(String[] args) throws ARGException {
45-
keepMeta = containsArg(ARG_keepMeta, true, args);
44+
private void parseCleanMeta(String[] args) throws ARGException {
45+
cleanMeta = containsArg(ARG_cleanMeta, true, args);
4646
}
4747
private void parseResDirName(String[] args) throws ARGException {
4848
this.resDirName=parseArgValue(ARG_resDir, true, args);
@@ -93,7 +93,7 @@ public String toString(){
9393
if(force){
9494
builder.append("\n Force: true");
9595
}
96-
if(keepMeta){
96+
if(cleanMeta){
9797
builder.append("\n Keep meta: true");
9898
}
9999
builder.append("\n ---------------------------- ");
@@ -112,7 +112,7 @@ public static String getHelp(){
112112
builder.append("\nFlags:\n");
113113
table=new String[][]{
114114
new String[]{ARG_force, ARG_DESC_force},
115-
new String[]{ARG_keepMeta, ARG_DESC_keepMeta}
115+
new String[]{ARG_cleanMeta, ARG_DESC_cleanMeta}
116116
};
117117
StringHelper.printTwoColumns(builder, " ", 75, table);
118118
String jar = APKEditor.getJarName();

src/main/java/com/reandroid/apkeditor/refactor/RefactorOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void parse(String[] args) throws ARGException {
3939
super.parse(args);
4040
}
4141
private void parseKeepMeta(String[] args) throws ARGException {
42-
keepMeta = containsArg(ARG_keepMeta, true, args);
42+
keepMeta = containsArg(ARG_cleanMeta, true, args);
4343
}
4444
private void parseFixTypes(String[] args) throws ARGException {
4545
fixTypeNames=containsArg(ARG_fix_types, true, args);
@@ -118,7 +118,7 @@ public static String getHelp(){
118118
table=new String[][]{
119119
new String[]{ARG_fix_types, ARG_DESC_fix_types},
120120
new String[]{ARG_force, ARG_DESC_force},
121-
new String[]{ARG_keepMeta, ARG_DESC_keepMeta}
121+
new String[]{ARG_cleanMeta, ARG_DESC_cleanMeta}
122122
};
123123
StringHelper.printTwoColumns(builder, " ", 75, table);
124124
String jar = APKEditor.getJarName();

0 commit comments

Comments
 (0)