Skip to content

Commit f3b75e1

Browse files
committed
Code refine: byte2hex
Signed-off-by: XhstormR <[email protected]>
1 parent b7b2445 commit f3b75e1

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

app/src/main/java/com/example/leo/monitor/util/SHA256.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ object SHA256 {
2121
}
2222
}
2323

24-
return byte2Hex(digest.digest())
24+
return digest.digest().toHEX()
2525
}
2626

2727
fun hash(input: String): String {
2828
val digest = digestProvider()
29-
return byte2Hex(digest.digest(input.toByteArray()))
29+
return digest.digest(input.toByteArray()).toHEX()
3030
}
3131

3232
fun hash(input: ByteArray): String {
3333
val digest = digestProvider()
34-
return byte2Hex(digest.digest(input))
34+
return digest.digest(input).toHEX()
3535
}
3636
}

app/src/main/java/com/example/leo/monitor/util/Util.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import com.squareup.moshi.Moshi
1010
import de.robv.android.xposed.XposedHelpers
1111
import java.io.File
1212
import java.util.concurrent.ConcurrentHashMap
13+
import okio.ByteString
1314
import okio.GzipSink
1415
import okio.HashingSource
1516
import okio.Okio
1617
import org.json.JSONObject
1718

1819
inline fun <reified T> clazz() = T::class.java
1920

20-
fun ByteArray.toHEX() =
21-
this.joinToString("") { String.format("%02x", it) }
21+
fun ByteArray.toHEX(): String =
22+
ByteString.of(this, 0, this.size).hex()
2223

2324
fun ByteArray.contains(bytes: ByteArray) =
2425
this.indexOf(bytes) != -1
@@ -53,14 +54,6 @@ fun currentApplicationHash(sourceApk: File = File(AndroidAppHelper.currentApplic
5354
.apply { Okio.buffer(this).use { it.readAll(Okio.blackhole()) } }
5455
.hash().hex()
5556

56-
fun byte2Hex(bytes: ByteArray) = StringBuilder(bytes.size * 2)
57-
.apply {
58-
for (byte in bytes) {
59-
append("%02x".format(byte))
60-
}
61-
}
62-
.toString()
63-
6457
fun gzip(input: File, output: File) {
6558
Okio.buffer(Okio.source(input)).use { source ->
6659
Okio.buffer(GzipSink(Okio.sink(output))).use { sink -> sink.writeAll(source) }

app/src/main/java/com/example/leo/monitor/xposed/ParseGenerator.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import java.io.FileOutputStream
1717
import java.net.Socket
1818
import javax.crypto.Cipher
1919
import javax.crypto.Mac
20+
import okio.ByteString
2021

2122
object ParseGenerator {
2223

@@ -153,9 +154,14 @@ object ParseGenerator {
153154
return "${action}_${cipher.algorithm}"
154155
}
155156

157+
private fun parseByteArray(obj: ByteArray) =
158+
if (obj.size > DEFAULT_BUFFER_SIZE) obj.toString()
159+
else ByteString.of(obj, 0, obj.size).base64()
160+
156161
fun parseObject(obj: Any?): Any = when (obj) {
157162
is List<*> -> obj.map { parseObject(it) }
158163
is Array<*> -> obj.map { parseObject(it) }
164+
is ByteArray -> parseByteArray(obj)
159165
else -> obj.toString()
160166
}
161167
}

assets/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22
# place this file at /data/adb/service.d
33
# https://github.com/topjohnwu/Magisk/blob/master/docs/guides.md#boot-scripts
4+
# adb push run.sh /data/local/tmp/run.sh && adb shell "su -c 'mv /data/local/tmp/run.sh /data/adb/service.d/run.sh && chmod +x /data/adb/service.d/run.sh'"
45

56
sleep 60
67
am start --user 19 com.example.leo.monitor
8+
am start -a android.intent.action.MAIN -c android.intent.category.HOME

0 commit comments

Comments
 (0)