/** {@inheritDoc} */ public String getConciseIdentity() { return "class_def_item: " + classType.getTypeDescriptor(); }
/** {@inheritDoc} */ public String getConciseIdentity() { return "type_id_item: " + getTypeDescriptor(); }
/** * Returns the "shorty" representation of this type, used to create the shorty prototype string for a method * @return the "shorty" representation of this type, used to create the shorty prototype string for a method */ public String toShorty() { String type = getTypeDescriptor(); if (type.length() > 1) { return "L"; } else { return type; } }
public ClassDefItem getClassDefByType(TypeIdItem typeIdItem) { return definedClasses.get(typeIdItem.getTypeDescriptor()); } }
/** * Calculates the number of 2-byte registers that an instance of this type requires * @return The number of 2-byte registers that an instance of this type requires */ public int getRegisterCount() { String type = this.getTypeDescriptor(); /** Only the long and double primitive types are 2 words, * everything else is a single word */ if (type.charAt(0) == 'J' || type.charAt(0) == 'D') { return 2; } else { return 1; } }
public Instruction41c(Opcode opcode, int regA, Item referencedItem) { super(opcode, referencedItem); if (regA >= 1 << 16) { throw new RuntimeException("The register number must be less than v65536"); } if (opcode == Opcode.NEW_INSTANCE_JUMBO) { assert referencedItem instanceof TypeIdItem; if (((TypeIdItem)referencedItem).getTypeDescriptor().charAt(0) != 'L') { throw new RuntimeException("Only class references can be used with the new-instance/jumbo opcode"); } } this.regA = (short)regA; }
public Instruction21c(Opcode opcode, short regA, Item referencedItem) { super(opcode, referencedItem); if (regA >= 1 << 8) { throw new RuntimeException("The register number must be less than v256"); } if (opcode == Opcode.NEW_INSTANCE) { assert referencedItem instanceof TypeIdItem; if (((TypeIdItem)referencedItem).getTypeDescriptor().charAt(0) != 'L') { throw new RuntimeException("Only class references can be used with the new-instance opcode"); } } this.regA = (byte)regA; }
private Instruction21c(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) { super(dexFile, opcode, buffer, bufferIndex); if (opcode == Opcode.NEW_INSTANCE && ((TypeIdItem)this.getReferencedItem()).getTypeDescriptor().charAt(0) != 'L') { throw new RuntimeException("Only class references can be used with the new-instance opcode"); } this.regA = buffer[bufferIndex + 1]; }
public static ClassDef getClassDef(TypeIdItem classType, boolean creatUnresolvedClassDef) { return getClassDef(classType.getTypeDescriptor(), creatUnresolvedClassDef); }
public static ClassDef getClassDef(TypeIdItem classType) { return getClassDef(classType.getTypeDescriptor()); }
public static RegisterType getRegisterTypeForTypeIdItem(TypeIdItem typeIdItem) { return getRegisterTypeForType(typeIdItem.getTypeDescriptor()); }
private void verifyReturnVoid(AnalyzedInstruction analyzedInstruction) { TypeIdItem returnType = encodedMethod.method.getPrototype().getReturnType(); if (returnType.getTypeDescriptor().charAt(0) != 'V') { //TODO: could add which return-* variation should be used instead throw new ValidationException("Cannot use return-void with a non-void return type (" + returnType.getTypeDescriptor() + ")"); } }
private Instruction41c(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) { super(dexFile, opcode, buffer, bufferIndex); if (opcode == Opcode.NEW_INSTANCE_JUMBO && ((TypeIdItem)this.getReferencedItem()).getTypeDescriptor().charAt(0) != 'L') { throw new RuntimeException("Only class references can be used with the new-instance/jumbo opcode"); } this.regA = (short)NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 6); }
private String[] loadInterfaces(ClassDefItem classDefItem) { TypeListItem typeList = classDefItem.getInterfaces(); if (typeList != null) { List<TypeIdItem> types = typeList.getTypes(); if (types != null && types.size() > 0) { String[] interfaces = new String[types.size()]; for (int i=0; i<interfaces.length; i++) { interfaces[i] = types.get(i).getTypeDescriptor(); } return interfaces; } } return null; }
public DexFileClassMap(DexFile dexFile) { for (ClassDefItem classDefItem: dexFile.ClassDefsSection.getItems()) { definedClasses.put(classDefItem.getClassType().getTypeDescriptor(), classDefItem); } }
public void loadDexFile(String dexFilePath, DexFile dexFile) { for (ClassDefItem classDefItem: dexFile.ClassDefsSection.getItems()) { try { //TODO: need to check if the class already exists. (and if so, what to do about it?) TempClassInfo tempClassInfo = new TempClassInfo(dexFilePath, classDefItem); tempClasses.put(tempClassInfo.classType, tempClassInfo); } catch (Exception ex) { throw ExceptionWithContext.withContext(ex, String.format("Error while loading class %s", classDefItem.getClassType().getTypeDescriptor())); } } }
private String[][] loadInstanceFields(ClassDataItem classDataItem) { EncodedField[] encodedFields = classDataItem.getInstanceFields(); if (encodedFields != null && encodedFields.length > 0) { String[][] instanceFields = new String[encodedFields.length][2]; for (int i=0; i<encodedFields.length; i++) { EncodedField encodedField = encodedFields[i]; instanceFields[i][0] = encodedField.field.getFieldName().getStringValue(); instanceFields[i][1] = encodedField.field.getFieldType().getTypeDescriptor(); } return instanceFields; } return null; } }
/** * Writes the <code>EncodedTypeAddrPair</code> to the given <code>AnnotatedOutput</code> object * @param out the <code>AnnotatedOutput</code> object to write to */ private void writeTo(AnnotatedOutput out) { if (out.annotates()) { out.annotate("exception_type: " + exceptionType.getTypeDescriptor()); out.writeUnsignedLeb128(exceptionType.getIndex()); out.annotate("handler_addr: 0x" + Integer.toHexString(handlerAddress)); out.writeUnsignedLeb128(handlerAddress); } else { out.writeUnsignedLeb128(exceptionType.getIndex()); out.writeUnsignedLeb128(handlerAddress); } }
/** {@inheritDoc} */ public void writeValue(AnnotatedOutput out) { byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value.getIndex()); if (out.annotates()) { out.annotate(1, "value_type=" + ValueType.VALUE_TYPE.name() + ",value_arg=" + (bytes.length - 1)); out.annotate(bytes.length, "value: " + value.getTypeDescriptor()); } out.writeByte(ValueType.VALUE_TYPE.value | ((bytes.length - 1) << 5)); out.write(bytes); }
/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { if (out.annotates()) { out.annotate(4, "shorty_descriptor: " + shortyDescriptor.getStringValue()); out.annotate(4, "return_type: " + returnType.getTypeDescriptor()); if (parameters == null) { out.annotate(4, "parameters:"); } else { out.annotate(4, "parameters: " + parameters.getTypeListString("")); } } out.writeInt(shortyDescriptor.getIndex()); out.writeInt(returnType.getIndex()); out.writeInt(parameters == null?0:parameters.getOffset()); }