13.07.2015 Views

Doing Evil Things with Common Lisp

Doing Evil Things with Common Lisp

Doing Evil Things with Common Lisp

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Parsing Binary Files➲ In C, you just create a struct of the correctlayout, and use fread➲ <strong>Common</strong> <strong>Lisp</strong> has no built in support for thisidiom➲ BINARY-TYPES is a Cliki library that letsyou use the C idiom➲ (define-binary-class mach-header ()((magic:binary-type 'u32) ; should be #xfeedface(cpu-type :binary-type 'u32)(cpu-subtype :binary-type 'u32)(file-type :binary-type 'mach-filetype-constants)(ncmds:binary-type 'u32)(sizeof-cmds :binary-type 'u32)(flags:binary-type 'u32)))➲ (<strong>with</strong>-open-file (stream “foo”)(read-binary 'mach-header stream))=> CLOS Object of type MACH-HEADER

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!