Replace sys.stdout.write with print

This commit is contained in:
Nicola Corna 2018-01-05 16:01:00 +01:00
parent 15e81288bc
commit f8f2fc17f4

View file

@ -14,6 +14,8 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
from __future__ import print_function
import argparse import argparse
import binascii import binascii
import hashlib import hashlib
@ -148,11 +150,11 @@ def remove_modules(f, mod_headers, ftpr_offset, me_end):
flags = unpack("<I", mod_header[0x50:0x54])[0] flags = unpack("<I", mod_header[0x50:0x54])[0]
comp_type = (flags >> 4) & 7 comp_type = (flags >> 4) & 7
sys.stdout.write(" {:<16} ({:<7}, ".format(name, comp_str[comp_type])) print(" {:<16} ({:<7}, ".format(name, comp_str[comp_type]), end="")
if comp_type == 0x00 or comp_type == 0x02: if comp_type == 0x00 or comp_type == 0x02:
sys.stdout.write("0x{:06x} - 0x{:06x}): " print("0x{:06x} - 0x{:06x}): "
.format(offset, offset + size)) .format(offset, offset + size), end="")
if name in unremovable_modules: if name in unremovable_modules:
end_addr = max(end_addr, offset + size) end_addr = max(end_addr, offset + size)
@ -163,7 +165,7 @@ def remove_modules(f, mod_headers, ftpr_offset, me_end):
print("removed") print("removed")
elif comp_type == 0x01: elif comp_type == 0x01:
sys.stdout.write("fragmented data ): ") print("fragmented data ): ", end="")
if not chunks_offsets: if not chunks_offsets:
f.seek(offset) f.seek(offset)
llut = f.read(4) llut = f.read(4)
@ -193,8 +195,8 @@ def remove_modules(f, mod_headers, ftpr_offset, me_end):
print("removed") print("removed")
else: else:
sys.stdout.write("0x{:06x} - 0x{:06x}): unknown compression, " print("0x{:06x} - 0x{:06x}): unknown compression, skipping"
"skipping".format(offset, offset + size)) .format(offset, offset + size), end="")
if chunks_offsets: if chunks_offsets:
removable_huff_chunks = [] removable_huff_chunks = []
@ -407,8 +409,8 @@ def check_and_remove_modules_me11(f, me_start, me_end, partition_offset,
else: else:
compression = comp_str[modules[i][2]] compression = comp_str[modules[i][2]]
sys.stdout.write(" {:<12} ({:<12}, 0x{:06x} - 0x{:06x}): " print(" {:<12} ({:<12}, 0x{:06x} - 0x{:06x}): "
.format(name, compression, offset, end)) .format(name, compression, offset, end), end="")
if name.endswith(".man"): if name.endswith(".man"):
print("NOT removed, partition manif.") print("NOT removed, partition manif.")
@ -688,11 +690,9 @@ if __name__ == "__main__":
"remove" "remove"
.format(part_name, "no data here", part_length)) .format(part_name, "no data here", part_length))
else: else:
sys.stdout.write(" {:<4} (0x{:08x} - 0x{:09x}, 0x{:08x} " print(" {:<4} (0x{:08x} - 0x{:09x}, 0x{:08x} total bytes): "
"total bytes): ".format(part_name, .format(part_name, part_start, part_end, part_length),
part_start, end="")
part_end,
part_length))
if part_name in whitelist or (blacklist and if part_name in whitelist or (blacklist and
part_name not in blacklist): part_name not in blacklist):
unremovable_part_fpt += partition unremovable_part_fpt += partition
@ -831,13 +831,13 @@ if __name__ == "__main__":
.format(args.extract_me)) .format(args.extract_me))
mef_copy = mef.save(args.extract_me, me_end - me_start) mef_copy = mef.save(args.extract_me, me_end - me_start)
sys.stdout.write("Checking the FTPR RSA signature of the extracted ME " print("Checking the FTPR RSA signature of the extracted ME image... ",
"image... ") end="")
print_check_partition_signature(mef_copy, ftpr_offset + print_check_partition_signature(mef_copy, ftpr_offset +
ftpr_mn2_offset - me_start) ftpr_mn2_offset - me_start)
mef_copy.close() mef_copy.close()
sys.stdout.write("Checking the FTPR RSA signature... ") print("Checking the FTPR RSA signature... ", end="")
print_check_partition_signature(f, ftpr_offset + ftpr_mn2_offset) print_check_partition_signature(f, ftpr_offset + ftpr_mn2_offset)
f.close() f.close()