Skip to content

Commit f4c83f3

Browse files
Lenny HalsethLenny Halseth
authored andcommitted
Remove ASM-based Java start line detection
1 parent 74c2cfe commit f4c83f3

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

codepulse/src/main/scala/com/secdec/codepulse/data/bytecode/MethodContentVisitor.scala

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ import java.io.InputStream
2525

2626
object AsmVisitors {
2727
// counterCallback(instructionCount)
28-
type CounterCallback = (Int, Int, Int) => Unit
28+
type CounterCallback = (Int, Int) => Unit
2929

3030
// methodCallback(methodSignature, instructionCount)
31-
type MethodCallback = (String, String, Int, Int, Int) => Unit
31+
type MethodCallback = (String, String, Int, Int) => Unit
3232

3333
def parseMethodsFromClass(classBytes: InputStream) = {
3434
val reader = new ClassReader(classBytes)
35-
val builder = List.newBuilder[(String, String, Int, Int, Int)]
36-
val visitor = new ClassStructureVisitor2({ (file, sig, size, lineCount, methodStartLine) => builder += ((file, sig, size, lineCount, methodStartLine)) })
35+
val builder = List.newBuilder[(String, String, Int, Int)]
36+
val visitor = new ClassStructureVisitor2({ (file, sig, size, lineCount) => builder += ((file, sig, size, lineCount)) })
3737
reader.accept(visitor, ClassReader.SKIP_FRAMES)
3838
builder.result()
3939
}
@@ -42,12 +42,10 @@ object AsmVisitors {
4242
class MethodContentVisitor(counterCallback: AsmVisitors.CounterCallback) extends MethodVisitor(Opcodes.ASM5) {
4343
private var instructionCounter = 0
4444
private var lineCounter = 0
45-
private var methodStart = false
46-
private var methodStartLine = -1
4745

4846
def inc() = instructionCounter += 1
49-
override def visitCode = { instructionCounter = 0; lineCounter = 0; methodStart = true; methodStartLine = -1 }
50-
override def visitEnd = { counterCallback(instructionCounter, lineCounter, methodStartLine) }
47+
override def visitCode = { instructionCounter = 0; lineCounter = 0 }
48+
override def visitEnd = { counterCallback(instructionCounter, lineCounter) }
5149

5250
override def visitFieldInsn(opcode: Int, owner: String, name: String, desc: String): Unit = inc()
5351
override def visitIincInsn(v: Int, amt: Int): Unit = inc()
@@ -62,15 +60,7 @@ class MethodContentVisitor(counterCallback: AsmVisitors.CounterCallback) extends
6260
override def visitTableSwitchInsn(min: Int, max: Int, dflt: Label, labels: Label*): Unit = inc()
6361
override def visitTypeInsn(opcode: Int, tp: String): Unit = inc()
6462
override def visitVarInsn(opcode: Int, v: Int): Unit = inc()
65-
override def visitLineNumber(line: Int, start: Label): Unit = {
66-
lineCounter += 1
67-
68-
if(methodStart) {
69-
methodStartLine = line
70-
methodStart = false
71-
}
72-
73-
}
63+
override def visitLineNumber(line: Int, start: Label): Unit = lineCounter += 1
7464
}
7565

7666
class ClassStructureVisitor2(methodCallback: AsmVisitors.MethodCallback) extends ClassVisitor(Opcodes.ASM5) {
@@ -87,8 +77,8 @@ class ClassStructureVisitor2(methodCallback: AsmVisitors.MethodCallback) extends
8777

8878
override def visitMethod(access: Int, name: String, desc: String, sig: String, exceptions: Array[String]): MethodVisitor = {
8979
val methodSignature = classSignature + "." + name + ";" + access + ";" + desc
90-
val counterCallback: AsmVisitors.CounterCallback = (insnCount, lineCount, methodStartLine) => {
91-
methodCallback(classFile, methodSignature, insnCount, lineCount, methodStartLine)
80+
val counterCallback: AsmVisitors.CounterCallback = (insnCount, lineCount) => {
81+
methodCallback(classFile, methodSignature, insnCount, lineCount)
9282
}
9383
new MethodContentVisitor(counterCallback)
9484
}

codepulse/src/main/scala/com/secdec/codepulse/input/bytecode/ByteCodeProcessor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class ByteCodeProcessor() extends LanguageProcessor with Loggable {
133133
case "class" =>
134134
val methods = AsmVisitors.parseMethodsFromClass(new CloseShieldInputStream(contents))
135135
for {
136-
(file, name, size, lineCount, methodStartLine) <- methods
136+
(file, name, size, lineCount) <- methods
137137
pkg = getPackageFromSig(name)
138138
filePath = FilePath(Array(pkg, file).mkString("/"))
139139
nestedPath = filePath.map(fp => entryPath match {

0 commit comments

Comments
 (0)