Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

androguard and android-21 #33

Closed
kvarga opened this issue Nov 12, 2014 · 14 comments
Closed

androguard and android-21 #33

kvarga opened this issue Nov 12, 2014 · 14 comments

Comments

@kvarga
Copy link

kvarga commented Nov 12, 2014

Looks like there is an issue with androguard and android-21. Specifically the get_android_resources() function seems to be having an issue parsing the resources.arsc file successfully. We discovered issue on some internal builds and I'm going to try to recreate a simple apk to demonstrate, but wanted to go ahead and create issue in case anyone has any ideas.

@kvarga
Copy link
Author

kvarga commented Nov 12, 2014

Example File Downloaded: https://storage.googleapis.com/randy/DeviceOwnerCheck.apk

Command Ran:

python -c "from androguard.core.bytecodes.apk import APK; apk = APK('DeviceOwnerCheck.apk'); apk.get_android_resources()"

Stack trace:

WARNING: ooo
Traceback (most recent call last):
  File "/Users/kylevarga/Code/devops/launchpad/env/lib/python2.7/site-packages/androguard/core/bytecodes/apk.py", line 627, in get_android_resources
    return self.arscÄ"resources.arsc"Å
KeyError: 'resources.arsc'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/kylevarga/Code/devops/launchpad/env/lib/python2.7/site-packages/androguard/core/bytecodes/apk.py", line 630, in get_android_resources
    self.arscÄ"resources.arsc"Å = ARSCParser(self.zip.read("resources.arsc"))
  File "/Users/kylevarga/Code/devops/launchpad/env/lib/python2.7/site-packages/androguard/core/bytecodes/apk.py", line 1277, in __init__
    mTableStrings = StringBlock(self.buff)
  File "/Users/kylevarga/Code/devops/launchpad/env/lib/python2.7/site-packages/androguard/core/bytecodes/apk.py", line 744, in __init__
    self.m_styles.append(unpack('<i', buff.read(4))Ä0Å)
struct.error: unpack requires a string argument of length 4

apk is a valid androguard APK object

@kvarga
Copy link
Author

kvarga commented Nov 12, 2014

This commit ( subho007@62418f1 ) on @xysec fork by @subho007 seems related to this. However it does not fix issue, just moves it further down do a different buff.read() statement somewhere else.

@subho007
Copy link
Member

@kvarga yes you are right, this doesn't solves the problem. That was again a quick fix, with broken resources. I am currently trying to find how the size%4==0 passes and then reading 4 chunks throws an error. The problem might be that the size being computed is not correct, or the buffer faces an invalid bytes.

@kvarga
Copy link
Author

kvarga commented Nov 17, 2014

This seems closely related to the issue here: iBotPeaches/Apktool@0d950f3

However, I'm not sure how to turn this into python to help fix androguard.

@subho007
Copy link
Member

@subho007
Copy link
Member

@adesnos @Lircyn any suggestions? Majority apps fails to work in androguard because of the following problem !

@adesnos
Copy link
Member

adesnos commented Dec 11, 2014

Sorry. I will take a look.

@subho007
Copy link
Member

@adesnos thank you :) I tried to follow iBotPeaches/Apktool@0d950f3 but the issue still existed ! My patch would be in https://github.com/xysec/androguard/tree/bug/resource which still doesn't work :( any help ?

@kvarga
Copy link
Author

kvarga commented Dec 17, 2014

Any idea / progress @adesnos - Unfortunately this is beyond my limits, but about at the point I need to find an alternative in the next few weeks if this isn't going to be fixed soon. Wish I could help get this fixed.

@kvarga
Copy link
Author

kvarga commented Jan 8, 2015

@adesnos Have you had a chance to look at this?

@Colbert337
Copy link
Contributor

@kvarga @subho007 I met the same problem!!! It occurs in the "> or = Android-SDK-21" apps.I think the problem might be that "self.header = unpack('<h', buff.read(2))[0]" is 0,it is not correct.

@xia0pin9
Copy link

xia0pin9 commented Feb 9, 2015

Don't know if it's related, but I get a similar error when open an apk file, the stack trace shows the error happened in zipfile.py (http://bugs.python.org/issue14315). The androguard included version (md5: 1e042f0661f8966e7a15c81651b4dfb9) generate an "unpack" error, but the (previously mentioned) patched version of zipfile.py works without any problems.

@subho007
Copy link
Member

This seems to be fixed at uTest/Androguard
Although, a small bug remains which can be patched according to my comments at uTest/Androguard#1

@subho007
Copy link
Member

I have implemented the fix in my repo too at subho007#8 with the fixes

piotrekno1 pushed a commit to ApplauseOSS/androguard that referenced this issue Feb 16, 2015
piotrekno1 pushed a commit to ApplauseOSS/androguard that referenced this issue Feb 16, 2015
@Lircyn Lircyn closed this as completed in 471222c Feb 16, 2015
Lircyn added a commit that referenced this issue Feb 16, 2015
subho007 added a commit to subho007/androguard that referenced this issue Feb 17, 2015
…o androguard-master

* 'master' of https://github.com/androguard/androguard:
  Fixed androguard#33: Android 21 compatibility
  androgui: hack to make xrefs work
  androgui: No more files written to the disk
  androgui: Reload is manual for now (no more scrolling when changing tab)
  androgui: fix bug not displaying class in tree when same name as namespace
  androgui: add x, n, g, i keyboard shortcuts
  androgui: Implement closing of tabs with the mouse middle-click
  androgui: Auto select word under the cursor when clicking
  androgui: add arguments to the xref window
  androgui: Support loading and saving .ag from/to arbitrary locations
  Use IPython pygments qt wrapper for androgui
  androgui now uses a fixed-width font
  Fix permission for androgui.py
subho007 added a commit to subho007/androguard that referenced this issue Feb 17, 2015
* androguard-master:
  Fixed androguard#33: Android 21 compatibility
  androgui: hack to make xrefs work
  androgui: No more files written to the disk
  androgui: Reload is manual for now (no more scrolling when changing tab)
  androgui: fix bug not displaying class in tree when same name as namespace
  androgui: add x, n, g, i keyboard shortcuts
  androgui: Implement closing of tabs with the mouse middle-click
  androgui: Auto select word under the cursor when clicking
  androgui: add arguments to the xref window
  androgui: Support loading and saving .ag from/to arbitrary locations
  Use IPython pygments qt wrapper for androgui
  androgui now uses a fixed-width font
  Fix permission for androgui.py
piotrekno1 pushed a commit to ApplauseOSS/androguard that referenced this issue Mar 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants