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

Commit

Permalink
feat: add test functions for java
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 28, 2022
1 parent 9082f2d commit fecf421
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.archguard.scanner.bytecode

import chapi.domain.core.CodeDataStruct
import chapi.domain.core.CodeFunction
import org.objectweb.asm.ClassReader
import org.objectweb.asm.Type
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode
import org.slf4j.LoggerFactory
import java.io.File
import java.io.FileInputStream
Expand Down Expand Up @@ -34,9 +36,18 @@ class ByteCodeParser {
val ds = CodeDataStruct()
ds.NodeName = getClassName(classNode.name).toString()

classNode.methods.forEach {
ds.Functions += this.createMethod(it, ds.NodeName, classNode)
}

return ds
}

private fun createMethod(methodNode: MethodNode, nodeName: String, classNode: ClassNode): CodeFunction {
val codeFunction = CodeFunction(Name = methodNode.name)
return codeFunction
}


private fun getClassName(internalName: String): String? {
return Type.getObjectType(internalName).className
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ internal class ByteCodeParserTest {

val ds = ByteCodeParser().parseClassFile(path)
assertEquals("org.archguard.demo.HelloWorld", ds.NodeName)
assertEquals(2, ds.Functions.size)
assertEquals("<init>", ds.Functions[0].Name)
assertEquals("main", ds.Functions[1].Name)
}
}

0 comments on commit fecf421

Please sign in to comment.