use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project android-classyshark by google.
the class ApkDashboard method fillAnalysisPerClassesDexIndex.
public static ClassesDexDataEntry fillAnalysisPerClassesDexIndex(int dexIndex, File classesDex) {
ClassesDexDataEntry dexData = new ClassesDexDataEntry(dexIndex);
try {
InputStream is = new FileInputStream(classesDex);
ApplicationVisitor av = new ApkNativeMethodsVisitor(dexData);
ApplicationReader ar = new ApplicationReader(Opcodes.ASM4, is);
ar.accept(av, 0);
} catch (Exception e) {
e.printStackTrace();
}
try {
DexFile dxFile = DexlibLoader.loadDexFile(classesDex);
DexBackedDexFile dataPack = (DexBackedDexFile) dxFile;
dexData.allMethods = dataPack.getMethodCount();
//dexData.syntheticAccessors =
// new SyntheticAccessorsInspector(dxFile).getSyntheticAccessors();
} catch (Exception e) {
e.printStackTrace();
System.out.println("here " + e);
}
return dexData;
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project android-classyshark by google.
the class DexInfoTranslator method apply.
@Override
public void apply() {
try {
elements.clear();
File classesDex = extractClassesDex(dexFileName, apkFile, this);
DexFile dxFile = DexlibLoader.loadDexFile(classesDex);
DexBackedDexFile dataPack = (DexBackedDexFile) dxFile;
ELEMENT element = new ELEMENT("\nclasses: " + dataPack.getClassCount(), TAG.MODIFIER);
elements.add(element);
element = new ELEMENT("\nstrings: " + dataPack.getStringCount(), TAG.DOCUMENT);
elements.add(element);
element = new ELEMENT("\ntypes: " + dataPack.getTypeCount(), TAG.DOCUMENT);
elements.add(element);
element = new ELEMENT("\nprotos: " + dataPack.getProtoCount(), TAG.DOCUMENT);
elements.add(element);
element = new ELEMENT("\nfields: " + dataPack.getFieldCount(), TAG.DOCUMENT);
elements.add(element);
element = new ELEMENT("\nmethods: " + dataPack.getMethodCount(), TAG.IDENTIFIER);
elements.add(element);
element = new ELEMENT("\n\nFile size: " + JarInfoTranslator.readableFileSize(classesDex.length()), TAG.DOCUMENT);
elements.add(element);
element = new ELEMENT("\n\nClasses with Native Calls\n", TAG.MODIFIER);
elements.add(element);
Set<String> classesWithNativeMethods = getClassesWithNativeMethodsPerDexIndex(index, classesDex);
for (String classWithNativeMethods : classesWithNativeMethods) {
element = new ELEMENT(classWithNativeMethods + "\n", TAG.DOCUMENT);
elements.add(element);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project dex2jar by pxb1988.
the class SmaliTest method dotest.
private void dotest(File dexFile) throws IOException {
DexBackedDexFile dex = DexFileFactory.loadDexFile(dexFile, 14, false);
Map<String, DexClassNode> map = readDex(dexFile);
for (DexBackedClassDef def : dex.getClasses()) {
String type = def.getType();
System.out.println(type);
DexClassNode dexClassNode = map.get(type);
Assert.assertNotNull(dexClassNode);
// original
String smali = baksmali(def);
Smali.smaliFile2Node("fake.smali", smali);
{
byte[] data = toDex(dexClassNode);
DexBackedClassDef def2 = new DexBackedDexFile(new Opcodes(14, false), data).getClasses().iterator().next();
// original
String baksmali3 = baksmali(def2);
Assert.assertEquals(smali, baksmali3);
}
String psmali = pbaksmali(dexClassNode);
DexClassNode dexClassNode2 = Smali.smaliFile2Node("fake.smali", psmali);
Assert.assertEquals("cmp smalip", psmali, pbaksmali(dexClassNode2));
{
byte[] data = toDex(dexClassNode2);
DexBackedClassDef def2 = new DexBackedDexFile(new Opcodes(14, false), data).getClasses().iterator().next();
// original
String baksmali3 = baksmali(def2);
Assert.assertEquals(smali, baksmali3);
}
}
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class DexFileFactory method loadDexContainer.
/**
* Loads a file containing 1 or more dex files
*
* If the given file is a dex or odex file, it will return a MultiDexContainer containing that single entry.
* Otherwise, for an oat or zip file, it will return an OatFile or ZipDexContainer respectively.
*
* @param file The file to open
* @param opcodes The set of opcodes to use
* @return A MultiDexContainer
* @throws DexFileNotFoundException If the given file does not exist
* @throws UnsupportedFileTypeException If the given file is not a valid dex/zip/odex/oat file
*/
public static MultiDexContainer<? extends DexBackedDexFile> loadDexContainer(@Nonnull File file, @Nonnull final Opcodes opcodes) throws IOException {
if (!file.exists()) {
throw new DexFileNotFoundException("%s does not exist", file.getName());
}
ZipDexContainer zipDexContainer = new ZipDexContainer(file, opcodes);
if (zipDexContainer.isZipFile()) {
return zipDexContainer;
}
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
try {
try {
DexBackedDexFile dexFile = DexBackedDexFile.fromInputStream(opcodes, inputStream);
return new SingletonMultiDexContainer(file.getPath(), dexFile);
} catch (DexBackedDexFile.NotADexFile ex) {
// just eat it
}
try {
DexBackedOdexFile odexFile = DexBackedOdexFile.fromInputStream(opcodes, inputStream);
return new SingletonMultiDexContainer(file.getPath(), odexFile);
} catch (DexBackedOdexFile.NotAnOdexFile ex) {
// just eat it
}
// Note: DexBackedDexFile.fromInputStream and DexBackedOdexFile.fromInputStream will reset inputStream
// back to the same position, if they fails
OatFile oatFile = null;
try {
oatFile = OatFile.fromInputStream(inputStream);
} catch (NotAnOatFileException ex) {
// just eat it
}
if (oatFile != null) {
// TODO: we should support loading earlier oat files, just not deodexing them
if (oatFile.isSupportedVersion() == OatFile.UNSUPPORTED) {
throw new UnsupportedOatVersionException(oatFile);
}
return oatFile;
}
} finally {
inputStream.close();
}
throw new UnsupportedFileTypeException("%s is not an apk, dex, odex or oat file.", file.getPath());
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class SmaliTestUtils method compileSmali.
public static ClassDef compileSmali(String smaliText, int apiLevel) throws RecognitionException, IOException {
CommonTokenStream tokens;
LexerErrorInterface lexer;
DexBuilder dexBuilder = new DexBuilder(Opcodes.forApi(apiLevel));
Reader reader = new StringReader(smaliText);
lexer = new smaliFlexLexer(reader);
tokens = new CommonTokenStream((TokenSource) lexer);
smaliParser parser = new smaliParser(tokens);
parser.setVerboseErrors(true);
parser.setAllowOdex(false);
parser.setApiLevel(apiLevel);
smaliParser.smali_file_return result = parser.smali_file();
if (parser.getNumberOfSyntaxErrors() > 0 || lexer.getNumberOfSyntaxErrors() > 0) {
throw new RuntimeException("Error occured while compiling text");
}
CommonTree t = result.getTree();
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
treeStream.setTokenStream(tokens);
smaliTreeWalker dexGen = new smaliTreeWalker(treeStream);
dexGen.setApiLevel(apiLevel);
dexGen.setVerboseErrors(true);
dexGen.setDexBuilder(dexBuilder);
dexGen.smali_file();
if (dexGen.getNumberOfSyntaxErrors() > 0) {
throw new RuntimeException("Error occured while compiling text");
}
MemoryDataStore dataStore = new MemoryDataStore();
dexBuilder.writeTo(dataStore);
DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.forApi(apiLevel), dataStore.getData());
return Iterables.getFirst(dexFile.getClasses(), null);
}
Aggregations