Matabi / smali

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

org.jf.dexlib.IndexedSection.getItemByIndex Exception #159

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
With attached dex file i get the following exception (with neweset checked out 
version)
I have no idea what this dexfile is - it was an upload into a web-tool.
Would be nice if you make it not downloadable (may be legal stuff?).

Dexdump also shows a glitch but isn't as restrictive as dexlib:

...\android-sdk-windows\platform-tools>dexdump -d classes_indexexc.de
x > classes_indexexc.txt
GLITCH: zero-width instruction at idx=0x0005

Exception:

org.jf.dexlib.Util.ExceptionWithContext: Index: 27491, Size: 4453
    at org.jf.dexlib.Util.ExceptionWithContext.withContext(ExceptionWithContext.java:54)
    at org.jf.dexlib.IndexedSection.getItemByIndex(IndexedSection.java:77)
    at org.jf.dexlib.Code.InstructionWithReference.lookupReferencedItem(InstructionWithReference.java:79)
    at org.jf.dexlib.Code.InstructionWithReference.<init>(InstructionWithReference.java:57)
    at org.jf.dexlib.Code.Format.Instruction21c.<init>(Instruction21c.java:63)
    at org.jf.dexlib.Code.Format.Instruction21c.<init>(Instruction21c.java:40)
    at org.jf.dexlib.Code.Format.Instruction21c$Factory.makeInstruction(Instruction21c.java:112)
    at org.jf.dexlib.Code.InstructionIterator.IterateInstructions(InstructionIterator.java:82)
    at org.jf.dexlib.CodeItem.readItem(CodeItem.java:154)
    at org.jf.dexlib.Item.readFrom(Item.java:77)
    at org.jf.dexlib.OffsettedSection.readItems(OffsettedSection.java:48)
    at org.jf.dexlib.Section.readFrom(Section.java:143)
    at org.jf.dexlib.DexFile.read(DexFile.java:439)
    at org.jf.dexlib.DexFile.<init>(DexFile.java:392)

Caused by: java.lang.IndexOutOfBoundsException: Index: 27491, Size: 4453
    at java.util.ArrayList.rangeCheck(ArrayList.java:604)
    at java.util.ArrayList.get(ArrayList.java:382)
    at org.jf.dexlib.IndexedSection.getItemByIndex(IndexedSection.java:75)
    ... 118 more

Original issue reported on code.google.com by andrePan...@gmail.com on 6 Jan 2013 at 12:11

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, I'll take a look at it.

Original comment by jesusfreke@jesusfreke.com on 6 Jan 2013 at 8:14

GoogleCodeExporter commented 9 years ago
I also have this error on attached file

Original comment by Firesera...@gmail.com on 16 Jan 2013 at 12:28

Attachments:

GoogleCodeExporter commented 9 years ago
Issue 162 has been merged into this issue.

Original comment by bgruv@google.com on 1 Mar 2013 at 6:36

GoogleCodeExporter commented 9 years ago
As an update on this issue, I'm aware of the problem, and plan on fixing this 
when I update smali/baksmali to use the new dexlib2 that is currently under 
development.

Original comment by bgruv@google.com on 1 Mar 2013 at 6:37

GoogleCodeExporter commented 9 years ago
Issue 163 has been merged into this issue.

Original comment by bgruv@google.com on 1 Mar 2013 at 10:51

GoogleCodeExporter commented 9 years ago
Ok, I'm waiting on it

Original comment by ikhsan.s...@gmail.com on 1 Mar 2013 at 10:58

GoogleCodeExporter commented 9 years ago
This should be fixed in 2.0. Feel free to grab the beta jars and give it a 
whirl.

What should occur is that an error will occur for the class/classes that have 
these invalid indexes, and baksmali will ignore that class and continue to 
process the rest of the dex file.

The dalvik verifier will throw out such a class anyway, and dalvik will refuse 
to load/use it. I'm not interested in trying to disassemble something that 
dalvik won't run - there could be any number of ways that someone could 
generate an invalid class and it just doesn't make sense to try to handle that, 
other than ignoring the class.

Original comment by jesusfreke@jesusfreke.com on 7 May 2013 at 8:10

GoogleCodeExporter commented 9 years ago

Original comment by jesusfreke@jesusfreke.com on 7 May 2013 at 8:20

GoogleCodeExporter commented 9 years ago
Hi,

great work! If I can at least read all valid classes instead of entirely 
stopping in the middle of the dex-file, this is totaly sufficient and 
understandable! great work.

building got a little harder now...

would it be possible to change DexFile.java in this way:

from:

        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
            if (zipFile != null) {
                zipFile.close();
            }
        }
        ReadContext readContext = new ReadContext();

to

        }
        read(in);
    }

    public DexFile(final Input in, boolean preserveSignedRegisters, boolean skipInstructions) {
            this(preserveSignedRegisters, skipInstructions);
            read(in);
    }

    private void read(final Input in) {
        ReadContext readContext = new ReadContext();

So it's easier to use the dexlib outside of baksmali.

Original comment by andrePan...@gmail.com on 8 May 2013 at 12:54

GoogleCodeExporter commented 9 years ago
ok forget my last comment, have seen dexlib2 looks totally different from 
previous

Original comment by andrePan...@gmail.com on 8 May 2013 at 2:03

GoogleCodeExporter commented 9 years ago
OK I could now adapt to the new library, it works with the given file.

And the new lib is phantastic! lots of indirections (IdItems) gone...much 
simpler to use.

2 issues:
* would be nice to have access to the full method descriptor (prototype) 
instead of concatenating the param types.
* Annotations and AnnotationEncodedValue could share some common interface for 
type and values?

cheers,
André

Original comment by andrePan...@gmail.com on 27 May 2013 at 3:20