Skip to content

Instantly share code, notes, and snippets.

@typcn
Last active March 5, 2017 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typcn/f7d70afe3c6f24b75dc57cd296c8b24b to your computer and use it in GitHub Desktop.
Save typcn/f7d70afe3c6f24b75dc57cd296c8b24b to your computer and use it in GitHub Desktop.
usb mouse move
import struct
from PIL import Image
import dpkt
import binascii
INIT_X, INIT_Y = 1000, 1000
def compliment(h):
i = int(h, 16)
return i - ((0x80 & i) << 1)
def print_map(pcap, device):
picture = Image.new("RGB", (2200, 2500), "white")
pixels = picture.load()
x, y = INIT_X, INIT_Y
for ts, buf in pcap:
mouse_data = buf[27:32]
mdstr = binascii.hexlify(mouse_data);
ml = len(mdstr)
if ml != 8:
continue
bits = int(mdstr[0] + mdstr[1],base=16)
bx = compliment(mdstr[2] + mdstr[3])
by = compliment(mdstr[4] + mdstr[5])
if bx > 20:
continue
if by > 20:
continue
status = bits
x = x + bx
y = y + by
if (status == 1):
for i in range(-5, 5):
for j in range(-5, 5):
pixels[x + i , y + j] = (0, 0, 0, 0)
else:
pixels[x, y] = (255, 0, 0, 0)
picture.save("out.png", "PNG")
if __name__ == "__main__":
f = open("1.pcap", "rb")
pcap = dpkt.pcap.Reader(f)
print_map(pcap, 3)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment