Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static String parseBitcode(String file) {
- StringBuffer output = new StringBuffer();
- try {
- Process p = Runtime.getRuntime().exec("opt -print-callgraph " + file);
- p.waitFor();
- BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
- String line = "";
- // Go through the bitcode file line by line
- String callerFunction = "";
- String[] foundFuncts;
- int count = 0;
- Map<String, Integer> Uses = new HashMap<String, Integer>();
- Map<String, HashMap<String,Integer>> functionsWithin = new HashMap<String, HashMap<String,Integer>>();
- Map<String, Integer> tempFunctionsWithin = new HashMap<String, Integer>();
- while ((line = reader.readLine())!= null) {
- if (line.contains("Call")) {
- // Check the caller function name
- if (line.contains("null function")) {
- callerFunction = "null";
- } else {
- callerFunction = line.split("'")[1];
- }
- if (foundFuncts[count] != callerFunction){ //if first time seeing new function
- count++;
- tempFunctionsWithin = new HashMap<String, Integer>(); // clear the tempFunctionsWithin
- foundFuncts[count] = callerFunction; // add to array
- functionsWithin.put(callerFunction,tempFunctionsWithin);
- } else {
- }
- } else if (line.contains("'")) {
- // Check the callee function name
- String calleeFunction = line.split("'")[1];
- // Add the caller/callee pair to the hashtable
- tempFunctionsWithin.put(calleeFunction,1);
- output.append(callerFunction + ":" + calleeFunction + "\n");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- System.out.println("derpp "+functionsWithin.entrySet());
- return output.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement