WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

HexDump.scala 2.35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package uvm.utils

import jnr.ffi.Pointer
import jnr.ffi.Runtime
import uvm.refimpl.mem.TypeSizes._
import scala.annotation.elidable
import scala.annotation.elidable.ASSERTION
import java.nio.ByteBuffer

/**
 * Show binary data in hexadecimal bytes notations.
 */
object HexDump {
  val mem = Pointer.wrap(Runtime.getSystemRuntime, 0L)

  val LINE_SIZE = 16
  
  def dumpByteBuffer(buf: ByteBuffer): String = dumpByteBuffer(buf, 0, buf.limit())
  
  def dumpByteBuffer(buf: ByteBuffer, begin: Int, size: Int): String = {
    val hd = new HexDump(begin)
    for (addr <- begin until (begin + size)) {
      val b = buf.get(addr)
      hd.addByte(b)
    }
    hd.finish()
  }

  def dumpMemory(begin: Long, size: Long): String = {
    val hd = new HexDump(begin)
    for (addr <- begin until (begin + size)) {
      val b = mem.getByte(addr)
      hd.addByte(b)
    }
    hd.finish()
  }
}

class HexDump(beginAddr: Long) {
  import HexDump._

  val buf = new Array[Byte](16)
  var curLineAddr: Long = alignDown(beginAddr, 16)
  var curLineSize: Int = (beginAddr - curLineAddr).toInt
  var linePreSkip: Int = curLineSize
  var linePostSkip: Int = 0
  val sb = new StringBuilder()

  def addByte(b: Byte) {
    buf(curLineSize) = b
    curLineSize += 1
    if (curLineSize == LINE_SIZE) {
      processLine()
    }
  }

  def processLine() {
    assert(curLineSize == LINE_SIZE, "Line not full: current: %d, expected: %d".format(curLineSize, LINE_SIZE))

    sb ++= "%16x".format(curLineAddr)
    sb ++= ":   "

    for ((b, i) <- buf.zipWithIndex) {
      val padding = i match {
        case 0 => ""
        case 8 => "  "
        case _ => " "
      }
      sb ++= padding

      val num = if (i < linePreSkip || i + linePostSkip >= LINE_SIZE) "  "
      else "%02x".format(b)

      sb ++= num
    }

    sb ++= "    "

    sb ++= "|"
    for ((b, i) <- buf.zipWithIndex) {
      val chr = if (i < linePreSkip || i + linePostSkip >= LINE_SIZE) " "
      else if (32 <= b && b <= 126)  b.toChar.toString() else "."

      sb ++= chr

    }
    sb ++= "|"

    sb ++= "\n"

    curLineSize = 0
    linePreSkip = 0
    linePostSkip = 0
    curLineAddr += LINE_SIZE
  }

  def finish(): String = {
    if (curLineSize > 0) {
      if (curLineSize < 16) {
        linePostSkip = (alignUp(curLineSize, 16) - curLineSize).toInt
        curLineSize = 16
      }
      processLine()

    }
    sb.toString()
  }
}