Skip to content

Commit c48e463

Browse files
committed
🐛 Fix hash string
1 parent 559e187 commit c48e463

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

app/src/main/java/com/kyhsgeekcode/disassembler/Analyzer.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,20 @@ class Analyzer(private val bytes: ByteArray) {
387387
var shash = "Unknown"
388388
try {
389389
val digest = MessageDigest.getInstance(algorithm)
390-
val hash = digest.digest(bytes)
391-
shash = ""
392-
for (b in hash) {
393-
shash += Integer.toHexString((b and 0xFF.toByte()).toInt())
394-
}
390+
shash = bytes?.digestString(digest)?:shash
391+
// val hash = digest.digest(bytes)
392+
// shash = ""
393+
// for (b in hash) {
394+
// shash += Integer.toHexString((b and 0xFF.toByte()).toInt())
395+
// }
395396
} catch (e: NoSuchAlgorithmException) {
396-
Logger.e(TAG, "Faied to get $algorithm hash;", e)
397+
Logger.e(TAG, "Failed to get $algorithm hash;", e)
397398
}
398399
return shash
399400
}
400401
}
401402

403+
402404
// Analyzes code, strings, etc
403405
init {
404406
uBytes = bytes.toUByteArray()

app/src/main/java/com/kyhsgeekcode/disassembler/Utils.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.kyhsgeekcode.disassembler
22

33
import java.io.File
4+
import java.math.BigInteger
5+
import java.security.MessageDigest
46

57
val hexArray = "0123456789ABCDEF".toCharArray()
68
fun bytesToHex(bytes: ByteArray): String? {
@@ -19,4 +21,12 @@ fun bytesToHex(bytes: ByteArray): String? {
1921

2022
fun copyDirectory(fromDir: File, toDir: File) {
2123
fromDir.copyRecursively(toDir)
22-
}
24+
}
25+
26+
27+
fun ByteArray.digestString(digester: MessageDigest): String =
28+
BigInteger(1, digester.digest(this)).toString(16).padStart(32, '0')
29+
30+
31+
fun String.digest(digester: MessageDigest): String =
32+
this.toByteArray().digestString(digester)

0 commit comments

Comments
 (0)