Created
June 23, 2013 00:52
-
-
Save introom/5843289 to your computer and use it in GitHub Desktop.
payload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
byte, short and other C types are serialized in network/big endian | |
""" | |
grammarSource = r""" | |
byte = anything:b -> ord(b) | |
short = byte:high byte:low -> high << 8 | low | |
int = short:high short:low -> high << 16 | low | |
header = short:id byte:byte3 byte:byte4 !(DNSParser.updateHeader(id, byte3, byte4)) | |
short:nqueries short:nans short:nns short:nadd -> nqueries, nans, nns, nadd | |
query = name:n short:type short:cls !(DNSParser.updateQuery(n, type, cls)) | |
name = !(DNSParser.preName()) label* (byte:b ?(b == 0) -> DNSParser.tempName | |
| pointer !(DNSParser.postName()) -> DNSParser.tempName) | |
label = byte:l ?(0 < l < 64) <byte{l}>:la !(DNSParser.updateName(la)) | |
pointer = byte:ptrH ?(ptrH >> 6 == 3) byte:ptrL !(DNSParser.updateNameOffset(ptrH, ptrL)) | |
rrheader = name:n short:type short:cls int:ttl short:rdlength | |
(->DNSParser.msg.lookupRecordType(type)):t ?(t) payload | |
# payload = byte{} | |
start = header:h (->h[0]):nqueries query{nqueries} (->h[1]):nans rrheader{nans} | |
(->h[2]):nns rrheader{nns} (->h[3])nadd rrheader{nadd} | |
digit = :x ?(x in '0123456789') -> x | |
| :y -> dict() | |
""" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In line #24, the payload of parsing depends on the type of t. I think I should add an expression like !(DNSParser.parser.doparseGrammar(t.type)) but I don't know the correct syntax.
The logic is corresponding to header.payload.decode inside Message.parseRecords