mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-27 23:37:04 -05:00
scripts: Added script to transform 010 editor CSV encoding files to table files
This commit is contained in:
@@ -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
31
scripts/csv2tbl.py
Normal 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
|
||||||
Reference in New Issue
Block a user