@Nonnull public static DexBackedDexFile loadDexFile(@Nonnull String path, @Nullable Opcodes opcodes) throws IOException { return loadDexFile(new File(path), opcodes); }
= DexFileFactory.loadDexContainer(dexSourceFile, Opcodes.forApi(api));
dexFile = DexFileFactory.loadDexEntry(file, dexEntry, exactMatch, opcodes); } catch (IOException ex) { throw new RuntimeException(ex); dexFile = DexFileFactory.loadDexFile(file, opcodes); } catch (IOException ex) { throw new RuntimeException(ex);
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()); obfuscateClasses.add(insTructionsReDef.reClassDef(classDef)); DexFileFactory.writeDexFile(outPutFile.getAbsolutePath(), new DexFile() { @Nonnull @Override
DexBackedDexFile dexFile = DexFileFactory.loadDexEntry(mApkFile, mDexFile, true, Opcodes.forApi(mApi));
public void writeDex(File outDexFile,Set<ClassDef>classDefs) throws IOException { DexFileFactory.writeDexFile(outDexFile.getAbsolutePath(), new DexFile() { @Nonnull @Override public Set<? extends ClassDef> getClasses() { return new AbstractSet<ClassDef>() { @Nonnull @Override public Iterator<ClassDef> iterator() { return classDefs.iterator(); } @Override public int size() { return classDefs.size(); } }; } }); }
DexFile dFile = DexFileFactory.loadDexFile(dexFile.getAbsolutePath(), 19, true); classes.addAll(dFile.getClasses()); DexFileFactory.writeDexFile(patchDexFile.getAbsolutePath(), new ImmutableDexFile(newClassDef.keySet())); } else if (patchClassDefs.size() > 0) { DexFileFactory.writeDexFile(patchDexFile.getAbsolutePath(), new ImmutableDexFile(patchClassDefs.keySet())); DexFileFactory.writeDexFile(tempDexFile.getAbsolutePath(), new DexFile() { @Nonnull @Override DexFileFactory.writeDexFile(tempDexFile.getAbsolutePath(), new ImmutableDexFile(classes)); DexFile patchDex = DexFileFactory.loadDexFile(patchDexFile.getAbsolutePath(), 19, true); DexFile tempDex = DexFileFactory.loadDexFile(tempDexFile.getAbsolutePath(), 19, true); Set<? extends ClassDef> patchClasses = patchDex.getClasses(); DexDiffInfo dexDiffInfo = new DexDiffInfo();
/** * @param f * the .oat or .apk file * @param entry * the name of the .dex file inside the container file * @param apiLevel * the api level wanted */ public DexFileModule(File f, String entry, int apiLevel) throws IllegalArgumentException { try { this.f = f; dexfile = DexFileFactory.loadDexEntry(f, entry,true, 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)); } }
public static Set<String> buildCode(File dexFile, DexDiffInfo info) throws IOException, RecognitionException { Set<String>classes = new HashSet<>(); Set<DexBackedClassDef> classDefs = new HashSet<DexBackedClassDef>(); classDefs.addAll(info.getModifiedClasses()); classDefs.addAll(info.getAddedClasses()); DexFileFactory.writeDexFile(dexFile.getAbsolutePath(), new DexFile() { @Nonnull @Override public Set<? extends ClassDef> getClasses() { return new AbstractSet<DexBackedClassDef>() { @Override public Iterator<DexBackedClassDef> iterator() { return classDefs.iterator(); } @Override public int size() { return classDefs.size(); } }; } }); for (ClassDef classDef:classDefs){ classes.add(classDef.getType()); } return classes; }
private void dotest(File dexFile) throws IOException { DexBackedDexFile dex; try { dex = DexFileFactory.loadDexFile(dexFile, 14, false); } catch (DexBackedDexFile.NotADexFile ex) { ex.printStackTrace();
public static void modifyMethod(String srcDexFile, String outDexFile, boolean isAndFix) throws IOException { DexFile dexFile = DexFileFactory.loadDexFile(srcDexFile, 15, true); DexFileFactory.writeDexFile(outDexFile, new DexFile() { @Nonnull @Override
dexFile = DexFileFactory.loadDexEntry(file, dexEntry, exactMatch, opcodes); } catch (IOException ex) { throw new RuntimeException(ex); dexFile = DexFileFactory.loadDexFile(file, opcodes); } catch (IOException ex) { throw new RuntimeException(ex);
try { MultiDexContainer<? extends DexBackedDexFile> container = DexFileFactory.loadDexContainer(file, Opcodes.getDefault()); entries = container.getDexEntryNames(); } catch (IOException ex) {
/** * @param f * the .oat or .apk file * @param entry * the name of the .dex file inside the container file * @param apiLevel * the api level wanted */ public DexFileModule(File f, String entry, int apiLevel) throws IllegalArgumentException { try { this.f = f; dexfile = DexFileFactory.loadDexEntry(f, entry,true, 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)); } }
public static void addField(String inFile, String outFile, DexBackedClassDef dexBackedClassDef, ImmutableField immutableField) throws IOException { DexFile dexFile = readDexFile(inFile); for (ClassDef classDef : dexFile.getClasses()) { if (dexBackedClassDef != null && dexBackedClassDef.getType().equals(classDef.getType())) { dexFile = addField(dexFile, classDef.getType(), immutableField); } else if (dexBackedClassDef == null) { dexFile = addField(dexFile, classDef.getType(), immutableField); } } reDexFile(dexFile); DexFileFactory.writeDexFile(outFile, new DexFile() { @Nonnull @Override public Set<? extends ClassDef> getClasses() { return new AbstractSet<ClassDef>() { @Nonnull @Override public Iterator<ClassDef> iterator() { return classes.iterator(); } @Override public int size() { return classes.size(); } }; } }); }
private static DexFile readDexFile(String fileName) throws IOException { File srcFile = new File(fileName); return DexFileFactory.loadDexFile(srcFile, 15, true); }
@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))); }
try { MultiDexContainer<? extends DexBackedDexFile> container = DexFileFactory.loadDexContainer(file, Opcodes.getDefault()); entries = container.getDexEntryNames(); } catch (IOException ex) {
@Nonnull public static DexBackedDexFile loadSingleDex(@Nonnull File file, @Nullable Opcodes opc) throws IOException { return DexFileFactory.loadDexFile(file, opc); }
container = DexFileFactory.loadDexContainer(entryFile, opcodes); } catch (DexFileFactory.UnsupportedFileTypeException ex) { throw new ClassPathResolver.ResolveException(ex);