Last active
November 9, 2018 12:38
-
-
Save jpstotz/a0beed8234ee2c1660e96d4d1ecc7623 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.util.Collections; | |
import soot.Body; | |
import soot.Main; | |
import soot.Scene; | |
import soot.SootClass; | |
import soot.SootMethod; | |
import soot.Unit; | |
import soot.options.Options; | |
import soot.toolkits.graph.ExceptionalUnitGraph; | |
import soot.toolkits.graph.ExceptionalUnitGraph.ExceptionDest; | |
public class SootJavaTestException { | |
private void test() throws Exception { | |
Options o = Options.v(); | |
o.set_verbose(false); | |
o.set_allow_phantom_refs(true); | |
o.set_whole_program(true); | |
o.set_process_dir(Collections.singletonList("java_classes")); | |
o.set_prepend_classpath(false); | |
o.set_coffi(false); | |
o.set_src_prec(Options.src_prec_class); | |
Main.v().autoSetOptions(); | |
Scene.v().loadNecessaryClasses(); | |
SootClass sootClass = Scene.v().getSootClass("TestClass"); | |
SootMethod method = sootClass.getMethodByName("test"); | |
Body body = method.retrieveActiveBody(); | |
System.out.println(body); | |
ExceptionalUnitGraph eug = new ExceptionalUnitGraph(body); | |
SootClass exception = Scene.v().loadClassAndSupport(IOException.class.getName()); | |
for (Unit u : body.getUnits()) { | |
for (ExceptionDest ed : eug.getExceptionDests(u)) { | |
System.out.println("-------------------"); | |
System.out.println(u + " " + ed); | |
System.out.println("catchable: " + ed.getThrowables().catchableAs(exception.getType())); | |
} | |
} | |
} | |
public static void main(String[] args) { | |
SootJavaTestException test = new SootJavaTestException(); | |
try { | |
test.test(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment