1

Need to calculate the number of methods and variables in the smali file, not through dex. How?

It's better to use Python language, please

I simply calculated the number of .field in the smali file and found a significant difference from the actual system calculation.

def parse_smali_method_num(smali_path):
    count = 0
    with open(smali_path, 'r', 4096, 'utf-8') as f:
        text = f.readline()
        if (not text.startswith('.class')):
            print('Warning:Not a class smali file:' + str(smali_path))
            return 0
        while (text):
            text = f.readline()
            if (text.startswith('.method')):
                count += 1
    return count

def parse_smali_field_num(smali_path):
    count = 0
    with open(smali_path, 'r', 4096, 'utf-8') as f:
        text = f.readline()
        if (not text.startswith('.class')):
            print('Warning:Not a class smali file:' + str(smali_path))
            return 0
        while (text):
            text = f.readline()
            if (text.startswith('.field')):
                count += 1
    return count
lhq
  • 11
  • 3
  • 1
    Please share part of your `smali` file including `.method` and `.field` – Byte Ninja Jul 06 '23 at 13:42
  • 1
    Hi, welcome to StackOverflow. Please take the [tour](https://stackoverflow.com/tour) and learn [How to Ask](https://stackoverflow.com/help/how-to-ask). In order to get help, you will need to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – alec_djinn Jul 06 '23 at 13:47
  • `I simply calculated the number of. fields in the smali file` How? Please share the code you use for counting the fields. Also what is the `actual system calculation`? Is this a value shown by some tool? (if yes which one?) – Robert Jul 06 '23 at 16:07
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jul 06 '23 at 19:53
  • Code shared~ please check – lhq Jul 07 '23 at 01:56

0 Answers0