Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f = open('/tmp/ctfkleph/dump.txt')
- mouse = 'USB_DEVICE_ID_APPLE_MAGICTRACKPAD2'
- mouse = 'USB_DEVICE_ID_APPLE_MAGICTRACKPAD'
- mouse = 'USB_DEVICE_ID_APPLE_MAGICMOUSE'
- TOUCH_STATE_MASK = 0xf0
- TOUCH_STATE_NONE = 0x00
- valid_reports = [0x28, 0x02, 0x31, 0x29, 0xf7]
- def magicmouse_emit_touch(data):
- arr = data.split(':')
- tdata = [int(x, 16) for x in arr]
- # print tdata
- # sba = [hex(x) for x in tdata]
- presure=""
- if mouse == "USB_DEVICE_ID_APPLE_MAGICMOUSE":
- id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf
- x = (tdata[1] << 28 | tdata[0] << 20) >> 20
- y = -((tdata[2] << 24 | tdata[1] << 16) >> 20)
- size = tdata[5] & 0x3f
- orientation = (tdata[6] >> 2) - 32
- touch_major = tdata[3]
- touch_minor = tdata[4]
- state = tdata[7] & TOUCH_STATE_MASK
- down = state != TOUCH_STATE_NONE
- if mouse == "USB_DEVICE_ID_APPLE_MAGICTRACKPAD2":
- id = tdata[8] & 0xf
- x = (tdata[1] << 27 | tdata[0] << 19) >> 19
- y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19)
- size = tdata[6]
- orientation = (tdata[8] >> 5) - 4
- touch_major = tdata[4]
- touch_minor = tdata[5]
- pressure = tdata[7]
- state = tdata[3] & 0xC0
- down = state == 0x80
- if mouse == "USB_DEVICE_ID_APPLE_MAGICTRACKPAD":
- id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf
- x = (tdata[1] << 27 | tdata[0] << 19) >> 19
- y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19)
- size = tdata[6] & 0x3f
- orientation = (tdata[7] >> 2) - 32
- touch_major = tdata[4]
- touch_minor = tdata[5]
- state = tdata[8] & TOUCH_STATE_MASK
- down = state != TOUCH_STATE_NONE
- res = {
- 'id': id,
- 'x' : x,
- 'y' : y,
- 'size' : size,
- 'orientation' : orientation,
- 'presure' : presure,
- 'major' : touch_major,
- 'minor' : touch_minor,
- 'state' : state,
- 'down' : down
- }
- return res
- # for offset in range(7):
- # print "processing offset %s" % offset
- print "Test for mouse %s" % mouse
- fic = open('%s.txt' % "plot.txt", 'w')
- for line in f.readlines():
- line = line.strip()
- if len(line) > 13:
- elts = line.split(':')
- newline= ":".join(elts[9::])
- # if elts[offset] in valid_reports:
- # print newline, len(newline.split(':'))
- if len(newline)<1: continue
- res = magicmouse_emit_touch(newline[6:])
- print "id={id},x={x},y={y},size={size},orientation={orientation},major={major},minor={minor},state={state},down={down},presure={presure}".format(
- id=res['id'], x=res['x'], y=res['y'], size=res['size'],
- orientation=res['orientation'], major=res['major'],
- minor=res['minor'], state=res['state'], down=res['down'],
- presure=res['presure']
- )
- fic.write('%s %s\n' % (res['x'], res['y']))
- fic.close()
- # static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata)
- # {
- #
- # struct input_dev *input = msc->input;
- # int id, x, y, size, orientation, touch_major, touch_minor, state, down;
- # int pressure = 0;
- #
- # if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
- # id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
- # x = (tdata[1] << 28 | tdata[0] << 20) >> 20;
- # y = -((tdata[2] << 24 | tdata[1] << 16) >> 20);
- # size = tdata[5] & 0x3f;
- # orientation = (tdata[6] >> 2) - 32;
- # touch_major = tdata[3];
- # touch_minor = tdata[4];
- # state = tdata[7] & TOUCH_STATE_MASK;
- # down = state != TOUCH_STATE_NONE;
- # } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
- # id = tdata[8] & 0xf;
- # x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
- # y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
- # size = tdata[6];
- # orientation = (tdata[8] >> 5) - 4;
- # touch_major = tdata[4];
- # touch_minor = tdata[5];
- # pressure = tdata[7];
- # state = tdata[3] & 0xC0;
- # down = state == 0x80;
- # } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
- # id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
- # x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
- # y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
- # size = tdata[6] & 0x3f;
- # orientation = (tdata[7] >> 2) - 32;
- # touch_major = tdata[4];
- # touch_minor = tdata[5];
- # state = tdata[8] & TOUCH_STATE_MASK;
- # down = state != TOUCH_STATE_NONE;
- # }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement