[SmaliMod] adjust handling for stream, files and dexlib2

This commit is contained in:
Connor Tumbleson 2013-08-13 15:43:35 -05:00
parent 3acff3ef34
commit 5aa18eee2d

View File

@ -20,6 +20,7 @@ import java.io.*;
import org.antlr.runtime.*;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.apache.commons.io.IOUtils;
import org.jf.dexlib2.writer.builder.DexBuilder;
import org.jf.smali.*;
@ -28,15 +29,35 @@ import org.jf.smali.*;
*/
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,
boolean printTokens) throws IOException,
RecognitionException {
boolean printTokens) throws IOException, RecognitionException {
CommonTokenStream tokens;
LexerErrorInterface lexer;
FileInputStream fis = new FileInputStream(smaliFile.getAbsolutePath());
InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
InputStream is = new FileInputStream(smaliFile);
InputStreamReader reader = new InputStreamReader(is, "UTF-8");
lexer = new smaliFlexLexer(reader);
((smaliFlexLexer)lexer).setSourceFile(smaliFile);