How to use the pypacker.pypacker.Packet function in pypacker

To help you get started, we’ve selected a few pypacker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mike01 / pypacker / pypacker / layer12 / prism.py View on Github external
PRISM_TYPE_80211	= 0
PRISM_DID_RSSI		= 0x41400000


class Did(pypacker.Packet):
	__hdr__ = (
		("id", "I", 0),
		("status", "H", 0),
		("len", "H", 0),
		("value", "I", 0),
	)

	__byte_order__ = "<"


class Prism(pypacker.Packet):
	__hdr__ = (
		("code", "I", 0),
		("len", "I", 144),
		("dev", "16s", b"\x00" * 16),
		("dids", None, triggerlist.TriggerList),
	)

	__handler__ = {
		PRISM_TYPE_80211: ieee80211.IEEE80211
	}

	def _dissect(self, buf):
		off = 24
		# assume 10 DIDs, 24 + 10*12 = 144 bytes prism header
		end = off + 10 * 12
github mike01 / pypacker / pypacker / layer12 / btle.py View on Github external
__hdr__ = (
		("rand", "8s", b"\x00" * 8),
		("encrdiv", "H", 0),
		("masterdiv", "Q", 0),
		("masterinit", "I", 0)
	)


class LLEncResp(pypacker.Packet):
	__hdr__ = (
		("slavediv", "8s", b"\x00" * 8),
		("slaveinit", "I", 0)
	)


class LLStartEnc(pypacker.Packet):
	pass


class LLVersionInd(pypacker.Packet):
	__hdr__ = (
		("version", "B", 0),
		("company", "H", 0),
		("subcompany", "H", 0)
	)


class LLFeatureReq(pypacker.Packet):
	pass


class LLRejectInd(pypacker.Packet):
github mike01 / pypacker / pypacker / layer4 / tcp.py View on Github external
def _update_fields(self):
		if self.len_au_active:
			self.len = len(self)

TCP_PROTO_TELNET	= 23
TCP_PROTO_TPKT		= 102
TCP_PROTO_PMAP		= 111
TCP_PROTO_BGP		= 179
TCP_PROTO_SSL		= 443
TCP_PROTO_HTTP		= (80, 8008, 8080)
TCP_PROTO_RTP 		= (5004, 5005)
TCP_PROTO_SIP		= (5060, 5061)


class TCP(pypacker.Packet):
	__hdr__ = (
		("sport", "H", 0xdead),
		("dport", "H", 0, FIELD_FLAG_AUTOUPDATE | FIELD_FLAG_IS_TYPEFIELD),
		("seq", "I", 0xdeadbeef),
		("ack", "I", 0),
		("off_x2", "B", ((5 << 4) | 0), FIELD_FLAG_AUTOUPDATE),  # 10*4 Byte
		("flags", "B", TH_SYN),  # acces via (obj.flags & TH_XYZ)
		("win", "H", TCP_WIN_MAX),
		("sum", "H", 0, FIELD_FLAG_AUTOUPDATE),
		("urp", "H", 0),
		("opts", None, triggerlist.TriggerList)
	)

	# 4 bits | 4 bits
	# offset | reserved
	# offset * 4 = header length
github mike01 / pypacker / pypacker / layer12 / lldp.py View on Github external
("value", None, b""),
	)

	tlv_type = get_property_tlv_type()
	tlv_len = get_property_tlv_len()

	def _dissect(self, buf):
		self.value = buf[TLV_HEADER_LEN:]
		return len(buf)

	def _update_fields(self):
		if self._changed() and self.type_len_au_active:
			self.tlv_len = len(self) - TLV_HEADER_LEN


class LLDPSystemDescription(pypacker.Packet):
	__hdr__ = (
		("type_len", "H", 3072, FIELD_FLAG_AUTOUPDATE),  # type(6)
		("value", None, b""),
	)

	tlv_type = get_property_tlv_type()
	tlv_len = get_property_tlv_len()

	def _dissect(self, buf):
		self.value = buf[TLV_HEADER_LEN:]
		return len(buf)

	def _update_fields(self):
		if self._changed() and self.type_len_au_active:
			self.tlv_len = len(self) - TLV_HEADER_LEN
github mike01 / pypacker / pypacker / layer567 / diameter.py View on Github external
buflen = len(buf)

		# parse AVPs
		while off < buflen:
			avplen = int.from_bytes(buf[off + 5: off + 8], "big")
			# REAL length of AVP is multiple of 4 Bytes
			mod_len = avplen % 4
			if mod_len != 0:
				avplen += 4 - mod_len
			avp = AVP(buf[off: off + avplen])
			avps.append(avp)
			off += avplen
		return avps


class AVP(pypacker.Packet):
	__hdr__ = (
		("code", "I", 0),
		("flags", "B", 0),
		("len", "3s", b""),
	)

	def __get_v(self):
		return (self.flags >> 7) & 0x1

	def __set_v(self, v):
		self.flags = (self.flags & ~0x80) | ((v & 0x1) << 7)
	vendor_flag = property(__get_v, __set_v)

	def __get_m(self):
		return (self.flags >> 6) & 0x1
github mike01 / pypacker / pypacker / layer3 / gre.py View on Github external
GRE_CP = 0x8000	 # Checksum Present
GRE_RP = 0x4000	 # Routing Present
GRE_KP = 0x2000	 # Key Present
GRE_SP = 0x1000	 # Sequence Present
GRE_SS = 0x0800	 # Strict Source Route
GRE_AP = 0x0080	 # Acknowledgment Present

GRE_opt_fields = (
	(GRE_CP|GRE_RP, "sum", "H"),
	(GRE_CP|GRE_RP, "off", "H"),
	(GRE_KP, "key", "I"),
	(GRE_SP, "seq", "I"),
	(GRE_AP, "ack", "I")
	)

class GRE(pypacker.Packet):
	__hdr__ = (
		("flags", "H", 0),
		("p", "H", 0x0800), # ETH_TYPE_IP
		)
	#_protosw = {}
	#sre = ()
	def get_v(self):
		return self.flags & 0x7
	def set_v(self, v):
		self.flags = (self.flags & ~0x7) | (v & 0x7)
	v = property(get_v, set_v)

	def get_recur(self):
		return (self.flags >> 5) & 0x7
	def set_recur(self, v):
		self.flags = (self.flags & ~0xe0) | ((v & 0x7) << 5)
github mike01 / pypacker / pypacker / layer4 / sccp.py View on Github external
def _dissect(self, buf):
		pypacker.Packet._unpack(self, buf)
		n = self.len - 4
		if n > len(self.body_bytes):
			raise pypacker.NeedData("not enough data")
		# TODO: add dynamic field msg: ("msg", "%ds" % len(), msg)
		self.msg = ""
		self.msg, self.body_bytes = self.body_bytes[:n], self.body_bytes[n:]
		try:
			p = self._msgsw[self.msgid](self.msg)
			setattr(self, p.__class__.__name__.lower(), p)
		except (KeyError, pypacker.UnpackError):
			pass
github mike01 / pypacker / pypacker / layer12 / lldp.py View on Github external
("value", None, b""),
	)

	tlv_type = get_property_tlv_type()
	tlv_len = get_property_tlv_len()

	def _dissect(self, buf):
		self.value = buf[TLV_HEADER_LEN:]
		return len(buf)

	def _update_fields(self):
		if self._changed() and self.type_len_au_active:
			self.tlv_len = len(self) - TLV_HEADER_LEN


class LLDPSystemCapabilities(pypacker.Packet):
	__hdr__ = (
		("type_len", "H", 3588),  # type(7), length(4)
		("capabilities", "H", 0),
		("enabled", "H", 0),
	)
	tlv_type = get_property_tlv_type()
	tlv_len = get_property_tlv_len()


class LLDPManagementAddress(pypacker.Packet):
	__hdr__ = (
		("type_len", "H", 4096, FIELD_FLAG_AUTOUPDATE),
		# contains the length of the addrsubtype(1 byte) + addrval(1-31 bytes) fields
		("addrlen", "B", 2, FIELD_FLAG_AUTOUPDATE),
		("addrsubtype", "B", 0),
		("addrval", None, b"\x00"),
github mike01 / pypacker / pypacker / layer12 / btle.py View on Github external
def __get_crcinit_rev_int(self):
		return unpack_I(b"\x00" + self.crcinit_rev)[0]

	crcinit_rev_int = property(__get_crcinit_rev_int)

#
# Data packets
#


class DataLLID0(pypacker.Packet):
	pass


class DataLLID1(pypacker.Packet):
	pass


class DataLLID2(pypacker.Packet):
	pass


# LLX-packets
class LLTerminateInd(pypacker.Packet):
	pass


class LLEncReq(pypacker.Packet):
	__hdr__ = (
		("rand", "8s", b"\x00" * 8),
		("encrdiv", "H", 0),
github mike01 / pypacker / pypacker / layer3 / ip6.py View on Github external
def __get_frag_off(self):
		return self.frag_off_resv_m >> 3

	def __set_frag_off(self, v):
		self.frag_off_resv_m = (self.frag_off_resv_m & ~0xfff8) | (v << 3)
	frag_off = property(__get_frag_off, __set_frag_off)

	def __get_m_flag(self):
		return self.frag_off_resv_m & 1

	def __set_m_flag(self, v):
		self.frag_off_resv_m = (self.frag_off_resv_m & ~0xfffe) | v
	m_flag = property(__get_m_flag, __set_m_flag)


class IP6AHHeader(pypacker.Packet):
	__hdr__ = (
		("nxt", "B", 0),			 # next extension header protocol
		("len", "B", 0),			 # length of header in 4 octet units (ignoring first 2 units)
		("resv", "H", 0),			 # reserved, 2 bytes of 0
		("spi", "I", 0),			 # SPI security parameter index
		("seq", "I", 0)				 # sequence no.
	)


class IP6ESPHeader(pypacker.Packet):
	def _dissect(self, buf):
		raise NotImplementedError("ESP extension headers are not supported.")


class IP6DstOptsHeader(IP6OptsHeader):
	def _dissect(self, buf):