4 ms·
Hammer is a nifty parser combinator library from the people behind Language-Theoretic Security [1]. Their goal is to promote the use of context-free formats an
by ShaneWilton 11y ago
Hammer is a nifty parser combinator library from the people behind Language-Theoretic Security [1].
Their goal is to promote the use of context-free formats and protocols, to avoid falling into the trap of trying to parse recursively-enumerable languages, a problem that reduces to the halting problem. The idea is that by sticking to context-free grammars, protocols will be easier to parse, and the bulk of memory corruption errors can eliminated.
Meredith Patterson and Sergey Bratus gave an excellent talk on the subject at 28c3 [2], and they've put together a video series on using Hammer to build a secure parser for JSON RPC [3].
[1] http://langsec.org/ http://langsec.org/
[2] https://www.youtube.com/watch?v=3kEfedtQVOY https://www.youtube.com/watch?v=3kEfedtQVOY
[3] https://github.com/sergeybratus/HammerPrimer https://github.com/sergeybratus/HammerPrimer
- jcr 11y agoTheir 28c3 talk is truly exceptional, and it's nearly enough to give one nightmares, or at the very least, it will give you the kind of haunting enduring doubts that most would rather not have. The part about HTML5+CSS3 being unintentionally turning complete still bothers me.
- jzelinskie 11y agoIs there a video available of said talk?
- killercup 11y agoHave a look at http://media.ccc.de/browse/congress/2011/ http://media.ccc.de/browse/congress/2011/
- thedonald123 11y agoWhat do you lose by sticking to context-free grammars?
- rumcajz 11y agoAbility to prefix fields by size. Which in turn means you can't preallocate buffers because you don't know the sizes in advance.
- nly 11y agoMeh, you're probably going to want to limit your buffer size anyway in any highly concurrent system. Assuming you need to scan them anyway, delimited fields can also be faster to scan. If a field can't contain 0x00, and is 0x00 terminated (you can ensure this), then you don't need to do as many bounds-checks. If you know what you're doing, then Ragels 'noend' directive enables this, for instance.
- DasIch 11y agoAs the name suggests you lose context, you can't "remember" anything you've seen in the token stream. So you can't really parse languages that use indentation. Although you can circumvent that by processing indentation in the lexer or inbetween lexer and parser.