Skip to content

Commit

Permalink
update to ARSCLib-1.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Jun 7, 2023
1 parent 4e32c8c commit 6d4ca29
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 184 deletions.
Binary file modified libs/ARSCLib.jar
Binary file not shown.
5 changes: 4 additions & 1 deletion src/main/java/com/reandroid/apkeditor/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ protected void parseFrameworkVersion(String[] args) throws ARGException {
}
}
protected void parseType(String[] args) throws ARGException {
parseType(args, TYPE_JSON);
}
protected void parseType(String[] args, String def) throws ARGException {
String[] choices = new String[]{TYPE_JSON, TYPE_XML, TYPE_SIG};
this.type = parseType(ARG_type, args, choices, TYPE_JSON);
this.type = parseType(ARG_type, args, choices, def);
}
protected void parseSignaturesDir(String[] args) throws ARGException {
this.signaturesDirectory = parseFile(ARG_sig, args);
Expand Down
29 changes: 12 additions & 17 deletions src/main/java/com/reandroid/apkeditor/compile/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@
*/
package com.reandroid.apkeditor.compile;

import com.reandroid.apk.*;
import com.reandroid.apkeditor.Util;
import com.reandroid.archive.WriteProgress;
import com.reandroid.archive2.Archive;
import com.reandroid.archive2.block.ApkSignatureBlock;
import com.reandroid.archive2.writer.ApkWriter;
import com.reandroid.commons.command.ARGException;
import com.reandroid.commons.utils.log.Logger;
import com.reandroid.apk.APKLogger;
import com.reandroid.apk.ApkJsonEncoder;
import com.reandroid.apk.ApkModule;
import com.reandroid.apk.ApkModuleXmlEncoder;
import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
import com.reandroid.xml.XMLException;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -64,9 +60,10 @@ private void restoreSignatures() throws IOException {
}
public void buildJson() throws IOException {
log("Scanning JSON directory ...");
ApkJsonEncoder encoder=new ApkJsonEncoder();
encoder.setAPKLogger(getAPKLogger());
ApkModule loadedModule=encoder.scanDirectory(options.inputFile);
ApkModuleJsonEncoder encoder=new ApkModuleJsonEncoder();
encoder.setApkLogger(getAPKLogger());
encoder.scanDirectory(options.inputFile);
ApkModule loadedModule = encoder.getApkModule();
loadedModule.setAPKLogger(getAPKLogger());
if(options.resDirName!=null){
log("Renaming resources root dir: "+options.resDirName);
Expand All @@ -86,15 +83,10 @@ public void buildXml() throws IOException {
log("Scanning XML directory ...");
ApkModuleXmlEncoder encoder=new ApkModuleXmlEncoder();
encoder.setApkLogger(getAPKLogger());
ApkModule loadedModule;
try {
loadedModule=encoder.getApkModule();
loadedModule.setPreferredFramework(options.frameworkVersion);
encoder.scanDirectory(options.inputFile);
loadedModule=encoder.getApkModule();
} catch (XMLException ex) {
throw new IOException(ex.getMessage(), ex);
}
ApkModule loadedModule = encoder.getApkModule();
loadedModule.setPreferredFramework(options.frameworkVersion);
encoder.scanDirectory(options.inputFile);
loadedModule = encoder.getApkModule();
log("Writing apk...");
loadedModule.writeApk(options.outputFile, null);
log("Built to: "+options.outputFile);
Expand Down Expand Up @@ -161,6 +153,9 @@ public static void execute(String[] args) throws ARGException, IOException {
}
private static boolean isXmlInDir(File dir){
File manifest=new File(dir, AndroidManifestBlock.FILE_NAME);
if(!manifest.isFile()){
manifest=new File(dir, AndroidManifestBlock.FILE_NAME_BIN);
}
return manifest.isFile();
}
private static boolean isJsonInDir(File dir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,28 @@ public class DecompileOptions extends Options {
public boolean splitJson;
public boolean validateResDir;
public String resDirName;
public boolean keepResPath;
public DecompileOptions(){
type=TYPE_JSON;
type=TYPE_XML;
}
@Override
public void parse(String[] args) throws ARGException {
parseInput(args);
parseType(args);
parseType(args, type);
parseOutput(args);
parseSplitResources(args);
parseKeepResPath(args);
parseResDirName(args);
parseValidateResDir(args);
parseSignaturesDir(args);
if(signaturesDirectory == null && type == null){
type = TYPE_JSON;
type = TYPE_XML;
}
super.parse(args);
}
private void parseKeepResPath(String[] args) throws ARGException {
keepResPath = containsArg(ARG_keep_res_path, true, args);
}
private void parseValidateResDir(String[] args) throws ARGException {
validateResDir=containsArg(ARG_validate_res_dir, true, args);
}
Expand Down Expand Up @@ -106,6 +111,9 @@ public String toString(){
if(force){
builder.append("\n Force: true");
}
if(keepResPath){
builder.append("\n Keep res path: true");
}
if(frameworkVersion != null){
builder.append("\nframework: ").append(frameworkVersion);
}
Expand All @@ -132,6 +140,7 @@ public static String getHelp(){
builder.append("\nFlags:\n");
table=new String[][]{
new String[]{ARG_force, ARG_DESC_force},
new String[]{ARG_keep_res_path, ARG_DESC_keep_res_path},
new String[]{ARG_split_resources, ARG_DESC_split_resources},
new String[]{ARG_validate_res_dir, ARG_DESC_validate_res_dir}
};
Expand Down Expand Up @@ -161,8 +170,11 @@ public static String getHelp(){
private static final String ARG_split_resources="-split-json";
private static final String ARG_DESC_split_resources="splits resources.arsc into multiple parts as per type entries (use this for large files)";

private static final String ARG_DESC_type = "Decode types: \n1) json \n2) xml \n3) sig \n default=json" +
"\n * Output directory contains \n a) res package directory(s) name={index number}-{package name}" +
"\n b) root: directory of raw files like dex, assets, lib ... \n c) AndroidManifest.xml";
private static final String ARG_DESC_type = "Decode types: \n 1) json \n 2) xml \n 3) sig \n default=" + TYPE_XML;


private static final String ARG_keep_res_path = "-keep-res-path";
private static final String ARG_DESC_keep_res_path = "Keeps original res/* file paths:" + "\n *Applies only when decoding to xml" +
"\n *All res/* files will be placed on dir <res-files>\n *The relative paths will be linked to values/*xml";

}
14 changes: 6 additions & 8 deletions src/main/java/com/reandroid/apkeditor/decompile/Decompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
*/
package com.reandroid.apkeditor.decompile;

import com.reandroid.apk.*;
import com.reandroid.apkeditor.Util;
import com.reandroid.archive2.Archive;
import com.reandroid.archive2.block.ApkSignatureBlock;
import com.reandroid.commons.command.ARGException;
import com.reandroid.commons.utils.log.Logger;
import com.reandroid.apk.APKLogger;
import com.reandroid.apk.ApkJsonDecoder;
import com.reandroid.apk.ApkModule;
import com.reandroid.apk.ApkModuleXmlDecoder;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -59,15 +56,16 @@ public void run() throws IOException {
}
if(DecompileOptions.TYPE_JSON.equals(options.type)){
log("Decompiling to JSON ...");
ApkJsonDecoder decoder=new ApkJsonDecoder(apkModule, options.splitJson);
ApkModuleJsonDecoder decoder = new ApkModuleJsonDecoder(apkModule, options.splitJson);
decoder.sanitizeFilePaths();
decoder.writeToDirectory(options.outputFile);
decoder.decode(options.outputFile);
}else{
log("Decompiling to XML ...");
ApkModuleXmlDecoder xmlDecoder=new ApkModuleXmlDecoder(apkModule);
ApkModuleXmlDecoder xmlDecoder = new ApkModuleXmlDecoder(apkModule);
xmlDecoder.setKeepResPath(options.keepResPath);
xmlDecoder.sanitizeFilePaths();
try {
xmlDecoder.decodeTo(options.outputFile);
xmlDecoder.decode(options.outputFile);
} catch (Exception ex) {
throw new IOException(ex.getMessage(), ex);
}
Expand Down
80 changes: 52 additions & 28 deletions src/main/java/com/reandroid/apkeditor/refactor/AutoRefactor.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 @@ -15,31 +15,34 @@
*/
package com.reandroid.apkeditor.refactor;

import com.reandroid.apk.APKLogger;
import com.reandroid.apk.ApkModule;
import com.reandroid.apk.ResFile;
import com.reandroid.apk.ResourceIds;
import com.reandroid.arsc.chunk.TableBlock;
import com.reandroid.identifiers.PackageIdentifier;
import com.reandroid.identifiers.TableIdentifier;
import com.reandroid.identifiers.TypeIdentifier;

import java.io.IOException;
import java.util.List;

public class AutoRefactor {
private final ApkModule mApkModule;
private APKLogger apkLogger;
public AutoRefactor(ApkModule apkModule){
this.mApkModule=apkModule;
this.mApkModule = apkModule;
this.apkLogger = apkModule.getApkLogger();
}
public int refactor() throws IOException {
ResourceIds refactoredId=buildRefactor();
TableBlock tableBlock=mApkModule.getTableBlock();
int renameCount=refactoredId.applyTo(tableBlock);
public void refactor() throws IOException {
refactorResourceNames();
refactorFilePaths();
return renameCount;
}
public int refactorFilePaths() throws IOException {
int renameCount=0;
public int refactorFilePaths(){
logMessage("Validating file paths ...");
int renameCount = 0;
List<ResFile> resFileList = mApkModule.listResFiles();
for(ResFile resFile:resFileList){
String path=RefactorUtil.RES_DIR+"/"+resFile.buildPath();
String path = RefactorUtil.RES_DIR + "/" + resFile.buildPath();
if(path.equals(resFile.getFilePath())){
continue;
}
Expand All @@ -48,24 +51,45 @@ public int refactorFilePaths() throws IOException {
}
return renameCount;
}
private ResourceIds buildRefactor() throws IOException {
ResourceIds.Table obfTable=new ResourceIds.Table();
ResourceIds resourceIds=new ResourceIds(obfTable);
TableBlock tableBlock=mApkModule.getTableBlock();
resourceIds.loadTableBlock(tableBlock);
ResourceIds.Table table=new ResourceIds.Table();
for(ResourceIds.Table.Package obfPackage: obfTable.listPackages()){
ResourceIds.Table.Package pkg=new ResourceIds.Table.Package(obfPackage.id);
pkg.name=obfPackage.name;
for(ResourceIds.Table.Package.Type obfType:obfPackage.listTypes()){
EntryRefactor entryRefactor=new EntryRefactor(tableBlock, obfType);
if(!entryRefactor.isObfuscated()){
continue;
}
pkg.add(entryRefactor.refactorAll());
private void refactorResourceNames(){
logMessage("Validating resource names ...");
TableIdentifier tableIdentifier = new TableIdentifier();
TableBlock tableBlock = mApkModule.getTableBlock();
tableIdentifier.load(tableBlock);
String msg = tableIdentifier.validateSpecNames();
if(msg == null){
logMessage("All resource names are valid");
return;
}
int count = 0;
for(PackageIdentifier pi: tableIdentifier.getPackages()){
for(TypeIdentifier ti:pi.list()){
EntryRefactor entryRefactor = new EntryRefactor(ti);
count += entryRefactor.refactorAll();
}
table.add(pkg);
}
return new ResourceIds(table);
logMessage(msg);
}
public void setApkLogger(APKLogger apkLogger) {
this.apkLogger = apkLogger;
}
void logMessage(String msg) {
APKLogger apkLogger = this.apkLogger;
if(apkLogger!=null){
apkLogger.logMessage(msg);
}
}
void logError(String msg, Throwable tr) {
APKLogger apkLogger = this.apkLogger;
if(apkLogger == null || (msg == null && tr == null)){
return;
}
apkLogger.logError(msg, tr);
}
void logVerbose(String msg) {
APKLogger apkLogger = this.apkLogger;
if(apkLogger!=null){
apkLogger.logVerbose(msg);
}
}
}
Loading

1 comment on commit 6d4ca29

@REAndroid
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #34
Fixes #35

Please sign in to comment.