Skip to content

Commit

Permalink
Stream write the graph
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Henderson <[email protected]>
  • Loading branch information
timtadh committed Oct 27, 2017
1 parent 2ba6169 commit 0e8164a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
8 changes: 3 additions & 5 deletions source/main/java/edu/cwru/jpdg/JPDG.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static void configure_and_run_soot(soot.Scene S, Options O, String cp, Li
O.set_process_dir(dirs);
// O.set_exclude(excluded);
// O.set_no_bodies_for_excluded(true);
if (true) {
if (false) {
O.set_whole_program(true);
// O.setPhaseOption("cg.spark", "enabled:true");
O.setPhaseOption("cg.cha", "enabled:true");
Expand Down Expand Up @@ -207,19 +207,17 @@ public static Graph build_PDG(soot.Scene S, List<String> excluded, String label_
System.out.println("LABEL TYPE " + label_type + " " + lm);
soot.util.Chain<soot.SootClass> classes = S.getApplicationClasses();
CallGraph cg = null;
if (true) {
if (false) {
cg = S.getCallGraph();
}
return PDG_Builder.build(cg, lm, classes, excluded);
}

public static void writeGraph(Graph g, String path) {
byte[] graph = g.Serialize().getBytes(Charset.forName("UTF-8"));

FileOutputStream s = null;
try {
s = new FileOutputStream(path);
s.write(graph);
g.Write(s);
} catch (IOException ex) {
System.err.println(ex);
} finally {
Expand Down
10 changes: 9 additions & 1 deletion source/main/java/edu/cwru/jpdg/PDG_Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,16 @@ void build_PDG() throws pDG_Builder.Error {
source = new String(c.getTag("SourceFileTag").getValue(), "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
throw new RuntimeException(e.toString());
} catch (java.lang.Exception e) {
source = "unknown";
}
for (soot.SootMethod m : c.getMethods()) {
List<soot.SootMethod> methods = null;
try {
methods = c.getMethods();
} catch (java.lang.Exception e) {
continue;
}
for (soot.SootMethod m : methods) {
String name = pDG_Builder.method_name(m);
int entry_uid = g.addNode(
name, "",
Expand Down
21 changes: 21 additions & 0 deletions source/main/java/edu/cwru/jpdg/graph/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
*/

import java.util.*;
import java.io.OutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.lang.StringBuilder;

import com.google.gson.Gson;
Expand Down Expand Up @@ -123,6 +126,24 @@ public boolean hasEdge(int a, int b, String type) {
return edges.get(type).get(a).contains(b);
}

public void Write(OutputStream fout) throws IOException {
for (Node n : nodes.values()) {
fout.write(n.Serialize().getBytes(Charset.forName("UTF-8")));
fout.write("\n".getBytes(Charset.forName("UTF-8")));
}
for (Map.Entry<String,HashMap<Integer,Set<Integer>>> E : edges.entrySet()) {
String e_label = E.getKey();
HashMap<Integer,Set<Integer>> edges = E.getValue();
for (Map.Entry<Integer,Set<Integer>> e : edges.entrySet()) {
int i = e.getKey();
for (int j : e.getValue()) {
fout.write((new Edge(i, j, e_label, this)).Serialize().getBytes(Charset.forName("UTF-8")));
fout.write("\n".getBytes(Charset.forName("UTF-8")));
}
}
}
}

public String Serialize() {
StringBuilder sb = new StringBuilder();
for (Node n : nodes.values()) {
Expand Down

0 comments on commit 0e8164a

Please sign in to comment.