mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-02 15:04:24 +02:00
[SmaliMod] adjust handling for stream, files and dexlib2
This commit is contained in:
parent
3acff3ef34
commit
5aa18eee2d
@ -20,6 +20,7 @@ import java.io.*;
|
|||||||
import org.antlr.runtime.*;
|
import org.antlr.runtime.*;
|
||||||
import org.antlr.runtime.tree.CommonTree;
|
import org.antlr.runtime.tree.CommonTree;
|
||||||
import org.antlr.runtime.tree.CommonTreeNodeStream;
|
import org.antlr.runtime.tree.CommonTreeNodeStream;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.jf.dexlib2.writer.builder.DexBuilder;
|
import org.jf.dexlib2.writer.builder.DexBuilder;
|
||||||
import org.jf.smali.*;
|
import org.jf.smali.*;
|
||||||
|
|
||||||
@ -28,15 +29,35 @@ import org.jf.smali.*;
|
|||||||
*/
|
*/
|
||||||
public class SmaliMod {
|
public class SmaliMod {
|
||||||
|
|
||||||
|
public static boolean assembleSmaliFile(String smali, DexBuilder dexBuilder, boolean verboseErrors,
|
||||||
|
boolean printTokens, File smaliFile) throws IOException, RuntimeException, RecognitionException {
|
||||||
|
|
||||||
|
InputStream is = new ByteArrayInputStream(smali.getBytes());
|
||||||
|
return assembleSmaliFile(is, dexBuilder, verboseErrors, printTokens, smaliFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean assembleSmaliFile(InputStream is,DexBuilder dexBuilder, boolean verboseErrors,
|
||||||
|
boolean printTokens, File smaliFile) throws IOException, RecognitionException {
|
||||||
|
|
||||||
|
// copy our filestream into a tmp file, so we don't overwrite
|
||||||
|
File tmp = File.createTempFile("BRUT",".bak");
|
||||||
|
tmp.deleteOnExit();
|
||||||
|
|
||||||
|
OutputStream os = new FileOutputStream(tmp);
|
||||||
|
IOUtils.copy(is, os);
|
||||||
|
os.close();
|
||||||
|
|
||||||
|
return assembleSmaliFile(tmp,dexBuilder, verboseErrors, printTokens);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean assembleSmaliFile(File smaliFile,DexBuilder dexBuilder, boolean verboseErrors,
|
public static boolean assembleSmaliFile(File smaliFile,DexBuilder dexBuilder, boolean verboseErrors,
|
||||||
boolean printTokens) throws IOException,
|
boolean printTokens) throws IOException, RecognitionException {
|
||||||
RecognitionException {
|
|
||||||
|
|
||||||
CommonTokenStream tokens;
|
CommonTokenStream tokens;
|
||||||
LexerErrorInterface lexer;
|
LexerErrorInterface lexer;
|
||||||
|
|
||||||
FileInputStream fis = new FileInputStream(smaliFile.getAbsolutePath());
|
InputStream is = new FileInputStream(smaliFile);
|
||||||
InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
|
InputStreamReader reader = new InputStreamReader(is, "UTF-8");
|
||||||
|
|
||||||
lexer = new smaliFlexLexer(reader);
|
lexer = new smaliFlexLexer(reader);
|
||||||
((smaliFlexLexer)lexer).setSourceFile(smaliFile);
|
((smaliFlexLexer)lexer).setSourceFile(smaliFile);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user