forked from openrs2/openrs2
parent
e3095f4a7e
commit
5d8dce0ed2
@ -1,29 +1,30 @@ |
|||||||
package dev.openrs2.deob.analysis |
package dev.openrs2.deob.analysis |
||||||
|
|
||||||
import com.google.common.graph.Graph |
import org.jgrapht.Graph |
||||||
import com.google.common.graph.GraphBuilder |
import org.jgrapht.graph.AsUnmodifiableGraph |
||||||
|
import org.jgrapht.graph.DefaultDirectedGraph |
||||||
|
import org.jgrapht.graph.DefaultEdge |
||||||
import org.objectweb.asm.tree.MethodNode |
import org.objectweb.asm.tree.MethodNode |
||||||
import org.objectweb.asm.tree.analysis.Analyzer |
import org.objectweb.asm.tree.analysis.Analyzer |
||||||
import org.objectweb.asm.tree.analysis.BasicInterpreter |
import org.objectweb.asm.tree.analysis.BasicInterpreter |
||||||
import org.objectweb.asm.tree.analysis.BasicValue |
import org.objectweb.asm.tree.analysis.BasicValue |
||||||
|
|
||||||
class ControlFlowAnalyzer : Analyzer<BasicValue>(BasicInterpreter()) { |
class ControlFlowAnalyzer : Analyzer<BasicValue>(BasicInterpreter()) { |
||||||
private val graph = GraphBuilder |
private val graph = DefaultDirectedGraph<Int, DefaultEdge>(DefaultEdge::class.java) |
||||||
.directed() |
|
||||||
.allowsSelfLoops(true) |
|
||||||
.immutable<Int>() |
|
||||||
|
|
||||||
override fun newControlFlowEdge(insnIndex: Int, successorIndex: Int) { |
override fun newControlFlowEdge(insnIndex: Int, successorIndex: Int) { |
||||||
graph.putEdge(insnIndex, successorIndex) |
graph.addVertex(insnIndex) |
||||||
|
graph.addVertex(successorIndex) |
||||||
|
graph.addEdge(insnIndex, successorIndex) |
||||||
} |
} |
||||||
|
|
||||||
override fun newControlFlowExceptionEdge(insnIndex: Int, successorIndex: Int): Boolean { |
override fun newControlFlowExceptionEdge(insnIndex: Int, successorIndex: Int): Boolean { |
||||||
graph.putEdge(insnIndex, successorIndex) |
newControlFlowEdge(insnIndex, successorIndex) |
||||||
return true |
return true |
||||||
} |
} |
||||||
|
|
||||||
fun createGraph(owner: String, method: MethodNode): Graph<Int> { |
fun createGraph(owner: String, method: MethodNode): Graph<Int, DefaultEdge> { |
||||||
analyze(owner, method) |
analyze(owner, method) |
||||||
return graph.build() |
return AsUnmodifiableGraph(graph) |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue