mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-29 21:10:13 +02:00
SmaliMod, BaksmaliMod: added modifications to original code.
This commit is contained in:
parent
22374f775f
commit
68899cf3f3
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package brut.androlib.mod;
|
package brut.androlib.mod;
|
||||||
|
|
||||||
|
import brut.androlib.src.TypeName;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -32,7 +33,7 @@ import org.jf.dexlib.DexFile;
|
|||||||
*/
|
*/
|
||||||
public class BaksmaliMod {
|
public class BaksmaliMod {
|
||||||
|
|
||||||
public static void disassembleDexFile(String dexFilePath, DexFile dexFile, boolean deodex, String outputDirectory,
|
public static void disassembleDexFile(boolean debug, String dexFilePath, DexFile dexFile, boolean deodex, String outputDirectory,
|
||||||
String[] classPathDirs, String bootClassPath, String extraBootClassPath,
|
String[] classPathDirs, String bootClassPath, String extraBootClassPath,
|
||||||
boolean noParameterRegisters, boolean useLocalsDirective,
|
boolean noParameterRegisters, boolean useLocalsDirective,
|
||||||
boolean useSequentialLabels, boolean outputDebugInfo, boolean addCodeOffsets,
|
boolean useSequentialLabels, boolean outputDebugInfo, boolean addCodeOffsets,
|
||||||
@ -58,7 +59,10 @@ public class BaksmaliMod {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (registerInfo != 0 || deodex || verify) {
|
boolean analyze = ! ClassPath.dontLoadClassPath
|
||||||
|
&& (registerInfo != 0 || deodex || verify);
|
||||||
|
|
||||||
|
if (analyze) {
|
||||||
try {
|
try {
|
||||||
String[] extraBootClassPathArray = null;
|
String[] extraBootClassPathArray = null;
|
||||||
if (extraBootClassPath != null && extraBootClassPath.length() > 0) {
|
if (extraBootClassPath != null && extraBootClassPath.length() > 0) {
|
||||||
@ -121,7 +125,7 @@ public class BaksmaliMod {
|
|||||||
* package name are separated by '/'
|
* package name are separated by '/'
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (registerInfo != 0 || deodex || verify) {
|
if (analyze) {
|
||||||
//If we are analyzing the bytecode, make sure that this class is loaded into the ClassPath. If it isn't
|
//If we are analyzing the bytecode, make sure that this class is loaded into the ClassPath. If it isn't
|
||||||
//then there was some error while loading it, and we should skip it
|
//then there was some error while loading it, and we should skip it
|
||||||
ClassPath.ClassDef classDef = ClassPath.getClassDef(classDefItem.getClassType(), false);
|
ClassPath.ClassDef classDef = ClassPath.getClassDef(classDefItem.getClassType(), false);
|
||||||
@ -141,6 +145,12 @@ public class BaksmaliMod {
|
|||||||
|
|
||||||
File smaliFile = fileNameHandler.getUniqueFilenameForClass(classDescriptor);
|
File smaliFile = fileNameHandler.getUniqueFilenameForClass(classDescriptor);
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
String smaliPath = smaliFile.getPath();
|
||||||
|
smaliFile = new File(
|
||||||
|
smaliPath.substring(0, smaliPath.length() - 6) + ".java");
|
||||||
|
}
|
||||||
|
|
||||||
//create and initialize the top level string template
|
//create and initialize the top level string template
|
||||||
ClassDefinition classDefinition = new ClassDefinition(classDefItem);
|
ClassDefinition classDefinition = new ClassDefinition(classDefItem);
|
||||||
|
|
||||||
@ -167,7 +177,19 @@ public class BaksmaliMod {
|
|||||||
new FileOutputStream(smaliFile), "UTF8"));
|
new FileOutputStream(smaliFile), "UTF8"));
|
||||||
|
|
||||||
writer = new IndentingWriter(bufWriter);
|
writer = new IndentingWriter(bufWriter);
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
TypeName name = TypeName.fromInternalName(
|
||||||
|
classDefItem.getClassType().getTypeDescriptor());
|
||||||
|
writer.write("package " + name.package_ + "; class "
|
||||||
|
+ name.getName(true, true) + " {/*\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
classDefinition.writeTo((IndentingWriter)writer);
|
classDefinition.writeTo((IndentingWriter)writer);
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
writer.write("\n*/}\n");
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.err.println("\n\nError occured while disassembling class " + classDescriptor.replace('/', '.') + " - skipping class");
|
System.err.println("\n\nError occured while disassembling class " + classDescriptor.replace('/', '.') + " - skipping class");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
@ -28,9 +28,10 @@ import org.jf.smali.*;
|
|||||||
*/
|
*/
|
||||||
public class SmaliMod {
|
public class SmaliMod {
|
||||||
|
|
||||||
private static boolean assembleSmaliFile(File smaliFile, DexFile dexFile, boolean verboseErrors, boolean oldLexer,
|
public static boolean assembleSmaliFile(InputStream smaliStream,
|
||||||
boolean printTokens)
|
String name, DexFile dexFile, boolean verboseErrors,
|
||||||
throws Exception {
|
boolean oldLexer, boolean printTokens)
|
||||||
|
throws IOException, RecognitionException {
|
||||||
CommonTokenStream tokens;
|
CommonTokenStream tokens;
|
||||||
|
|
||||||
|
|
||||||
@ -38,17 +39,16 @@ public class SmaliMod {
|
|||||||
LexerErrorInterface lexer;
|
LexerErrorInterface lexer;
|
||||||
|
|
||||||
if (oldLexer) {
|
if (oldLexer) {
|
||||||
ANTLRFileStream input = new ANTLRFileStream(smaliFile.getAbsolutePath(), "UTF-8");
|
ANTLRInputStream input = new ANTLRInputStream(smaliStream, "UTF-8");
|
||||||
input.name = smaliFile.getAbsolutePath();
|
input.name = name;
|
||||||
|
|
||||||
lexer = new smaliLexer(input);
|
lexer = new smaliLexer(input);
|
||||||
tokens = new CommonTokenStream((TokenSource)lexer);
|
tokens = new CommonTokenStream((TokenSource)lexer);
|
||||||
} else {
|
} else {
|
||||||
FileInputStream fis = new FileInputStream(smaliFile.getAbsolutePath());
|
InputStreamReader reader =
|
||||||
InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
|
new InputStreamReader(smaliStream, "UTF-8");
|
||||||
|
|
||||||
lexer = new smaliFlexLexer(reader);
|
lexer = new smaliFlexLexer(reader);
|
||||||
((smaliFlexLexer)lexer).setSourceFile(smaliFile);
|
|
||||||
tokens = new CommonTokenStream((TokenSource)lexer);
|
tokens = new CommonTokenStream((TokenSource)lexer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user