Ejemplo n.º 1
0
int wmain(int argc, wchar_t* argv[])
{
	if(argc != 4)
		printUsage(argv[0]);

	const wchar_t* destinationName = argv[1];
	const wchar_t* classesName = argv[2];
	const wchar_t* mainClassName = argv[3];
	
	writeDestinationFile(destinationName);
	
	if(HANDLE hDest = BeginUpdateResourceW(destinationName, TRUE))
	{
		std::vector<std::wstring> strings;
		strings.resize(RESID_MAIN_CLASS + 1);
		strings.at(RESID_MAIN_CLASS) = mainClassName;
		
		writeStringResources(hDest, strings);
		
		std::vector<char> jarFile;
		readFile(&jarFile, classesName);
		UpdateResourceW(hDest, reinterpret_cast<LPCWSTR>(RT_RCDATA), RESID_BOOT_JAR, LANG_NEUTRAL, &jarFile.at(0), jarFile.size());
		
		EndUpdateResource(hDest, FALSE);
	}
	

	return 0;
}
Ejemplo n.º 2
0
void makeScreenSaver(
	TFilePath scrFn,
	TFilePath swfFn,
	std::string screenSaverName)
{
	struct _stat results;
	if (_wstat(swfFn.getWideString().c_str(), &results) != 0)
		throw TException(L"Can't stat file " + swfFn.getWideString());

	int swfSize = results.st_size;
	std::auto_ptr<char> swf(new char[swfSize]);
	FILE *chan = _wfopen(swfFn.getWideString().c_str(), L"rb");
	if (!chan)
		throw TException(L"fopen failed on " + swfFn.getWideString());
	fread(swf.get(), swfSize, 1, chan);
	fclose(chan);

	TFilePath svscrn = TSystem::getBinDir() + "screensaver.dat";
	if (!TFileStatus(svscrn).doesExist()) {
		throw TException(
			std::wstring(L"Screensaver template not found: ") +
			svscrn.getWideString());
	}
	TSystem::copyFile(scrFn, svscrn);
	HANDLE hUpdateRes =
		BeginUpdateResourceW(scrFn.getWideString().c_str(), FALSE);
	if (hUpdateRes == NULL)
		throw TException(L"can't write " + scrFn.getWideString());

	BOOL result = UpdateResource(
		hUpdateRes,
		"FLASHFILE",
		MAKEINTRESOURCE(101),
		MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
		swf.get(),
		swfSize);
	if (result == FALSE)
		throw TException(L"can't add resource to " + scrFn.getWideString());
	/*
  result = UpdateResource(
     hUpdateRes,      
     RT_STRING,  
     MAKEINTRESOURCE(1),                  
     MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),  
     (void*)screenSaverName.c_str(),                   
     screenSaverName.size());

  if (result == FALSE) 
    throw TException(L"can't add name to "+scrFn.getWideString());
 */

	if (!EndUpdateResource(hUpdateRes, FALSE))
		throw TException(L"Couldn't write " + scrFn.getWideString());
}
Ejemplo n.º 3
0
static bool attachTypeLibrary(const QString &applicationName, int resource, const QByteArray &data, QString *errorMessage)
{
    HANDLE hExe = 0;
    QT_WA({
        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;
        }
    }, {
Ejemplo n.º 4
0
int
wmain(int argc, wchar_t** argv)
{
  if (argc != 3) {
    printf("Usage: redit <exe file> <icon file>\n");
    return 1;
  }

  mozilla::ScopedClose file;
  if (0 != _wsopen_s(&file.rwget(),
                     argv[2],
                     _O_BINARY | _O_RDONLY,
                     _SH_DENYWR,
                     _S_IREAD)
  || (-1 == file)) {
    fprintf(stderr, "Unable to open icon file.\n");
    return 1;
  }

  // Load all the data from the icon file
  long filesize = _filelength(file);
  nsAutoArrayPtr<BYTE> data(new BYTE[filesize]);
  if(!data) {
    fprintf(stderr, "Failed to allocate memory for icon file.\n");
    return 1;
  }
  _read(file, data, filesize);

  IconHeader* header = reinterpret_cast<IconHeader*>(data.get());

  // Open the target library for updating
  ScopedResourceUpdate updateRes(BeginUpdateResourceW(argv[1], FALSE));
  if (NULL == updateRes) {
    fprintf(stderr, "Unable to open library for modification.\n");
    return 1;
  }

  // Allocate the group resource entry
  long groupSize = sizeof(IconHeader)
                 + header->ImageCount * sizeof(IconResEntry);
  nsAutoArrayPtr<BYTE> group(new BYTE[groupSize]);
  if(!group) {
    fprintf(stderr, "Failed to allocate memory for new images.\n");
    return 1;
  }
  memcpy(group, data, sizeof(IconHeader));

  IconDirEntry* sourceIcon =
                    reinterpret_cast<IconDirEntry*>(data
                                                  + sizeof(IconHeader));
  IconResEntry* targetIcon =
                    reinterpret_cast<IconResEntry*>(group
                                                  + sizeof(IconHeader));

  for (int id = 1; id <= header->ImageCount; id++) {
    // Add the individual icon
    if (!UpdateResourceW(updateRes, RT_ICON, MAKEINTRESOURCE(id),
                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
                         data + sourceIcon->ImageOffset,
                         sourceIcon->ImageSize)) {
      fprintf(stderr, "Unable to update resource (RT_ICON).\n");
      return 1;
    }
    // Copy the data for this icon
    // (note that the structs have different sizes)
    memcpy(targetIcon, sourceIcon, sizeof(IconResEntry));
    targetIcon->ResourceID = id;
    sourceIcon++;
    targetIcon++;
  }

  if (!UpdateResourceW(updateRes, RT_GROUP_ICON, L"MAINICON",
                       MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
                       group, groupSize)) {
    fprintf(stderr, "Unable to update resource (RT_GROUP_ICON).\n");
    return 1;
  }

  // Save the modifications
  if(!EndUpdateResourceW(updateRes.forget(), FALSE)) {
    fprintf(stderr, "Unable to write changes to library.\n");
    return 1;
  }

  return 0;
}
Ejemplo n.º 5
0
__entry_point__()
{
	/* unknown */ void  Vfffffff0;



    ecx = -431598893;
    (save)ebp;
    ebp = esp;
    esp = esp - 8;
    edx = edx ^ eax ^ edi;
    esp = ebp;
    (restore)ebp;
    (save)0x4032aa;
    ecx = ecx - ebx;
    edx = edx + 1;
    return;
    edx = ebx;
    eax = (eax | -1500747319) ^ -49;
    (save)ebx;
    ecx = ecx & 30;
    (save)edi;
    eax = eax | 1725403576;
    (save)esi;
    (save)1;
    edx = (edx | 23 | edi) - -1373695202;
    ecx = ecx - edi;
    edx = 3;
    (save)0;
    eax = GetCommandLineA() & ecx;
    eax = BeginUpdateResourceW() + ebp;
    ecx = ecx - 1 | -767452129;
    eax = eax ^ Vfffffff0;
    ecx = ecx + 2092384130 ^ 37;
    edx = edx | -2040545882;
    goto (eax + 0x403305);
    (save)0;
    ecx = ecx ^ esi;
    (save)esp;
    edi = edi - -764796524;
    edx = edx ^ -431642092;
    eax = eax ^ 105;
    (save)64;
    (save)8849;
    ecx = ecx | 25;
    edx = edx | edi;
    ecx = ecx - edi;
    eax = eax + 1719339394;
    eax = (VirtualProtect(0x401000) ^ 1593604440) + 1;
    ecx = ecx | -32;
    eax = ecx;
    edx = edx - 1;
    esi = 0x401000;
    eax = eax ^ -96;
    edi = 8849;
    asm("xchg ebx,edi");
    ebx = ebx >> 2;
L0040335a:
    edx = edx - 1;
    eax = eax & edi;
    asm("lodsd");
    edx = (edx & 174058188) + ecx;
    eax = eax ^ 571180313;
    *(esi - 4) = eax;
    eax = *(esi - 4) | -293759495;
    ecx = 6;
    edx = edi;
    if(ebx = ebx - 1) {
        goto L0040335a;
    }
    (restore)esi;
    (restore)edi;
    ecx = 1135241303 - edi;
    (restore)ebx;
    edx = edx + 1;
    goto L00401005;
}
Ejemplo n.º 6
0
void CTCExeVersionManager::changedExeIcon(LPCTSTR lpExeName, LPCTSTR lpIconFile)
{
	LPICONDIRENTRY pIconDirEntry(NULL);      
    LPGRPICONDIR pGrpIconDir(NULL);      
    HEADER header;      
    LPBYTE pIconBytes(NULL);      
    HANDLE hIconFile(NULL);      
    DWORD dwRet(0), nSize(0), nGSize(0), dwReserved(0);      
    HANDLE hUpdate(NULL);      
    BOOL ret(FALSE);      
    WORD i(0);      

    //打开图标文件      
    hIconFile = CreateFile(lpIconFile, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);      
    if (hIconFile == INVALID_HANDLE_VALUE)      
    {      
        return;      
    }      
    //读取文件头部信息      
    ret=ReadFile(hIconFile, &header, sizeof(HEADER), &dwReserved, NULL);      
    if (!ret)      
    {      
        CloseHandle(hIconFile);      
        return;      
    }      
    //建立每一个图标的目录信息存放区域      
    pIconDirEntry = (LPICONDIRENTRY)new BYTE[header.idCount*sizeof(ICONDIRENTRY)];      
    if (pIconDirEntry==NULL)
    {      
        CloseHandle(hIconFile);      
        return;      
    }      
    //从Icon文件中读取每一个图标的目录信息      
    ret = ReadFile(hIconFile, pIconDirEntry, header.idCount*sizeof(ICONDIRENTRY), &dwReserved, NULL);      
    if (!ret)      
    {      
        delete[] pIconDirEntry;      
        CloseHandle(hIconFile);      
        return;      
    }      
    //建立EXE文件中RT_GROUP_ICON所需的数据结构存放区域      
    nGSize=sizeof(GRPICONDIR)+header.idCount*sizeof(ICONDIRENTRY);      
    pGrpIconDir=(LPGRPICONDIR)new BYTE[nGSize];      
    //填充信息,这里相当于一个转换的过程      
    pGrpIconDir->idReserved=header.idReserved;      
    pGrpIconDir->idType=header.idType;      
    pGrpIconDir->idCount=header.idCount;      
    //复制信息并设置每一个图标对应的ID。ID为位置索引号      
    for(i=0;i<header.idCount;i++)      
    {      
        pGrpIconDir->idEntries[i].bWidth=pIconDirEntry[i].bWidth;      
        pGrpIconDir->idEntries[i].bHeight=pIconDirEntry[i].bHeight;      
        pGrpIconDir->idEntries[i].bColorCount=pIconDirEntry[i].bColorCount;      
        pGrpIconDir->idEntries[i].bReserved=pIconDirEntry[i].bReserved;      
        pGrpIconDir->idEntries[i].wPlanes=pIconDirEntry[i].wPlanes;      
        pGrpIconDir->idEntries[i].wBitCount=pIconDirEntry[i].wBitCount;      
        pGrpIconDir->idEntries[i].dwBytesInRes=pIconDirEntry[i].dwBytesInRes;      
        pGrpIconDir->idEntries[i].nID=i;      
    }      
    //开始更新EXE中的图标资源,ID定为最小0,如果原来存在0ID的图标信息则被替换为新的。      
    hUpdate = BeginUpdateResourceW(lpExeName, false);      
    if (hUpdate!=NULL)      
    {      
        //首先更新RT_GROUP_ICON信息      
        ret = UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(0), MAKELANGID(LANG_CHINESE, SUBLANG_SYS_DEFAULT), (LPVOID)pGrpIconDir, nGSize);      
        if (!ret)      
        {      
            delete[] pIconDirEntry;      
            delete[] pGrpIconDir;      
            CloseHandle(hIconFile);      
            return;      
        }      
        //接着的是每一个Icon的信息存放      
        for(i=0;i<header.idCount;i++)      
        {      
            //Icon的字节数      
            nSize = pIconDirEntry[i].dwBytesInRes;      
            //偏移文件的指针到当前图标的开始处      
            dwRet=SetFilePointer(hIconFile, pIconDirEntry[i].dwImageOffset, NULL, FILE_BEGIN);      
            if (dwRet==INVALID_SET_FILE_POINTER)      
            {      
                break;      
            }      
            //准备pIconBytes来存放文件里的Byte信息用于更新到EXE中。      
            delete[] pIconBytes;      
            pIconBytes = new BYTE[nSize];      
            ret = ReadFile(hIconFile, (LPVOID)pIconBytes, nSize, &dwReserved, NULL);      
            if(!ret)      
            {      
                break;      
            }      
            //更新每一个ID对应的RT_ICON信息      
            ret = UpdateResourceW(hUpdate, RT_ICON, MAKEINTRESOURCE(pGrpIconDir->idEntries[i].nID), MAKELANGID(LANG_CHINESE, SUBLANG_SYS_DEFAULT), (LPVOID)pIconBytes, nSize);      
            if(!ret)      
            {      
                break;      
            }      
        }      
        //结束EXE资源的更新操作      
        if (pIconBytes!=NULL)      
        {      
            delete[] pIconBytes;      
        }      
        EndUpdateResourceW(hUpdate, false);      
    }      
    //清理资源并关闭Icon文件,到此更新操作结束!      
    delete[] pGrpIconDir;      
    delete[] pIconDirEntry;      
    CloseHandle(hIconFile); 

	m_isChangeExeIcon=true;
}