mirror of
https://github.com/revanced/smali.git
synced 2025-04-29 22:24:26 +02:00
Switch out IndentingWriter for BaksmaliWriter throughout baksmali
This refactors everything using an IndentingWriter to use a BaksmaliWriter instead, but the usages of ReferenceUtil and EncodedValue aren't refactored yet.
This commit is contained in:
parent
6efebc1543
commit
9ce00aae9c
@ -29,9 +29,9 @@
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.baksmali.Adaptors.EncodedValue.AnnotationEncodedValueAdaptor;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.AnnotationVisibility;
|
||||
import org.jf.dexlib2.iface.Annotation;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -40,7 +40,7 @@ import java.util.Collection;
|
||||
|
||||
public class AnnotationFormatter {
|
||||
|
||||
public static void writeTo(@Nonnull IndentingWriter writer,
|
||||
public static void writeTo(@Nonnull BaksmaliWriter writer,
|
||||
@Nonnull Collection<? extends Annotation> annotations,
|
||||
@Nullable String containingClass) throws IOException {
|
||||
boolean first = true;
|
||||
@ -54,7 +54,7 @@ public class AnnotationFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeTo(@Nonnull IndentingWriter writer, @Nonnull Annotation annotation,
|
||||
public static void writeTo(@Nonnull BaksmaliWriter writer, @Nonnull Annotation annotation,
|
||||
@Nullable String containingClass) throws IOException {
|
||||
writer.write(".annotation ");
|
||||
writer.write(AnnotationVisibility.getVisibility(annotation.getVisibility()));
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
//a "spacer" between instructions
|
||||
public class BlankMethodItem extends MethodItem {
|
||||
@ -40,7 +40,7 @@ public class BlankMethodItem extends MethodItem {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
public boolean writeTo(IndentingWriter writer) {
|
||||
public boolean writeTo(BaksmaliWriter writer) {
|
||||
//we didn't technically print something, but returning true indicates that a newline should be printed
|
||||
//after this method item, which is the intended functionality
|
||||
return true;
|
||||
|
@ -29,7 +29,7 @@
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.baksmali.BaksmaliOptions;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -79,7 +79,7 @@ public class CatchMethodItem extends MethodItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
if (exceptionType == null) {
|
||||
writer.write(".catchall");
|
||||
} else {
|
||||
|
@ -29,6 +29,8 @@
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.baksmali.BaksmaliOptions;
|
||||
import org.jf.baksmali.formatter.BaksmaliFormatter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.AccessFlags;
|
||||
import org.jf.dexlib2.dexbacked.DexBackedClassDef;
|
||||
import org.jf.dexlib2.iface.*;
|
||||
@ -37,7 +39,6 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction21c;
|
||||
import org.jf.dexlib2.iface.reference.FieldReference;
|
||||
import org.jf.dexlib2.iface.reference.Reference;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.util.StringUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -51,12 +52,14 @@ public class ClassDefinition {
|
||||
@Nonnull public final BaksmaliOptions options;
|
||||
@Nonnull public final ClassDef classDef;
|
||||
@Nonnull private final HashSet<String> fieldsSetInStaticConstructor;
|
||||
@Nonnull private final BaksmaliFormatter formatter;
|
||||
|
||||
protected boolean validationErrors;
|
||||
|
||||
public ClassDefinition(@Nonnull BaksmaliOptions options, @Nonnull ClassDef classDef) {
|
||||
this.options = options;
|
||||
this.classDef = classDef;
|
||||
formatter = new BaksmaliFormatter(options.implicitReferences ? classDef.getType() : null);
|
||||
fieldsSetInStaticConstructor = findFieldsSetInStaticConstructor(classDef);
|
||||
}
|
||||
|
||||
@ -101,7 +104,7 @@ public class ClassDefinition {
|
||||
return fieldsSetInStaticConstructor;
|
||||
}
|
||||
|
||||
public void writeTo(IndentingWriter writer) throws IOException {
|
||||
public void writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writeClass(writer);
|
||||
writeSuper(writer);
|
||||
writeSourceFile(writer);
|
||||
@ -113,21 +116,21 @@ public class ClassDefinition {
|
||||
writeVirtualMethods(writer, directMethods);
|
||||
}
|
||||
|
||||
private void writeClass(IndentingWriter writer) throws IOException {
|
||||
private void writeClass(BaksmaliWriter writer) throws IOException {
|
||||
writer.write(".class ");
|
||||
writeAccessFlags(writer);
|
||||
writer.write(classDef.getType());
|
||||
writer.write('\n');
|
||||
}
|
||||
|
||||
private void writeAccessFlags(IndentingWriter writer) throws IOException {
|
||||
private void writeAccessFlags(BaksmaliWriter writer) throws IOException {
|
||||
for (AccessFlags accessFlag: AccessFlags.getAccessFlagsForClass(classDef.getAccessFlags())) {
|
||||
writer.write(accessFlag.toString());
|
||||
writer.write(' ');
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSuper(IndentingWriter writer) throws IOException {
|
||||
private void writeSuper(BaksmaliWriter writer) throws IOException {
|
||||
String superClass = classDef.getSuperclass();
|
||||
if (superClass != null) {
|
||||
writer.write(".super ");
|
||||
@ -136,7 +139,7 @@ public class ClassDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSourceFile(IndentingWriter writer) throws IOException {
|
||||
private void writeSourceFile(BaksmaliWriter writer) throws IOException {
|
||||
String sourceFile = classDef.getSourceFile();
|
||||
if (sourceFile != null) {
|
||||
writer.write(".source \"");
|
||||
@ -145,7 +148,7 @@ public class ClassDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeInterfaces(IndentingWriter writer) throws IOException {
|
||||
private void writeInterfaces(BaksmaliWriter writer) throws IOException {
|
||||
List<String> interfaces = classDef.getInterfaces();
|
||||
|
||||
if (interfaces.size() != 0) {
|
||||
@ -159,7 +162,7 @@ public class ClassDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeAnnotations(IndentingWriter writer) throws IOException {
|
||||
private void writeAnnotations(BaksmaliWriter writer) throws IOException {
|
||||
Collection<? extends Annotation> classAnnotations = classDef.getAnnotations();
|
||||
if (classAnnotations.size() != 0) {
|
||||
writer.write("\n\n");
|
||||
@ -174,7 +177,7 @@ public class ClassDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> writeStaticFields(IndentingWriter writer) throws IOException {
|
||||
private Set<String> writeStaticFields(BaksmaliWriter writer) throws IOException {
|
||||
boolean wroteHeader = false;
|
||||
Set<String> writtenFields = new HashSet<String>();
|
||||
|
||||
@ -194,11 +197,11 @@ public class ClassDefinition {
|
||||
writer.write('\n');
|
||||
|
||||
boolean setInStaticConstructor;
|
||||
IndentingWriter fieldWriter = writer;
|
||||
BaksmaliWriter fieldWriter = writer;
|
||||
String fieldString = ReferenceUtil.getShortFieldDescriptor(field);
|
||||
if (!writtenFields.add(fieldString)) {
|
||||
writer.write("# duplicate field ignored\n");
|
||||
fieldWriter = new CommentingIndentingWriter(writer);
|
||||
fieldWriter = getCommentingWriter(writer);
|
||||
System.err.println(String.format("Ignoring duplicate field: %s->%s", classDef.getType(), fieldString));
|
||||
setInStaticConstructor = false;
|
||||
} else {
|
||||
@ -209,7 +212,7 @@ public class ClassDefinition {
|
||||
return writtenFields;
|
||||
}
|
||||
|
||||
private void writeInstanceFields(IndentingWriter writer, Set<String> staticFields) throws IOException {
|
||||
private void writeInstanceFields(BaksmaliWriter writer, Set<String> staticFields) throws IOException {
|
||||
boolean wroteHeader = false;
|
||||
Set<String> writtenFields = new HashSet<String>();
|
||||
|
||||
@ -228,11 +231,11 @@ public class ClassDefinition {
|
||||
}
|
||||
writer.write('\n');
|
||||
|
||||
IndentingWriter fieldWriter = writer;
|
||||
BaksmaliWriter fieldWriter = writer;
|
||||
String fieldString = ReferenceUtil.getShortFieldDescriptor(field);
|
||||
if (!writtenFields.add(fieldString)) {
|
||||
writer.write("# duplicate field ignored\n");
|
||||
fieldWriter = new CommentingIndentingWriter(writer);
|
||||
fieldWriter = getCommentingWriter(writer);
|
||||
System.err.println(String.format("Ignoring duplicate field: %s->%s", classDef.getType(), fieldString));
|
||||
} else if (staticFields.contains(fieldString)) {
|
||||
System.err.println(String.format("Duplicate static+instance field found: %s->%s",
|
||||
@ -246,7 +249,7 @@ public class ClassDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> writeDirectMethods(IndentingWriter writer) throws IOException {
|
||||
private Set<String> writeDirectMethods(BaksmaliWriter writer) throws IOException {
|
||||
boolean wroteHeader = false;
|
||||
Set<String> writtenMethods = new HashSet<String>();
|
||||
|
||||
@ -268,10 +271,10 @@ public class ClassDefinition {
|
||||
// TODO: check for method validation errors
|
||||
String methodString = ReferenceUtil.getMethodDescriptor(method, true);
|
||||
|
||||
IndentingWriter methodWriter = writer;
|
||||
BaksmaliWriter methodWriter = writer;
|
||||
if (!writtenMethods.add(methodString)) {
|
||||
writer.write("# duplicate method ignored\n");
|
||||
methodWriter = new CommentingIndentingWriter(writer);
|
||||
methodWriter = getCommentingWriter(writer);
|
||||
}
|
||||
|
||||
MethodImplementation methodImpl = method.getImplementation();
|
||||
@ -285,7 +288,7 @@ public class ClassDefinition {
|
||||
return writtenMethods;
|
||||
}
|
||||
|
||||
private void writeVirtualMethods(IndentingWriter writer, Set<String> directMethods) throws IOException {
|
||||
private void writeVirtualMethods(BaksmaliWriter writer, Set<String> directMethods) throws IOException {
|
||||
boolean wroteHeader = false;
|
||||
Set<String> writtenMethods = new HashSet<String>();
|
||||
|
||||
@ -307,10 +310,10 @@ public class ClassDefinition {
|
||||
// TODO: check for method validation errors
|
||||
String methodString = ReferenceUtil.getMethodDescriptor(method, true);
|
||||
|
||||
IndentingWriter methodWriter = writer;
|
||||
BaksmaliWriter methodWriter = writer;
|
||||
if (!writtenMethods.add(methodString)) {
|
||||
writer.write("# duplicate method ignored\n");
|
||||
methodWriter = new CommentingIndentingWriter(writer);
|
||||
methodWriter = getCommentingWriter(writer);
|
||||
} else if (directMethods.contains(methodString)) {
|
||||
writer.write("# There is both a direct and virtual method with this signature.\n" +
|
||||
"# You will need to rename one of these methods, including all references.\n");
|
||||
@ -328,4 +331,12 @@ public class ClassDefinition {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BaksmaliWriter getCommentingWriter(BaksmaliWriter writer) {
|
||||
return formatter.getWriter(new CommentingIndentingWriter(writer.indentingWriter()));
|
||||
}
|
||||
|
||||
public BaksmaliFormatter getFormatter() {
|
||||
return formatter;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -47,7 +47,7 @@ public class CommentMethodItem extends MethodItem {
|
||||
return sortOrder;
|
||||
}
|
||||
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write('#');
|
||||
writer.write(comment);
|
||||
return true;
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -44,7 +44,7 @@ public class CommentedOutMethodItem extends MethodItem {
|
||||
return commentedOutMethodItem.getSortOrder() + .001;
|
||||
}
|
||||
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write('#');
|
||||
commentedOutMethodItem.writeTo(writer);
|
||||
return true;
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors.Debug;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -41,7 +41,7 @@ public class BeginEpilogueMethodItem extends DebugMethodItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write(".prologue");
|
||||
return true;
|
||||
}
|
||||
|
@ -32,8 +32,8 @@
|
||||
package org.jf.baksmali.Adaptors.Debug;
|
||||
|
||||
import org.jf.baksmali.Adaptors.RegisterFormatter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.debug.EndLocal;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -50,7 +50,7 @@ public class EndLocalMethodItem extends DebugMethodItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write(".end local ");
|
||||
registerFormatter.writeTo(writer, endLocal.getRegister());
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors.Debug;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -41,7 +41,7 @@ public class EndPrologueMethodItem extends DebugMethodItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write(".prologue");
|
||||
return true;
|
||||
}
|
||||
|
@ -31,8 +31,8 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors.Debug;
|
||||
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.debug.LineNumber;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -46,9 +46,9 @@ public class LineNumberMethodItem extends DebugMethodItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write(".line ");
|
||||
writer.printUnsignedIntAsDec(lineNumber);
|
||||
writer.writeUnsignedIntAsDec(lineNumber);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
package org.jf.baksmali.Adaptors.Debug;
|
||||
|
||||
import org.jf.baksmali.Adaptors.ReferenceFormatter;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -52,7 +52,7 @@ public class LocalFormatter {
|
||||
*
|
||||
* One of name, type or signature must be non-null
|
||||
*/
|
||||
public static void writeLocal(@Nonnull IndentingWriter writer, @Nullable String name, @Nullable String type,
|
||||
public static void writeLocal(@Nonnull BaksmaliWriter writer, @Nullable String name, @Nullable String type,
|
||||
@Nullable String signature) throws IOException {
|
||||
if (name != null) {
|
||||
ReferenceFormatter.writeStringReference(writer, name);
|
||||
|
@ -32,8 +32,8 @@
|
||||
package org.jf.baksmali.Adaptors.Debug;
|
||||
|
||||
import org.jf.baksmali.Adaptors.RegisterFormatter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.debug.RestartLocal;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -50,7 +50,7 @@ public class RestartLocalMethodItem extends DebugMethodItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write(".restart local ");
|
||||
registerFormatter.writeTo(writer, restartLocal.getRegister());
|
||||
|
||||
|
@ -31,8 +31,8 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors.Debug;
|
||||
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.debug.SetSourceFile;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.util.StringUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -48,7 +48,7 @@ public class SetSourceFileMethodItem extends DebugMethodItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write(".source");
|
||||
|
||||
if (sourceFile != null) {
|
||||
|
@ -32,8 +32,8 @@
|
||||
package org.jf.baksmali.Adaptors.Debug;
|
||||
|
||||
import org.jf.baksmali.Adaptors.RegisterFormatter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.debug.StartLocal;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -50,7 +50,7 @@ public class StartLocalMethodItem extends DebugMethodItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write(".local ");
|
||||
registerFormatter.writeTo(writer, startLocal.getRegister());
|
||||
|
||||
|
@ -28,9 +28,9 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors.EncodedValue;
|
||||
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.AnnotationElement;
|
||||
import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -39,7 +39,7 @@ import java.util.Collection;
|
||||
|
||||
public abstract class AnnotationEncodedValueAdaptor {
|
||||
|
||||
public static void writeTo(@Nonnull IndentingWriter writer,
|
||||
public static void writeTo(@Nonnull BaksmaliWriter writer,
|
||||
@Nonnull AnnotationEncodedValue annotationEncodedValue,
|
||||
@Nullable String containingClass) throws IOException {
|
||||
writer.write(".subannotation ");
|
||||
@ -50,7 +50,7 @@ public abstract class AnnotationEncodedValueAdaptor {
|
||||
writer.write(".end subannotation");
|
||||
}
|
||||
|
||||
public static void writeElementsTo(@Nonnull IndentingWriter writer,
|
||||
public static void writeElementsTo(@Nonnull BaksmaliWriter writer,
|
||||
@Nonnull Collection<? extends AnnotationElement> annotationElements,
|
||||
@Nullable String containingClass) throws IOException {
|
||||
writer.indent(4);
|
||||
|
@ -28,9 +28,9 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors.EncodedValue;
|
||||
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.value.ArrayEncodedValue;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -38,7 +38,7 @@ import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
public class ArrayEncodedValueAdaptor {
|
||||
public static void writeTo(@Nonnull IndentingWriter writer,
|
||||
public static void writeTo(@Nonnull BaksmaliWriter writer,
|
||||
@Nonnull ArrayEncodedValue arrayEncodedValue,
|
||||
@Nullable String containingClass) throws IOException {
|
||||
writer.write('{');
|
||||
|
@ -30,18 +30,18 @@ package org.jf.baksmali.Adaptors.EncodedValue;
|
||||
|
||||
import org.jf.baksmali.Adaptors.ReferenceFormatter;
|
||||
import org.jf.baksmali.Renderers.*;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.ReferenceType;
|
||||
import org.jf.dexlib2.ValueType;
|
||||
import org.jf.dexlib2.iface.value.*;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class EncodedValueAdaptor {
|
||||
public static void writeTo(@Nonnull IndentingWriter writer, @Nonnull EncodedValue encodedValue,
|
||||
public static void writeTo(@Nonnull BaksmaliWriter writer, @Nonnull EncodedValue encodedValue,
|
||||
@Nullable String containingClass)
|
||||
throws IOException {
|
||||
switch (encodedValue.getValueType()) {
|
||||
|
@ -30,20 +30,20 @@ package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.baksmali.Adaptors.EncodedValue.EncodedValueAdaptor;
|
||||
import org.jf.baksmali.BaksmaliOptions;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.AccessFlags;
|
||||
import org.jf.dexlib2.HiddenApiRestriction;
|
||||
import org.jf.dexlib2.iface.Annotation;
|
||||
import org.jf.dexlib2.iface.Field;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.util.EncodedValueUtils;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public class FieldDefinition {
|
||||
public static void writeTo(BaksmaliOptions options, IndentingWriter writer, Field field,
|
||||
public static void writeTo(BaksmaliOptions options, BaksmaliWriter writer, Field field,
|
||||
boolean setInStaticConstructor) throws IOException {
|
||||
EncodedValue initialValue = field.getInitialValue();
|
||||
int accessFlags = field.getAccessFlags();
|
||||
@ -95,7 +95,7 @@ public class FieldDefinition {
|
||||
}
|
||||
|
||||
private static void writeAccessFlagsAndRestrictions(
|
||||
IndentingWriter writer, int accessFlags, Set<HiddenApiRestriction> hiddenApiRestrictions)
|
||||
BaksmaliWriter writer, int accessFlags, Set<HiddenApiRestriction> hiddenApiRestrictions)
|
||||
throws IOException {
|
||||
for (AccessFlags accessFlag: AccessFlags.getAccessFlagsForField(accessFlags)) {
|
||||
writer.write(accessFlag.toString());
|
||||
|
@ -30,8 +30,8 @@ package org.jf.baksmali.Adaptors.Format;
|
||||
|
||||
import org.jf.baksmali.Adaptors.MethodDefinition;
|
||||
import org.jf.baksmali.Renderers.LongRenderer;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.instruction.formats.ArrayPayload;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@ -41,11 +41,11 @@ public class ArrayDataMethodItem extends InstructionMethodItem<ArrayPayload> {
|
||||
super(methodDef, codeAddress, instruction);
|
||||
}
|
||||
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
int elementWidth = instruction.getElementWidth();
|
||||
|
||||
writer.write(".array-data ");
|
||||
writer.printSignedIntAsDec(instruction.getElementWidth());
|
||||
writer.writeSignedIntAsDec(instruction.getElementWidth());
|
||||
writer.write('\n');
|
||||
|
||||
writer.indent(4);
|
||||
|
@ -34,6 +34,7 @@ import org.jf.baksmali.Adaptors.MethodItem;
|
||||
import org.jf.baksmali.Adaptors.ReferenceFormatter;
|
||||
import org.jf.baksmali.BaksmaliOptions;
|
||||
import org.jf.baksmali.Renderers.LongRenderer;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.VerificationError;
|
||||
import org.jf.dexlib2.iface.instruction.*;
|
||||
@ -44,7 +45,6 @@ import org.jf.dexlib2.iface.reference.CallSiteReference;
|
||||
import org.jf.dexlib2.iface.reference.Reference;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
import org.jf.util.ExceptionWithContext;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.util.NumberUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -80,11 +80,11 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
|
||||
}
|
||||
|
||||
private interface Writable {
|
||||
void writeTo(IndentingWriter writer) throws IOException;
|
||||
void writeTo(BaksmaliWriter writer) throws IOException;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
Opcode opcode = instruction.getOpcode();
|
||||
String verificationErrorName = null;
|
||||
Writable referenceWritable = null;
|
||||
@ -97,7 +97,7 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
|
||||
verificationErrorName = VerificationError.getVerificationErrorName(verificationError);
|
||||
if (verificationErrorName == null) {
|
||||
writer.write("#was invalid verification error type: ");
|
||||
writer.printSignedIntAsDec(verificationError);
|
||||
writer.writeSignedIntAsDec(verificationError);
|
||||
writer.write("\n");
|
||||
verificationErrorName = "generic-error";
|
||||
}
|
||||
@ -120,14 +120,14 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
|
||||
if (reference instanceof CallSiteReference) {
|
||||
referenceWritable = new Writable() {
|
||||
@Override
|
||||
public void writeTo(IndentingWriter indentingWriter) throws IOException {
|
||||
public void writeTo(BaksmaliWriter indentingWriter) throws IOException {
|
||||
ReferenceFormatter.writeCallSiteReference(indentingWriter, (CallSiteReference)reference);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
referenceWritable = new Writable() {
|
||||
@Override
|
||||
public void writeTo(IndentingWriter indentingWriter) throws IOException {
|
||||
public void writeTo(BaksmaliWriter indentingWriter) throws IOException {
|
||||
indentingWriter.write(ReferenceUtil.getReferenceString(reference, classContext));
|
||||
}
|
||||
};
|
||||
@ -220,7 +220,7 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
|
||||
case Format10x:
|
||||
if (instruction instanceof UnknownInstruction) {
|
||||
writer.write("#unknown opcode: 0x");
|
||||
writer.printUnsignedLongAsHex(((UnknownInstruction)instruction).getOriginalOpcode());
|
||||
writer.writeUnsignedLongAsHex(((UnknownInstruction)instruction).getOriginalOpcode());
|
||||
writer.write('\n');
|
||||
}
|
||||
writeOpcode(writer);
|
||||
@ -416,33 +416,33 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void writeOpcode(IndentingWriter writer) throws IOException {
|
||||
protected void writeOpcode(BaksmaliWriter writer) throws IOException {
|
||||
writer.write(instruction.getOpcode().name);
|
||||
}
|
||||
|
||||
protected void writeTargetLabel(IndentingWriter writer) throws IOException {
|
||||
protected void writeTargetLabel(BaksmaliWriter writer) throws IOException {
|
||||
//this method is overridden by OffsetInstructionMethodItem, and should only be called for the formats that
|
||||
//have a target
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
protected void writeRegister(IndentingWriter writer, int registerNumber) throws IOException {
|
||||
protected void writeRegister(BaksmaliWriter writer, int registerNumber) throws IOException {
|
||||
methodDef.registerFormatter.writeTo(writer, registerNumber);
|
||||
}
|
||||
|
||||
protected void writeFirstRegister(IndentingWriter writer) throws IOException {
|
||||
protected void writeFirstRegister(BaksmaliWriter writer) throws IOException {
|
||||
writeRegister(writer, ((OneRegisterInstruction)instruction).getRegisterA());
|
||||
}
|
||||
|
||||
protected void writeSecondRegister(IndentingWriter writer) throws IOException {
|
||||
protected void writeSecondRegister(BaksmaliWriter writer) throws IOException {
|
||||
writeRegister(writer, ((TwoRegisterInstruction)instruction).getRegisterB());
|
||||
}
|
||||
|
||||
protected void writeThirdRegister(IndentingWriter writer) throws IOException {
|
||||
protected void writeThirdRegister(BaksmaliWriter writer) throws IOException {
|
||||
writeRegister(writer, ((ThreeRegisterInstruction) instruction).getRegisterC());
|
||||
}
|
||||
|
||||
protected void writeInvokeRegisters(IndentingWriter writer) throws IOException {
|
||||
protected void writeInvokeRegisters(BaksmaliWriter writer) throws IOException {
|
||||
FiveRegisterInstruction instruction = (FiveRegisterInstruction)this.instruction;
|
||||
final int regCount = instruction.getRegisterCount();
|
||||
|
||||
@ -487,7 +487,7 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
|
||||
writer.write('}');
|
||||
}
|
||||
|
||||
protected void writeInvokeRangeRegisters(IndentingWriter writer) throws IOException {
|
||||
protected void writeInvokeRangeRegisters(BaksmaliWriter writer) throws IOException {
|
||||
RegisterRangeInstruction instruction = (RegisterRangeInstruction)this.instruction;
|
||||
|
||||
int regCount = instruction.getRegisterCount();
|
||||
@ -499,15 +499,15 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeLiteral(IndentingWriter writer) throws IOException {
|
||||
protected void writeLiteral(BaksmaliWriter writer) throws IOException {
|
||||
LongRenderer.writeSignedIntOrLongTo(writer, ((WideLiteralInstruction)instruction).getWideLiteral());
|
||||
}
|
||||
|
||||
protected void writeCommentIfLikelyFloat(IndentingWriter writer) throws IOException {
|
||||
protected void writeCommentIfLikelyFloat(BaksmaliWriter writer) throws IOException {
|
||||
writeCommentIfLikelyFloat(writer, ((NarrowLiteralInstruction)instruction).getNarrowLiteral());
|
||||
}
|
||||
|
||||
protected void writeCommentIfLikelyFloat(IndentingWriter writer, int val) throws IOException {
|
||||
protected void writeCommentIfLikelyFloat(BaksmaliWriter writer, int val) throws IOException {
|
||||
if (NumberUtils.isLikelyFloat(val)) {
|
||||
writer.write(" # ");
|
||||
float fval = Float.intBitsToFloat(val);
|
||||
@ -530,11 +530,11 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeCommentIfLikelyDouble(IndentingWriter writer) throws IOException {
|
||||
protected void writeCommentIfLikelyDouble(BaksmaliWriter writer) throws IOException {
|
||||
writeCommentIfLikelyDouble(writer, ((WideLiteralInstruction)instruction).getWideLiteral());
|
||||
}
|
||||
|
||||
protected void writeCommentIfLikelyDouble(IndentingWriter writer, long val) throws IOException {
|
||||
protected void writeCommentIfLikelyDouble(BaksmaliWriter writer, long val) throws IOException {
|
||||
if (NumberUtils.isLikelyDouble(val)) {
|
||||
writer.write(" # ");
|
||||
double dval = Double.longBitsToDouble(val);
|
||||
@ -555,11 +555,11 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean writeCommentIfResourceId(IndentingWriter writer) throws IOException {
|
||||
protected boolean writeCommentIfResourceId(BaksmaliWriter writer) throws IOException {
|
||||
return writeCommentIfResourceId(writer, ((NarrowLiteralInstruction)instruction).getNarrowLiteral());
|
||||
}
|
||||
|
||||
protected boolean writeCommentIfResourceId(IndentingWriter writer, int val) throws IOException {
|
||||
protected boolean writeCommentIfResourceId(BaksmaliWriter writer, int val) throws IOException {
|
||||
Map<Integer,String> resourceIds = methodDef.classDef.options.resourceIds;
|
||||
String resource = resourceIds.get(Integer.valueOf(val));
|
||||
if (resource != null) {
|
||||
@ -570,18 +570,18 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void writeFieldOffset(IndentingWriter writer) throws IOException {
|
||||
protected void writeFieldOffset(BaksmaliWriter writer) throws IOException {
|
||||
writer.write("field@0x");
|
||||
writer.printUnsignedLongAsHex(((FieldOffsetInstruction)instruction).getFieldOffset());
|
||||
writer.writeUnsignedLongAsHex(((FieldOffsetInstruction)instruction).getFieldOffset());
|
||||
}
|
||||
|
||||
protected void writeInlineIndex(IndentingWriter writer) throws IOException {
|
||||
protected void writeInlineIndex(BaksmaliWriter writer) throws IOException {
|
||||
writer.write("inline@");
|
||||
writer.printSignedIntAsDec(((InlineIndexInstruction)instruction).getInlineIndex());
|
||||
writer.writeSignedIntAsDec(((InlineIndexInstruction)instruction).getInlineIndex());
|
||||
}
|
||||
|
||||
protected void writeVtableIndex(IndentingWriter writer) throws IOException {
|
||||
protected void writeVtableIndex(BaksmaliWriter writer) throws IOException {
|
||||
writer.write("vtable@");
|
||||
writer.printSignedIntAsDec(((VtableIndexInstruction)instruction).getVtableIndex());
|
||||
writer.writeSignedIntAsDec(((VtableIndexInstruction)instruction).getVtableIndex());
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,9 @@ package org.jf.baksmali.Adaptors.Format;
|
||||
import org.jf.baksmali.Adaptors.LabelMethodItem;
|
||||
import org.jf.baksmali.Adaptors.MethodDefinition;
|
||||
import org.jf.baksmali.BaksmaliOptions;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.iface.instruction.OffsetInstruction;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -50,7 +50,7 @@ public class OffsetInstructionFormatMethodItem extends InstructionMethodItem<Off
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeTargetLabel(IndentingWriter writer) throws IOException {
|
||||
protected void writeTargetLabel(BaksmaliWriter writer) throws IOException {
|
||||
label.writeTo(writer);
|
||||
}
|
||||
|
||||
|
@ -28,13 +28,12 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors.Format;
|
||||
|
||||
import org.jf.baksmali.Adaptors.CommentingIndentingWriter;
|
||||
import org.jf.baksmali.Adaptors.LabelMethodItem;
|
||||
import org.jf.baksmali.Adaptors.MethodDefinition;
|
||||
import org.jf.baksmali.Renderers.IntegerRenderer;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.instruction.SwitchElement;
|
||||
import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.Renderers.IntegerRenderer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -81,9 +80,9 @@ public class PackedSwitchMethodItem extends InstructionMethodItem<PackedSwitchPa
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
if (commentedOut) {
|
||||
writer = new CommentingIndentingWriter(writer);
|
||||
writer = methodDef.classDef.getCommentingWriter(writer);
|
||||
}
|
||||
writer.write(".packed-switch ");
|
||||
IntegerRenderer.writeTo(writer, firstKey);
|
||||
@ -102,7 +101,7 @@ public class PackedSwitchMethodItem extends InstructionMethodItem<PackedSwitchPa
|
||||
}
|
||||
|
||||
private static abstract class PackedSwitchTarget {
|
||||
public abstract void writeTargetTo(IndentingWriter writer) throws IOException;
|
||||
public abstract void writeTargetTo(BaksmaliWriter writer) throws IOException;
|
||||
}
|
||||
|
||||
private static class PackedSwitchLabelTarget extends PackedSwitchTarget {
|
||||
@ -110,7 +109,7 @@ public class PackedSwitchMethodItem extends InstructionMethodItem<PackedSwitchPa
|
||||
public PackedSwitchLabelTarget(LabelMethodItem target) {
|
||||
this.target = target;
|
||||
}
|
||||
public void writeTargetTo(IndentingWriter writer) throws IOException {
|
||||
public void writeTargetTo(BaksmaliWriter writer) throws IOException {
|
||||
target.writeTo(writer);
|
||||
}
|
||||
}
|
||||
@ -120,11 +119,11 @@ public class PackedSwitchMethodItem extends InstructionMethodItem<PackedSwitchPa
|
||||
public PackedSwitchOffsetTarget(int target) {
|
||||
this.target = target;
|
||||
}
|
||||
public void writeTargetTo(IndentingWriter writer) throws IOException {
|
||||
public void writeTargetTo(BaksmaliWriter writer) throws IOException {
|
||||
if (target >= 0) {
|
||||
writer.write('+');
|
||||
}
|
||||
writer.printSignedIntAsDec(target);
|
||||
writer.writeSignedIntAsDec(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,13 +28,12 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors.Format;
|
||||
|
||||
import org.jf.baksmali.Adaptors.CommentingIndentingWriter;
|
||||
import org.jf.baksmali.Adaptors.LabelMethodItem;
|
||||
import org.jf.baksmali.Adaptors.MethodDefinition;
|
||||
import org.jf.baksmali.Renderers.IntegerRenderer;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.instruction.SwitchElement;
|
||||
import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.Renderers.IntegerRenderer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -69,9 +68,9 @@ public class SparseSwitchMethodItem extends InstructionMethodItem<SparseSwitchPa
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
if (commentedOut) {
|
||||
writer = new CommentingIndentingWriter(writer);
|
||||
writer = methodDef.classDef.getCommentingWriter(writer);
|
||||
}
|
||||
|
||||
writer.write(".sparse-switch\n");
|
||||
@ -94,7 +93,7 @@ public class SparseSwitchMethodItem extends InstructionMethodItem<SparseSwitchPa
|
||||
this.key = key;
|
||||
}
|
||||
public int getKey() { return key; }
|
||||
public abstract void writeTargetTo(IndentingWriter writer) throws IOException;
|
||||
public abstract void writeTargetTo(BaksmaliWriter writer) throws IOException;
|
||||
}
|
||||
|
||||
private static class SparseSwitchLabelTarget extends SparseSwitchTarget {
|
||||
@ -104,7 +103,7 @@ public class SparseSwitchMethodItem extends InstructionMethodItem<SparseSwitchPa
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public void writeTargetTo(IndentingWriter writer) throws IOException {
|
||||
public void writeTargetTo(BaksmaliWriter writer) throws IOException {
|
||||
target.writeTo(writer);
|
||||
}
|
||||
}
|
||||
@ -116,11 +115,11 @@ public class SparseSwitchMethodItem extends InstructionMethodItem<SparseSwitchPa
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public void writeTargetTo(IndentingWriter writer) throws IOException {
|
||||
public void writeTargetTo(BaksmaliWriter writer) throws IOException {
|
||||
if (target >= 0) {
|
||||
writer.write('+');
|
||||
}
|
||||
writer.printSignedIntAsDec(target);
|
||||
writer.writeSignedIntAsDec(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,8 @@
|
||||
package org.jf.baksmali.Adaptors.Format;
|
||||
|
||||
import org.jf.baksmali.Adaptors.MethodDefinition;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.analysis.UnresolvedOdexInstruction;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -41,12 +41,12 @@ public class UnresolvedOdexInstructionMethodItem extends InstructionMethodItem<U
|
||||
super(methodDef, codeAddress, instruction);
|
||||
}
|
||||
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writeThrowTo(writer);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void writeThrowTo(IndentingWriter writer) throws IOException {
|
||||
private void writeThrowTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write("#Replaced unresolvable odex instruction with a throw\n");
|
||||
writer.write("throw ");
|
||||
writeRegister(writer, instruction.objectRegisterNum);
|
||||
|
@ -29,7 +29,7 @@
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.baksmali.BaksmaliOptions;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -73,13 +73,13 @@ public class LabelMethodItem extends MethodItem {
|
||||
}
|
||||
|
||||
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write(':');
|
||||
writer.write(labelPrefix);
|
||||
if (options.sequentialLabels) {
|
||||
writer.printUnsignedLongAsHex(labelSequence);
|
||||
writer.writeUnsignedLongAsHex(labelSequence);
|
||||
} else {
|
||||
writer.printUnsignedLongAsHex(this.getLabelAddress());
|
||||
writer.writeUnsignedLongAsHex(this.getLabelAddress());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import com.google.common.collect.Lists;
|
||||
import org.jf.baksmali.Adaptors.Debug.DebugMethodItem;
|
||||
import org.jf.baksmali.Adaptors.Format.InstructionMethodItemFactory;
|
||||
import org.jf.baksmali.BaksmaliOptions;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.*;
|
||||
import org.jf.dexlib2.analysis.AnalysisException;
|
||||
import org.jf.dexlib2.analysis.AnalyzedInstruction;
|
||||
@ -53,7 +54,6 @@ import org.jf.dexlib2.util.SyntheticAccessorResolver;
|
||||
import org.jf.dexlib2.util.SyntheticAccessorResolver.AccessedMember;
|
||||
import org.jf.dexlib2.util.TypeUtils;
|
||||
import org.jf.util.ExceptionWithContext;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.util.SparseIntArray;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -159,7 +159,7 @@ public class MethodDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeEmptyMethodTo(IndentingWriter writer, Method method,
|
||||
public static void writeEmptyMethodTo(BaksmaliWriter writer, Method method,
|
||||
BaksmaliOptions options) throws IOException {
|
||||
writer.write(".method ");
|
||||
writeAccessFlagsAndRestrictions(writer, method.getAccessFlags(), method.getHiddenApiRestrictions());
|
||||
@ -186,7 +186,7 @@ public class MethodDefinition {
|
||||
writer.write(".end method\n");
|
||||
}
|
||||
|
||||
public void writeTo(IndentingWriter writer) throws IOException {
|
||||
public void writeTo(BaksmaliWriter writer) throws IOException {
|
||||
int parameterRegisterCount = 0;
|
||||
if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) {
|
||||
parameterRegisterCount++;
|
||||
@ -211,10 +211,10 @@ public class MethodDefinition {
|
||||
writer.indent(4);
|
||||
if (classDef.options.localsDirective) {
|
||||
writer.write(".locals ");
|
||||
writer.printSignedIntAsDec(methodImpl.getRegisterCount() - parameterRegisterCount);
|
||||
writer.writeSignedIntAsDec(methodImpl.getRegisterCount() - parameterRegisterCount);
|
||||
} else {
|
||||
writer.write(".registers ");
|
||||
writer.printSignedIntAsDec(methodImpl.getRegisterCount());
|
||||
writer.writeSignedIntAsDec(methodImpl.getRegisterCount());
|
||||
}
|
||||
writer.write('\n');
|
||||
writeParameters(writer, method, methodParameters, classDef.options);
|
||||
@ -301,7 +301,7 @@ public class MethodDefinition {
|
||||
}
|
||||
|
||||
private static void writeAccessFlagsAndRestrictions(
|
||||
IndentingWriter writer, int accessFlags, Set<HiddenApiRestriction> hiddenApiRestrictions)
|
||||
BaksmaliWriter writer, int accessFlags, Set<HiddenApiRestriction> hiddenApiRestrictions)
|
||||
throws IOException {
|
||||
for (AccessFlags accessFlag: AccessFlags.getAccessFlagsForMethod(accessFlags)) {
|
||||
writer.write(accessFlag.toString());
|
||||
@ -313,7 +313,7 @@ public class MethodDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeParameters(IndentingWriter writer, Method method,
|
||||
private static void writeParameters(BaksmaliWriter writer, Method method,
|
||||
List<? extends MethodParameter> parameters,
|
||||
BaksmaliOptions options) throws IOException {
|
||||
boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags());
|
||||
@ -324,7 +324,7 @@ public class MethodDefinition {
|
||||
Collection<? extends Annotation> annotations = parameter.getAnnotations();
|
||||
if ((options.debugInfo && parameterName != null) || annotations.size() != 0) {
|
||||
writer.write(".param p");
|
||||
writer.printSignedIntAsDec(registerNumber);
|
||||
writer.writeSignedIntAsDec(registerNumber);
|
||||
|
||||
if (parameterName != null && options.debugInfo) {
|
||||
writer.write(", ");
|
||||
@ -426,9 +426,9 @@ public class MethodDefinition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write("#@");
|
||||
writer.printUnsignedLongAsHex(codeAddress & 0xFFFFFFFFL);
|
||||
writer.writeUnsignedLongAsHex(codeAddress & 0xFFFFFFFFL);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@ -505,9 +505,9 @@ public class MethodDefinition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write("#@");
|
||||
writer.printUnsignedLongAsHex(codeAddress & 0xFFFFFFFFL);
|
||||
writer.writeUnsignedLongAsHex(codeAddress & 0xFFFFFFFFL);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -55,5 +55,5 @@ public abstract class MethodItem implements Comparable<MethodItem> {
|
||||
return result;
|
||||
}
|
||||
|
||||
public abstract boolean writeTo(IndentingWriter writer) throws IOException;
|
||||
public abstract boolean writeTo(BaksmaliWriter writer) throws IOException;
|
||||
}
|
||||
|
@ -29,9 +29,9 @@
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.baksmali.BaksmaliOptions;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.analysis.AnalyzedInstruction;
|
||||
import org.jf.dexlib2.analysis.RegisterType;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -55,7 +55,7 @@ public class PostInstructionRegisterInfoMethodItem extends MethodItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
int registerInfo = registerFormatter.options.registerInfo;
|
||||
int registerCount = analyzedInstruction.getRegisterCount();
|
||||
BitSet registers = new BitSet(registerCount);
|
||||
@ -82,7 +82,7 @@ public class PostInstructionRegisterInfoMethodItem extends MethodItem {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean writeRegisterInfo(IndentingWriter writer, BitSet registers) throws IOException {
|
||||
private boolean writeRegisterInfo(BaksmaliWriter writer, BitSet registers) throws IOException {
|
||||
int registerNum = registers.nextSetBit(0);
|
||||
if (registerNum < 0) {
|
||||
return false;
|
||||
|
@ -29,11 +29,11 @@
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.baksmali.BaksmaliOptions;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.analysis.AnalyzedInstruction;
|
||||
import org.jf.dexlib2.analysis.MethodAnalyzer;
|
||||
import org.jf.dexlib2.analysis.RegisterType;
|
||||
import org.jf.dexlib2.iface.instruction.*;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -63,7 +63,7 @@ public class PreInstructionRegisterInfoMethodItem extends MethodItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
int registerCount = analyzedInstruction.getRegisterCount();
|
||||
BitSet registers = new BitSet(registerCount);
|
||||
BitSet mergeRegisters = null;
|
||||
@ -171,7 +171,7 @@ public class PreInstructionRegisterInfoMethodItem extends MethodItem {
|
||||
registers.set(registerCount-parameterRegisterCount, registerCount);
|
||||
}
|
||||
|
||||
private void writeFullMerge(IndentingWriter writer, int registerNum) throws IOException {
|
||||
private void writeFullMerge(BaksmaliWriter writer, int registerNum) throws IOException {
|
||||
registerFormatter.writeTo(writer, registerNum);
|
||||
writer.write('=');
|
||||
analyzedInstruction.getPreInstructionRegisterType(registerNum).writeTo(writer);
|
||||
@ -192,7 +192,7 @@ public class PreInstructionRegisterInfoMethodItem extends MethodItem {
|
||||
writer.write("Start:");
|
||||
} else {
|
||||
writer.write("0x");
|
||||
writer.printUnsignedLongAsHex(methodAnalyzer.getInstructionAddress(predecessor));
|
||||
writer.writeUnsignedLongAsHex(methodAnalyzer.getInstructionAddress(predecessor));
|
||||
writer.write(':');
|
||||
}
|
||||
predecessorRegisterType.writeTo(writer);
|
||||
@ -202,7 +202,7 @@ public class PreInstructionRegisterInfoMethodItem extends MethodItem {
|
||||
writer.write('}');
|
||||
}
|
||||
|
||||
private boolean writeRegisterInfo(IndentingWriter writer, BitSet registers,
|
||||
private boolean writeRegisterInfo(BaksmaliWriter writer, BitSet registers,
|
||||
BitSet fullMergeRegisters) throws IOException {
|
||||
boolean firstRegister = true;
|
||||
boolean previousWasFullMerge = false;
|
||||
|
@ -29,24 +29,24 @@
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.baksmali.Adaptors.EncodedValue.EncodedValueAdaptor;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.MethodHandleType;
|
||||
import org.jf.dexlib2.ReferenceType;
|
||||
import org.jf.dexlib2.iface.reference.*;
|
||||
import org.jf.dexlib2.iface.value.EncodedValue;
|
||||
import org.jf.dexlib2.util.ReferenceUtil;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.util.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ReferenceFormatter {
|
||||
public static void writeStringReference(IndentingWriter writer, String item) throws IOException {
|
||||
public static void writeStringReference(BaksmaliWriter writer, String item) throws IOException {
|
||||
writer.write('"');
|
||||
StringUtils.writeEscapedString(writer, item);
|
||||
writer.write('"');
|
||||
}
|
||||
|
||||
public static void writeCallSiteReference(IndentingWriter writer, CallSiteReference callSite) throws IOException {
|
||||
public static void writeCallSiteReference(BaksmaliWriter writer, CallSiteReference callSite) throws IOException {
|
||||
writer.write(callSite.getName());
|
||||
writer.write('(');
|
||||
writer.write('"');
|
||||
@ -66,7 +66,7 @@ public class ReferenceFormatter {
|
||||
writeReference(writer, ReferenceType.METHOD, callSite.getMethodHandle().getMemberReference());
|
||||
}
|
||||
|
||||
public static void writeReference(IndentingWriter writer, int referenceType,
|
||||
public static void writeReference(BaksmaliWriter writer, int referenceType,
|
||||
Reference reference) throws IOException {
|
||||
switch (referenceType) {
|
||||
case ReferenceType.STRING:
|
||||
|
@ -29,7 +29,7 @@
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.baksmali.BaksmaliOptions;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -53,27 +53,27 @@ public class RegisterFormatter {
|
||||
* output the registers in the v<n> format. But if false, then it will check if *both* registers are parameter
|
||||
* registers, and if so, use the p<n> format for both. If only the last register is a parameter register, it will
|
||||
* use the v<n> format for both, otherwise it would be confusing to have something like {v20 .. p1}
|
||||
* @param writer the <code>IndentingWriter</code> to write to
|
||||
* @param writer the <code>BaksmaliWriter</code> to write to
|
||||
* @param startRegister the first register in the range
|
||||
* @param lastRegister the last register in the range
|
||||
*/
|
||||
public void writeRegisterRange(IndentingWriter writer, int startRegister, int lastRegister) throws IOException {
|
||||
public void writeRegisterRange(BaksmaliWriter writer, int startRegister, int lastRegister) throws IOException {
|
||||
if (options.parameterRegisters) {
|
||||
assert startRegister <= lastRegister;
|
||||
|
||||
if (startRegister >= registerCount - parameterRegisterCount) {
|
||||
writer.write("{p");
|
||||
writer.printSignedIntAsDec(startRegister - (registerCount - parameterRegisterCount));
|
||||
writer.writeSignedIntAsDec(startRegister - (registerCount - parameterRegisterCount));
|
||||
writer.write(" .. p");
|
||||
writer.printSignedIntAsDec(lastRegister - (registerCount - parameterRegisterCount));
|
||||
writer.writeSignedIntAsDec(lastRegister - (registerCount - parameterRegisterCount));
|
||||
writer.write('}');
|
||||
return;
|
||||
}
|
||||
}
|
||||
writer.write("{v");
|
||||
writer.printSignedIntAsDec(startRegister);
|
||||
writer.writeSignedIntAsDec(startRegister);
|
||||
writer.write(" .. v");
|
||||
writer.printSignedIntAsDec(lastRegister);
|
||||
writer.writeSignedIntAsDec(lastRegister);
|
||||
writer.write('}');
|
||||
}
|
||||
|
||||
@ -82,18 +82,18 @@ public class RegisterFormatter {
|
||||
* output a register in the v<n> format. If false, then it determines if the register is a parameter register,
|
||||
* and if so, formats it in the p<n> format instead.
|
||||
*
|
||||
* @param writer the <code>IndentingWriter</code> to write to
|
||||
* @param writer the <code>BaksmaliWriter</code> to write to
|
||||
* @param register the register number
|
||||
*/
|
||||
public void writeTo(IndentingWriter writer, int register) throws IOException {
|
||||
public void writeTo(BaksmaliWriter writer, int register) throws IOException {
|
||||
if (options.parameterRegisters) {
|
||||
if (register >= registerCount - parameterRegisterCount) {
|
||||
writer.write('p');
|
||||
writer.printSignedIntAsDec((register - (registerCount - parameterRegisterCount)));
|
||||
writer.writeSignedIntAsDec((register - (registerCount - parameterRegisterCount)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
writer.write('v');
|
||||
writer.printSignedIntAsDec(register);
|
||||
writer.writeSignedIntAsDec(register);
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,10 @@
|
||||
|
||||
package org.jf.baksmali.Adaptors;
|
||||
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.ReferenceType;
|
||||
import org.jf.dexlib2.util.SyntheticAccessorResolver;
|
||||
import org.jf.util.ExceptionWithContext;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -48,7 +48,7 @@ public class SyntheticAccessCommentMethodItem extends MethodItem {
|
||||
return 99.8;
|
||||
}
|
||||
|
||||
public boolean writeTo(IndentingWriter writer) throws IOException {
|
||||
public boolean writeTo(BaksmaliWriter writer) throws IOException {
|
||||
writer.write("# ");
|
||||
switch (accessedMember.accessedMemberType) {
|
||||
case SyntheticAccessorResolver.METHOD:
|
||||
|
@ -31,10 +31,10 @@ package org.jf.baksmali;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
import org.jf.baksmali.Adaptors.ClassDefinition;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.ClassDef;
|
||||
import org.jf.dexlib2.iface.DexFile;
|
||||
import org.jf.util.ClassFileNameHandler;
|
||||
import org.jf.util.IndentingWriter;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.*;
|
||||
@ -131,7 +131,7 @@ public class Baksmali {
|
||||
ClassDefinition classDefinition = new ClassDefinition(options, classDef);
|
||||
|
||||
//write the disassembly
|
||||
Writer writer = null;
|
||||
BaksmaliWriter writer = null;
|
||||
try
|
||||
{
|
||||
File smaliParent = smaliFile.getParentFile();
|
||||
@ -155,8 +155,10 @@ public class Baksmali {
|
||||
BufferedWriter bufWriter = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(smaliFile), "UTF8"));
|
||||
|
||||
writer = new IndentingWriter(bufWriter);
|
||||
classDefinition.writeTo((IndentingWriter)writer);
|
||||
writer = new BaksmaliWriter(
|
||||
bufWriter,
|
||||
options.implicitReferences ? classDef.getType() : null);
|
||||
classDefinition.writeTo(writer);
|
||||
} catch (Exception ex) {
|
||||
System.err.println("\n\nError occurred while disassembling class " + classDescriptor.replace('/', '.') + " - skipping class");
|
||||
ex.printStackTrace();
|
||||
|
@ -28,12 +28,12 @@
|
||||
|
||||
package org.jf.baksmali.Renderers;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class BooleanRenderer {
|
||||
public static void writeTo(IndentingWriter writer, boolean val) throws IOException {
|
||||
public static void writeTo(BaksmaliWriter writer, boolean val) throws IOException {
|
||||
if (val) {
|
||||
writer.write("true");
|
||||
} else {
|
||||
|
@ -28,26 +28,26 @@
|
||||
|
||||
package org.jf.baksmali.Renderers;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ByteRenderer {
|
||||
public static void writeTo(IndentingWriter writer, byte val) throws IOException {
|
||||
public static void writeTo(BaksmaliWriter writer, byte val) throws IOException {
|
||||
if (val<0) {
|
||||
writer.write("-0x");
|
||||
writer.printUnsignedLongAsHex(-val);
|
||||
writer.writeUnsignedLongAsHex(-val);
|
||||
writer.write('t');
|
||||
} else {
|
||||
writer.write("0x");
|
||||
writer.printUnsignedLongAsHex(val);
|
||||
writer.writeUnsignedLongAsHex(val);
|
||||
writer.write('t');
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeUnsignedTo(IndentingWriter writer, byte val) throws IOException {
|
||||
public static void writeUnsignedTo(BaksmaliWriter writer, byte val) throws IOException {
|
||||
writer.write("0x");
|
||||
writer.printUnsignedLongAsHex(val & 0xFF);
|
||||
writer.writeUnsignedLongAsHex(val & 0xFF);
|
||||
writer.write('t');
|
||||
}
|
||||
}
|
||||
|
@ -28,13 +28,13 @@
|
||||
|
||||
package org.jf.baksmali.Renderers;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.util.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CharRenderer {
|
||||
public static void writeTo(IndentingWriter writer, char val) throws IOException {
|
||||
public static void writeTo(BaksmaliWriter writer, char val) throws IOException {
|
||||
writer.write('\'');
|
||||
StringUtils.writeEscapedChar(writer, val);
|
||||
writer.write('\'');
|
||||
|
@ -28,12 +28,12 @@
|
||||
|
||||
package org.jf.baksmali.Renderers;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DoubleRenderer {
|
||||
public static void writeTo(IndentingWriter writer, double val) throws IOException {
|
||||
public static void writeTo(BaksmaliWriter writer, double val) throws IOException {
|
||||
writer.write(Double.toString(val));
|
||||
}
|
||||
}
|
||||
|
@ -28,12 +28,12 @@
|
||||
|
||||
package org.jf.baksmali.Renderers;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FloatRenderer {
|
||||
public static void writeTo(IndentingWriter writer, float val) throws IOException {
|
||||
public static void writeTo(BaksmaliWriter writer, float val) throws IOException {
|
||||
writer.write(Float.toString(val));
|
||||
writer.write('f');
|
||||
}
|
||||
|
@ -28,23 +28,23 @@
|
||||
|
||||
package org.jf.baksmali.Renderers;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IntegerRenderer {
|
||||
public static void writeTo(IndentingWriter writer, int val) throws IOException {
|
||||
public static void writeTo(BaksmaliWriter writer, int val) throws IOException {
|
||||
if (val<0) {
|
||||
writer.write("-0x");
|
||||
writer.printUnsignedLongAsHex(-((long) val));
|
||||
writer.writeUnsignedLongAsHex(-((long) val));
|
||||
} else {
|
||||
writer.write("0x");
|
||||
writer.printUnsignedLongAsHex(val);
|
||||
writer.writeUnsignedLongAsHex(val);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeUnsignedTo(IndentingWriter writer, int val) throws IOException {
|
||||
public static void writeUnsignedTo(BaksmaliWriter writer, int val) throws IOException {
|
||||
writer.write("0x");
|
||||
writer.printUnsignedLongAsHex(val & 0xFFFFFFFFL);
|
||||
writer.writeUnsignedLongAsHex(val & 0xFFFFFFFFL);
|
||||
}
|
||||
}
|
||||
|
@ -28,33 +28,33 @@
|
||||
|
||||
package org.jf.baksmali.Renderers;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class LongRenderer {
|
||||
public static void writeTo(IndentingWriter writer, long val) throws IOException {
|
||||
public static void writeTo(BaksmaliWriter writer, long val) throws IOException {
|
||||
if (val<0) {
|
||||
writer.write("-0x");
|
||||
writer.printUnsignedLongAsHex(-val);
|
||||
writer.writeUnsignedLongAsHex(-val);
|
||||
writer.write('L');
|
||||
} else {
|
||||
writer.write("0x");
|
||||
writer.printUnsignedLongAsHex(val);
|
||||
writer.writeUnsignedLongAsHex(val);
|
||||
writer.write('L');
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeSignedIntOrLongTo(IndentingWriter writer, long val) throws IOException {
|
||||
public static void writeSignedIntOrLongTo(BaksmaliWriter writer, long val) throws IOException {
|
||||
if (val<0) {
|
||||
writer.write("-0x");
|
||||
writer.printUnsignedLongAsHex(-val);
|
||||
writer.writeUnsignedLongAsHex(-val);
|
||||
if (val < Integer.MIN_VALUE) {
|
||||
writer.write('L');
|
||||
}
|
||||
} else {
|
||||
writer.write("0x");
|
||||
writer.printUnsignedLongAsHex(val);
|
||||
writer.writeUnsignedLongAsHex(val);
|
||||
if (val > Integer.MAX_VALUE) {
|
||||
writer.write('L');
|
||||
}
|
||||
|
@ -28,19 +28,19 @@
|
||||
|
||||
package org.jf.baksmali.Renderers;
|
||||
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ShortRenderer {
|
||||
public static void writeTo(IndentingWriter writer, short val) throws IOException {
|
||||
public static void writeTo(BaksmaliWriter writer, short val) throws IOException {
|
||||
if (val < 0) {
|
||||
writer.write("-0x");
|
||||
writer.printUnsignedLongAsHex(-val);
|
||||
writer.writeUnsignedLongAsHex(-val);
|
||||
writer.write('s');
|
||||
} else {
|
||||
writer.write("0x");
|
||||
writer.printUnsignedLongAsHex(val);
|
||||
writer.writeUnsignedLongAsHex(val);
|
||||
writer.write('s');
|
||||
}
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Resources;
|
||||
import junit.framework.Assert;
|
||||
import org.jf.baksmali.Adaptors.ClassDefinition;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.DexFileFactory;
|
||||
import org.jf.dexlib2.Opcodes;
|
||||
import org.jf.dexlib2.analysis.ClassPath;
|
||||
import org.jf.dexlib2.analysis.ClassProvider;
|
||||
import org.jf.dexlib2.iface.ClassDef;
|
||||
import org.jf.dexlib2.iface.DexFile;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -111,7 +111,7 @@ public class AnalysisTest {
|
||||
|
||||
for (ClassDef classDef: dexFile.getClasses()) {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
IndentingWriter writer = new IndentingWriter(stringWriter);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(stringWriter);
|
||||
ClassDefinition classDefinition = new ClassDefinition(options, classDef);
|
||||
classDefinition.writeTo(writer);
|
||||
writer.close();
|
||||
|
@ -35,9 +35,9 @@ import com.google.common.io.ByteStreams;
|
||||
import junit.framework.Assert;
|
||||
import org.antlr.runtime.RecognitionException;
|
||||
import org.jf.baksmali.Adaptors.ClassDefinition;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.iface.ClassDef;
|
||||
import org.jf.smali.SmaliTestUtils;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -88,7 +88,7 @@ public class BaksmaliTestUtils {
|
||||
boolean stripComments)
|
||||
throws IOException {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
IndentingWriter writer = new IndentingWriter(stringWriter);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(stringWriter);
|
||||
ClassDefinition classDefinition = new ClassDefinition(options, classDef);
|
||||
classDefinition.writeTo(writer);
|
||||
writer.close();
|
||||
|
@ -37,6 +37,7 @@ import org.jf.baksmali.Adaptors.ClassDefinition;
|
||||
import org.jf.baksmali.Adaptors.Format.InstructionMethodItem;
|
||||
import org.jf.baksmali.Adaptors.MethodDefinition;
|
||||
import org.jf.baksmali.Adaptors.RegisterFormatter;
|
||||
import org.jf.baksmali.formatter.BaksmaliWriter;
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.HiddenApiRestriction;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
@ -49,7 +50,6 @@ import org.jf.dexlib2.iface.debug.DebugItem;
|
||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction21c;
|
||||
import org.jf.dexlib2.iface.reference.Reference;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -141,7 +141,7 @@ public class InstructionMethodItemTest {
|
||||
InstructionMethodItem methodItem = new InstructionMethodItem<Instruction21c>(methodDefinition, 0, instruction);
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
IndentingWriter indentingWriter = new IndentingWriter(stringWriter);
|
||||
BaksmaliWriter indentingWriter = new BaksmaliWriter(stringWriter);
|
||||
methodItem.writeTo(indentingWriter);
|
||||
|
||||
Assert.assertEquals("#Invalid reference\n#const-string v0, blahblahblah\nnop", stringWriter.toString());
|
||||
|
@ -38,7 +38,6 @@ import org.jf.dexlib2.iface.reference.MethodHandleReference;
|
||||
import org.jf.dexlib2.immutable.ImmutableAnnotationElement;
|
||||
import org.jf.dexlib2.immutable.reference.*;
|
||||
import org.jf.dexlib2.immutable.value.*;
|
||||
import org.jf.util.IndentingWriter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -48,102 +47,92 @@ import java.io.StringWriter;
|
||||
|
||||
public class BaksmaliWriterTest {
|
||||
|
||||
private StringWriter stringWriter;
|
||||
private IndentingWriter output;
|
||||
private StringWriter output;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
stringWriter = new StringWriter();
|
||||
output = new IndentingWriter(stringWriter);
|
||||
output = new StringWriter();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteMethodDescriptor_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeMethodDescriptor(getMethodReferenceWithSpaces());
|
||||
|
||||
Assert.assertEquals(
|
||||
"Ldefining/class/`with spaces`;->`methodName with spaces`(L`param with spaces 1`;L`param with spaces 2`;)" +
|
||||
"Lreturn/type/`with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteShortMethodDescriptor_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeShortMethodDescriptor(getMethodReferenceWithSpaces());
|
||||
|
||||
Assert.assertEquals(
|
||||
"`methodName with spaces`(L`param with spaces 1`;L`param with spaces 2`;)" +
|
||||
"Lreturn/type/`with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteMethodProtoDescriptor_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeMethodProtoDescriptor(getMethodProtoReferenceWithSpaces());
|
||||
|
||||
Assert.assertEquals(
|
||||
"(L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteFieldDescriptor_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeFieldDescriptor(getFieldReferenceWithSpaces());
|
||||
|
||||
Assert.assertEquals("Ldefining/class/`with spaces`;->`fieldName with spaces`:Lfield/`type with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteShortFieldDescriptor_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeShortFieldDescriptor(getFieldReferenceWithSpaces());
|
||||
|
||||
Assert.assertEquals("`fieldName with spaces`:Lfield/`type with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteMethodHandle_fieldAccess_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeMethodHandle(getMethodHandleReferenceForFieldWithSpaces());
|
||||
|
||||
Assert.assertEquals("instance-get@Ldefining/class/`with spaces`;->`fieldName with spaces`:" +
|
||||
"Lfield/`type with spaces`;", stringWriter.toString());
|
||||
"Lfield/`type with spaces`;", output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteMethodHandle_methodAccess_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeMethodHandle(getMethodHandleReferenceForMethodWithSpaces());
|
||||
|
||||
Assert.assertEquals("invoke-instance@Ldefining/class/`with spaces`;->`methodName with spaces`(" +
|
||||
"L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteCallsite_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeCallSite(new ImmutableCallSiteReference(
|
||||
"callsiteName with spaces",
|
||||
@ -162,13 +151,12 @@ public class BaksmaliWriterTest {
|
||||
"L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;)@" +
|
||||
"Ldefining/class/`with spaces`;->`methodName with spaces`(" +
|
||||
"L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteEncodedValue_annotation_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeEncodedValue(new ImmutableAnnotationEncodedValue(
|
||||
"Lannotation/type with spaces;",
|
||||
@ -185,13 +173,12 @@ public class BaksmaliWriterTest {
|
||||
" `element with spaces 2` = Ldefining/class/`with spaces`;->`methodName with spaces`(" +
|
||||
"L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;\n" +
|
||||
".end subannotation",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteEncodedValue_array_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeEncodedValue(new ImmutableArrayEncodedValue(ImmutableList.of(
|
||||
new ImmutableFieldEncodedValue(getFieldReferenceWithSpaces()),
|
||||
@ -202,74 +189,68 @@ public class BaksmaliWriterTest {
|
||||
" Ldefining/class/`with spaces`;->`fieldName with spaces`:Lfield/`type with spaces`;,\n" +
|
||||
" Ldefining/class/`with spaces`;->`methodName with spaces`(L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;\n" +
|
||||
"}",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteEncodedValue_field_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeEncodedValue(new ImmutableFieldEncodedValue(getFieldReferenceWithSpaces()));
|
||||
|
||||
Assert.assertEquals(
|
||||
"Ldefining/class/`with spaces`;->`fieldName with spaces`:Lfield/`type with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteEncodedValue_enum_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeEncodedValue(new ImmutableEnumEncodedValue(getFieldReferenceWithSpaces()));
|
||||
|
||||
Assert.assertEquals(
|
||||
".enum Ldefining/class/`with spaces`;->`fieldName with spaces`:Lfield/`type with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteEncodedValue_method_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeEncodedValue(new ImmutableMethodEncodedValue(getMethodReferenceWithSpaces()));
|
||||
|
||||
Assert.assertEquals(
|
||||
"Ldefining/class/`with spaces`;->`methodName with spaces`(" +
|
||||
"L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteEncodedValue_type_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeEncodedValue(new ImmutableTypeEncodedValue("Ltest/type with spaces;"));
|
||||
|
||||
Assert.assertEquals(
|
||||
"Ltest/`type with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteEncodedValue_methodType_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeEncodedValue(new ImmutableMethodTypeEncodedValue(getMethodProtoReferenceWithSpaces()));
|
||||
|
||||
Assert.assertEquals(
|
||||
"(L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteEncodedValue_methodHandle_withSpaces() throws IOException {
|
||||
BaksmaliWriter writer =
|
||||
new BaksmaliWriter(output);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeEncodedValue(
|
||||
new ImmutableMethodHandleEncodedValue(getMethodHandleReferenceForMethodWithSpaces()));
|
||||
@ -277,7 +258,7 @@ public class BaksmaliWriterTest {
|
||||
Assert.assertEquals(
|
||||
"invoke-instance@Ldefining/class/`with spaces`;->`methodName with spaces`(" +
|
||||
"L`param with spaces 1`;L`param with spaces 2`;)Lreturn/type/`with spaces`;",
|
||||
stringWriter.toString());
|
||||
output.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -296,13 +277,12 @@ public class BaksmaliWriterTest {
|
||||
}
|
||||
|
||||
private String performWriteUnsignedLongAsHex(long value) throws IOException {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
IndentingWriter indentingWriter = new IndentingWriter(stringWriter);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(indentingWriter);
|
||||
output = new StringWriter();
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeUnsignedLongAsHex(value);
|
||||
writer.close();
|
||||
return stringWriter.toString();
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -321,13 +301,12 @@ public class BaksmaliWriterTest {
|
||||
}
|
||||
|
||||
private String performWriteSignedLongAsDec(long value) throws IOException {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
IndentingWriter indentingWriter = new IndentingWriter(stringWriter);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(indentingWriter);
|
||||
output = new StringWriter();
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeSignedLongAsDec(value);
|
||||
writer.close();
|
||||
return stringWriter.toString();
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -340,13 +319,12 @@ public class BaksmaliWriterTest {
|
||||
}
|
||||
|
||||
private String performWriteSignedIntAsDec(int value) throws IOException {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
IndentingWriter indentingWriter = new IndentingWriter(stringWriter);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(indentingWriter);
|
||||
output = new StringWriter();
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeSignedIntAsDec(value);
|
||||
writer.close();
|
||||
return stringWriter.toString();
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -359,13 +337,12 @@ public class BaksmaliWriterTest {
|
||||
}
|
||||
|
||||
private String performWriteUnsignedIntAsDec(int value) throws IOException {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
IndentingWriter indentingWriter = new IndentingWriter(stringWriter);
|
||||
BaksmaliWriter writer = new BaksmaliWriter(indentingWriter);
|
||||
output = new StringWriter();
|
||||
BaksmaliWriter writer = new BaksmaliWriter(output);
|
||||
|
||||
writer.writeUnsignedIntAsDec(value);
|
||||
writer.close();
|
||||
return stringWriter.toString();
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private ImmutableMethodReference getMethodReferenceWithSpaces() {
|
||||
|
@ -173,72 +173,4 @@ public class IndentingWriter extends Writer {
|
||||
indentLevel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void printUnsignedLongAsHex(long value) throws IOException {
|
||||
int bufferIndex = 23;
|
||||
do {
|
||||
int digit = (int)(value & 15);
|
||||
if (digit < 10) {
|
||||
buffer[bufferIndex--] = (char)(digit + '0');
|
||||
} else {
|
||||
buffer[bufferIndex--] = (char)((digit - 10) + 'a');
|
||||
}
|
||||
|
||||
value >>>= 4;
|
||||
} while (value != 0);
|
||||
|
||||
bufferIndex++;
|
||||
|
||||
writeLine(buffer, bufferIndex, 24-bufferIndex);
|
||||
}
|
||||
|
||||
public void printSignedLongAsDec(long value) throws IOException {
|
||||
int bufferIndex = 23;
|
||||
|
||||
if (value < 0) {
|
||||
value *= -1;
|
||||
write('-');
|
||||
}
|
||||
|
||||
do {
|
||||
long digit = value % 10;
|
||||
buffer[bufferIndex--] = (char)(digit + '0');
|
||||
|
||||
value = value / 10;
|
||||
} while (value != 0);
|
||||
|
||||
bufferIndex++;
|
||||
|
||||
writeLine(buffer, bufferIndex, 24-bufferIndex);
|
||||
}
|
||||
|
||||
public void printSignedIntAsDec(int value) throws IOException {
|
||||
int bufferIndex = 15;
|
||||
|
||||
if (value < 0) {
|
||||
value *= -1;
|
||||
write('-');
|
||||
}
|
||||
|
||||
do {
|
||||
int digit = value % 10;
|
||||
buffer[bufferIndex--] = (char)(digit + '0');
|
||||
|
||||
value = value / 10;
|
||||
} while (value != 0);
|
||||
|
||||
bufferIndex++;
|
||||
|
||||
writeLine(buffer, bufferIndex, 16-bufferIndex);
|
||||
}
|
||||
|
||||
public void printUnsignedIntAsDec(int value) throws IOException {
|
||||
int bufferIndex = 15;
|
||||
|
||||
if (value < 0) {
|
||||
printSignedLongAsDec(value & 0xFFFFFFFFL);
|
||||
} else {
|
||||
printSignedIntAsDec(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.util;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class IndentingWriterTest {
|
||||
@Test
|
||||
public void testPrintSignedLongAsDec() throws IOException {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
IndentingWriter writer = new IndentingWriter(stringWriter);
|
||||
|
||||
writer.printUnsignedIntAsDec(-1);
|
||||
writer.close();
|
||||
|
||||
Assert.assertEquals("4294967295", stringWriter.toString());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user