示例#1
0
 def validateArgs(self):
     '''Validate all arguments given by the user, and tests them.'''
     errors = []
     i = 0
     for param in self.code.getParams():
         if param.defaultvalue == None and not isinstance(self.args[i], ASTNode):
             try:
                 ParamType.rewrite(param.ptype,  self.args[i])
             except:
                 errors.append("Value error: 0x%s (argument %d)"%(self.args[i], i))
             i += 1
     return errors
示例#2
0
 def validateArgs(self):
     '''Validate all arguments given by the user, and tests them.'''
     errors = []
     i = 0
     for param in self.code.getParams():
         if param.defaultvalue == None and not isinstance(
                 self.args[i], ASTNode):
             try:
                 ParamType.rewrite(param.ptype, self.args[i])
             except:
                 errors.append("Value error: 0x%s (argument %d)" %
                               (self.args[i], i))
             i += 1
     return errors
示例#3
0
 def _prepargs(self, command, args):
     #Rewrite references to AST Reference nodes
     rawargs = []
     i_args = 0
     for i in range(0, len(command.params)):
         commandparam = command.getParam(i)
         #print(repr(commandparam))
         if commandparam.defaultvalue == None:
             #print(" -> consume! "+repr(args[i_args]))
             if ParamType.ispointer(commandparam.ptype):
                 rawargs.append(ast.ASTRef(args[i_args]))
             elif commandparam.definevaluestype != None:
                 defines = self.langdef.getDefines(commandparam.definevaluestype)
                 #Reversed defines lookup, not as elegant as I hoped it
                 key = args[i_args].upper()
                 val = None
                 try:
                     #If defines is a list:
                     try:
                         val = defines.index(key)
                     except:
                         val = next((dval for dval, dkey in defines.items() if dkey == key))
                     rawargs.append(ast.ASTDefinedValue(key, val))
                 except:
                     #There is no define for the value, parse it as is
                     # but then ofc. it should be an int.
                     try:
                         rawargs.append(toint(args[i_args]))
                     except:
                         raise Exception("%s is not defined, and could not be converted to an integer!"%args[i_args])
             else:
                 rawargs.append(toint(args[i_args]))
             i_args += 1
     return rawargs
示例#4
0
    def parsecommandargs(self, command, argbytes):
        '''
        Rewrites the command to a AST Node with proper arguments set.
        
        The argbytes contains a BYTE-array of all values. These are read
        from it and appended to the command.
        '''
        print(">>> ", argbytes)
        args = []

        p = 0
        for param in command.params:
            paramtype = param.ptype

            if param.defaultvalue == None and paramtype != ParamType.eos:
                if paramtype == ParamType.byte:
                    value = argbytes[p]
                    p += 1

                elif paramtype == ParamType.word:
                    value = struct.unpack("<H", argbytes[p:p + 2])[0]
                    p += 2

                elif ParamType.ispointer(paramtype):
                    pointer = struct.unpack("<I", argbytes[p:p + 4])[0]
                    if pointer > 0x08000000:
                        pointer -= 0x08000000
                    value = ASTPointerRef(
                        pointer,
                        _ptype_to_decompiletype(paramtype))  #TODO paramtype,
                    p += 4

                elif paramtype == ParamType.int:
                    value = struct.unpack("<I", argbytes[p:p + 4])[0]
                    p += 4

                else:
                    print("Unknown ParamType: " + repr(paramtype))

                #Chech wheter it is possible to update the value to a nice string representation
                if param.definevaluestype != None:
                    defines = self.langdef.getDefines(param.definevaluestype)
                    try:
                        value = ASTDefinedValue(defines[value], value)
                    except:
                        pass
                args.append(value)

        return ASTCommand(command, args), {}  #TODO: Remove last arg
    def parsecommandargs(self, command, argbytes):
        '''
        Rewrites the command to a AST Node with proper arguments set.
        
        The argbytes contains a BYTE-array of all values. These are read
        from it and appended to the command.
        '''
        print(">>> ", argbytes)
        args = []
        
        p = 0
        for param in command.params:
            paramtype = param.ptype

            if param.defaultvalue == None and paramtype != ParamType.eos:
                if paramtype == ParamType.byte:
                    value = argbytes[p]
                    p+=1
          
                elif paramtype == ParamType.word:
                    value = struct.unpack("<H", argbytes[p:p+2])[0]
                    p+=2
          
                elif ParamType.ispointer(paramtype):
                    pointer = struct.unpack("<I", argbytes[p:p+4])[0]
                    if pointer > 0x08000000:
                        pointer -= 0x08000000
                    value = ASTPointerRef(pointer, _ptype_to_decompiletype(paramtype))  #TODO paramtype,
                    p += 4
            
                elif paramtype == ParamType.int:
                    value = struct.unpack("<I", argbytes[p:p+4])[0]
                    p += 4
                    
                else:
                    print("Unknown ParamType: "+repr(paramtype))
   
                #Chech wheter it is possible to update the value to a nice string representation
                if param.definevaluestype != None:
                    defines = self.langdef.getDefines(param.definevaluestype)
                    try:
                        value = ASTDefinedValue(defines[value], value)
                    except:
                        pass
                args.append(value)
                
      
        return ASTCommand(command, args), {} #TODO: Remove last arg