本文整理汇总了Java中org.jf.dexlib2.DexFileFactory类的典型用法代码示例。如果您正苦于以下问题:Java DexFileFactory类的具体用法?Java DexFileFactory怎么用?Java DexFileFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DexFileFactory类属于org.jf.dexlib2包,在下文中一共展示了DexFileFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scanClasses
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
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;
}
示例2: writeDex
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
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();
}
};
}
});
}
示例3: test1
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
public static void test1(String argv[]){
try{
DexBackedDexFile dexFile = DexFileFactory.loadDexFile(search_path, 16);
for (ClassDef classDef: dexFile.getClasses()){
if (classDef.getType().startsWith("Landroid") ||
classDef.getType().startsWith("Ljava") ||
classDef.getType().startsWith("Ldalvik")) {
continue;
}
for (Method method: classDef.getMethods()){
// if (method.getDefiningClass().equals("Lcom/cc/test/MainActivity;")
// && method.getName().equals("onCreate")){
if (method.getImplementation() == null)
continue;
Grapher grapher = new Grapher(method.getImplementation());
grapher.visitConstant();
grapher.search();
// grapher.printInfo();
// }
}
}
MethodConfig.printInfo();
} catch (Exception e){
e.printStackTrace();
}
}
示例4: customize
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
void customize() throws IOException {
nRedirected = nRemoved = nNotRedirected = 0;
final List<ClassDef> classes;
if (customClasses != null)
classes = new ArrayList<>(customClasses);
else
classes = new ArrayList<>();
DexFile dexFile = DexFileFactory.loadDexFile(inputFile, 19, false);
for (ClassDef classDef : dexFile.getClasses())
classes.add(customizeClass(classDef));
if (!onlyAdsRemoving) {
if (nNotRedirected == 0)
out.printf(IOutput.Level.VERBOSE,
"Removed %d invocation(s) and redirected %d (no NOT redirected)\n",
nRemoved,
nRedirected);
else
out.printf(IOutput.Level.ERROR,
"Removed %d invocation(s), redirected %d, NOT redirected %d\n",
nRemoved,
nRedirected,
nNotRedirected);
}
writeDexFile(classes);
}
示例5: decode
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
private void decode() throws AndrolibException {
try {
baksmaliOptions options = new baksmaliOptions();
options.useImplicitReferences = true;
DexBackedDexFile dexFile = DexFileFactory.loadDexFile(mApkFile, options.apiLevel, false);
baksmali.disassembleDexFile(dexFile, options);
//ojo
/*baksmali.disassembleDexFile(mApkFile.getAbsolutePath(),
new DexFile(mApkFile), false, mOutDir.getAbsolutePath(),
null, null, null, false, true, true, mBakDeb, false, false,
0, false, false, null, false);*/
} catch (IOException ex) {
throw new AndrolibException(ex);
}
}
示例6: scanBaseDexFile
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
/**
* 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);
}
}
}
示例7: buildCode
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
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;
}
示例8: addField
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
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();
}
};
}
});
}
示例9: getBundleClassDef
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
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;
}
示例10: run
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
public Observable<File> run(App app, File outputDir) {
return Observable.fromCallable(() -> {
File apkFile = new File(app.sourceDir());
check(apkFile.exists(), "must provide valid .apk file for analysis");
if (!outputDir.exists()) {
check(outputDir.mkdirs(), "could not create .smali output directory");
}
baksmaliOptions options = getDefaultOptions();
options.outputDirectory = outputDir.getPath();
// Limit the max. used threads.
options.jobs = Runtime.getRuntime().availableProcessors();
if (options.jobs > 6) {
options.jobs = 6;
}
DexBackedDexFile dexFile =
DexFileFactory.loadDexFile(apkFile, "classes.dex", app.targetSdk(), false);
if (dexFile instanceof DexBackedOdexFile) {
options.inlineResolver = InlineMethodResolver.createInlineMethodResolver(
((DexBackedOdexFile) dexFile).getOdexVersion());
}
check(baksmali.disassembleDexFile(dexFile, options), "disassembling apk to smali failed");
return outputDir;
});
}
示例11: loadDex
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
public boolean loadDex(String absfilename) {
try {
dexfile = DexFileFactory.loadDexFile(absfilename, API);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
示例12: initialize
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
public void initialize() {
try {
int api = 1; // TODO:
this.dexFile = DexFileFactory.loadDexFile(inputDexFile, api, false);
} catch (Exception e) {
throw new RuntimeException(e.toString());
}
if (dexFile instanceof DexBackedDexFile) {
DexBackedDexFile dbdf = (DexBackedDexFile)dexFile;
for (int i = 0; i < dbdf.getTypeCount(); i++) {
String t = dbdf.getType(i);
Type st = DexType.toSoot(t);
if (st instanceof ArrayType) {
st = ((ArrayType) st).baseType;
}
Debug.printDbg("Type: ", t ," soot type:", st);
String sootTypeName = st.toString();
if (!Scene.v().containsClass(sootTypeName)) {
if (st instanceof PrimType || st instanceof VoidType || systemAnnotationNames.contains(sootTypeName)) {
// dex files contain references to the Type IDs of void / primitive types - we obviously do not want them to be resolved
/*
* dex files contain references to the Type IDs of the system annotations.
* They are only visible to the Dalvik VM (for reflection, see vm/reflect/Annotations.cpp), and not to
* the user - so we do not want them to be resolved.
*/
continue;
}
SootResolver.v().makeClassRef(sootTypeName);
}
SootResolver.v().resolveClass(sootTypeName, SootClass.SIGNATURES);
}
} else {
System.out.println("Warning: DexFile not instance of DexBackedDexFile! Not resolving types!");
System.out.println("type: "+ dexFile.getClass());
}
}
示例13: classesOfDex
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
/**
* Return names of classes in dex/apk file.
*
* @param file
* file to dex/apk file. Can be the path of a zip file.
*
* @return set of class names
*/
public static Set<String> classesOfDex(File file) throws IOException {
Set<String> classes = new HashSet<String>();
// TODO (SA): Go for API 1 because DexlibWrapper does so, but needs more attention
DexBackedDexFile d = DexFileFactory.loadDexFile(file, 1, false);
for (ClassDef c : d.getClasses()) {
String name = Util.dottedClassName(c.getType());
classes.add(name);
}
return classes;
}
示例14: getDexClasses
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
private Set<String> getDexClasses()
{
Set<String> dexClasses = new HashSet<String>();
try {
DexFile dexFile = DexFileFactory.loadDexFile(new File(apk.getAbsolutePath()), targetSdkVersion());
for (ClassDef classDef: dexFile.getClasses())
{
String cls = classDef.getType();
if (cls.contains("$"))
{
//do not consider sub-classes
continue;
}
cls = cls.replace("/", ".").substring(1, cls.length()-1);
dexClasses.add(cls);
}
}
catch (IOException e)
{
e.printStackTrace();
}
return dexClasses;
}
示例15: MergeDex
import org.jf.dexlib2.DexFileFactory; //导入依赖的package包/类
public MergeDex(Configure configure, String addpath) throws IOException{
this.config = configure;
this.add_path = addpath;
if (configure.hasModifed) {
dexfile = DexFileFactory.loadDexFile(configure.outPath, configure.API_LEVEL);
}else{
dexfile = DexFileFactory.loadDexFile(configure.inPath, configure.API_LEVEL);
}
}