@@ -1052,7 +1052,7 @@ def off_to_addr(off: int) -> int:
1052
1052
raw_off = round_up (self .header .headers_size )
1053
1053
1054
1054
# Construct section data
1055
- section_data = b""
1055
+ section_data = bytearray ()
1056
1056
for name in sorted (
1057
1057
self .sections , key = lambda x : cast (int , self .sections [x ].header .virtual_addr )
1058
1058
):
@@ -1062,23 +1062,23 @@ def off_to_addr(off: int) -> int:
1062
1062
"Expected %#x for %s, got %#x" , s .header .raw_addr , name , raw_off
1063
1063
)
1064
1064
s .header .raw_addr = raw_off
1065
- section_data += s .data
1065
+ section_data . extend ( s .data )
1066
1066
raw_off += len (s .data )
1067
1067
1068
1068
# Align to 4k
1069
1069
new_offset = round_up (raw_off )
1070
- section_data += bytes (new_offset - raw_off )
1070
+ section_data . extend ( bytes (new_offset - raw_off ) )
1071
1071
raw_off = new_offset
1072
1072
1073
1073
#
1074
1074
# Construct headers
1075
1075
#
1076
- headers_data = b""
1076
+ headers_data = bytearray ()
1077
1077
1078
1078
def do_append (data : bytes ) -> int :
1079
1079
nonlocal raw_off , headers_data
1080
1080
old_off = raw_off
1081
- headers_data += data
1081
+ headers_data . extend ( data )
1082
1082
raw_off += len (data )
1083
1083
return off_to_addr (old_off )
1084
1084
@@ -1204,20 +1204,20 @@ def do_append(data: bytes) -> int:
1204
1204
)
1205
1205
1206
1206
# Construct final image
1207
- output = b""
1208
- output += bytes (self .header )
1209
- output += bytes (self .cert )
1207
+ output = bytearray ()
1208
+ output . extend ( bytes (self .header ) )
1209
+ output . extend ( bytes (self .cert ) )
1210
1210
for name , s in self .sections .items ():
1211
1211
log .info ("Writing section %s at %#x" , name , len (output ))
1212
- output += bytes (s .header )
1213
- output += headers_data
1214
- output += section_data
1212
+ output . extend ( bytes (s .header ) )
1213
+ output . extend ( headers_data )
1214
+ output . extend ( section_data )
1215
1215
1216
1216
# MS XBEs seem to always add an extra page if the last page is completely filled
1217
1217
# FIXME: Why?
1218
1218
if output [- 1 ] != 0 :
1219
- output += bytes (0x1000 )
1220
- return output
1219
+ output . extend ( bytes (0x1000 ) )
1220
+ return bytes ( output )
1221
1221
1222
1222
@classmethod
1223
1223
def from_file (cls , path : str ) -> "Xbe" :
0 commit comments