Reputation: 1
I created code to convert an xlsm file to a hex file.
So far, it's working.
After creating the file that contains the data (in 32bit), I need to change the address of the fist data, and update the following address. I did it for an address of 4 (0000) but I need to do it for a address of 8 (0000 0000). When I try to change the address of the data in the file, it seem that my hexadecimal file isn't valid (Like in the screen shot).
Example Screenshot of file
Do you have any idea how I can change this ?
Code sample;
def defineNewAdresse(name_file):
with open(name_file, "rb") as f:
content = f.readlines()
adr_list = list(map(lambda x: x[3:6], content))
if not adr_list:
adr_list.append("")
adr_first = checkHexa()
adr_list[0] = adr_first
bin_list = []
formatted_hexa = []
for i in range(1, len(adr_list)):
previous_value = int(adr_list[i - 1], 16)
current_value = previous_value + 16
adr_list[i] = hex(current_value)[2:].zfill(8)
for hex_value in adr_list:
adr_decimal = int(hex_value, 16)
adr_binary = bin(adr_decimal)[2:]
bin_list.append(adr_binary)
for binary_value in bin_list:
binary_string = format(int(binary_value, 2), "032b")
hex_num = hex(int(binary_string, 2))[2:].zfill(4)
formatted_hexa.append(hex_num.zfill(8))
for i in range(len(content)):
if i < len(formatted_hexa):
line = content[i].decode("utf-8")
modified_line = line[:3] + formatted_hexa[i] + line[7:]
content[i] = modified_line.encode("utf-8")
with open(name_file, "wb") as f:
f.write(b"".join(content))
f.close()
Upvotes: 0
Views: 51