Skip to content

Commit

Permalink
Remove dex debug info #96 and dump-build dex markers
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Apr 23, 2024
1 parent 05bb63f commit f25f4ae
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class DecompileOptions extends Options {
public String resDirName;
public boolean keepResPath;
public boolean dex;
public boolean noDexDebug;
public boolean dexMarkers;

public DecompileOptions(){
type=TYPE_XML;
}
Expand All @@ -37,6 +40,8 @@ public void parse(String[] args) throws ARGException {
parseType(args, type);
parseOutput(args);
parseSplitResources(args);
parseNoDexDebug(args);
parseDexMarkers(args);
parseDex(args);
parseKeepResPath(args);
parseResDirName(args);
Expand All @@ -47,19 +52,25 @@ public void parse(String[] args) throws ARGException {
}
super.parse(args);
}
private void parseKeepResPath(String[] args) throws ARGException {
private void parseKeepResPath(String[] args) {
keepResPath = containsArg(ARG_keep_res_path, true, args);
}
private void parseValidateResDir(String[] args) throws ARGException {
private void parseValidateResDir(String[] args) {
validateResDir=containsArg(ARG_validate_res_dir, true, args);
}
private void parseResDirName(String[] args) throws ARGException {
this.resDirName=parseArgValue(ARG_resDir, true, args);
}
private void parseSplitResources(String[] args) throws ARGException {
private void parseSplitResources(String[] args) {
splitJson=containsArg(ARG_split_resources, true, args);
}
private void parseDex(String[] args) throws ARGException {
private void parseNoDexDebug(String[] args) {
noDexDebug = containsArg(ARG_no_dex_debug, true, args);
}
private void parseDexMarkers(String[] args) {
dexMarkers = containsArg(ARG_dex_markers, true, args);
}
private void parseDex(String[] args) {
dex = containsArg(ARG_dex, true, args);
}
private void parseOutput(String[] args) throws ARGException {
Expand Down Expand Up @@ -155,7 +166,9 @@ public static String getHelp(){
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}
new String[]{ARG_validate_res_dir, ARG_DESC_validate_res_dir},
new String[]{ARG_no_dex_debug, ARG_DESC_no_dex_debug},
new String[]{ARG_dex_markers, ARG_DESC_dex_markers}
};
StringHelper.printTwoColumns(builder, " ", Options.PRINT_WIDTH, table);
String jar = APKEditor.getJarName();
Expand Down Expand Up @@ -199,5 +212,10 @@ public static String getHelp(){
private static final String ARG_dex = "-dex";
private static final String ARG_DESC_dex = "Copy raw dex files / skip smali";

private static final String ARG_no_dex_debug = "-no-dex-debug";
private static final String ARG_DESC_no_dex_debug = "Drops all debug info from smali/dex";

private static final String ARG_dex_markers = "-dex-markers";
private static final String ARG_DESC_dex_markers = "Dumps dex markers (applies only when smali mode)";

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private SmaliDecompiler getSmaliDecompiler(TableBlock tableBlock){
if(getOptions().dex){
return null;
}
SmaliDecompiler smaliDecompiler = new SmaliDecompiler(tableBlock);
SmaliDecompiler smaliDecompiler = new SmaliDecompiler(tableBlock, getOptions());
smaliDecompiler.setApkLogger(this);
return smaliDecompiler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.reandroid.archive.InputSource;
import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
import com.reandroid.utils.StringsUtil;
import org.jf.dexlib2.extra.DexMarker;
import org.jf.smali.Smali;
import org.jf.smali.SmaliOptions;

Expand Down Expand Up @@ -79,6 +80,10 @@ private InputSource build(String progress, File classesDir, File dexCacheFile) t
dir.mkdirs();
}
smaliOptions.outputDexFile = dexCacheFile.getAbsolutePath();
File marker = new File(classesDir, DexMarker.FILE_NAME);
if(marker.isFile()){
smaliOptions.markersListFile = marker.getAbsolutePath();
}
if(smaliOptions.jobs <= 0){
smaliOptions.jobs = 1;
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/reandroid/apkeditor/smali/SmaliDecompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.reandroid.apk.APKLogger;
import com.reandroid.apk.DexDecoder;
import com.reandroid.apk.DexFileInputSource;
import com.reandroid.apkeditor.decompile.DecompileOptions;
import com.reandroid.arsc.chunk.TableBlock;
import org.jf.baksmali.Baksmali;
import org.jf.baksmali.BaksmaliOptions;
Expand All @@ -30,10 +31,16 @@

public class SmaliDecompiler implements DexDecoder {
private final TableBlock tableBlock;
private final DecompileOptions decompileOptions;
private ResourceComment mComment;
private APKLogger apkLogger;
public SmaliDecompiler(TableBlock tableBlock){
public SmaliDecompiler(TableBlock tableBlock, DecompileOptions decompileOptions){
this.tableBlock = tableBlock;
this.decompileOptions = decompileOptions;
}
@Deprecated
public SmaliDecompiler(TableBlock tableBlock){
this(tableBlock, new DecompileOptions());
}
@Override
public boolean decodeDex(DexFileInputSource inputSource, File mainDir) throws IOException {
Expand All @@ -50,6 +57,8 @@ private void disassembleDexFile(DexFileInputSource inputSource, File mainDir) th
options.localsDirective = true;
options.sequentialLabels = true;
options.skipDuplicateLineNumbers = true;
options.debugInfo = !decompileOptions.noDexDebug;
options.dumpMarkers = decompileOptions.dexMarkers;
options.setCommentProvider(getComment());
DexBackedDexFile dexFile = getInputDexFile(inputSource, options);
Baksmali.disassembleDexFile(dexFile, dir, 1, options);
Expand Down

1 comment on commit f25f4ae

@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.

#87

Please sign in to comment.