scripts: Added script to transform 010 editor CSV encoding files to table files

This commit is contained in:
WerWolv
2022-07-27 15:58:03 +02:00
parent 63468e543a
commit 3a4b3873d1
2 changed files with 32 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ Hex patterns, include patterns and magic files for the use with the ImHex Hex Ed
| Name | Path | Description | | Name | Path | Description |
|------|------|-------------| |------|------|-------------|
| svd2pat | `scripts/svd2pat.py` | Converts a ARM .svd register MMIO definition file into a pattern | | svd2pat | `scripts/svd2pat.py` | Converts a ARM .svd register MMIO definition file into a pattern |
| csv2tbl | `scripts/csv2tbl.py` | Converts a 010 editor CSV encoding file into a table file |
### Pattern Libraries ### Pattern Libraries

31
scripts/csv2tbl.py Normal file
View File

@@ -0,0 +1,31 @@
import csv
import sys
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <file.csv>")
exit()
fileName = sys.argv[1]
index = 0x00
with open(f"{fileName}.tbl", "w", encoding="utf-8") as outFile:
with open(fileName) as file:
reader = csv.reader(file)
for row in reader:
for cell in row:
if cell != "":
try:
number = int(cell, 16)
if number <= 0x1F:
lut = [ "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "TAB", "LF", "VT", "FF", "CR", "SO", "SI", "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"]
print(f"{index:02X}={lut[number]}", file=outFile)
elif number == 0x7F:
print(f"{index:02X}=DEL", file=outFile)
else:
if chr(number) == chr(0xFFFD):
raise Exception
print(f"{index:02X}={chr(number)}", file=outFile)
except Exception:
print(f"{index:02X}", file=outFile)
index += 1