1 year ago

#144420

test-img

k1k4ss0

why in the raw data the first byte is in asciii

I've got the followings raw data in bytes :

b'\r\xdc\xc9\x00\x00\x00\x00\x00\x9f\x03\xdf\x00\x9f\x03\xdfI\x82W\x00\x00\x97\x00'
b'\x16\xd9\xc9\x00\x00\x00\x00\x00\x9f\x03\xdf\x00\x9f\x03\xdfI\xf2d\x02\x00\x97\x00'
b'K\xde\xc9\x01\x00\x00\x00\x00\x9f\x03\xdf\x00\x9f\x03\xdfI\x82W\x00\x00\x97\x00'
b':\xda\xc9\x02\x00\x00\x00\x00\x9f\x03\xdf\x00\x9f\x03\xdfI\x82W\x00\x00\x97\x00'
b'B\xda\xc9\x00\x00\x00\x00\x00\x9f\x03\xdf\x00\x9f\x03\xdfI\x82W\x00\x00\x97\x00'
b'\x15\xdb\xc9\x01\x00\x00\x00\x00\x9f\x03\xdf\x00\x9f\x03\xdfI\x82W\x00\x00\x97\x00'

As you can see the first value is in ascii. For example this couple are the same:

b'B\xda\xc9\x00\x00\x00\x00\x00\x9f\x03\xdf\x00\x9f\x03\xdfI\x82W\x00\x00\x97\x00'

enter image description here

Looking into the code of pyshark i see this :

def get_raw_packet(self):
  assert "FRAME_RAW" in self, "Packet contains no raw data. In order to contains it, " \
                                    "make sure that use_json and include_raw are set to True " \
                                    "in the Capture object"
  raw_packet = b''
  byte_values = [''.join(x) for x in zip(self.frame_raw.value[0::2], self.frame_raw.value[1::2])]
    for value in byte_values:
      raw_packet += binascii.unhexlify(value)
    return raw_packet

And my code is the following :

import pyshark
from pyshark.capture.pipe_capture import PipeCapture
import os
FIFO = 'informacion.pcap'
def print_callback(pkt):
  print (pkt.get_raw_packet())


with open(FIFO) as fifo:
  capture = PipeCapture(pipe=fifo,use_json=True,include_raw=True)
  capture.apply_on_packets(print_callback)

python-3.x

byte

ascii

pcap

pyshark

0 Answers

Your Answer

Accepted video resources