Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. private static String parseBitcode(String file) {
  2. StringBuffer output = new StringBuffer();
  3.  
  4. try {
  5. Process p = Runtime.getRuntime().exec("opt -print-callgraph " + file);
  6. p.waitFor();
  7. BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
  8. String line = "";
  9.  
  10. // Go through the bitcode file line by line
  11. String callerFunction = "";
  12. String[] foundFuncts;
  13. int count = 0;
  14. Map<String, Integer> Uses = new HashMap<String, Integer>();
  15. Map<String, HashMap<String,Integer>> functionsWithin = new HashMap<String, HashMap<String,Integer>>();
  16. Map<String, Integer> tempFunctionsWithin = new HashMap<String, Integer>();
  17. while ((line = reader.readLine())!= null) {
  18. if (line.contains("Call")) {
  19. // Check the caller function name
  20. if (line.contains("null function")) {
  21. callerFunction = "null";
  22. } else {
  23. callerFunction = line.split("'")[1];
  24. }
  25. if (foundFuncts[count] != callerFunction){ //if first time seeing new function
  26. count++;
  27. tempFunctionsWithin = new HashMap<String, Integer>(); // clear the tempFunctionsWithin
  28. foundFuncts[count] = callerFunction; // add to array
  29. functionsWithin.put(callerFunction,tempFunctionsWithin);
  30. } else {
  31.  
  32. }
  33.  
  34. } else if (line.contains("'")) {
  35. // Check the callee function name
  36. String calleeFunction = line.split("'")[1];
  37. // Add the caller/callee pair to the hashtable
  38. tempFunctionsWithin.put(calleeFunction,1);
  39. output.append(callerFunction + ":" + calleeFunction + "\n");
  40. }
  41.  
  42. }
  43.  
  44. } catch (Exception e) {
  45. e.printStackTrace();
  46. }
  47. System.out.println("derpp "+functionsWithin.entrySet());
  48. return output.toString();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement