Skip to content

Commit 0bab873

Browse files
committed
migration to python3
1 parent a428667 commit 0bab873

File tree

14 files changed

+57
-57
lines changed

14 files changed

+57
-57
lines changed

umap2/apps/list_classes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def run(self):
1717
ks = self.umap_classes
1818
verbose = self.options.get('--verbose', False)
1919
if verbose:
20-
print '%-20s %s' % ('Device', 'Description')
21-
print '-------------------- ----------------------------------------------------'
20+
print('%-20s %s' % ('Device', 'Description'))
21+
print('-------------------- ----------------------------------------------------')
2222
for k in ks:
2323
if verbose:
2424
print('%-20s %s' % (k, self.umap_class_dict[k][1]))

umap2/dev/audio.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ def setup_local_handlers(self):
4242
}
4343
self._settings = {
4444
# (val, index): [cur, min, max, res, (idle)]
45-
(0x0100, 0x0001): ['\x44\xac\x00', '\x44\xac\x00', '\x80\xbb\x00', '\x80\xbb\x00'],
45+
(0x0100, 0x0001): [b'\x44\xac\x00', b'\x44\xac\x00', b'\x80\xbb\x00', b'\x80\xbb\x00'],
4646
# (0x0100, 0x0002): ['\x44\xac\x00', '\x44\xac\x00', '\x80\xbb\x00', '\x80\xbb\x00'],
47-
(0x0100, 0x0082): ['\x44\xac\x00', '\x44\xac\x00', '\x80\xbb\x00', '\x80\xbb\x00'],
48-
(0x0100, 0x0900): ['\x00', '\x00', '\xff', '\x00'],
49-
(0x0100, 0x0a00): ['\x01', '\x00', '\xff', '\x00'],
50-
(0x0100, 0x0d00): ['\x01', '\x00', '\xff', '\x00'],
51-
(0x0101, 0x0f00): ['\x01', '\x00', '\xff', '\x00'],
52-
(0x0102, 0x0f00): ['\x01', '\x00', '\xff', '\x00'],
53-
(0x0200, 0x0a00): ['\x00\x00', '\x00\x00', '\x55\x00', '\x30\x00', '\x00\x00'],
54-
(0x0200, 0x0d00): ['\x80\x22', '\x00\x00', '\xd0\x00', '\x30\x00'],
55-
(0x0201, 0x0900): ['\x80\x22', '\x20\x00', '\xa0\x00', '\x30\x00'],
56-
(0x0201, 0x0f00): ['\x01', '\x00', '\xff', '\x00'],
57-
(0x0202, 0x0900): ['\xcf\x00', '\x00\x00', '\xcf\x00', '\x30\x00'],
58-
(0x0202, 0x0f00): ['\x01', '\x00', '\xff', '\x00'],
59-
(0x0301, 0x0f00): ['\x01', '\x00', '\xff', '\x00'],
60-
(0x0302, 0x0f00): ['\x00\x00', '\x00\x00', '\x00\x00', '\x00\x00'],
61-
(0x0700, 0x0a00): ['\x01', '\x00', '\xff', '\x00'],
47+
(0x0100, 0x0082): [b'\x44\xac\x00', b'\x44\xac\x00', b'\x80\xbb\x00', b'\x80\xbb\x00'],
48+
(0x0100, 0x0900): [b'\x00', b'\x00', b'\xff', b'\x00'],
49+
(0x0100, 0x0a00): [b'\x01', b'\x00', b'\xff', b'\x00'],
50+
(0x0100, 0x0d00): [b'\x01', b'\x00', b'\xff', b'\x00'],
51+
(0x0101, 0x0f00): [b'\x01', b'\x00', b'\xff', b'\x00'],
52+
(0x0102, 0x0f00): [b'\x01', b'\x00', b'\xff', b'\x00'],
53+
(0x0200, 0x0a00): [b'\x00\x00', b'\x00\x00', b'\x55\x00', b'\x30\x00', b'\x00\x00'],
54+
(0x0200, 0x0d00): [b'\x80\x22', b'\x00\x00', b'\xd0\x00', b'\x30\x00'],
55+
(0x0201, 0x0900): [b'\x80\x22', b'\x20\x00', b'\xa0\x00', b'\x30\x00'],
56+
(0x0201, 0x0f00): [b'\x01', b'\x00', b'\xff', b'\x00'],
57+
(0x0202, 0x0900): [b'\xcf\x00', b'\x00\x00', b'\xcf\x00', b'\x30\x00'],
58+
(0x0202, 0x0f00): [b'\x01', b'\x00', b'\xff', b'\x00'],
59+
(0x0301, 0x0f00): [b'\x01', b'\x00', b'\xff', b'\x00'],
60+
(0x0302, 0x0f00): [b'\x00\x00', b'\x00\x00', b'\x00\x00', b'\x00\x00'],
61+
(0x0700, 0x0a00): [b'\x01', b'\x00', b'\xff', b'\x00'],
6262
}
6363

6464
self._cur = b'\x44\xac\x00'
@@ -205,29 +205,29 @@ def __init__(self, app, phy, vid=0x0d8c, pid=0x000c, rev=0x0001, *args, **kwargs
205205
app=app, phy=phy, iface_num=0, iface_alt=0, iface_str_idx=0,
206206
cs_ifaces=[
207207
# Class specific AC interface: header (4.3.2)
208-
USBCSInterface('ACHeader', app, phy, '\x01\x00\x01\x64\x00\x02\x01\x02'),
208+
USBCSInterface('ACHeader', app, phy, b'\x01\x00\x01\x64\x00\x02\x01\x02'),
209209
# Class specific AC interface: input terminal (Table 4.3.2.1)
210-
USBCSInterface('ACInputTerminal0', app, phy, '\x02\x01\x01\x01\x00\x02\x03\x00\x00\x00'),
211-
USBCSInterface('ACInputTerminal1', app, phy, '\x02\x02\x01\x02\x00\x01\x01\x00\x00\x00'),
210+
USBCSInterface('ACInputTerminal0', app, phy, b'\x02\x01\x01\x01\x00\x02\x03\x00\x00\x00'),
211+
USBCSInterface('ACInputTerminal1', app, phy, b'\x02\x02\x01\x02\x00\x01\x01\x00\x00\x00'),
212212
# Class specific AC interface: output terminal (Table 4.3.2.2)
213-
USBCSInterface('ACOutputTerminal0', app, phy, '\x03\x06\x01\x03\x00\x09\x00'),
214-
USBCSInterface('ACOutputTerminal1', app, phy, '\x03\x07\x01\x01\x00\x08\x00'),
213+
USBCSInterface('ACOutputTerminal0', app, phy, b'\x03\x06\x01\x03\x00\x09\x00'),
214+
USBCSInterface('ACOutputTerminal1', app, phy, b'\x03\x07\x01\x01\x00\x08\x00'),
215215
# Class specific AC interface: selector unit (Table 4.3.2.4)
216-
USBCSInterface('ACSelectorUnit', app, phy, '\x05\x08\x01\x0a\x00'),
216+
USBCSInterface('ACSelectorUnit', app, phy, b'\x05\x08\x01\x0a\x00'),
217217
# Class specific AC interface: feature unit (Table 4.3.2.5)
218-
USBCSInterface('ACFeatureUnit0', app, phy, '\x06\x09\x0f\x01\x01\x02\x02\x00'),
219-
USBCSInterface('ACFeatureUnit1', app, phy, '\x06\x0a\x02\x01\x43\x00\x00'),
220-
USBCSInterface('ACFeatureUnit2', app, phy, '\x06\x0d\x02\x01\x03\x00\x00'),
218+
USBCSInterface('ACFeatureUnit0', app, phy, b'\x06\x09\x0f\x01\x01\x02\x02\x00'),
219+
USBCSInterface('ACFeatureUnit1', app, phy, b'\x06\x0a\x02\x01\x43\x00\x00'),
220+
USBCSInterface('ACFeatureUnit2', app, phy, b'\x06\x0d\x02\x01\x03\x00\x00'),
221221
# Class specific AC interface: mixer unit (Table 4.3.2.3)
222-
USBCSInterface('ACMixerUnit', app, phy, '\x04\x0f\x02\x01\x0d\x02\x03\x00\x00\x00\x00'),
222+
USBCSInterface('ACMixerUnit', app, phy, b'\x04\x0f\x02\x01\x0d\x02\x03\x00\x00\x00\x00'),
223223
],
224224
usb_class=usb_class
225225
),
226226
USBAudioStreamingInterface(
227227
app=app, phy=phy, iface_num=1, iface_alt=0, iface_str_idx=0,
228228
cs_ifaces=[
229-
USBCSInterface('ASGeneral', app, phy, '\x01\x01\x01\x01\x00'),
230-
USBCSInterface('ASFormatType', app, phy, '\x02\x01\x02\x02\x10\x02\x44\xac\x00\x44\xac\x00'),
229+
USBCSInterface('ASGeneral', app, phy, b'\x01\x01\x01\x01\x00'),
230+
USBCSInterface('ASFormatType', app, phy, b'\x02\x01\x02\x02\x10\x02\x44\xac\x00\x44\xac\x00'),
231231
],
232232
endpoints=[
233233
USBEndpoint(
@@ -240,7 +240,7 @@ def __init__(self, app, phy, vid=0x0d8c, pid=0x000c, rev=0x0001, *args, **kwargs
240240
interval=1,
241241
handler=audio_streaming.data_available,
242242
cs_endpoints=[
243-
USBCSEndpoint('ASEndpoint', app, phy, '\x01\x01\x01\x01\x00')
243+
USBCSEndpoint('ASEndpoint', app, phy, b'\x01\x01\x01\x01\x00')
244244
],
245245
usb_class=usb_class,
246246
)
@@ -250,8 +250,8 @@ def __init__(self, app, phy, vid=0x0d8c, pid=0x000c, rev=0x0001, *args, **kwargs
250250
USBAudioStreamingInterface(
251251
app=app, phy=phy, iface_num=2, iface_alt=0, iface_str_idx=0,
252252
cs_ifaces=[
253-
USBCSInterface('ASGeneral', app, phy, '\x01\x07\x01\x01\x00'),
254-
USBCSInterface('ASFormatType', app, phy, '\x02\x01\x01\x02\x10\x02\x44\xac\x00\x44\xac\x00'),
253+
USBCSInterface('ASGeneral', app, phy, b'\x01\x07\x01\x01\x00'),
254+
USBCSInterface('ASFormatType', app, phy, b'\x02\x01\x01\x02\x10\x02\x44\xac\x00\x44\xac\x00'),
255255
],
256256
endpoints=[
257257
USBEndpoint(
@@ -264,7 +264,7 @@ def __init__(self, app, phy, vid=0x0d8c, pid=0x000c, rev=0x0001, *args, **kwargs
264264
interval=1,
265265
handler=audio_streaming.buffer_available,
266266
cs_endpoints=[
267-
USBCSEndpoint('ASEndpoint', app, phy, '\x01\x01\x00\x00\x00')
267+
USBCSEndpoint('ASEndpoint', app, phy, b'\x01\x01\x00\x00\x00')
268268
],
269269
usb_class=usb_class,
270270
)

umap2/dev/cdc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def handle_getter(self, req):
191191
key = (param_id, req.value, req.index)
192192
if key in self.params:
193193
return self.params[key]
194-
return '\x00' * req.length
194+
return b'\x00' * req.length
195195

196196
def handle_clear(self, req):
197197
param_id = self.get_param_id_from_request(req.request)

umap2/dev/cdc_acm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, app, phy, vid=0x2548, pid=0x1001, rev=0x0010, cs_interfaces=N
2929
cdc_cls = self.get_default_class(app, phy)
3030
cs_interfaces = [
3131
# Header Functional Descriptor
32-
FD(app, phy, FD.Header, '\x01\x01'),
32+
FD(app, phy, FD.Header, b'\x01\x01'),
3333
# Call Management Functional Descriptor
3434
FD(app, phy, FD.CM, struct.pack('BB', bmCapabilities, USBCDCDevice.bDataInterface)),
3535
FD(app, phy, FD.ACM, struct.pack('B', bmCapabilities)),

umap2/dev/cdc_dl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, app, phy, vid=0x2548, pid=0x1001, rev=0x0010, cs_interfaces=N
2828
cdc_cls = self.get_default_class(app, phy)
2929
cs_interfaces = [
3030
# Header Functional Descriptor
31-
FD(app, phy, FD.Header, '\x01\x01'),
31+
FD(app, phy, FD.Header, b'\x01\x01'),
3232
# Call Management Functional Descriptor
3333
FD(app, phy, FD.CM, struct.pack('BB', bmCapabilities, USBCDCDevice.bDataInterface)),
3434
FD(app, phy, FD.DLM, struct.pack('B', bmCapabilities)),

umap2/dev/hub.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def handle_get_descriptor(self, req):
5454
num_bytes = self.num_ports // 7
5555
if self.num_ports % 7 != 0:
5656
num_bytes += 1
57-
d += '\x00' * num_bytes
58-
d += '\xff' * num_bytes
57+
d += b'\x00' * num_bytes
58+
d += b'\xff' * num_bytes
5959
d = struct.pack('B', len(d) + 1) + d
6060
return d
6161

umap2/dev/mass_storage.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def put_sector_data(self, address, data):
129129
block_end = (address + 1) * self.block_size # slices are NON-inclusive
130130

131131
pad_len = (self.block_size - (len(data) % self.block_size)) % self.block_size
132-
data += '\x00' * pad_len
132+
data += b'\x00' * pad_len
133133
self.image[block_start:block_end] = data[:self.block_size]
134134
self.image.flush()
135135

@@ -391,7 +391,7 @@ def handle_scsi_mode_sense(self, mode_type, page, subpage, alloc_len, ctrl, with
391391
if report is None:
392392
# default behaviour, taken from previous implementation
393393
# this should probably be changed ...
394-
report = '\x07\x00\x00\x00\x00\x00\x00\x00'
394+
report = b'\x07\x00\x00\x00\x00\x00\x00\x00'
395395
if with_header:
396396
self.debug('SCSI mode sense (%d) - adding header' % (mode_type))
397397
report = self._report_header(mode_type, len(report)) + report

umap2/fuzz/fuzz_engine.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from kitty.model import GraphModel
2121
from kitty.model import Template, Meta, String, UInt32
2222

23-
from templates import audio, cdc, enum, generic, hid, hub, mass_storage
23+
from . templates import audio, cdc, enum, generic, hid, hub, mass_storage
2424
from templates import smart_card
2525

2626
from controller import UmapController

umap2/fuzz/helpers.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import binascii
77
import inspect
88

9-
109
class StageLogger(object):
1110

1211
def __init__(self, filename):
@@ -22,7 +21,8 @@ def stop(self):
2221

2322
def log_stage(self, stage):
2423
if self.fd:
25-
self.fd.write(stage + '\n')
24+
25+
self.fd.write(stage.encode() + b'\n')
2626
self.fd.flush()
2727

2828

@@ -46,8 +46,8 @@ def mutable(stage, silent=False):
4646
def wrap_f(func):
4747
func_self = None
4848
if inspect.ismethod(func):
49-
func_self = func.im_self
50-
func = func.im_func
49+
func_self = func.__self__
50+
func = func.__func__
5151

5252
def wrapper(*args, **kwargs):
5353
if func_self is None:
@@ -79,7 +79,7 @@ def wrapper(*args, **kwargs):
7979
self.logger.error(''.join(traceback.format_stack()))
8080
raise e
8181
if response is not None:
82-
info('Response: %s' % binascii.hexlify(response))
82+
info(f'Response: {response.hex()}')
8383
return response
8484
return wrapper
8585
return wrap_f

umap2/fuzz/templates/audio.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from kitty.model import Template, Repeat, List, Container, ForEach, OneOf
77
from kitty.model import ElementCount, SizeInBytes
88
from kitty.model import ENC_INT_LE
9-
from hid import GenerateHidReport
10-
from generic import Descriptor, SizedPt, DynamicInt, SubDescriptor
9+
from . hid import GenerateHidReport
10+
from . generic import Descriptor, SizedPt, DynamicInt, SubDescriptor
1111

1212

1313
class _AC_DescriptorSubTypes: # AC Interface Descriptor Subtype
@@ -138,7 +138,7 @@ class _AS_DescriptorSubTypes: # AS Interface Descriptor Subtype
138138
audio_report_descriptor = Template(
139139
name='audio_report_descriptor',
140140
fields=GenerateHidReport(
141-
'050C0901A1011500250109E909EA75019502810209E209008106050B092095018142050C09009503810226FF000900750895038102090095049102C0'.decode('hex')
141+
bytes.fromhex('050C0901A1011500250109E909EA75019502810209E209008106050B092095018142050C09009503810226FF000900750895038102090095049102C0')
142142
)
143143
)
144144

umap2/fuzz/templates/cdc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from kitty.model import Template, Repeat, List, Container, ForEach, OneOf
99
from kitty.model import ElementCount
1010
from kitty.model import MutableField
11-
from generic import SubDescriptor
11+
from . generic import SubDescriptor
1212

1313

1414
cdc_control_interface_descriptor = Template(

umap2/fuzz/templates/enum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from kitty.model import ElementCount, SizeInBytes
1111
# encoders
1212
from kitty.model import StrEncodeEncoder, ENC_INT_LE
13-
from generic import Descriptor, SubDescriptor
13+
from . generic import Descriptor, SubDescriptor
1414

1515

1616
# Device descriptor

umap2/fuzz/templates/hid.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from kitty.model import ENC_INT_LE
2525
from kitty.core import KittyException
2626
from random import Random
27-
from generic import DynamicInt, Descriptor
27+
from . generic import DynamicInt, Descriptor
2828

2929

3030
opcodes = {
@@ -124,7 +124,7 @@ def GenerateHidReport(report_str, name=None):
124124
index = 0
125125
namer = NameGen()
126126
while index < len(report_str):
127-
opcode = ord(report_str[index])
127+
opcode = report_str[index]
128128
num_args = opcode & 3
129129
if index + num_args >= len(report_str):
130130
raise KittyException('Not enough bytes in hid report for last opcode')
@@ -134,7 +134,7 @@ def GenerateHidReport(report_str, name=None):
134134
fields.append(UInt8(opcode, name=cur_name))
135135
else:
136136
args = report_str[index:index + num_args]
137-
value = sum(ord(args[i]) << (i * 8) for i in range(len(args))) # little endian...
137+
value = sum(args[i] << (i * 8) for i in range(len(args))) # little endian...
138138
fields.append(Container(
139139
name=cur_name,
140140
fields=[
@@ -179,6 +179,6 @@ def GenerateHidReport(report_str, name=None):
179179
hid_report_descriptor = Template(
180180
name='hid_report_descriptor',
181181
fields=GenerateHidReport(
182-
'05010906A101050719E029E7150025017501950881029501750881011900296515002565750895018100C0'.decode('hex')
182+
bytes.fromhex('05010906A101050719E029E7150025017501950881029501750881011900296515002565750895018100C0')
183183
)
184184
)

umap2/phy/facedancer/max342x_phy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def service_irqs(self):
210210
self.clear_irq_bit(Regs.endpoint_irq, PINCTL.setup_data_avail)
211211

212212
b = self.read_bytes(Regs.setup_data_fifo, 8)
213-
if (irq & PINCTL.out0_data_avail) and (ord(b[0]) & 0x80 == 0x00):
213+
if (irq & PINCTL.out0_data_avail) and (b[0] & 0x80 == 0x00):
214214
data_bytes_len = struct.unpack('<H', b[6:])[0]
215215
b += self.read_bytes(Regs.ep0_fifo, data_bytes_len)
216216
self.app.signal_setup_packet_received()

0 commit comments

Comments
 (0)