public static Set<String> classesOfDex(DexBackedDexFile dexFile) { Set<String> classes = new HashSet<String>(); for (ClassDef c : dexFile.getClasses()) { String name = Util.dottedClassName(c.getType()); classes.add(name); } return classes; }
DexBackedDexFile entry = dexContainer.getEntry(entryName); entryName = deriveDexName(entryName); logger.debug("" + String.format("Found dex file '%s' with %d classes in '%s'", entryName, entry.getClasses().size(), dexSourceFile.getCanonicalPath()));
public void initialize() { for (ClassDef defItem : dexFile.getClasses()) { String forClassName = Util.dottedClassName(defItem.getType()); classesToDefItems.put(forClassName, new ClassInformation(dexFile, defItem));
for (DexBackedClassDef def : dex.getClasses()) { String type = def.getType(); System.out.println(type); DexBackedClassDef def2 = new DexBackedDexFile(new Opcodes(14, false), data).getClasses().iterator().next(); DexBackedClassDef def2 = new DexBackedDexFile(new Opcodes(14, false), data).getClasses().iterator().next();
private static Map<String, ClassDef> getBundleClassDef(File file) throws IOException { HashMap<String, ClassDef> classDefMap = new HashMap<String, ClassDef>(); File[] dexFiles = getDexFiles(file); HashSet<ClassDef> classDefs = new HashSet<ClassDef>(); for (File dexFile : dexFiles) { classDefs.addAll(DexFileFactory.loadDexFile(dexFile, 19, true).getClasses()); } for (ClassDef classDef : classDefs) { classDefMap.put(classDef.getType(), classDef); } return classDefMap; }
@Override public void run() { if (help || inputList == null || inputList.isEmpty()) { usage(); return; } if (inputList.size() > 1) { System.err.println("Too many files specified"); usage(); return; } String input = inputList.get(0); loadDexFile(input); for (ClassDef classDef: dexFile.getClasses()) { System.out.println(classDef.getType()); } } }
@Override public void run() { if (help || inputList == null || inputList.isEmpty()) { usage(); return; } if (inputList.size() > 1) { System.err.println("Too many files specified"); usage(); return; } String input = inputList.get(0); loadDexFile(input); for (ClassDef classDef: dexFile.getClasses()) { System.out.println(classDef.getType()); } } }
/** * scan base Dex,get base Dex info */ private void scanBaseDexFile() throws IOException { for (File baseDexFile : baseDexFiles) { DexBackedDexFile baseBackedDexFile = DexFileFactory.loadDexFile(baseDexFile, apiLevel, true); final Set<? extends DexBackedClassDef> baseClassDefs = baseBackedDexFile.getClasses(); dexDiffInfo.setOldClasses(baseClassDefs); for (DexBackedClassDef baseClassDef : baseClassDefs) { String className = getDalvikClassName(baseClassDef.getType()); baseClassDefMap.put(className, baseClassDef); } } }
List<? extends ClassDef> classDefs = Ordering.natural().sortedCopy(dexFile.getClasses());
@Override public void run() { if (help || inputList == null || inputList.isEmpty()) { usage(); return; } if (inputList.size() > 1) { System.err.println("Too many files specified"); usage(); return; } String input = inputList.get(0); loadDexFile(input); BaksmaliOptions options = getOptions(); try { for (ClassDef classDef: dexFile.getClasses()) { ClassProto classProto = (ClassProto) options.classPath.getClass(classDef); SparseArray<FieldReference> fields = classProto.getInstanceFields(); String className = "Class " + classDef.getType() + " : " + fields.size() + " instance fields\n"; System.out.write(className.getBytes()); for (int i=0;i<fields.size();i++) { String field = fields.keyAt(i) + ":" + fields.valueAt(i).getType() + " " + fields.valueAt(i).getName() + "\n"; System.out.write(field.getBytes()); } System.out.write("\n".getBytes()); } System.out.close(); } catch (IOException ex) { throw new RuntimeException(ex); } }
@Override public void run() { if (help || inputList == null || inputList.isEmpty()) { usage(); return; } if (inputList.size() > 1) { System.err.println("Too many files specified"); usage(); return; } String input = inputList.get(0); loadDexFile(input); BaksmaliOptions options = getOptions(); try { for (ClassDef classDef: dexFile.getClasses()) { ClassProto classProto = (ClassProto) options.classPath.getClass(classDef); SparseArray<FieldReference> fields = classProto.getInstanceFields(); String className = "Class " + classDef.getType() + " : " + fields.size() + " instance fields\n"; System.out.write(className.getBytes()); for (int i=0;i<fields.size();i++) { String field = fields.keyAt(i) + ":" + fields.valueAt(i).getType() + " " + fields.valueAt(i).getName() + "\n"; System.out.write(field.getBytes()); } System.out.write("\n".getBytes()); } System.out.close(); } catch (IOException ex) { throw new RuntimeException(ex); } }
for (ClassDef classDef : dexFile.getClasses()) { if (!AccessFlags.INTERFACE.isSet(classDef.getAccessFlags())) { listClassVtable((ClassProto)options.classPath.getClass(classDef));
for (ClassDef classDef : dexFile.getClasses()) { if (!AccessFlags.INTERFACE.isSet(classDef.getAccessFlags())) { listClassVtable((ClassProto)options.classPath.getClass(classDef));
public static Set<DexBackedClassDef> scanClasses(File smaliDir, List<File> newFiles) throws PatchException { Set<DexBackedClassDef> classes = Sets.newHashSet(); try { for (File newFile : newFiles) { DexBackedDexFile newDexFile = DexFileFactory.loadDexFile(newFile, 19, true); Set<? extends DexBackedClassDef> dexClasses = newDexFile.getClasses(); classes.addAll(dexClasses); } final ClassFileNameHandler outFileNameHandler = new ClassFileNameHandler(smaliDir, ".smali"); final ClassFileNameHandler inFileNameHandler = new ClassFileNameHandler(smaliDir, ".smali"); for (DexBackedClassDef classDef : classes) { String className = classDef.getType(); ApkPatch.currentClassType = null; AfBakSmali.disassembleClass(classDef, outFileNameHandler, getBuildOption(classes, 19), true, true); File smaliFile = inFileNameHandler.getUniqueFilenameForClass(className); } } catch (Exception e) { throw new PatchException(e); } return classes; }
for (File newDexFile : newDexFiles) { DexBackedDexFile newBackedDexFile = DexFileFactory.loadDexFile(newDexFile, apiLevel, true); newDexClassDefs.addAll(newBackedDexFile.getClasses()); dexDiffInfo.setNewClasses(newDexClassDefs);
@Test public void testAnnotationElementOrder() { // Elements are out of order wrt to the element name ImmutableSet<ImmutableAnnotationElement> elements = ImmutableSet.of(new ImmutableAnnotationElement("zabaglione", ImmutableNullEncodedValue.INSTANCE), new ImmutableAnnotationElement("blah", ImmutableNullEncodedValue.INSTANCE)); ImmutableAnnotation annotation = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lorg/test/anno;", elements); ImmutableClassDef classDef = new ImmutableClassDef("Lorg/test/blah;", 0, "Ljava/lang/Object;", null, null, ImmutableSet.of(annotation), null, null); MemoryDataStore dataStore = new MemoryDataStore(); try { DexPool.writeTo(dataStore, new ImmutableDexFile(Opcodes.getDefault(), ImmutableSet.of(classDef))); } catch (IOException ex) { throw new RuntimeException(ex); } DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer()); ClassDef dbClassDef = Iterables.getFirst(dexFile.getClasses(), null); Assert.assertNotNull(dbClassDef); Annotation dbAnnotation = Iterables.getFirst(dbClassDef.getAnnotations(), null); Assert.assertNotNull(dbAnnotation); List<AnnotationElement> dbElements = Lists.newArrayList(dbAnnotation.getElements()); // Ensure that the elements were written out in sorted order Assert.assertEquals(2, dbElements.size()); Assert.assertEquals("blah", dbElements.get(0).getName()); Assert.assertEquals("zabaglione", dbElements.get(1).getName()); }
ClassDef dbClassDef = Iterables.getFirst(dexFile.getClasses(), null); Assert.assertNotNull(dbClassDef); Annotation dbAnnotation = Iterables.getFirst(dbClassDef.getAnnotations(), null);
protected void runTest(@Nonnull String testName, @Nonnull BaksmaliOptions options) { try { DexBackedDexFile inputDex = getInputDexFile(testName, options); Assert.assertEquals(1, inputDex.getClassCount()); ClassDef inputClass = Iterables.getFirst(inputDex.getClasses(), null); Assert.assertNotNull(inputClass); String input = BaksmaliTestUtils.getNormalizedSmali(inputClass, options, true); String output = BaksmaliTestUtils.readResourceFully(getOutputFilename(testName)); output = BaksmaliTestUtils.normalizeSmali(output, true); // Run smali, baksmali, and then compare strings are equal (minus comments/whitespace) Assert.assertEquals(output, input); } catch (IOException ex) { Assert.fail(); } } }
return Iterables.getFirst(dexFile.getClasses(), null);
return Iterables.getFirst(dexFile.getClasses(), null);