-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean_ip3000.py
executable file
·51 lines (42 loc) · 1.94 KB
/
clean_ip3000.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/env python3
import usb.util
import sys
ENDPOINT = 0x1
TIMEOUT = 1000
PAYLOADS = [
[0x1B, 0x5B, 0x4B, 0x02, 0x00, 0x00, 0x1F, 0x42, 0x4A, 0x4C, 0x53, 0x54, 0x41, 0x52, 0x54, 0x0A,
0x43, 0x6F, 0x6E, 0x74, 0x72, 0x6F, 0x6C, 0x4D, 0x6F, 0x64, 0x65, 0x3D, 0x44, 0x72, 0x69, 0x76,
0x65, 0x72, 0x0A, 0x24, 0x4A, 0x6F, 0x62, 0x54, 0x79, 0x70, 0x65, 0x3D, 0x4D, 0x6E, 0x74, 0x0A,
0x42, 0x4A, 0x4C, 0x45, 0x4E, 0x44],
[0x1B, 0x5B, 0x4B, 0x02, 0x00, 0x00, 0x1F, 0x42, 0x4A, 0x4C, 0x53, 0x54, 0x41, 0x52, 0x54, 0x0A,
0x43, 0x6F, 0x6E, 0x74, 0x72, 0x6F, 0x6C, 0x4D, 0x6F, 0x64, 0x65, 0x3D, 0x43, 0x6F, 0x6D, 0x6D,
0x6F, 0x6E, 0x0A, 0x53, 0x65, 0x74, 0x54, 0x69, 0x6D, 0x65, 0x3D, 0x32, 0x30, 0x31, 0x38, 0x31,
0x30, 0x30, 0x32, 0x31, 0x37, 0x32, 0x34, 0x34, 0x36, 0x0A, 0x53, 0x65, 0x74, 0x53, 0x69, 0x6C,
0x65, 0x6E, 0x74, 0x3D, 0x4F, 0x46, 0x46, 0x0A, 0x42, 0x4A, 0x4C, 0x45, 0x4E, 0x44, 0x0A],
[0x1B, 0x5B, 0x4B, 0x02, 0x00, 0x00, 0x1F, 0x42, 0x4A, 0x4C, 0x53, 0x54, 0x41, 0x52, 0x54, 0x0A,
0x40, 0x43, 0x6C, 0x65, 0x61, 0x6E, 0x69, 0x6E, 0x67, 0x3D, 0x32, 0x41, 0x4C, 0x4C, 0x0A, 0x42,
0x4A, 0x4C, 0x45, 0x4E, 0x44, 0x0A],
]
# find our device - canon ip3000
dev = usb.core.find(idVendor=0x04A9, idProduct=0x1094)
if dev is None:
raise ValueError('Our device is not connected')
# workaround for: [Errno 16] Resource busy
kernel_driver = dev.is_kernel_driver_active(0)
try:
if kernel_driver:
dev.detach_kernel_driver(0)
# setup library
dev.set_configuration()
# write payloads
for payload in PAYLOADS:
written = dev.write(ENDPOINT, payload, TIMEOUT)
if written != len(payload):
raise AssertionError(
"Written bytes did not match payload length - is the device busy?")
except Exception as e:
sys.stderr.write(e)
sys.stderr.write('\n')
# restore system state
if kernel_driver:
dev.attach_kernel_driver(0)