Refactor dexlib so that the output is generated directly, instead of using the StringTemplate library

git-svn-id: https://smali.googlecode.com/svn/trunk@681 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com
2010-04-03 23:01:17 +00:00
parent a7139f6586
commit 6eae34831f
51 changed files with 1836 additions and 1345 deletions

View File

@ -31,13 +31,15 @@ package org.jf.dexlib;
import org.jf.dexlib.Util.ExceptionWithContext;
public enum AnnotationVisibility {
BUILD((byte)0),
RUNTIME((byte)1),
SYSTEM((byte)2);
BUILD((byte)0, "build"),
RUNTIME((byte)1, "runtime"),
SYSTEM((byte)2, "system");
public final byte value;
private AnnotationVisibility(byte value) {
public final String visibility;
private AnnotationVisibility(byte value, String visibility) {
this.value = value;
this.visibility = visibility;
}
public static AnnotationVisibility fromByte(byte value) {

View File

@ -354,6 +354,10 @@ public class MethodAnalyzer {
return instructions.getValues();
}
public ClassDataItem.EncodedMethod getMethod() {
return this.encodedMethod;
}
public ValidationException getValidationException() {
return validationException;
}

View File

@ -30,6 +30,9 @@ package org.jf.dexlib.Code.Analysis;
import org.jf.dexlib.TypeIdItem;
import static org.jf.dexlib.Code.Analysis.ClassPath.ClassDef;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
public class RegisterType {
@ -54,6 +57,16 @@ public class RegisterType {
return "(" + category.name() + (type==null?"":("," + type.getClassType())) + ")";
}
public void writeTo(Writer writer) throws IOException {
writer.write('(');
writer.write(category.name());
if (type != null) {
writer.write(',');
writer.write(type.getClassType());
}
writer.write(')');
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -16,6 +16,9 @@
package org.jf.dexlib.Util;
import java.io.IOException;
import java.io.Writer;
/**
* Constants of type <code>CONSTANT_Utf8_info</code>.
*/
@ -166,6 +169,55 @@ public final class Utf8Utils {
" at offset " + Hex.u4(offset));
}
public static void writeEscapedChar(Writer writer, char c) throws IOException {
if ((c >= ' ') && (c < 0x7f)) {
if ((c == '\'') || (c == '\"') || (c == '\\')) {
writer.write('\\');
}
writer.write(c);
return;
} else if (c <= 0x7f) {
switch (c) {
case '\n': writer.write("\\n"); return;
case '\r': writer.write("\\r"); return;
case '\t': writer.write("\\t"); return;
}
}
writer.write("\\u");
writer.write(Character.forDigit(c >> 12, 16));
writer.write(Character.forDigit((c >> 8) & 0x0f, 16));
writer.write(Character.forDigit((c >> 4) & 0x0f, 16));
writer.write(Character.forDigit(c & 0x0f, 16));
}
public static void writeEscapedString(Writer writer, String value) throws IOException {
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if ((c >= ' ') && (c < 0x7f)) {
if ((c == '\'') || (c == '\"') || (c == '\\')) {
writer.write('\\');
}
writer.write(c);
continue;
} else if (c <= 0x7f) {
switch (c) {
case '\n': writer.write("\\n"); continue;
case '\r': writer.write("\\r"); continue;
case '\t': writer.write("\\t"); continue;
}
}
writer.write("\\u");
writer.write(Character.forDigit(c >> 12, 16));
writer.write(Character.forDigit((c >> 8) & 0x0f, 16));
writer.write(Character.forDigit((c >> 4) & 0x0f, 16));
writer.write(Character.forDigit(c & 0x0f, 16));
}
}
public static String escapeString(String value) {
int len = value.length();
StringBuilder sb = new StringBuilder(len * 3 / 2);