def getDeviceName():
"""
Get Device Name from a driver.
@rtype: void
@returns: void
"""
ea = 0
while True:
ea = FindText(ea, SEARCH_NEXT | SEARCH_REGEX, 0, 0, "\\\\Device\\\\")
string = GetString(ea, -1, ASCSTR_UNICODE)
if string is None:
continue
else:
#Message("Find in %x\n" % ea)
Message("device is %s\n" % string)
break
def getFunctionInstructions():
"""
Get All Instructions from a function.
Here,Just Get All Instructions Offset,and store them in list
@rtype: List
@returns: List of All Instructions
"""
Instructions = []
DispatchBeginAddress = getDispatchAddress()
if DispatchBeginAddress == BADADDR:
Message("Cann't find the Function Instructions List")
return None
DispatchEndAddress = GetFunctionAttr(DispatchBeginAddress,FUNCATTR_END)
i = DispatchBeginAddress
while True:
#Instructions.append(GetDisasm(i))
Instructions.append(i)
tmp = i + ItemSize(i)
if tmp < DispatchEndAddress:
i = i + ItemSize(i)
else:
break
address = i
return Instructions
def getIoctlCode():
"""
Get All IoctlCodes from a driver.
@rtype: List
@returns: List of All IoctlCodes
"""
isConditionalJmp = False
isFirst = True
BaseRegister = None
OperRegister = None
IoctlCode = []
DispatchFunctionInstructions = []
DispatchFunctionInstructions = getFunctionInstructions()[::-1]
if DispatchFunctionInstructions == None:
Message("Cann't get the IoctlCodes")
return
for i in DispatchFunctionInstructions:
#Message("The instrucion of this function is %x\n" % i)
mnem = GetMnem(i)
if "jz" in mnem or "je" in mnem:
isConditionalJmp = True
continue
if "cmp" in mnem and isConditionalJmp and isFirst:
sisConditionalJmp = False
BaseRegister = GetOpnd(i,0)
IoctlCode.append(GetOperandValue(i,1))
isFirst = False
continue
if "cmp" in mnem and isConditionalJmp and not isFirst:
isConditionalJmp = False
OperRegister = GetOpnd(i,0)
if OperRegister == BaseRegister:
IoctlCode.append(GetOperandValue(i,1))
for i in IoctlCode:
Message("The ioctlcode of this driver is %x\n" % i)