Example #1
0
void ProcessModuleData(Module *module)
{
	int i = 0;
	PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)module->base;
	if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) {
		regamedll_syserror(__FUNCTION__": Invalid DOS header signature");
		return;
	}

	PIMAGE_NT_HEADERS NTHeaders = (PIMAGE_NT_HEADERS)((size_t)module->base + dosHeader->e_lfanew);
	if (NTHeaders->Signature != 0x4550) {
		regamedll_syserror(__FUNCTION__": Invalid NT header signature");
		return;
	}

	PIMAGE_SECTION_HEADER cSection = (PIMAGE_SECTION_HEADER)((size_t)(&NTHeaders->OptionalHeader) + NTHeaders->FileHeader.SizeOfOptionalHeader);

	PIMAGE_SECTION_HEADER CodeSection = NULL;

	for (i = 0; i < NTHeaders->FileHeader.NumberOfSections; i++, cSection++) {
		if (cSection->VirtualAddress == NTHeaders->OptionalHeader.BaseOfCode)
			CodeSection = cSection;
	}

	if (CodeSection == NULL) {
		regamedll_syserror(__FUNCTION__": Code section not found");
		return;
	}

	module->codeSection.start = (uint32_t)module->base + CodeSection->VirtualAddress;
	module->codeSection.size = CodeSection->Misc.VirtualSize;
	module->codeSection.end = module->codeSection.start + module->codeSection.size;
	module->codeSection.next = NULL;
}
Example #2
0
void VirtualTableInit(void *ptr, const char *baseClass)
{
	if (!baseClass || *baseClass == '\0')
	{
		return;
	}

	VirtualTableRef *refsVtbl = GetVirtualTableRefAddr(baseClass);
	if (!refsVtbl)
	{
		regamedll_syserror(__FUNCTION__": Missing vtable for \"%s\"", baseClass);
	}

	/*
	int nCount = vtable_size(refsVtbl->originalAddress);

	if (nCount != refsVtbl->size)
		regamedll_syserror(__FUNCTION__": Invalid size virtual table, expected [%d], got [%d]", nCount, refsVtbl->size);
	*/

	int **ivtable = *(int ***)ptr;
	int **ivtable_orig = (int **)refsVtbl->originalAddress;

	for (size_t i = 0; i < refsVtbl->size; i++)
	{
		if (!GetAddressUsingHook((size_t)ivtable_orig[i]))
		{
			EnablePageWrite((size_t)&ivtable[i], 5);
			ivtable[i] = ivtable_orig[i];
			RestorePageProtection((size_t)&ivtable[i], 5);
		}
	}
}
Example #3
0
void CRegameDLLRuntimeConfig::parseFromCommandLine(const char *cmdLine)
{
    char localBuf[2048];
    if (strlen(cmdLine) >= sizeof(localBuf))
        regamedll_syserror("%s: too long cmdline", __FUNCTION__);

    strcpy(localBuf, cmdLine);
    char *cpos = localBuf;

    getNextToken(&cpos); //skip executable path

    const char *token = getNextToken(&cpos);
    while (token != NULL)
    {
        if (!strcmp(token, "--regamedll-test-record"))
        {
            const char *fname = getNextToken(&cpos);

            if (fname == NULL)
                regamedll_syserror("%s: usage: --regamedll-test-record <filename>", __FUNCTION__);

            strncpy(testRecordingFileName, fname, sizeof(testRecordingFileName));
            testRecordingFileName[sizeof(testRecordingFileName) - 1] = 0;
            testPlayerMode = TPM_RECORD;
        }
        else if (!strcmp(token, "--regamedll-test-play"))
        {
            const char *fname = getNextToken(&cpos);

            if (fname == NULL)
                regamedll_syserror("%s: usage: --regamedll-test-play <filename>", __FUNCTION__);

            strncpy(testRecordingFileName, fname, sizeof(testRecordingFileName));
            testRecordingFileName[sizeof(testRecordingFileName) - 1] = 0;
            testPlayerMode = TPM_PLAY;
        }
        else if (!strcmp(token, "--regamedll-cfg-init"))
        {
            const char *fname = getNextToken(&cpos);

            if (fname != NULL)
            {
                strncpy(testConfigFileName, fname, sizeof(testConfigFileName));
                testConfigFileName[sizeof(testConfigFileName) - 1] = 0;
            }
        }
        else if (!strcmp(token, "--regamedll-disable-all-hooks"))
        {
            disableAllHooks = true;
        }
        else if (!strcmp(token, "-game"))
        {
            const char *szTokenGame = getNextToken(&cpos);

            if (szTokenGame != NULL && !strcmp(szTokenGame, "czero"))
                bIsZero = true;
        }

        token = getNextToken(&cpos);
    }

    // parse config filename for testdemo
    parseFromConfigFile();
}