[racket-dev] A disassembler for Racket

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Wed Jan 5 17:28:17 EST 2011

I've been on-and-off working on a disassembler for jitted x86
functions in Racket, and it now seems to work well enough to show
other people.

You can find it at http://github.com/samth/disassemble . You'll need
`ndisasm' in your path.

To use it, try something like this:

[samth at punge:~/sw/disassemble (master) plt] racket
Welcome to Racket v5.0.99.6.
> (enter! "decompiler.rkt")
> (define (const x) 1)
> (const 3) ;; makes sure that `const' is jitted
> (decompile const)
00000000  8943FC            mov [ebx-0x4],eax
00000003  83C3FC            add ebx,byte -0x4
00000006  B803000000        mov eax,0x3
0000000B  83C41C            add esp,byte +0x1c
0000000E  5F                pop edi
0000000F  5E                pop esi
00000010  5B                pop ebx
00000011  5D                pop ebp
00000012  C3                ret

Currently, `decompile' takes a #:size parameter which specifies how
many bytes to decompile, because it doesn't understand x86 code enough
to find the end of the function.

Patches, uses, complaints, and suggestions are all welcome.

Thanks to Felix Klock and Matthew Flatt for advice, and to Stevie
Strickland and Vincent St-Amour for derision.
sam th
samth at ccs.neu.edu

Posted on the dev mailing list.