@Nonnull public static DexBackedDexFile loadDexFile(@Nonnull String path, @Nullable Opcodes opcodes) throws IOException { return loadDexFile(new File(path), opcodes); }
dexFile = DexFileFactory.loadDexFile(file, opcodes); } catch (IOException ex) { throw new RuntimeException(ex);
private void dotest(File dexFile) throws IOException { DexBackedDexFile dex; try { dex = DexFileFactory.loadDexFile(dexFile, 14, false); } catch (DexBackedDexFile.NotADexFile ex) { ex.printStackTrace();
private static DexFile readDexFile(String fileName) throws IOException { File srcFile = new File(fileName); return DexFileFactory.loadDexFile(srcFile, 15, true); }
@Nonnull public static DexBackedDexFile loadSingleDex(@Nonnull File file, @Nullable Opcodes opc) throws IOException { return DexFileFactory.loadDexFile(file, opc); }
@Nonnull public static DexBackedDexFile loadDexFile(@Nonnull String path, @Nullable Opcodes opcodes) throws IOException { return loadDexFile(new File(path), opcodes); }
public DexReader(List<File>files) throws IOException { for (File file:files){ DexFile dexFile =DexFileFactory.loadDexFile(file,19,true); classDefs.addAll(dexFile.getClasses()); } }
public DexReader(File file) throws IOException { if (file.exists()){ org.jf.dexlib2.iface.DexFile dexFile = DexFileFactory.loadDexFile(file,19,true); this.classDefs = dexFile.getClasses(); } } public DexReader(List<File>files) throws IOException {
@Nonnull public static DexBackedDexFile loadDexFile(String path, int api) throws IOException { return loadDexFile(new File(path), new Opcodes(api)); }
@Nonnull public static DexBackedDexFile loadDexFile(File dexFile, int api) throws IOException { return loadDexFile(dexFile, new Opcodes(api)); }
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; }
/** * @param f * the .dex or .apk file */ private DexFileModule(File f, int apiLevel) throws IllegalArgumentException { try { this.f = f; dexfile = DexFileFactory.loadDexFile(f, apiLevel == AUTO_INFER_API_LEVEL? null : Opcodes.forApi(apiLevel)); } catch (IOException e) { throw new IllegalArgumentException(e); } // create ModuleEntries from ClassDefItem entries = new HashSet<>(); for (ClassDef cdefitems : dexfile.getClasses()) { entries.add(new DexModuleEntry(cdefitems, this)); } }
/** * @param f * the .dex or .apk file */ private DexFileModule(File f, int apiLevel) throws IllegalArgumentException { try { this.f = f; dexfile = DexFileFactory.loadDexFile(f, apiLevel == AUTO_INFER_API_LEVEL? null : Opcodes.forApi(apiLevel)); } catch (IOException e) { throw new IllegalArgumentException(e); } // create ModuleEntries from ClassDefItem entries = new HashSet<>(); for (ClassDef cdefitems : dexfile.getClasses()) { entries.add(new DexModuleEntry(cdefitems, this)); } }
/** * 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); } } }
dexFile = DexFileFactory.loadDexFile(dexFileFile, 15); } catch(org.jf.util.ExceptionWithContext e) { System.err.println(e);
mappingProcessor.updateFieldType(); InsTructionsReIClassDef insTructionsReDef = new InsTructionsReIClassDef(new MappingClassProcessor(mappingProcessor)); DexFile dFile = DexFileFactory.loadDexFile(inputFile.getAbsolutePath(), 19, true); Set<ClassDef> classes = new HashSet<ClassDef>(); classes.addAll(dFile.getClasses());
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; }
public void runTest(String test, boolean registerInfo, boolean isArt) throws IOException, URISyntaxException { String dexFilePath = String.format("%s%sclasses.dex", test, File.separatorChar); DexFile dexFile = DexFileFactory.loadDexFile(findResource(dexFilePath), Opcodes.getDefault()); BaksmaliOptions options = new BaksmaliOptions(); if (registerInfo) { options.registerInfo = BaksmaliOptions.ALL | BaksmaliOptions.FULLMERGE; if (isArt) { options.classPath = new ClassPath(new ArrayList<ClassProvider>(), true, 56); } else { options.classPath = new ClassPath(); } } options.implicitReferences = false; for (ClassDef classDef: dexFile.getClasses()) { StringWriter stringWriter = new StringWriter(); IndentingWriter writer = new IndentingWriter(stringWriter); ClassDefinition classDefinition = new ClassDefinition(options, classDef); classDefinition.writeTo(writer); writer.close(); String className = classDef.getType(); String smaliPath = String.format("%s%s%s.smali", test, File.separatorChar, className.substring(1, className.length() - 1)); String smaliContents = readResource(smaliPath); Assert.assertEquals(BaksmaliTestUtils.normalizeWhitespace(smaliContents), BaksmaliTestUtils.normalizeWhitespace((stringWriter.toString()))); } }
@Test public void testBuilderCallSite() throws IOException { DexBuilder dexBuilder = new DexBuilder(Opcodes.forArtVersion(111)); BuilderCallSiteReference callSite = dexBuilder.internCallSite(new ImmutableCallSiteReference("call_site_1", new ImmutableMethodHandleReference( MethodHandleType.INVOKE_STATIC, new ImmutableMethodReference("Lcls1", "loader", ImmutableList.of("Ljava/lang/invoke/Lookup;", "Ljava/lang/String;", "Ljava/lang/invoke/MethodType;"), "Ljava/lang/invoke/CallSite;")), "someMethod", new ImmutableMethodProtoReference(ImmutableList.of(), "V"), ImmutableList.of())); MethodImplementationBuilder methodImplementationBuilder = new MethodImplementationBuilder(10); methodImplementationBuilder.addInstruction(new BuilderInstruction35c(Opcode.INVOKE_CUSTOM, 0, 0, 0, 0, 0, 0, callSite)); BuilderMethod method = dexBuilder.internMethod("Lcls1", "method1", null, "V", 0, ImmutableSet.of(), methodImplementationBuilder.getMethodImplementation()); dexBuilder.internClassDef("Lcls1;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, ImmutableSet.of(), null, ImmutableList.of(method)); File tempFile = File.createTempFile("dex", ".dex"); dexBuilder.writeTo(new FileDataStore(tempFile)); verifyDexFile(DexFileFactory.loadDexFile(tempFile, Opcodes.forArtVersion(111))); }
@Test public void testPoolCallSite() throws IOException { ClassDef class1 = new ImmutableClassDef("Lcls1;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, null, null, Lists.<Method>newArrayList( new ImmutableMethod("Lcls1", "method1", ImmutableList.of(), "V", AccessFlags.PUBLIC.getValue(), null, new ImmutableMethodImplementation(10, ImmutableList.of( new ImmutableInstruction35c(Opcode.INVOKE_CUSTOM, 0, 0, 0, 0, 0, 0, new ImmutableCallSiteReference("call_site_1", new ImmutableMethodHandleReference(MethodHandleType.INVOKE_STATIC, new ImmutableMethodReference("Lcls1", "loader", ImmutableList.of("Ljava/lang/invoke/Lookup;", "Ljava/lang/String;", "Ljava/lang/invoke/MethodType;"), "Ljava/lang/invoke/CallSite;")), "someMethod", new ImmutableMethodProtoReference(ImmutableList.of(), "V"), ImmutableList.of())) ), null, null)))); File tempFile = File.createTempFile("dex", ".dex"); DexFileFactory.writeDexFile(tempFile.getPath(), new ImmutableDexFile(Opcodes.forArtVersion(111), ImmutableList.of(class1))); verifyDexFile(DexFileFactory.loadDexFile(tempFile, Opcodes.forArtVersion(111))); }