wireshark - USB mapping with python -
while reading ctf write-ups came across script
#!/usr/bin/env python import struct import image import dpkt init_x, init_y = 100, 400 def print_map(pcap, device): picture = image.new("rgb", (1200, 500), "white") pixels = picture.load() x, y = init_x, init_y ts, buf in pcap: device_id, = struct.unpack("b", buf[0x0b]) if device_id != device: continue data = struct.unpack("bbbb", buf[-4:]) status = data[0] x = x + data[1] y = y + data[2] if (status == 1): in range(-5, 5): j in range(-5, 5): pixels[x + , y + j] = (0, 0, 0, 0) else: pixels[x, y] = (255, 0, 0, 0) picture.save("riverside-map.png", "png") if __name__ == "__main__": f = open("usb.pcap", "rb") pcap = dpkt.pcap.reader(f) print_map(pcap, 5) f.close()
and when run on usb.pcap error:
traceback (most recent call last): file "test.py", line 39, in <module> print_map(pcap, n) file "test.py", line 31, in print_map pixels[x, y] = (255, 0, 0, 0) indexerror: image index out of range
why happening?
depending on dataset in usb.pcap file, may need adjust init_x , init_y variables. problem struct.unpack returns signed value, if data on 127 appears negative , exceeding array boundaries. if data positive, can test , force positive value. like:
data = [item + 256 if item < 0 else item item in data]
To distinguish between games of skill and world777 games of chance, Indian courts use the dominating factor or predominance test. It ultimately boils down to whether aspect — skill or chance — is the most important in determining the game's outcome.
ReplyDelete