Skip to content

Commit

Permalink
Move helper functions to util file
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrodie committed Jun 20, 2016
1 parent 92c1127 commit 7f130c6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
33 changes: 0 additions & 33 deletions app/src/main/java/app/adbuster/AdVpnService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -230,37 +230,4 @@ class AdVpnService : VpnService(), Handler.Callback {
}
return true
}


private fun logPacket(packet: ByteArray) = logPacket(packet, 0, packet.size)

private fun logPacket(packet: ByteArray, size: Int) = logPacket(packet, 0, size)

private fun logPacket(packet: ByteArray, offset: Int, size: Int) {
var logLine = "PACKET: <"
for (index in (offset..(size-1))) {
logLine += String.format("%02x", packet[index])
}

Log.i(TAG, logLine + ">")
}

private fun logPacketNice(packet: ByteBuffer) {
Log.i(TAG, "=============== PACKET ===============")
var logLine = String.format("%04x: ", 0)
for ((index, value) in packet.array().withIndex()) {
if (index != 0 && index % 16 == 0) {
Log.i(TAG, logLine)
logLine = String.format("%04x: ", index)
}

if (index == packet.limit()) {
break
}

logLine += String.format("%02x ", value)
}

Log.i(TAG, logLine)
}
}
35 changes: 35 additions & 0 deletions app/src/main/java/app/adbuster/Util.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
package app.adbuster

import android.util.Log
import java.nio.ByteBuffer

fun toHexString(ba: ByteArray) : String {
val str = StringBuilder()
for(c in ba) {
str.append(String.format("%x", c))
}
return str.toString()
}

private fun logPacket(TAG: String, packet: ByteArray) = logPacket(TAG, packet, 0, packet.size)

private fun logPacket(TAG: String, packet: ByteArray, size: Int) = logPacket(TAG, packet, 0, size)

private fun logPacket(TAG: String, packet: ByteArray, offset: Int, size: Int) {
var logLine = "PACKET: <"
for (index in (offset..(size-1))) {
logLine += String.format("%02x", packet[index])
}

Log.i(TAG, logLine + ">")
}

private fun logPacketNice(TAG: String, packet: ByteBuffer) {
Log.i(TAG, "=============== PACKET ===============")
var logLine = String.format("%04x: ", 0)
for ((index, value) in packet.array().withIndex()) {
if (index != 0 && index % 16 == 0) {
Log.i(TAG, logLine)
logLine = String.format("%04x: ", index)
}

if (index == packet.limit()) {
break
}

logLine += String.format("%02x ", value)
}

Log.i(TAG, logLine)
}

0 comments on commit 7f130c6

Please sign in to comment.