Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.44 KB | None | 0 0
  1. f = open('/tmp/ctfkleph/dump.txt')
  2. mouse = 'USB_DEVICE_ID_APPLE_MAGICTRACKPAD2'
  3. mouse = 'USB_DEVICE_ID_APPLE_MAGICTRACKPAD'
  4. mouse = 'USB_DEVICE_ID_APPLE_MAGICMOUSE'
  5.  
  6. TOUCH_STATE_MASK = 0xf0
  7. TOUCH_STATE_NONE = 0x00
  8.  
  9. valid_reports = [0x28, 0x02, 0x31, 0x29, 0xf7]
  10.  
  11. def magicmouse_emit_touch(data):
  12.     arr = data.split(':')
  13.     tdata = [int(x, 16) for x in arr]
  14.     # print tdata
  15.     # sba = [hex(x) for x in tdata]
  16.     presure=""
  17.     if mouse == "USB_DEVICE_ID_APPLE_MAGICMOUSE":
  18.         id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf
  19.         x = (tdata[1] << 28 | tdata[0] << 20) >> 20
  20.         y = -((tdata[2] << 24 | tdata[1] << 16) >> 20)
  21.         size = tdata[5] & 0x3f
  22.         orientation = (tdata[6] >> 2) - 32
  23.         touch_major = tdata[3]
  24.         touch_minor = tdata[4]
  25.         state = tdata[7] & TOUCH_STATE_MASK
  26.         down = state != TOUCH_STATE_NONE
  27.     if mouse == "USB_DEVICE_ID_APPLE_MAGICTRACKPAD2":
  28.         id = tdata[8] & 0xf
  29.         x = (tdata[1] << 27 | tdata[0] << 19) >> 19
  30.         y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19)
  31.         size = tdata[6]
  32.         orientation = (tdata[8] >> 5) - 4
  33.         touch_major = tdata[4]
  34.         touch_minor = tdata[5]
  35.         pressure = tdata[7]
  36.         state = tdata[3] & 0xC0
  37.         down = state == 0x80
  38.     if mouse == "USB_DEVICE_ID_APPLE_MAGICTRACKPAD":
  39.         id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf
  40.         x = (tdata[1] << 27 | tdata[0] << 19) >> 19
  41.         y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19)
  42.         size = tdata[6] & 0x3f
  43.         orientation = (tdata[7] >> 2) - 32
  44.         touch_major = tdata[4]
  45.         touch_minor = tdata[5]
  46.         state = tdata[8] & TOUCH_STATE_MASK
  47.         down = state != TOUCH_STATE_NONE
  48.     res = {
  49.         'id': id,
  50.         'x' : x,
  51.         'y' : y,
  52.         'size' : size,
  53.         'orientation' : orientation,
  54.         'presure' : presure,
  55.         'major' : touch_major,
  56.         'minor' : touch_minor,
  57.         'state' : state,
  58.         'down' : down
  59.     }
  60.     return res
  61.  
  62.  
  63.  
  64. # for offset in range(7):
  65. # print "processing offset %s" % offset
  66. print "Test for mouse %s" % mouse
  67. fic = open('%s.txt' % "plot.txt", 'w')
  68. for line in f.readlines():
  69.     line = line.strip()
  70.     if len(line) > 13:
  71.         elts = line.split(':')
  72.         newline= ":".join(elts[9::])
  73.         # if elts[offset] in valid_reports:
  74.         # print newline, len(newline.split(':'))
  75.         if len(newline)<1: continue
  76.         res = magicmouse_emit_touch(newline[6:])
  77.         print "id={id},x={x},y={y},size={size},orientation={orientation},major={major},minor={minor},state={state},down={down},presure={presure}".format(
  78.         id=res['id'], x=res['x'], y=res['y'], size=res['size'],
  79.         orientation=res['orientation'], major=res['major'],
  80.         minor=res['minor'], state=res['state'], down=res['down'],
  81.         presure=res['presure']
  82.         )
  83.         fic.write('%s %s\n' % (res['x'], res['y']))
  84. fic.close()
  85.  
  86.  
  87.  
  88.     # static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata)
  89.     # {
  90.     #
  91.     # struct input_dev *input = msc->input;
  92.     # int id, x, y, size, orientation, touch_major, touch_minor, state, down;
  93.     # int pressure = 0;
  94.     #
  95.     # if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
  96.     #   id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
  97.     #   x = (tdata[1] << 28 | tdata[0] << 20) >> 20;
  98.     #   y = -((tdata[2] << 24 | tdata[1] << 16) >> 20);
  99.     #   size = tdata[5] & 0x3f;
  100.     #   orientation = (tdata[6] >> 2) - 32;
  101.     #   touch_major = tdata[3];
  102.     #   touch_minor = tdata[4];
  103.     #   state = tdata[7] & TOUCH_STATE_MASK;
  104.     #   down = state != TOUCH_STATE_NONE;
  105.     # } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
  106.     #   id = tdata[8] & 0xf;
  107.     #   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
  108.     #   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
  109.     #   size = tdata[6];
  110.     #   orientation = (tdata[8] >> 5) - 4;
  111.     #   touch_major = tdata[4];
  112.     #   touch_minor = tdata[5];
  113.     #   pressure = tdata[7];
  114.     #   state = tdata[3] & 0xC0;
  115.     #   down = state == 0x80;
  116.     # } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
  117.     #   id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
  118.     #   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
  119.     #   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
  120.     #   size = tdata[6] & 0x3f;
  121.     #   orientation = (tdata[7] >> 2) - 32;
  122.     #   touch_major = tdata[4];
  123.     #   touch_minor = tdata[5];
  124.     #   state = tdata[8] & TOUCH_STATE_MASK;
  125.     #   down = state != TOUCH_STATE_NONE;
  126.     # }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement