LIEF
LIEF copied to clipboard
DEX parser returns classes that are not defined
Describe the bug
The field classes
of the class lief.DEX.File
returned by lief.DEX.parse
contains classes that are not defined in the DEX file, but also classes that are used in parameters, fields, etc.
To Reproduce Steps to reproduce the behavior: analyzing the attached file bug.zip with the following code:
dex = lief.DEX.parse(dex_file)
for c in dex.classes:
print(c.fullname)
For example, this code prints the class Landroid/service/autofill/SaveRequest;
.
But the aforementioned class is not defined in the dex file (confirmed by dexdump and radare).
Expected behavior There's the need to distinguish between classes defined in the DEX file and classes without implementation.
Environment:
- System and Version: Ubuntu 18.04
- Target format: DEX
- LIEF commit version: 0.9.0-a448c5e
Hello @packmad
You are right, in the current version we don't distinguish external classes from internal ones. One way to workaround this issue is to check if at least one of the method of the class has a code size > 0
(and the class is not abstract)
It looks like this code is doing what I wanted (I'm also intrested in abs classes):
def get_internal_classes(dex) -> Set[str]:
ret = set()
for c in dex.classes:
for m in c.methods:
if len(m.bytecode) > 0:
ret.add(c.fullname)
break
return ret