rallat / smali

Automatically exported from code.google.com/p/smali
0 stars 0 forks source link

Issues with Google Guice with baksmali/smali v2.0.3 #220

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What seems to be the problem?
After decompiling and recompiling an APK that uses Google Guice with 
baksmali-2.0.3 and smali-2.0.3, I am unable to run dex2jar on the APK.
However, I don't have the same issues with baksmali/smali version 1.4.1

What is the exact smali/baksmali command that you ran?
java -jar baksmali-2.0.3.jar <apk>
java -jar smali-2.0.3.jar out

What version of smali/baksmali are you using? What rom are you working
from?
2.0.3

What is the airspeed velocity of an unladen swallow?

Please provide any additional information below: error messages, symptoms,
etc.
dex2jar out.dex -> out-dex2jar.jar
com.googlecode.dex2jar.DexException: while accept 
method:[Lcom/google/inject/InjectorImpl;.<init>(Lcom/google/inject/InjectorImpl;
Lcom/google/inject/State;Lcom/google/inject/Initializer;)V]
    at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:694)
    at com.googlecode.dex2jar.reader.DexFileReader.acceptClass(DexFileReader.java:436)
    at com.googlecode.dex2jar.reader.DexFileReader.accept(DexFileReader.java:323)
    at com.googlecode.dex2jar.v3.Dex2jar.doTranslate(Dex2jar.java:85)
    at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:261)
    at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:252)
    at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:110)
    at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:174)
    at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:34)
Caused by: com.googlecode.dex2jar.DexException: while accept parameter 
annotation in 
method:[Lcom/google/inject/InjectorImpl;.<init>(Lcom/google/inject/InjectorImpl;
Lcom/google/inject/State;Lcom/google/inject/Initializer;)V], parameter:[1]
    at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:663)
    ... 8 more
Caused by: com.googlecode.dex2jar.DexException: Not support yet.
    at com.googlecode.dex2jar.reader.Constant.ReadConstant(Constant.java:128)
    at com.googlecode.dex2jar.reader.DexAnnotationReader.accept(DexAnnotationReader.java:58)
    at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:660)
    ... 8 more

Original issue reported on code.google.com by dongjuna...@gmail.com on 23 Sep 2014 at 2:17

GoogleCodeExporter commented 9 years ago
Looks like a problem with dex2jar to me.. :)

Original comment by jesusfreke@jesusfreke.com on 23 Sep 2014 at 2:20

GoogleCodeExporter commented 9 years ago
Do you happen to know what was changed since 1.4.1 to 2.0.3 that may have made 
jex2jar no longer compatible in this scenario?

Original comment by dongjuna...@gmail.com on 23 Sep 2014 at 2:23

GoogleCodeExporter commented 9 years ago
"at com.googlecode.dex2jar.reader.Constant.ReadConstant(Constant.java:128) at 
com.googlecode.dex2jar.reader.DexAnnotationReader.accept(DexAnnotationReader.jav
a:58)"

My guess is something related to a constant used in a method annotation.

Original comment by jesusfreke@jesusfreke.com on 23 Sep 2014 at 2:27

GoogleCodeExporter commented 9 years ago
I have determined that the issue is related to annotations on parameters in 
constructors and attempting to get these Parameter annotations. I also found 
out that when an app with these properties is recompiled with version 2.0.3 it 
not only fails dex2jar, but it causes the app to crash for one of the devices I 
was testing with.

1)      Constructor Parameter Failure Cases:
a.       @Nullable InjectorImpl parent, String b
b.      @Nullable InjectorImpl parent, int b
c.       @Nullable InjectorImpl parent, State b
d.      String b, @Nullable InjectorImpl parent

2)      Constructor Parameter Success Cases:
a.       @Nullable InjectorImpl parent
b.      @Nullable InjectorImpl parent, @Nullable String b

I have attached a zip with the source code that causes this issue, the original 
dex file, the decompiled smali code from both 1.4.1 and 2.0.3, and the final 
dex file for both 1.4.1 and 2.0.3.

Original comment by dongjuna...@gmail.com on 24 Sep 2014 at 7:21

Attachments:

GoogleCodeExporter commented 9 years ago
Here is an example source code that causes the issue:
Example Code:

Run:
new InjectorImpl(null, 
null).getClass().getConstructors()[0].getParameterAnnotations();

Define:
package com.example.samlitesterhelloworld;

public class InjectorImpl {

       public InjectorImpl(@Nullable InjectorImpl parent, String b)
         {

         }
}

Define:
package com.example.samlitesterhelloworld;

public @interface Nullable {

}

I would appreciate it if you can let me know what might be causing this issue, 
or where in the baksmali/smali source code I can look. Thanks.

Original comment by dongjuna...@gmail.com on 24 Sep 2014 at 7:27

GoogleCodeExporter commented 9 years ago
Ah-ha, gotcha. I bet 
https://code.google.com/p/smali/source/detail?r=5280047b4261f5a6619a7a7b64e2666c
06e107f6 is the culprit. You can try to build a new smali from the latest 
source and see if that works for you.

Original comment by jesusfreke@jesusfreke.com on 24 Sep 2014 at 7:43

GoogleCodeExporter commented 9 years ago
I tried building the new smali from the latest source, but I am still getting 
the same error when trying to run dex2jar, and it is causing the app to crash 
on a device running 2.3 and a device running ICS.

Original comment by dongjuna...@gmail.com on 24 Sep 2014 at 11:37

GoogleCodeExporter commented 9 years ago
The following devices are not working with RoboGuice (a common framework for 
Android devs).  Also note building the latest smali/baksmali didn’t fix the 
issue either.
1)      LG LS670 – Android Version 2.3.3
2)      Kindle Fire – Android Version 4.0.3
3)      Lenovo S2005A-H – Android Version 4.0.3
4)      Motorola XT881 – Android Version 4.0.4

I'm sure there are more Android Versions that may have similar issues. Thanks.

Original comment by dongjuna...@gmail.com on 25 Sep 2014 at 1:00

GoogleCodeExporter commented 9 years ago
Could this be caused by either:

a.  annotation_set_ref_list -> size not being the number of parameters for the 
method 
b.  Or the annotation_set_ref_item-> annotations_off for the non-annotated 
parameter is incorrect (I am guessing maybe non-zero when it should be 0). 

Original comment by derek.g...@gmail.com on 25 Sep 2014 at 10:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Has anyone found a solution to this issue yet?

Original comment by yid...@outlook.com on 3 Oct 2014 at 9:04

GoogleCodeExporter commented 9 years ago
dongjunam23: I tried the example you mentioned, but I don't get any runtime 
exception, before or after repacking with smali/baksmali 2.0.3. In both cases, 
it is able to successfully get the parameter annotation on the constructor. 
I've tried running it on 5.0, 4.4 and 2.3.

So, I'm not able to reproduce the problem on a device, and manual inspection of 
the dex file (using baksmali -D) shows that the annotations in the dex file are 
correct with respect to the dex specification.

If you can provide more information from one of the devices it doesn't work on, 
I may be able to decipher what the problem is. In particular, the exception 
when it crashes, and any errors/warnings that dalvik prints in logcat when the 
apk is being odexed during/immediately after installation.

Original comment by jesusfreke@jesusfreke.com on 7 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago
I get almost the identical issue as being described by dongjunam23. I created a 
simple application with an empty activity and the android support libraries. I 
am able to convert the dex file using dex2jar, but if I disassemble and 
reassemble the dex file with baksmali and smali, I am unable to convert the 
file using dex2jar. I get the same error related to the @Nullable parameter 
annotation. When I examine the two dex files they appear similar (both have the 
annotation), but something has changed such that dex2jar throws an exception. I 
have attached the classes.dex file being used.

Below are the steps to reproduce with the resulting error message:

test » dex2jar classes.dex  
dex2jar classes.dex -> classes-dex2jar.jar

test » baksmali classes.dex 

test » smali out 

test » dex2jar out.dex 
dex2jar out.dex -> out-dex2jar.jar
com.googlecode.dex2jar.DexException: while accept 
method:[Landroid/support/v4/app/ActivityCompat;.startActivity(Landroid/app/Activ
ity;Landroid/content/Intent;Landroid/os/Bundle;)V]
  at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:694)
  at com.googlecode.dex2jar.reader.DexFileReader.acceptClass(DexFileReader.java:436)
  at com.googlecode.dex2jar.reader.DexFileReader.accept(DexFileReader.java:323)
  at com.googlecode.dex2jar.v3.Dex2jar.doTranslate(Dex2jar.java:85)
  at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:261)
  at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:252)
  at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:110)
  at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:174)
  at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:34)
Caused by: com.googlecode.dex2jar.DexException: while accept parameter 
annotation in 
method:[Landroid/support/v4/app/ActivityCompat;.startActivity(Landroid/app/Activ
ity;Landroid/content/Intent;Landroid/os/Bundle;)V], parameter:[0]
  at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:663)
  ... 8 more
Caused by: java.lang.RuntimeException: EOF
  at com.googlecode.dex2jar.reader.io.ArrayDataIn.readUByte(ArrayDataIn.java:131)
  at com.googlecode.dex2jar.reader.DexAnnotationReader.accept(DexAnnotationReader.java:49)
  at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:660)
  ... 8 more

Original comment by dwayney...@gmail.com on 14 Nov 2014 at 11:51

Attachments:

GoogleCodeExporter commented 9 years ago
Yes. As far as I can tell, the out.dex that smali produces in this case is a 
valid dex file that follows the dex specification, and works correctly on a 
device. The fact that dex2jar isn't able to handle a such a valid dex file is a 
bug in dex2jar.

Original comment by bgruv@google.com on 15 Nov 2014 at 12:01

GoogleCodeExporter commented 9 years ago

Original comment by jesusfreke@jesusfreke.com on 28 Dec 2014 at 10:18

GoogleCodeExporter commented 9 years ago
Regardless the validity of the resulting dex, it sounds reasonable that when a 
dex is baksmalied and smalied you will get the same dex as original. Thus, this 
should be fix.

Original comment by hanag...@gmail.com on 31 Dec 2014 at 7:12

GoogleCodeExporter commented 9 years ago
It is the same dex file, in every way that matters to dalvik/art.

Original comment by jesusfreke@jesusfreke.com on 31 Dec 2014 at 9:27

GoogleCodeExporter commented 9 years ago
There seem to be a problem with parameter annotation.
I'm trying to read the resulting dex with a third party tool like dex2jar, 
and the amount of annotations for a parameter with no annotations, is corrupted.

Detailed explanation and a very small example (single class with a single 
method) in the attached file. 

Original comment by jsg...@gmail.com on 31 Dec 2014 at 2:44

Attachments:

GoogleCodeExporter commented 9 years ago
Yes, the problem is that dex2jar can't read the valid dex file that smali 
produces.

Here is a summary of the differences in how the annotations are represented in 
the dex file:

http://pastebin.com/sGiqMZiv

Per the dex specification 
(http://source.android.com/devices/tech/dalvik/dex-format.html), either 
encoding is acceptable, and both encodings are semantically identical. The fact 
that dex2jar can't read a valid dex file is a bug in dex2jar.

If the resulting dex file didn't work identically to the original on a device, 
then I would consider it a bug. I code to what dalvik/art expect and can 
handle, not some third party tool.

Original comment by jesusfreke@jesusfreke.com on 31 Dec 2014 at 8:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thanks,
you're right, I've only started to learn and dig through the dex format, and I 
thought the pointer was corrupted.

The diff you made, really helped me understand that the tool simply tries to 
read the annotation without checking if it points to offset 0.

Original comment by jsg...@gmail.com on 1 Jan 2015 at 11:59

GoogleCodeExporter commented 9 years ago
You can use the -D option in baksmali to generate an annotated hex dump, like 
what was in my pastebin. use baksmali -??  (two ?'s) to see the help/usage info 
for it.

Original comment by jesusfreke@jesusfreke.com on 1 Jan 2015 at 6:50

GoogleCodeExporter commented 9 years ago
i created a ticket in dex2jar:
https://sourceforge.net/p/dex2jar/tickets/235/

Original comment by lanc...@gmail.com on 13 Mar 2015 at 1:58