Skip to content

Instantly share code, notes, and snippets.

@crcx
Last active December 28, 2018 19:05
Show Gist options
  • Save crcx/8420576c3d1c75d5374af5dc0781cd89 to your computer and use it in GitHub Desktop.
Save crcx/8420576c3d1c75d5374af5dc0781cd89 to your computer and use it in GitHub Desktop.

SEE

crc: d:words but no d:see ?

Retro includes a disassembler as part of the Autopsy debugger, but it's not quite a replacement for a traditional see as it requires both a starting address and the length. I decided to implement a see word using the disassembler. (This will likely be rolled into Autopsy soon).

Implementation

As mentioned before, this will use Autopsy's dissembler. It exposes a single word (see) to dictionary.

{{

First, constants for the instruction I need to identify when the end of a word is reached.

  #1793 'LIJU.... const
  #2049 'LICA.... const
  #10   'RE...... const
  #1    'LI...... const

I will use a variable to track the number of nested functions (quotes) within the word.

  'Nested var

And then a few shorter words to check against the instructions.

  :ju? LIJU.... eq? [ &n:inc dip &Nested v:inc ] if ;
  :li? LI...... eq? [ &n:inc dip ] if ;
  :ca? LICA.... eq? [ &n:inc dip ] if ;
  :re? RE...... eq? [ &Nested v:dec ] if @Nested n:zero? ;

With these I can see if we are at the end of a word.

  :at-end? (an-Af) dup ju? dup ca? dup li? re? ;

The last part is to wrap this all up in a simple loop.

  :find-length (a-n)
    #1 !Nested
    dup [ fetch-next at-end? ] until swap - ;
---reveal---

And with that, tie it to disassemble and I can see a word:

  :see (a-) dup find-length disassemble ;
}}

A Test

&d:words see

Future

The output format is not very easy to read:

:d:words [ d:name s:put sp ] d:for-each ;

Disassembles as:

(8670) 'liju.... i
(8671) #8678 d
(8672) 'lica.... i
(8673) #165 d		(possibly_`d:name`)
(8674) 'lica.... i
(8675) #8634 d		(possibly_`s:put`)
(8676) 'lica.... i
(8677) #8608 d		(possibly_`sp`)
(8678) 're...... i
(8679) 'li...... i
(8680) #8671 d
(8681) 'lica.... i
(8682) #6680 d		(possibly_`d:for-each`)
(8683) 're...... i

It'd be nice to have an easier to read format that makes it easier to identify the start and end of quotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment