Skip to content

Commit ebd59e6

Browse files
committed
squash merge of develop branch:
- improve itercfg method and lbackward CFG reconstruction - improve widening/fixpoint in computation of func's map - improve pretty printing methods - start merging ui.graphics packages
1 parent cf75ac1 commit ebd59e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1362
-449
lines changed

README.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,21 @@ Please see `LICENSE`_.
13381338
Changelog
13391339
=========
13401340

1341+
- `v2.4.3`_
1342+
1343+
* add ui.graphics packages (emptied)
1344+
* add ui.views module with support for block/func/xfunc
1345+
* add ui.render.vltable class to pretty print tables
1346+
* improve instruction formatter class to access pp tokens
1347+
* cleaner itercfg and lbackward algorithms
1348+
* add vecw expression class to represent 'widened' vec expressions
1349+
* improve Memory write of vec expressions
1350+
* improve widening and fixpoint in func.makemap()
1351+
* add 'type' attribute (std/pc/flags/stack/other)
1352+
* define register type for x86 arch
1353+
* fix some x86/64 decoding/formating/semantics
1354+
* update travis config, fix pytest vs. Token.
1355+
13411356
- `v2.4.2`_
13421357

13431358
* merge support for pygments pretty printing methods (in ui.render module)
@@ -1351,7 +1366,6 @@ Changelog
13511366
* add sparc coprocessor registers
13521367
* update README
13531368

1354-
13551369
- `v2.4.1`_
13561370

13571371
* add lbackward analysis and func.makemap() implementations
@@ -1430,6 +1444,7 @@ Changelog
14301444
.. _ply: http://www.dabeaz.com/ply/
14311445
.. _zodb: http://www.zodb.org
14321446
.. _LICENSE: https://github.com/bdcht/amoco/blob/release/LICENSE
1447+
.. _v2.4.3: https://github.com/bdcht/amoco/releases/tag/v2.4.3
14331448
.. _v2.4.2: https://github.com/bdcht/amoco/releases/tag/v2.4.2
14341449
.. _v2.4.1: https://github.com/bdcht/amoco/releases/tag/v2.4.1
14351450
.. _v2.4.0: https://github.com/bdcht/amoco/releases/tag/v2.4.0

amoco/arch/arm/v7/formats.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44
from .utils import *
55
from amoco.arch.core import Formatter
66

7+
from amoco.ui.render import Token, TokenListJoin
8+
79
def mnemo(i):
810
m = i.mnemonic
911
if hasattr(i,'setflags') and i.setflags:
1012
m += 'S'
1113
if hasattr(i,'cond') and i.cond!=CONDITION_AL:
1214
m += '.%s'%CONDITION[i.cond][0]
13-
return '%s'%(m.lower()).ljust(12)
15+
return [(Token.Mnemonic,'%s'%(m.lower()).ljust(12))]
1416

1517
def regs(i,limit=None):
1618
ops = i.operands
1719
if limit: ops = ops[:limit]
18-
return ['{0}'.format(r) for r in ops]
20+
return [(Token.Register,'{0}'.format(r)) for r in ops]
1921

2022
def reglist(i,pos=-1):
2123
l = i.operands[pos]
22-
return "{%s}"%(', '.join(['{0}'.format(r) for r in l]))
24+
return [(Token.Register,"{%s}"%(', '.join(['{0}'.format(r) for r in l])))]
2325

2426
def deref(i,pos=-2):
2527
assert len(i.operands)>2
@@ -37,19 +39,19 @@ def deref(i,pos=-2):
3739
loc = '[%s], %s'%(base, ostr)
3840
else:
3941
loc = '[%s], %s'%(base,ostr)
40-
return [loc]
42+
return [(Token.Memory,loc)]
4143

4244
def label(i,pos=0):
4345
_pc = i.address
4446
if _pc is None: _pc=pc
4547
pcoffset = 4 if internals['isetstate']==0 else 2
4648
_pc = _pc + 2*pcoffset
4749
offset = i.operands[pos]
48-
return '*'+str(_pc+offset)
50+
return [(Token.Address,'*'+str(_pc+offset))]
4951

5052
def setend(i):
5153
endian_specifier = 'BE' if i.set_bigend else 'LE'
52-
return mnemo(i)+endian_specifier
54+
return mnemo(i)+[(Token.Literal,endian_specifier)]
5355

5456
def plx(i):
5557
m = mnemo(i)
@@ -59,23 +61,23 @@ def plx(i):
5961
ostr = '#%c%d'%(sign,offset.value)
6062
else:
6163
ostr = sign+str(offset)
62-
loc = '[%s, %s]'%(base, ostr)
64+
loc = [(Token.Memory,'[%s, %s]'%(base, ostr))]
6365
return m+loc
6466

6567
def specreg(i):
6668
spec_reg = "%s_"%apsr
6769
if i.write_nzcvq: spec_reg += 'nzcvq'
6870
if i.write_g: spec_reg += 'g'
69-
return '%s, %s'%(i.operands[0],spec_reg)
71+
return [(Token.Register,'%s, %s'%(i.operands[0],spec_reg))]
7072

71-
format_allregs = [lambda i: ', '.join(regs(i))]
73+
format_allregs = [lambda i: TokenListJoin(', ',regs(i))]
7274
format_default = [mnemo]+format_allregs
7375
format_sreg = format_default
7476
format_label = [mnemo, label]
75-
format_adr = [mnemo, lambda i: '{0}, '.format(i.operands[0]), lambda i: label(i,1)]
77+
format_adr = [mnemo, lambda i: regs(i,1), lambda i: label(i,1)]
7678
format_bits = format_default
77-
format_reglist = [mnemo, (lambda i: ', '.join(regs(i,-1))), reglist]
78-
format_deref = [mnemo, lambda i: ', '.join(regs(i,-2)+deref(i,-2))]
79+
format_reglist = [mnemo, (lambda i: TokenListJoin(', ',regs(i,-1))), reglist]
80+
format_deref = [mnemo, lambda i: TokenListJoin(', ',regs(i,-2)+deref(i,-2))]
7981
format_plx = [plx]
8082
format_msr = [mnemo, specreg]
8183
format_setend = [setend]

amoco/arch/core.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from amoco.logger import Log
1515
logger = Log(__name__)
1616

17+
from amoco.ui.render import Token,highlight
18+
1719
type_unpredictable = -1
1820
type_undefined = 0
1921
type_data_processing = 1
@@ -93,15 +95,19 @@ def __repr__(self):
9395
def set_formatter(cls,f):
9496
cls.formatter = f
9597

96-
#default formatter:
97-
def formatter(self,i):
98-
m = i.mnemonic
99-
o = ','.join(map(str,i.operands))
100-
return '%s %s'%(m,o)
98+
@staticmethod
99+
def formatter(i,toks=False):
100+
t = (Token.Mnemonic,i.mnemonic)
101+
t+= [(Token.Literal,op) for op in map(str,i.operands[0:1])]
102+
t+= [(Token.Literal,', '+op) for op in map(str,i.operands[1:])]
103+
return t if toks else highlight(t)
101104

102105
def __str__(self):
103106
return self.formatter(i=self)
104107

108+
def toks(self):
109+
return self.formatter(i=self,toks=True)
110+
105111
def __getstate__(self):
106112
return (self.bytes,
107113
self.type,
@@ -470,16 +476,17 @@ def getparts(self,i):
470476
fmts = self.formats.get(i.spec.hook.func_name,self.default)
471477
return fmts
472478

473-
def __call__(self,i):
479+
def __call__(self,i,toks=False):
474480
s=[]
475481
for f in self.getparts(i):
476482
if hasattr(f,'format'):
477-
# It is a string
478-
s.append(f.format(i=i))
483+
t = f.format(i=i)
479484
else:
480-
# It is a function
481-
s.append(f(i))
482-
return ''.join(s)
485+
t = f(i)
486+
if isinstance(t,str):
487+
t = [(Token.Literal,t)]
488+
s.extend(t)
489+
return s if toks else highlight(s)
483490

484491

485492
# ispec format parser:

amoco/arch/sparc/asm.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,18 +551,18 @@ def i_flush(ins,fmap):raise NotImplementedError
551551

552552
@__pcnpc
553553
def i_FPop1(ins,fmap):
554-
raise InstructionError
554+
raise NotImplementedError
555555
@__pcnpc
556556
def i_FPop2(ins,fmap):
557-
raise InstructionError
557+
raise NotImplementedError
558558

559559
@__pcnpc
560560
def i_CPop1(ins,fmap):
561-
raise InstructionError
561+
raise NotImplementedError
562562
@__pcnpc
563563
def i_CPop2(ins,fmap):
564-
raise InstructionError
564+
raise NotImplementedError
565565

566566
@__pcnpc
567567
def i_unimp(ins,fmap):
568-
raise InstructionError
568+
raise NotImplementedError

amoco/arch/sparc/formats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def label(i):
204204

205205
SPARC_V8_full = Formatter(SPARC_V8_full_formats)
206206

207-
def SPARC_V8_synthetic(null,i):
207+
def SPARC_V8_synthetic(null,i,toks=False):
208208
s = SPARC_V8_full(i)
209209
return SPARC_Synthetic_renaming(s, i)
210210

amoco/arch/x64/spec_ia32e.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ def ia32_strings(obj):
136136
# imm8:
137137
@ispec_ia32("16>[ {6a} ib(8) ]", mnemonic = "PUSH", type=type_data_processing)
138138
@ispec_ia32("16>[ {cd} ib(8) ]", mnemonic = "INT", type=type_control_flow)
139+
def ia32_imm8(obj,ib):
140+
obj.operands = [env.cst(ib,8)]
141+
139142
@ispec_ia32("16>[ {eb} ib(8) ]", mnemonic = "JMP", type=type_control_flow)
140143
@ispec_ia32("16>[ {e2} ib(8) ]", mnemonic = "LOOP", type=type_control_flow)
141144
@ispec_ia32("16>[ {e1} ib(8) ]", mnemonic = "LOOPE", type=type_control_flow)
@@ -285,7 +288,8 @@ def ia32_imm_rel(obj,cc,cb):
285288
def ia32_imm_rel(obj,cc,data):
286289
obj.cond = CONDITION_CODES[cc]
287290
size = obj.misc['opdsz'] or 32
288-
if size==16: raise InstructionError(obj)
291+
if size==16 or data.size<size:
292+
raise InstructionError(obj)
289293
imm = data[0:size]
290294
op1 = env.cst(imm.int(-1),size)
291295
op1.sf = True

amoco/arch/x86/cpu_x86.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
from amoco.arch.x86.formats import *
1212

13-
instruction.set_formatter(IA32_Intel)
14-
1513
from amoco.arch.x86 import spec_ia32
16-
1714
disassemble = disassembler([spec_ia32])
1815
disassemble.maxlen = 15
1916

@@ -24,7 +21,10 @@ def configure(**kargs):
2421
from amoco.config import get_module_conf
2522
conf = get_module_conf('x86')
2623
conf.update(kargs)
27-
if conf['highlight']:
28-
instruction.set_formatter(IA32_Intel_highlighted)
24+
# asm format:
25+
if conf['format'] in ('AT&T','at&t','ATT','att'):
26+
instruction.set_formatter(IA32_ATT)
27+
else:
28+
instruction.set_formatter(IA32_Intel)
2929

3030
configure()

amoco/arch/x86/env.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
eip = reg('eip',32) # instruction pointer in 32 bit mode
2222
eflags = reg('eflags',32)
2323

24+
is_reg_pc(eip)
25+
is_reg_flags(eflags)
26+
is_reg_stack(esp)
27+
2428
ax = slc(eax,0,16,'ax')
2529
bx = slc(ebx,0,16,'bx')
2630
cx = slc(ecx,0,16,'cx')
@@ -45,25 +49,27 @@
4549
af = slc(eflags,4,1,'af') # aux carry flag
4650
zf = slc(eflags,6,1,'zf') # zero flag
4751
sf = slc(eflags,7,1,'sf') # sign flag
48-
tf = slc(eflags,8,1,'sf') # trap flag
52+
tf = slc(eflags,8,1,'tf') # trap flag
4953
df = slc(eflags,10,1,'df') # direction flag
5054
of = slc(eflags,11,1,'of') # overflow flag
5155

52-
# segment registers & other mappings:
53-
cs = reg('cs',16) # segment selector for the code segment
54-
ds = reg('ds',16) # segment selector to a data segment
55-
ss = reg('ss',16) # segment selector to the stack segment
56-
es = reg('es',16) # (data)
57-
fs = reg('fs',16) # (data)
58-
gs = reg('gs',16) # (data)
56+
with is_reg_other:
57+
# segment registers & other mappings:
58+
cs = reg('cs',16) # segment selector for the code segment
59+
ds = reg('ds',16) # segment selector to a data segment
60+
ss = reg('ss',16) # segment selector to the stack segment
61+
es = reg('es',16) # (data)
62+
fs = reg('fs',16) # (data)
63+
gs = reg('gs',16) # (data)
64+
65+
mmregs = [reg('mm%d'%n,64) for n in range(8)]
66+
67+
xmmregs = [reg('xmm%d'%n, 128) for n in range(16)]
5968

6069
# fpu registers (80 bits holds double extended floats see Intel Vol1--4.4.2):
6170
def st(num):
62-
return reg('st%d'%num,80)
71+
return is_reg_other(reg('st%d'%num,80))
6372

64-
mmregs = [reg('mm%d'%n,64) for n in range(8)]
65-
66-
xmmregs = [reg('xmm%d'%n, 128) for n in range(16)]
6773

6874
# return R/M register (see ModR/M Byte encoding) :
6975
def getreg(i,size=32):
@@ -74,13 +80,12 @@ def getreg(i,size=32):
7480
128 : xmmregs[:8],
7581
}[size][i]
7682

77-
7883
# system registers:
7984

8085
# control regs:
8186
def cr(num):
82-
return reg('cr%d'%num,32)
87+
return is_reg_other(reg('cr%d'%num,32))
8388

8489
# debug regs:
8590
def dr(num):
86-
return reg('dr%d'%num,32)
91+
return is_reg_other(reg('dr%d'%num,32))

0 commit comments

Comments
 (0)