org.jf.dexlib2.dexbacked.DexBackedDexFile Java Examples
The following examples show how to use
org.jf.dexlib2.dexbacked.DexBackedDexFile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeListItem.java From zjdroid with Apache License 2.0 | 6 votes |
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int typeListOffset) { if (typeListOffset == 0) { return ""; } StringBuilder sb = new StringBuilder(); int size = dexFile.readSmallUint(typeListOffset); for (int i=0; i<size; i++) { int typeIndex = dexFile.readUshort(typeListOffset + 4 + i*2); String type = dexFile.getType(typeIndex); sb.append(type); } return sb.toString(); }
Example #2
Source File: ProtoIdItem.java From HeyGirl with Apache License 2.0 | 6 votes |
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int protoIndex) { int offset = dexFile.getProtoIdItemOffset(protoIndex); StringBuilder sb = new StringBuilder(); sb.append("("); int parametersOffset = dexFile.readSmallUint(offset + PARAMETERS_OFFSET); sb.append(TypeListItem.asString(dexFile, parametersOffset)); sb.append(")"); int returnTypeIndex = dexFile.readSmallUint(offset + RETURN_TYPE_OFFSET); String returnType = dexFile.getType(returnTypeIndex); sb.append(returnType); return sb.toString(); }
Example #3
Source File: AnnotationsDirectory.java From zjdroid with Apache License 2.0 | 6 votes |
@Nonnull public static List<Set<? extends DexBackedAnnotation>> getParameterAnnotations( @Nonnull final DexBackedDexFile dexFile, final int annotationSetListOffset) { if (annotationSetListOffset > 0) { final int size = dexFile.readSmallUint(annotationSetListOffset); return new FixedSizeList<Set<? extends DexBackedAnnotation>>() { @Nonnull @Override public Set<? extends DexBackedAnnotation> readItem(int index) { int annotationSetOffset = dexFile.readSmallUint(annotationSetListOffset + 4 + index * 4); return getAnnotations(dexFile, annotationSetOffset); } @Override public int size() { return size; } }; } return ImmutableList.of(); }
Example #4
Source File: TypeListItem.java From HeyGirl with Apache License 2.0 | 6 votes |
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int typeListOffset) { if (typeListOffset == 0) { return ""; } StringBuilder sb = new StringBuilder(); int size = dexFile.readSmallUint(typeListOffset); for (int i=0; i<size; i++) { int typeIndex = dexFile.readUshort(typeListOffset + 4 + i*2); String type = dexFile.getType(typeIndex); sb.append(type); } return sb.toString(); }
Example #5
Source File: ProtoIdItem.java From zjdroid with Apache License 2.0 | 6 votes |
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int protoIndex) { int offset = dexFile.getProtoIdItemOffset(protoIndex); StringBuilder sb = new StringBuilder(); sb.append("("); int parametersOffset = dexFile.readSmallUint(offset + PARAMETERS_OFFSET); sb.append(TypeListItem.asString(dexFile, parametersOffset)); sb.append(")"); int returnTypeIndex = dexFile.readSmallUint(offset + RETURN_TYPE_OFFSET); String returnType = dexFile.getType(returnTypeIndex); sb.append(returnType); return sb.toString(); }
Example #6
Source File: TypeListItem.java From ZjDroid with Apache License 2.0 | 6 votes |
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int typeListOffset) { if (typeListOffset == 0) { return ""; } StringBuilder sb = new StringBuilder(); int size = dexFile.readSmallUint(typeListOffset); for (int i=0; i<size; i++) { int typeIndex = dexFile.readUshort(typeListOffset + 4 + i*2); String type = dexFile.getType(typeIndex); sb.append(type); } return sb.toString(); }
Example #7
Source File: SmaliDiffUtils.java From atlas with Apache License 2.0 | 6 votes |
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, Opcodes.getDefault()); 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; }
Example #8
Source File: TypeListItem.java From zjdroid with Apache License 2.0 | 5 votes |
@Nonnull public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int typeListOffset) { if (typeListOffset == 0) { return "type_list_item[NO_OFFSET]"; } try { String typeList = asString(dexFile, typeListOffset); return String.format("type_list_item[0x%x]: %s", typeListOffset, typeList); } catch (Exception ex) { ex.printStackTrace(System.err); } return String.format("type_list_item[0x%x]", typeListOffset); }
Example #9
Source File: TypeIdItem.java From zjdroid with Apache License 2.0 | 5 votes |
@Nonnull public static String getOptionalReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int typeIndex) { if (typeIndex == -1) { return "type_id_item[NO_INDEX]"; } return getReferenceAnnotation(dexFile, typeIndex); }
Example #10
Source File: SmaliUtils.java From Box with Apache License 2.0 | 5 votes |
@NotNull public static String getSmaliCode(DexNode dex, int clsDefOffset) { try { Path path = dex.getDexFile().getPath(); DexBackedDexFile dexFile = DexFileFactory.loadDexFile(path.toFile(), null); DexBackedClassDef dexBackedClassDef = new DexBackedClassDef(dexFile, clsDefOffset); return getSmaliCode(dexBackedClassDef); } catch (Exception e) { LOG.error("Error generating smali", e); return "Error generating smali code: " + e.getMessage() + '\n' + Utils.getStackTrace(e); } }
Example #11
Source File: DexBackedReference.java From ZjDroid with Apache License 2.0 | 5 votes |
public static Reference makeReference(@Nonnull DexBackedDexFile dexFile, int referenceType, int referenceIndex) { switch (referenceType) { case ReferenceType.STRING: return new DexBackedStringReference(dexFile, referenceIndex); case ReferenceType.TYPE: return new DexBackedTypeReference(dexFile, referenceIndex); case ReferenceType.METHOD: return new DexBackedMethodReference(dexFile, referenceIndex); case ReferenceType.FIELD: return new DexBackedFieldReference(dexFile, referenceIndex); default: throw new ExceptionWithContext("Invalid reference type: %d", referenceType); } }
Example #12
Source File: AnnotationsDirectory.java From zjdroid with Apache License 2.0 | 5 votes |
@Nonnull public static AnnotationsDirectory newOrEmpty(@Nonnull DexBackedDexFile dexFile, int directoryAnnotationsOffset) { if (directoryAnnotationsOffset == 0) { return EMPTY; } return new AnnotationsDirectoryImpl(dexFile, directoryAnnotationsOffset); }
Example #13
Source File: AnnotationItem.java From HeyGirl with Apache License 2.0 | 5 votes |
public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int annotationItemOffset) { try { DexReader reader = dexFile.readerAt(annotationItemOffset); reader.readUbyte(); int typeIndex = reader.readSmallUleb128(); String annotationType = dexFile.getType(typeIndex); return String.format("annotation_item[0x%x]: %s", annotationItemOffset, annotationType); } catch (Exception ex) { ex.printStackTrace(System.err); } return String.format("annotation_item[0x%x]", annotationItemOffset); }
Example #14
Source File: FieldIdItem.java From ZjDroid with Apache License 2.0 | 5 votes |
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int fieldIndex) { int fieldOffset = dexFile.getFieldIdItemOffset(fieldIndex); int classIndex = dexFile.readUshort(fieldOffset + CLASS_OFFSET); String classType = dexFile.getType(classIndex); int typeIndex = dexFile.readUshort(fieldOffset + TYPE_OFFSET); String fieldType = dexFile.getType(typeIndex); int nameIndex = dexFile.readSmallUint(fieldOffset + NAME_OFFSET); String fieldName = dexFile.getString(nameIndex); return String.format("%s->%s:%s", classType, fieldName, fieldType); }
Example #15
Source File: MethodIdItem.java From ZjDroid with Apache License 2.0 | 5 votes |
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int methodIndex) { int methodOffset = dexFile.getMethodIdItemOffset(methodIndex); int classIndex = dexFile.readUshort(methodOffset + CLASS_OFFSET); String classType = dexFile.getType(classIndex); int protoIndex = dexFile.readUshort(methodOffset + PROTO_OFFSET); String protoString = ProtoIdItem.asString(dexFile, protoIndex); int nameIndex = dexFile.readSmallUint(methodOffset + NAME_OFFSET); String methodName = dexFile.getString(nameIndex); return String.format("%s->%s%s", classType, methodName, protoString); }
Example #16
Source File: AnnotationSetRefList.java From ZjDroid with Apache License 2.0 | 5 votes |
@Nonnull public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int annotationSetRefListOffset) { if (annotationSetRefListOffset == 0) { return "annotation_set_ref_list[NO_OFFSET]"; } return String.format("annotation_set_ref_list[0x%x]", annotationSetRefListOffset); }
Example #17
Source File: DexClassProvider.java From JAADAS with GNU General Public License v3.0 | 5 votes |
/** * 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; }
Example #18
Source File: DexBackedArrayPayload.java From HeyGirl with Apache License 2.0 | 5 votes |
public DexBackedArrayPayload(@Nonnull DexBackedDexFile dexFile, int instructionStart) { super(dexFile, OPCODE, instructionStart); elementWidth = dexFile.readUshort(instructionStart + ELEMENT_WIDTH_OFFSET); elementCount = dexFile.readSmallUint(instructionStart + ELEMENT_COUNT_OFFSET); }
Example #19
Source File: TypeIdItem.java From ZjDroid with Apache License 2.0 | 5 votes |
@Nonnull public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int typeIndex) { try { String typeString = dexFile.getType(typeIndex); return String.format("type_id_item[%d]: %s", typeIndex, typeString); } catch (Exception ex) { ex.printStackTrace(System.err); } return String.format("type_id_item[%d]", typeIndex); }
Example #20
Source File: FieldIdItem.java From ZjDroid with Apache License 2.0 | 5 votes |
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int fieldIndex) { int fieldOffset = dexFile.getFieldIdItemOffset(fieldIndex); int classIndex = dexFile.readUshort(fieldOffset + CLASS_OFFSET); String classType = dexFile.getType(classIndex); int typeIndex = dexFile.readUshort(fieldOffset + TYPE_OFFSET); String fieldType = dexFile.getType(typeIndex); int nameIndex = dexFile.readSmallUint(fieldOffset + NAME_OFFSET); String fieldName = dexFile.getString(nameIndex); return String.format("%s->%s:%s", classType, fieldName, fieldType); }
Example #21
Source File: MethodIdItem.java From ZjDroid with Apache License 2.0 | 5 votes |
@Nonnull public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int methodIndex) { try { String methodString = asString(dexFile, methodIndex); return String.format("method_id_item[%d]: %s", methodIndex, methodString); } catch (Exception ex) { ex.printStackTrace(System.err); } return String.format("method_id_item[%d]", methodIndex); }
Example #22
Source File: SmaliDecoder.java From ratel with Apache License 2.0 | 5 votes |
private void decode() throws AndrolibException { try { final BaksmaliOptions options = new BaksmaliOptions(); // options options.deodex = false; options.implicitReferences = false; options.parameterRegisters = true; options.localsDirective = true; options.sequentialLabels = true; options.debugInfo = mBakDeb; options.codeOffsets = false; options.accessorComments = false; options.registerInfo = 0; options.inlineResolver = null; // set jobs automatically int jobs = Runtime.getRuntime().availableProcessors(); if (jobs > 6) { jobs = 6; } // create the dex DexBackedDexFile dexFile = DexFileFactory.loadDexEntry(mApkFile, mDexFile, true, Opcodes.forApi(mApi)); if (dexFile.isOdexFile()) { throw new AndrolibException("Warning: You are disassembling an odex file without deodexing it."); } if (dexFile instanceof DexBackedOdexFile) { options.inlineResolver = InlineMethodResolver.createInlineMethodResolver(((DexBackedOdexFile)dexFile).getOdexVersion()); } Baksmali.disassembleDexFile(dexFile, mOutDir, jobs, options); } catch (IOException ex) { throw new AndrolibException(ex); } }
Example #23
Source File: DexBackedInstruction.java From HeyGirl with Apache License 2.0 | 5 votes |
public DexBackedInstruction(@Nonnull DexBackedDexFile dexFile, @Nonnull Opcode opcode, int instructionStart) { this.dexFile = dexFile; this.opcode = opcode; this.instructionStart = instructionStart; }
Example #24
Source File: MethodIdItem.java From ZjDroid with Apache License 2.0 | 5 votes |
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int methodIndex) { int methodOffset = dexFile.getMethodIdItemOffset(methodIndex); int classIndex = dexFile.readUshort(methodOffset + CLASS_OFFSET); String classType = dexFile.getType(classIndex); int protoIndex = dexFile.readUshort(methodOffset + PROTO_OFFSET); String protoString = ProtoIdItem.asString(dexFile, protoIndex); int nameIndex = dexFile.readSmallUint(methodOffset + NAME_OFFSET); String methodName = dexFile.getString(nameIndex); return String.format("%s->%s%s", classType, methodName, protoString); }
Example #25
Source File: StringIdItem.java From ZjDroid with Apache License 2.0 | 5 votes |
public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int stringIndex, boolean quote) { try { String string = dexFile.getString(stringIndex); if (quote) { string = String.format("\"%s\"", StringUtils.escapeString(string)); } return String.format("string_id_item[%d]: %s", stringIndex, string); } catch (Exception ex) { ex.printStackTrace(System.err); } return String.format("string_id_item[%d]", stringIndex); }
Example #26
Source File: DebugInfo.java From HeyGirl with Apache License 2.0 | 5 votes |
public static DebugInfo newOrEmpty(@Nonnull DexBackedDexFile dexFile, int debugInfoOffset, @Nonnull DexBackedMethodImplementation methodImpl) { if (debugInfoOffset == 0) { return EmptyDebugInfo.INSTANCE; } return new DebugInfoImpl(dexFile, debugInfoOffset, methodImpl); }
Example #27
Source File: TypeIdItem.java From HeyGirl with Apache License 2.0 | 5 votes |
@Nonnull public static String getOptionalReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int typeIndex) { if (typeIndex == -1) { return "type_id_item[NO_INDEX]"; } return getReferenceAnnotation(dexFile, typeIndex); }
Example #28
Source File: MethodIdItem.java From zjdroid with Apache License 2.0 | 5 votes |
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int methodIndex) { int methodOffset = dexFile.getMethodIdItemOffset(methodIndex); int classIndex = dexFile.readUshort(methodOffset + CLASS_OFFSET); String classType = dexFile.getType(classIndex); int protoIndex = dexFile.readUshort(methodOffset + PROTO_OFFSET); String protoString = ProtoIdItem.asString(dexFile, protoIndex); int nameIndex = dexFile.readSmallUint(methodOffset + NAME_OFFSET); String methodName = dexFile.getString(nameIndex); return String.format("%s->%s%s", classType, methodName, protoString); }
Example #29
Source File: StringIdItem.java From HeyGirl with Apache License 2.0 | 5 votes |
public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int stringIndex, boolean quote) { try { String string = dexFile.getString(stringIndex); if (quote) { string = String.format("\"%s\"", StringUtils.escapeString(string)); } return String.format("string_id_item[%d]: %s", stringIndex, string); } catch (Exception ex) { ex.printStackTrace(System.err); } return String.format("string_id_item[%d]", stringIndex); }
Example #30
Source File: TypeListItem.java From ZjDroid with Apache License 2.0 | 5 votes |
@Nonnull public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int typeListOffset) { if (typeListOffset == 0) { return "type_list_item[NO_OFFSET]"; } try { String typeList = asString(dexFile, typeListOffset); return String.format("type_list_item[0x%x]: %s", typeListOffset, typeList); } catch (Exception ex) { ex.printStackTrace(System.err); } return String.format("type_list_item[0x%x]", typeListOffset); }