Skip to content

MethodSignatureConverter

Jordan Samhi edited this page Aug 22, 2023 · 2 revisions

MethodSignatureConverter 🧰

The MethodSignatureConverter class is part of the AndroSpecter library and serves as a utility class for converting Java method signatures to Soot method signatures and extracting various components of method signatures.

Class Definition

Constructors

The class offers one constructor:

  1. public MethodSignatureConverter(): Constructs a new MethodSignatureConverter object.

Singleton Accessor

  • public static MethodSignatureConverter v(): Returns the singleton instance of MethodSignatureConverter.

Methods

  • public String getClassNameFromJimpleSignature(String sig): Extracts and returns the class name from the given Jimple signature.
  • public String getMethodNameFromJimpleSignature(String sig): Extracts and returns the method name from the given Jimple signature.
  • public String getReturnNameFromJimpleSignature(String sig): Extracts and returns the return type from the given Jimple signature.
  • public List<String> getParametersNamesFromJimpleSignature(String sig): Extracts and returns the list of parameter types from the given Jimple signature. An empty list is returned if no parameters exist.
  • public String javaSigToSootSig(String sig): Converts a Java signature to a Soot signature.
  • public String sigToSubSig(String sig): Extracts the sub-signature from a given signature string.

Usage

Here is an example of how to use the MethodSignatureConverter class:

MethodSignatureConverter converter = MethodSignatureConverter.v();

// Jimple signature example
String jimpleSignature = "<com.example.MyClass: void myMethod(java.lang.String,int,boolean)>(\"String\",1,true)";

// Extracting class name
String className = converter.getClassNameFromJimpleSignature(jimpleSignature); // Result: "com.example.MyClass"

// Extracting method name
String methodName = converter.getMethodNameFromJimpleSignature(jimpleSignature); // Result: "myMethod"

// Extracting return type
String returnType = converter.getReturnNameFromJimpleSignature(jimpleSignature); // Result: "void"

// Extracting parameters
List<String> parameters = converter.getParametersNamesFromJimpleSignature(jimpleSignature); // Result: ["java.lang.String", "int", "boolean"]

// Extracting sub-signature
String subSignature = converter.sigToSubSig(jimpleSignature); // Result: "void myMethod(java.lang.String,int,boolean)"