asmdex issueshttps://gitlab.ow2.org/asm/asmdex/-/issues2017-12-24T09:25:37Zhttps://gitlab.ow2.org/asm/asmdex/-/issues/316470Instruction getting wrongly transformed.2017-12-24T09:25:37ZvipinInstruction getting wrongly transformed.```
Problem:-
java.lang.IllegalArgumentException: The number 28 can't be held in 4 bits !
at
org.ow2.asmdex.instruction.Instruction.test4BitsLimit(Instruction.java:150)
at
org.ow2.asmdex.instruction.Instruction.test4BitsL...```
Problem:-
java.lang.IllegalArgumentException: The number 28 can't be held in 4 bits !
at
org.ow2.asmdex.instruction.Instruction.test4BitsLimit(Instruction.java:150)
at
org.ow2.asmdex.instruction.Instruction.test4BitsLimit(Instruction.java:176)
at
org.ow2.asmdex.instruction.InstructionFormat35C.<init>
(InstructionFormat35C.java:170)
InstructionFormat35C in asmdex source code:-
public InstructionFormat35C(int opcode, String type, int[] registers) {
super(opcode);
this.type = type;
this.registers = registers;
Instruction.test4BitsLimit(registers);
}
Registers-> [28, 29]
test4BitsLimit(...) throws up since it expects registers in the range 0..15
Any idea why the registers are out of bound in the above case?
From Pierre:-
The mistake is in InstructionEncoder.encodeMultiANewArrayInsn
The main difference with method calls instruction is that the visitor does not
have the opcode as argument. So it does not know
the format it should use.
The test do decide the format is wrong. Not only the number of arguments must
be bellow 5 but the registers must also be bellow
16. A quick and dirty solution is to test the last register.
If it is above 15 then when must use a 3RC.
So the test is now
int l = registers.length;
if (l <= 5 && l > 0 && registers[l - 1] < 16)
If there was another register above 15 but the last is below then the format is
wrong anyway.
I will check later where and how the complete check on the correctness of
indices is done.
```https://gitlab.ow2.org/asm/asmdex/-/issues/316341something wrong while visitAnnotationDefault2017-12-24T09:25:37ZGhost Usersomething wrong while visitAnnotationDefault```
dalvik got 'some/type' element 'value' incomplete. especial there is an array
value. test code:
enum C {
X, Y
}
public @interface B {
String[] b() default { "1", "2" };
C[] c() default { C.X, C.Y ...```
dalvik got 'some/type' element 'value' incomplete. especial there is an array
value. test code:
enum C {
X, Y
}
public @interface B {
String[] b() default { "1", "2" };
C[] c() default { C.X, C.Y };
}
here is my solution:
for Reader
I record all the Ldalvik/annotation/AnnotationDefault; Annotation visit to
AnnotationNodes, and play them when visiting Methods.
for Writer
I record all visitAnnotationDefault visit to AnnotationNodes, and play them in
the ClassWrite.visitEnd().
This works for me, here is my patch
```https://gitlab.ow2.org/asm/asmdex/-/issues/316332no visitLabel when using AsmDexifierApplicationVisitor to generate code2017-12-24T09:25:37ZGhost Userno visitLabel when using AsmDexifierApplicationVisitor to generate code```
all code generated is just like this
Label l1 = new Label();
mv.visitJumpInsn(INSN_GOTO, l1, 0, 0);
this no visitLabel(l1) for it;
version is svn r1620.
after a little modification to the code, it ...```
all code generated is just like this
Label l1 = new Label();
mv.visitJumpInsn(INSN_GOTO, l1, 0, 0);
this no visitLabel(l1) for it;
version is svn r1620.
after a little modification to the code, it works for me, here is the patch for
it.
```https://gitlab.ow2.org/asm/asmdex/-/issues/316339asmdex adding codeitem to native method2017-10-02T21:00:45ZGhost Userasmdex adding codeitem to native method```
here is my path
``````
here is my path
```https://gitlab.ow2.org/asm/asmdex/-/issues/316340got dalvik error invalid type "Lsome/adf"2017-10-02T21:00:45ZGhost Usergot dalvik error invalid type "Lsome/adf"```
the error is caused by the missing ';' dealing inner class.
here is my path
``````
the error is caused by the missing ';' dealing inner class.
here is my path
```https://gitlab.ow2.org/asm/asmdex/-/issues/316371MethodWriter should not accept to write bogus instructions2017-10-02T21:00:45ZpcregutMethodWriter should not accept to write bogus instructions```
In the abstract representation of instructions, register indexes can be
arbitrarily large. This is useful when we write a transformation, but when we
dump the code, the writer should check the bounds and throw an exception. Most
inst...```
In the abstract representation of instructions, register indexes can be
arbitrarily large. This is useful when we write a transformation, but when we
dump the code, the writer should check the bounds and throw an exception. Most
instructions only accept either the first 256 registers or even the first 16
registers (eg. invokes).
```https://gitlab.ow2.org/asm/asmdex/-/issues/316378Crash when parsing annotations.2017-10-02T21:00:45ZvipinCrash when parsing annotations.```
Crash when parsing annotations in the dex. I have attached the dex file.
java.lang.ArrayIndexOutOfBoundsException: 48379650
at
org.ow2.asmdex.lowLevelUtils.DexFileReader.getStringItemFromStringIndex(DexFile
Reader.java:104)
...```
Crash when parsing annotations in the dex. I have attached the dex file.
java.lang.ArrayIndexOutOfBoundsException: 48379650
at
org.ow2.asmdex.lowLevelUtils.DexFileReader.getStringItemFromStringIndex(DexFile
Reader.java:104)
at
org.ow2.asmdex.ApplicationReader.interpretEncodedValue(ApplicationReader.java:9
34)
at
org.ow2.asmdex.ApplicationReader.readEncodedValue(ApplicationReader.java:874)
at
org.ow2.asmdex.ApplicationReader.readAnnotationElement(ApplicationReader.java:1
494)
at
org.ow2.asmdex.ApplicationReader.readEncodedAnnotation(ApplicationReader.java:1
518)
at
org.ow2.asmdex.ApplicationReader.readEncodedValue(ApplicationReader.java:861)
at
org.ow2.asmdex.ApplicationReader.readAnnotationElement(ApplicationReader.java:1
494)
at
org.ow2.asmdex.ApplicationReader.parseSpecificAnnotations(ApplicationReader.jav
a:1473)
at
org.ow2.asmdex.ApplicationReader.readDefaultAnnotations(ApplicationReader.java:
1271)
at
org.ow2.asmdex.ApplicationReader.visitClass(ApplicationReader.java:561)
at org.ow2.asmdex.ApplicationReader.accept(ApplicationReader.java:437)
at org.ow2.asmdex.ApplicationReader.accept(ApplicationReader.java:338)
```https://gitlab.ow2.org/asm/asmdex/-/issues/316368asmdex fails to create a proper dex2017-10-02T21:00:45Zvipinasmdex fails to create a proper dex```
I take a dex file and run it through a passthrough pipeline:-
RulesManager rm = new RulesManager(rules);
ApplicationReader ar = new ApplicationReader(api,
inFile);//mergedFile);
ApplicationWriter aw = new ApplicationWri...```
I take a dex file and run it through a passthrough pipeline:-
RulesManager rm = new RulesManager(rules);
ApplicationReader ar = new ApplicationReader(api,
inFile);//mergedFile);
ApplicationWriter aw = new ApplicationWriter();
ApplicationVisitor aa = new ReferenceChanger(rm, api,
aw);
ar.accept(aa, 0);
byte [] b = aw.toByteArray();
FileOutputStream fout = new
FileOutputStream("c:\\test.dex");
fout.write(b);
fout.close();
The generated dex is not proper. I am seeing this with multiple dex
files.
C:\>dexdump test.dex
Processing 'test.dex'...
E/dalvikvm( 4552): outsSize (13) > registersSize (12)
E/dalvikvm( 4552): Trouble with item 1492 @ offset 0x90938
E/dalvikvm( 4552): Swap of section type 2001 failed
E/dalvikvm( 4552): ERROR: Byte swap + verify failed
ERROR: Failed structural verification of 'test.dex'
```https://gitlab.ow2.org/asm/asmdex/-/issues/316394parameter annotation not working2017-10-02T21:00:45Zvipinparameter annotation not working```
package annotations;
public abstract interface Annotation<T>
{
public abstract boolean apply(@Test T paramT);
public abstract boolean equals(@Test Object paramObject);
}
@interface Test
{
}
asmdex fails to process a dex ...```
package annotations;
public abstract interface Annotation<T>
{
public abstract boolean apply(@Test T paramT);
public abstract boolean equals(@Test Object paramObject);
}
@interface Test
{
}
asmdex fails to process a dex file that contains the above annotation.
resultant dex file post visiting is invalid.
```https://gitlab.ow2.org/asm/asmdex/-/issues/316395SubAnnotation value lost when running through asmdex2017-10-02T21:00:45ZvipinSubAnnotation value lost when running through asmdex```
Attached is the dex file.
If you baksmali you will see this:-
.annotation system Ldalvik/annotation/AnnotationDefault;
value = .subannotation Lorg/codehaus/jackson/annotate/JsonAutoDetect;
creatorVisibility = .enu...```
Attached is the dex file.
If you baksmali you will see this:-
.annotation system Ldalvik/annotation/AnnotationDefault;
value = .subannotation Lorg/codehaus/jackson/annotate/JsonAutoDetect;
creatorVisibility = .enum
Lorg/codehaus/jackson/annotate/JsonAutoDetect$Visibility;-
>DEFAULT:Lorg/codehaus/jackson/annotate/JsonAutoDetect$Visibility;
fieldVisibility = .enum
Lorg/codehaus/jackson/annotate/JsonAutoDetect$Visibility;-
>DEFAULT:Lorg/codehaus/jackson/annotate/JsonAutoDetect$Visibility;
getterVisibility = .enum
Lorg/codehaus/jackson/annotate/JsonAutoDetect$Visibility;-
>DEFAULT:Lorg/codehaus/jackson/annotate/JsonAutoDetect$Visibility;
isGetterVisibility = .enum
Lorg/codehaus/jackson/annotate/JsonAutoDetect$Visibility;-
>DEFAULT:Lorg/codehaus/jackson/annotate/JsonAutoDetect$Visibility;
setterVisibility = .enum
Lorg/codehaus/jackson/annotate/JsonAutoDetect$Visibility;-
>DEFAULT:Lorg/codehaus/jackson/annotate/JsonAutoDetect$Visibility;
value = {
.enum Lorg/codehaus/jackson/annotate/JsonMethod;-
>ALL:Lorg/codehaus/jackson/annotate/JsonMethod;
}
.end subannotation
.end annotation
If you run the attached dex file through asmdex, the subannotation
value is lost in the generated dex. Missing portion:-
value = {
.enum Lorg/codehaus/jackson/annotate/JsonMethod;-
>ALL:Lorg/codehaus/jackson/annotate/JsonMethod;
}
```https://gitlab.ow2.org/asm/asmdex/-/issues/316398output dex generated is invalid2017-10-02T21:00:45Zvipinoutput dex generated is invalid```
Attached is the input dex.
I think the problem is happening due to two things:-
1) we dont clear default annotations.(Bug 316397)
2) There is some problem with uniqueness of items in the
AnnotationDirectoryItem...```
Attached is the input dex.
I think the problem is happening due to two things:-
1) we dont clear default annotations.(Bug 316397)
2) There is some problem with uniqueness of items in the
AnnotationDirectoryItems (constantpool.java)
/**
* HashSet of annotation_directory_items. They are unique, but we don't
care about their order.
*/
private HashSet<AnnotationDirectoryItem> annotationDirectoryItems = new
HashSet<AnnotationDirectoryItem>();
When I remove the uniqueness by returning always false from equals(...)
function in AnnotationDirectoryItem, it works
[AnnotationDirectoryItem.java]
@Override
public boolean equals(Object obj) {
return false;
}
```https://gitlab.ow2.org/asm/asmdex/-/issues/316374read error if the arrayElementsAnnotationVisitor is null2017-10-02T21:00:45ZGhost Userread error if the arrayElementsAnnotationVisitor is null```
dex put annotation values in a sequence, if we need to skip a value(a null visitor). we need to read the value even if the visitor is null before visit next value.
test case:
@Test
public void test() {
ApplicationWri...```
dex put annotation values in a sequence, if we need to skip a value(a null visitor). we need to read the value even if the visitor is null before visit next value.
test case:
@Test
public void test() {
ApplicationWriter aw = new ApplicationWriter();
ClassVisitor cv = aw.visitClass(0, "a", null, "java/lang/Object", null);
AnnotationVisitor av = cv.visitAnnotation("LAnno;", true);
av.visit("a", 1);
AnnotationVisitor av2 = av.visitArray("btheArray");
av2.visit(null, "a1");
av2.visit(null, "a2");
av2.visitEnd();
av.visit("c", "c");
av.visitEnd();
cv.visitEnd();
aw.visitEnd();
ApplicationReader ar = new ApplicationReader(Opcodes.ASM4, aw.toByteArray());
ar.accept(new ApplicationVisitor(Opcodes.ASM4) {
@Override
public ClassVisitor visitClass(int access, String name, String[] signature, String superName,
String[] interfaces) {
return new ClassVisitor(Opcodes.ASM4) {
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
return new AnnotationVisitor(Opcodes.ASM4) {
@Override
public AnnotationVisitor visitArray(String name) {
return null;// skip the array
}
};
}
};
}
}, 0);
}
here is my patch.
```https://gitlab.ow2.org/asm/asmdex/-/issues/316387dex with annotation fails post transformation2017-10-02T21:00:45Zvipindex with annotation fails post transformation```
Attaches two classes:-
classes.dex. I run this through
ApplicationWriter aw = new ApplicationWriter();
ApplicationVisitor avr = new ApplicationVisitorRaw(aw);
aw.visit();
ApplicationReader ar = new
ApplicationReader(Op...```
Attaches two classes:-
classes.dex. I run this through
ApplicationWriter aw = new ApplicationWriter();
ApplicationVisitor avr = new ApplicationVisitorRaw(aw);
aw.visit();
ApplicationReader ar = new
ApplicationReader(Opcodes.ASM4, dexFile);
ar.accept(avr, 0);
aw.visitEnd();
The out.dex that is generated is improper and dexdump fails.
```https://gitlab.ow2.org/asm/asmdex/-/issues/316405filled-new-array/range instruction rewritten as filled-new-aray instruction2017-10-02T21:00:45Zkrishnanm86filled-new-array/range instruction rewritten as filled-new-aray instruction```
ASMDex tends to rewrite Filled-new-array-range instructions as filled-new-array.
Bug: >>Number greater than 16<< cannot be stored in 4-bit register exception is
thrown with "Apks" which have filled-new-array/range instructions whic...```
ASMDex tends to rewrite Filled-new-array-range instructions as filled-new-array.
Bug: >>Number greater than 16<< cannot be stored in 4-bit register exception is
thrown with "Apks" which have filled-new-array/range instructions which access
registers greater than 16 .
Cause (In ASMDex) : Instruction.test4bitslimit method fails.
Specific Cause (in ASMDex) : visitMultiNewArray Instruction is being called
even for filled-new-array/range instruction which rewrites the instruction as
filled-new-array in the transformed dex file.
I have included a test apk which fails. You dont have to do any sort of
instrumentation. Just use ASmDex to write the dex as is into a new file.
```https://gitlab.ow2.org/asm/asmdex/-/issues/316397Stale annotations getting in classes2017-10-02T21:00:45ZvipinStale annotations getting in classes```
This seems to be happening because defaultAnnotations hashmap which is
part of ApplicationReader class is not cleared when visiting classes.
Download the apk and extract the classes.dex from
http://www.android...```
This seems to be happening because defaultAnnotations hashmap which is
part of ApplicationReader class is not cleared when visiting classes.
Download the apk and extract the classes.dex from
http://www.androiddrawer.com/7694/download-facebook-2-0-app-apk/
After runing through asmdex, decompile the output dex
out\com\facebook\common\json\jsonmirror\JMAutogen.smali will contain additional
annotations
patch is here:-
Index: src/org/ow2/asmdex/ApplicationReader.java
===================================================================
--- src/org/ow2/asmdex/ApplicationReader.java (revision 1656)
+++ src/org/ow2/asmdex/ApplicationReader.java (working copy)
@@ -542,7 +542,6 @@
classVisitor.visitSource(sourceFile, null);
}
-
// Reads the annotations. The Class annotations are parsed and
visited directly.
// The field, method and parameter annotations are stored into
three maps, to
// to speed up the search when parsing these elements later.
@@ -563,10 +562,13 @@
// wants them in the Methods they are
linked to, so we have to store them and
// use them later.
dexFile.seek(classAnnotationsOffset);
// Get to the annotation_set_item.
+
readDefaultAnnotations();
dexFile.seek(annotationsOffset + 4); //
Get to the annotations_directory_item, fields_size field.
}
+ else
+ defaultAnnotations.clear();
// Now pointing on the
annotations_directory_item, fields_size field.
// We build the annotations maps for use later.
@@ -1252,7 +1254,6 @@
{
continue;
}
-
AnnotationVisitor annotationVisitor = null;
if (visitorType == VisitorType.classVisitor) {
annotationVisitor =
((ClassVisitor)visitor).visitAnnotation(annotationType, isAnnotationVisible);
```https://gitlab.ow2.org/asm/asmdex/-/issues/316433AsmDex: Instrumentation of move_16 or move_wide_16 instructions for Double an...2017-10-02T21:00:44ZzhazkonyaAsmDex: Instrumentation of move_16 or move_wide_16 instructions for Double and Float type inserts move or move_wide moving from register v0->v14.```
I'm currently trying to instrument *.apk files and move register value to
another register. By default I used insn_move_16 instruction to move primitive
type registers. But Asmdex for the double and float types it inserts insn_move...```
I'm currently trying to instrument *.apk files and move register value to
another register. By default I used insn_move_16 instruction to move primitive
type registers. But Asmdex for the double and float types it inserts insn_move
instruction for moving from v0->v14. I also tried with insn_move_wide_16 but
again it inserts insn_move_wide and that causes out of range error. I'm sending
screenshot of errors for move_16 and move_wide_16 cases. Pls, find it attached.
Do you why it happeds and how I can solve this problem?
thank you in advance!
```https://gitlab.ow2.org/asm/asmdex/-/issues/316490Incorrect output DEX file2017-10-02T21:00:44ZmrlespikeIncorrect output DEX file```
The attached simple test class simply reads a DEX file and visits all classes/methods and writes
out a new DEX file. For some input DEX files, the resulting output DEX file would be incorrect and cause
dexdump to generate the error ...```
The attached simple test class simply reads a DEX file and visits all classes/methods and writes
out a new DEX file. For some input DEX files, the resulting output DEX file would be incorrect and cause
dexdump to generate the error shown below.
E/dalvikvm(16494): Invalid annotations_directory_item
E/dalvikvm(16494): Trouble with item 186 @ offset 0xc14c0
E/dalvikvm(16494): Cross-item verify of section type 0006 failed
E/dalvikvm(16494): ERROR: Byte swap + verify failed
Will attach an input DEX file is also attached.
```https://gitlab.ow2.org/asm/asmdex/-/issues/316426Label.toString() causes a jvm crash on 64-bit machines2017-10-02T21:00:44ZmrlespikeLabel.toString() causes a jvm crash on 64-bit machines```
In the code below (from org.ow2.asmdex.structureCommon.Label), the resulting integer in the
StringBuilder(int) constructor is very very large when running in 64-bit mode. A workaround is to run in
32-bit mode.
public String to...```
In the code below (from org.ow2.asmdex.structureCommon.Label), the resulting integer in the
StringBuilder(int) constructor is very very large when running in 64-bit mode. A workaround is to run in
32-bit mode.
public String toString() {
StringBuilder result = new StringBuilder('L' + System.identityHashCode(this));
if ((status & RESOLVED) > 0) {
result.append(" (offset 0x" + Integer.toHexString(position) + ", line " + line + ")");
}
return result.toString();
}
```https://gitlab.ow2.org/asm/asmdex/-/issues/316471NullPointerException crash2017-10-02T21:00:44ZvipinNullPointerException crash```
Exception in thread "main" java.lang.NullPointerException
at
org.ow2.asmdex.structureWriter.ConstantPool.getStringIndex(ConstantPool.java:38
9)
at
org.ow2.asmdex.ApplicationWriter.writeAnnotationItems(ApplicationWriter.java:87
7)...```
Exception in thread "main" java.lang.NullPointerException
at
org.ow2.asmdex.structureWriter.ConstantPool.getStringIndex(ConstantPool.java:38
9)
at
org.ow2.asmdex.ApplicationWriter.writeAnnotationItems(ApplicationWriter.java:87
7)
at
org.ow2.asmdex.ApplicationWriter.generateDexFile(ApplicationWriter.java:475)
at
org.ow2.asmdex.ApplicationWriter.visitEnd(ApplicationWriter.java:276)
repro is simple(apk is attached to bug):-
public static class ApplicationVisitorRaw extends ApplicationVisitor {
public ApplicationVisitorRaw(ApplicationVisitor ar) {
super(Opcodes.ASM4, ar);
}
@Override
public void visit() {
}
@Override
public void visitEnd() {
}
}
ApplicationWriter aw = new ApplicationWriter();
ApplicationVisitor avr = new ApplicationVisitorRaw(aw);
aw.visit();
ar.accept(avr, 0);
```https://gitlab.ow2.org/asm/asmdex/-/issues/316473crash2017-10-02T21:00:44Zvipincrash```
Exception in thread "main" java.lang.NullPointerException
at
org.ow2.asmdex.structureWriter.ConstantPool.getStringIndex(ConstantPool.java:38
9)
at
org.ow2.asmdex.ApplicationWriter.writeAnnotationItems(ApplicationWriter.java:87
7)...```
Exception in thread "main" java.lang.NullPointerException
at
org.ow2.asmdex.structureWriter.ConstantPool.getStringIndex(ConstantPool.java:38
9)
at
org.ow2.asmdex.ApplicationWriter.writeAnnotationItems(ApplicationWriter.java:87
7)
at
org.ow2.asmdex.ApplicationWriter.generateDexFile(ApplicationWriter.java:475)
at
org.ow2.asmdex.ApplicationWriter.visitEnd(ApplicationWriter.java:276)
repro is simple(apk is attached to bug):-
public static class ApplicationVisitorRaw extends ApplicationVisitor {
public ApplicationVisitorRaw(ApplicationVisitor ar) {
super(Opcodes.ASM4, ar);
}
@Override
public void visit() {
}
@Override
public void visitEnd() {
}
}
ApplicationWriter aw = new ApplicationWriter();
ApplicationVisitor avr = new ApplicationVisitorRaw(aw);
aw.visit();
ar.accept(avr, 0);
```