Rizin
unix-like reverse engineering framework and cli tools
autogen_x86imm.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # By Nguyen Anh Quynh, 2015
3 # This tool extract sizes of immediadte operands from X86 instruction names.
4 # Syntax: ./autogen_x86imm.py
5 
6 # Gather immediate sizes to put into X86ImmSize.inc
7 OUTPUT = "../arch/X86/X86ImmSize.inc"
8 
9 f = open("../arch/X86/X86GenInstrInfo.inc")
10 f2 = open(OUTPUT, "w")
11 for line in f.readlines():
12  tmp = line.strip().split("=")
13  if len(tmp) == 2: # X86_xxx = nnn,
14  name = tmp[0].strip()
15  if name == "X86_INSTRUCTION_LIST_END": # no more instructions
16  break
17  if name.endswith("_DB"): # pseudo instruction
18  continue
19  if "_LOCK_" in name or "BEXTR" in name: # exception
20  continue
21  if name.startswith("X86_"): # instruction
22  if name.endswith("16mi8"):
23  f2.write("{2, %s},\n" %name)
24  elif name.endswith("16ri8"):
25  f2.write("{2, %s},\n" %name)
26  elif name.endswith("32ri8"):
27  f2.write("{4, %s},\n" %name)
28  elif name.endswith("32mi8"):
29  f2.write("{4, %s},\n" %name)
30  elif name.endswith("64i32"):
31  f2.write("{8, %s},\n" %name)
32  elif name.endswith("64mi32"):
33  f2.write("{8, %s},\n" %name)
34  elif name.endswith("64ri32"):
35  f2.write("{8, %s},\n" %name)
36  elif name.endswith("64ri8"):
37  f2.write("{8, %s},\n" %name)
38  elif name.endswith("64mi8"):
39  f2.write("{8, %s},\n" %name)
40  elif name.endswith("16rmi8"):
41  f2.write("{2, %s},\n" %name)
42  elif name.endswith("32rmi8"):
43  f2.write("{4, %s},\n" %name)
44  elif name.endswith("16rri8"):
45  f2.write("{2, %s},\n" %name)
46  elif name.endswith("32rri8"):
47  f2.write("{4, %s},\n" %name)
48  elif name.endswith("64rmi8"):
49  f2.write("{8, %s},\n" %name)
50  elif name.endswith("64rmi32"):
51  f2.write("{8, %s},\n" %name)
52  elif name.endswith("64rri32"):
53  f2.write("{8, %s},\n" %name)
54  elif name.endswith("64rri8"):
55  f2.write("{8, %s},\n" %name)
56  elif name.endswith("32ri64"): # special case
57  f2.write("{8, %s},\n" %name)
58  elif name.endswith("16i8"): # special case
59  f2.write("{2, %s},\n" %name)
60  elif name.endswith("32i8"): # special case
61  f2.write("{4, %s},\n" %name)
62  elif name.endswith("64i16"): # special case
63  f2.write("{8, %s},\n" %name)
64  elif name.endswith("64i8"): # special case
65  f2.write("{8, %s},\n" %name)
66 
67  elif name.endswith("i8") or "i8_" in name:
68  f2.write("{1, %s},\n" %name)
69  elif "8ri" in name or "8mi" in name:
70  f2.write("{1, %s},\n" %name)
71 
72  elif name.endswith("i16") or "i16_" in name:
73  f2.write("{2, %s},\n" %name)
74  elif "16ri" in name or "16mi" in name:
75  f2.write("{2, %s},\n" %name)
76 
77  elif name.endswith("i32") or "i32_" in name:
78  f2.write("{4, %s},\n" %name)
79  elif "32ri" in name or "32mi" in name:
80  f2.write("{4, %s},\n" %name)
81 
82  elif name.endswith("i64") or "i64_" in name:
83  f2.write("{8, %s},\n" %name)
84  elif "64ri" in name or "64mi" in name:
85  f2.write("{8, %s},\n" %name)
86 
87 f.close()
88 f2.close()
89 
90 print("Generated %s" %OUTPUT)
size_t len
Definition: 6502dis.c:15