Skip to content

Commit

Permalink
added jump details and colors to analysis. fixed batch
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Jan 30, 2011
1 parent cf6951b commit 842c8f3
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 1,254 deletions.
482 changes: 72 additions & 410 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cjbe.bat
Expand Up @@ -4,5 +4,5 @@ echo Code Maintained by Contra
cd out
cd production
cd cjbe
java net.rec.contra.cjbe.editor.BrowserApplication
java -cp ".;soot.jar" net.rec.contra.cjbe.editor.BrowserApplication
pause
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added out/production/CJBE/soot.jar
Binary file not shown.
Binary file added soot.jar
Binary file not shown.
Expand Up @@ -3,6 +3,8 @@
import net.rec.contra.cjbe.editor.BrowserInternalFrame;
import org.gjt.jclasslib.structures.ClassFile;
import soot.*;
import soot.dava.DavaBody;
import soot.dava.DavaUnitPrinter;
import soot.grimp.Grimp;
import soot.grimp.GrimpBody;
import soot.javaToJimple.AbstractJimpleBodyBuilder;
Expand All @@ -11,8 +13,10 @@
import soot.jimple.JimpleMethodSource;
import soot.jimple.parser.JimpleAST;
import soot.toolkits.graph.CompleteUnitGraph;
import soot.toolkits.graph.ExceptionalUnitGraph;

import javax.swing.*;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;
import java.util.Iterator;

Expand All @@ -24,35 +28,43 @@ public class AnalysisDisplay extends JEditorPane {

SootMethod thisMethod;
Body mBody;
CompleteUnitGraph cGraph;

ExceptionalUnitGraph cGraph;

AnalysisDisplay(int methodIndex, ClassFile classFile, BrowserInternalFrame internalFrame) {
this.internalFrame = internalFrame;
setEditorKitForContentType("text/html", new HTMLEditorKit());
setContentType("text/html");
try {
setEditable(false);
Scene tz = Scene.v();
tz.setSootClassPath(System.getProperty("java.class.path") + ";" + internalFrame.getClassPathString());
tz.setPhantomRefs(true);
this.klass = tz.loadClassAndSupport(classFile.getThisClassName());
this.thisMethod = (SootMethod) klass.getMethods().toArray()[methodIndex];
this.mBody = thisMethod.retrieveActiveBody();
//soot.grimp.Grimp gb = new soot.grimp.Grimp.v();
this.cGraph = new CompleteUnitGraph(mBody);
Scene.v().setSootClassPath(System.getProperty("java.class.path") + ";" + internalFrame.getClassPathString());
Scene.v().setPhantomRefs(true);
klass = Scene.v().loadClassAndSupport(classFile.getThisClassName());
thisMethod = (SootMethod) klass.getMethods().toArray()[methodIndex];
mBody = thisMethod.retrieveActiveBody();
cGraph = new CompleteUnitGraph(mBody);
} catch (Exception e) {
e.printStackTrace();
setText("Error: " + e + "\nControl Flow Analysis Unavailable.\nMake sure your classpath has all necessary dependencies.");
setText("Error: " + e + "<br>\nControl Flow Analysis Unavailable.<br>\nMake sure your classpath has all necessary dependencies.");
return;
}
Iterator<Unit> it = cGraph.iterator();
String pageText = "";
Iterator<Unit> it = cGraph.iterator();
while (it.hasNext()) {
pageText += it.next().toString();
if (it.hasNext()) pageText += "\n";
Unit u = it.next();
pageText += u.toString();
if (u.branches())
{
pageText += " <font color=\"red\">(Jumps)</font>";
}
if (u.getBoxesPointingToThis().size() > 1){
pageText += " <font color=\"red\">(Jump Point)</font>";
}
if (it.hasNext()) pageText += "<br>\n";
}
setFont(new Font("monospaced", Font.PLAIN, 12));
setCaretPosition(0);
if (!pageText.equals("")) {
setCaretPosition(0);
pageText = pageText.replaceAll("virutalinvoke", "<font color=\"orange\">virtualinvoke</font>");
pageText = "<html>\n<body>\n<font size='3' face='monospaced'>\n" + pageText + "\n</font>\n</body>\n</html>";
setText(pageText);
} else {
setText("Control Flow Analysis Unavailable.");
Expand Down
Expand Up @@ -7,6 +7,7 @@
import net.rec.contra.cjbe.editor.BrowserInternalFrame;
import net.rec.contra.cjbe.editor.BrowserServices;
import net.rec.contra.cjbe.editor.BrowserTreeNode;
import org.apache.bcel.classfile.LineNumber;
import org.gjt.jclasslib.structures.ClassFile;
import org.gjt.jclasslib.structures.MethodInfo;
import org.gjt.jclasslib.structures.attributes.CodeAttribute;
Expand Down Expand Up @@ -50,7 +51,8 @@ private void addEditPane(String methodIndex, ClassFile classFile) {
//System.out.println(methodIndex);
//Scrollbar
JScrollPane scroll = new JScrollPane(editArea);
scroll.setRowHeaderView(new LineNumberView(editArea));
//LineNumberView view = new LineNumberView(editArea);
//scroll.setRowHeaderView(view);
scroll.getVerticalScrollBar().setValue(10);
this.add(scroll, methodIndex);

Expand Down
@@ -1,17 +1,21 @@
package net.rec.contra.cjbe.editor.detail.attributes.code;

import net.rec.contra.cjbe.editor.BrowserInternalFrame;
import net.rec.contra.cjbe.editor.detail.attributes.code.graph.cfg.Block;
import net.rec.contra.cjbe.editor.detail.attributes.code.graph.cfg.BlockGraph;
import net.rec.contra.cjbe.editor.detail.attributes.code.graph.cfg.InstructionGraph;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionHandle;
import org.apache.bcel.generic.MethodGen;
import soot.CoffiClassSource;
import soot.G;
import soot.dava.Dava;
import soot.dava.DavaBody;
import soot.tools.CFGViewer;
import soot.util.cfgcmd.CFGIntermediateRep;

import javax.swing.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;


Expand All @@ -27,44 +31,15 @@ public class DiagramDisplay extends JEditorPane {
try {
javaClass = new ClassParser(internalFrame.getFileName()).parse();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
System.out.println("Failed to analyze control flow. Skipping...");
return;
}
ClassGen cg = new ClassGen(javaClass);
MethodGen mg = new MethodGen(cg.getMethods()[methodIndex], cg.getClassName(), cg.getConstantPool());
InstructionGraph ig = new InstructionGraph(mg, true);
BlockGraph blockGraph = new BlockGraph(ig);
String pageText = "";
Iterator<Block> it = blockGraph.iterator();
while(it.hasNext()){
Block bk = it.next();
pageText += "Block " + bk.getIndex() + ":\n";
if(bk.getSuccs() != null){
pageText += " Hops to";
for (Block bz : bk.getSuccs()){
pageText += "\n - Block " + bz.getIndex();
}
pageText += "\n";
}
InstructionHandle[] handles = bk.getMethod().getInstructionList().getInstructionHandles();
for(int i = bk.getHead().getPosition(); i <= bk.getTail().getPosition(); i++){
if(i < handles.length){
pageText += handles[i].toString() + "\n";
} else {
pageText += " INVALID\n";
}
/*
if(bk.getTail().getPosition() > mg.getInstructionList().getInstructionHandles().length){
System.out.println(mg.getName() + " had invalid unit data.");
pageText += "INVALID UNIT DATA\n";
break;
} else {
pageText += handles[i].toString() + "\n";
} */
}
}
setText(pageText);
soot.tools.CFGViewer cfg = new CFGViewer();

//soot.dava.Dava d = new Dava(G.);
}

}

This file was deleted.

This file was deleted.

0 comments on commit 842c8f3

Please sign in to comment.