Añadidos scripts python
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Parámetros equivalentes
|
||||
desp = 0x2000
|
||||
numBytes = 0x2000
|
||||
firstByte = desp + 0x200
|
||||
lastByte = desp + numBytes - 1
|
||||
checksum1 = desp + 0x270
|
||||
checksum2 = desp + 0x271
|
||||
|
||||
buffer = bytearray()
|
||||
|
||||
|
||||
def check_parameters():
|
||||
if len(sys.argv) != 2:
|
||||
exe = os.path.basename(sys.argv[0])
|
||||
print(f"Uso: {exe} FILE")
|
||||
sys.exit(1)
|
||||
return sys.argv[1]
|
||||
|
||||
|
||||
def load_file(path):
|
||||
global buffer
|
||||
try:
|
||||
with open(path, "rb") as f:
|
||||
buffer = bytearray(f.read())
|
||||
except IOError:
|
||||
print(f"No se puede abrir el archivo: {path}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def save_file(path):
|
||||
try:
|
||||
with open(path, "wb") as f:
|
||||
f.write(buffer)
|
||||
print(f"Fichero guardado: {path}")
|
||||
except IOError:
|
||||
print(f"No se puede abrir el archivo: {path}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def calc_checksum():
|
||||
total = 0
|
||||
for i in range(firstByte, lastByte + 1):
|
||||
if i not in (checksum1, checksum2):
|
||||
total += buffer[i]
|
||||
|
||||
total += 3328 # Corrección del checksum
|
||||
|
||||
buffer[checksum1] = total % 256
|
||||
buffer[checksum2] = (total >> 8) % 256
|
||||
|
||||
return total
|
||||
|
||||
|
||||
def main():
|
||||
filePath = check_parameters()
|
||||
load_file(filePath)
|
||||
save_file(filePath + ".bak")
|
||||
calc_checksum()
|
||||
save_file(filePath)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user