示例#1
0
文件: engine.cpp 项目: Eltamih/uvudec
uv_err_t UVDPluginEngine::getAllPluginDependencies(const std::string &name, std::vector<UVDPlugin *> &out)
{
	std::set<UVDPlugin *> dependencies;	
	UVDPlugin::PluginDependencies pluginDependencies;
	UVDPlugin *plugin = NULL;
	
	if( m_plugins.find(name) == m_plugins.end() )
	{
		printf_error("no plugin named %s\n", name.c_str());
		return UV_DEBUG(UV_ERR_GENERAL);
	}
	
	plugin = m_plugins[name];
	uv_assert_err_ret(plugin->getDependencies(pluginDependencies));

	//FIXME: single pass for now...
	out.clear();
	for( std::map<std::string, UVDVersionRange>::iterator iter = pluginDependencies.begin();
			iter != pluginDependencies.end(); ++iter )
	{
		std::string dependentPluginName = (*iter).first;
		UVDPlugin *dependentPlugin = m_plugins[dependentPluginName];

		//No circular refs
		if( dependencies.find(dependentPlugin) != dependencies.end() )
		{
			printf_error("circular plugin dependency on %s / %s\n", dependentPluginName.c_str(), name.c_str());
			return UV_DEBUG(UV_ERR_GENERAL);
		}
		out.insert(out.begin(), dependentPlugin);
		dependencies.insert(dependentPlugin);
	}

	return UV_ERR_OK;
}
示例#2
0
文件: engine.cpp 项目: Eltamih/uvudec
uv_err_t UVDPluginEngine::activatePluginByName(const std::string &name)
{
	std::map<std::string, UVDPlugin *>::iterator iter = m_plugins.find(name);
	UVDPlugin *plugin = NULL;

	printf_plugin_debug("initializing plugin %s\n", name.c_str());
	if( iter == m_plugins.end() )
	{
		printf_error("no plugin loaded named %s\n", name.c_str());
		return UV_DEBUG(UV_ERR_GENERAL);
	}
	if( m_loadedPlugins.find(name) != m_loadedPlugins.end() )
	{
		printf_warn("skipping double load of plugin %s\n", name.c_str());
		return UV_DEBUG(UV_ERR_WARNING);
	}
	plugin = (*iter).second;
	uv_assert_ret(plugin);
	
	/*
	Initialize dependencies
	TODO: check for circular refs
	*/
	std::vector<UVDPlugin *> dependencies;
	uv_assert_err_ret(getAllPluginDependencies(name, dependencies));

	//std::string pluginName;
	for( std::vector<UVDPlugin *>::iterator iter = dependencies.begin();
			iter != dependencies.end(); ++iter )
	{
		//std::string dependentPluginName = *iter;
		UVDPlugin *dependentPlugin = *iter;
		
		uv_assert_err_ret(ensurePluginActiveByName(dependentPlugin->getName()));
	}
	
	uv_assert_err_ret(plugin->init(g_config));
	m_loadedPlugins[name] = plugin;
	
	//Notify callbacks
	for( std::set<OnPluginActivatedItem>::iterator iter = m_onPluginActivated.begin();
			iter != m_onPluginActivated.end(); ++iter )
	{
		OnPluginActivated callback = (*iter).first;
		void *user = (*iter).second;
	
		if( !callback )
		{
			printf_error("bad callback\n");
			continue;
		}
		//Ready to roll
		UV_DEBUG(callback(plugin, user));
	}
	
	return UV_ERR_OK;
}
示例#3
0
文件: config.cpp 项目: Eltamih/uvudec
static uv_err_t argParser(const UVDArgConfig *argConfig, std::vector<std::string> argumentArguments, void *user)
{
	UVDConfig *config = NULL;
	//If present
	std::string firstArg;
	uint32_t firstArgNum = 0;
	
	config = g_config;
	uv_assert_ret(config);
	uv_assert_ret(config->m_argv);

	uv_assert_ret(argConfig);

	if( !argumentArguments.empty() )
	{
		firstArg = argumentArguments[0];
		firstArgNum = strtol(firstArg.c_str(), NULL, 0);
	}

	if( argConfig->m_propertyForm == UVDBFD_ARCHITECTURE_HINT )
	{
		uv_assert_ret(!argumentArguments.empty());
		g_bfdConfig->m_architecture = firstArg;
	}
	else
	{
		printf_error("Property not recognized in callback: %s\n", argConfig->m_propertyForm.c_str());
		return UV_DEBUG(UV_ERR_GENERAL);
	}

	return UV_ERR_OK;
}
示例#4
0
文件: ringbuf.c 项目: semenovf/cwt
/**
 * Write bytes from file into ring buffer
 *
 * @param rb the ring buffer
 * @param fd file descriptor
 * @param n max bytes to write
 * @return bytes written into the ring buffer, or -1 if error
 */
ssize_t rb_write_from_file(CwtRingBuffer* rb, int fd, size_t n)
{
	BYTE ibuf[256];
	size_t total_br = 0;
	CwtUnistdNS *ns = cwt_unistd_ns();

	if( fd < 0 ) {
		print_error(_Tr("invalid file descriptor"));
		return 0;
	}

	while( total_br < n ) {
		/* TODO fix unsigned int cast */
		ssize_t br = ns->read(fd, ibuf, (UINT)(n - total_br));

		if( br == 0 ) /* end of file */
			break;

		if( br < 0 ) {
			printf_error(_Tr("read file error: %s"), strerror(errno));
			return (ssize_t)-1;
		}

		total_br += br;

		if( !rb_push_back(rb, ibuf, br) ) {
			return (ssize_t)-1;
		}
	}

	return (ssize_t)total_br;
}
示例#5
0
uv_err_t UVDConfigExpressionInterpreter::getConfigExpressionInterpreter(UVDConfigExpressionInterpreter **interpreter_in)
{
	UVDConfigExpressionInterpreter *interpreter = NULL;
	//Select the embedded interpreter we are going to use
	int selectedInterpreter = 0;
	int selectedInterpreterInterface = 0;
	
	uv_assert_ret(g_asmConfig);
	selectedInterpreter = g_asmConfig->m_configInterpreterLanguage;
	selectedInterpreterInterface = g_asmConfig->m_configInterpreterLanguageInterface;
	switch( selectedInterpreter )
	{
#ifdef USING_PYTHON
	case UVD_LANGUAGE_PYTHON:
		switch( selectedInterpreterInterface )
		{
#ifdef USING_PYTHON_API
		case UVD_LANGUAGE_INTERFACE_API:
			printf_debug_level(UVD_DEBUG_SUMMARY, "Chose python API interpreter\n");
			interpreter = new UVDPythonConfigExpressionAPIInterpreter();
			break;
#endif //USING_PYTHON_API
#ifdef USING_PYTHON_EXEC
		case UVD_LANGUAGE_INTERFACE_EXEC:
			printf_debug_level(UVD_DEBUG_SUMMARY, "Chose python exec interpreter\n");
			interpreter = new UVDPythonConfigExpressionExecInterpreter();
			break;
#endif //USING_PYTHON_EXEC
		default:
			printf_error("Unknown python interpreter interface\n");
			return UV_DEBUG(UV_ERR_GENERAL);
		}
		break;
#endif //USING_PYTHON
#ifdef USING_LUA
	case UVD_LANGUAGE_LUA:
		printf_debug_level(UVD_DEBUG_SUMMARY, "Chose Lua interpreter\n");
		interpreter = new UVDLuaConfigExpressionInterpreter();
		break;
#endif //USING_LUA
#ifdef USING_JAVASCRIPT
	case UVD_LANGUAGE_JAVASCRIPT:
		printf_debug_level(UVD_DEBUG_SUMMARY, "Chose JavaScript interpreter\n");
		interpreter = new UVDJavascriptConfigExpressionInterpreter();
		break;
#endif //USING_JAVASCRIPT
	default:
		printf("Invalid config interpreter: 0x%.8X\n", selectedInterpreter);
		return UV_DEBUG(UV_ERR_GENERAL);
	}
	
	uv_assert_ret(interpreter);
	uv_assert_err_ret(interpreter->init());
	uv_assert_ret(interpreter->m_interpreter);
	
	uv_assert_ret(interpreter_in);
	*interpreter_in = interpreter;
	
	return UV_ERR_OK;
}
示例#6
0
文件: cpap.c 项目: hawkhsieh/sigbox
int isErrorCode( uint8_t test_byte )
{

    if (( test_byte & 0xf0 ) == 0xe0 )
    {
        printf_error( "error code is 0x%x\n" , test_byte );
        return 1;
    }
    return 0;
}
示例#7
0
t_pl_func	AI_PI(char **cmd, double *delay)
{
  char		*args;
  int		cmd_id;

  printf_debug("Parsing command: %s", *cmd);
  if ((cmd_id = get_cmd_id(*cmd)) == -1)
    {
      printf_error("%s: command not found", *cmd);
      return (NULL);
    }
  args = *cmd + strlen(g_cmds[cmd_id].name);
  while (*args != '\0' && (*args == ' ' || *args == '\t' || *args == '\n'))
    ++args;
  if ((*args != '\0' && *args != '\n') != (g_cmds[cmd_id].hasArg))
    {
      printf_error("%s: invalid arguments", *cmd);
      return (NULL);
    }
  *cmd = (*args != '\0' ? args : NULL);
  *delay = g_cmds[cmd_id].delay;
  return (g_cmds[cmd_id].fn);
}
示例#8
0
文件: cpap.c 项目: hawkhsieh/sigbox
static void tryToOpenCPAP( void )
{
    if ( cpap_global.dont_reopen == 0 )
    {
        int retry;
        for( retry=10 ; retry>0 ; retry-- )
        {
            printf_error( "try to reopen uart %d\n", retry );
            cpap_global.uart_fd = openCPAPDevice();
            if ( cpap_global.uart_fd > 0 )
                break;
            sleep(1);
        }
    }
}
示例#9
0
文件: engine.cpp 项目: Eltamih/uvudec
uv_err_t UVDPluginEngine::ensurePluginActiveByName(const std::string &name)
{
	if( m_plugins.find(name) == m_plugins.end() )
	{
		printf_error("no plugin loaded named %s\n", name.c_str());
		return UV_DEBUG(UV_ERR_GENERAL);
	}

	if( m_loadedPlugins.find(name) != m_loadedPlugins.end() )
	{
		printf_plugin_debug("skpping activated loaded plugin %s\n", name.c_str());
		return UV_ERR_OK;
	}
	
	return UV_DEBUG(activatePluginByName(name));
}
示例#10
0
文件: main.cpp 项目: Eltamih/uvudec
int main(int argc, char **argv)
{
	printf_debug("main: enter\n");

	//Simple translation to keep most stuff in the framework
	uv_err_t rc = uvmain(argc, argv);
	printf_debug("main: exit\n");
	if( UV_FAILED(rc) )
	{
		printf_error("failed\n");
		return 1;
	}
	else
	{
		return 0;
	}
}
示例#11
0
文件: engine.cpp 项目: Eltamih/uvudec
uv_err_t UVDPluginEngine::deactivatePluginByName(const std::string &name)
{
	std::map<std::string, UVDPlugin *>::iterator iter = m_loadedPlugins.find(name);
	UVDPlugin *plugin = NULL;

	uv_assert_ret(iter != m_loadedPlugins.end());
	plugin = (*iter).second;
	uv_assert_ret(plugin);
	if( UV_FAILED(plugin->deinit(g_config)) )
	{
		printf_error("failed to cleanly unload plugin %s\n", name.c_str());
		return UV_DEBUG(UV_ERR_GENERAL);
	}
	
	m_loadedPlugins.erase(iter);
	
	return UV_ERR_OK;
}
示例#12
0
文件: object.cpp 项目: Eltamih/uvudec
uv_err_t UVDBFDObject::init(UVDData *data)
{
	std::string file;
	UVDDataFile *dataFile = NULL;
	uv_err_t rc = UV_ERR_GENERAL;

	uv_assert_ret(data);
	if( typeid(*data) != typeid(UVDDataFile) )
	{
		return UV_DEBUG(UV_ERR_NOTSUPPORTED);
	}

	uv_assert_err(UVDObject::init(data));

	dataFile = (UVDDataFile *)data;
	file = dataFile->m_sFile;

	//FIXME: make default bfd architecture a command line option
	m_bfd = bfd_openr(file.c_str(), "default");
	if( m_bfd == NULL )
	{
		printf_error("Could not open file <%s>\n", file.c_str());
		rc = UV_DEBUG(UV_ERR_GENERAL);
		goto error;
	}

	//Needs to be an object or an archive
	if( !bfd_check_format(m_bfd, bfd_object)
			&& !bfd_check_format(m_bfd, bfd_archive) )
	{
		bfd_close(m_bfd);
		rc = UV_DEBUG(UV_ERR_NOTSUPPORTED);
		goto error;
	}
	
	//TODO: we should build the section table
	uv_assert_err(rebuildSections());

	return UV_ERR_OK;

error:
	m_data = NULL;
	return UV_DEBUG(rc);
}
示例#13
0
文件: init.cpp 项目: Eltamih/uvudec
/*
file: data file to target
architecture: hint about what we are trying to disassemble
*/
uv_err_t UVD::initFromFileName(const std::string &file, const UVDRuntimeHints &hints)
{
	uv_err_t rcTemp = UV_ERR_GENERAL;
	UVDData *data = NULL;
	
	uv_assert_err_ret(initEarly());
		
	rcTemp = UVDDataFile::getUVDDataFile(&data, file);
	if( UV_FAILED(rcTemp) || !data )
	{
		printf_error("could not open file: %s\n", file.c_str());
		return UV_DEBUG(UV_ERR_GENERAL);
	}
	uv_assert_err(initFromData(data, hints));
	return UV_ERR_OK;

error:
	delete data;
	return UV_DEBUG(UV_ERR_GENERAL);
}
示例#14
0
文件: object.cpp 项目: Eltamih/uvudec
uv_err_t UVDObject::fromString(const std::string &type, UVDData *data, UVDObject **out)
{
	std::string pluginName;
	UVDPlugin *plugin = NULL;
	
	if( type.empty() )
	{
		return UV_DEBUG(g_uvd->initObject(data, UVDRuntimeHints(), out));
	}
	pluginName = UVDSplit(type, '.')[0];
	if( g_uvd->m_pluginEngine->m_loadedPlugins.find(pluginName) == g_uvd->m_pluginEngine->m_loadedPlugins.end() )
	{
		printf_error("cannot load object from type %s because plugin %s is not loaded\n", type.c_str(), pluginName.c_str());
		return UV_DEBUG(UV_ERR_GENERAL);
	}
	plugin = (*g_uvd->m_pluginEngine->m_loadedPlugins.find(pluginName)).second;
	uv_assert_err_ret(plugin->loadObject(data, UVDRuntimeHints(), out));
	
	return UV_ERR_OK;
}
示例#15
0
uv_err_t UVDElfPCRelocation::updateRelocationTypeByBits(uint32_t nBits)
{
	uint32_t relocationType = 0;
	switch( nBits )
	{
	case 8:
		relocationType = R_386_PC8;
		break;
	case 16:
		relocationType = R_386_PC16;
		break;
	case 32:
		relocationType = R_386_PC32;
		break;
	default:
		printf_error("Invalid number of bits: %d\n", nBits);
		return UV_DEBUG(UV_ERR_GENERAL);
	}
	m_relocation.r_info = ELF32_R_INFO(ELF32_R_SYM(m_relocation.r_info), relocationType);
	return UV_ERR_OK;
}
示例#16
0
uv_err_t UVDDisasmOpcodeLookupTable::init_opcode(UVDConfigSection *op_section)
{
	unsigned int cur_line = 0;

	printf_debug("Initializing opcodes\n");
	if( op_section == NULL )
	{
		printf_debug(".OP section required\n");
		return UV_DEBUG(UV_ERR_GENERAL);
	}
		
	printf_debug("Processing opcode lines...\n");
	cur_line = 0;
	for( ;;  )
	{
		//Its easier to parse some things before others
		std::string value_desc;
		std::string value_usage;
		UVDConfigLine value_syntax;
		UVDConfigLine conditionLine;
		std::string value_action;
		std::string value_cycles;
		std::string value_name;
		UVDDisasmInstructionShared *inst_shared = NULL;

		printf_debug("\nLooking for next instruction block at index %d / %d\n", cur_line, op_section->m_lines.size());
		//Start by extracting key/value pairs
		for( ; cur_line < op_section->m_lines.size(); ++cur_line )
		{
			std::string::size_type equalsPos = 0;
			std::string key;
			std::string value;
			UVDConfigLine configLine = op_section->m_lines[cur_line];
			std::string line = configLine.m_line;

			printf_debug("Line: <%s>\n", line.c_str());
			
			//Skip comments, empty
			if( line.empty() || line[0] == '#' )
			{
				continue;
			}
			else if( line[0] == '.' )
			{
				printf_debug("Section parsing too crude to handle specified section ordering\n");
				return UV_DEBUG(UV_ERR_GENERAL);
			}
			
			//Setup key/value pairing
			equalsPos = line.find("=");
			if( equalsPos == std::string::npos )
			{
				printf_debug("no key/value pair detected\n");
				return UV_DEBUG(UV_ERR_GENERAL);
			}
			//Skip equals
			value = line.substr(equalsPos + 1);
			/* Skip the equals sign, make key comparisons easier */
			key = line.substr(0, equalsPos);
			configLine.m_key = key;
			configLine.m_value = value;
			
			printf_debug("key: <%s>, value: <%s>\n", key.c_str(), value.c_str());
	
			if( value_name.empty() && key != "NAME" )
			{
				printf_debug("NAME must go first\n");
				return UV_DEBUG(UV_ERR_GENERAL);
			}
			
			if( key == "NAME" )
			{
				printf_debug("Name found, value_name: %s\n", value_name.c_str());
				//If we alreayd have a name value, we are at the next entry
				if( !value_name.empty() )
				{
					break;
				}
				value_name = value;
			}
			else if( key == "DESC" )
			{
				value_desc = value;
			}
			else if( key == "USAGE" )
			{
				value_usage = value;
			}
			else if( key == "SYNTAX" )
			{
				value_syntax = configLine;
			}
			else if( key == "ACTION" )
			{
				value_action = value;
			}
			else if( key == "CYCLES" )
			{
				value_cycles = value;
			}
			else if( key == "CONDITION" )
			{
				conditionLine = configLine;
			}
			else
			{
				printf_debug("Invalid key\n");
				return UV_DEBUG(UV_ERR_GENERAL);
			}
		}

		/*
		NAME=XRL
		DESC=Bitwise Exclusive OR
		USAGE=0x6E
		SYNTAX=%A,%R6
		ACTION=nop
		CYCLES=1
		*/

		if( value_name.empty() )
		{
			printf_debug("No more config entries\n");
			break;
		}		

		inst_shared = new UVDDisasmInstructionShared();
		uv_assert_ret(inst_shared);
		printf_debug("Allocated new instruction, new: 0x%X\n", (unsigned int)inst_shared);	
		
		printf_debug("std::string value_name = %s\n", value_name.c_str());
		printf_debug("std::string value_desc = %s\n", value_desc.c_str());
		printf_debug("std::string value_usage = %s\n", value_usage.c_str());
		printf_debug("std::string value_syntax = %s\n", value_syntax.m_line.c_str());
		printf_debug("std::string value_action = %s\n", value_action.c_str());
		printf_debug("std::string value_cycles = %s\n", value_cycles.c_str());

		if( value_desc.empty() )
		{
			printf_debug("Description field missing\n");
			return UV_DEBUG(UV_ERR_GENERAL);
		}

		if( value_usage.empty() )
		{
			printf_debug("Usage field missing\n");
			return UV_DEBUG(UV_ERR_GENERAL);
		}

		if( value_action.empty() )
		{
			printf_debug("Action field missing\n");
			return UV_DEBUG(UV_ERR_GENERAL);
		}

		inst_shared->m_config_line_syntax = value_syntax.m_lineNumber;
		inst_shared->m_config_line_usage = op_section->m_lineNumber;
		
		//Trivial parsing
		inst_shared->m_memoric = value_name;
		inst_shared->m_desc = value_desc;
		if( !value_cycles.empty() )
		{
			inst_shared->m_cpi = strtol(value_cycles.c_str(), NULL, 0);
		}
		else
		{
			inst_shared->m_cpi = 1;
		}

		printf_debug("*Parsing syntax\n");		
		if( UV_FAILED(uvd_parse_syntax(inst_shared, value_syntax.m_value)) )
		{
			printf_error("Error parsing syntax line %d, %s\n", value_syntax.m_lineNumber, value_syntax.m_line.c_str());
			return UV_DEBUG(UV_ERR_GENERAL);
		}
				
		printf_debug("*Parsing usage\n");		
		if( UV_FAILED(uvd_parse_usage(inst_shared, value_usage)) )
		{
			printf_debug("Error parsing usage line %d\n", inst_shared->m_config_line_usage);
			return UV_DEBUG(UV_ERR_GENERAL);
		}
		
		inst_shared->m_action = value_action;

		printf_debug("Storing processed\n");
		/*
		Make sure its valid 
		At a minimum need a name and a usage
		*/
		uv_assert_ret(!inst_shared->m_memoric.empty() && inst_shared->m_opcode_length != 0 )
		
		//Compute some things to help speed up analysis and know the nature of this instruction
		uv_assert_err_ret(inst_shared->analyzeAction());
		
		//Check for a repeated/conflicting opcode
		printf_debug("table size: 0x%.8X\n", sizeof(m_lookupTable));
		std::set<uint8_t> opcodes;
		uv_assert_err_ret(inst_shared->getOpcodes(opcodes));
		for( std::set<uint8_t>::iterator iter = opcodes.begin(); iter != opcodes.end(); ++iter )
		{
			uint8_t primary_opcode = 0;
			
			primary_opcode = *iter;
			printf_debug("Primary opcode: 0x%.2X\n", primary_opcode);
		
			if( m_lookupTable[primary_opcode] )
			{
				if( g_error_opcode_repeat )
				{
					UVDDisasmInstructionShared *old = m_lookupTable[primary_opcode];
					
					printf_error("Duplicate opcode: 0x%.2X\n", primary_opcode);
					printf_error("old: %s/%s\n", old->m_memoric.c_str(), old->m_desc.c_str());
					printf_error("new: %s\n", inst_shared->m_memoric.c_str(), inst_shared->m_desc.c_str());
					return UV_DEBUG(UV_ERR_GENERAL);
				}
			}

			printf_debug("Doing actual store of opcode 0x%02X\n", primary_opcode);
			m_lookupTable[primary_opcode] = inst_shared;
			printf_debug("Stored processed\n");
		}
	}
	return UV_ERR_OK;
}
示例#17
0
/* 
USAGE field
How the instruction looks in binary
The SYNTAX field must have already been parsed before this to setup the operand structs
The main job of this field is to
-Map immediates to arguments as seen in an assembler
-Figure out how long the entire instruction is so the next instruction class can be deciphered
*/
uv_err_t UVDDisasmOpcodeLookupTable::uvd_parse_usage(UVDDisasmInstructionShared *inst_shared, const std::string value_usage)
{
	//Ignore for now...
	//FIXME: we need to know how many bytes this took at a minimum
	/* USAGE=0x53 i0 i1 */
	std::vector<std::string> usageParts;
	
	usageParts =  UVDSplit(value_usage, ',', TRUE);
	
	/* Collect immediates and operands */
	for( std::vector<std::string>::size_type curUsagePart = 0; curUsagePart < usageParts.size(); ++curUsagePart )
	{
		const std::string &cur = usageParts[curUsagePart];
		/* Iterate over the fields already setup by usage */
		UVDDisasmOperandShared *op_shared = NULL;
		UVDConfigValue parsed_type;

		printf_debug("Current operand: %s\n", cur.c_str());
		uv_assert_err_ret(UVDConfigValue::parseType(cur, &parsed_type));		
		printf_debug("Type: %d\n", parsed_type.m_operand_type);
		
		if( parsed_type.m_operand_type == UV_DISASM_DATA_CONSTANT )
		{
			if( inst_shared->m_opcode_length >= MAX_OPCODE_SIZE )
			{
				printf_debug("Maximum opcode length exceeded\n");
				return UV_DEBUG(UV_ERR_GENERAL);
			}
			inst_shared->m_opcode[inst_shared->m_opcode_length] = parsed_type.m_value;
			inst_shared->m_opcodeRangeOffset[inst_shared->m_opcode_length] = parsed_type.m_opcodeRangeOffset;
			inst_shared->m_bitmask[inst_shared->m_opcode_length] = parsed_type.m_bitmask;
			++inst_shared->m_opcode_length;
			inst_shared->m_total_length += 1;
			continue;
		}
		
		/*
		Find the syntax field that matches parsed_type from the list of
		syntax fields in inst_shared and place it in op_shared
		*/
		if( UV_FAILED(uvd_match_syntax_usage(inst_shared, &parsed_type, &op_shared)) )
		{
			printf_error("can't match syntax and usage for syntax line %d, usage line %d\n",
					inst_shared->m_config_line_syntax, inst_shared->m_config_line_usage);
			return UV_DEBUG(UV_ERR_GENERAL);
		}
		
		if( !op_shared )
		{
			printf_debug("Could not match up SHARED and USAGE fields\n");
			return UV_DEBUG(UV_ERR_GENERAL);
		}
		if( op_shared->m_type != parsed_type.m_operand_type )
		{
			printf_debug("USAGE/SYNTAX type mismatch\n");
			printf_debug("shared: %s=%s(%d), parsed: %s=%s(%d)\n", op_shared->m_name.c_str(), uvd_data_str(op_shared->m_type), op_shared->m_type, 
					parsed_type.m_name.c_str(), uvd_data_str(parsed_type.m_operand_type), parsed_type.m_operand_type);
			return UV_DEBUG(UV_ERR_GENERAL);
		}
		
		if( parsed_type.m_operand_type == UV_DISASM_DATA_IMMS
			|| parsed_type.m_operand_type == UV_DISASM_DATA_IMMU )
		{
			/* It is possible that DPTR may cause a few 16 bit immediates, but syntax does not yet support that */
			if( op_shared->m_immediate_size != parsed_type.m_num_bits )
			{
				printf_error("USAGE/SYNTAX size mismatch\n");
				return UV_DEBUG(UV_ERR_GENERAL);
			}
			inst_shared->m_total_length += op_shared->m_immediate_size / 8;
		}
		else if( parsed_type.m_operand_type == UV_DISASM_DATA_REG )
		{
			/* Mayber later some sort of Intel /r thing */
			printf_error("No registers during usage\n");
			return UV_DEBUG(UV_ERR_GENERAL);
		}
		else if( parsed_type.m_operand_type == UV_DISASM_DATA_FUNC )
		{
			/* Likely this will involve a fork onto the linked list */
			printf_error("Special modifier, not yet supported\n");
			return UV_DEBUG(UV_ERR_GENERAL);
		}
		else
		{
			printf_error("Unknown operand type\n");
			return UV_DEBUG(UV_ERR_GENERAL);
		}
	}
		
	return UV_ERR_OK;
}
示例#18
0
文件: engine.cpp 项目: Eltamih/uvudec
uv_err_t UVDPluginEngine::loadByDir(const std::string &pluginDir, UVDConfig *config,
			bool recursive,
			bool failOnError, bool failOnPluginError)
{
	//boost throws exceptions
	//TODO: move to UVD friendly adapter interface
	try
	{
		for( boost::filesystem::directory_iterator iter(pluginDir);
			iter != boost::filesystem::directory_iterator(); ++iter )
		{
			//Not necessarily canonical
			std::string path;
			uv_err_t loadByPathRc = UV_ERR_GENERAL;
		
			path = pluginDir + "/" + iter->path().filename();
			if( is_directory(iter->status()) )
			{
				if( recursive )
				{
					uv_assert_err_ret(loadByDir(path, config,
							recursive,
							failOnError, failOnPluginError));
				}
				continue;				
			}
		
			//Try loading it, ignoring errors since it might just be a plugin config file or something
			//We should print a warning if
			loadByPathRc = loadByPath(path, false);
			if( UV_FAILED(loadByPathRc) )
			{
				if( loadByPathRc == UV_ERR_NOTSUPPORTED )
				{
					if( failOnError )
					{
						printf_error("failed to load possible plugin: %s\n", path.c_str());
						return UV_DEBUG(UV_ERR_GENERAL);
					}
					else
					{
						printf_plugin_debug("failed to load possible plugin: %s\n", path.c_str());
					}
				}
				else
				{
					if( failOnError || failOnPluginError )
					{
						printf_error("failed to load plugin: %s\n", path.c_str());
						return UV_DEBUG(UV_ERR_GENERAL);
					}
					else
					{
						printf_warn("failed to load plugin: %s\n", path.c_str());
					}
				}
			}
		}		

		return UV_ERR_OK;
	}
	catch(...)
	{
		if( !config->m_suppressErrors )
		{
			printf_error("failed to load plugin dir %s\n", pluginDir.c_str());
		}
		
		if( config->m_ignoreErrors )
		{
			return UV_DEBUG(UV_ERR_WARNING);
		}
		else
		{
			return UV_DEBUG(UV_ERR_GENERAL);			
		}		
	}
}
示例#19
0
void *functionGetStatus( void *param )
{
    Socket2Uart *socket_to_uart=( Socket2Uart *)param;
    int listen_fd=-1;
    int connect_fd;
    char buffer[1024];
    while(1)
    {
        connect_fd = start_tcp_server( &listen_fd , PORT_OF_GETSTATUS );

        if ( connect_fd < 0 )
        {
            printf_error( "GetStatus:the listen socket error\n" );
            continue;
        }

        int read_size;
        read_size = read_socket( connect_fd , buffer );

        if ( read_size < 0 )
        {
            printf_error( "GetStatus:read socket error\n" );
            continue;
        }
        else if ( read_size == 0 )
        {
            printf_debug( "GetStatus:read socket[%d] time out\n" , connect_fd );
            continue;
        }

        if ( debug )
        {
            printf_debug( "GetStatus:socket[%d] >>>\n" , connect_fd );
            if ( read_size > 0 )
                printData( buffer , read_size , "" , 1  );
        }
        char status_string[128];

        if ( strstr( buffer , "status" ) )
        {
            socket2uart_GetStatusString( socket_to_uart , status_string , sizeof( status_string ));

            if ( debug )
            {
                printf_debug( "socket[%d] <<<\n" , connect_fd );
                printData( status_string , strlen( status_string ) , "" , 0  );
            }
            char output_status[256];
            if ( strlen( status_string ) > 0 )
            {
                snprintf( output_status , sizeof(output_status) , "STATUS\n%s" , status_string );
            }
            else
            {
                snprintf( output_status , sizeof(output_status) , "FAILED\nPAP is not connected\n" );
            }
            write( connect_fd , output_status , strlen( output_status ));
        }

        close( connect_fd );
    }



    return 0;
}
示例#20
0
/*
 * Parses a timestamp, figuring out its format.
 *
 * Returns a negative value if anything goes wrong.
 *
 * Expected formats:
 *
 *   YYYY-MM-DD hh:mm:ss.ns
 *   hh:mm:ss.ns
 *   -ss.ns
 *   ss.ns
 *   YYYY-MM-DD hh:mm:ss
 *   hh:mm:ss
 *   -ss
 *   ss
 */
static
int timestamp_from_arg(const char *arg, struct trimmer *trimmer,
		struct trimmer_bound *result_bound, bt_bool gmt)
{
	int ret;
	int64_t value;
	unsigned int year, month, day, hh, mm, ss, ns;

	/* YYYY-MM-DD hh:mm:ss.ns */
	ret = sscanf(arg, "%u-%u-%u %u:%u:%u.%u",
		&year, &month, &day, &hh, &mm, &ss, &ns);
	if (ret == 7) {
		struct tm tm = {
			.tm_sec = ss,
			.tm_min = mm,
			.tm_hour = hh,
			.tm_mday = day,
			.tm_mon = month - 1,
			.tm_year = year - 1900,
			.tm_isdst = -1,
		};
		time_t result;

		if (gmt) {
			result = bt_timegm(&tm);
			if (result < 0) {
				return -1;
			}
		} else {
			result = mktime(&tm);
			if (result < 0) {
				return -1;
			}
		}
		value = (int64_t) result;
		value *= NSEC_PER_SEC;
		value += ns;
		if (!trimmer->date) {
			trimmer->year = year;
			trimmer->month = month;
			trimmer->day = day;
			trimmer->date = true;
		}
		goto set;
	}
	/* hh:mm:ss.ns */
	ret = sscanf(arg, "%u:%u:%u.%u",
		&hh, &mm, &ss, &ns);
	if (ret == 4) {
		if (!trimmer->date) {
			/* We don't know which day until we get an event. */
			result_bound->lazy_values.hh = hh;
			result_bound->lazy_values.mm = mm;
			result_bound->lazy_values.ss = ss;
			result_bound->lazy_values.ns = ns;
			result_bound->lazy_values.gmt = gmt;
			goto lazy;
		} else {
			struct tm tm = {
				.tm_sec = ss,
				.tm_min = mm,
				.tm_hour = hh,
				.tm_mday = trimmer->day,
				.tm_mon = trimmer->month - 1,
				.tm_year = trimmer->year - 1900,
				.tm_isdst = -1,
			};
			time_t result;

			if (gmt) {
				result = bt_timegm(&tm);
				if (result < 0) {
					return -1;
				}
			} else {
				result = mktime(&tm);
				if (result < 0) {
					return -1;
				}
			}
			value = (int64_t) result;
			value *= NSEC_PER_SEC;
			value += ns;
			goto set;
		}
	}
	/* -ss.ns */
	ret = sscanf(arg, "-%u.%u",
		&ss, &ns);
	if (ret == 2) {
		value = -ss * NSEC_PER_SEC;
		value -= ns;
		goto set;
	}
	/* ss.ns */
	ret = sscanf(arg, "%u.%u",
		&ss, &ns);
	if (ret == 2) {
		value = ss * NSEC_PER_SEC;
		value += ns;
		goto set;
	}

	/* YYYY-MM-DD hh:mm:ss */
	ret = sscanf(arg, "%u-%u-%u %u:%u:%u",
		&year, &month, &day, &hh, &mm, &ss);
	if (ret == 6) {
		struct tm tm = {
			.tm_sec = ss,
			.tm_min = mm,
			.tm_hour = hh,
			.tm_mday = day,
			.tm_mon = month - 1,
			.tm_year = year - 1900,
			.tm_isdst = -1,
		};

		if (gmt) {
			value = bt_timegm(&tm);
			if (value < 0) {
				return -1;
			}
		} else {
			value = mktime(&tm);
			if (value < 0) {
				return -1;
			}
		}
		value *= NSEC_PER_SEC;
		if (!trimmer->date) {
			trimmer->year = year;
			trimmer->month = month;
			trimmer->day = day;
			trimmer->date = true;
		}
		goto set;
	}
	/* hh:mm:ss */
	ret = sscanf(arg, "%u:%u:%u",
		&hh, &mm, &ss);
	if (ret == 3) {
		if (!trimmer->date) {
			/* We don't know which day until we get an event. */
			result_bound->lazy_values.hh = hh;
			result_bound->lazy_values.mm = mm;
			result_bound->lazy_values.ss = ss;
			result_bound->lazy_values.ns = 0;
			result_bound->lazy_values.gmt = gmt;
			goto lazy;
		} else {
			struct tm tm = {
				.tm_sec = ss,
				.tm_min = mm,
				.tm_hour = hh,
				.tm_mday = trimmer->day,
				.tm_mon = trimmer->month - 1,
				.tm_year = trimmer->year - 1900,
				.tm_isdst = -1,
			};
			time_t result;

			if (gmt) {
				result = bt_timegm(&tm);
				if (result < 0) {
					return -1;
				}
			} else {
				result = mktime(&tm);
				if (result < 0) {
					return -1;
				}
			}
			value = (int64_t) result;
			value *= NSEC_PER_SEC;
			goto set;
		}
	}
	/* -ss */
	ret = sscanf(arg, "-%u",
		&ss);
	if (ret == 1) {
		value = -ss * NSEC_PER_SEC;
		goto set;
	}
	/* ss */
	ret = sscanf(arg, "%u",
		&ss);
	if (ret == 1) {
		value = ss * NSEC_PER_SEC;
		goto set;
	}

	/* Not found. */
	return -1;

set:
	result_bound->value = value;
	result_bound->set = true;
	return 0;

lazy:
	result_bound->lazy = true;
	return 0;
}

static
enum bt_component_status init_from_params(struct trimmer *trimmer,
		struct bt_value *params)
{
	struct bt_value *value = NULL;
	bt_bool gmt = BT_FALSE;
	enum bt_component_status ret = BT_COMPONENT_STATUS_OK;

	assert(params);

        value = bt_value_map_get(params, "clock-gmt");
	if (value) {
		enum bt_value_status value_ret;

		value_ret = bt_value_bool_get(value, &gmt);
		if (value_ret) {
			ret = BT_COMPONENT_STATUS_INVALID;
			printf_error("Failed to retrieve clock-gmt value. Expecting a boolean");
		}
	}
	bt_put(value);
	if (ret != BT_COMPONENT_STATUS_OK) {
		goto end;
	}

        value = bt_value_map_get(params, "begin");
	if (value) {
		enum bt_value_status value_ret;
		const char *str;

		value_ret = bt_value_string_get(value, &str);
		if (value_ret || timestamp_from_arg(str,
				trimmer, &trimmer->begin, gmt)) {
			ret = BT_COMPONENT_STATUS_INVALID;
			printf_error("Failed to retrieve begin value. Expecting a timestamp string");
		}
	}
	bt_put(value);
	if (ret != BT_COMPONENT_STATUS_OK) {
		goto end;
	}

        value = bt_value_map_get(params, "end");
	if (value) {
		enum bt_value_status value_ret;
		const char *str;

		value_ret = bt_value_string_get(value, &str);
		if (value_ret || timestamp_from_arg(str,
				trimmer, &trimmer->end, gmt)) {
			ret = BT_COMPONENT_STATUS_INVALID;
			printf_error("Failed to retrieve end value. Expecting a timestamp string");
		}
	}
	bt_put(value);
end:
	if (trimmer->begin.set && trimmer->end.set) {
		if (trimmer->begin.value > trimmer->end.value) {
			printf_error("Unexpected: time range begin value is above end value");
			ret = BT_COMPONENT_STATUS_INVALID;
		}
	}
	return ret;
}

enum bt_component_status trimmer_component_init(
	struct bt_private_component *component, struct bt_value *params,
	UNUSED_VAR void *init_method_data)
{
	enum bt_component_status ret;
	struct trimmer *trimmer = create_trimmer_data();

	if (!trimmer) {
		ret = BT_COMPONENT_STATUS_NOMEM;
		goto end;
	}

	/* Create input and output ports */
	ret = bt_private_component_filter_add_input_private_port(
		component, "in", NULL, NULL);
	if (ret != BT_COMPONENT_STATUS_OK) {
		goto error;
	}

	ret = bt_private_component_filter_add_output_private_port(
		component, "out", NULL, NULL);
	if (ret != BT_COMPONENT_STATUS_OK) {
		goto error;
	}

	ret = bt_private_component_set_user_data(component, trimmer);
	if (ret != BT_COMPONENT_STATUS_OK) {
		goto error;
	}

	ret = init_from_params(trimmer, params);
end:
	return ret;
error:
	destroy_trimmer_data(trimmer);
	ret = BT_COMPONENT_STATUS_ERROR;
	return ret;
}
示例#21
0
int socket2uart( Socket2Uart *socket_to_uart )
{
    char buffer[BUF_SIZE];

    socket_to_uart->relay_thread_handle = -1;
    socket_to_uart->listen_fd = -1;
    socket_to_uart->connect_fd = -1;
    pthread_cond_init( &socket_to_uart->condSocket2Uart , 0 );
    pthread_mutex_init( &socket_to_uart->mutexSocket2Uart , 0);

    while(1)
    {
        socket_to_uart->connect_fd = start_tcp_server( &socket_to_uart->listen_fd , socket_to_uart->port );

        if ( socket_to_uart->relay_thread_handle == -1 )
            pthread_create( &socket_to_uart->relay_thread_handle , 0 ,  relay_uart_to_socket , socket_to_uart );

        if ( DisconnectIfNoPermit( socket_to_uart ) == 0 )
        {
            printf_debug( "no permit, maybe ExecuteSeriesCommand take long time\n" );
            continue;
        }

        if ( socket_to_uart->connect_fd < 0 )
        {
            printf_error( "the listen socket error\n" );
            continue;
        }

        socket2uart_SetReconnected( socket_to_uart );

        do{
            if ( DisconnectIfNoPermit( socket_to_uart ) == 0 )
            {
                printf_debug( "socket2uart too long\n" );
                break;
            }

            int read_size;
            read_size = read_socket( socket_to_uart->connect_fd , buffer );

            if ( read_size < 0 )
                break;
            else if ( read_size == 0 )
            {
                printf_debug( "read socket[%d] time out\n" , socket_to_uart->connect_fd );
                break;
            }

            if ( debug )
            {
                printf_debug( "socket[%d] >>>\n" , socket_to_uart->connect_fd );
                printData( buffer , read_size , "" , 1  );
            }

            if ( CPAP_send( 0 , buffer , read_size ) >= 0 )
            {
                //note the uart-to-socket thread to read uart
                pthread_mutex_lock( &socket_to_uart->mutexSocket2Uart );
                pthread_cond_signal( &socket_to_uart->condSocket2Uart );
                pthread_mutex_unlock( &socket_to_uart->mutexSocket2Uart );
            }
            else
            {
                char *uart_open_failed="FAILED\nCPAP open error\n";
                write( socket_to_uart->connect_fd , uart_open_failed , strlen(uart_open_failed) );
            }

        }while(1);

        socket2uart_CloseClient( socket_to_uart );
    }
}
示例#22
0
文件: flirt.cpp 项目: Eltamih/uvudec
uv_err_t UVDFLIRTPatternAnalysisUVD::saveToString(std::string &output)
{
	/*
	This is documented in the FLAIR toolkit, see pat.txt.  In summary...
	558BEC8B5E04D1E3F787....02007406B8050050EB141EB43F8B5E048B4E0AC5 0B B56E 002F :0000 __read ^000B __openfd ^002C __IOERROR ....5DC3
	pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp ll ssss LLLL gggggggggggg rrrrrrrrrrrrrrrrrrrrrrrrrrrrrr tttttttt

    Module essentially refers to a function within a library
    
    p - PATTERN BYTES (64 positions)
        space
    l - 2 positions contain ALEN (example:12)
        space
    s - 4 positions contain ASUM (example:1234)
        space
    L - 4 positions contain TOTAL LENGTH OF MODULE IN BYTES (example:1234)
        space
    g - LIST OF PUBLIC NAMES
    r - LIST OF REFERENCED NAMES
    t - TAIL BYTES
	*/
	
	//Begining signature
	uint32_t signatureLengthMin = g_config->m_flirt.m_patSignatureLengthMin;
	std::string lineEnding = g_config->m_flirt.m_patternFileNewline;
	//From pat doc
	const uint32_t maxModuleLength = 0x8000;
	uint32_t moduleLength = 0;
	
	uv_assert_ret(m_library);
	uv_assert_ret(m_library->m_data);
	uv_assert_err_ret(m_library->m_data->size(&moduleLength));
	if( moduleLength > maxModuleLength )
	{
		printf_error("really big library (>0x%X)!  Cannot save data\n", maxModuleLength);
		return UV_DEBUG(UV_ERR_GENERAL);
	}
	
	output = "";

	//One line per function
	for( std::vector<UVDFLIRTPatternEntry *>::iterator iter = m_entries.begin(); iter != m_entries.end(); ++iter )
	{
		UVDFLIRTPatternEntry *entry = *iter;
		std::string sEntry;
		//char **rawData = NULL;
		uint32_t rawDataSize = 0;
		/*
		Pat doc calls this list of "public names", ie names we export this symbol as.  Most likely one
		XXXX: offset in module
		:XXXX name
		*/
		UVDBinarySymbol *symbol = NULL;
		UVDData *data = NULL;
		
		//We are a bit careful here, but during subroutines don't do error check
		uv_assert_ret(entry);
		symbol = entry->m_symbol;
		uv_assert_ret(symbol);
		data = symbol->m_data;
		uv_assert_ret(data);
		
		uv_assert_err_ret(data->size(&rawDataSize));
		
		//Under special circumstances we take these, but usually ignore them
		//For example, FLAIR claims it will take short sigs if they contain relocations
		if( rawDataSize < signatureLengthMin )
		{
			continue;
		}
		
		//uv_assert_err_ret(data->readData(&rawData));
		
		std::string temp;
		
		uv_assert_err_ret(getPatLeadingSignature(entry, temp));
		sEntry += temp;
		uv_assert_err_ret(getPatCRC(entry, temp));
		sEntry += temp;
		uv_assert_err_ret(getPatPublicNames(entry, temp));
		sEntry += temp;
		uv_assert_err_ret(getPatReferencedNames(entry, temp));
		sEntry += temp;
		uv_assert_err_ret(getPatTailBytes(entry, temp));
		sEntry += temp;
		
		sEntry += lineEnding;
		output += sEntry;
		
		//free(rawData);
	}	
	
	output += "---" + lineEnding;

	return UV_ERR_OK;
}
示例#23
0
文件: main.cpp 项目: Eltamih/uvudec
uv_err_t uvmain(int argc, char **argv)
{
	uv_err_t rc = UV_ERR_GENERAL;
	UVDConfig *config = NULL;
	UVDFLIRTConfig *flirtConfig = NULL;
	uv_err_t parseMainRc = UV_ERR_GENERAL;
	
	if( strcmp(GetVersion(), UVDGetVersion()) )
	{
		printf_warn("libuvudec version mismatch (exe: %s, libuvudec: %s)\n", GetVersion(), UVDGetVersion());
		fflush(stdout);
	}
	
	//Early library initialization.  Logging and arg parsing structures
	uv_assert_err_ret(UVDInit());
	config = g_config;
	uv_assert_ret(config);
	//Early local initialization
	uv_assert_err_ret(initProgConfig());
	
	//Grab our command line options
	parseMainRc = config->parseMain(argc, argv);
	uv_assert_err_ret(parseMainRc);
	if( parseMainRc == UV_ERR_DONE )
	{
		rc = UV_ERR_OK;
		goto error;
	}


	//Create a doConvertr engine active on that input
	printf_debug_level(UVD_DEBUG_SUMMARY, "doConvert: initializing FLIRT engine...\n");
	if( UV_FAILED(UVDFLIRT::getFLIRT(&g_flirt)) )
	{
		printf_error("Failed to initialize FLIRT engine\n");
		rc = UV_ERR_OK;
		goto error;
	}
	uv_assert_ret(g_flirt);

	flirtConfig = g_UVDFLIRTConfig;
	uv_assert_ret(flirtConfig);

	//Source .pat files
	if( flirtConfig->m_targetFiles.empty() )
	{
		printf_error("Target file(s) not specified\n");
		config->printHelp();
		uv_assert_err(UV_ERR_GENERAL);
	}
	
	if( UV_FAILED(doConvert()) )
	{
		printf_error("Top level doConvert failed\n");
		uv_assert(UV_ERR_GENERAL);
	}	

	rc = UV_ERR_OK;

error:
	uv_assert_err_ret(UVDDeinit());
		
	return UV_DEBUG(rc);
}
示例#24
0
static bool	error_type_sbp(t_graphic *graphic, char *arg)
{
  printf_error("\"%s\" is invalid map position", arg);
  graphic_sbp(graphic);
  return (false);
}
示例#25
0
文件: main.cpp 项目: Eltamih/uvudec
static uv_err_t argParser(const UVDArgConfig *argConfig, std::vector<std::string> argumentArguments, void *user)
{
	UVDConfig *config = NULL;
	UVDFLIRTConfig *flirtConfig = NULL;
	//If present
	std::string firstArg;
	uint32_t firstArgNum = 0;
	
	config = g_config;
	uv_assert_ret(config);
	uv_assert_ret(config->m_argv);
	uv_assert_ret(argConfig);
	flirtConfig = g_UVDFLIRTConfig;
	uv_assert_ret(flirtConfig);

	if( !argumentArguments.empty() )
	{
		firstArg = argumentArguments[0];
		firstArgNum = strtol(firstArg.c_str(), NULL, 0);
	}

	if( argConfig->isNakedHandler() )
	{
		/*
		Try to guess type based on file suffixes
		*/
		
		for( std::vector<std::string>::iterator iter = argumentArguments.begin();
				iter != argumentArguments.end(); ++iter )
		{
			const std::string &arg = *iter;
			
			if( arg.find(".pat") != std::string::npos )
			{
				flirtConfig->m_targetFiles.push_back(arg);
			}
			else if( arg.find(".sig") != std::string::npos )
			{
				flirtConfig->m_outputFile = arg;
			}
			//Hmm okay append suffixes and guess
			else
			{
				printf_error("cannot guess argument purpose: %s\n", arg.c_str());
				return UV_DEBUG(UV_ERR_GENERAL);
			}
		}
	}
	else if( argConfig->m_propertyForm == UVD_PROP_FLIRT_SIG_VERSION )
	{
		uv_assert_ret(!argumentArguments.empty());
		flirtConfig->m_sigVersion = firstArgNum;
	}
	else if( argConfig->m_propertyForm == UVD_PROP_FLIRT_SIG_LIB_NAME )
	{
		uv_assert_ret(!argumentArguments.empty());
		flirtConfig->m_libName = firstArg;
	}
	else if( argConfig->m_propertyForm == UVD_PROP_FLIRT_SIG_FEATURES )
	{
		uv_assert_ret(!argumentArguments.empty());
		flirtConfig->m_sigFeatures = firstArgNum;
	}
	else if( argConfig->m_propertyForm == UVD_PROP_FLIRT_SIG_PAD )
	{
		uv_assert_ret(!argumentArguments.empty());
		flirtConfig->m_sigPad = firstArgNum;
	}
	else if( argConfig->m_propertyForm == UVD_PROP_FLIRT_SIG_PROCESSOR_ID )
	{
		uv_assert_ret(!argumentArguments.empty());
		flirtConfig->m_sigProcessorID = firstArgNum;
	}
	else if( argConfig->m_propertyForm == UVD_PROP_FLIRT_SIG_OS_TYPES )
	{
		uv_assert_ret(!argumentArguments.empty());
		flirtConfig->m_sigOSTypes = firstArgNum;
	}
	else if( argConfig->m_propertyForm == UVD_PROP_FLIRT_SIG_APP_TYPES )
	{
		uv_assert_ret(!argumentArguments.empty());
		flirtConfig->m_sigAppTypes = firstArgNum;
	}
	else if( argConfig->m_propertyForm == UVD_PROP_FLIRT_SIG_FILE_TYPES )
	{
		uv_assert_ret(!argumentArguments.empty());
		flirtConfig->m_sigFileTypes = firstArgNum;
	}
	else
	{
		//return UV_DEBUG(argParserDefault(argConfig, argumentArguments));
		return UV_DEBUG(UV_ERR_GENERAL);
	}

	return UV_ERR_OK;
}
示例#26
0
文件: init.cpp 项目: Eltamih/uvudec
uv_err_t UVD::initObject(UVDData *data, const UVDRuntimeHints &hints, UVDObject **out)
{
	//FIXME: replace this with a config based selection
	//Must be able to feed into plugins
	//This should be a switch instead
	//m_architecture->m_architecture = architecture;
	UVDObject *object = NULL;
	std::vector<UVDPlugin *> best;
	uvd_priority_t bestPriority = UVD_MATCH_NONE;
	
	printf_debug_level(UVD_DEBUG_PASSES, "UVD::initObject()...\n");
	UVD_POKE(data);
	//Iterate over all plugins until one accepts our input
	uv_assert_ret(m_pluginEngine);
	for( std::map<std::string, UVDPlugin *>::iterator iter = m_pluginEngine->m_loadedPlugins.begin();
			iter != m_pluginEngine->m_loadedPlugins.end(); ++iter )
	{
		UVDPlugin *plugin = (*iter).second;
		uv_err_t rcTemp = UV_ERR_GENERAL;
		uvd_priority_t loadPriority = 0;
		
		uv_assert_ret(plugin);
		printf_plugin_debug("plugin %s trying canLoad object\n", (*iter).first.c_str());
		rcTemp = plugin->canLoadObject(data, hints,  &loadPriority);
		if( UV_FAILED(rcTemp) )
		{
			printf_plugin_debug("plugin %s failed to canLoad object\n", (*iter).first.c_str());
			continue;
		}

		if( loadPriority <= bestPriority )
		{
			printf_plugin_debug("plugin %s candidate at priority 0x%08X\n", (*iter).first.c_str(), loadPriority);
			if( loadPriority < bestPriority )
			{
				if( !best.empty() )
				{
					printf_plugin_debug("clearing %d plugins due to better priorty\n", best.size());
				}
				best.clear();
				bestPriority = loadPriority;
			}
			best.push_back(plugin);
		}
		else
		{
			printf_plugin_debug("plugin %s skipped due to worse priority (cur: %d, plugin: %d)\n",
					(*iter).first.c_str(), bestPriority, loadPriority);
		}
	}
	
	UVD_POKE(data);
	printf_plugin_debug("best priorty: 0x%08X, plugins: %d\n", bestPriority, best.size());
	if( bestPriority == UVD_MATCH_NONE )
	{
		printf_warn("could not find a suitable object loader\n");
		return UV_ERR_NOTFOUND;
	}
	uv_assert_ret(!best.empty());

	//Iterate over all plugins until one accepts our input
	uv_assert_ret(m_pluginEngine);
	for( std::vector<UVDPlugin *>::iterator iter = best.begin();
		iter != best.end(); ++iter )
	{
		UVDPlugin *plugin = *iter;
		uv_err_t rcTemp = UV_ERR_GENERAL;
		
		uv_assert_ret(plugin);
		rcTemp = plugin->loadObject(data, hints, &object);
		if( UV_FAILED(rcTemp) )
		{
			printf_error("plugin %s failed to load object\n", plugin->getName().c_str());
			continue;
		}
		else if( !object )
		{
			printf_error("plugin %s claimed successed but didn't set object\n", plugin->getName().c_str());
			continue;
		}
		else
		{
			printf_debug_level(UVD_DEBUG_PASSES, "loaded object from plugin %s (%p)\n", plugin->getName().c_str(), object);
			break;
		}
	}
	
	if( !object )
	{
		printf_error("could not find a suitable object module\n");
		return UV_ERR_GENERAL;
	}
	
	//Its probably better to let the object take care of this
	//For example, if init fails, we can try another candidate
	//uv_assert_err_ret(object->init(data));
	
	uv_assert_ret(out);
	*out = object;

	return UV_ERR_OK;
}
示例#27
0
文件: init.cpp 项目: Eltamih/uvudec
uv_err_t UVD::initArchitecture(UVDObject *object, const UVDRuntimeHints &hints, UVDArchitecture **out)
{
	//FIXME: replace this with a config based selection
	//Must be able to feed into plugins
	//This should be a switch instead
	//m_architecture->m_architecture = architecture;
	UVDArchitecture *architecture = NULL;
	std::vector<UVDPlugin *> best;
	uvd_priority_t bestPriority = UVD_MATCH_NONE;
	
	printf_debug_level(UVD_DEBUG_PASSES, "UVD::initArchitecture()...\n");
	for( std::map<std::string, UVDPlugin *>::iterator iter = m_pluginEngine->m_loadedPlugins.begin();
		iter != m_pluginEngine->m_loadedPlugins.end(); ++iter )
	{
		UVDPlugin *plugin = (*iter).second;
		uv_err_t rcTemp = UV_ERR_GENERAL;
		uvd_priority_t loadPriority = 0;
		
		uv_assert_ret(plugin);
		rcTemp = plugin->canGetArchitecture(object, hints,  &loadPriority);
		if( UV_FAILED(rcTemp) )
		{
			printf_plugin_debug("plugin %s failed to canLoad architecture\n", (*iter).first.c_str());
			continue;
		}

		printf_plugin_debug("plugin %s returned from canLoad architecture with priority 0x%08X\n",
				(*iter).first.c_str(), loadPriority);
		if( loadPriority <= bestPriority )
		{
			if( loadPriority < bestPriority )
			{
				best.clear();
				bestPriority = loadPriority;
			}
			best.push_back(plugin);
		}
	}
	
	printf_plugin_debug("best priorty: 0x%08X, plugins: %d\n", bestPriority, best.size());
	if( bestPriority == UVD_MATCH_NONE )
	{
		printf_warn("could not find a suitable architecture loader\n");
		return UV_ERR_NOTFOUND;
	}
	uv_assert_ret(!best.empty());

	//Iterate over all plugins until one accepts our input
	for( std::vector<UVDPlugin *>::iterator iter = best.begin();
		iter != best.end(); ++iter )
	{
		UVDPlugin *plugin = *iter;
		uv_err_t rcTemp = UV_ERR_GENERAL;
		
		uv_assert_ret(plugin);		
		rcTemp = plugin->getArchitecture(object, hints, &architecture);
		if( UV_FAILED(rcTemp) )
		{
			printf_error("plugin %s failed to load architecture\n", plugin->getName().c_str());
			continue;
		}
		else if( !architecture )
		{
			printf_error("plugin %s claimed successed but didn't set architecture\n", plugin->getName().c_str());
			continue;
		}
		else
		{
			printf_debug_level(UVD_DEBUG_PASSES, "loaded architecture from plugin %s\n", plugin->getName().c_str());
			break;
		}
	}
	
	if( !architecture )
	{
		printf_error("could not find a suitable architecture loader\n");
		return UV_ERR_NOTFOUND;
	}
	
	uv_assert_err_ret(architecture->doInit());
	uv_assert_err_ret(architecture->fixupDefaults());

	uv_assert_ret(out);
	*out = architecture;

	return UV_ERR_OK;
}
示例#28
0
文件: engine.cpp 项目: Eltamih/uvudec
uv_err_t UVDPluginEngine::loadByPath(const std::string &path, bool reportErrors)
{
	UVDPlugin *plugin = NULL;
	void *library = NULL;
	UVDPlugin::PluginMain pluginMain = NULL;
	const char *lastError = NULL;
	uv_err_t rcTemp = UV_ERR_GENERAL;
	std::string name;

	printf_plugin_debug("trying to load plugin path %s\n", path.c_str());

	//Clear errors
	dlerror();
	library = dlopen(path.c_str(), RTLD_LAZY);
	lastError = dlerror();
	if( !library || lastError )
	{
		if( reportErrors )
		{
			//Maybe should be a warning?
			//is there any reason why we'd lazily try to load a plugin only if it exists?
			if( !lastError )
			{
				lastError = "<UNKNOWN>";
			}
			printf_error("%s: load library failed: %s\n", path.c_str(), lastError);
			return UV_DEBUG(UV_ERR_NOTSUPPORTED);
		}
		else
		{
			if( !lastError )
			{
				lastError = "<UNKNOWN>";
			}
			printf_plugin_debug("%s: load library failed: %s\n", path.c_str(), lastError);
			return UV_ERR_NOTSUPPORTED;
		}
	}

	/*
	Prefer mangled symbol since its more type safe
	*/
	pluginMain = (UVDPlugin::PluginMain)dlsym(library, UVD_PLUGIN_MAIN_MANGLED_SYMBOL_STRING);
	lastError = dlerror();
	if( !pluginMain || lastError )
	{
		//But settle for the extern'd symbol if they do that for w/e reason
		pluginMain = (UVDPlugin::PluginMain)dlsym(library, UVD_PLUGIN_MAIN_SYMBOL_STRING);
		lastError = dlerror();
		if( !pluginMain || lastError )
		{
			if( reportErrors )
			{
				if( !lastError )
				{
					lastError = "<UNKNOWN>";
				}
				printf_error("plugin %s: failed to load main: %s\n", path.c_str(), lastError);
				dlclose(library);
				return UV_DEBUG(UV_ERR_NOTSUPPORTED);
			}
			else
			{
				if( !lastError )
				{
					lastError = "<UNKNOWN>";
				}
				printf_plugin_debug("plugin %s: failed to load main: %s\n", path.c_str(), lastError);
				dlclose(library);
				return UV_ERR_NOTSUPPORTED;
			}
		}
	}
	
	//	typedef PluginMain uv_err_t (*)(UVD *uvd, UVDPlugin **out);
	UVDConfig *config = NULL;
	if( m_uvd )
	{
		config = m_uvd->m_config;
	}
	else
	{
		uv_assert_ret(g_config);
		config = g_config;
	}
	rcTemp = UV_DEBUG(pluginMain(config, &plugin));
	if( UV_FAILED(rcTemp) )
	{
		//Don't do report error checks since it has demonstrated reasonable effort at being a valid plugin
		printf_error("plugin %s: main failed\n", path.c_str());
		dlclose(library);
		return UV_DEBUG(UV_ERR_GENERAL);
	}
	if( !plugin )
	{
		if( !config->m_suppressErrors )
		{
			printf_error("plugin %s: didn't return a plugin object\n", path.c_str());
		}

		dlclose(library);
		return UV_DEBUG(UV_ERR_GENERAL);
	}

	rcTemp = UV_DEBUG(plugin->getName(name));
	if( UV_FAILED(rcTemp) )
	{
		dlclose(library);
		return UV_DEBUG(UV_ERR_GENERAL);
	}
	
	if( name.empty() )
	{
		/*
		we could do
		name = path;
		but it might cause issues later
		refusing to load makes people stop being lazy
		*/
		printf_error("plugin %s: didn't provide a name\n", path.c_str());
		dlclose(library);
		return UV_DEBUG(UV_ERR_GENERAL);
	}
	
	plugin->m_hLibrary = library;
	m_plugins[name] = plugin;
	
	printf_plugin_debug("loaded plugin: %s\n", name.c_str());

	return UV_ERR_OK;
}