diff --git a/basis/tools/disassembler/disassembler.factor b/basis/tools/disassembler/disassembler.factor index 744318a0a4..0a8ab0b116 100755 --- a/basis/tools/disassembler/disassembler.factor +++ b/basis/tools/disassembler/disassembler.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: tr arrays sequences io words generic system combinators -vocabs.loader kernel ; +USING: alien alien.c-types arrays byte-arrays combinators +destructors generic io kernel libc math sequences system tr +vocabs.loader words ; IN: tools.disassembler GENERIC: disassemble ( obj -- ) @@ -12,6 +13,13 @@ HOOK: disassemble* disassembler-backend ( from to -- lines ) 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: word disassemble word-xt 2array disassemble ; diff --git a/core/byte-arrays/byte-arrays-docs.factor b/core/byte-arrays/byte-arrays-docs.factor index f1d94a46f7..56832a56e5 100644 --- a/core/byte-arrays/byte-arrays-docs.factor +++ b/core/byte-arrays/byte-arrays-docs.factor @@ -23,6 +23,10 @@ $nl 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 { $description "The class of byte arrays. See " { $link "syntax-byte-arrays" } " for syntax and " { $link "byte-arrays" } " for general information." } ; diff --git a/core/byte-arrays/byte-arrays.factor b/core/byte-arrays/byte-arrays.factor index 72989ac447..b32060ec99 100644 --- a/core/byte-arrays/byte-arrays.factor +++ b/core/byte-arrays/byte-arrays.factor @@ -1,9 +1,16 @@ ! Copyright (C) 2007, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors kernel kernel.private alien.accessors sequences -sequences.private math ; +USING: accessors alien.accessors ascii grouping kernel +kernel.private lexer math math.parser parser sequences +sequences.private ; 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 length length>> ; M: byte-array nth-unsafe swap >fixnum alien-unsigned-1 ;