Skip to content

Commit

Permalink
update ARSCLib with preserve signature block #3
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Apr 28, 2023
1 parent 4d33b3a commit 83dc6f4
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 22 deletions.
Binary file modified libs/ARSCLib.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions src/main/java/com/reandroid/apkeditor/Options.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -131,6 +131,6 @@ protected boolean containsArg(String argSwitch, boolean ignore_case, String[] ar
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')";
protected static final String ARG_force="-f";
protected static final String ARG_DESC_force="force delete output path";
protected static final String ARG_keepMeta = "-keep-meta";
protected static final String ARG_DESC_keepMeta = "keeps META-INF directory";
protected static final String ARG_cleanMeta = "-clean-meta";
protected static final String ARG_DESC_cleanMeta = "cleans META-INF directory along with signature block";
}
6 changes: 2 additions & 4 deletions src/main/java/com/reandroid/apkeditor/compile/Builder.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -29,7 +29,6 @@

import java.io.File;
import java.io.IOException;
import java.util.zip.ZipEntry;

public class Builder implements WriteProgress {
private final BuildOptions options;
Expand All @@ -47,6 +46,7 @@ public void run() throws IOException {
public void buildJson() throws IOException {
log("Scanning JSON directory ...");
ApkJsonEncoder encoder=new ApkJsonEncoder();
encoder.setAPKLogger(getAPKLogger());
ApkModule loadedModule=encoder.scanDirectory(options.inputFile);
loadedModule.setAPKLogger(getAPKLogger());
if(options.resDirName!=null){
Expand Down Expand Up @@ -79,8 +79,6 @@ public void buildXml() throws IOException {
log("Writing apk...");
loadedModule.getApkArchive().sortApkFiles();
loadedModule.writeApk(options.outputFile, null);
log("Zip align ...");
ZipAlign.align4(options.outputFile);
log("Built to: "+options.outputFile);
log("Done");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -59,6 +59,7 @@ public void run() throws IOException {
}else{
log("Decompiling to XML ...");
ApkModuleXmlDecoder xmlDecoder=new ApkModuleXmlDecoder(apkModule);
xmlDecoder.setUseAndroidSerializer(true);
xmlDecoder.sanitizeFilePaths();
try {
xmlDecoder.decodeTo(options.outputFile);
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/reandroid/apkeditor/merge/Merger.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.reandroid.apkeditor.common.AndroidManifestHelper;
import com.reandroid.archive.APKArchive;
import com.reandroid.archive.WriteProgress;
import com.reandroid.archive.ZipAlign;
import com.reandroid.archive2.Archive;
import com.reandroid.arsc.value.ResTableEntry;
import com.reandroid.arsc.value.ResValue;
Expand Down Expand Up @@ -78,9 +77,10 @@ public void run() throws IOException {
log("Validating resources dir ...");
mergedModule.validateResourcesDir();
}
if(!options.keepMeta){
if(options.cleanMeta){
log("Clearing META-INF ...");
removeSignature(mergedModule);
mergedModule.setApkSignatureBlock(null);
}
if(mergedModule.hasAndroidManifestBlock()){
sanitizeManifest(mergedModule);
Expand All @@ -91,8 +91,6 @@ public void run() throws IOException {
if(extracted){
Util.deleteDir(dir);
}
log("Zip align ...");
ZipAlign.align4(options.outputFile);
log("Saved to: "+options.outputFile);
log("Done");
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/reandroid/apkeditor/merge/MergerOptions.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -24,7 +24,7 @@

public class MergerOptions extends Options {
public boolean validateResDir;
public boolean keepMeta;
public boolean cleanMeta;
public String resDirName;
public MergerOptions(){
super();
Expand All @@ -35,14 +35,14 @@ public void parse(String[] args) throws ARGException {
parseOutput(args);
parseResDirName(args);
parseValidateResDir(args);
parseKeepMeta(args);
parseCleanMeta(args);
super.parse(args);
}
private void parseValidateResDir(String[] args) throws ARGException {
validateResDir=containsArg(ARG_validate_res_dir, true, args);
}
private void parseKeepMeta(String[] args) throws ARGException {
keepMeta = containsArg(ARG_keepMeta, true, args);
private void parseCleanMeta(String[] args) throws ARGException {
cleanMeta = containsArg(ARG_cleanMeta, true, args);
}
private void parseResDirName(String[] args) throws ARGException {
this.resDirName=parseArgValue(ARG_resDir, true, args);
Expand Down Expand Up @@ -93,7 +93,7 @@ public String toString(){
if(force){
builder.append("\n Force: true");
}
if(keepMeta){
if(cleanMeta){
builder.append("\n Keep meta: true");
}
builder.append("\n ---------------------------- ");
Expand All @@ -112,7 +112,7 @@ public static String getHelp(){
builder.append("\nFlags:\n");
table=new String[][]{
new String[]{ARG_force, ARG_DESC_force},
new String[]{ARG_keepMeta, ARG_DESC_keepMeta}
new String[]{ARG_cleanMeta, ARG_DESC_cleanMeta}
};
StringHelper.printTwoColumns(builder, " ", 75, table);
String jar = APKEditor.getJarName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void parse(String[] args) throws ARGException {
super.parse(args);
}
private void parseKeepMeta(String[] args) throws ARGException {
keepMeta = containsArg(ARG_keepMeta, true, args);
keepMeta = containsArg(ARG_cleanMeta, true, args);
}
private void parseFixTypes(String[] args) throws ARGException {
fixTypeNames=containsArg(ARG_fix_types, true, args);
Expand Down Expand Up @@ -118,7 +118,7 @@ public static String getHelp(){
table=new String[][]{
new String[]{ARG_fix_types, ARG_DESC_fix_types},
new String[]{ARG_force, ARG_DESC_force},
new String[]{ARG_keepMeta, ARG_DESC_keepMeta}
new String[]{ARG_cleanMeta, ARG_DESC_cleanMeta}
};
StringHelper.printTwoColumns(builder, " ", 75, table);
String jar = APKEditor.getJarName();
Expand Down

0 comments on commit 83dc6f4

Please sign in to comment.