Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
feat: add line position for method node
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 29, 2022
1 parent 83f8311 commit e66a8f6
Showing 1 changed file with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import chapi.domain.core.*
import org.archguard.scanner.bytecode.module.CodeModule
import org.archguard.scanner.bytecode.module.ModuleUtil.getModule
import org.objectweb.asm.ClassReader
import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.*
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -204,28 +206,42 @@ class ByteCodeParser {
return codeFunction
}

class SimpleMethodVisitor() : MethodVisitor(Opcodes.ASM9) {

}

private fun createFunctionCalls(methodNode: MethodNode, node: ClassNode): Array<CodeCall> {
var calls: Array<CodeCall> = arrayOf()
methodNode.instructions.map { it ->

var isStart = false
val position = CodePosition()
methodNode.instructions.map {
when (it) {
is LineNumberNode -> {
if (!isStart) {
position.StartLine = it.line
isStart = true
} else {
position.StartLine = it.line
}
}
is MethodInsnNode -> {
val qualifiedName = refineMethodOwner(it.name, it.owner, node).orEmpty()

val names = importCollector.splitPackageAndClassName(qualifiedName)
importCollector.processClassName(qualifiedName)

// val previous = it.previous
// println("${it.name}: ${it.previous.type}")
//
// var value = ""
// when (previous) {
// is LdcInsnNode -> {
// value = previous.cst.toString()
// }
// is TypeInsnNode -> {
// previous.desc
// }
// }
if (qualifiedName == "org.springframework.web.client.RestTemplate") {
println(it.opcode)
when(it.opcode) {
CodeConstants.opc_invokevirtual -> {

}
CodeConstants.opc_invokespecial -> {

}
}
}

calls += CodeCall(
Package = names.first,
Expand All @@ -236,10 +252,12 @@ class ByteCodeParser {
// Type = Type.getType(it.desc).returnType.className
)
}
else -> {}
else -> {
}
}
}

// todo: convert position
return calls
}

Expand Down

0 comments on commit e66a8f6

Please sign in to comment.