File: disassemblertables_reduce.py

package info (click to toggle)
capstone 5.0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie, trixie-proposed-updates
  • size: 58,188 kB
  • sloc: ansic: 96,086; cpp: 67,489; cs: 29,510; python: 25,829; pascal: 24,412; java: 15,582; ml: 14,473; makefile: 1,275; sh: 479; ruby: 386
file content (50 lines) | stat: -rwxr-xr-x 1,326 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
# convert LLVM GenDisassemblerTables.inc for Capstone disassembler.
# this just adds a header
# by Nguyen Anh Quynh, 2019

import sys

if len(sys.argv) == 1:
    print("Syntax: %s <GenDisassemblerTables.inc> <X86GenDisassemblerTables.inc> <X86GenDisassemblerTables2.inc>" %sys.argv[0])
    sys.exit(1)

f = open(sys.argv[1])
lines = f.readlines()
f.close()

f1 = open(sys.argv[2], 'w+')

f2 = open(sys.argv[3], 'w+')

f1.write("/* Capstone Disassembly Engine, http://www.capstone-engine.org */\n")
f1.write("/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */\n")
f1.write("\n")

f2.write("/* Capstone Disassembly Engine, http://www.capstone-engine.org */\n")
f2.write("/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */\n")
f2.write("\n")

# static const struct ContextDecision x86DisassemblerOneByteOpcodes = {

# static const struct ContextDecision x86DisassemblerXOP8Opcodes = {

write_to_f2 = False

for line in lines:
    # ignore all tables from XOP onwards
    if 'ContextDecision x86DisassemblerXOP8Opcodes = {' in line:
        # done
        break

    if 'ContextDecision x86DisassemblerOneByteOpcodes = {' in line:
        # done with f1, start writing to f2
        write_to_f2 = True

    if write_to_f2:
        f2.write(line)
    else:
        f1.write(line)

f1.close()
f2.close()