void AbstractBTGenerator::LoadSymbols()
{
    TModulesMap modules = m_process.GetModules();
    for (TModulesMap::iterator i = modules.begin(); i != modules.end(); i++)
    {
        MODULEINFO modInfo;
        ZeroMemory(&modInfo, sizeof(modInfo));

        QString strModule = i.key();

        GetModuleInformation(m_process.GetHandle(), i.value(), &modInfo, sizeof(modInfo));
        SymLoadModuleEx(
            m_process.GetHandle(),
            NULL,
            (CHAR*) i.key().toLatin1().constData(),
            (CHAR*) i.key().toLatin1().constData(),
            (DWORD64) modInfo.lpBaseOfDll,
            modInfo.SizeOfImage,
            NULL,
            0);

        LoadSymbol(strModule, (DWORD64) modInfo.lpBaseOfDll);

        if (!IsSymbolLoaded(strModule))
        {
            emit MissingSymbol(strModule);
        }
    }

    emit DebugLine(QString());
}
Example #2
0
bool MapFile::EnumerateLines(char *Start, int Type)
{
	int line	= 0;
	char *ptr	= Start;
	char *eol	= nullptr;

	for (; *ptr; ptr++)
	{
		switch (*ptr)
		{
		case '\n':
			line++;

		case '\r':
		case ' ':
		case '\t':
			continue;
		}

		// Line #0 is the heading
		if (line < 1)
			continue;

		// Terminate the line
		eol = strchr(ptr, '\r');

		if (!eol)
			eol = strchr(ptr, '\n');

		if (eol)
			*eol = '\0';

		// If the delimiter is not present, the line is not valid
		if (!strchr(ptr, ':'))
			break;

		if (Type == 'SEGM' && !LoadSegment(ptr))
			break;
		
		if (Type == 'SYMB' && !LoadSymbol(ptr))
			break;

		if (eol)
			ptr = eol + 1;
	}

	if (eol)
		*eol = '\r';

	m_FileData = ptr;
	return true;
}
Example #3
0
static entity_t *LoadPlayerEntity(char *name, int net_role)
{
	char		lib_name[MAX_OS_PATH] = "./";		// "./entites/"
	char		classname[256] = "";

	DLHANDLE	lib_handle;
	Entity		*(*GetEntityRefAPI)(game_import_t*); //typedef this
	Entity		*edict;
	
	strcat(lib_name, name);
	strcat(lib_name, SYS_DLL_ENDING);
	
	if(!(lib_handle = LoadDLibrary(lib_name)))
	{
		if(entity_info) Error("EW_LoadWorldEntity: couldn't load %s\n", lib_name);
		return NULL;
	}
	
	GetEntityRefAPI = (Entity*(*)(game_import_t*))LoadSymbol(lib_handle, "GetEntityRefAPI");
	
	gi.net_role = net_role;
/*	
	if(net_role == NR_SERVER) gi.frametime = srv_frametime;
	if(net_role == NR_CLIENT) gi.frametime = cl_frametime;
*/
	gi.frametime = &frametime;
	gi.num_entity = num_clients[net_role];

	edict = GetEntityRefAPI(&gi);
//	edict->GetClassName(classname);
	
	//add to list
	if(num_clients[net_role] >= MAX_CLIENTS) return NULL; //error handling

	WorldEntities[net_role][num_clients[net_role]] = edict;
	world_entities[net_role][num_clients[net_role]] = &edict->entity;
	world_entities[net_role][num_clients[net_role]]->num_entity = num_clients[net_role];

	world_entities[net_role][num_clients[net_role]]->client = clients[net_role] + num_clients[net_role];

	entity_libs[net_role][num_clients[net_role]] = lib_handle;

	return world_entities[net_role][num_clients[net_role]++];
}
Example #4
0
HRESULT CoreClrEmbedding::Initialize(BOOL debugMode)
{
    // Much of the CoreCLR bootstrapping process is cribbed from 
    // https://github.com/aspnet/dnx/blob/dev/src/dnx.coreclr.unix/dnx.coreclr.cpp

	DBG("CoreClrEmbedding::Initialize - Started")

    HRESULT result = S_OK;
    char currentDirectory[PATH_MAX];

#ifdef EDGE_PLATFORM_WINDOWS
    if (!_getcwd(&currentDirectory[0], PATH_MAX))
#else
    if (!getcwd(&currentDirectory[0], PATH_MAX))
#endif
    {
		throwV8Exception("Unable to get the current directory.");
        return E_FAIL;
    }

	char edgeNodePath[PATH_MAX];

#ifdef EDGE_PLATFORM_WINDOWS
    HMODULE moduleHandle = NULL;

    GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) &CoreClrEmbedding::Initialize, &moduleHandle);
    GetModuleFileName(moduleHandle, edgeNodePath, PATH_MAX);
    PathRemoveFileSpec(edgeNodePath);
#else
    Dl_info dlInfo;

	dladdr((void*)&CoreClrEmbedding::Initialize, &dlInfo);
	strcpy(edgeNodePath, dlInfo.dli_fname);
	strcpy(edgeNodePath, dirname(edgeNodePath));
#endif

    DBG("CoreClrEmbedding::Initialize - edge.node path is %s", edgeNodePath);

    void* libCoreClr = NULL;
    char bootstrapper[PATH_MAX];

    GetPathToBootstrapper(&bootstrapper[0], PATH_MAX);
    DBG("CoreClrEmbedding::Initialize - Bootstrapper is %s", bootstrapper);

    char coreClrDirectory[PATH_MAX];
    char* coreClrEnvironmentVariable = getenv("CORECLR_DIR");

    if (coreClrEnvironmentVariable)
    {
        if (coreClrEnvironmentVariable[0] == '"')
        {
            strncpy(&coreClrDirectory[0], &coreClrEnvironmentVariable[1], strlen(coreClrEnvironmentVariable) - 2);
            coreClrDirectory[strlen(coreClrEnvironmentVariable) - 2] = '\0';
        }

        else
        {
            strncpy(&coreClrDirectory[0], coreClrEnvironmentVariable, strlen(coreClrEnvironmentVariable) + 1);
        }

    	DBG("CoreClrEmbedding::Initialize - Trying to load %s from the path specified in the CORECLR_DIR environment variable: %s", LIBCORECLR_NAME, coreClrDirectory);

        LoadCoreClrAtPath(coreClrDirectory, &libCoreClr);
    }

    if (!libCoreClr)
    {
    	strncpy(&coreClrDirectory[0], currentDirectory, strlen(currentDirectory) + 1);
    	LoadCoreClrAtPath(coreClrDirectory, &libCoreClr);
    }

    if (!libCoreClr)
    {
        // Try to load CoreCLR from application path
#ifdef EDGE_PLATFORM_WINDOWS
        char* lastSlash = strrchr(&bootstrapper[0], '\\');
#else
        char* lastSlash = strrchr(&bootstrapper[0], '/');
#endif

        assert(lastSlash);
        strncpy(&coreClrDirectory[0], &bootstrapper[0], lastSlash - &bootstrapper[0]);
        coreClrDirectory[lastSlash - &bootstrapper[0]] = '\0';

        LoadCoreClrAtPath(coreClrDirectory, &libCoreClr);
    }

    if (!libCoreClr)
    {
    	std::string pathEnvironmentVariable = getenv("PATH");
#if EDGE_PLATFORM_WINDOWS
    	char delimeter = ';';
#else
    	char delimeter = ':';
#endif

    	size_t previousIndex = 0;
    	size_t currentIndex = pathEnvironmentVariable.find(delimeter);

    	while (!libCoreClr && currentIndex != std::string::npos)
    	{
    		strncpy(&coreClrDirectory[0], pathEnvironmentVariable.substr(previousIndex, currentIndex - previousIndex).c_str(), currentIndex - previousIndex);
    		coreClrDirectory[currentIndex - previousIndex] = '\0';

    		LoadCoreClrAtPath(coreClrDirectory, &libCoreClr);

    		if (!libCoreClr)
    		{
				previousIndex = currentIndex + 1;
				currentIndex = pathEnvironmentVariable.find(delimeter, previousIndex);
    		}
    	}
    }

    if (!libCoreClr)
    {
		throwV8Exception("Failed to find CoreCLR.  Make sure that you have either specified the CoreCLR directory in the CORECLR_DIR environment variable or it exists somewhere in your PATH environment variable, which you do via the \"dnvm install\" and \"dnvm use\" commands.");
        return E_FAIL;
    }

    DBG("CoreClrEmbedding::Initialize - %s loaded successfully from %s", LIBCORECLR_NAME, &coreClrDirectory[0]);

    std::string assemblySearchDirectories;

    assemblySearchDirectories.append(&currentDirectory[0]);
    assemblySearchDirectories.append(":");
    assemblySearchDirectories.append(&coreClrDirectory[0]);

    DBG("CoreClrEmbedding::Initialize - Assembly search path is %s", assemblySearchDirectories.c_str());

    coreclr_initializeFunction initializeCoreCLR = (coreclr_initializeFunction) LoadSymbol(libCoreClr, "coreclr_initialize");

    if (!initializeCoreCLR)
    {
    	throwV8Exception("Error loading the coreclr_initialize function from %s: %s.", LIBCORECLR_NAME, GetLoadError());
        return E_FAIL;
    }

    DBG("CoreClrEmbedding::Initialize - coreclr_initialize loaded successfully");
    coreclr_create_delegateFunction createDelegate = (coreclr_create_delegateFunction) LoadSymbol(libCoreClr, "coreclr_create_delegate");

    if (!createDelegate)
    {
    	throwV8Exception("Error loading the coreclr_create_delegate function from %s: %s.", LIBCORECLR_NAME, GetLoadError());
    	return E_FAIL;
    }

    DBG("CoreClrEmbedding::Initialize - coreclr_create_delegate loaded successfully");

    const char* propertyKeys[] = {
    	"TRUSTED_PLATFORM_ASSEMBLIES",
    	"APP_PATHS",
    	"APP_NI_PATHS",
    	"NATIVE_DLL_SEARCH_DIRECTORIES",
    	"AppDomainCompatSwitch"
    };

    std::string tpaList;
    AddToTpaList(coreClrDirectory, &tpaList);

    std::string appPaths(&currentDirectory[0]);
#if EDGE_PLATFORM_WINDOWS
    appPaths.append(";");
#else
    appPaths.append(":");
#endif
    appPaths.append(edgeNodePath);

    DBG("CoreClrEmbedding::Initialize - Using %s as the app path value", appPaths.c_str());

    const char* propertyValues[] = {
    	tpaList.c_str(),
        appPaths.c_str(),
        appPaths.c_str(),
        assemblySearchDirectories.c_str(),
        "UseLatestBehaviorWhenTFMNotSpecified"
    };

    DBG("CoreClrEmbedding::Initialize - Calling coreclr_initialize()");
	result = initializeCoreCLR(
			bootstrapper,
			"Edge",
			sizeof(propertyKeys) / sizeof(propertyKeys[0]),
			&propertyKeys[0],
			&propertyValues[0],
			&hostHandle,
			&appDomainId);

	if (FAILED(result))
	{
		throwV8Exception("Call to coreclr_initialize() failed with a return code of 0x%x.", result);
		return result;
	}

	DBG("CoreClrEmbedding::Initialize - CoreCLR initialized successfully");
    DBG("CoreClrEmbedding::Initialize - App domain created successfully (app domain ID: %d)", appDomainId);

    SetCallV8FunctionDelegateFunction setCallV8Function;

    CREATE_DELEGATE("GetFunc", &getFunc);
    CREATE_DELEGATE("CallFunc", &callFunc);
    CREATE_DELEGATE("ContinueTask", &continueTask);
    CREATE_DELEGATE("FreeHandle", &freeHandle);
    CREATE_DELEGATE("FreeMarshalData", &freeMarshalData);
    CREATE_DELEGATE("SetCallV8FunctionDelegate", &setCallV8Function);
    CREATE_DELEGATE("CompileFunc", &compileFunc);
	CREATE_DELEGATE("Initialize", &initialize);

	DBG("CoreClrEmbedding::Initialize - Getting runtime info");

	CoreClrGcHandle exception = NULL;
	BootstrapperContext context;

	context.runtimeDirectory = &coreClrDirectory[0];
	context.applicationDirectory = getenv("EDGE_APP_ROOT");
	context.edgeNodePath = &edgeNodePath[0];

	if (!context.applicationDirectory)
	{
		context.applicationDirectory = &currentDirectory[0];
	}

	std::string operatingSystem = GetOSName();
	std::string operatingSystemVersion = GetOSVersion();

	context.architecture = GetOSArchitecture();
	context.operatingSystem = operatingSystem.c_str();
	context.operatingSystemVersion = operatingSystemVersion.c_str();

	DBG("CoreClrEmbedding::Initialize - Operating system: %s", context.operatingSystem);
	DBG("CoreClrEmbedding::Initialize - Operating system version: %s", context.operatingSystemVersion);
	DBG("CoreClrEmbedding::Initialize - Architecture: %s", context.architecture);
	DBG("CoreClrEmbedding::Initialize - Runtime directory: %s", context.runtimeDirectory);
	DBG("CoreClrEmbedding::Initialize - Application directory: %s", context.applicationDirectory);

	DBG("CoreClrEmbedding::Initialize - Calling CLR Initialize() function");

	initialize(&context, &exception);

	if (exception)
	{
		v8::Local<v8::Value> v8Exception = CoreClrFunc::MarshalCLRToV8(exception, V8TypeException);
		FreeMarshalData(exception, V8TypeException);

		throwV8Exception(v8Exception);
	}

	else
	{
		DBG("CoreClrEmbedding::Initialize - CLR Initialize() function called successfully")
	}

	exception = NULL;
	setCallV8Function(CoreClrNodejsFunc::Call, &exception);

	if (exception)
	{
		v8::Local<v8::Value> v8Exception = CoreClrFunc::MarshalCLRToV8(exception, V8TypeException);
		FreeMarshalData(exception, V8TypeException);

		throwV8Exception(v8Exception);
	}

	else
	{
		DBG("CoreClrEmbedding::Initialize - CallV8Function delegate set successfully");
	}

	DBG("CoreClrEmbedding::Initialize - Completed");

    return S_OK;
}