Skip to content

Commit

Permalink
Fix and dig more properties for yaml return
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan committed Oct 18, 2022
1 parent c07fbe1 commit 2c9be6d
Showing 1 changed file with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.
///////////////////////////////////////////////////////////////////////////


package ossf.fuzz.introspector.soot;

import java.io.File;
Expand All @@ -23,6 +22,13 @@
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import ossf.fuzz.introspector.soot.yaml.FunctionConfig;
import ossf.fuzz.introspector.soot.yaml.FunctionElement;
import ossf.fuzz.introspector.soot.yaml.FuzzerConfig;
import soot.PackManager;
import soot.Scene;
import soot.SceneTransformer;
Expand All @@ -33,7 +39,8 @@
import soot.jimple.toolkits.callgraph.Edge;
import soot.options.Options;

public class CallGraphGenerator {
public class CallGraphGenerator
{
public static void main(String[] args) {
if (args.length != 2) {
System.err.println("No entryClass or entryMethod.");
Expand Down Expand Up @@ -85,6 +92,7 @@ class CustomSenceTransformer extends SceneTransformer {
public CustomSenceTransformer() {
excludeList = new LinkedList<String> ();

excludeList.add("jdk.");
excludeList.add("java.");
excludeList.add("javax.");
excludeList.add("sun.");
Expand All @@ -100,16 +108,39 @@ protected void internalTransform(String phaseName, Map<String, String> options)
int numOfEdges = 0;
int numOfClasses = 0;
int numOfMethods = 0;
List<FuzzerConfig> classYaml = new ArrayList<FuzzerConfig>();

CallGraph callGraph = Scene.v().getCallGraph();
System.out.println("--------------------------------------------------");
for(SootClass c : Scene.v().getApplicationClasses()) {
if (c.getName().startsWith("jdk")) {
continue;
}

FuzzerConfig classConfig = new FuzzerConfig();
FunctionConfig methodConfig = new FunctionConfig();
classConfig.setFilename(c.getName());
methodConfig.setListName("All functions");

numOfClasses++;
System.out.println("Class #" + numOfClasses + ": " + c.getName());
for (SootMethod m : c.getMethods()) {
FunctionElement element= new FunctionElement();
element.setFunctionName(m.getName());
element.setFunctionSourceFile(c.getFilePath());
//element.setLinkageType("???");
element.setFunctionLinenumber(m.getJavaSourceStartLineNumber());
element.setReturnType(m.getReturnType().toString());
element.setArgCount(m.getParameterCount());
for (soot.Type type:m.getParameterTypes()) {
element.addArgType(type.toString());
}
//element.setConstantsTouched([]);
//element.setArgNames();
//element.setBBCount(0);
//element.setiCount(0);
//element.setCyclomaticComplexity(0);

numOfMethods++;
int methodEdges = 0;
Iterator<Edge> outEdges = callGraph.edgesOutOf(m);
Expand All @@ -130,6 +161,7 @@ protected void internalTransform(String phaseName, Map<String, String> options)

System.out.println("\n\t Total: " + methodEdges + " internal calls.\n");

element.setFunctionUses(methodEdges);
methodEdges = 0;

if (!outEdges.hasNext()) {
Expand All @@ -141,16 +173,33 @@ protected void internalTransform(String phaseName, Map<String, String> options)
SootMethod tgt = (SootMethod) edge.getTgt();
System.out.println("\t > calls " + tgt + " on Line " +
edge.srcStmt().getJavaSourceStartLineNumber());
element.addFunctionReached(tgt.toString());
}
System.out.println("\n\t Total: " + methodEdges + " external calls.\n");
numOfEdges += methodEdges;

element.setEdgeCount(methodEdges);
//element.setBranchProfiles(new BranchProfile());
methodConfig.addFunctionElement(element);
}
System.out.println("--------------------------------------------------");
classConfig.setFunctionConfig(methodConfig);
classYaml.add(classConfig);
}
System.out.println("Total Edges:" + numOfEdges);
System.out.println("------------------------------------------------------------");
ObjectMapper om = new ObjectMapper(new YAMLFactory());
for(FuzzerConfig config:classYaml) {
try {
System.out.println(om.writeValueAsString(config) + "\n");
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
}

public List<String> getExcludeList() {
return excludeList;
}
}

0 comments on commit 2c9be6d

Please sign in to comment.