macho: add utility for getting exported symbols from a dylib

release
Joe Groff 2010-04-14 14:37:21 -07:00
parent 94c0382b99
commit 3544568fe8
1 changed files with 22 additions and 3 deletions

View File

@ -1,9 +1,10 @@
! Copyright (C) 2010 Erik Charlebois. ! Copyright (C) 2010 Erik Charlebois.
! See http:// factorcode.org/license.txt for BSD license. ! See http:// factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.strings alien.syntax USING: accessors alien alien.c-types alien.strings alien.syntax
classes classes.struct combinators io.encodings.ascii classes classes.struct combinators combinators.short-circuit
io.encodings.string kernel literals make math sequences io.encodings.ascii io.encodings.string kernel literals make
specialized-arrays typed fry io.mmap formatting locals ; math sequences specialized-arrays typed fry io.mmap formatting
locals splitting ;
FROM: alien.c-types => short ; FROM: alien.c-types => short ;
IN: macho IN: macho
@ -912,6 +913,9 @@ TYPED: load-commands ( macho: mach_header_32/64 -- load-commands )
: symbol-name ( symbol string-table -- name ) : symbol-name ( symbol string-table -- name )
[ n_strx>> ] dip <displaced-alien> ascii alien>string ; [ n_strx>> ] dip <displaced-alien> ascii alien>string ;
: c-symbol-name ( symbol string-table -- name )
symbol-name "_" ?head drop ;
: with-mapped-macho ( path quot -- ) : with-mapped-macho ( path quot -- )
'[ '[
address>> macho-header @ address>> macho-header @
@ -930,3 +934,18 @@ TYPED: load-commands ( macho: mach_header_32/64 -- load-commands )
] curry each ] curry each
] each ] each
] with-mapped-macho ; ] with-mapped-macho ;
: dylib-export? ( symtab-entry -- ? )
n_type>> {
[ N_EXT bitand zero? not ]
[ N_TYPE bitand N_UNDF = not ]
} 1&& ;
: dylib-exports ( path -- symbol-names )
[| macho |
macho load-commands symtab-commands [| symtab |
macho symtab symbols
[ [ dylib-export? ] filter ]
[ [ c-symbol-name ] curry { } map-as ] bi*
] { } map-as concat
] with-mapped-macho ;