Post Reply 
(newRPL) Hex dump
10-29-2021, 09:33 PM
Post: #1
(newRPL) Hex dump
Curious about internal representation of newRPL objects but can't stand reading code?
Retroengineering is your hobby?

Here's a quick aid for your investigation, meet HEXDUMP: given an object it will return its size and the classic hex dump divided in 8 bytes chunks (a small font is advised).

E.g. 1_mm HEXDUMP

Code:

24
"00: 05 00 68 03 01 00 E0 00  ..h...à.
08: 01 00 08 02 6D 6D 00 00  ....mm..
10: 01 00 E0 00 01 00 E0 00  ..à...à."

Enjoy!

Code:

« → o
  « o BYTES SWAP DROP                                           @ Compute size
    DUP MKBINDATA                                               @ Create suitable BINDATA object
    0 o BINPUTOBJ                                               @ Store object in it
    'bin' LSTO
    'size' LSTO
    size LN 16 LN / CEIL 'dgt' LSTO                             @ How many hex digits is size?
    0 size 1 - FOR 'i'
      "00000000" #0h i + →STR TAIL RTAIL +                      @ Format the offset string: a field of
      DUP SIZE DUP dgt - 1 + SWAP SUB ":" +                     @ 'dgt' digits, rhs justified and trailed by ":"
      bin size i -                                              @ How many bytes remain? More than 8 or less?
      8 MIN                                                     @ i.e. necessarily 4, since newRPL objects are
      i SWAP BINGETB                                            @ word aligned. Take a chunk for the byte dump
      BINGETB                                                   @ and another one for the char dump
      IF DUP SIZE 8 - THEN                                      @ If 4 bytes remain, pad them with #0000h
        { #0h #0h #0h #0h } ADD
      END
      DUP 1 « →STR TAIL RTAIL "0" SWAP +                        @ Remove "#" and "h" from bytes,
              DUP SIZE DUP 1 - SWAP SUB                         @ pad them with "0"'s and add a leading space
              " " SWAP + » DOLIST
      "  " ADD                                                  @ Add some space
      SWAP 1 « IF DUP 32 < THEN DROP #2Eh END →UTF8 » DOLIST    @ Turn bytes into printable characters
      ADD ADD 10 →UTF8 ADD                                      @ Concatenate lists and add a new line
      ΣLIST                                                     @ Concatenate all strings
    8 STEP                                                      @ Next 8 bytes
    size 8 / CEIL →LIST ΣLIST RTAIL                             @ Concatenate all lines, trim last newline
    size SWAP                                                   @ Return original size and hexdump
  »
»
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(newRPL) Hex dump - JoJo1973 - 10-29-2021 09:33 PM
RE: (newRPL) Hex dump - Claudio L. - 11-02-2021, 02:27 PM
RE: (newRPL) Hex dump - JoJo1973 - 11-02-2021, 09:14 PM
RE: (newRPL) Hex dump - Claudio L. - 11-05-2021, 08:09 PM



User(s) browsing this thread: 1 Guest(s)