File tree Expand file tree Collapse file tree
app/src/main/java/com/kyhsgeekcode/disassembler Expand file tree Collapse file tree Original file line number Diff line number Diff 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()
Original file line number Diff line number Diff line change 11package com.kyhsgeekcode.disassembler
22
33import java.io.File
4+ import java.math.BigInteger
5+ import java.security.MessageDigest
46
57val hexArray = " 0123456789ABCDEF" .toCharArray()
68fun bytesToHex (bytes : ByteArray ): String? {
@@ -19,4 +21,12 @@ fun bytesToHex(bytes: ByteArray): String? {
1921
2022fun 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)
You can’t perform that action at this time.
0 commit comments