/** * Writes the <code>EncodedField</code> to the given <code>AnnotatedOutput</code> object * * @param out the <code>AnnotatedOutput</code> object to write to * @param previousEncodedField The previous <code>EncodedField</code> in the list containing * this <code>EncodedField</code>. */ private void writeTo(AnnotatedOutput out, EncodedField previousEncodedField) { int previousIndex = previousEncodedField == null ? 0 : previousEncodedField.field.getIndex(); if (out.annotates()) { out.annotate("field: " + field.getFieldString()); out.writeUnsignedLeb128(field.getIndex() - previousIndex); out.annotate("access_flags: " + AccessFlags.formatAccessFlagsForField(accessFlags)); out.writeUnsignedLeb128(accessFlags); } else { out.writeUnsignedLeb128(field.getIndex() - previousIndex); out.writeUnsignedLeb128(accessFlags); } }
protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) { if (getReferencedItem().getIndex() > 0xFFFF) { if (opcode.hasJumboOpcode()) { throw new RuntimeException( String.format( "%s index is too large. Use the %s instruction instead.", opcode.referenceType.name(), opcode.getJumboOpcode().name)); } else { throw new RuntimeException( String.format("%s index is too large.", opcode.referenceType.name())); } } if (TrapPicker.trapMap.containsKey(getReferencedItem().getConciseIdentity())) { out.writeByte(opcode.value); out.writeByte((regB << 4) | regA); out.writeShort( TrapPicker.trapMap.get(getReferencedItem().getConciseIdentity()).getObfascatorNum()); } else { out.writeByte(opcode.value); out.writeByte((regB << 4) | regA); out.writeShort(getReferencedItem().getIndex()); } }
/** * Writes the <code>EncodedMethod</code> to the given <code>AnnotatedOutput</code> object * * @param out the <code>AnnotatedOutput</code> object to write to * @param previousEncodedMethod The previous <code>EncodedMethod</code> in the list containing * this <code>EncodedMethod</code>. */ private void writeTo(AnnotatedOutput out, EncodedMethod previousEncodedMethod) { int previousIndex = previousEncodedMethod == null ? 0 : previousEncodedMethod.method.getIndex(); if (out.annotates()) { out.annotate("method: " + method.getMethodString()); out.writeUnsignedLeb128(method.getIndex() - previousIndex); out.annotate("access_flags: " + AccessFlags.formatAccessFlagsForMethod(accessFlags)); out.writeUnsignedLeb128(accessFlags); if (codeItem != null) { out.annotate("code_off: 0x" + Integer.toHexString(codeItem.getOffset())); out.writeUnsignedLeb128(codeItem.getOffset()); } else { out.annotate("code_off: 0x0"); out.writeUnsignedLeb128(0); } } else { out.writeUnsignedLeb128(method.getIndex() - previousIndex); out.writeUnsignedLeb128(accessFlags); out.writeUnsignedLeb128(codeItem == null ? 0 : codeItem.getOffset()); } }
/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { if (out.annotates()) { out.annotate( "static_fields_size: 0x" + Integer.toHexString(staticFields.length) + " (" + staticFields.length + ")"); out.writeUnsignedLeb128(staticFields.length); out.annotate( "instance_fields_size: 0x" + Integer.toHexString(instanceFields.length) + " (" + instanceFields.length + ")"); out.writeUnsignedLeb128(instanceFields.length); out.annotate( "direct_methods_size: 0x" + Integer.toHexString(directMethods.length) + " (" + directMethods.length + ")"); out.writeUnsignedLeb128(directMethods.length); out.annotate( "virtual_methods_size: 0x" + Integer.toHexString(virtualMethods.length) + " (" + virtualMethods.length + ")"); out.writeUnsignedLeb128(virtualMethods.length); EncodedField[] staticFields = this.staticFields; int index = 0; EncodedField previousEncodedField = null; for (EncodedField encodedField : staticFields) { out.annotate("[" + index++ + "] static_field"); out.indent(); encodedField.writeTo(out, previousEncodedField); out.deindent(); previousEncodedField = encodedField; } EncodedField[] instanceFields = this.instanceFields; index = 0; previousEncodedField = null; for (EncodedField encodedField : instanceFields) { out.annotate("[" + index++ + "] instance_field"); out.indent(); encodedField.writeTo(out, previousEncodedField); out.deindent(); previousEncodedField = encodedField; } EncodedMethod[] directMethods = this.directMethods; index = 0; EncodedMethod previousEncodedMethod = null; for (EncodedMethod encodedMethod : directMethods) { out.annotate("[" + index++ + "] direct_method"); out.indent(); encodedMethod.writeTo(out, previousEncodedMethod); out.deindent(); previousEncodedMethod = encodedMethod; } EncodedMethod[] virtualMethods = this.virtualMethods; index = 0; previousEncodedMethod = null; for (EncodedMethod encodedMethod : virtualMethods) { out.annotate("[" + index++ + "] virtual_method"); out.indent(); encodedMethod.writeTo(out, previousEncodedMethod); out.deindent(); previousEncodedMethod = encodedMethod; } } else { out.writeUnsignedLeb128(staticFields.length); out.writeUnsignedLeb128(instanceFields.length); out.writeUnsignedLeb128(directMethods.length); out.writeUnsignedLeb128(virtualMethods.length); EncodedField[] staticFields = this.staticFields; EncodedField previousEncodedField = null; for (EncodedField encodedField : staticFields) { encodedField.writeTo(out, previousEncodedField); previousEncodedField = encodedField; } EncodedField[] instanceFields = this.instanceFields; previousEncodedField = null; for (EncodedField encodedField : instanceFields) { encodedField.writeTo(out, previousEncodedField); previousEncodedField = encodedField; } EncodedMethod[] directMethods = this.directMethods; EncodedMethod previousEncodedMethod = null; for (EncodedMethod encodedMethod : directMethods) { encodedMethod.writeTo(out, previousEncodedMethod); previousEncodedMethod = encodedMethod; } EncodedMethod[] virtualMethods = this.virtualMethods; previousEncodedMethod = null; for (EncodedMethod encodedMethod : virtualMethods) { encodedMethod.writeTo(out, previousEncodedMethod); previousEncodedMethod = encodedMethod; } } }
/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { if (out.annotates()) { TypeIdItem parentType = getParentType(); if (parentType != null) { out.annotate(0, parentType.getTypeDescriptor()); } if (classAnnotations != null) { out.annotate( 4, "class_annotations_off: 0x" + Integer.toHexString(classAnnotations.getOffset())); } else { out.annotate(4, "class_annotations_off:"); } int length = fieldAnnotations == null ? 0 : fieldAnnotations.length; out.annotate( 4, "annotated_fields_size: 0x" + Integer.toHexString(length) + " (" + length + ")"); length = methodAnnotations == null ? 0 : methodAnnotations.length; out.annotate( 4, "annotated_methods_size: 0x" + Integer.toHexString(length) + " (" + length + ")"); length = parameterAnnotations == null ? 0 : parameterAnnotations.length; out.annotate( 4, "annotated_parameters_size: 0x" + Integer.toHexString(length) + " (" + length + ")"); int index; if (fieldAnnotations != null) { index = 0; for (FieldAnnotation fieldAnnotation : fieldAnnotations) { out.annotate(0, "[" + index++ + "] field_annotation"); out.indent(); out.annotate( 4, "field: " + fieldAnnotation.field.getFieldName().getStringValue() + ":" + fieldAnnotation.field.getFieldType().getTypeDescriptor()); out.annotate( 4, "annotations_off: 0x" + Integer.toHexString(fieldAnnotation.annotationSet.getOffset())); out.deindent(); } } if (methodAnnotations != null) { index = 0; for (MethodAnnotation methodAnnotation : methodAnnotations) { out.annotate(0, "[" + index++ + "] method_annotation"); out.indent(); out.annotate(4, "method: " + methodAnnotation.method.getMethodString()); out.annotate( 4, "annotations_off: 0x" + Integer.toHexString(methodAnnotation.annotationSet.getOffset())); out.deindent(); } } if (parameterAnnotations != null) { index = 0; for (ParameterAnnotation parameterAnnotation : parameterAnnotations) { out.annotate(0, "[" + index++ + "] parameter_annotation"); out.indent(); out.annotate(4, "method: " + parameterAnnotation.method.getMethodString()); out.annotate( 4, "annotations_off: 0x" + Integer.toHexString(parameterAnnotation.annotationSet.getOffset())); } } } out.writeInt(classAnnotations == null ? 0 : classAnnotations.getOffset()); out.writeInt(fieldAnnotations == null ? 0 : fieldAnnotations.length); out.writeInt(methodAnnotations == null ? 0 : methodAnnotations.length); out.writeInt(parameterAnnotations == null ? 0 : parameterAnnotations.length); if (fieldAnnotations != null) { for (FieldAnnotation fieldAnnotation : fieldAnnotations) { out.writeInt(fieldAnnotation.field.getIndex()); out.writeInt(fieldAnnotation.annotationSet.getOffset()); } } if (methodAnnotations != null) { for (MethodAnnotation methodAnnotation : methodAnnotations) { out.writeInt(methodAnnotation.method.getIndex()); out.writeInt(methodAnnotation.annotationSet.getOffset()); } } if (parameterAnnotations != null) { for (ParameterAnnotation parameterAnnotation : parameterAnnotations) { out.writeInt(parameterAnnotation.method.getIndex()); out.writeInt(parameterAnnotation.annotationSet.getOffset()); } } }