disassemble method for byte-arrays. HEX{ abcd } syntax for byte-arrays
parent
afb3825b8e
commit
7493e07c68
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: tr arrays sequences io words generic system combinators
|
USING: alien alien.c-types arrays byte-arrays combinators
|
||||||
vocabs.loader kernel ;
|
destructors generic io kernel libc math sequences system tr
|
||||||
|
vocabs.loader words ;
|
||||||
IN: tools.disassembler
|
IN: tools.disassembler
|
||||||
|
|
||||||
GENERIC: disassemble ( obj -- )
|
GENERIC: disassemble ( obj -- )
|
||||||
|
@ -12,6 +13,13 @@ HOOK: disassemble* disassembler-backend ( from to -- lines )
|
||||||
|
|
||||||
TR: tabs>spaces "\t" "\s" ;
|
TR: tabs>spaces "\t" "\s" ;
|
||||||
|
|
||||||
|
M: byte-array disassemble
|
||||||
|
[
|
||||||
|
[ malloc-byte-array &free alien-address dup ]
|
||||||
|
[ length + ] bi
|
||||||
|
2array disassemble
|
||||||
|
] with-destructors ;
|
||||||
|
|
||||||
M: pair disassemble first2 disassemble* [ tabs>spaces print ] each ;
|
M: pair disassemble first2 disassemble* [ tabs>spaces print ] each ;
|
||||||
|
|
||||||
M: word disassemble word-xt 2array disassemble ;
|
M: word disassemble word-xt 2array disassemble ;
|
||||||
|
|
|
@ -23,6 +23,10 @@ $nl
|
||||||
|
|
||||||
ABOUT: "byte-arrays"
|
ABOUT: "byte-arrays"
|
||||||
|
|
||||||
|
HELP: HEX{
|
||||||
|
{ $syntax "HEX{ 0123 45 67 89abcdef }" }
|
||||||
|
{ $description "Constructs a " { $link byte-array } " from data specified in hexadecimal format. Whitespace between the curly braces is ignored." } ;
|
||||||
|
|
||||||
HELP: byte-array
|
HELP: byte-array
|
||||||
{ $description "The class of byte arrays. See " { $link "syntax-byte-arrays" } " for syntax and " { $link "byte-arrays" } " for general information." } ;
|
{ $description "The class of byte arrays. See " { $link "syntax-byte-arrays" } " for syntax and " { $link "byte-arrays" } " for general information." } ;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
! Copyright (C) 2007, 2009 Slava Pestov.
|
! Copyright (C) 2007, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors kernel kernel.private alien.accessors sequences
|
USING: accessors alien.accessors ascii grouping kernel
|
||||||
sequences.private math ;
|
kernel.private lexer math math.parser parser sequences
|
||||||
|
sequences.private ;
|
||||||
IN: byte-arrays
|
IN: byte-arrays
|
||||||
|
|
||||||
|
SYNTAX: HEX{
|
||||||
|
"}" parse-tokens "" join
|
||||||
|
[ blank? not ] filter
|
||||||
|
2 group [ hex> ] B{ } map-as
|
||||||
|
parsed ;
|
||||||
|
|
||||||
M: byte-array clone (clone) ;
|
M: byte-array clone (clone) ;
|
||||||
M: byte-array length length>> ;
|
M: byte-array length length>> ;
|
||||||
M: byte-array nth-unsafe swap >fixnum alien-unsigned-1 ;
|
M: byte-array nth-unsafe swap >fixnum alien-unsigned-1 ;
|
||||||
|
|
Loading…
Reference in New Issue