Java Code Examples for org.jf.util.IndentingWriter#indent()
The following examples show how to use
org.jf.util.IndentingWriter#indent() .
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: ArrayEncodedValueAdaptor.java From atlas with Apache License 2.0 | 6 votes |
public static void writeTo(@Nonnull IndentingWriter writer, @Nonnull ArrayEncodedValue arrayEncodedValue, @Nullable String containingClass) throws IOException { writer.write('{'); Collection<? extends EncodedValue> values = arrayEncodedValue.getValue(); if (values.size() == 0) { writer.write('}'); return; } writer.write('\n'); writer.indent(4); boolean first = true; for (EncodedValue encodedValue: values) { if (!first) { writer.write(",\n"); } first = false; EncodedValueAdaptor.writeTo(writer, encodedValue, containingClass); } writer.deindent(4); writer.write("\n}"); }
Example 2
Source File: MethodDefinition.java From zjdroid with Apache License 2.0 | 6 votes |
public static void writeEmptyMethodTo(IndentingWriter writer, Method method, baksmaliOptions options) throws IOException { writer.write(".method "); writeAccessFlags(writer, method.getAccessFlags()); writer.write(method.getName()); writer.write("("); ImmutableList<MethodParameter> methodParameters = ImmutableList.copyOf(method.getParameters()); for (MethodParameter parameter: methodParameters) { writer.write(parameter.getType()); } writer.write(")"); writer.write(method.getReturnType()); writer.write('\n'); writer.indent(4); writeParameters(writer, method, methodParameters, options); AnnotationFormatter.writeTo(writer, method.getAnnotations()); writer.deindent(4); writer.write(".end method\n"); }
Example 3
Source File: ArrayEncodedValueAdaptor.java From zjdroid with Apache License 2.0 | 6 votes |
public static void writeTo(IndentingWriter writer, ArrayEncodedValue arrayEncodedValue) throws IOException { writer.write('{'); Collection<? extends EncodedValue> values = arrayEncodedValue.getValue(); if (values.size() == 0) { writer.write('}'); return; } writer.write('\n'); writer.indent(4); boolean first = true; for (EncodedValue encodedValue: values) { if (!first) { writer.write(",\n"); } first = false; EncodedValueAdaptor.writeTo(writer, encodedValue); } writer.deindent(4); writer.write("\n}"); }
Example 4
Source File: MethodDefinition.java From ZjDroid with Apache License 2.0 | 6 votes |
public static void writeEmptyMethodTo(IndentingWriter writer, Method method, baksmaliOptions options) throws IOException { writer.write(".method "); writeAccessFlags(writer, method.getAccessFlags()); writer.write(method.getName()); writer.write("("); ImmutableList<MethodParameter> methodParameters = ImmutableList.copyOf(method.getParameters()); for (MethodParameter parameter: methodParameters) { writer.write(parameter.getType()); } writer.write(")"); writer.write(method.getReturnType()); writer.write('\n'); writer.indent(4); writeParameters(writer, method, methodParameters, options); AnnotationFormatter.writeTo(writer, method.getAnnotations()); writer.deindent(4); writer.write(".end method\n"); }
Example 5
Source File: MethodDefinition.java From HeyGirl with Apache License 2.0 | 6 votes |
public static void writeEmptyMethodTo(IndentingWriter writer, Method method, baksmaliOptions options) throws IOException { writer.write(".method "); writeAccessFlags(writer, method.getAccessFlags()); writer.write(method.getName()); writer.write("("); ImmutableList<MethodParameter> methodParameters = ImmutableList.copyOf(method.getParameters()); for (MethodParameter parameter: methodParameters) { writer.write(parameter.getType()); } writer.write(")"); writer.write(method.getReturnType()); writer.write('\n'); writer.indent(4); writeParameters(writer, method, methodParameters, options); AnnotationFormatter.writeTo(writer, method.getAnnotations()); writer.deindent(4); writer.write(".end method\n"); }
Example 6
Source File: PackedSwitchMethodItem.java From zjdroid with Apache License 2.0 | 6 votes |
@Override public boolean writeTo(IndentingWriter writer) throws IOException { writer.write(".packed-switch "); IntegerRenderer.writeTo(writer, firstKey); writer.indent(4); writer.write('\n'); int key = firstKey; for (PackedSwitchTarget target: targets) { target.writeTargetTo(writer); writeResourceId(writer, key); writer.write('\n'); key++; } writer.deindent(4); writer.write(".end packed-switch"); return true; }
Example 7
Source File: PackedSwitchMethodItem.java From ZjDroid with Apache License 2.0 | 6 votes |
@Override public boolean writeTo(IndentingWriter writer) throws IOException { writer.write(".packed-switch "); IntegerRenderer.writeTo(writer, firstKey); writer.indent(4); writer.write('\n'); int key = firstKey; for (PackedSwitchTarget target: targets) { target.writeTargetTo(writer); writeResourceId(writer, key); writer.write('\n'); key++; } writer.deindent(4); writer.write(".end packed-switch"); return true; }
Example 8
Source File: FieldDefinition.java From ZjDroid with Apache License 2.0 | 5 votes |
public static void writeTo(IndentingWriter writer, Field field, boolean setInStaticConstructor) throws IOException { EncodedValue initialValue = field.getInitialValue(); int accessFlags = field.getAccessFlags(); if (setInStaticConstructor && AccessFlags.STATIC.isSet(accessFlags) && AccessFlags.FINAL.isSet(accessFlags) && initialValue != null) { if (!EncodedValueUtils.isDefaultValue(initialValue)) { writer.write("# The value of this static final field might be set in the static constructor\n"); } else { // don't write out the default initial value for static final fields that get set in the static // constructor initialValue = null; } } writer.write(".field "); writeAccessFlags(writer, field.getAccessFlags()); writer.write(field.getName()); writer.write(':'); writer.write(field.getType()); if (initialValue != null) { writer.write(" = "); EncodedValueAdaptor.writeTo(writer, initialValue); } writer.write('\n'); Collection<? extends Annotation> annotations = field.getAnnotations(); if (annotations.size() > 0) { writer.indent(4); AnnotationFormatter.writeTo(writer, annotations); writer.deindent(4); writer.write(".end field\n"); } }
Example 9
Source File: SparseSwitchMethodItem.java From zjdroid with Apache License 2.0 | 5 votes |
@Override public boolean writeTo(IndentingWriter writer) throws IOException { writer.write(".sparse-switch\n"); writer.indent(4); for (SparseSwitchTarget target: targets) { IntegerRenderer.writeTo(writer, target.getKey()); writer.write(" -> "); target.writeTargetTo(writer); writeResourceId(writer, target.getKey()); writer.write('\n'); } writer.deindent(4); writer.write(".end sparse-switch"); return true; }
Example 10
Source File: FieldDefinition.java From ZjDroid with Apache License 2.0 | 5 votes |
public static void writeTo(IndentingWriter writer, Field field, boolean setInStaticConstructor) throws IOException { EncodedValue initialValue = field.getInitialValue(); int accessFlags = field.getAccessFlags(); if (setInStaticConstructor && AccessFlags.STATIC.isSet(accessFlags) && AccessFlags.FINAL.isSet(accessFlags) && initialValue != null) { if (!EncodedValueUtils.isDefaultValue(initialValue)) { writer.write("# The value of this static final field might be set in the static constructor\n"); } else { // don't write out the default initial value for static final fields that get set in the static // constructor initialValue = null; } } writer.write(".field "); writeAccessFlags(writer, field.getAccessFlags()); writer.write(field.getName()); writer.write(':'); writer.write(field.getType()); if (initialValue != null) { writer.write(" = "); EncodedValueAdaptor.writeTo(writer, initialValue); } writer.write('\n'); Collection<? extends Annotation> annotations = field.getAnnotations(); if (annotations.size() > 0) { writer.indent(4); AnnotationFormatter.writeTo(writer, annotations); writer.deindent(4); writer.write(".end field\n"); } }
Example 11
Source File: MethodDefinition.java From zjdroid with Apache License 2.0 | 5 votes |
private static void writeParameters(IndentingWriter writer, Method method, List<? extends MethodParameter> parameters, baksmaliOptions options) throws IOException { boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags()); int registerNumber = isStatic?0:1; for (MethodParameter parameter: parameters) { String parameterType = parameter.getType(); String parameterName = parameter.getName(); Collection<? extends Annotation> annotations = parameter.getAnnotations(); if (parameterName != null || annotations.size() != 0) { writer.write(".param p"); writer.printSignedIntAsDec(registerNumber); if (parameterName != null && options.outputDebugInfo) { writer.write(", "); ReferenceFormatter.writeStringReference(writer, parameterName); } writer.write(" # "); writer.write(parameterType); writer.write("\n"); if (annotations.size() > 0) { writer.indent(4); AnnotationFormatter.writeTo(writer, annotations); writer.deindent(4); writer.write(".end param\n"); } } registerNumber++; if (TypeUtils.isWideType(parameterType)) { registerNumber++; } } }
Example 12
Source File: ArrayDataMethodItem.java From zjdroid with Apache License 2.0 | 5 votes |
public boolean writeTo(IndentingWriter writer) throws IOException { int elementWidth = instruction.getElementWidth(); writer.write(".array-data "); writer.printSignedIntAsDec(instruction.getElementWidth()); writer.write('\n'); writer.indent(4); List<Number> elements = instruction.getArrayElements(); String suffix = ""; switch (elementWidth) { case 1: suffix = "t"; break; case 2: suffix = "s"; break; } for (Number number: elements) { LongRenderer.writeSignedIntOrLongTo(writer, number.longValue()); writer.write(suffix); if (elementWidth == 4) writeResourceId(writer, number.intValue()); writer.write("\n"); } writer.deindent(4); writer.write(".end array-data"); return true; }
Example 13
Source File: MethodDefinition.java From atlas with Apache License 2.0 | 5 votes |
public static void writeEmptyMethodTo(IndentingWriter writer, Method method, BaksmaliOptions options) throws IOException { writer.write(".method "); writeAccessFlags(writer, method.getAccessFlags()); writer.write(method.getName()); writer.write("("); ImmutableList<MethodParameter> methodParameters = ImmutableList.copyOf(method.getParameters()); for (MethodParameter parameter : methodParameters) { writer.write(parameter.getType()); } writer.write(")"); writer.write(method.getReturnType()); writer.write('\n'); writer.indent(4); writeParameters(writer, method, methodParameters, options); String containingClass = null; if (options.implicitReferences) { containingClass = method.getDefiningClass(); } //如果是修改的方法,需要添加ReplaceAnnotation if (DexDiffInfo.modifiedMethods.contains(method)) { MethodReplaceAnnotation replaceAnnotation = new MethodReplaceAnnotation(method.getDefiningClass(), method.getName()); AnnotationFormatter.writeTo(writer, method.getAnnotations(), containingClass, replaceAnnotation); } else { AnnotationFormatter.writeTo(writer, method.getAnnotations(), containingClass); } writer.deindent(4); writer.write(".end method\n"); }
Example 14
Source File: ArrayDataMethodItem.java From HeyGirl with Apache License 2.0 | 5 votes |
public boolean writeTo(IndentingWriter writer) throws IOException { int elementWidth = instruction.getElementWidth(); writer.write(".array-data "); writer.printSignedIntAsDec(instruction.getElementWidth()); writer.write('\n'); writer.indent(4); List<Number> elements = instruction.getArrayElements(); String suffix = ""; switch (elementWidth) { case 1: suffix = "t"; break; case 2: suffix = "s"; break; } for (Number number: elements) { LongRenderer.writeSignedIntOrLongTo(writer, number.longValue()); writer.write(suffix); if (elementWidth == 4) writeResourceId(writer, number.intValue()); writer.write("\n"); } writer.deindent(4); writer.write(".end array-data"); return true; }
Example 15
Source File: SparseSwitchMethodItem.java From HeyGirl with Apache License 2.0 | 5 votes |
@Override public boolean writeTo(IndentingWriter writer) throws IOException { writer.write(".sparse-switch\n"); writer.indent(4); for (SparseSwitchTarget target: targets) { IntegerRenderer.writeTo(writer, target.getKey()); writer.write(" -> "); target.writeTargetTo(writer); writeResourceId(writer, target.getKey()); writer.write('\n'); } writer.deindent(4); writer.write(".end sparse-switch"); return true; }
Example 16
Source File: FieldDefinition.java From HeyGirl with Apache License 2.0 | 5 votes |
public static void writeTo(IndentingWriter writer, Field field, boolean setInStaticConstructor) throws IOException { EncodedValue initialValue = field.getInitialValue(); int accessFlags = field.getAccessFlags(); if (setInStaticConstructor && AccessFlags.STATIC.isSet(accessFlags) && AccessFlags.FINAL.isSet(accessFlags) && initialValue != null) { if (!EncodedValueUtils.isDefaultValue(initialValue)) { writer.write("# The value of this static final field might be set in the static constructor\n"); } else { // don't write out the default initial value for static final fields that get set in the static // constructor initialValue = null; } } writer.write(".field "); writeAccessFlags(writer, field.getAccessFlags()); writer.write(field.getName()); writer.write(':'); writer.write(field.getType()); if (initialValue != null) { writer.write(" = "); EncodedValueAdaptor.writeTo(writer, initialValue); } writer.write('\n'); Collection<? extends Annotation> annotations = field.getAnnotations(); if (annotations.size() > 0) { writer.indent(4); AnnotationFormatter.writeTo(writer, annotations); writer.deindent(4); writer.write(".end field\n"); } }
Example 17
Source File: AnnotationEncodedValueAdaptor.java From zjdroid with Apache License 2.0 | 5 votes |
public static void writeElementsTo(IndentingWriter writer, Collection<? extends AnnotationElement> annotationElements) throws IOException { writer.indent(4); for (AnnotationElement annotationElement: annotationElements) { writer.write(annotationElement.getName()); writer.write(" = "); EncodedValueAdaptor.writeTo(writer, annotationElement.getValue()); writer.write('\n'); } writer.deindent(4); }
Example 18
Source File: MethodDefinition.java From HeyGirl with Apache License 2.0 | 5 votes |
private static void writeParameters(IndentingWriter writer, Method method, List<? extends MethodParameter> parameters, baksmaliOptions options) throws IOException { boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags()); int registerNumber = isStatic?0:1; for (MethodParameter parameter: parameters) { String parameterType = parameter.getType(); String parameterName = parameter.getName(); Collection<? extends Annotation> annotations = parameter.getAnnotations(); if (parameterName != null || annotations.size() != 0) { writer.write(".param p"); writer.printSignedIntAsDec(registerNumber); if (parameterName != null && options.outputDebugInfo) { writer.write(", "); ReferenceFormatter.writeStringReference(writer, parameterName); } writer.write(" # "); writer.write(parameterType); writer.write("\n"); if (annotations.size() > 0) { writer.indent(4); AnnotationFormatter.writeTo(writer, annotations); writer.deindent(4); writer.write(".end param\n"); } } registerNumber++; if (TypeUtils.isWideType(parameterType)) { registerNumber++; } } }
Example 19
Source File: MethodDefinition.java From ZjDroid with Apache License 2.0 | 4 votes |
public void writeTo(IndentingWriter writer) throws IOException { int parameterRegisterCount = 0; if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) { parameterRegisterCount++; } writer.write(".method "); writeAccessFlags(writer, method.getAccessFlags()); writer.write(method.getName()); writer.write("("); for (MethodParameter parameter: methodParameters) { String type = parameter.getType(); writer.write(type); parameterRegisterCount++; if (TypeUtils.isWideType(type)) { parameterRegisterCount++; } } writer.write(")"); writer.write(method.getReturnType()); writer.write('\n'); writer.indent(4); if (classDef.options.useLocalsDirective) { writer.write(".locals "); writer.printSignedIntAsDec(methodImpl.getRegisterCount() - parameterRegisterCount); } else { writer.write(".registers "); writer.printSignedIntAsDec(methodImpl.getRegisterCount()); } writer.write('\n'); writeParameters(writer, method, methodParameters, classDef.options); if (registerFormatter == null) { registerFormatter = new RegisterFormatter(classDef.options, methodImpl.getRegisterCount(), parameterRegisterCount); } AnnotationFormatter.writeTo(writer, method.getAnnotations()); writer.write('\n'); List<MethodItem> methodItems = getMethodItems(); for (MethodItem methodItem: methodItems) { if (methodItem.writeTo(writer)) { writer.write('\n'); } } writer.deindent(4); writer.write(".end method\n"); }
Example 20
Source File: MethodDefinition.java From HeyGirl with Apache License 2.0 | 4 votes |
public void writeTo(IndentingWriter writer) throws IOException { int parameterRegisterCount = 0; if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) { parameterRegisterCount++; } writer.write(".method "); writeAccessFlags(writer, method.getAccessFlags()); writer.write(method.getName()); writer.write("("); for (MethodParameter parameter: methodParameters) { String type = parameter.getType(); writer.write(type); parameterRegisterCount++; if (TypeUtils.isWideType(type)) { parameterRegisterCount++; } } writer.write(")"); writer.write(method.getReturnType()); writer.write('\n'); writer.indent(4); if (classDef.options.useLocalsDirective) { writer.write(".locals "); writer.printSignedIntAsDec(methodImpl.getRegisterCount() - parameterRegisterCount); } else { writer.write(".registers "); writer.printSignedIntAsDec(methodImpl.getRegisterCount()); } writer.write('\n'); writeParameters(writer, method, methodParameters, classDef.options); if (registerFormatter == null) { registerFormatter = new RegisterFormatter(classDef.options, methodImpl.getRegisterCount(), parameterRegisterCount); } AnnotationFormatter.writeTo(writer, method.getAnnotations()); writer.write('\n'); List<MethodItem> methodItems = getMethodItems(); for (MethodItem methodItem: methodItems) { if (methodItem.writeTo(writer)) { writer.write('\n'); } } writer.deindent(4); writer.write(".end method\n"); }