Commit 1ba19d36 authored by Skylot's avatar Skylot

core: fix annotations number decoder

parent 07402ba4
......@@ -106,9 +106,9 @@ public class TypeGen {
}
private static String wrapNegNum(boolean lz, String str) {
if (lz)
return "(" + str + ")";
else
// if (lz)
// return "(" + str + ")";
// else
return str;
}
}
......@@ -11,7 +11,7 @@ import jadx.core.dex.nodes.MethodNode;
import jadx.core.utils.exceptions.DecodeException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -43,7 +43,6 @@ public class AnnotationsParser {
for (int i = 0; i < annotated_methods_size; i++) {
MethodNode m = cls.searchMethodById(section.readInt());
m.getAttributes().add(readAnnotationSet(section.readInt()));
// LOG.info(m + " " + m.getAttributes());
}
for (int i = 0; i < annotated_parameters_size; i++) {
......@@ -80,17 +79,17 @@ public class AnnotationsParser {
};
public static Annotation readAnnotation(DexNode dex, Section s, boolean readVisibility) throws DecodeException {
EncValueParser ep = new EncValueParser(dex, s);
EncValueParser parser = new EncValueParser(dex, s);
Visibility visibility = null;
if (readVisibility)
if (readVisibility) {
visibility = visibilities[s.readByte()];
}
int typeIndex = s.readUleb128();
int size = s.readUleb128();
Map<String, Object> values = new HashMap<String, Object>(size);
Map<String, Object> values = new LinkedHashMap<String, Object>(size);
for (int i = 0; i < size; i++) {
String name = dex.getString(s.readUleb128());
values.put(name, ep.parseValue());
values.put(name, parser.parseValue());
}
return new Annotation(visibility, dex.getType(typeIndex), values);
}
......
......@@ -22,9 +22,9 @@ public class EncValueParser extends EncodedValueReader {
}
public Object parseValue() throws DecodeException {
int argAndType = in.readByte() & 0xff;
int type = argAndType & 0x1f;
int arg = (argAndType & 0xe0) >> 5;
int argAndType = in.readByte() & 0xFF;
int type = argAndType & 0x1F;
int arg = (argAndType & 0xE0) >> 5;
int size = arg + 1;
switch (type) {
......@@ -32,34 +32,35 @@ public class EncValueParser extends EncodedValueReader {
return null;
case ENCODED_BOOLEAN:
return Boolean.valueOf(arg == 1);
return arg == 1;
case ENCODED_BYTE:
return Byte.valueOf((byte) parseNumber(size));
return in.readByte();
case ENCODED_SHORT:
return Short.valueOf((short) parseNumber(size));
return (short) parseNumber(size, true);
case ENCODED_CHAR:
return Character.valueOf((char) parseNumber(size));
return (char) parseNumber(size, false);
case ENCODED_INT:
return Integer.valueOf((int) parseNumber(size));
return (int) parseNumber(size, true);
case ENCODED_LONG:
return Long.valueOf(parseNumber(size));
return parseNumber(size, true);
case ENCODED_FLOAT:
return Float.intBitsToFloat((int) parseNumber(size));
return Float.intBitsToFloat((int) parseNumber(size, false));
case ENCODED_DOUBLE:
return Double.longBitsToDouble(parseNumber(size));
return Double.longBitsToDouble(parseNumber(size, false));
case ENCODED_STRING:
return dex.getString((int) parseNumber(size));
return dex.getString((int) parseNumber(size, false));
case ENCODED_TYPE:
return dex.getType((int) parseNumber(size));
return dex.getType((int) parseNumber(size, false));
case ENCODED_METHOD:
return MethodInfo.fromDex(dex, (int) parseNumber(size));
return MethodInfo.fromDex(dex, (int) parseNumber(size, false));
case ENCODED_FIELD:
case ENCODED_ENUM:
return FieldInfo.fromDex(dex, (int) parseNumber(size));
return FieldInfo.fromDex(dex, (int) parseNumber(size, false));
case ENCODED_ARRAY:
int count = Leb128Utils.readUnsignedLeb128(in);
......@@ -75,11 +76,16 @@ public class EncValueParser extends EncodedValueReader {
throw new DecodeException("Unknown encoded value type: 0x" + Integer.toHexString(type));
}
private long parseNumber(int byteCount) {
private long parseNumber(int byteCount, boolean isSignExtended) {
long result = 0;
int shift = 0;
for (int i = 0; i < byteCount; i++) {
result |= (long) (in.readByte() & 0xff) << shift;
int shift = 8;
int first = in.readByte() & 0xFF;
if (isSignExtended && (first & 0x80) != 0) {
result = ~result << shift;
}
result |= (long) first;
for (int i = 1; i < byteCount; i++) {
result |= (long) (in.readByte() & 0xFF) << shift;
shift += 8;
}
return result;
......
package jadx.tests.internal;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
public class TestAnnotations extends InternalJadxTest {
public static class TestCls {
private static @interface A {
int a();
}
@A(a = -1)
public void method1() {
}
private static @interface V {
boolean value();
}
@V(false)
public void method2() {
}
private static @interface D {
float value() default 1.1f;
}
@D
public void method3() {
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, not(containsString("@A(a = 255)")));
assertThat(code, containsString("@A(a = -1)"));
assertThat(code, containsString("@V(false)"));
assertThat(code, not(containsString("@D()")));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment