Example #1
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    SERVICE_TABLE_ENTRY ste[2];
#ifdef _DEBUG
    FILE *fp;
#endif

    GetIlevel();

    if(ilevel < 4) {
        TryRaiseIlevel();
    } else {
        ste[0].lpServiceName = TEXT(SERVICE_NAME);
        ste[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;
        ste[1].lpServiceName = NULL;
        ste[1].lpServiceProc = NULL;

        if(StartServiceCtrlDispatcher(ste) > 0)
            return 0;
    }

    EntryPoint();

#ifdef _DEBUG
    if((fp = fopen("memlog.txt", "w")) != NULL) {
        showmemstats(fp);
        fclose(fp);
    }
#endif

    return 0;
}
Example #2
0
void ServiceMain(DWORD dwArgc, LPSTR *lpszArgv) {
    SERVICE_STATUS_HANDLE ssh = RegisterServiceCtrlHandlerA(SERVICE_NAME, &Handler);
    SERVICE_STATUS ss;

    if(ssh == (SERVICE_STATUS_HANDLE)0)
        return;

    ss.dwCheckPoint = 0;
    ss.dwControlsAccepted = 0;
    ss.dwCurrentState = SERVICE_RUNNING;
    ss.dwServiceType = SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS;
    ss.dwWaitHint = 0;
    ss.dwWin32ExitCode = NO_ERROR;

    SetServiceStatus(ssh, &ss);

    EntryPoint();

    ss.dwCheckPoint = 0;
    ss.dwControlsAccepted = 0;
    ss.dwCurrentState = SERVICE_STOPPED;
    ss.dwServiceType = SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS;
    ss.dwWaitHint = 0;
    ss.dwWin32ExitCode = NO_ERROR;

    SetServiceStatus(ssh, &ss);
}
Example #3
0
void WServer::addEntryPoint(EntryPointType type, ApplicationCreator callback,
			    const std::string& path, const std::string& favicon)
{
  if (!path.empty() && !boost::starts_with(path, "/")) 
    throw WServer::Exception("WServer::addEntryPoint() error: "
			     "deployment path should start with \'/\'");

  configuration().addEntryPoint(EntryPoint(type, callback, path, favicon));
}
HANDLE WINAPI _export OpenPlugin(int OpenFrom,INT_PTR Item)
{
	if (InfoA == NULL)
		return INVALID_HANDLE_VALUE;

	ReloadResourcesA();
	EntryPoint(OpenFrom, Item, false);
	return INVALID_HANDLE_VALUE;
}
Example #5
0
void WServer::addResource(WResource *resource, const std::string& path)
{
  if (!boost::starts_with(path, "/")) 
    throw WServer::Exception("WServer::addResource() error: "
			     "static resource path should start with \'/\'");

  resource->setInternalPath(path);

  configuration().addEntryPoint(EntryPoint(resource, path));
}
TInt E32Main()
/**
Server process entry-point
Recover the startup parameters and run the server
**/
	{
	TServerStart start;
	TInt r=start.GetCommand();
	if (r==KErrNone)
		r=EntryPoint((TAny*)&start);
	return r;
	}
Example #7
0
int WINAPI WinMain(HINSTANCE _0, HINSTANCE _1, LPSTR _2, int _3)
{
#ifdef ENABLE_LOG
	AllocConsole();
	SetConsoleTitle("PIANO - console");

	#pragma warning(push)
	#pragma warning(disable: 4996)
	freopen("CONOUT$", "w+t", stdout);
	freopen("CONIN$", "r+t", stdin);
	#pragma warning(pop)
#endif

	return EntryPoint();
}
Example #8
0
int C_App::Launch (const void * Data, const char * CmdLine)
{
	void (*EntryPoint)();
	
	u32 Level = 0;
	
	EntryPoint = (void (*)()) this->Load(Data, CmdLine, APP_ACTION_PRELOAD);
	if (EntryPoint == NULL) { return 0; }

	EntryPoint = (void(*)()) this->Load (Data, NULL, APP_ACTION_RUN);

	//BeforeExit();
	SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
	_CPU_ISR_Disable (Level);
	EntryPoint();
	
	return 1;
}
Example #9
0
void WServer::addResource(WResource *resource, const std::string& path)
{
    if (!boost::starts_with(path, "/"))
        throw WServer::Exception("WServer::addResource() error: "
                                 "static resource path should start with \'/\'");

    std::vector<EntryPoint> entryPoints = configuration().entryPoints();
    for (unsigned i = 0; i < entryPoints.size(); ++i) {
        if (entryPoints[i].resource() &&
                entryPoints[i].resource()->internalPath() == path) {
            WString error("WServer::addResource() error: "
                          "a static resource was already deployed on path '{1}'");
            throw WServer::Exception(error.arg(path).toUTF8());
        }
    }

    resource->setInternalPath(path);

    configuration().addEntryPoint(EntryPoint(resource, path));
}
Example #10
0
/*
 * Sys_LoadLibrary
 *
 * Opens and loads the specified shared library. The function identified by
 * entry_point is resolved and invoked with the specified parameters, its
 * return value returned by this function.
 */
void *Sys_LoadLibrary(const char *name, void **handle, const char *entry_point,
		void *params) {
	typedef void *entry_point_t(void *);
	entry_point_t *EntryPoint;

	if (*handle) {
		Com_Warn("Sys_LoadLibrary: %s: handle already open\n", name);
		Sys_CloseLibrary(handle);
	}

	Sys_OpenLibrary(name, handle);

	EntryPoint = (entry_point_t *) dlsym(*handle, entry_point);

	if (!EntryPoint) {
		Sys_CloseLibrary(handle);
		Com_Error(ERR_DROP, "Sys_LoadLibrary: %s: Failed to resolve %s\n",
				name, entry_point);
	}

	return EntryPoint(params);
}
BOOL WINAPI APIENTRY DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved)
{
	switch (dwReason)
	{
	case DLL_QUERY_HMODULE:
		hAppInstance = hinstDLL;
		if (lpReserved != NULL)
		{
			*(HMODULE *)lpReserved = hAppInstance;
		}
		break;
	case DLL_PROCESS_ATTACH:
		hAppInstance = hinstDLL;
		EntryPoint(lpReserved);
		break;
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
Example #12
0
 static nsIGlobalObject* EntryGlobal() {
   ScriptSettingsStackEntry *entry = EntryPoint();
   return entry ? entry->mGlobalObject : nullptr;
 }
Example #13
0
int MakePE()
{
	unsigned short numobj = 1;
	char* importblock = NULL;
	char* relocblock = NULL;
	char* exportblock = NULL;
	unsigned long psize, vsize = 0, sizereloc = 0, sizeReloc = 0, sizeImport = 0, sizeExport = 0,
						 sizebss = 0, sizeRes = 0;
	unsigned long startsec = 0, startsecr = 0, startsece = 0, startsecres = 0;
	unsigned int posrel = 0, sizeimport = 0, startimportname = 0, sizeexport = 0, sizeres = 0,
				 startexportname = 0;
	unsigned int sizehead;	//размер заголовка
	unsigned int exportnum = 0; //номер секции экспорта
	unsigned int relocnum = 0;	//номер секции перемещений
	unsigned int importnum = 0;	//номер секции импорта
	unsigned int codenum = 0;	//номер секции кода
	unsigned int resnum = 0;	//номер секции ресурсов

	if (hout == NULL)
	{
		return -1;
	}

	if (WinMonoBlock == FALSE)
	{
		vsize = Align(outptr + (wbss == FALSE ? postsize : 0), OBJECTALIGN); //виртуальный размер секции кода
		psize = Align(outptr, FILEALIGN);	//физический размер секции кода
	}
	else
	{
		vsize = outptr;
		psize = Align(outptr, FILEALIGN);	//физический размер секции кода
	}

	//	sizehead=((postsize&&wbss)?2:1)*sizeof(OBJECT_ENTRY);
	sizehead = numrs * sizeof(OBJECT_ENTRY);
	OBJECT_ENTRY* objentry = (OBJECT_ENTRY*)MALLOC(sizehead); //тавлица объектов
	memset(objentry, 0, sizehead); //очистить таблицу объектов

	//секция .bss
	if (wbss) 	//есть post переменные
	{
		numobj++;     //увеличиваем число объектов
		codenum = 1;	//номер секции кода
		strcpy(objentry->name, ".bss"); //имя секции
		objentry->vsize = sizebss = Align(postsize, OBJECTALIGN);
		objentry->pOffset = objentry->psize = 0;
		objentry->flags = 0xC0000080;
		objentry->sectionRVA = vsizeheader;
	}

	strcpy((objentry + codenum)->name, "CODE");	//ее имя
	(objentry + codenum)->vsize = vsize;      //размер секции в памяти
	(objentry + codenum)->psize = psize;      //размер секции в файле
	(objentry + codenum)->flags = 0xe0000060; //флаг секции
	(objentry + codenum)->sectionRVA = vsizeheader + sizebss; //виртуальный адрес секции в памяти

	//секция импорта
	if (numapi != 0) 	//есть вызовы api-процедур созд секцию импорта
	{
		if (!WinMonoBlock) 	//если не единый блок
		{
			importnum = numobj;
			numobj++;     //увеличиваем число объектов
		}

		startsec = vsizeheader + vsize + sizebss;	//начало секции в памяти
		//реальный размер секции
		startimportname = (numdll + 1) * 20 + (numapi + numdll) * (shortimport == 0 ? 8 : 4);
		sizeimport = Align(startimportname, FILEALIGN);	//размер секции в памяти
		importblock = (char*)MALLOC(sizeimport);	//память под нее
		memset(importblock, 0, sizeimport);	//очистить ее
		DLLLIST* newdll = listdll;	//табличка dll с импортируемыми процедурами
		unsigned long sn, sn1;
		sn1 = sn = (numdll + 1) * 20;

		for (int i = 0;; i++)
		{
			while (newdll->num == 0)if ((newdll = newdll->next) == NULL)
				{
					break;    //пропуск неиспользуемых
				}

			if (newdll == NULL)
			{
				break;    //завершить цикл если список dll пуст
			}

			APIPROC* listapi = newdll->list;	//табличка процедур из текущей dll
			*(long*)&importblock[i * 20 + 12] = startsec + startimportname;
			*(long*)&importblock[i * 20] = (shortimport == 0 ? startsec + sn : 0);
			*(long*)&importblock[i * 20 + 16] = startsec + sn + (shortimport == 0 ? (numdll + numapi) * 4 : 0);
			sn += (newdll->num + 1) * 4;
			unsigned int lenn = strlen(newdll->name) + 1;

			if ((lenn + startimportname + 1) >= sizeimport)
			{
				sizeimport += FILEALIGN;	//увеличить размер секции
				importblock = (char*)REALLOC(importblock, sizeimport);
				memset(importblock + sizeimport - FILEALIGN, 0, FILEALIGN);
			}

			strcpy(&importblock[startimportname], newdll->name);
			startimportname += lenn;

			for (int n = 0, t = 0; n < newdll->num; n++, t++)
			{
				while ((listapi + t)->recapi->recrm == 0)
				{
					t++;
				}

				idrec* rec = (listapi + t)->recapi;
				unsigned long newadr;
				newadr = ImageBase + startsec + sn1 + (shortimport == 0 ? (numdll + numapi) * 4 : 0);

				if (rec->recrm == API_JMP)
				{
					*(long*)&output[rec->recnumber] = newadr;
				}
				else
				{
					for (unsigned int j = 0; j < posts; j++) 	//поиск использования процедуры
					{
						if ((postbuf + j)->num == (unsigned long)rec->recnumber && (postbuf + j)->type == CALL_32I)
						{
							*(long*)&output[(postbuf + j)->loc] = newadr;	//исправить
						}
					}
				}

				if (useordinal && rec->recsib != -1)
				{
					*(long*)&importblock[sn1] = rec->recsib | 0x80000000;

					if (shortimport == 0)
					{
						*(long*)&importblock[sn1 + (numdll + numapi) * 4] = rec->recsib | 0x80000000;
					}
				}
				else
				{
					if ((startimportname % 2) == 1)
					{
						importblock[startimportname++] = 0;
					}

					*(long*)&importblock[sn1] = startsec + startimportname;

					if (shortimport == 0)
					{
						*(long*)&importblock[sn1 + (numdll + numapi) * 4] = startsec + startimportname;
					}

					if (rec->recsize != -1)
					{
						sprintf((char*)string2, "%s@%u", rec->recid, rec->recsize);
					}
					else
					{
						strcpy((char*)string2, rec->recid);
					}

					lenn = strlen((char*)string2) + 1;

					if ((lenn + startimportname + 4) >= sizeimport)
					{
						sizeimport += FILEALIGN;
						importblock = (char*)REALLOC(importblock, sizeimport);
						memset(importblock + sizeimport - FILEALIGN, 0, FILEALIGN);
					}

					*(short*)&importblock[startimportname] = 0;
					startimportname += 2;
					strcpy(&importblock[startimportname], (char*)string2);
					startimportname += lenn;
				}

				sn1 += 4;
			}

			if (newdll->next == NULL)
			{
				break;
			}

			newdll = newdll->next;
			sn1 += 4;
		}

		importblock[startimportname++] = 0;

		if (!WinMonoBlock) 	//если не единый блок
		{
			strcpy((objentry + importnum)->name, ".idata"); //имя секции
			(objentry + importnum)->vsize = sizeImport = Align(sizeimport, OBJECTALIGN);
			(objentry + importnum)->psize = sizeimport;
			(objentry + importnum)->flags = 0xC0000040;
			(objentry + importnum)->sectionRVA = startsec;
		}
		else
		{
			sizeImport = sizeimport = Align(startimportname, 4);
		}
	}

	//секция экспорта
	if (numexport != 0)
	{
		if (!WinMonoBlock) 	//если не единый блок
		{
			exportnum = numobj;
			numobj++;     //увеличиваем число объектов
		}

		startsece = vsizeheader + vsize + sizeImport + sizebss; //начало секции в памяти
		startexportname = sizeof(EXPORT_TABLE) + numexport * 10; //реальный размер секции
		sizeexport = Align(startexportname, FILEALIGN);	//размер секции в памяти
		exportblock = (char*)MALLOC(sizeexport);	//память под нее
		memset(exportblock, 0, sizeexport);	//очистить ее
		*(long*)&exportblock[12] = startsece + startexportname; //адрес имени файла
		*(long*)&exportblock[16] = 1;	//Ordinal Base
		*(long*)&exportblock[20] = numexport;	//Num of Functions
		*(long*)&exportblock[24] = numexport;	//Num of Name Pointer
		*(long*)&exportblock[28] = startsece + sizeof(EXPORT_TABLE); //Address Table RVA
		*(long*)&exportblock[32] = startsece + sizeof(EXPORT_TABLE) + numexport * 4; //Name Pointers RVA
		*(long*)&exportblock[36] = startsece + sizeof(EXPORT_TABLE) + numexport * 8; //Ordinal Table RVA
		char* oname;
		strcpy((char*)string2, (char*)rawfilename);
		oname = strrchr((char*)string2, '\\');

		if (oname == NULL)
		{
			oname = (char*)string2;
		}
		else
		{
			oname = oname + 1;
		}

		sprintf((char*)string, "%s.%s", oname, outext);
		unsigned int lenn = strlen((char*)string) + 1;

		if ((lenn + startexportname + 1) >= sizeexport)
		{
			sizeexport += FILEALIGN;	//увеличить размер секции
			exportblock = (char*)REALLOC(exportblock, sizeexport);
			memset(exportblock + sizeexport - FILEALIGN, 0, FILEALIGN);
		}

		strcpy(&exportblock[startexportname], (char*)string);
		startexportname += lenn;

		for (int i = 0; i < numexport; i++)
		{
			*(long*)&exportblock[sizeof(EXPORT_TABLE) + i * 4] = (lexport + i)->address + vsizeheader + sizebss;	//адреса функций
			*(long*)&exportblock[sizeof(EXPORT_TABLE) + (numexport + i) * 4] = startsece + startexportname;	//адреса имен
			*(short*)&exportblock[sizeof(EXPORT_TABLE) + numexport * 8 + i * 2] = (short)i;	//ординалы имен
			lenn = strlen((lexport + i)->name) + 1;

			if ((lenn + startexportname + 1) >= sizeexport)
			{
				sizeexport += FILEALIGN;	//увеличить размер секции
				exportblock = (char*)REALLOC(exportblock, sizeexport);
				memset(exportblock + sizeexport - FILEALIGN, 0, FILEALIGN);
			}

			strcpy(&exportblock[startexportname], (lexport + i)->name);
			startexportname += lenn;
		}

		free(lexport);//освободим уже не нужный блок

		if (!WinMonoBlock) 	//если не единый блок
		{
			strcpy((objentry + exportnum)->name, ".edata"); //имя секции
			(objentry + exportnum)->vsize = sizeExport = Align(sizeexport, OBJECTALIGN);
			(objentry + exportnum)->psize = sizeexport;
			(objentry + exportnum)->flags = 0x40000040;
			(objentry + exportnum)->sectionRVA = startsece;
		}
		else
		{
			sizeexport = sizeExport = Align(startexportname, 4);
		}
	}

	if (numres) 	//секция ресурсов
	{
		if (WinMonoBlock == FALSE) 	//если не единый блок
		{
			resnum = numobj;
			numobj++;                     //увеличить число объектов
		}

		startsecres = vsizeheader + vsize + sizeImport + sizebss + sizeExport; //начало секции в памяти
		LISTRELOC* resrel;

		if (MakeRes(startsecres, &resrel))
		{
			free(resrel);
		}

		if (!WinMonoBlock) 	//если не единый блок
		{
			strcpy((objentry + resnum)->name, ".rsrc"); //имя секции
			(objentry + resnum)->vsize = sizeRes = Align(curposbuf, OBJECTALIGN);
			(objentry + resnum)->psize = sizeres = Align(curposbuf, FILEALIGN);
			(objentry + resnum)->flags = 0x40000040;
			(objentry + resnum)->sectionRVA = startsecres;
		}
		else
		{
			sizeres = Align(curposbuf, 4);
		}
	}

	//секция таблиц перемещения
	if ((FixUpTable == TRUE && numrel != 0)/*||numexport!=0*/) //создать секцию перемещения
	{
		if (WinMonoBlock == FALSE || dllflag == TRUE) 	//если не единый блок и это DLL
		{
			relocnum = numobj;
			numobj++;                     //увеличить число объектов
		}

		if (WinMonoBlock && dllflag)startsecr = vsizeheader +
													Align(sizeimport + sizeexport + outptr + (wbss == FALSE ? postsize : 0) + sizebss + sizeres, OBJECTALIGN);
		else
		{
			startsecr = vsizeheader + vsize + sizeImport + sizeExport + sizebss + sizeres;    //виртуальный адрес секции в памяти
		}

		//физический размер секции таблицы перемещений
		sizereloc = Align(numrel * 2 + (outptr / 4096 + 1) * 10, FILEALIGN);
		sizeReloc = Align(sizereloc, OBJECTALIGN); //виртуальный размер этой секции
		relocblock = (char*)MALLOC(sizereloc);	//память под эту секцию
		memset(relocblock, 0, sizereloc);	//очистить ее
		//заполняем секцию перемещения
		unsigned int startrsec = 0;	//адрес начала блока в секции перемещения
		unsigned int startblc = 0;	//адрес первого блока
		posrel = 8;

		do
		{
			unsigned char fr = FALSE;	//флаг элемента

			for (unsigned int i = 0; i < posts; i++) 	//обходим всю таблицу post
			{
				if (
					(
						(postbuf + i)->type == CALL_32I ||
						((postbuf + i)->type >= POST_VAR32 && (postbuf + i)->type <= FIX_CODE32))
					&&
					(postbuf + i)->loc >= startblc && (postbuf + i)->loc < (startblc + 4096))
				{
					*(short*)&relocblock[posrel] = (short)((postbuf + i)->loc % 4096 | 0x3000);
					posrel += 2;
					fr = TRUE;
				}
			}

			if (fr != FALSE) 	//если были перемещаемые адреса
			{
				posrel += posrel % 4;	//выравниваем
				*(long*)&relocblock[startrsec] = vsizeheader + sizebss + startblc;
				*(long*)&relocblock[startrsec + 4] = posrel - startrsec;	//размер куска
				startrsec = posrel;
				posrel += 8;
			}

			startblc += 4096;
		}
		while (startblc < vsize);

		posrel -= 8;

		if (WinMonoBlock == FALSE || dllflag == TRUE) 	//если не единый блок
		{
			strcpy((objentry + relocnum)->name, ".reloc");	//имя секции
			(objentry + relocnum)->vsize = sizeReloc;    //размер секции в памяти
			(objentry + relocnum)->psize = sizereloc;    //размер секции в файле
			(objentry + relocnum)->flags = 0x52000040;   //флаг секции
			(objentry + relocnum)->sectionRVA = startsecr; //виртуальный адрес секции в памяти
		}
		else
		{
			sizereloc = Align(posrel, 4);
		}
	}

	if (WinMonoBlock)
	{
		psize = sizeimport + sizeexport + (dllflag == FALSE ? sizereloc : 0) + sizeres;	//размер дополнительных данных

		if (wbss == 0)
		{
			for (unsigned int i = 0; i < posts; i++)
			{
				if ((postbuf + i)->type == POST_VAR32)
				{
					*(long*)&output[(postbuf + i)->loc] += psize;
				}
			}
		}

		psize += outptr;
		(objentry + codenum)->vsize = vsize = Align(psize + (wbss == FALSE ? postsize : 0), OBJECTALIGN); //виртуальный размер секции кода
		filingzerope = (objentry + codenum)->psize = Align(psize, FILEALIGN);	//физический размер секции кода
		filingzerope -= psize;
		psize = (objentry + codenum)->psize;
		sizeImport = sizeExport = 0;

		if (dllflag == FALSE)
		{
			sizeReloc = 0;
		}
	}

	PE_HEADER* peheader = (PE_HEADER*)MALLOC(sizeof(PE_HEADER));
	memset(peheader, 0, sizeof(PE_HEADER));
	sizehead = Align(sizeof(PE_HEADER) + sizestub + (numobj + (numres != 0 ? 0 : 1)) * sizeof(OBJECT_ENTRY), FILEALIGN);
	peheader->sign = 'P' + ('E' << 8);
	peheader->cpu = 0x14c; //(chip>=4?(chip>=5?0x14e:0x14D):0x14c);
	//	peheader->date_time=0;
	peheader->DLLflag = dllflag;
	peheader->numobj = numobj;
	peheader->NTheadsize = 0xe0;
	peheader->flags = (short)(0x818e | (dllflag == 0 ? 0 : 0x2000));
	peheader->Magic = 0x10b;
	peheader->LinkVer = (short)((short)ver2 * 256 + ver1);
	peheader->sizecode = psize;
	peheader->sizeuninitdata = postsize;
	{
		unsigned int temp;
		temp = EntryPoint();

		if (temp == 0xffffffff)
		{
			peheader->EntryRVA = 0;
		}
		else
		{
			peheader->EntryRVA = vsizeheader + sizebss + temp;
		}
	}
	peheader->basecode = vsizeheader + sizebss;
	peheader->objAlig = OBJECTALIGN;
	peheader->fileAlig = FILEALIGN;
	peheader->OSver = 1;
	peheader->SubSysVer = 4;
	peheader->ImageBase = ImageBase;
	peheader->headsize = sizehead;
	peheader->imagesize = vsizeheader +	//размер заголовка
						  vsize +	//размер кода
						  sizebss +		//размер post блока
						  sizeReloc +	//размер таблицы перемещения
						  sizeImport + //размер таблицы импорта
						  sizeRes +	//размер таблицы ресурсов
						  sizeExport;//размер таблицы экспорта
	peheader->SubSys = (short)(2 + wconsole);	//GUIWIN
	peheader->stackRezSize = stacksize * 0x10;
	peheader->stackComSize = stacksize;
	peheader->heapRezSize = 0x10000;
	peheader->heapComSize = 0x1000; //postsize;	//????
	peheader->numRVA = 0x10;

	if (!usestub)
	{
		peheader->basedata = 12;
		peheader->pCOFF = 0x40;
	}

	(objentry + codenum)->pOffset = sizehead;

	if (numapi)
	{
		if (!WinMonoBlock)
		{
			(objentry + importnum)->pOffset = sizehead + psize;
		}

		peheader->importRVA = startsec;
		peheader->importSize = startimportname;
	}

	if (numexport)
	{
		if (!WinMonoBlock)
		{
			(objentry + exportnum)->pOffset = sizehead + psize + sizeimport;
		}

		peheader->exportRVA = startsece;
		peheader->exportSize = startexportname;
	}

	if (numres)
	{
		if (!WinMonoBlock)
		{
			(objentry + resnum)->pOffset = sizehead + psize + sizeimport + sizeexport;
		}

		peheader->resourRVA = startsecres;
		peheader->resourSize = curposbuf;
	}

	if (posrel)
	{
		if (!WinMonoBlock)
		{
			(objentry + relocnum)->pOffset = sizehead + psize + sizeimport + sizeexport + sizeres;
		}
		else if (dllflag)
		{
			(objentry + relocnum)->pOffset = sizehead + psize;
		}

		peheader->fixupRVA = startsecr;
		peheader->fixupSize = posrel;
	}

	if (fwrite(peheader, sizeof(PE_HEADER), 1, hout) != 1)
	{
errwrite:
		ErrWrite();
		fclose(hout);
		hout = NULL;
		return (-1);
	}

	if (fwrite(objentry, sizeof(OBJECT_ENTRY)*numobj, 1, hout) != 1)
	{
		goto errwrite;
	}

	ChSize(sizehead);
	runfilesize = sizehead + psize;
	outputcodestart = ftell(hout);

	if (fwrite(output, outptr, 1, hout) != 1)
	{
		goto errwrite;    //блок кода
	}

	if (!WinMonoBlock)
	{
		filingzerope = psize - outptr;
		ChSize(runfilesize);
	}

	if (numapi)
	{
		if (fwrite(importblock, sizeimport, 1, hout) != 1)
		{
			goto errwrite;
		}

		free(importblock);
	}

	if (numexport)
	{
		if (fwrite(exportblock, sizeexport, 1, hout) != 1)
		{
			goto errwrite;
		}

		free(exportblock);
	}

	if (numres)
	{
		if (fwrite(resbuf, sizeres, 1, hout) != 1)
		{
			goto errwrite;
		}

		free(resbuf);
	}

	if (posrel)
	{
		if (WinMonoBlock && dllflag)
		{
			ChSize(runfilesize);
		}

		if (fwrite(relocblock, sizereloc, 1, hout) != 1)
		{
			goto errwrite;
		}

		free(relocblock);
	}

	if (WinMonoBlock)
	{
		if (dllflag)
		{
			runfilesize += sizereloc;
		}
	}
	else
	{
		runfilesize += sizereloc + sizeimport + sizeexport + sizeres;
	}

	ChSize(runfilesize);
	free(peheader);
	free(objentry);
	fclose(hout);
	hout = NULL;
	ImageBase += vsizeheader + sizebss;	//изм размер для листинга
	return 0;
}
Example #14
0
	int main(int argc, char*argv[]) {
		std::string dir = "cool";
		EntryPoint i_like = EntryPoint(dir);
		
		Game the_game = Game(i_like);
	}
Example #15
0
int CreateW32Debug()
{
int sstNames,sstDirectory;
int	startcode=outptr;
int sstGlobalSym;
int sstsrc;
unsigned int i,j,jj,ofs;
	for(;numsymbols<(short)totalmodule;numsymbols++)AddNameToPul((startfileinfo+numsymbols)->filename);
	segcode=(wbss==FALSE?1:2);
	outptr=0;
	outdword(0x41304246); 	 // TDS - signature
	outdword(0);		// offset of Subsection Directory (fill later)
//sstModule subsection
	outdword(0);		// OvlNum=0 & LibIndex=0
	outword(segcode); 			 // SegCount
	outword(0x5643); 			 // CV-style
	outdword(1);		// Name
	for(i=0;i<4;i++)outdword(0);
//	outdword(0);	//Time
//	outdword(0);
//	outdword(0);
//	outdword(0);
	if(wbss){
		outword(0x0001); 			 // SegNumber
		outword(0); 			 // flag
		outdword(0);		// start
		outdword(postsize); // len
	}
	outword(segcode); 			 // SegNumber
	outword(0x0001); 			 // flag
	outdword(startptr);		// start
	outdword(startcode); // len
	sstsrc=outptr;
//sstSrcModule subsection
	outword((short)numcorrel);  //cFile - количество SRC-файлов(сегментов)
	outword((short)numcorrel);  // SegCount (see SegCount in sstModule
	ofs=14*numcorrel+4;
	for(i=0,jj=0;i<(unsigned int)numcorrel;i++){
		if(i!=0)jj=jj+((corinfo+i-1)->count+1)*6+22;
		outdword(ofs+jj);
	}
	for(i=0;i<(unsigned int)numcorrel;i++){
		outdword((corinfo+i)->ofs);
		outdword((corinfo+i)->end);
	}
	for(i=0;i<(unsigned int)numcorrel;i++)outword(segcode); // массив индексов сегментов
	for(i=0;i<(unsigned int)numcorrel;i++){
		outword(1); 	 // Segm#
		outdword((corinfo+i)->file+1);// File#
		outdword(outptr-sstsrc+12);
		outdword((corinfo+i)->ofs);
		outdword((corinfo+i)->end);
		outword(segcode); 	 //Segm#
		jj=(corinfo+i)->count;
		outword(jj+1); 	 // Lines count
		ofs=(corinfo+i)->startline;
		for(j=0;j<jj;j++)outdword(dbgloc[j+ofs]);
		outdword((corinfo+i)->end);
		for(j=0;j<jj;j++)outword(dbgnum[j+ofs]);
		outword(0);
	}
//таблица глобальных символов
	sstGlobalSym=outptr;
	for(i=0;i<8;i++)outdword(0);
//	outdword(0);	//modindex
//	outdword(0);	//size correct later
//	outdword(0);
//	outdword(0);
//	outdword(0);
//	outdword(0);	//num others correct later
//	outdword(0);	//total correct later
//	outdword(0);	//SymHash,  AddrHash
	outdword(0x02100008);	//S_ENTRY32
	outdword(EntryPoint());
	outword(segcode);
	AddGlobalName(treestart);
	sstNames=outptr;
	outdword(numsymbols);
	outptr=sstGlobalSym+4;
	outdword(sstNames-sstGlobalSym-32);
	outptr+=12;
	outdword(numsymbols-totalmodule);
	outdword(numsymbols-totalmodule);
	outptr=4;
	sstDirectory=sstNames+4+lastofspul;
	outdword(sstDirectory);
	if(fwrite(output,sstNames+4,1,hout)!=1)return -1;
	if(fwrite(bufname,lastofspul,1,hout)!=1)return -1;
	free(bufname);
// Subsection Directory
	outptr=0;
	outdword(0x0C0010);
	outdword(4);		// cDir - number of subsections
	outdword(0);
	outdword(0);
//sstModule
	outdword(0x10120);
	outdword(8);	//start
	outdword(sstsrc-8);		// size
// sstSrcModule
	outdword(0x10127);
	outdword(sstsrc);	//start
	outdword(sstNames-sstsrc);//size
//sstGlobalSym
	outdword(0x129);
	outdword(sstGlobalSym);	//start
	outdword(sstNames-sstGlobalSym);	//size
// sstNames
	outdword(0x130);
	outdword(sstNames);
	outdword(sstDirectory-sstGlobalSym);
	outdword(0x41304246); 	 // TDS - signature
	outdword(sstDirectory+outptr+4); 	 // TDS-len
	return 0;
}