def basic_deliver_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x00\x3c"), # Class h.token("\x00\x3c"), # Method h.end_p() ) return parser
def connection_start_ok_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x00\x0a"), # Class h.token("\x00\x0b"), # Method h.end_p() ) return parser
def connection_close_ok_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x00\x0a"), # Class h.token("\x00\x33"), # Method # No arguments h.end_p() ) return parser
def channel_open_ok_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x16\x28"), # Class h.token("\x00\x0b"), # Method # Arguments h.uint32(), # Channel-Id h.end_p() ) return parser
def basic_consume_ok_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x00\x3c"), # Class h.token("\x00\x15"), # Method # Arguments # consumer-tag h.end_p() ) return parser
def channel_open_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x00\x14"), # Class h.token("\x00\x0a"), # Method # Arguments h.ch('\x00'), # Out-of-bounds h.end_p() ) return parser
def connection_open_vhost_ok_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x00\x0a"), # Class h.token("\x00\x29"), # Method # Arguments h.ch('\x00'),# Known-Host # most likely going to change this according to the message h.end_p() ) return parser
def connection_tune_ok_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x00\x0a"), # Class h.token("\x00\x1f"), # Method # Arguments h.uint16(), # Channel max h.uint32(), # Frame max h.uint16(), # Heartbeat h.end_p() ) return parser
def connection_close_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x00\x0a"), # Class h.token("\x00\x32"), # Method # Arguments h.uint16(), # Replay-code #Replay-text h.uint16(), # Class-Id h.uint16(), # Method-Id h.end_p() ) return parser
def basic_consume_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x00\x3c"), # Class h.token("\x00\x14"), # Method # Arguments h.uint16(), # Ticket # how do you parse that long message? #Queue h.many(h.ch_range('\x00', '\xff')), # consumer-tag h.end_p() ) return parser
def queue_declare_ok_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x00\x32"), # Class h.token("\x00\x0b"), # Method # Arguments #how do you parse that long message? #Queue h.many(h.ch_range('\x00', '\xff')), #h.uint32(), # message-count #h.uint32(), # consumer-count h.end_p() ) return parser
def queue_declare_parser(): parser = h.sequence( h.ch('\x01'), # type h.uint16(), # Channel h.uint32(), # Length h.token("\x00\x32"), # Class h.token("\x00\x0a"), # Method # Arguments h.uint16(), # Ticket # how do you parse that long message?#Queue h.many(h.ch_range('\x00', '\xff')), #When you parse this out... (, ,, , 0L, ('','','','')) h.end_p() ) return parser
def get_version(text): version_string = h.right(h.token("SW: Version "), h.sepBy(alphanumeric, h.ch('.'))) version = h.whitespace(version_string) parser = h.action(version, tuple_string) for i in text.split("\n"): ret = parser.parse(i.encode('ascii','ignore')) if ret is not None: return {'os_version': ".".join(ret)}
def relay_definition_message(): header = h.token('\xa5\xc0') any_char = h.ch_range('\x00', '\xff') parser = h.sequence(header, h.uint8(), h.uint8(), h.uint8(), h.uint8(), h.many1(any_char)) return parser
def fast_meter_message(): header = h.token('\xa5\xd1') any_char = h.ch_range('\x00', '\xff') parser = h.sequence(header, h.uint8(), h.ch('\x00'), h.repeat_n(h.uint32(), 7), h.uint64(), h.repeat_n(any_char, 167), any_char) return parser
def relay_operate_configuration(): header = h.token('\xa5\xce') length = h.uint8() breaker_bits = h.uint8() remote_bits = h.uint16() remote_pulse = h.uint8() reserved = h.uint8() parser = h.sequence( header, length, breaker_bits, remote_bits, remote_pulse, reserved, h.repeat_n(h.uint8(), 2), h.repeat_n(h.sequence(h.uint8(), h.uint8(), h.uint8()), 32), h.uint8()) return parser
def fast_message_block(): header = h.token('\xa5\x46') length = h.uint8() routing_address = h.repeat_n(h.uint8(), 5) status = h.uint8() function_code = h.uint8() sequence_byte = h.uint8() response_number = h.uint8() any_value = h.many1(h.ch_range('\x00', '\xff')) crc = h.uint16() parser = h.sequence(header, length, routing_address, status, function_code, sequence_byte, response_number, any_value) return parser
def peak_fast_meter_configuration_block(): header = h.token("\xa5\xc3") length = h.uint8() scale_factors = h.uint8() analog = h.uint8() samples = h.uint8() digital = h.uint8() analog_offset = h.uint16() timestamp_offset = h.uint16() digital_offset = h.uint16() analog_signal = h.repeat_n(h.uint8(), 10) all_signals = h.repeat_n(analog_signal, 5) checksum = h.ch_range('\x00', '\xff') calculation_blocks = h.uint8() parser = h.sequence(header, length, h.uint8(), h.uint8(), scale_factors, analog, samples, digital, calculation_blocks, analog_offset, timestamp_offset, digital_offset, all_signals, checksum) return parser
def setUpClass(cls): cls.parser = h.token("95\xa2")
def setUpClass(cls): cls.parser = h.sequence(h.ch("a"), h.choice(h.sequence(h.ch("+"), h.not_(h.ch("+"))), h.token("++")), h.ch("b"))
def setUpClass(cls): cls.parser = h.difference(h.token("ab"), h.ch("a"))
def setUpClass(cls): cls.parser = h.butnot(h.ch("a"), h.token("ab"))
def setUpClass(cls): cls.parser = h.token(b"95\xa2")
def setUpClass(cls): cls.parser = h.sequence( h.ch(b"a"), h.choice(h.sequence(h.ch(b"+"), h.not_(h.ch(b"+"))), h.token(b"++")), h.ch(b"b"))
def setUpClass(cls): cls.parser = h.sequence(h.ch("a"), h.choice(h.ch("+"), h.token("++")), h.ch("b"))
def setUpClass(cls): cls.parser = h.butnot(h.ch(b"a"), h.token(b"ab"))
import hammer as h signals = h.choice(h.token("hmi.signal1"), h.token("hmi.signal2"), h.token("hmi.signal3"))
import hammer as h digit = h.ch_range('0','9') upper = h.ch_range('A', 'Z') lower = h.ch_range('a', 'z') chars = h.choice(digit, upper, lower) alphanumeric = h.many(chars) words = h.sepBy1(alphanumeric, h.ch(' ')) version = h.token("Version") allchars = h.ch_range("!", "~") printable_chars = h.many(allchars) token = h.many1(printable_chars) tokens = h.sepBy1(printable_chars, h.choice(h.ch(' '), h.ch('\n'), h.ch('\r'))) # Action Modifiers def tuple_string(t): new_coll = list() for c in t: if isinstance(c, tuple): new_coll.append("".join(c)) else: return "".join(t) return tuple(new_coll)
def setUpClass(cls): cls.parser = h.difference(h.token(b"ab"), h.ch(b"a"))
def schemaVersion_parser(): parser = h.sequence( h.token('0.6'), #SchemaVersion h.end_p()) return parser