@@ -54,14 +54,14 @@ def test_dummy(self):
5454 self .fail ("dummy" )
5555
5656class InstBin (Test ):
57- def __init__ (self , bin , mode , features ):
57+ def __init__ (self , bin , mode , features , address ):
5858 Test .__init__ (self )
5959 try :
6060 bin = bin .decode ("hex" )
6161 except :
6262 bin = bytes .fromhex (bin )
6363 #fbin[mode].write(bin)
64- self .insts = distorm3 .Decompose (0 , bin , mode , features )
64+ self .insts = distorm3 .Decompose (address , bin , mode , features )
6565 self .inst = self .insts [0 ]
6666 def check_valid (self , instsNo = 1 ):
6767 self .assertNotEqual (self .inst .rawFlags , 65535 )
@@ -141,14 +141,14 @@ def I16(instText, instNo = 0, features = 0):
141141def I32 (instText , features = 0 ):
142142 return Inst (instText , distorm3 .Decode32Bits , 0 , features )
143143
144- def IB32 (bin , features = 0 ):
145- return InstBin (bin , distorm3 .Decode32Bits , features )
144+ def IB32 (bin , features = 0 , address = 0 ):
145+ return InstBin (bin , distorm3 .Decode32Bits , features , address )
146146
147147def I64 (instText , features = 0 ):
148148 return Inst (instText , distorm3 .Decode64Bits , 0 , features )
149149
150- def IB64 (bin , features = 0 ):
151- return InstBin (bin , distorm3 .Decode64Bits , features )
150+ def IB64 (bin , features = 0 , address = 0 ):
151+ return InstBin (bin , distorm3 .Decode64Bits , features , address )
152152
153153def ABS64 (x ):
154154 return x
@@ -1607,6 +1607,19 @@ def test_drop_prefixes(self):
16071607 def test_zzz_must_be_last_drop_prefixes (self ):
16081608 # Drop prefixes when the last byte in stream is a prefix.
16091609 IB32 ("66" )
1610+ def test_undefined_byte00 (self ):
1611+ # This is a regression test for the decomposer wrapper
1612+ a = ""
1613+ insts = IB32 ("c300" ).insts
1614+ for i in insts :
1615+ a += str (i )
1616+ insts = IB32 ("33c0" * 2000 + "90" , 0 , 0x4000 ).insts
1617+ self .assertEqual (insts [- 1 ].mnemonic , "NOP" )
1618+ self .assertEqual (insts [- 1 ].instructionBytes , b"\x90 " )
1619+ self .assertEqual (insts [- 1 ].address , 0x4000 + 2000 * 2 )
1620+ self .assertEqual (insts [1000 ].mnemonic , "XOR" )
1621+ self .assertEqual (insts [1000 ].instructionBytes , b"\x33 \xc0 " )
1622+ self .assertEqual (insts [1000 ].address , 0x4000 + 1000 * 2 )
16101623
16111624class TestFeatures (unittest .TestCase ):
16121625 def test_addr16 (self ):
@@ -1637,7 +1650,14 @@ def test_fc(self):
16371650 a = I32 ("nop\n xor eax, eax\n " + j + "\n inc eax" , distorm3 .DF_RETURN_FC_ONLY | distorm3 .DF_STOP_ON_FLOW_CONTROL )
16381651 self .assertEqual (len (a .insts ), 1 )
16391652 def test_filter (self ):
1640- pass
1653+ a = IB32 ("33c0907e00" * 5 , distorm3 .DF_RETURN_FC_ONLY ).insts
1654+ self .assertEqual (len (a ), 5 )
1655+ self .assertEqual (a [0 ].mnemonic [0 ], "J" )
1656+ self .assertEqual (a [0 ].address , 3 )
1657+ self .assertEqual (a [1 ].address , 8 )
1658+ self .assertEqual (a [2 ].address , 13 )
1659+ self .assertEqual (a [3 ].address , 18 )
1660+ self .assertEqual (a [4 ].address , 23 )
16411661 def test_stop_on_privileged (self ):
16421662 a = I32 ("nop\n iret\n ret" , distorm3 .DF_STOP_ON_PRIVILEGED )
16431663 self .assertEqual (len (a .insts ), 2 )
@@ -1663,6 +1683,34 @@ def test_step_byte(self):
16631683 self .assertEqual (a [5 ].address , 5 )
16641684 self .assertEqual (a [5 ].mnemonic , "DEC" )
16651685 self .assertEqual (a [5 ].size , 1 )
1686+ def test_eflags_on (self ):
1687+ a = IB32 ("33c04890" , distorm3 .DF_FILL_EFLAGS ).insts
1688+ # XOR
1689+ self .assertEqual (a [0 ].modifiedFlags , distorm3 .D_SF | distorm3 .D_ZF | distorm3 .D_PF )
1690+ self .assertEqual (a [0 ].testedFlags , 0 )
1691+ self .assertEqual (a [0 ].undefinedFlags , distorm3 .D_AF )
1692+ # INC
1693+ self .assertEqual (a [1 ].modifiedFlags , distorm3 .D_OF | distorm3 .D_SF | distorm3 .D_ZF | distorm3 .D_AF | distorm3 .D_PF )
1694+ self .assertEqual (a [1 ].testedFlags , 0 )
1695+ self .assertEqual (a [1 ].undefinedFlags , 0 )
1696+ # NOP
1697+ self .assertEqual (a [2 ].modifiedFlags , 0 )
1698+ self .assertEqual (a [2 ].testedFlags , 0 )
1699+ self .assertEqual (a [2 ].undefinedFlags , 0 )
1700+ def test_eflags_off (self ):
1701+ a = IB32 ("33c04890" ).insts
1702+ # XOR
1703+ self .assertEqual (a [0 ].modifiedFlags , 0 )
1704+ self .assertEqual (a [0 ].testedFlags , 0 )
1705+ self .assertEqual (a [0 ].undefinedFlags , 0 )
1706+ # INC
1707+ self .assertEqual (a [1 ].modifiedFlags , 0 )
1708+ self .assertEqual (a [1 ].testedFlags , 0 )
1709+ self .assertEqual (a [1 ].undefinedFlags , 0 )
1710+ # NOP
1711+ self .assertEqual (a [2 ].modifiedFlags , 0 )
1712+ self .assertEqual (a [2 ].testedFlags , 0 )
1713+ self .assertEqual (a [2 ].undefinedFlags , 0 )
16661714
16671715def GetNewSuite (className ):
16681716 suite = unittest .TestSuite ()
0 commit comments