gdabah / distorm

Powerful Disassembler Library For x86/AMD64
Other
1.26k stars 238 forks source link

python -- register mask enumeration #158

Closed sfinktah closed 3 years ago

sfinktah commented 3 years ago

If you liked my last PR, you may want this as well. It just adds the pretty names in a list named 'registers'.

'registers': ['RM_AX', 'RM_CX'],

Python>pp(de()[0].__dict__)
{   'address': 5381649640L,
    'dt': 2,
    'flags': ['FLAG_DST_WR'],
    'flowControl': 'FC_NONE',
    'instructionBytes': '\x8bA\x10',
    'instructionClass': 'ISC_INTEGER',
    'isSegmentDefault': False,
    'meta': 256,
    'mnemonic': 'MOV',
    'modifiedFlags': 0,
    'opcode': 218,
    'operands': [   <distorm3c.Operand object at 0x00000293DE8EFC50>,
                    <distorm3c.Operand object at 0x00000293E06E5F98>],
    'privileged': False,
    'rawFlags': 2368,
    'registers': ['RM_AX', 'RM_CX'],
    'segment': 255,
    'size': 3,
    'testedFlags': 0,
    'undefinedFlags': 0,
    'unusedPrefixesMask': 0,
    'usedRegistersMask': 3L,
    'valid': True}
gdabah commented 3 years ago

I've added my own algo, it walks the actual mask and not the whole reigster masks every time:

calculate register masks

    self.registers = []
    maskIndex = 1
    v = self.usedRegistersMask
    while (v):
        if (v & maskIndex):
            self.registers.append(RegisterMasks[maskIndex])
            v ^= maskIndex
        maskIndex <<= 1