Bitstring

Bitstring package contains bitstrings and bitmatching for OCaml.
Download

Bitstring Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL
  • Price:
  • FREE
  • Publisher Name:
  • Richard Jones
  • Publisher web site:
  • http://code.google.com/p/bitstring/

Bitstring Tags


Bitstring Description

Bitstring package contains bitstrings and bitmatching for OCaml. Bitstring package contains bitstrings and bitmatching for OCaml.The ocaml-bitstring project adds Erlang-style bitstrings and matching over bitstrings as a syntax extension and library for OCaml.(This project was formerly known as "bitmatch").You can use this module to both parse and generate binary formats, files and protocols.Bitstring handling is added as primitives to the language, making it exceptionally simple to use and very powerful.Here is how to parse the header from a GIF image: let bits = Bitstring.bitstring_of_file "image.gif" in bitmatch bits with | { ("GIF87a"|"GIF89a") : 6*8 : string; (* GIF magic. *) width : 16 : littleendian; height : 16 : littleendian } -> printf "%s: GIF image is %d x %d pixels" filename width height | { _ } -> eprintf "%s: Not a GIF imagen" filenameThis example shows how to parse the first few fields in a Linux ELF binary (see < elf.h >): let bits = Bitstring.bitstring_of_file "/bin/ls" in bitmatch bits with | { 0x7f : 8; "ELF" : 24 : string; (* ELF magic number *) e_ident : 12*8 : bitstring; (* ELF identifier *) e_type : 16 : littleendian; (* object file type *) e_machine : 16 : littleendian (* architecture *) } -> printf "This is an ELF binary, type %d, arch %dn" e_type e_machine;Bitstring handles integers, strings, sub-bitstrings, big-, little- and native-endianness, signed and unsigned types, variable-width fields, fields with arbitrary bit alignment. What's New in This Release:· Many examples have been added, including a tcpdump file printer and GIF and ELF header display.


Bitstring Related Software