Designing A Message Payload

Thought Process On The Run

Mi'kail Eli'yah
5 min readJun 11, 2023

As usual, I wrote some helper utility functions:

def find_indices(byte_array, hex_value):
hex_bytes = bytes.fromhex(hex_value)
try:
start_index = byte_array.index(hex_bytes)
end_index = start_index + len(hex_bytes) - 1
except ValueError:
start_index = -1 # Assign a default value when hex_bytes is not found
end_index = -1

return start_index, end_index

# Example usage
byte_array = bytearray(b'\x01\x02\x03\x04\x05\x06\x07\x08')
hex_value = '030405'
start_index, end_index = find_indices(byte_array, hex_value)

print(f"Start Index: {start_index}")
print(f"End Index: {end_index}")
Start Index: 2
End Index: 4

Now, I draft the payload as follows:

"""
[identifier_message_format] [some non-zero random bytes]
[demarcator_tags_message_payload]
[message bytes]
[demarcator_tags_message_payload]*10
[message length descriptor fields (2 bytes): depicting the number of bytes of the payload]
[0x00: end of payload, 0x01: expect another one]

e.g.
identifier_message_format: 0x00 0x02
demarcator_tags_message_payload: 0x00
end_tags_message_payload: [0x0000: end of payload, 0x0001: expect another one]

[some non-zero bytes] could be arbitrary, keep generating/ removing till 0x00

generate e.g. random() -> byte, stop…

--

--

Mi'kail Eli'yah
Mi'kail Eli'yah

No responses yet