<s> '''<STR_LIT>''' <EOL> import signal <EOL> import re <EOL> from tools import * <EOL> '''<STR_LIT>''' <EOL> def isBranchAvNotNearNull ( target ) : <EOL> return isBranchAv ( target ) and not isNearNull ( faultingAddress ( target ) ) <EOL> def isReturnAv ( target ) : <EOL> rets = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> return isAccessViolationSignal ( target ) and target . current_instruction ( ) and ( target . current_instruction ( ) . mnemonic in rets ) <EOL> def isSegFaultOnPcNotNearNull ( target ) : <EOL> return isSegFaultOnPc ( target ) and not isFaNearNull ( target ) <EOL> def isErrorWhileExecutingFromStack ( target ) : <EOL> if isBenign ( target ) : <EOL> return False <EOL> map = target . procmaps ( ) . findByAddr ( target . pc ( ) ) <EOL> if map and map . name == "<STR_LIT>" : <EOL> return True <EOL> return False <EOL> def isStackBufferOverflow ( target ) : <EOL> frames = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> return isInBacktrace ( target , frames ) <EOL> def isPossibleStackCorruption ( target ) : <EOL> if isBenign ( target ) : <EOL> return False <EOL> if isStackOverflow ( target ) : <EOL> return False <EOL> bt = target . backtrace ( ) <EOL> if bt . abnormal_termination : <EOL> return True <EOL> for fr in bt [ <NUM_LIT:1> : ] : <EOL> if not fr . mapped_region : <EOL> return True <EOL> pm = target . procmaps ( ) . findByAddr ( target . stack_pointer ( ) ) <EOL> if not pm or pm . name != "<STR_LIT>" : <EOL> return True <EOL> return False <EOL> def isDestAvNotNearNull ( target ) : <EOL> return isDestAv ( target ) and not isFaNearNull ( target ) <EOL> def isHeapError ( target ) : <EOL> libc_bts = [ [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] ] <EOL> for seq in libc_bts : <EOL> if isInBacktrace ( target , seq , "<STR_LIT>" ) : <EOL> return True <EOL> return False <EOL> def isStackOverflow ( target ) : <EOL> if not isAccessViolationSignal ( target ) or not target . current_instruction ( ) : <EOL> return False <EOL> if "<STR_LIT>" not in target . current_instruction ( ) . mnemonic and not ( target . current_instruction ( ) . mnemonic == "<STR_LIT>" and faultingAddress ( target ) != target . current_instruction ( ) . dest . eval ( ) and faultingAddress ( target ) + target . pointer_size ( ) == target . stack_pointer ( ) ) : <EOL> return False <EOL> pm = target . procmaps ( ) . findByAddr ( target . stack_pointer ( ) ) <EOL> if pm and pm . name == "<STR_LIT>" : <EOL> return False <EOL> return True <EOL> def isMalformedInstructionSignal ( target ) : <EOL> siglist = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> return isSignalInList ( target , siglist ) <EOL> def isSegFaultOnPcNearNull ( target ) : <EOL> return isSegFaultOnPc ( target ) and isFaNearNull ( target ) <EOL> def isBranchAvNearNull ( target ) : <EOL> return isBranchAv ( target ) and isNearNull ( faultingAddress ( target ) ) <EOL> blk_mv_regex = re . compile ( "<STR_LIT>" ) <EOL> def isBlockMove ( target ) : <EOL> if isBenign ( target ) or not target . current_instruction ( ) : <EOL> return False <EOL> m = target . current_instruction ( ) . mnemonic <EOL> if re . match ( blk_mv_regex , m ) : <EOL> return True <EOL> return False <EOL> def isDestAvNearNull ( target ) : <EOL> return isDestAv ( target ) and isFaNearNull ( target ) <EOL> def isBenignSignal ( target ) : <EOL> siglist = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> return isSignalInList ( target , siglist ) <EOL> def isSourceAvNotNearNull ( target ) : <EOL> return isSourceAv ( target ) and not isFaNearNull ( target ) <EOL> def isFloatingPointException ( target ) : <EOL> siglist = [ "<STR_LIT>" ] <EOL> return isSignalInList ( target , siglist ) <EOL> def isSourceAvNearNull ( target ) : <EOL> return isSourceAv ( target ) and isFaNearNull ( target ) <EOL> def isAbortSignal ( target ) : <EOL> return isOnSignal ( target ) and target . si_signo ( ) == signal . SIGABRT <EOL> def isAccessViolationSignal ( target ) : <EOL> return isSignalInList ( target , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def isUncategorizedSignal ( target ) : <EOL> return not ( isAccessViolationSignal ( target ) or isAbortSignal ( target ) or isBenignSignal ( target ) or isFloatingPointException ( target ) or isMalformedInstructionSignal ( target ) ) <EOL> '''<STR_LIT>''' <EOL> def isOnSignal ( target ) : <EOL> return bool ( target . si_signo ( ) ) <EOL> def isSignalInList ( target , siglist ) : <EOL> '''<STR_LIT>''' <EOL> if not isOnSignal ( target ) : <EOL> return False <EOL> for s in siglist : <EOL> signo = getattr ( signal , s , None ) <EOL> if signo : <EOL> if signo == target . si_signo ( ) : <EOL> return True <EOL> return False <EOL> def isNearNull ( addr ) : <EOL> '''<STR_LIT>''' <EOL> if addr < <NUM_LIT:64> * <NUM_LIT> : <EOL> return True <EOL> return False <EOL> def isInBacktrace ( target , fnames , region = None ) : <EOL> i = <NUM_LIT:0> <EOL> for fr in target . backtrace ( ) : <EOL> if fr . name ( ) and fnames [ i ] == fr . name ( ) and ( not region or region in fr . mapped_region ) : <EOL> i = i + <NUM_LIT:1> <EOL> if i == len ( fnames ) : <EOL> return True <EOL> else : <EOL> i = <NUM_LIT:0> <EOL> return False <EOL> def isFaNearNull ( target ) : <EOL> return isNearNull ( faultingAddress ( target ) ) <EOL> def isBenign ( target ) : <EOL> return isOnSignal ( target ) and isBenignSignal ( target ) <EOL> def isJumpInstruction ( target ) : <EOL> jumps = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> return target . current_instruction ( ) and target . current_instruction ( ) . mnemonic in jumps <EOL> def isBranchAv ( target ) : <EOL> calls = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> if not isAccessViolationSignal ( target ) : <EOL> return False <EOL> return isJumpInstruction ( target ) or ( target . current_instruction ( ) and target . current_instruction ( ) . mnemonic in calls ) <EOL> def faultingAddress ( target ) : <EOL> if isJumpInstruction ( target ) : <EOL> return target . current_instruction ( ) . operands [ <NUM_LIT:0> ] . eval ( ) <EOL> return target . si_addr ( ) <EOL> def isSegFaultOnPc ( target ) : <EOL> return isAccessViolationSignal ( target ) and faultingAddress ( target ) == target . pc ( ) <EOL> def isDestAv ( target ) : <EOL> if not isAccessViolationSignal ( target ) : <EOL> return False <EOL> dest_op = getattr ( target . current_instruction ( ) , "<STR_LIT>" , False ) <EOL> return dest_op and dest_op . is_pointer and dest_op . eval ( ) == faultingAddress ( target ) <EOL> def isSourceAv ( target ) : <EOL> if not isAccessViolationSignal ( target ) : <EOL> return False <EOL> source_op = getattr ( target . current_instruction ( ) , "<STR_LIT:source>" , False ) <EOL> return source_op and source_op . is_pointer and source_op . eval ( ) == faultingAddress ( target ) </s>
