pysap.utils.fields module¶
- class pysap.utils.fields.ASN1F_CHOICE_SAFE(name, default, *args, **kwargs)[source]¶
Bases:
ASN1F_CHOICE
- class pysap.utils.fields.AdjustableFieldLenField(name, default, length_of=None)[source]¶
Bases:
Field- addfield(pkt, s, val)[source]¶
Add an internal value to a string
Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.
- adjust¶
- count_of¶
- getfield(pkt, s)[source]¶
Extract an internal value from a string
Extract from the raw packet s the field value belonging to layer pkt.
Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.
- length_of¶
- class pysap.utils.fields.ByteMultiEnumKeysField(name: str, default: int, enum: Dict[I, Dict[I, str]], depends_on: Callable[[Packet | None], I], fmt: str = 'H')[source]¶
Bases:
MultiEnumFieldMultiEnumField that picks a reduced number of values. Used for fuzzing Byte fields with reduced number of values.
- class pysap.utils.fields.IntToStrField(name, default, length=11)[source]¶
Bases:
FieldCustom field from int to str values, with a variable length
- format¶
- getfield(pkt, s)[source]¶
Extract an internal value from a string
Extract from the raw packet s the field value belonging to layer pkt.
Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.
- i2count(pkt, x)[source]¶
Convert internal value to a number of elements usable by a FieldLenField. Always 1 except for list fields
- length¶
- class pysap.utils.fields.MutablePacketField(name, default, length_from, get_class, evaluators=None)[source]¶
Bases:
StrLenFieldPacket field that mutates the class according to a list of evaluators. The evaluators are run against the packet and given to a class getter.
If the class can’t be found, the field is treated as a StrLenField.
- evaluators¶
- length_from¶
- class pysap.utils.fields.PacketListStopField(name, default, cls, count_from=None, length_from=None, stop=None)[source]¶
Bases:
PacketListFieldCustom field that contains a list of packets until a ‘stop’ condition is met.
- count_from¶
- getfield(pkt, s)[source]¶
Extract an internal value from a string
Extract from the raw packet s the field value belonging to layer pkt.
Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.
- length_from¶
- stop¶
- class pysap.utils.fields.PacketNoPadded(_pkt, /)[source]¶
Bases:
PacketRegular scapy packet with no padding.
- aliastypes = [<class 'pysap.utils.fields.PacketNoPadded'>, <class 'scapy.packet.Packet'>]¶
- class pysap.utils.fields.RandByteReduced[source]¶
Bases:
RandNumRandByte that only returns random values between 0 and x2a. Used while performing some fuzz to reduce the test cases space.
- class pysap.utils.fields.StrEncodedPaddedField(name, default, encoding='utf-16', padd=b'\x0c', fmt='H', remain=0)[source]¶
Bases:
StrField- addfield(pkt, s, val)[source]¶
Add an internal value to a string
Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.
- encoding¶
- getfield(pkt, s)[source]¶
Extract an internal value from a string
Extract from the raw packet s the field value belonging to layer pkt.
Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.
- padd¶
- remain¶
- class pysap.utils.fields.StrFixedLenDecodedField(name: str, default: bytes | None, length: int | None = None, length_from: Callable[[Packet], int] | None = None)[source]¶
Bases:
StrFixedLenFieldStrFixedLenField that decodes bytes to str in show() output.
- class pysap.utils.fields.StrFixedLenPaddedField(name, default, length=None, length_from=None, padd=' ', encoding=None)[source]¶
Bases:
StrFixedLenFieldPacket field that has a fixed length and is padded with a given character.
The optional encoding parameter enables transparent decoding of fields that carry multi-byte character encodings in a fixed-width byte buffer. This is required for SAP NetWeaver RFC SDK (NWRFC) connections, where fixed-length string fields are encoded in UTF-16LE rather than ASCII.
When encoding is set:
getfield()attempts to decode the raw bytes with encoding and strips trailing null and space padding from the decoded string. If decoding fails the raw bytes are returned unchanged (graceful fallback).addfield()encodes astrvalue with encoding, padding with NUL bytes, before writing.
- addfield(pkt, s, val)[source]¶
Add an internal value to a string
Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.
- encoding¶
- getfield(pkt, s)[source]¶
Extract an internal value from a string
Extract from the raw packet s the field value belonging to layer pkt.
Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.
- length_from¶
- padd¶
- class pysap.utils.fields.StrNullDecodedField(name: str, default: I | None, fmt: str = 'H', remain: int = 0)[source]¶
Bases:
StrNullFieldStrNullField that decodes bytes to str in show() output.
- class pysap.utils.fields.StrNullFixedLenField(name, default, length=None, length_from=None, max_length=None, null_terminated=None)[source]¶
Bases:
StrFixedLenFieldPacket field that has a fixed length and is conditionally null-terminated.
- addfield(pkt, s, val)[source]¶
Add an internal value to a string
Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.
- getfield(pkt, s)[source]¶
Extract an internal value from a string
Extract from the raw packet s the field value belonging to layer pkt.
Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.
- length_from¶
- max_length¶
- null_terminated¶
- class pysap.utils.fields.StrNullFixedLenPaddedField(name, default, length=None, length_from=None, padd=' ')[source]¶
Bases:
StrFixedLenFieldPacket field that has a fixed length and is padded with a given character and null terminated.
- addfield(pkt, s, val)[source]¶
Add an internal value to a string
Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.
- getfield(pkt, s)[source]¶
Extract an internal value from a string
Extract from the raw packet s the field value belonging to layer pkt.
Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.
- length_from¶
- padd¶