DexFileBuilder: added possibility to smali InputStream.

This commit is contained in:
Ryszard Wiśniewski 2010-04-26 18:37:24 +02:00
parent 5afc491ebc
commit 853d807f59

View File

@ -32,16 +32,22 @@ import org.jf.smali.*;
public class DexFileBuilder { public class DexFileBuilder {
public void addSmaliFile(File smaliFile) throws AndrolibException { public void addSmaliFile(File smaliFile) throws AndrolibException {
try { try {
if (!assembleSmaliFile(smaliFile)) { addSmaliFile(new FileInputStream(smaliFile));
} catch (FileNotFoundException ex) {
throw new AndrolibException(ex);
}
}
public void addSmaliFile(InputStream smaliStream) throws AndrolibException {
try {
if (!assembleSmaliFile(smaliStream)) {
throw new AndrolibException( throw new AndrolibException(
"Could not smali file: " + smaliFile); "Could not smali file: " + smaliStream);
} }
} catch (IOException ex) { } catch (IOException ex) {
throw new AndrolibException( throw new AndrolibException(ex);
"Could not smali file: " + smaliFile, ex);
} catch (RecognitionException ex) { } catch (RecognitionException ex) {
throw new AndrolibException( throw new AndrolibException(ex);
"Could not smali file: " + smaliFile, ex);
} }
} }
@ -74,10 +80,9 @@ public class DexFileBuilder {
return bytes; return bytes;
} }
private boolean assembleSmaliFile(File smaliFile) private boolean assembleSmaliFile(InputStream smaliStream)
throws IOException, RecognitionException { throws IOException, RecognitionException {
ANTLRInputStream input = new ANTLRInputStream(new FileInputStream(smaliFile), "UTF8"); ANTLRInputStream input = new ANTLRInputStream(smaliStream, "UTF8");
input.name = smaliFile.getAbsolutePath();
smaliLexer lexer = new smaliLexer(input); smaliLexer lexer = new smaliLexer(input);