-1

I want to extracts method from all .smalli file .
Is there any format to declare methods(API Functions) in .smalli file so i can easily extract it using python script. I am looking for concept so I can identify how 1. User-define function 2. API function 3. API call sequence are defined and declared .I want to print only API functions and API call sequence using python .

Suman Tiwari
  • 40
  • 1
  • 10
  • Do you mean smali or dex? Enjarify parses dex files and is written in Python. – Antimony Oct 30 '17 at 17:15
  • i mean smali. i want to extract API functions from .smali file but I am not able to understand which are API functions. Is there any special way to define API functions so that i can identify them from .smalli file . I want to extract API call sequence also , So is there any ways with which i can identify API call sequence and extract it. – Suman Tiwari Oct 30 '17 at 17:26

2 Answers2

0

The question asks about parsing smali files, but that is unlikely to be what you actually want. Assuming your goal is to analyze Android applications, you need to parse dex files. Luckily, there is a tool written in Python called Enjarify that contains a dex parser. It's not designed to be used as a library, so it will take a little bit of work to integrate, but you should be able to figure it out pretty easily. You can start by looking at parsedex.py.

Assuming that you really do want to parse smali files for some reason, things are a lot harder, as smali is a file format defined by the smali tool, which is written in Java. However, you could use Jython to call it from Python.

Antimony
  • 37,781
  • 10
  • 100
  • 107
  • Thanks , I want to extract functions and API call sequence from .smalli file and I want to create feature vector for my research work. I have used baksmali tool to convert calsses.dex into .smalli files. for ex. Landroid/app/Activity;-> is method(Activity methods is written like this). I dont want user defined methods but only android API like loadjar(), setcomponent() etc. then how to identify system API and call sequence. Currently I am looking concepts point of view to understand .smalli file and how can I identify system API , Call sequence. – Suman Tiwari Oct 31 '17 at 04:04
0

Following is Syntax that is used to identify .Smali Function calls

  1. invoke-super vx, vy, : invokes the parent classes method in object vx, passing in parameter(s) vy.
  2. invoke-direct vx, vy : invokes a method in object vx with parameters vy, … without the virtual method resolution.
  3. invoke-virtual vx, vy : invokes the virtual method in object vx, passing in parameters vy.

Following links provide good source to start with .smalli file https://apkudo.com/?p=775

Suman Tiwari
  • 40
  • 1
  • 10