Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list all classes and methods from Android SDK used in my source code?

Tags:

java

android

I have the source code of an apk, containing a few hundred classes. I need to get the list of all calls to Android SDK methods in my source code. I thought about developing a python script to parse all sources, but there seem to be too many rules to define. I fell it would be too complicated.

Does anyone has an idea ? Or are there existing tools that can do it ?

For exemple, if the code looks like this :

class MyActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        if (savedInstanceState.containsKey("toto")) {
            setContentView(R.layout.mylayout);
            this.uselessMethod();
        }
    }
    public int uselessMethod() {
        new Thread();
    }
}

I want to get something like this :

  • java.lang.Thread#<'init'>()
  • android.app.Activity#onCreate(Bundle) void
  • android.app.Activity#setContentView(int) void
  • android.os.Bundle#containsKey(String) boolean

Thanks.

like image 683
Vincent Avatar asked Oct 21 '22 11:10

Vincent


2 Answers

Look at Doxygen for extract out all of the methods. You'll probably want to use EXTRACT_ALL http://www.doxygen.nl/manual/starting.html#extract_all which will assume everything in your sources should be documented (like third-party methods).

I was working from memory and just tried it over here. I thought Doxygen did it with additional options (see: how to get doxygen to produce call & caller graphs for c functions). While with Graphviz/dot, Doxygen does generate a collaboration diagram, it doesn't look like it will extract out what you are looking for, which I think is to list out all of the method calls, including those that aren't in your source tree.

like image 119
Morrison Chang Avatar answered Oct 31 '22 15:10

Morrison Chang


This one worked for me:

static void printMethods(Class cls)
{
    if(cls!=null){
        System.out.println();
        System.out.println("Printing Methods of "+cls.getName()+":");
        System.out.println();
        for(Method m:cls.getDeclaredMethods()){
            System.out.println(m.toString());
        }
    }
}

How to call it:

    printMethods(Class_Goes_Here);

Example:

    printMethods(java.lang.Boolean.class);

Result:

Printing Methods of java.lang.Boolean:

public static int java.lang.Boolean.compare(boolean,boolean)
public static boolean java.lang.Boolean.getBoolean(java.lang.String)
public static int java.lang.Boolean.hashCode(boolean)
public static boolean java.lang.Boolean.logicalAnd(boolean,boolean)
public static boolean java.lang.Boolean.logicalOr(boolean,boolean)
public static boolean java.lang.Boolean.logicalXor(boolean,boolean)
public static boolean java.lang.Boolean.parseBoolean(java.lang.String)
public static java.lang.String java.lang.Boolean.toString(boolean)
public static java.lang.Boolean java.lang.Boolean.valueOf(java.lang.String)
public static java.lang.Boolean java.lang.Boolean.valueOf(boolean)
public boolean java.lang.Boolean.booleanValue()
public int java.lang.Boolean.compareTo(java.lang.Boolean)
public int java.lang.Boolean.compareTo(java.lang.Object)
public boolean java.lang.Boolean.equals(java.lang.Object)
public int java.lang.Boolean.hashCode()
public java.lang.String java.lang.Boolean.toString()

Lemme know if you have any further Questions or Doubts

— DiLDoST

like image 30
DiLDoST Avatar answered Oct 31 '22 15:10

DiLDoST