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
static fields showing up in wrong class #989
Comments
i will try to take a close look at this in the following days but from a first glance the get_fields/get_methods implies returning all fields and methods and not just the xrefs. |
Thanks, I'm happy to make PRs where helpful, just let me know. I have unit tests for access flags for fields and methods in a fork, but will hold until these changes make it in. |
having my reservations regarding my understanding over the reasons why this was initially developed this way i can say the following:
having said that, tested a bit the besides this issue with the |
maybe we can discuss further regarding adding these unit tests and along the way improve the "user friendliness" of the source |
The unit tests were added here: https://github.com/ehrenb/androguard/blob/master/tests/test_dex.py. I noticed that one of the field tests was failing, and that's what led me to the issue in this thread. For these test, I can access using the ClassAnalysis' 'orig_class' attribute for now and that will be fine (as is in my above example) and create a PR. Once new "user friendliness" designs are implemented, it probably makes sense to port those changes to the test case as well. I will try to write up my thoughts on what "user friendliness" changes may look like. I'm thinking this could be cleared up with some method name changes and definitive examples for use. |
That would be perfect and it can help in creating a plan on what needs to be done further. Unfortunately I have very very limited time these days to help sort things faster. |
My understanding has changed slightly, I don't think the This is apparent by their addition in the ...
self.classes[current_class.get_name()] = ClassAnalysis(current_class)
...
new_class.add_method(self.methods[method]) But fields were seemingly never wrapped and added like the above, maybe this was left undone? They were only wrapped and added into a ClassAnalysis when an XREF occurred. That may have led to my confusion about why only certain fields were in the Analysis with my test. We can ensure all of the app-internal fields are wrapped by adding a Then, Anyways, I've spent a decent amount of time trying to understand the intent of this code. If we move forward with the above understanding about the design (which I now believe wasn't completely finished), here are some things we can add to complete it:
|
@ehrenb there are a few things scattered around the source that are either forgotten or stopped midway while developing them due to lack of time etc, so I would not be surprised if fields are just not completed in that sense. Additionally, its a project that is several years old, without actively being maintained since 2019 and therefore proper testing of the code is a bit behind on schedule. This is the reason why one of the first moves I did was to reinstate the tests. To conclude, I am up to proceed with your ideas, when I will get a bit more time I will review things and consider what more can be done |
Understood, getting testing up and running will help reveal some of these issues/designs that aren't so obvious (such as the fields!). I'll work on PRs for the above tasks I mentioned, then can help tackle whatever else comes up (issue backlog or new features, docs, etc). |
…. fix failing test mentioned in androguard#989 so that it assumes testing for wrapped fields. make new tests for DEX-class level testing that tests counts of parsed values in the DEX header
I was in the process of writing more test cases for fields, when I noticed that a static field was being attached to the wrong class. The 'i' and 'j' static fields are within the TestLoops$Loop class, not TestLoops. Instance fields seem to be connected properly (see TestSynthetic$1) though.
Using TestActivity.apk:
output:
In smali, TestLoops$Loop.smali:
In smali, TestLoops.smali, there are no fields:
TestSynthetic$1.smali
I also used Kaitai Struct to take a look at the dex, and the 'i' and 'j' fields are indeed within TestLoops$Loop:
The text was updated successfully, but these errors were encountered: