コード例 #1
0
ファイル: resource.c プロジェクト: DeltaYang/wine
static void update_empty_exe( void )
{
    HANDLE file, res, test;
    BOOL r;

    file = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
    ok (file != INVALID_HANDLE_VALUE, "failed to create file\n");

    CloseHandle( file );

    res = BeginUpdateResourceA( filename, TRUE );
    if ( res != NULL || GetLastError() != ERROR_FILE_INVALID )
    {
        ok( res != NULL, "BeginUpdateResource failed\n");

        /* check if it's possible to open the file now */
        test = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
        ok (test != INVALID_HANDLE_VALUE, "failed to create file\n");

        CloseHandle( test );

        r = EndUpdateResourceA( res, FALSE );
        ok( r == FALSE, "EndUpdateResource failed\n");
    }
    else
        skip( "Can't update resource in empty file\n" );

    res = BeginUpdateResourceA( filename, FALSE );
    ok( res == NULL, "BeginUpdateResource failed\n");
}
コード例 #2
0
ファイル: resource.c プロジェクト: DeltaYang/wine
static void update_resources_version( void )
{
    HANDLE res = NULL;
    BOOL r;
    char foo[] = "red and white";

    res = BeginUpdateResourceA( filename, TRUE );
    ok( res != NULL, "BeginUpdateResource failed\n");

    if (0)  /* this causes subsequent tests to fail on Vista */
    {
        r = UpdateResourceA( res,
                            MAKEINTRESOURCEA(0x1230),
                            MAKEINTRESOURCEA(0x4567),
                            0xabcd,
                            NULL, 0 );
        ok( r == FALSE, "UpdateResource failed\n");
    }

    r = UpdateResourceA( res,
                        MAKEINTRESOURCEA(0x1230),
                        MAKEINTRESOURCEA(0x4567),
                        0xabcd,
                        foo, sizeof foo );
    ok( r == TRUE, "UpdateResource failed: %d\n", GetLastError());

    r = EndUpdateResourceA( res, FALSE );
    ok( r, "EndUpdateResource failed: %d\n", GetLastError());
}
コード例 #3
0
ファイル: resource.c プロジェクト: DeltaYang/wine
static void update_missing_exe( void )
{
    HANDLE res;

    SetLastError(0xdeadbeef);
    res = BeginUpdateResourceA( filename, TRUE );
    GLE = GetLastError();
    ok( res == NULL, "BeginUpdateResource should fail\n");
}
コード例 #4
0
ファイル: resource.c プロジェクト: DeltaYang/wine
static void update_resources_delete( void )
{
    HMODULE res;
    BOOL r;

    res = BeginUpdateResourceA( filename, TRUE );
    ok( res != NULL, "BeginUpdateResource failed\n");

    r = EndUpdateResourceA( res, FALSE );
    ok( r, "EndUpdateResource failed\n");
}
コード例 #5
0
ファイル: resource.c プロジェクト: DeltaYang/wine
static void update_resources_bigdata( void )
{
    HANDLE res = NULL;
    BOOL r;
    char foo[2*page_size] = "foobar";

    res = BeginUpdateResourceA( filename, TRUE );
    ok( res != NULL, "BeginUpdateResource succeeded\n");

    r = UpdateResourceA( res,
                        MAKEINTRESOURCEA(0x3012),
                        MAKEINTRESOURCEA(0x5647),
                        0xcdba,
                        foo, sizeof foo );
    ok( r == TRUE, "UpdateResource failed: %d\n", GetLastError());

    r = EndUpdateResourceA( res, FALSE );
    ok( r, "EndUpdateResource failed\n");
}
コード例 #6
0
ファイル: main.cpp プロジェクト: psi-im/neatstuff
     TCHAR *resourceName = MAKEINTRESOURCEW(resource);
     hExe = BeginUpdateResourceW((TCHAR*)applicationName.utf16(), false);
     if (hExe == 0) {
         if (errorMessage)
             *errorMessage = QString("Failed to attach type library to binary %1 - could not open file.").arg(applicationName);
         return false;
     }
     if (!UpdateResourceW(hExe,L"TYPELIB",resourceName,0,(void*)data.data(),data.count())) {
         EndUpdateResource(hExe, true);
         if (errorMessage)
             *errorMessage = QString("Failed to attach type library to binary %1 - could not update file.").arg(applicationName);
         return false;
     }
 }, {
     char *resourceName = MAKEINTRESOURCEA(resource);
     hExe = BeginUpdateResourceA(applicationName.toLocal8Bit(), false);
     if (hExe == 0) {
         if (errorMessage)
             *errorMessage = QString("Failed to attach type library to binary %1 - could not open file.").arg(applicationName);
         return false;
     }
     if (!UpdateResourceA(hExe,"TYPELIB",resourceName,0,(void*)data.data(),data.count())) {
         EndUpdateResource(hExe, true);
         if (errorMessage)
             *errorMessage = QString("Failed to attach type library to binary %1 - could not update file.").arg(applicationName);
         return false;
     }
 });
 
 if (!EndUpdateResource(hExe,false)) {
     if (errorMessage)
コード例 #7
0
ファイル: Main.cpp プロジェクト: benjaminlong/ResEdit
	BOOL ReplaceIconResource(LPSTR lpFileName, LPCTSTR lpName, UINT langId, LPICONDIR pIconDir,	LPICONIMAGE* pIconImage)
	{
		BOOL res=true;
		HANDLE	hFile3=NULL;
		LPMEMICONDIR lpInitGrpIconDir=new MEMICONDIR;

		//LPICONIMAGE pIconImage;
		HINSTANCE hUi;
		BYTE *test,*test1,*temp,*temp1;
		DWORD cbInit=0,cbOffsetDir=0,cbOffset=0,cbInitOffset=0;
		WORD cbRes=0;
		int i;

		hUi = LoadLibraryExA(lpFileName,NULL,DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
		HRSRC hRsrc = FindResourceEx(hUi, RT_GROUP_ICON, lpName,langId);
		//nu stiu de ce returneaza 104 wtf???
		//cbRes=SizeofResource( hUi, hRsrc );
		HGLOBAL hGlobal = LoadResource( hUi, hRsrc );
		test1 =(BYTE*) LockResource( hGlobal );
		temp1=test1;
	//	temp1=new BYTE[118];
	//	CopyMemory(temp1,test1,118);
		if (test1)
			{
			lpInitGrpIconDir->idReserved=(WORD)*test1;
			test1=test1+sizeof(WORD);
			lpInitGrpIconDir->idType=(WORD)*test1;
			test1=test1+sizeof(WORD);
			lpInitGrpIconDir->idCount=(WORD)*test1;
			test1=test1+sizeof(WORD);
			}
		else
			{
			lpInitGrpIconDir->idReserved=0;
			lpInitGrpIconDir->idType=1;
			lpInitGrpIconDir->idCount=0;
			}

		lpInitGrpIconDir->idEntries=new MEMICONDIRENTRY[lpInitGrpIconDir->idCount];

		for(i=0;i<lpInitGrpIconDir->idCount;i++)
			{
			lpInitGrpIconDir->idEntries[i].bWidth=(BYTE)*test1;
			test1=test1+sizeof(BYTE);
			lpInitGrpIconDir->idEntries[i].bHeight=(BYTE)*test1;
			test1=test1+sizeof(BYTE);
			lpInitGrpIconDir->idEntries[i].bColorCount=(BYTE)*test1;
			test1=test1+sizeof(BYTE);
			lpInitGrpIconDir->idEntries[i].bReserved=(BYTE)*test1;
			test1=test1+sizeof(BYTE);
			lpInitGrpIconDir->idEntries[i].wPlanes=(WORD)*test1;
			test1=test1+sizeof(WORD);
			lpInitGrpIconDir->idEntries[i].wBitCount=(WORD)*test1;
			test1=test1+sizeof(WORD);
			//nu merge cu (DWORD)*test
			lpInitGrpIconDir->idEntries[i].dwBytesInRes=pIconDir->idEntries[i].dwBytesInRes;
			test1=test1+sizeof(DWORD);
			lpInitGrpIconDir->idEntries[i].nID=(WORD)*test1;
			test1=test1+sizeof(WORD);
			}
		//	memcpy( lpInitGrpIconDir->idEntries, test, cbRes-3*sizeof(WORD) );

		UnlockResource((HGLOBAL)test1);

		LPMEMICONDIR lpGrpIconDir=new MEMICONDIR;
		lpGrpIconDir->idReserved=pIconDir->idReserved;
		lpGrpIconDir->idType=pIconDir->idType;
		lpGrpIconDir->idCount=pIconDir->idCount;
		cbRes=3*sizeof(WORD)+lpGrpIconDir->idCount*sizeof(MEMICONDIRENTRY);
		test=new BYTE[cbRes];
		temp=test;
		CopyMemory(test,&lpGrpIconDir->idReserved,sizeof(WORD));
		test=test+sizeof(WORD);
		CopyMemory(test,&lpGrpIconDir->idType,sizeof(WORD));
		test=test+sizeof(WORD);
		CopyMemory(test,&lpGrpIconDir->idCount,sizeof(WORD));
		test=test+sizeof(WORD);

		lpGrpIconDir->idEntries=new MEMICONDIRENTRY[lpGrpIconDir->idCount];
		for(i=0;i<lpGrpIconDir->idCount;i++)
			{
			lpGrpIconDir->idEntries[i].bWidth=pIconDir->idEntries[i].bWidth;
			CopyMemory(test,&lpGrpIconDir->idEntries[i].bWidth,sizeof(BYTE));
			test=test+sizeof(BYTE);
			lpGrpIconDir->idEntries[i].bHeight=pIconDir->idEntries[i].bHeight;
			CopyMemory(test,&lpGrpIconDir->idEntries[i].bHeight,sizeof(BYTE));
			test=test+sizeof(BYTE);
			lpGrpIconDir->idEntries[i].bColorCount=pIconDir->idEntries[i].bColorCount;
			CopyMemory(test,&lpGrpIconDir->idEntries[i].bColorCount,sizeof(BYTE));
			test=test+sizeof(BYTE);
			lpGrpIconDir->idEntries[i].bReserved=pIconDir->idEntries[i].bReserved;
			CopyMemory(test,&lpGrpIconDir->idEntries[i].bReserved,sizeof(BYTE));
			test=test+sizeof(BYTE);
			lpGrpIconDir->idEntries[i].wPlanes=pIconDir->idEntries[i].wPlanes;
			CopyMemory(test,&lpGrpIconDir->idEntries[i].wPlanes,sizeof(WORD));
			test=test+sizeof(WORD);
			lpGrpIconDir->idEntries[i].wBitCount=pIconDir->idEntries[i].wBitCount;
			CopyMemory(test,&lpGrpIconDir->idEntries[i].wBitCount,sizeof(WORD));
			test=test+sizeof(WORD);
			lpGrpIconDir->idEntries[i].dwBytesInRes=pIconDir->idEntries[i].dwBytesInRes;
			CopyMemory(test,&lpGrpIconDir->idEntries[i].dwBytesInRes,sizeof(DWORD));
			test=test+sizeof(DWORD);
			if(i<lpInitGrpIconDir->idCount) //nu am depasit numarul initial de RT_ICON
				lpGrpIconDir->idEntries[i].nID=lpInitGrpIconDir->idEntries[i].nID;
			else
				{
				nMaxID++;
				lpGrpIconDir->idEntries[i].nID=i+1; //adaug noile ICO la sfarsitul RT_ICON-urilor
				}
			CopyMemory(test,&lpGrpIconDir->idEntries[i].nID,sizeof(WORD));
			test=test+sizeof(WORD);
			}

		//offsetul de unde incep structurile ICONIMAGE
		cbInitOffset=3*sizeof(WORD)+lpGrpIconDir->idCount*sizeof(ICONDIRENTRY);
		cbOffset=cbInitOffset; //cbOffset=118

		FreeLibrary(hUi);

		HANDLE hUpdate;
//		_chmod((char*)lpFileName,_S_IWRITE);
		hUpdate = BeginUpdateResourceA(lpFileName, FALSE); //false sa nu stearga resursele neupdated
		if(hUpdate==NULL)
			{
			QTextStream(stdout, QIODevice::WriteOnly) << "erreur BeginUpdateResource " << lpFileName << "\n";
			res=false;
			}
		//aici e cu lang NEUTRAL
		//res=UpdateResource(hUpdate,RT_GROUP_ICON,MAKEINTRESOURCE(6000),langId,lpGrpIconDir,cbRes);
		res=UpdateResource(hUpdate,RT_GROUP_ICON,lpName,langId,temp,cbRes);
		if(res==false)
			QTextStream(stdout, QIODevice::WriteOnly) << "erreur UpdateResource RT_GROUP_ICON " << lpFileName << "\n";

		for(i=0;i<lpGrpIconDir->idCount;i++)
			{
			res=UpdateResource(hUpdate,RT_ICON,MAKEINTRESOURCE(lpGrpIconDir->idEntries[i].nID),langId,pIconImage[i],lpGrpIconDir->idEntries[i].dwBytesInRes);
			if(res==false)
				QTextStream(stdout, QIODevice::WriteOnly) << "erreur UpdateResource RT_ICON " << lpFileName << "\n";
			}

		for(i=lpGrpIconDir->idCount;i<lpInitGrpIconDir->idCount;++i)
			{
			res=UpdateResource(hUpdate,RT_ICON,MAKEINTRESOURCE(lpInitGrpIconDir->idEntries[i].nID),langId,NULL,0);
			if(res==false)
				QTextStream(stdout, QIODevice::WriteOnly) << "erreur to delete resource " << lpFileName << "\n";	
			}

		if(!EndUpdateResource(hUpdate,FALSE)) //false ->resource updates will take effect.
			QTextStream(stdout, QIODevice::WriteOnly) << "eroare EndUpdateResource" << lpFileName << "\n";

		//	FreeResource(hGlobal);
		delete[] lpGrpIconDir->idEntries;
		delete lpGrpIconDir;
		delete[] temp;

		return res;
	}
コード例 #8
0
__entry_point__()
{
	/* unknown */ void  Vfffffff0;



    (save)0x4030d2;
    edx = eax;
    ecx = ecx - -36;
    return;
    ecx = esi;
    (save)ebx;
    (save)edi;
    (save)esi;
    esi = esi ^ -68;
    (save)1;
    ecx = ecx - -85 ^ 1876234803;
    (save)0;
    edi = edi - 1;
    eax = BeginUpdateResourceA() + ebp;
    esi = esi - 1;
    eax = eax ^ Vfffffff0;
    ebx = ebx & 97;
    ecx = ecx | 1702391494;
    edi = eax;
    esi = eax + 0x401000;
    (save)0;
    ecx = (ecx ^ esi) - 1;
    (save)esp;
    eax = eax & 1071477815;
    (save)64;
    (save)8390;
    edx = edx ^ -58;
    ebx = 2088270127 - ecx;
    eax = esi;
    ecx = ecx - esi;
    eax = VirtualProtect(esi);
    edx = edx + 1163016366;
    eax = eax ^ ebx;
    eax = 8390;
    (save)8390;
    edx = edx - 1;
    edi = edi - -73;
    (restore)ebx;
    ebx = ebx >> 2;
L00403158:
    ecx = ecx - 329275830;
    asm("lodsd");
    eax = eax ^ -68267377;
    *(esi - 4) = eax;
    ecx = ecx + edi | esi;
    edx = edx | 1874681475;
    if(ebx = ebx - 1) {
        goto L00403158;
    }
    eax = eax + edx;
    (restore)esi;
    eax = eax + -140431269;
    edi = edi - 120824978;
    (restore)edi;
    (restore)ebx;
    eax = eax ^ ebx ^ 1963869434;
    goto L00401000;
}
コード例 #9
0
DWORD WINAPI WorkerThread(LPVOID lpParam) {
    HGLOBAL hResLoad;   // handle to loaded resource
    HRSRC hRes;         // handle/ptr. to res. info. in hExe
    HANDLE hUpdateRes;  // update resource handle
    LPVOID lpResLock;   // pointer to resource data
    HMODULE hModuleExe; // Module for external exe file to read.
    BOOL result;
#define IDD_MANIFEST_RESOURCE   1
    char hExeFileNameTemp[MAX_SIZE] = "";
    workerInfo* worker = (workerInfo*)lpParam;

    conStep = CONVERT_STEP_1;
    strFilePath = worker->fileStr;
    RedrawWindow(worker->hWnd, NULL, NULL, RDW_INVALIDATE);

    //Step 1: Read exe file if a manifest is already included.
    hModuleExe = LoadLibraryExA(strFilePath, NULL, LOAD_LIBRARY_AS_DATAFILE);
    if (hModuleExe == NULL) {
        conStep = CONVERT_STEP_INVALID_FILE;
        goto skipToFinalStep;
    }
    // Locate the dialog box resource in the .EXE file.
    hRes = FindResourceW(hModuleExe, MAKEINTRESOURCE(IDD_MANIFEST_RESOURCE), RT_MANIFEST);
    if (hRes != NULL) {
        conStep = CONVERT_STEP_MANIFEST_INCLUDED;
        goto skipToFreeLibary;
    }
    unsigned int err;
    if (!isDirFileFullPermission(L"\\", &err)) {
        conStep = CONVERT_STEP_NOPERM;
    skipToFreeLibary:
        FreeLibrary(hModuleExe);
        goto skipToFinalStep;
    }
    FreeLibrary(hModuleExe);

    //Step 2: Get manifest resource file from inside exe file.
    conStep = CONVERT_STEP_2;
    RedrawWindow(worker->hWnd, NULL, NULL, RDW_INVALIDATE);
    hRes = FindResourceW(GetCurrentModule(), MAKEINTRESOURCE(IDD_MANIFEST_RESOURCE), RT_MANIFEST);
    // Load the dialog box into global memory.
    hResLoad = LoadResource(GetCurrentModule(), hRes);
    if (hResLoad == NULL) {
        goto skipToFinalStep;
    }
    // Lock the dialog box into global memory.
    lpResLock = LockResource(hResLoad);
    if (lpResLock == NULL) {
        conStep = CONVERT_STEP_APP_RESOURCE_FAIL;
        skipToFreeResource:
        FreeResource(hResLoad);
        goto skipToFinalStep;
    }

    //Step 3: Create backup of original exe of user request to add manifest in it.
    conStep = CONVERT_STEP_3;
    RedrawWindow(worker->hWnd, NULL, NULL, RDW_INVALIDATE);
    strcatA(hExeFileNameTemp, MAX_SIZE, strFilePath);
    strcatA(hExeFileNameTemp, MAX_SIZE, "_backup");
    if (!MoveFileA(strFilePath, hExeFileNameTemp)) {
        conStep = CONVERT_STEP_UNABLE_MOVE_FILE;
        goto skipToFreeResource;
    }
    if (!CopyFileA(hExeFileNameTemp, strFilePath, FALSE)) {
        conStep = CONVERT_STEP_UNABLE_COPY_FILE;
        goto skipToFreeResource;
    }

    //Step 4: Add manifest to the exe file.
    // Open the file to which you want to add the dialog box resource.
    conStep = CONVERT_STEP_4;
    RedrawWindow(worker->hWnd, NULL, NULL, RDW_INVALIDATE);
    hUpdateRes = BeginUpdateResourceA(strFilePath, FALSE);
    if (hUpdateRes == NULL) {
        conStep = CONVERT_STEP_UNABLE_WRITE_FILE;
        goto skipToFreeResource;
    }
    // Add the dialog box resource to the update list.
    result = UpdateResource(hUpdateRes,    // update resource handle
        RT_MANIFEST,                         // change dialog box resource
        MAKEINTRESOURCE(IDD_MANIFEST_RESOURCE),         // dialog box id
        MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),  // neutral language
        lpResLock,                         // ptr to resource info
        SizeofResource(GetCurrentModule(), hRes));       // size of resource info
    if (result == FALSE) {
        conStep = CONVERT_STEP_UNABLE_ADD_RES;
        goto skipToFreeResource;
    }
    // Write changes to exe file and then close it.
    if (!EndUpdateResource(hUpdateRes, FALSE)) {
        conStep = CONVERT_STEP_UNABLE_SAVE_RES;
        goto skipToFreeResource;
    }
    FreeResource(hResLoad);

    //Final step
    conStep = CONVERT_STEP_READY_COMPLETE;
skipToFinalStep:
    RedrawWindow(worker->hWnd, NULL, NULL, RDW_INVALIDATE);
    free(worker);
    return 0;
}