DexFileBuilder: added possibility to name streams.

This commit is contained in:
Ryszard Wiśniewski 2010-04-27 21:29:49 +02:00
parent 853d807f59
commit f9c9588f1d

View File

@ -32,15 +32,17 @@ 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 {
addSmaliFile(new FileInputStream(smaliFile)); addSmaliFile(new FileInputStream(smaliFile),
smaliFile.getAbsolutePath());
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
throw new AndrolibException(ex); throw new AndrolibException(ex);
} }
} }
public void addSmaliFile(InputStream smaliStream) throws AndrolibException { public void addSmaliFile(InputStream smaliStream, String name)
throws AndrolibException {
try { try {
if (!assembleSmaliFile(smaliStream)) { if (!assembleSmaliFile(smaliStream, name)) {
throw new AndrolibException( throw new AndrolibException(
"Could not smali file: " + smaliStream); "Could not smali file: " + smaliStream);
} }
@ -80,9 +82,10 @@ public class DexFileBuilder {
return bytes; return bytes;
} }
private boolean assembleSmaliFile(InputStream smaliStream) private boolean assembleSmaliFile(InputStream smaliStream, String name)
throws IOException, RecognitionException { throws IOException, RecognitionException {
ANTLRInputStream input = new ANTLRInputStream(smaliStream, "UTF8"); ANTLRInputStream input = new ANTLRInputStream(smaliStream, "UTF8");
input.name = name;
smaliLexer lexer = new smaliLexer(input); smaliLexer lexer = new smaliLexer(input);