Exemple #1
0
def magicbyte(insn):
    p,o,m,s,d,i = insn
    mod,reg,rm = decoder.extractmodrm(m)

    if reg == 6:
        return [4,2][b'\x66' in p]
    return 0
Exemple #2
0
def magicbyte(insn):
    p,o,m,s,d,i = insn
    mod,reg,rm = decoder.extractmodrm(m)

    if reg == 6:
        return [4,2]['\x66' in p]
    return 0
Exemple #3
0
def isFarJmp(instruction):
    opcode = getOpcode(instruction)
    if opcode == '\xff':
        modrm = getModrm(instruction)
        mod, reg, rm = decoder.extractmodrm(ord(modrm))
        return reg == 5
    return False
Exemple #4
0
def decode(instruction):
    '''Extract the modrm tuple out of the provided instruction'''
    modrm = instruction[2]
    if len(modrm) > 0:
        modrm = decoder.decodeInteger(modrm)
        return decoder.extractmodrm(modrm)
    return None
Exemple #5
0
def isRegisterCall(instruction):
    '''call Ev'''
    if getOpcode(instruction) == '\xff':
        modrm = getModrm(instruction)
        mod,reg,rm = decoder.extractmodrm(ord(modrm))
        return reg == 2 and mod == 3
    return False
Exemple #6
0
def isFarJmp(instruction):
    opcode = getOpcode(instruction)
    if opcode == '\xff':
        modrm = getModrm(instruction)
        mod,reg,rm = decoder.extractmodrm(ord(modrm))
        return reg == 5
    return False
Exemple #7
0
def isMemoryCall(instruction):
    '''call Mp'''
    if getOpcode(instruction) == '\xff':
        modrm = getModrm(instruction)
        mod,reg,rm = decoder.extractmodrm(ord(modrm))
        return reg in [2,3] and mod < 3
    return False
Exemple #8
0
def isJmpFF(instruction):
    opcode = getOpcode(instruction)
    if opcode == '\xff':
        modrm = getModrm(instruction)
        mod,reg,rm = decoder.extractmodrm(ord(modrm))
        return reg in [4,5]
    return False
Exemple #9
0
def isMemoryCall(instruction):
    '''call Mp'''
    if getOpcode(instruction) == '\xff':
        modrm = getModrm(instruction)
        mod, reg, rm = decoder.extractmodrm(ord(modrm))
        return reg in [2, 3] and mod < 3
    return False
Exemple #10
0
def decode(instruction):
    '''Extract the modrm tuple out of the provided instruction'''
    modrm = instruction[2]
    if len(modrm) > 0:
        modrm = decoder.decodeInteger(modrm)
        return decoder.extractmodrm(modrm)
    return None
Exemple #11
0
def isRegisterCall(instruction):
    '''call Ev'''
    if getOpcode(instruction) == '\xff':
        modrm = getModrm(instruction)
        mod, reg, rm = decoder.extractmodrm(ord(modrm))
        return reg == 2 and mod == 3
    return False
Exemple #12
0
def isJmpFF(instruction):
    opcode = getOpcode(instruction)
    if opcode == '\xff':
        modrm = getModrm(instruction)
        mod, reg, rm = decoder.extractmodrm(ord(modrm))
        return reg in [4, 5]
    return False
Exemple #13
0
def isDispBranch(instruction):
    if isJmpFF(instruction):
        modrm = getModrm(instruction)
        mod,reg,rm = decoder.extractmodrm(ord(modrm))
        return rm == 5 and mod in [1,2]
    return False
Exemple #14
0
def isMemoryBranch(instruction):
    if isJmpFF(instruction):
        modrm = getModrm(instruction)
        mod,reg,rm = decoder.extractmodrm(ord(modrm))
        return mod < 3
    return False
Exemple #15
0
def isRegisterBranch(instruction):
    if isJmpFF(instruction):
        modrm = getModrm(instruction)
        mod,reg,rm = decoder.extractmodrm(ord(modrm))
        return mod == 3
    return False
Exemple #16
0
def extractmodrm(instruction):
    '''Return the (Mod, Reg, r/m) components of an instruction'''
    modrm = getModrm(instruction)
    return decoder.extractmodrm( decodeInteger(modrm) )
Exemple #17
0
def isMemoryBranch(instruction):
    if isJmpFF(instruction):
        modrm = getModrm(instruction)
        mod, reg, rm = decoder.extractmodrm(ord(modrm))
        return mod < 3
    return False
Exemple #18
0
def isSibBranch(instruction):
    if isJmpFF(instruction):
        modrm = getModrm(instruction)
        mod, reg, rm = decoder.extractmodrm(ord(modrm))
        return rm == 4 and mod < 3
    return False
Exemple #19
0
def isDispBranch(instruction):
    if isJmpFF(instruction):
        modrm = getModrm(instruction)
        mod, reg, rm = decoder.extractmodrm(ord(modrm))
        return rm == 5 and mod in [1, 2]
    return False
Exemple #20
0
def isSibBranch(instruction):
    if isJmpFF(instruction):
        modrm = getModrm(instruction)
        mod,reg,rm = decoder.extractmodrm(ord(modrm))
        return rm == 4 and mod < 3
    return False
Exemple #21
0
    if True:
        code = 'C7 05 6C B0 88 30 A0 BC 88 30'
        code = [chr(int(x, 16)) for x in code.split(' ')]
        source = iter(code)

        insn = decoder.consume(source)
        checkinsn()

    if False:
        code = b'\x6b\xc0\x2c'
        lookup = optable.Lookup(b'\x6b')
        #        print(optable.HasModrm(lookup),optable.HasImmediate(lookup))

        modrm = b'\xc0'
        mod, reg, rm = decoder.extractmodrm(ord(modrm))
#        print(mod,reg,rm)

    if True:
        list = ['f7 d8', '1a c0', '68 80 00 00 00']
        checklist()

    if True:
        code = 'F7 C1 00 01 00 00'
        code = [chr(int(x, 16)) for x in code.split(' ')]
        source = iter(code)

        insn = decoder.consume(source)
        checkinsn()

    if True:
Exemple #22
0
def isRegisterBranch(instruction):
    if isJmpFF(instruction):
        modrm = getModrm(instruction)
        mod, reg, rm = decoder.extractmodrm(ord(modrm))
        return mod == 3
    return False
Exemple #23
0
    if True:
        code = 'C7 05 6C B0 88 30 A0 BC 88 30'
        code = [ chr(int(x,16)) for x in code.split(' ') ]
        source = iter(code)

        insn = decoder.consume(source)
        checkinsn()

    if False:
        code = '\x6b\xc0\x2c'
        lookup = optable.Lookup('\x6b')
#        print optable.HasModrm(lookup),optable.HasImmediate(lookup)

        modrm = '\xc0'
        mod,reg,rm = decoder.extractmodrm(ord(modrm))
#        print mod,reg,rm    

    if True:
        list = ['f7 d8', '1a c0', '68 80 00 00 00']
        checklist()

    if True:
        code = 'F7 C1 00 01 00 00'
        code = [ chr(int(x,16)) for x in code.split(' ') ]
        source = iter(code)

        insn = decoder.consume(source)
        checkinsn()

    if True:
Exemple #24
0
def extractmodrm(instruction):
    '''Return the (Mod, Reg, r/m) components of an instruction'''
    modrm = getModrm(instruction)
    return decoder.extractmodrm(decodeInteger(modrm))