Skip to content

Commit 4339160

Browse files
committed
bg_gen_unified_kernel: Switch to format strings
No functional change, just nicer to read. Signed-off-by: Jan Kiszka <[email protected]>
1 parent f59f6f4 commit 4339160

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

tools/bg_gen_unified_kernel

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,35 +60,35 @@ class PEHeaders:
6060
def __init__(self, name, blob):
6161
# Parse headers: DOS, COFF, optional header
6262
if len(blob) < 0x40:
63-
print("Invalid %s, image too small" % name, file=sys.stderr)
63+
print(f'Invalid {name}, image too small', file=sys.stderr)
6464
exit(1)
6565

6666
(magic, pe_offs) = struct.unpack_from('<H58xI', blob)
6767

6868
if magic != 0x5a4d:
69-
print("Invalid %s, bad DOS header magic" % name, file=sys.stderr)
69+
print(f'Invalid {name}, bad DOS header magic', file=sys.stderr)
7070
exit(1)
7171

7272
self.dos_header = blob[:pe_offs]
7373

7474
self.header_size = pe_offs + 0x18
7575
if self.header_size > len(blob):
76-
print("Invalid %s, incomplete COFF header" % name, file=sys.stderr)
76+
print(f'Invalid {name}, incomplete COFF header', file=sys.stderr)
7777
exit(1)
7878

7979
self.coff_header = blob[pe_offs:self.header_size]
8080

8181
(magic, self.machine, num_sections, opt_header_size) = \
8282
struct.unpack_from('<IHH12xH2x', self.coff_header)
8383
if magic != 0x4550:
84-
print("Invalid %s, bad PE header magic" % name, file=sys.stderr)
84+
print(f'Invalid {name}, bad PE header magic', file=sys.stderr)
8585
exit(1)
8686

8787
coff_offs = self.header_size
8888

8989
self.header_size += opt_header_size
9090
if self.header_size > len(blob):
91-
print("Invalid %s, incomplete optional header" % name,
91+
print(f'Invalid {name}, incomplete optional header',
9292
file=sys.stderr)
9393
exit(1)
9494

@@ -100,15 +100,15 @@ class PEHeaders:
100100
elif magic == 0x20b:
101101
self.is_pe_plus = True
102102
else:
103-
print("Invalid %s, unknown optional header magic" % name,
103+
print(f'Invalid {name}, unknown optional header magic',
104104
file=sys.stderr)
105105
exit(1)
106106

107107
section_offs = self.header_size
108108

109109
self.header_size += num_sections * 0x28
110110
if self.header_size > len(blob):
111-
print("Invalid %s, incomplete section headers" % name,
111+
print(f'Invalid {name}, incomplete section headers',
112112
file=sys.stderr)
113113
exit(1)
114114

@@ -120,7 +120,7 @@ class PEHeaders:
120120
section = Section.from_struct(
121121
blob[section_offs:section_offs+0x28])
122122
if section.data_offs + section.data_size > len(blob):
123-
print("Invalid %s, section data missing" % name,
123+
print(f'Invalid {name}, section data missing',
124124
file=sys.stderr)
125125
exit(1)
126126

@@ -137,12 +137,12 @@ class PEHeaders:
137137

138138
def get_opt_header_field(self, offsets):
139139
offs = offsets[1 if self.is_pe_plus else 0]
140-
format = '<%dxI' % offs
140+
format = f'<{offs}xI'
141141
return struct.unpack_from(format, self.opt_header)[0]
142142

143143
def set_opt_header_field(self, offsets, val):
144144
offs = offsets[1 if self.is_pe_plus else 0]
145-
format = '<%dsI%ds' % (offs, len(self.opt_header) - offs - 4)
145+
format = f'<{offs}sI{len(self.opt_header) - offs - 4}s'
146146
self.opt_header = struct.pack(format, self.opt_header[:offs], val,
147147
self.opt_header[offs+4:])
148148

0 commit comments

Comments
 (0)