udis86: Update to latest. Fix compatibility with python3

This commit is contained in:
Alexey Pavlov
2019-12-29 14:21:20 +03:00
parent 34ec27bc8f
commit 133855dacd
5 changed files with 852 additions and 6 deletions

View File

@@ -0,0 +1,527 @@
From 16b95113bd94a4a722dad1edc55bde645d40dae0 Mon Sep 17 00:00:00 2001
From: Benjamin Pollack <benjamin@bitquabit.com>
Date: Mon, 20 Mar 2017 15:16:08 -0400
Subject: [PATCH] Fix the more egregious PEP-8 violations
---
scripts/ud_itab.py | 118 +++++++++++++++++++++----------------------
scripts/ud_opcode.py | 73 +++++++++++---------------
2 files changed, 86 insertions(+), 105 deletions(-)
diff --git a/scripts/ud_itab.py b/scripts/ud_itab.py
index 31d859e..63de355 100644
--- a/scripts/ud_itab.py
+++ b/scripts/ud_itab.py
@@ -195,8 +195,8 @@ class UdItabGenerator:
"cast" : "P_cast",
}
- MnemonicAliases = ( "invalid", "3dnow", "none", "db", "pause" )
-
+ MnemonicAliases = ("invalid", "3dnow", "none", "db", "pause")
+
def __init__(self, tables):
self.tables = tables
self._insnIndexMap, i = {}, 0
@@ -221,15 +221,15 @@ def getTableName(self, table):
def genOpcodeTable(self, table, isGlobal=False):
"""Emit Opcode Table in C.
"""
- self.ItabC.write( "\n" );
+ self.ItabC.write("\n")
if not isGlobal:
self.ItabC.write('static ')
- self.ItabC.write( "const uint16_t %s[] = {\n" % self.getTableName(table))
+ self.ItabC.write("const uint16_t %s[] = {\n" % self.getTableName(table))
for i in range(table.size()):
- if i > 0 and i % 4 == 0:
- self.ItabC.write( "\n" )
+ if i > 0 and i % 4 == 0:
+ self.ItabC.write("\n")
if i % 4 == 0:
- self.ItabC.write( " /* %2x */" % i)
+ self.ItabC.write(" /* %2x */" % i)
e = table.entryAt(i)
if e is None:
self.ItabC.write("%12s," % "INVALID")
@@ -237,35 +237,32 @@ def genOpcodeTable(self, table, isGlobal=False):
self.ItabC.write("%12s," % ("GROUP(%d)" % self.getTableIndex(e)))
elif isinstance(e, UdInsnDef):
self.ItabC.write("%12s," % self.getInsnIndex(e))
- self.ItabC.write( "\n" )
- self.ItabC.write( "};\n" )
-
+ self.ItabC.write("\n")
+ self.ItabC.write("};\n")
def genOpcodeTables(self):
tables = self.tables.getTableList()
for table in tables:
self.genOpcodeTable(table, table is self.tables.root)
-
def genOpcodeTablesLookupIndex(self):
- self.ItabC.write( "\n\n" );
- self.ItabC.write( "struct ud_lookup_table_list_entry ud_lookup_table_list[] = {\n" )
+ self.ItabC.write("\n\n")
+ self.ItabC.write("struct ud_lookup_table_list_entry ud_lookup_table_list[] = {\n")
for table in self.tables.getTableList():
f0 = self.getTableName(table) + ","
f1 = table.label() + ","
f2 = "\"%s\"" % table.meta()
- self.ItabC.write(" /* %03d */ { %s %s %s },\n" %
+ self.ItabC.write(" /* %03d */ { %s %s %s },\n" %
(self.getTableIndex(table), f0, f1, f2))
- self.ItabC.write( "};" )
+ self.ItabC.write("};")
-
- def genInsnTable( self ):
- self.ItabC.write( "struct ud_itab_entry ud_itab[] = {\n" );
+ def genInsnTable(self):
+ self.ItabC.write("struct ud_itab_entry ud_itab[] = {\n")
for insn in self.tables.getInsnList():
- opr_c = [ "O_NONE", "O_NONE", "O_NONE", "O_NONE" ]
+ opr_c = ["O_NONE", "O_NONE", "O_NONE", "O_NONE"]
pfx_c = []
- opr = insn.operands
- for i in range(len(opr)):
+ opr = insn.operands
+ for i in range(len(opr)):
if not (opr[i] in self.OperandDict.keys()):
print("error: invalid operand declaration: %s\n" % opr[i])
opr_c[i] = "O_" + opr[i]
@@ -273,18 +270,17 @@ def genInsnTable( self ):
opr_c[2] + ",", opr_c[3])
for p in insn.prefixes:
- if not ( p in self.PrefixDict.keys() ):
+ if not (p in self.PrefixDict.keys()):
print("error: invalid prefix specification: %s \n" % pfx)
- pfx_c.append( self.PrefixDict[p] )
+ pfx_c.append(self.PrefixDict[p])
if len(insn.prefixes) == 0:
- pfx_c.append( "P_none" )
- pfx = "|".join( pfx_c )
+ pfx_c.append("P_none")
+ pfx = "|".join(pfx_c)
- self.ItabC.write( " /* %04d */ { UD_I%s %s, %s },\n" \
- % ( self.getInsnIndex(insn), insn.mnemonic + ',', opr, pfx ) )
- self.ItabC.write( "};\n" )
+ self.ItabC.write(" /* %04d */ { UD_I%s %s, %s },\n" \
+ % (self.getInsnIndex(insn), insn.mnemonic + ',', opr, pfx))
+ self.ItabC.write("};\n")
-
def getMnemonicsList(self):
mnemonics = self.tables.getMnemonicsList()
mnemonics.extend(self.MnemonicAliases)
@@ -292,88 +288,88 @@ def getMnemonicsList(self):
def genMnemonicsList(self):
mnemonics = self.getMnemonicsList()
- self.ItabC.write( "\n\n" );
- self.ItabC.write( "const char* ud_mnemonics_str[] = {\n " )
- self.ItabC.write( ",\n ".join( [ "\"%s\"" % m for m in mnemonics ] ) )
- self.ItabC.write( "\n};\n" )
-
+ self.ItabC.write("\n\n")
+ self.ItabC.write("const char* ud_mnemonics_str[] = {\n ")
+ self.ItabC.write(",\n ".join(["\"%s\"" % m for m in mnemonics]))
+ self.ItabC.write("\n};\n")
- def genItabH( self, filePath ):
- self.ItabH = open( filePath, "w" )
+ def genItabH(self, filePath):
+ self.ItabH = open(filePath, "w")
# Generate Table Type Enumeration
- self.ItabH.write( "#ifndef UD_ITAB_H\n" )
- self.ItabH.write( "#define UD_ITAB_H\n\n" )
+ self.ItabH.write("#ifndef UD_ITAB_H\n")
+ self.ItabH.write("#define UD_ITAB_H\n\n")
self.ItabH.write("/* itab.h -- generated by udis86:scripts/ud_itab.py, do no edit */\n\n")
# table type enumeration
- self.ItabH.write( "/* ud_table_type -- lookup table types (see decode.c) */\n" )
- self.ItabH.write( "enum ud_table_type {\n " )
+ self.ItabH.write("/* ud_table_type -- lookup table types (see decode.c) */\n")
+ self.ItabH.write("enum ud_table_type {\n ")
enum = UdOpcodeTable.getLabels()
- self.ItabH.write( ",\n ".join( enum ) )
- self.ItabH.write( "\n};\n\n" );
+ self.ItabH.write(",\n ".join(enum))
+ self.ItabH.write("\n};\n\n")
# mnemonic enumeration
- self.ItabH.write( "/* ud_mnemonic -- mnemonic constants */\n" )
- enum = "enum ud_mnemonic_code {\n "
- enum += ",\n ".join( [ "UD_I%s" % m for m in self.getMnemonicsList() ] )
+ self.ItabH.write("/* ud_mnemonic -- mnemonic constants */\n")
+ enum = "enum ud_mnemonic_code {\n "
+ enum += ",\n ".join(["UD_I%s" % m for m in self.getMnemonicsList()])
enum += ",\n UD_MAX_MNEMONIC_CODE"
enum += "\n};\n"
- self.ItabH.write( enum )
- self.ItabH.write( "\n" )
+ self.ItabH.write(enum)
+ self.ItabH.write("\n")
- self.ItabH.write( "extern const char * ud_mnemonics_str[];\n" )
+ self.ItabH.write("extern const char * ud_mnemonics_str[];\n")
- self.ItabH.write( "\n#endif /* UD_ITAB_H */\n" )
-
- self.ItabH.close()
+ self.ItabH.write("\n#endif /* UD_ITAB_H */\n")
+ self.ItabH.close()
def genItabC(self, filePath):
self.ItabC = open(filePath, "w")
self.ItabC.write("/* itab.c -- generated by udis86:scripts/ud_itab.py, do no edit")
- self.ItabC.write(" */\n");
- self.ItabC.write("#include \"decode.h\"\n\n");
+ self.ItabC.write(" */\n")
+ self.ItabC.write("#include \"decode.h\"\n\n")
self.ItabC.write("#define GROUP(n) (0x8000 | (n))\n")
self.ItabC.write("#define INVALID %d\n\n" % self.getInsnIndex(self.tables.invalidInsn))
- self.genOpcodeTables()
+ self.genOpcodeTables()
self.genOpcodeTablesLookupIndex()
#
# Macros defining short-names for operands
#
- self.ItabC.write("\n\n/* itab entry operand definitions (for readability) */\n");
+ self.ItabC.write("\n\n/* itab entry operand definitions (for readability) */\n")
operands = self.OperandDict.keys()
operands = sorted(operands)
for o in operands:
self.ItabC.write("#define O_%-7s { %-12s %-8s }\n" %
- (o, self.OperandDict[o][0] + ",", self.OperandDict[o][1]));
- self.ItabC.write("\n");
+ (o, self.OperandDict[o][0] + ",", self.OperandDict[o][1]))
+ self.ItabC.write("\n")
self.genInsnTable()
self.genMnemonicsList()
self.ItabC.close()
- def genItab( self, location ):
+ def genItab(self, location):
self.genItabC(os.path.join(location, "itab.c"))
self.genItabH(os.path.join(location, "itab.h"))
+
def usage():
print("usage: ud_itab.py <optable.xml> <output-path>")
-def main():
+def main():
if len(sys.argv) != 3:
usage()
sys.exit(1)
-
+
tables = UdOpcodeTables(xml=sys.argv[1])
- itab = UdItabGenerator(tables)
+ itab = UdItabGenerator(tables)
itab.genItab(sys.argv[2])
+
if __name__ == '__main__':
main()
diff --git a/scripts/ud_opcode.py b/scripts/ud_opcode.py
index fe1833d..4495883 100644
--- a/scripts/ud_opcode.py
+++ b/scripts/ud_opcode.py
@@ -52,7 +52,6 @@ def lookupPrefix(self, pfx):
"""Lookup prefix (if any, None otherwise), by name"""
return True if pfx in self.prefixes else None
-
@property
def vendor(self):
return self._opcexts.get('/vendor', None)
@@ -87,9 +86,9 @@ class IndexError(Exception):
@classmethod
def vendor2idx(cls, v):
- return (0 if v == 'amd'
- else (1 if v == 'intel'
- else 2))
+ return (0 if v == 'amd'
+ else (1 if v == 'intel'
+ else 2))
@classmethod
def vex2idx(cls, v):
@@ -166,13 +165,11 @@ def vex2idx(cls, v):
'/vexl' : { 'label' : 'UD_TAB__OPC_VEX_L', 'size' : 2 },
}
-
def __init__(self, typ):
assert typ in self._TableInfo
- self._typ = typ
+ self._typ = typ
self._entries = {}
-
def size(self):
return self._TableInfo[self._typ]['size']
@@ -191,11 +188,9 @@ def typ(self):
def meta(self):
return self._typ
-
def __str__(self):
return "table-%s" % self._typ
-
def add(self, opc, obj):
typ = UdOpcodeTable.getOpcodeTyp(opc)
idx = UdOpcodeTable.getOpcodeIdx(opc)
@@ -203,7 +198,6 @@ def add(self, opc, obj):
raise CollisionError()
self._entries[idx] = obj
-
def lookup(self, opc):
typ = UdOpcodeTable.getOpcodeTyp(opc)
idx = UdOpcodeTable.getOpcodeIdx(opc)
@@ -211,7 +205,6 @@ def lookup(self, opc):
raise UdOpcodeTable.CollisionError("%s <-> %s" % (self._typ, typ))
return self._entries.get(idx, None)
-
def entryAt(self, index):
"""Returns the entry at a given index of the table,
None if there is none. Raises an exception if the
@@ -234,7 +227,6 @@ def getOpcodeTyp(cls, opc):
else:
return 'opctbl'
-
@classmethod
def getOpcodeIdx(cls, opc):
if opc.startswith('/'):
@@ -244,7 +236,6 @@ def getOpcodeIdx(cls, opc):
# plain opctbl opcode
return int(opc, 16)
-
@classmethod
def getLabels(cls):
"""Returns a list of all labels"""
@@ -282,7 +273,7 @@ def walk(self, tbl, opcodes):
to walk, the object at the leaf otherwise.
"""
opc = opcodes[0]
- e = tbl.lookup(opc)
+ e = tbl.lookup(opc)
if e is None:
return None
elif isinstance(e, UdOpcodeTable) and len(opcodes[1:]):
@@ -295,7 +286,7 @@ def map(self, tbl, opcodes, obj):
needed.
"""
opc = opcodes[0]
- e = tbl.lookup(opc)
+ e = tbl.lookup(opc)
if e is None:
tbl.add(opc, self.mkTrie(opcodes[1:], obj))
else:
@@ -304,16 +295,16 @@ def map(self, tbl, opcodes, obj):
self.map(e, opcodes[1:], obj)
def __init__(self, xml):
- self._tables = []
- self._insns = []
+ self._tables = []
+ self._insns = []
self._mnemonics = {}
# The root table is always a 256 entry opctbl, indexed
# by a plain opcode byte
- self.root = self.newTable('opctbl')
+ self.root = self.newTable('opctbl')
if os.getenv("UD_OPCODE_DEBUG"):
- self._logFh = open("opcodeTables.log", "w")
+ self._logFh = open("opcodeTables.log", "w")
# add an invalid instruction entry without any mapping
# in the opcode tables.
@@ -333,7 +324,6 @@ def log(self, s):
if os.getenv("UD_OPCODE_DEBUG"):
self._logFh.write(s + "\n")
-
def mergeSSENONE(self):
"""Merge sse tables with only one entry for /sse=none
"""
@@ -345,6 +335,7 @@ def mergeSSENONE(self):
if sse:
table.setEntryAt(k, sse)
uniqTables = {}
+
def genTableList(tbl):
if tbl not in uniqTables:
self._tables.append(tbl)
@@ -352,9 +343,9 @@ def genTableList(tbl):
for k, e in tbl.entries():
if isinstance(e, UdOpcodeTable):
genTableList(e)
+
self._tables = []
genTableList(self.root)
-
def patchAvx2byte(self):
# create avx tables
@@ -371,7 +362,6 @@ def patchAvx2byte(self):
table = self.walk(self.root, ('c4', '/vex=' + vex))
self.map(self.root, ('c5', '/vex=' + vex), table)
-
def addInsn(self, **insnDef):
# Canonicalize opcode list
@@ -409,14 +399,13 @@ def addInsn(self, **insnDef):
self._insns.append(insn)
# add to lookup by mnemonic structure
if insn.mnemonic not in self._mnemonics:
- self._mnemonics[insn.mnemonic] = [ insn ]
+ self._mnemonics[insn.mnemonic] = [insn]
else:
self._mnemonics[insn.mnemonic].append(insn)
-
def addInsnDef(self, insnDef):
- opcodes = []
- opcexts = {}
+ opcodes = []
+ opcexts = {}
# pack plain opcodes first, and collect opcode
# extensions
@@ -454,7 +443,7 @@ def addInsnDef(self, insnDef):
# Construct a long-form definition of the avx instruction
opcodes.insert(0, 'c4')
elif (opcodes[0] == '0f' and opcodes[1] != '0f' and
- '/sse' not in opcexts):
+ '/sse' not in opcexts):
# Make all 2-byte opcode form isntructions play nice with sse
# opcode maps.
opcexts['/sse'] = 'none'
@@ -471,7 +460,6 @@ def addInsnDef(self, insnDef):
operands = insnDef['operands'],
cpuid = insnDef['cpuid'])
-
def addSSE2AVXInsn(self, **insnDef):
"""Add an instruction definition containing an avx cpuid bit, but
declared in its legacy SSE form. The function splits the
@@ -481,20 +469,20 @@ def addSSE2AVXInsn(self, **insnDef):
# SSE
ssemnemonic = insnDef['mnemonic']
- sseopcodes = insnDef['opcodes']
+ sseopcodes = insnDef['opcodes']
# remove vex opcode extensions
- sseopcexts = dict([(e, v) for e, v in itemslist(insnDef['opcexts'])
- if not e.startswith('/vex')])
+ sseopcexts = dict([(e, v) for e, v in itemslist(insnDef['opcexts'])
+ if not e.startswith('/vex')])
# strip out avx operands, preserving relative ordering
# of remaining operands
sseoperands = [opr for opr in insnDef['operands']
- if opr not in ('H', 'L')]
+ if opr not in ('H', 'L')]
# strip out avx prefixes
sseprefixes = [pfx for pfx in insnDef['prefixes']
- if not pfx.startswith('vex')]
+ if not pfx.startswith('vex')]
# strip out avx bits from cpuid
- ssecpuid = [flag for flag in insnDef['cpuid']
- if not flag.startswith('avx')]
+ ssecpuid = [flag for flag in insnDef['cpuid']
+ if not flag.startswith('avx')]
self.addInsn(mnemonic = ssemnemonic,
prefixes = sseprefixes,
@@ -521,8 +509,8 @@ def addSSE2AVXInsn(self, **insnDef):
if o in ('V', 'W', 'H', 'U'):
o = o + 'x'
vexoperands.append(o)
- vexcpuid = [flag for flag in insnDef['cpuid']
- if not flag.startswith('sse')]
+ vexcpuid = [flag for flag in insnDef['cpuid']
+ if not flag.startswith('sse')]
self.addInsn(mnemonic = vexmnemonic,
prefixes = vexprefixes,
@@ -535,7 +523,6 @@ def getInsnList(self):
"""Returns a list of all instructions in the collection"""
return self._insns
-
def getTableList(self):
"""Returns a list of all tables in the collection"""
return self._tables
@@ -544,7 +531,6 @@ def getMnemonicsList(self):
"""Returns a sorted list of mnemonics"""
return sorted(self._mnemonics.keys())
-
def pprint(self):
def printWalk(tbl, indent=""):
entries = tbl.entries()
@@ -554,8 +540,8 @@ def printWalk(tbl, indent=""):
printWalk(e, indent + " |")
elif isinstance(e, UdInsnDef):
self.log("%s |-<%02x> %s" % (indent, k, e))
- printWalk(self.root)
+ printWalk(self.root)
def printStats(self):
tables = self.getTableList()
@@ -574,7 +560,6 @@ def printStats(self):
self.pprint()
-
@staticmethod
def parseOptableXML(xml):
"""Parse udis86 optable.xml file and return list of
@@ -584,9 +569,9 @@ def parseOptableXML(xml):
xmlDoc = minidom.parse(xml)
tlNode = xmlDoc.firstChild
- insns = []
+ insns = []
- while tlNode and tlNode.localName != "x86optable":
+ while tlNode and tlNode.localName != "x86optable":
tlNode = tlNode.nextSibling
for insnNode in tlNode.childNodes:
@@ -605,7 +590,7 @@ def parseOptableXML(xml):
for node in insnNode.childNodes:
if node.localName == 'def':
- insnDef = { 'pfx' : [] }
+ insnDef = {'pfx': []}
for node in node.childNodes:
if not node.localName:
continue

View File

@@ -0,0 +1,163 @@
From 6e216df0e8ea9aacd772c53f10518c2bffee6094 Mon Sep 17 00:00:00 2001
From: Benjamin Pollack <benjamin@bitquabit.com>
Date: Mon, 20 Mar 2017 15:25:58 -0400
Subject: [PATCH] More cleanup and some bug fixes
---
scripts/ud_itab.py | 12 ++++++------
scripts/ud_opcode.py | 42 +++++++++++++++++-------------------------
2 files changed, 23 insertions(+), 31 deletions(-)
diff --git a/scripts/ud_itab.py b/scripts/ud_itab.py
index 63de355..4b0b43e 100644
--- a/scripts/ud_itab.py
+++ b/scripts/ud_itab.py
@@ -262,16 +262,16 @@ def genInsnTable(self):
opr_c = ["O_NONE", "O_NONE", "O_NONE", "O_NONE"]
pfx_c = []
opr = insn.operands
- for i in range(len(opr)):
- if not (opr[i] in self.OperandDict.keys()):
- print("error: invalid operand declaration: %s\n" % opr[i])
- opr_c[i] = "O_" + opr[i]
+ for i, op in enumerate(opr):
+ if op not in self.OperandDict:
+ print("error: invalid operand declaration: %s\n" % op)
+ opr_c[i] = "O_" + op
opr = "%s %s %s %s" % (opr_c[0] + ",", opr_c[1] + ",",
opr_c[2] + ",", opr_c[3])
for p in insn.prefixes:
- if not (p in self.PrefixDict.keys()):
- print("error: invalid prefix specification: %s \n" % pfx)
+ if p not in self.PrefixDict:
+ print("error: invalid prefix specification: %s \n" % p)
pfx_c.append(self.PrefixDict[p])
if len(insn.prefixes) == 0:
pfx_c.append("P_none")
diff --git a/scripts/ud_opcode.py b/scripts/ud_opcode.py
index 4495883..4a4b74c 100644
--- a/scripts/ud_opcode.py
+++ b/scripts/ud_opcode.py
@@ -25,16 +25,15 @@
import os
-# Some compatibility stuff for supporting python 2.x as well as python 3.x
-def itemslist(dict):
- try:
- return dict.iteritems() # python 2.x
- except AttributeError:
- return list(dict.items()) # python 3.x
+
+class CollisionError(Exception):
+ pass
+
class UdInsnDef:
"""An x86 instruction definition
"""
+
def __init__(self, **insnDef):
self.mnemonic = insnDef['mnemonic']
self.prefixes = insnDef['prefixes']
@@ -77,13 +76,6 @@ class UdOpcodeTable:
a decode field.
"""
- class CollisionError(Exception):
- pass
-
- class IndexError(Exception):
- """Invalid Index Error"""
- pass
-
@classmethod
def vendor2idx(cls, v):
return (0 if v == 'amd'
@@ -174,10 +166,10 @@ def size(self):
return self._TableInfo[self._typ]['size']
def entries(self):
- return itemslist(self._entries)
+ return self._entries.items()
def numEntries(self):
- return len(self._entries.keys())
+ return len(self._entries)
def label(self):
return self._TableInfo[self._typ]['label']
@@ -195,14 +187,14 @@ def add(self, opc, obj):
typ = UdOpcodeTable.getOpcodeTyp(opc)
idx = UdOpcodeTable.getOpcodeIdx(opc)
if self._typ != typ or idx in self._entries:
- raise CollisionError()
+ raise CollisionError
self._entries[idx] = obj
def lookup(self, opc):
typ = UdOpcodeTable.getOpcodeTyp(opc)
idx = UdOpcodeTable.getOpcodeIdx(opc)
if self._typ != typ:
- raise UdOpcodeTable.CollisionError("%s <-> %s" % (self._typ, typ))
+ raise CollisionError("%s <-> %s" % (self._typ, typ))
return self._entries.get(idx, None)
def entryAt(self, index):
@@ -212,13 +204,13 @@ def entryAt(self, index):
"""
if index < self.size():
return self._entries.get(index, None)
- raise self.IndexError("index out of bounds: %s" % index)
+ raise IndexError("index out of bounds: %s" % index)
def setEntryAt(self, index, obj):
if index < self.size():
self._entries[index] = obj
else:
- raise self.IndexError("index out of bounds: %s" % index)
+ raise IndexError("index out of bounds: %s" % index)
@classmethod
def getOpcodeTyp(cls, opc):
@@ -239,7 +231,7 @@ def getOpcodeIdx(cls, opc):
@classmethod
def getLabels(cls):
"""Returns a list of all labels"""
- return [cls._TableInfo[k]['label'] for k in cls._TableInfo.keys()]
+ return [cls._TableInfo[k]['label'] for k in cls._TableInfo]
class UdOpcodeTables(object):
@@ -471,8 +463,8 @@ def addSSE2AVXInsn(self, **insnDef):
ssemnemonic = insnDef['mnemonic']
sseopcodes = insnDef['opcodes']
# remove vex opcode extensions
- sseopcexts = dict([(e, v) for e, v in itemslist(insnDef['opcexts'])
- if not e.startswith('/vex')])
+ sseopcexts = {e: v for e, v in insnDef['opcexts'].items()
+ if not e.startswith('/vex')}
# strip out avx operands, preserving relative ordering
# of remaining operands
sseoperands = [opr for opr in insnDef['operands']
@@ -495,8 +487,8 @@ def addSSE2AVXInsn(self, **insnDef):
vexmnemonic = 'v' + insnDef['mnemonic']
vexprefixes = insnDef['prefixes']
vexopcodes = ['c4']
- vexopcexts = dict([(e, insnDef['opcexts'][e])
- for e in insnDef['opcexts'] if e != '/sse'])
+ vexopcexts = {e: insnDef['opcexts'][e]
+ for e in insnDef['opcexts'] if e != '/sse'}
vexopcexts['/vex'] = insnDef['opcexts']['/sse'] + '_' + '0f'
if insnDef['opcodes'][1] == '38' or insnDef['opcodes'][1] == '3a':
vexopcexts['/vex'] += insnDef['opcodes'][1]
@@ -507,7 +499,7 @@ def addSSE2AVXInsn(self, **insnDef):
for o in insnDef['operands']:
# make the operand size explicit: x
if o in ('V', 'W', 'H', 'U'):
- o = o + 'x'
+ o += 'x'
vexoperands.append(o)
vexcpuid = [flag for flag in insnDef['cpuid']
if not flag.startswith('sse')]

View File

@@ -0,0 +1,34 @@
From fcdc356c12c2ced673b6aac3d44e5ad48ff7b552 Mon Sep 17 00:00:00 2001
From: Benjamin Pollack <benjamin@bitquabit.com>
Date: Mon, 20 Mar 2017 15:29:08 -0400
Subject: [PATCH] Fix for Python 3
---
scripts/ud_opcode.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/scripts/ud_opcode.py b/scripts/ud_opcode.py
index 4a4b74c..aeff64b 100644
--- a/scripts/ud_opcode.py
+++ b/scripts/ud_opcode.py
@@ -521,17 +521,17 @@ def getTableList(self):
def getMnemonicsList(self):
"""Returns a sorted list of mnemonics"""
- return sorted(self._mnemonics.keys())
+ return sorted(self._mnemonics)
def pprint(self):
def printWalk(tbl, indent=""):
entries = tbl.entries()
for k, e in entries:
if isinstance(e, UdOpcodeTable):
- self.log("%s |-<%02x> %s" % (indent, k, e))
+ self.log("%s |-<%02x> %s" % (indent, int(k), e))
printWalk(e, indent + " |")
elif isinstance(e, UdInsnDef):
- self.log("%s |-<%02x> %s" % (indent, k, e))
+ self.log("%s |-<%02x> %s" % (indent, int(k), e))
printWalk(self.root)

View File

@@ -0,0 +1,101 @@
From 1b0c2c8eedb0c8003d3397c2d80f1db170b313cb Mon Sep 17 00:00:00 2001
From: hasherezade <hasherezade@op.pl>
Date: Sat, 28 Feb 2015 16:06:01 +0100
Subject: [PATCH] resolved #97 : added files to build with CMake
---
CMakeLists.txt | 23 +++++++++++++++++++++++
libudis86/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++++
udcli/CMakeLists.txt | 12 ++++++++++++
3 files changed, 69 insertions(+)
create mode 100644 CMakeLists.txt
create mode 100644 libudis86/CMakeLists.txt
create mode 100644 udcli/CMakeLists.txt
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..217f0b9
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,23 @@
+cmake_minimum_required (VERSION 2.8)
+project (udis86)
+
+# modules:
+set (M_LIBUDIS "libudis86")
+set (M_UDCLI "udcli")
+
+# modules paths:
+set (LIBUDIS_DIR "${CMAKE_SOURCE_DIR}/${M_LIBUDIS}" CACHE PATH "libudis86 main path")
+set (UDCLI_DIR "${CMAKE_SOURCE_DIR}/${M_UDCLI}" CACHE PATH "udcli main path")
+
+# Add sub-directories
+#
+# libs
+add_subdirectory (libudis86)
+get_property (libudis86_location TARGET libudis86 PROPERTY LOCATION)
+set (LIBUDIS_LIB ${libudis86_location} CACHE FILE "libudis86 library path")
+
+# executables
+add_subdirectory(udcli)
+
+# dependencies
+add_dependencies(udcli libudis86)
diff --git a/libudis86/CMakeLists.txt b/libudis86/CMakeLists.txt
new file mode 100644
index 0000000..0a47f77
--- /dev/null
+++ b/libudis86/CMakeLists.txt
@@ -0,0 +1,34 @@
+cmake_minimum_required (VERSION 2.8)
+
+project (udis86)
+
+set (ITAB_H "${CMAKE_CURRENT_LIST_DIR}/itab.h")
+set (ITAB_C "${CMAKE_CURRENT_LIST_DIR}/itab.c")
+
+if(NOT EXISTS ${ITAB_H} OR NOT EXISTS ${ITAB_C} )
+ message(FATAL_ERROR "You must generate files: ${ITAB_H}, ${ITAB_C} before you start.")
+endif()
+
+include_directories(../)
+
+set (udis86_srcs
+ decode.c
+ itab.c
+ syn.c
+ syn-att.c
+ syn-intel.c
+ udis86.c
+)
+
+set (udis86_hdrs
+ ../udis86.h
+ decode.h
+ itab.h
+ extern.h
+ syn.h
+ types.h
+ udint.h
+)
+
+add_library (libudis86 SHARED ${udis86_srcs} ${udis86_hdrs})
+add_library (libudis86a STATIC ${udis86_srcs} ${udis86_hdrs})
diff --git a/udcli/CMakeLists.txt b/udcli/CMakeLists.txt
new file mode 100644
index 0000000..98edfd6
--- /dev/null
+++ b/udcli/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required (VERSION 2.8)
+
+project (udcli)
+
+include_directories(../)
+
+set (udcli_srcs
+ udcli.c
+)
+
+add_executable (udcli ${udcli_srcs} )
+target_link_libraries (udcli ${LIBUDIS_LIB})

View File

@@ -3,7 +3,7 @@
_realname=udis86
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7.2
pkgver=1.7.3rc1
pkgrel=1
pkgdesc="A minimalistic disassembler library (mingw-w64)"
arch=('any')
@@ -11,16 +11,35 @@ url="https://udis86.sourceforge.io/"
license=("BSD")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
"${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-python2")
depends=("${MINGW_PACKAGE_PREFIX}-python")
options=('strip' '!libtool' 'staticlibs')
source=("https://downloads.sourceforge.net/udis86/${_realname}-${pkgver}.tar.gz")
sha256sums=('9c52ac626ac6f531e1d6828feaad7e797d0f3cce1e9f34ad4e84627022b3c2f4')
source=(${_realname}::git+https://github.com/vmt/udis86.git#commit=56ff6c87c11de0ffa725b14339004820556e343d
#"https://downloads.sourceforge.net/udis86/${_realname}-${pkgver}.tar.gz"
001-pep8-violations.patch
002-cleanup-and-bug-fixes.patch
003-python3-fixes.patch
004-add-cmake-build.patch)
sha256sums=('SKIP'
'2081a4e4b5d90a1555ddb05632a9e9efc9488a90726250e4cc6ee609a5eaeef7'
'79eef5840934a3591b09b6de6ad9a411c0313d7c7379cf66978b2181bdd45825'
'c196636cbe2a34187f89bd239c92ff27eae0b3673f7a557b78335c14a988e3fd'
'88fb254a94ce28928b04a103e31c1fcba61c87a76c4a4ee09e30d1575bb0e150')
prepare() {
cd ${_realname}
patch -p1 -i ${srcdir}/001-pep8-violations.patch
patch -p1 -i ${srcdir}/002-cleanup-and-bug-fixes.patch
patch -p1 -i ${srcdir}/003-python3-fixes.patch
patch -p1 -i ${srcdir}/004-add-cmake-build.patch
autoreconf -fiv
}
build() {
[[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
mkdir -p "${srcdir}/build-${MINGW_CHOST}"
cd "${srcdir}/build-${MINGW_CHOST}"
../${_realname}-${pkgver}/configure \
../${_realname}/configure \
--prefix=${MINGW_PREFIX} \
--build=${MINGW_CHOST} \
--host=${MINGW_CHOST}
@@ -29,5 +48,7 @@ build() {
package () {
cd "${srcdir}/build-${MINGW_CHOST}"
make DESTDIR="$pkgdir" install
make DESTDIR="${pkgdir}" install
cp ${srcdir}/${_realname}/scripts/*.py ${pkgdir}${MINGW_PREFIX}/bin/
}