virtual int performAction(std::vector<std::string> &args) { uint32 exeHeadSize = GetExeSize(args[0].c_str()); printf("Header Size: %u\n", exeHeadSize); UTIL::FS::FileHandle fh(args[0].c_str(), UTIL::FS::FILE_APPEND); fh.seek(exeHeadSize-1); char buff[1] = {0}; fh.write(buff, 1); printf("Wrote to end...\n"); return 0; }
/////////////////////////////////////////////////////////////////////////////// // // InitInstance // /////////////////////////////////////////////////////////////////////////////// BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { g_hInst = hInstance; InitCommonControls(); g_sExeFileName[0] = L'\0'; if (GetModuleFileName(NULL, g_sExeFullFileName, MAX_PATH) == 0) return FALSE; wcscpy(g_sSourcePath, g_sExeFullFileName); WCHAR *sSlash = wcsrchr(g_sSourcePath, L'\\'); wcscpy(g_sExeFileName, sSlash + 1); *sSlash = L'\0'; // cut the file name g_dwExeSize = GetExeSize(); return LoadStrings(); }
virtual int performAction(std::vector<std::string> &args) { uint32 exeHeadSize = GetExeSize(args[2].c_str()); uint32 exeSize = UTIL::FS::getFileSize(args[2].c_str()); InstallerPackerHeader iph; memset(&iph, 0, sizeof(InstallerPackerHeader)); iph.installMcf.offset = exeHeadSize + sizeof(InstallerPackerHeader); iph.installMcf.size = UTIL::FS::getFileSize(args[0].c_str()); iph.installMcf.crc = UTIL::FS::CRC32(args[0].c_str()); iph.contentMcf.offset = iph.installMcf.size + iph.installMcf.offset; iph.contentMcf.size = UTIL::FS::getFileSize(args[1].c_str()); iph.contentMcf.crc = UTIL::FS::CRC32(args[1].c_str()); printf("Install crc: %u\n", iph.installMcf.crc); printf("Content crc: %u\n", iph.contentMcf.crc); UTIL::FS::FileHandle fh(args[2].c_str(), UTIL::FS::FILE_APPEND); fh.seek(exeHeadSize); fh.write((char*)&iph, sizeof(InstallerPackerHeader)); char buff[10 * 1024]; { UTIL::FS::FileHandle rfh(args[0].c_str(), UTIL::FS::FILE_READ); uint64 done = 0; uint32 buffSize = 10 * 1024; while (done < iph.installMcf.size) { if (buffSize > (iph.installMcf.size - done)) buffSize = (uint32)(iph.installMcf.size-done); rfh.read(buff, buffSize); fh.write(buff, buffSize); done+=buffSize; } } { UTIL::FS::FileHandle rfh(args[1].c_str(), UTIL::FS::FILE_READ); uint64 done = 0; uint32 buffSize = 10 * 1024; while (done < iph.contentMcf.size) { if (buffSize > (iph.contentMcf.size - done)) buffSize = (uint32)(iph.contentMcf.size-done); rfh.read(buff, buffSize); fh.write(buff, buffSize); done+=buffSize; } } return 0; }
virtual int performAction(std::vector<std::string> &args) { UTIL::FS::delFile("temp.mcf"); UTIL::FS::delFile(args[1].c_str()); makeMCF(args[0].c_str()); uint32 exeHeadSize = GetExeSize("exe_packer.exe"); uint32 exeSize = UTIL::FS::getFileSize("exe_packer.exe"); uint32 diff = exeHeadSize - exeSize; uint32 size = UTIL::FS::getFileSize("temp.mcf"); ExePackerHeader ep; strcpy(ep.exe, args[2].c_str()); ep.crc = 0; ep.size = size; UTIL::FS::FileHandle fh(args[1].c_str(), UTIL::FS::FILE_APPEND); UTIL::FS::FileHandle fhExe("exe_packer.exe", UTIL::FS::FILE_READ); char buff[10*1024]; while (exeSize > 0) { uint32 read = 10*1024; if (read > exeSize) read = exeSize; fhExe.read(buff, read); fh.write(buff, read); exeSize -= read; } fhExe.close(); printf("Diff is %d\n", diff); while (diff > 0) { uint32 read = 10*1024; if (read > diff) read = diff; fh.write(buff, read); diff -= read; } UTIL::FS::FileHandle mcf("temp.mcf", UTIL::FS::FILE_READ); fh.write((char*)(&ep), sizeof(ExePackerHeader)); while (size > 0) { uint32 read = 10*1024; if (read > size) read = size; mcf.read(buff, read); fh.write(buff, read); size -= read; } fh.close(); mcf.close(); return 0; }