Esempio n. 1
0
def mkTrace(path, raw_inputs, debug = False):
    
    if debug:
      print "Loading trace.."
    
    inputs = parse_inputs(raw_inputs)
    
    #if (raw_inputs <> []):
    #  print "Using these inputs.."
    
    #  for op in Inputs:
    #    print op,"=", Inputs[op]
    if debug:
      print "Detecting callstack layout..."
    callstack = Callstack(path)#, Inputs) #TODO: it should recieve inputs also!
    
    if debug:
      print callstack
    
    allocationLog = Allocation()
    memAccess = MemAccess()
    funcParameters = FuncParameters()
    
    path_size = len(path)
    
    # we reset path iterator and callstack
    path.reset()
    callstack.reset()
    
    #print "Detecting memory accesses and function parameters.."
  
    for ins in path:
      
      counter = ins.getCounter()
      callstack.nextInstruction(ins)
      #print ins,counter
      if ins.isReadWrite():
        memAccess.detectMemAccess(path[0:counter+1], callstack, inputs, counter)
        #AllocationLog.check(MemAccess.getAccess(end), end)
        
      elif ins.isCall() and ins.called_function <> None:
        funcParameters.detectFuncParameters(path[0:counter+1], memAccess, callstack, inputs, counter)
        #if (ins.called_function == "malloc"):
          
          #try:
            #size = int(FuncParameters.getParameters(end)[0][1].name)
          #except ValueError:
            #size = None
          #AllocationLog.alloc(ins.address, end, size)
        #elif (ins.called_function == "free"):
          #ptr = (FuncParameters.getParameters(end)[0][1].mem_source)
          #AllocationLog.free(ptr, end)
    
    if debug:      
      print memAccess
      print funcParameters
      allocationLog.report()
    
    callstack.reset()
    path.reset()
    
    # trace definition
    trace = dict()
    trace["code"] = path
    trace["initial_conditions"] = inputs
    trace["final_conditions"] = dict()
    trace["callstack"] = callstack
    trace["mem_access"] = memAccess
    trace["func_parameters"] = funcParameters
    
    return trace
Esempio n. 2
0
def mkTrace(trace_filename, first, last, raw_inputs):
    
    print "Loading trace.."
    reil_code = ReilPath(trace_filename, first, last)
    
    Inputs = parse_inputs(raw_inputs)
    
    if (raw_inputs <> []):
      print "Using these inputs.."
    
      for op in Inputs:
        print op,"=", Inputs[op]
    
    print "Detecting callstack layout..."
    Callstack = CS(reil_code)#, Inputs) #TODO: it should recieve inputs also!
    
    reil_code.reset()
    
    print Callstack
    
    AllocationLog = Allocation()
    MemAccess = MemAccessREIL()
    FuncParameters = FuncParametersREIL()
    
    reil_size = len(reil_code)
    start = 0  
  
    Callstack.reset()
    
    print "Detecting memory accesses and function parameters.."
  
    for (end,ins) in enumerate(reil_code):
      
      Callstack.nextInstruction(ins)
      
      if ins.instruction in ["stm", "ldm"]:
	
        MemAccess.detectMemAccess(reil_code[start:end+1], Callstack, Inputs, end)
        AllocationLog.check(MemAccess.getAccess(end), end)
        
      elif ins.isCall() and ins.called_function <> None:
        ##print "detect parameters of", ins.called_function, "at", ins_str
        FuncParameters.detectFuncParameters(reil_code[start:end+1], MemAccess, Callstack, Inputs, end)
        if (ins.called_function == "malloc"):
          
          try:
            size = int(FuncParameters.getParameters(end)[0][1].name)
          except ValueError:
            size = None
          AllocationLog.alloc(ins.address, end, size)
        elif (ins.called_function == "free"):
          ptr = (FuncParameters.getParameters(end)[0][1].mem_source)
          AllocationLog.free(ptr, end)
    
    
    print MemAccess
    print FuncParameters
    AllocationLog.report()
    
    
    Callstack.reset()
    reil_code.reset()
    
    # trace definition
    trace = dict()
    trace["code"] = reil_code
    trace["initial_conditions"] = Inputs
    trace["final_conditions"] = dict()
    trace["callstack"] = Callstack
    trace["mem_access"] = MemAccess
    trace["func_parameters"] = FuncParameters
    
    return trace
Esempio n. 3
0
def mkTrace(path, raw_inputs, debug=False):

    if debug:
        print "Loading trace.."

    inputs = parse_inputs(raw_inputs)

    #if (raw_inputs <> []):
    #  print "Using these inputs.."

    #  for op in Inputs:
    #    print op,"=", Inputs[op]
    if debug:
        print "Detecting callstack layout..."
    callstack = Callstack(
        path)  #, Inputs) #TODO: it should recieve inputs also!

    if debug:
        print callstack

    allocationLog = Allocation()
    memAccess = MemAccess()
    funcParameters = FuncParameters()

    path_size = len(path)

    # we reset path iterator and callstack
    path.reset()
    callstack.reset()

    #print "Detecting memory accesses and function parameters.."

    for ins in path:

        counter = ins.getCounter()
        callstack.nextInstruction(ins)
        #print ins,counter
        if ins.isReadWrite():
            memAccess.detectMemAccess(path[0:counter + 1], callstack, inputs,
                                      counter)
            #AllocationLog.check(MemAccess.getAccess(end), end)

        elif ins.isCall() and ins.called_function <> None:
            funcParameters.detectFuncParameters(path[0:counter + 1], memAccess,
                                                callstack, inputs, counter)
            #if (ins.called_function == "malloc"):

            #try:
            #size = int(FuncParameters.getParameters(end)[0][1].name)
            #except ValueError:
            #size = None
            #AllocationLog.alloc(ins.address, end, size)
            #elif (ins.called_function == "free"):
            #ptr = (FuncParameters.getParameters(end)[0][1].mem_source)
            #AllocationLog.free(ptr, end)

    if debug:
        print memAccess
        print funcParameters
        allocationLog.report()

    callstack.reset()
    path.reset()

    # trace definition
    trace = dict()
    trace["code"] = path
    trace["initial_conditions"] = inputs
    trace["final_conditions"] = dict()
    trace["callstack"] = callstack
    trace["mem_access"] = memAccess
    trace["func_parameters"] = funcParameters

    return trace