Skip to content

Commit 657a37d

Browse files
committed
reaper: Output build data
1 parent 5ef6755 commit 657a37d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

gradle-plugin/plugin/src/main/kotlin/com/emergetools/android/gradle/instrumentation/reaper/ReaperClassLoadTransform.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.objectweb.asm.Opcodes
1010
import org.slf4j.Logger
1111
import org.slf4j.LoggerFactory
1212
import java.security.MessageDigest
13+
import java.util.Base64
1314

1415
abstract class ReaperClassLoadClassVisitorFactory :
1516
AsmClassVisitorFactory<InstrumentationParameters.None> {
@@ -83,24 +84,37 @@ class ReaperClassLoadClassVisitor(
8384
return mv?.let {
8485
val sig = "$className.$name$descriptor"
8586
logger.info("Processing method: $sig")
86-
ReaperClassLoadMethodVisitor(api, mv, className, name)
87+
ReaperClassLoadMethodVisitor(api, mv, className, name, logger)
8788
}
8889
}
8990
}
9091

92+
fun longToBase64(hash: Long): String {
93+
val buf = ByteArray(8)
94+
for (i in 0..7) {
95+
buf[i] = ((hash shr i * 8) and 0xFFL).toByte()
96+
}
97+
val hashAsBase64 = Base64.getEncoder().encode(buf).toString(Charsets.UTF_8)
98+
return hashAsBase64
99+
}
100+
91101
class ReaperClassLoadMethodVisitor(
92102
api: Int,
93103
methodVisitor: MethodVisitor,
94104
private val className: String,
95105
// private val writer: PrintWriter,
96106
private val name: String?,
107+
private val logger: Logger,
97108
) : MethodVisitor(api, methodVisitor) {
98109
override fun visitCode() {
99110
super.visitCode()
100111
if (name == "<clinit>" || name == "<init>") {
101112
val signature = "L" + className.replace(".", "/") + ";"
102113
val hashedSignature = topLong(toSha256(signature))
103114

115+
// TODO: output to file
116+
logger.error("${className}\t${hashedSignature}\t${longToBase64(hashedSignature)}\t${signature}\t${name}")
117+
104118
// Push method argument onto the stack
105119
mv.visitLdcInsn(hashedSignature)
106120

0 commit comments

Comments
 (0)