Registration Code (Part 1): w%kQ6
Registration Code (Part 2): b<#$1[*(cw~
In order to register on this forum, you must use the codes above. Combine them into one code (copy paste).

CodeFusion File Patcher Dumper

Programming topics that relate to the C/C++ languages.
Post Reply
User avatar
atom0s
Site Admin
Posts: 401
Joined: Sun Jan 04, 2015 11:23 pm
Location: 127.0.0.1
Contact:

CodeFusion File Patcher Dumper

Post by atom0s » Fri Jan 09, 2015 10:13 am

This is an old project I wrote a while ago. This will dump the patcher information from CodeFusion patcher files.
http://www.softpedia.com/get/Programmin ... sion.shtml

A handful of resources are left out on purpose since this is an old project. I do not recommend using this but for anything more then a reference if you plan to compile it.

CodeFusion.h
  1. #pragma once
  2.  
  3. /*
  4. * *****************************************************************************
  5. * CodeFusion.h - (c) atom0s 2009 [atom0s@live.com]
  6. * *****************************************************************************
  7. *
  8. *    This file is part of FusionDump.
  9. *
  10. *    FusionDump is free software; you can redistribute it and/or modify
  11. *    it under the terms of the GNU General Public License as published by
  12. *    the Free Software Foundation, either version 3 of the License, or
  13. *    (at your opinion) any later version.
  14. *
  15. *    FusionDump is distributed in the top that it will be useful, but WITHOUT
  16. *    ANY WARRANTY; without even the implied warranty of MERCHANTABLILITY or
  17. *    FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. *    for more details.
  19. *
  20. *    You should have received a copy of the GNU General Public License along
  21. *    with FusionDumper. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. *******************************************************************************
  24. */
  25.  
  26. /*
  27. * *****************************************************************************
  28. * Informational
  29. * *****************************************************************************
  30. *
  31. *    This file contains various structures, functions, and definitions
  32. *    used to read a CodeFusion file overlay. This file is made for
  33. *    educational purposes only, and not to damage CodeFusion in any
  34. *    way. You are NOT permitted to use this file if you plan to use
  35. *    it for any malicious reasons.
  36. *
  37. *    CodeFusion is copyright to:
  38. *    CodeFusion (c) 2003 - 2009 Kobik.domain [Krichmar Kobi, Israel]
  39. *
  40. *******************************************************************************
  41. */
  42.  
  43. #ifndef __CODEFUSION_H_INCLUDED__
  44. #define __CODEFUSION_H_INCLUDED__
  45.  
  46. #define STRICT
  47. #define WIN32_LEAN_AND_MEAN
  48. #define _WIN32_WINNT 0x0501
  49.  
  50. #include <windows.h>
  51.  
  52. /**
  53. * CodeFusion Overlay Signature
  54. *
  55. *    @._P-DATA_.@
  56. *
  57. */
  58. #define CODEFUSION_FILE_SIGNATURE "@._P-DATA_.@"
  59.  
  60. /**
  61. * CodeFusion Patch Types
  62. *
  63. */
  64. typedef enum _PATCH_TYPES {
  65.  
  66.     BytePatchOffset        = 0,
  67.     FindReplace            = 1,
  68.     FindReplaceAll        = 2,
  69.     PatternFindReplace    = 3,
  70.     UNKNOWN_TYPE_4        = 4,
  71.     TruncateFile        = 5,
  72.  
  73. } PATCH_TYPES, *LPPATCH_TYPES;
  74.  
  75. /**
  76. * CodeFusion Patch Entry
  77. *
  78. */
  79. typedef struct _CODEFUSION_PATCHENTRY {
  80.  
  81.     unsigned char    PatchType;
  82.     unsigned long    PatchOffset;
  83.  
  84.     // Patch Type 0 Data
  85.     std::vector< unsigned char > PatchData;
  86.  
  87.     // Patch Type 1, 3 Data
  88.     std::vector< unsigned char > FindData;
  89.     std::vector< unsigned char > ReplaceData;
  90.  
  91. } CODEFUSION_PATCHENTRY, *LPCODEFUSION_PATCHENTRY;
  92.  
  93. /**
  94. * CodeFusion File Entry
  95. *
  96. */
  97. typedef struct _CODEFUSION_FILEENTRY {
  98.  
  99.     // Basic File Info
  100.     std::string        FileName;
  101.     unsigned long    FileSize;
  102.     std::string        FileSizeText;
  103.     std::string        FileDate;
  104.     std::string        OpenDialogFilter;
  105.     unsigned long    FileCrc32;
  106.  
  107.     // File Flags
  108.     unsigned char    CheckFileSize;
  109.     unsigned char    CheckFileCrc32;
  110.     unsigned char    ShowFileDate;
  111.  
  112.     // File Patch Entries
  113.     unsigned long    FilePatchCount;
  114.     std::vector< CODEFUSION_PATCHENTRY > PatchEntries;
  115.  
  116. } CODEFUSION_FILEENTRY, *LPCODEFUSION_FILEENTRY;
  117.  
  118. /**
  119. * CodeFusion Overlay
  120. *
  121. */
  122. typedef struct _CODEFUSION_OVERLAY {
  123.  
  124.     unsigned char    Unknown1;    // Unknown byte. Has been 4 always so far. [Assuming version of some sort.]
  125.     unsigned char    Encrypted;    // Encrypted flag, 0 = no, 1 = yes.
  126.  
  127.     // Main Window Information
  128.     std::string        WindowTitle;
  129.     std::string        PatchDescription;
  130.     std::string        PatchNotes;
  131.  
  132.     // About Box Window Information
  133.     std::string        AboutBox;
  134.     std::string        ButtonOneText;
  135.     std::string        ButtonOneAction;
  136.     std::string        ButtonTwoText;
  137.     std::string        ButtonTwoAction;
  138.  
  139.     // File Entries
  140.     unsigned char    FilesToPatch;
  141.     std::vector< CODEFUSION_FILEENTRY > FileEntries;
  142.  
  143.     // Cleanup Function
  144.     void ClearData( void )
  145.     {
  146.         this->Unknown1        = 0;
  147.         this->Encrypted        = 0;
  148.         this->FilesToPatch    = 0;
  149.  
  150.         this->WindowTitle.clear();
  151.         this->PatchDescription.clear();
  152.         this->PatchNotes.clear();
  153.         this->AboutBox.clear();
  154.         this->ButtonOneText.clear();
  155.         this->ButtonOneAction.clear();
  156.         this->ButtonTwoText.clear();
  157.         this->ButtonTwoAction.clear();
  158.         this->FileEntries.clear();
  159.     }
  160.  
  161. } CODEFUSION_OVERLAY, *LPCODEFUSION_OVERLAY;
  162.  
  163. /**
  164. * DecryptString
  165. * -----------------------------------------------------------------------
  166. * @Purpose:        Decrypts xored strings inside CodeFusion overlays.
  167. * @Returns:        int - 0 on fail, nSize on success.
  168. * -----------------------------------------------------------------------
  169. */
  170. __inline int DecryptString( int nSize, LPCSTR lpString, LPSTR lpBuffer )
  171. {
  172.     if( ! nSize || ! lpString || ! lpBuffer )
  173.         return 0;
  174.  
  175.     try
  176.     {
  177.         unsigned char* lpDataPtr = reinterpret_cast< unsigned char* >( lpBuffer );
  178.  
  179.         for( int x = 0; x < nSize; x++ )
  180.         {
  181.             ( *lpDataPtr ) = static_cast< unsigned char >( ( lpString[ x ] ^ ( x + 1 ) ) );
  182.            
  183.             lpDataPtr++;
  184.         }
  185.  
  186.         return nSize;
  187.     }
  188.     catch( ... )
  189.     {
  190.         return 0;
  191.     }
  192. }
  193.  
  194. /**
  195. * DecryptVector
  196. * -----------------------------------------------------------------------
  197. * @Purpose:        Decrypts xored patch data.
  198. * @Returns:        int - 0 on fail, nSize on success.
  199. */
  200. __inline int DecryptVector( int nSize, std::vector< unsigned char >& vPatchData )
  201. {
  202.     if( ! nSize || vPatchData.empty() )
  203.         return 0;
  204.  
  205.     try
  206.     {
  207.         for( int x = 0; x < nSize; x++ )
  208.         {
  209.             vPatchData[x] = ( vPatchData[x] ^ ( x + 1 ) );
  210.         }
  211.  
  212.         return nSize;
  213.     }
  214.     catch( ... )
  215.     {
  216.         return 0;
  217.     }
  218. }
  219.  
  220. /**
  221. * ReadPatchString
  222. * -----------------------------------------------------------------------
  223. * @Purpose:        Reads a string from the given buffer.
  224. * @Returns:        int - -1 on fail, size of string on success.
  225. * -----------------------------------------------------------------------
  226. *
  227. * This function reads a string from the given buffer based on the starting
  228. * byte as the size. You should not skip the size byte with the offset being
  229. * passed to this function. Strings are setup as:
  230. *
  231. * size | string[ size ]
  232. *
  233. */
  234. __inline int ReadPatchString( LPVOID lpOverlay, LPVOID lpBuffer )
  235. {
  236.     if( ! lpOverlay || ! lpBuffer )
  237.         return -1;
  238.  
  239.     try
  240.     {
  241.         unsigned char* lpDataPtr = reinterpret_cast< unsigned char* >( lpOverlay );
  242.  
  243.         int nStringSize = lpDataPtr[ 0 ];
  244.         if( nStringSize == 0 )
  245.             return 0;
  246.  
  247.         memcpy( lpBuffer, ( ++lpDataPtr ), nStringSize );
  248.  
  249.         return nStringSize;
  250.     }
  251.     catch( ... )
  252.     {
  253.         return -1;
  254.     }
  255. }
  256.  
  257.  
  258. //
  259. // Text File Dump Headers
  260. //
  261. // ------------------------------------------------------------------
  262.  
  263. #define TXT_OVERVIEW_HEADER \
  264. "------------------------------------------------------------------------------------------------------------\r\n" \
  265. "FusionDump Log File - {FILE_PATH}\r\n" \
  266. "------------------------------------------------------------------------------------------------------------\r\n" \
  267. "File Name          : {FILE_PATH}\r\n" \
  268. "File Size          : {FILE_SIZE} bytes\r\n" \
  269. "Overlay Size       : {OVERLAY_SIZE} bytes\r\n" \
  270. "Overlay Encrypted  : {OVERLAY_ENCRYPTED}\r\n\r\n"
  271.  
  272. #define TXT_MAINWINDOW_HEADER \
  273. "------------------------------------------------------------------------------------------------------------\r\n" \
  274. "MAIN WINDOW INFORMATION\r\n" \
  275. "------------------------------------------------------------------------------------------------------------\r\n" \
  276. "Window Title       : {WINDOW_TITLE}\r\n" \
  277. "Patch Description  : {WINDOW_DESCRIPTION}\r\n" \
  278. "Patch Notes        : \r\n\r\n{WINDOW_NOTES}\r\n\r\n"
  279.  
  280. #define TXT_ABOUTWINDOW_HEADER \
  281. "------------------------------------------------------------------------------------------------------------\r\n" \
  282. "ABOUT WINDOW INFORMATION\r\n" \
  283. "------------------------------------------------------------------------------------------------------------\r\n" \
  284. "Button One Text    : {ABOUT_BUTTON_ONE_TEXT}\r\n" \
  285. "Button One Action  : {ABOUT_BUTTON_ONE_ACTION}\r\n\r\n" \
  286. "Button Two Text    : {ABOUT_BUTTON_TWO_TEXT}\r\n" \
  287. "Button Two Action  : {ABOUT_BUTTON_TWO_ACTION}\r\n\r\n" \
  288. "About Box Text     : \r\n\r\n{ABOUT_BOX_TEXT}\r\n\r\n\r\n"
  289.  
  290. #define TXT_PATCHINFO_HEADER \
  291. "------------------------------------------------------------------------------------------------------------\r\n" \
  292. "FILE PATCH INFORMATION\r\n" \
  293. "------------------------------------------------------------------------------------------------------------\r\n" \
  294. "Files To Patch     : {FILE_PATCH_COUNT}\r\n\r\n"
  295.  
  296. #define TXT_FILEENTRY_HEADER \
  297. "    ----------------------------------------------------------------------------------------------------\r\n" \
  298. "    | FILE ENTRY #{FILE_ENTRY_NUMBER} - {FILE_ENTRY_NAME} - ({FILE_ENTRY_PATCH_COUNT} patches.)\r\n" \
  299. "    ----------------------------------------------------------------------------------------------------\r\n"
  300.  
  301. #define TXT_FILEPATCHENTRY( type ) \
  302.     TXT_FILEPATCHENTRY_##type
  303.  
  304. #define TXT_FILEPATCHENTRY_0 \
  305. "        ----------------------------------------\r\n" \
  306. "        | PATCH #{PATCH_ENTRY_NUMBER} - Byte Patch at Offset\r\n" \
  307. "        ----------------------------------------\r\n" \
  308. "        Offset  : {PATCH_OFFSET}\r\n" \
  309. "        Patch   : {PATCH_DATA}\r\n"
  310.  
  311. #define TXT_FILEPATCHENTRY_1 \
  312. "        ----------------------------------------\r\n" \
  313. "        | PATCH #{PATCH_ENTRY_NUMBER} - Find and Replace\r\n" \
  314. "        ----------------------------------------\r\n" \
  315. "        Offset  : {PATCH_OFFSET}\r\n" \
  316. "        Find    : {PATCH_FIND_DATA}\r\n" \
  317. "        Replace : {PATCH_REPLACE_DATA}\r\n"
  318.  
  319.  
  320. #define TXT_FILEPATCHENTRY_2 \
  321. "        ----------------------------------------\r\n" \
  322. "        | PATCH #{PATCH_ENTRY_NUMBER} - Find and Replace (All)\r\n" \
  323. "        ----------------------------------------\r\n" \
  324. "        Offset  : {PATCH_OFFSET}\r\n" \
  325. "        Find    : {PATCH_FIND_DATA}\r\n" \
  326. "        Replace : {PATCH_REPLACE_DATA}\r\n"
  327.  
  328. #define TXT_FILEPATCHENTRY_3 \
  329. "        ----------------------------------------\r\n" \
  330. "        | PATCH #{PATCH_ENTRY_NUMBER} - Pattern Find and Replace\r\n" \
  331. "        ----------------------------------------\r\n" \
  332. "        Offset  : {PATCH_OFFSET}\r\n" \
  333. "        Pattern : {PATCH_FIND_DATA}\r\n" \
  334. "        Replace : {PATCH_REPLACE_DATA}\r\n"
  335.  
  336. #define TXT_FILEPATCHENTRY_4 \
  337. "        ----------------------------------------\r\n" \
  338. "        | PATCH #{PATCH_ENTRY_NUMBER} - UNKNOWN PATCH TYPE\r\n" \
  339. "        ----------------------------------------\r\n" \
  340. "        Unknown patch type, please report this!\r\n"
  341.  
  342. #define TXT_FILEPATCHENTRY_5 \
  343. "        ----------------------------------------\r\n" \
  344. "        | PATCH #{PATCH_ENTRY_NUMBER} - Truncate End of File\r\n" \
  345. "        ----------------------------------------\r\n" \
  346. "        Offset  : {PATCH_OFFSET}\r\n"
  347.  
  348. #endif // __CODEFUSION_H_INCLUDED__
FileDump.hpp
  1. #pragma once
  2.  
  3. /*
  4. * *****************************************************************************
  5. * CFileDump.hpp - (c) atom0s 2009 [atom0s@live.com]
  6. * *****************************************************************************
  7. *
  8. *    This file is part of FusionDump.
  9. *
  10. *    FusionDump is free software; you can redistribute it and/or modify
  11. *    it under the terms of the GNU General Public License as published by
  12. *    the Free Software Foundation, either version 3 of the License, or
  13. *    (at your opinion) any later version.
  14. *
  15. *    FusionDump is distributed in the top that it will be useful, but WITHOUT
  16. *    ANY WARRANTY; without even the implied warranty of MERCHANTABLILITY or
  17. *    FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. *    for more details.
  19. *
  20. *    You should have received a copy of the GNU General Public License along
  21. *    with FusionDumper. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. *******************************************************************************
  24. */
  25.  
  26. #ifndef __CFILEDUMP_HPP_INCLUDED__
  27. #define __CFILEDUMP_HPP_INCLUDED__
  28.  
  29. #include "defines.h"
  30. #include "CodeFusion.h"
  31.  
  32. #define MAX_SECTIONS 20
  33.  
  34. class CFileDump
  35. {
  36.     std::string                m_vFilePath;
  37.     int                        m_vSaveMethod;
  38.    
  39.     DWORD                    m_vFileSize;
  40.     LPVOID                    m_vFileDump;
  41.  
  42.     DWORD                    m_vOverlaySize;
  43.     DWORD                    m_vOverlayStart;
  44.  
  45.     CODEFUSION_OVERLAY        m_vOverlay;
  46.  
  47. public:
  48.     CFileDump( const std::string& sFile, int nSaveMethod = 0 );
  49.     ~CFileDump( void );
  50.  
  51. public:
  52.     HRESULT LoadFile( LPCTSTR lpFilePath = NULL );
  53.  
  54. private:
  55.     HRESULT DumpOverlay( void );
  56.     HRESULT SaveOverlay( void );
  57.  
  58. };
  59.  
  60. #endif // __CFILEDUMP_HPP_INCLUDED__
FileDump.cpp
  1. /*
  2. * *****************************************************************************
  3. * CFileDump.cpp - (c) atom0s 2009 [atom0s@live.com]
  4. * *****************************************************************************
  5. *
  6. *    This file is part of FusionDump.
  7. *
  8. *    FusionDump is free software; you can redistribute it and/or modify
  9. *    it under the terms of the GNU General Public License as published by
  10. *    the Free Software Foundation, either version 3 of the License, or
  11. *    (at your opinion) any later version.
  12. *
  13. *    FusionDump is distributed in the top that it will be useful, but WITHOUT
  14. *    ANY WARRANTY; without even the implied warranty of MERCHANTABLILITY or
  15. *    FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. *    for more details.
  17. *
  18. *    You should have received a copy of the GNU General Public License along
  19. *    with FusionDumper. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. *******************************************************************************
  22. */
  23.  
  24. #include "CFileDump.hpp"
  25.  
  26. CFileDump::CFileDump( const std::string& sFile, int nSaveMethod ) : m_vFileDump( 0 ), m_vFileSize( 0 ), m_vOverlaySize( 0 ), m_vOverlayStart( 0 )
  27. {
  28.     this->m_vFilePath    = sFile;
  29.     this->m_vSaveMethod = nSaveMethod;
  30.  
  31.     this->m_vOverlay.ClearData();
  32. }
  33. CFileDump::~CFileDump( void )
  34. {
  35.     if( this->m_vFileDump )
  36.         delete[] this->m_vFileDump;
  37.     this->m_vFileDump = NULL;
  38.  
  39.     this->m_vOverlay.ClearData();
  40. }
  41.  
  42. HRESULT CFileDump::LoadFile( LPCTSTR lpFilePath /* = NULL */ )
  43. {
  44.     // User Passing New File?
  45.     if( lpFilePath )
  46.         this->m_vFilePath = lpFilePath;
  47.  
  48.     // Ensure A File To Dump Is Given
  49.     if( this->m_vFilePath.length() == 0 )
  50.     {
  51.         LogMessage( _T( "ERROR: Call to LoadFile without a selected file.\r\n" ) );
  52.         return E_FAIL;
  53.     }
  54.  
  55.     // Cleanup Any Previous Information
  56.     if( this->m_vFileDump )
  57.         delete[] this->m_vFileDump;
  58.  
  59.     this->m_vFileDump        = NULL;
  60.     this->m_vFileSize        = NULL;
  61.     this->m_vOverlaySize    = NULL;
  62.     this->m_vOverlayStart    = NULL;
  63.  
  64.     this->m_vOverlay.ClearData();
  65.    
  66.     // Valid File Existence
  67.     if( GetFileAttributes( this->m_vFilePath.c_str() ) == 0xFFFFFFFF )
  68.     {
  69.         LogMessage( _T( "ERROR: File was not found.\r\n" ) );
  70.         return E_FAIL;
  71.     }
  72.  
  73.     //
  74.     // Main file opening happens below. Handles are
  75.     // opened from this point on, any failures in
  76.     // this function MUST close any open handles!
  77.     // ------------------------------------------------------------------
  78.  
  79.     // Attempt To Open The File
  80.     LogMessage( _T( "Opening Selected File......" ) );
  81.     HANDLE hFileHandle = CreateFile( this->m_vFilePath.c_str(), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
  82.     if( hFileHandle == INVALID_HANDLE_VALUE )
  83.     {
  84.         LogMessage( _T( "Failed!\r\n" ) );
  85.         return E_FAIL;
  86.     }
  87.     LogMessage( _T( "Done!\r\n" ) );
  88.  
  89.     // Attempt To Read Memory Map
  90.     LogMessage( _T( "Creating File Mapping......" ) );
  91.     HANDLE hFileMapping = CreateFileMapping( hFileHandle, 0, PAGE_READWRITE, 0, 0, 0 );
  92.     if( hFileMapping == NULL )
  93.     {
  94.         LogMessage( _T( "Failed!\r\n" ) );
  95.         CloseHandle( hFileHandle );
  96.         return E_FAIL;
  97.     }
  98.     LogMessage( _T( "Done!\r\n" ) );
  99.  
  100.     // Attempt To Map File View Into Our Address Space
  101.     LogMessage( _T( "Mapping View Of File......." ) );
  102.     LPVOID lpFilePtr = MapViewOfFile( hFileMapping, FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, 0 );
  103.     if( ! lpFilePtr )
  104.     {
  105.         LogMessage( _T( "Failed!\r\n" ) );
  106.         CloseHandle( hFileMapping );
  107.         CloseHandle( hFileHandle );
  108.         return E_FAIL;
  109.     }
  110.     LogMessage( _T( "Done!\r\n" ) );
  111.  
  112.     //
  113.     // Since we got this far, we will dump the loaded file into
  114.     // our class variables rather then leave the handles open
  115.     // and have to do various close handle calls.
  116.     // ------------------------------------------------------------------
  117.  
  118.     LogMessage( _T( "Dumping File Into Memory..." ) );
  119.  
  120.     // Obtain True File Size
  121.     this->m_vFileSize = GetFileSize( hFileHandle, NULL );
  122.  
  123.     // Dump File Into Our class
  124.     this->m_vFileDump = new unsigned char[ this->m_vFileSize + 1 ];
  125.     memcpy( this->m_vFileDump, lpFilePtr, this->m_vFileSize );
  126.  
  127.     // Cleanup Handles
  128.     UnmapViewOfFile( lpFilePtr );
  129.     CloseHandle( hFileMapping );
  130.     CloseHandle( hFileHandle );
  131.  
  132.     LogMessage( _T( "Done!\r\n" ) );
  133.  
  134.     //
  135.     // Next we need to dump the headers of the file to ensure that
  136.     // we have loaded a valid PE file. We also use the headers to
  137.     // read the sections inside the file to obtain the 'seen' size
  138.     // of the file to calculate the overlay size.
  139.     // ------------------------------------------------------------------
  140.  
  141.     PIMAGE_DOS_HEADER pDosHeader = NULL;
  142.     PIMAGE_NT_HEADERS pNtHeaders = NULL;
  143.  
  144.     // Validate Dos Header
  145.     LogMessage( _T( "Validating Dos Signature..." ) );
  146.     pDosHeader = reinterpret_cast< PIMAGE_DOS_HEADER >( this->m_vFileDump );
  147.     if( pDosHeader->e_magic != IMAGE_DOS_SIGNATURE )
  148.     {
  149.         LogMessage( _T( "Failed!\r\n" ) );
  150.         return E_FAIL;
  151.     }
  152.     LogMessage( _T( "Done!\r\n" ) );
  153.  
  154.     // Validate Nt Headers
  155.     LogMessage( _T( "Validating Nt Signature...." ) );
  156.     pNtHeaders = reinterpret_cast< PIMAGE_NT_HEADERS >( reinterpret_cast< DWORD >( this->m_vFileDump ) + pDosHeader->e_lfanew );
  157.     if( pNtHeaders->Signature != IMAGE_NT_SIGNATURE )
  158.     {
  159.         LogMessage( _T( "Failed!\r\n" ) );
  160.         return E_FAIL;
  161.     }
  162.     LogMessage( _T( "Done!\r\n" ) );
  163.  
  164.     DWORD dwFileSize        = NULL;
  165.     DWORD dwMaxPointer        = NULL;
  166.     DWORD dwCurrPosition    = ( reinterpret_cast< DWORD >( this->m_vFileDump ) + pDosHeader->e_lfanew + sizeof( IMAGE_NT_HEADERS ) );
  167.  
  168.     // Read Sections From Header [Read File Size Too]
  169.     LogMessage( _T( "Dumping Header Sections...." ) );
  170.     for( int x = 0; x < pNtHeaders->FileHeader.NumberOfSections; x++ )
  171.     {
  172.         PIMAGE_SECTION_HEADER pSectionHeader = reinterpret_cast< PIMAGE_SECTION_HEADER >( dwCurrPosition );
  173.  
  174.         if( pSectionHeader->PointerToRawData > dwMaxPointer )
  175.         {
  176.             dwMaxPointer = pSectionHeader->PointerToRawData;
  177.             dwFileSize = ( pSectionHeader->PointerToRawData + pSectionHeader->SizeOfRawData );
  178.         }
  179.  
  180.         dwCurrPosition += sizeof( IMAGE_SECTION_HEADER );
  181.     }
  182.     LogMessage( _T( "Done!\r\n" ) );
  183.  
  184.     // Check If Overlay Exists
  185.     if( this->m_vFileSize <= dwFileSize )
  186.     {
  187.         LogMessage( _T( "ERROR: File does not appear to contain an overlay!\r\n" ) );
  188.         return E_FAIL;
  189.     }
  190.  
  191.     // Store Overlay Information
  192.     this->m_vOverlaySize    = ( this->m_vFileSize - dwFileSize );
  193.     this->m_vOverlayStart    = dwFileSize;
  194.  
  195.     if( ! this->DumpOverlay() )
  196.         return E_FAIL;
  197.  
  198.     return S_OK;
  199. }
  200.  
  201. HRESULT CFileDump::DumpOverlay( void )
  202. {
  203.     if( ! this->m_vFileDump || this->m_vFileSize == 0 || this->m_vOverlaySize == 0 )
  204.         return E_FAIL;
  205.  
  206.     // Local Variables
  207.     int nSize        = 0;
  208.  
  209.     // Setup Pointer To Overlay
  210.     unsigned char* lpOverlay = reinterpret_cast< unsigned char* >( reinterpret_cast< DWORD >( this->m_vFileDump ) + this->m_vOverlayStart );
  211.  
  212.     //
  213.     // Read and validate the file overlay signature to
  214.     // ensure the current overlay is a CodeFusion file.
  215.     // ------------------------------------------------------------------
  216.  
  217.     LogMessage( _T( "Validating Overlay........." ) );
  218.  
  219.     unsigned char btSignature[ 0x0D ] = { 0 };
  220.     memcpy( & btSignature, lpOverlay, 0x0C );
  221.  
  222.     if( _stricmp( reinterpret_cast< LPCSTR >( btSignature ), CODEFUSION_FILE_SIGNATURE ) != 0 )
  223.     {
  224.         LogMessage( _T( "Failed!\r\n" ) );
  225.         return E_FAIL;
  226.     }
  227.  
  228.     LogMessage( _T( "Done!\r\n" ) );
  229.  
  230.     lpOverlay += 0x0C;
  231.  
  232.     //
  233.     // Read the starting two bytes which contain the
  234.     // encryption flag for the overlay.
  235.     // ------------------------------------------------------------------
  236.  
  237.     this->m_vOverlay.Unknown1    = lpOverlay[0];
  238.     this->m_vOverlay.Encrypted    = lpOverlay[1];
  239.  
  240.     lpOverlay += 2;
  241.  
  242.     //
  243.     // Read the window title.
  244.     // ------------------------------------------------------------------
  245.  
  246.     char szTitleString[ 0xFF ] = { 0 };
  247.     nSize = ReadPatchString( lpOverlay, & szTitleString );
  248.  
  249.     if( this->m_vOverlay.Encrypted )
  250.         DecryptString( nSize, const_cast< LPCSTR >( &szTitleString[ 0 ] ), szTitleString );
  251.  
  252.     this->m_vOverlay.WindowTitle = szTitleString;
  253.  
  254.     lpOverlay += nSize;
  255.     lpOverlay += 1;
  256.  
  257.     //
  258.     // Read the description.
  259.     // ------------------------------------------------------------------
  260.  
  261.     char szDescription[ 0xFF ] = { 0 };
  262.     nSize = ReadPatchString( lpOverlay, & szDescription );
  263.  
  264.     if( this->m_vOverlay.Encrypted )
  265.         DecryptString( nSize, const_cast< LPCSTR >( &szDescription[ 0 ] ), szDescription );
  266.  
  267.     this->m_vOverlay.PatchDescription = szDescription;
  268.  
  269.     lpOverlay += nSize;
  270.     lpOverlay += 1;
  271.  
  272.     //
  273.     // Read the patch notes.
  274.     // ------------------------------------------------------------------
  275.    
  276.     char szPatchNotes[ 0xFF ] = { 0 };
  277.     nSize = ReadPatchString( lpOverlay, & szPatchNotes );
  278.  
  279.     if( this->m_vOverlay.Encrypted )
  280.         DecryptString( nSize, const_cast< LPCSTR >( &szPatchNotes[ 0 ] ), szPatchNotes );
  281.  
  282.     this->m_vOverlay.PatchNotes = szPatchNotes;
  283.  
  284.     lpOverlay += nSize;
  285.     lpOverlay += 1;
  286.  
  287.     //
  288.     // Read the about box text.
  289.     // ------------------------------------------------------------------
  290.  
  291.     char szAboutBox[ 0xFF ] = { 0 };
  292.     nSize = ReadPatchString( lpOverlay, & szAboutBox );
  293.  
  294.     if( this->m_vOverlay.Encrypted )
  295.         DecryptString( nSize, const_cast< LPCSTR >( &szAboutBox[ 0 ] ), szAboutBox );
  296.  
  297.     this->m_vOverlay.AboutBox = szAboutBox;
  298.  
  299.     lpOverlay += nSize;
  300.     lpOverlay += 1;
  301.  
  302.     //
  303.     // Read the button one caption.
  304.     // ------------------------------------------------------------------
  305.  
  306.     char szButtonOne[ 0xFF ] = { 0 };
  307.     nSize = ReadPatchString( lpOverlay, & szButtonOne );
  308.  
  309.     if( this->m_vOverlay.Encrypted )
  310.         DecryptString( nSize, const_cast< LPCSTR >( &szButtonOne[ 0 ] ), szButtonOne );
  311.  
  312.     this->m_vOverlay.ButtonOneText = szButtonOne;
  313.  
  314.     lpOverlay += nSize;
  315.     lpOverlay += 1;
  316.  
  317.     //
  318.     // Read the button one action.
  319.     // ------------------------------------------------------------------
  320.  
  321.     char szButtonOneAction[ 0xFF ] = { 0 };
  322.     nSize = ReadPatchString( lpOverlay, & szButtonOneAction );
  323.  
  324.     if( this->m_vOverlay.Encrypted )
  325.         DecryptString( nSize, const_cast< LPCSTR >( &szButtonOneAction[ 0 ] ), szButtonOneAction );
  326.  
  327.     this->m_vOverlay.ButtonOneAction = szButtonOneAction;
  328.  
  329.     lpOverlay += nSize;
  330.     lpOverlay += 1;
  331.    
  332.     //
  333.     // Read the button two caption.
  334.     // ------------------------------------------------------------------
  335.  
  336.     char szButtonTwo[ 0xFF ] = { 0 };
  337.     nSize = ReadPatchString( lpOverlay, & szButtonTwo );
  338.  
  339.     if( this->m_vOverlay.Encrypted )
  340.         DecryptString( nSize, const_cast< LPCSTR >( &szButtonTwo[ 0 ] ), szButtonTwo );
  341.  
  342.     this->m_vOverlay.ButtonTwoText = szButtonTwo;
  343.  
  344.     lpOverlay += nSize;
  345.     lpOverlay += 1;
  346.  
  347.     //
  348.     // Read the button two action.
  349.     // ------------------------------------------------------------------
  350.  
  351.     char szButtonTwoAction[ 0xFF ] = { 0 };
  352.     nSize = ReadPatchString( lpOverlay, & szButtonTwoAction );
  353.  
  354.     if( this->m_vOverlay.Encrypted )
  355.         DecryptString( nSize, const_cast< LPCSTR >( &szButtonTwoAction[ 0 ] ), szButtonTwoAction );
  356.  
  357.     this->m_vOverlay.ButtonTwoAction = szButtonTwoAction;
  358.  
  359.     lpOverlay += nSize;
  360.     lpOverlay += 1;
  361.  
  362.     //
  363.     // Read the file patch count.
  364.     // ------------------------------------------------------------------
  365.  
  366.     this->m_vOverlay.FilesToPatch = lpOverlay[ 0 ];
  367.     lpOverlay += 1;
  368.  
  369.     //
  370.     // Loop and read the file entries.
  371.     // ------------------------------------------------------------------
  372.  
  373.     for( int x = 0; x < this->m_vOverlay.FilesToPatch; x++ )
  374.     {
  375.         CODEFUSION_FILEENTRY cFileEntry;
  376.  
  377.         //
  378.         // Read the file name.
  379.         // ------------------------------------------------------------------
  380.  
  381.         char szFileName[ 0xFF ] = { 0 };
  382.         nSize = ReadPatchString( lpOverlay, & szFileName );
  383.  
  384.         if( this->m_vOverlay.Encrypted )
  385.             DecryptString( nSize, const_cast< LPCSTR >( &szFileName[ 0 ] ), szFileName );
  386.  
  387.         cFileEntry.FileName = szFileName;
  388.  
  389.         lpOverlay += nSize;
  390.         lpOverlay += 1;
  391.  
  392.         //
  393.         // Read the file size.
  394.         // ------------------------------------------------------------------
  395.  
  396.         cFileEntry.FileSize = *(DWORD*)( reinterpret_cast< DWORD >( lpOverlay ) );
  397.         lpOverlay += 4;
  398.  
  399.         //
  400.         // Read the file size text.
  401.         // ------------------------------------------------------------------
  402.  
  403.         char szFileSize[ 0xFF ] = { 0 };
  404.         nSize = ReadPatchString( lpOverlay, & szFileSize );
  405.  
  406.         if( this->m_vOverlay.Encrypted )
  407.             DecryptString( nSize, const_cast< LPCSTR >( &szFileSize[ 0 ] ), szFileSize );
  408.  
  409.         cFileEntry.FileSizeText = szFileSize;
  410.  
  411.         lpOverlay += nSize;
  412.         lpOverlay += 1;
  413.  
  414.         //
  415.         // Read the file date.
  416.         // ------------------------------------------------------------------
  417.  
  418.         char szFileDate[ 0xFF ] = { 0 };
  419.         nSize = ReadPatchString( lpOverlay, & szFileDate );
  420.  
  421.         if( this->m_vOverlay.Encrypted )
  422.             DecryptString( nSize, const_cast< LPCSTR >( &szFileDate[ 0 ] ), szFileDate );
  423.  
  424.         cFileEntry.FileDate = szFileDate;
  425.  
  426.         lpOverlay += nSize;
  427.         lpOverlay += 1;
  428.        
  429.         //
  430.         // Read the open file dialog filter.
  431.         // ------------------------------------------------------------------
  432.  
  433.         char szOpenFileFilter[ 0xFF ] = { 0 };
  434.         nSize = ReadPatchString( lpOverlay, & szOpenFileFilter );
  435.  
  436.         if( this->m_vOverlay.Encrypted )
  437.             DecryptString( nSize, const_cast< LPCSTR >( &szOpenFileFilter[ 0 ] ), szOpenFileFilter );
  438.  
  439.         cFileEntry.OpenDialogFilter = szOpenFileFilter;
  440.  
  441.         lpOverlay += nSize;
  442.         lpOverlay += 1;
  443.  
  444.         //
  445.         // Read the file crc32.
  446.         // ------------------------------------------------------------------
  447.  
  448.         cFileEntry.FileCrc32 = *(DWORD*)( reinterpret_cast< DWORD >( lpOverlay ) );
  449.         lpOverlay += 4;
  450.  
  451.         //
  452.         // Read the file flags.
  453.         // ------------------------------------------------------------------
  454.  
  455.         cFileEntry.CheckFileSize    = lpOverlay[ 0 ];
  456.         cFileEntry.CheckFileCrc32    = lpOverlay[ 1 ];
  457.         cFileEntry.ShowFileDate        = lpOverlay[ 2 ];
  458.  
  459.         lpOverlay += 3;
  460.         lpOverlay += 2; // Two unknown bytes.
  461.  
  462.         //
  463.         // Read the file patch count.
  464.         // ------------------------------------------------------------------
  465.  
  466.         cFileEntry.FilePatchCount = *(DWORD*)( reinterpret_cast< DWORD >( lpOverlay ) );
  467.         lpOverlay += 4;
  468.  
  469.         //
  470.         // Loop and read the file patches.
  471.         // ------------------------------------------------------------------
  472.  
  473.         for( unsigned long y = 0; y < cFileEntry.FilePatchCount; y++ )
  474.         {
  475.             CODEFUSION_PATCHENTRY cPatchEntry;
  476.  
  477.             //
  478.             // Read patch type.
  479.             // ------------------------------------------------------------------
  480.  
  481.             cPatchEntry.PatchType = lpOverlay[ 0 ];
  482.             lpOverlay += 1;
  483.  
  484.             //
  485.             // Patch Type 0 = Byte Replace
  486.             //
  487.             // Patch type 0 tells the patcher to replace bytes at
  488.             // the specific offset in the file.
  489.             //
  490.             // ------------------------------------------------------------------
  491.             if( cPatchEntry.PatchType == 0 )
  492.             {
  493.                 //
  494.                 // Read patch offset.
  495.                 // ------------------------------------------------------------------
  496.  
  497.                 cPatchEntry.PatchOffset = *(DWORD*)( reinterpret_cast< DWORD >( lpOverlay ) );
  498.                 lpOverlay += 4;
  499.  
  500.                 //
  501.                 // Read patch length.
  502.                 // ------------------------------------------------------------------
  503.  
  504.                 unsigned char cPatchLength = lpOverlay[ 0 ];
  505.                 lpOverlay += 1;
  506.  
  507.                 //
  508.                 // Read patch data.
  509.                 // ------------------------------------------------------------------
  510.  
  511.                 cPatchEntry.PatchData.resize( static_cast< size_t >( cPatchLength ), 0x00 );
  512.                 memcpy( &cPatchEntry.PatchData[ 0 ], lpOverlay, static_cast< size_t >( cPatchLength ) );
  513.                 lpOverlay += cPatchLength;
  514.  
  515.                 //
  516.                 // Decrypt patch data.
  517.                 //
  518.                 if( this->m_vOverlay.Encrypted )
  519.                     DecryptVector( cPatchLength, cPatchEntry.PatchData );
  520.             }
  521.  
  522.             //
  523.             // Patch Type 1, 2, 3 = Find and Replace
  524.             //
  525.             // Patch types 1 and 3 tell the patcher to replace bytes
  526.             // based on a given pattern, and not a specific offset.
  527.             //
  528.             // 1 = Normal find and replace.
  529.             // 2 = Find and replace all.
  530.             // 3 = Pattern find and replace.
  531.             //
  532.             // ------------------------------------------------------------------
  533.             else if( cPatchEntry.PatchType == 1 || cPatchEntry.PatchType == 2 || cPatchEntry.PatchType == 3 )
  534.             {
  535.                 //
  536.                 // Read patch offset.
  537.                 // ------------------------------------------------------------------
  538.  
  539.                 cPatchEntry.PatchOffset = *(DWORD*)( reinterpret_cast< DWORD >( lpOverlay ) );
  540.                 lpOverlay += 4;
  541.  
  542.                 //
  543.                 // Read patch length.
  544.                 // ------------------------------------------------------------------
  545.  
  546.                 unsigned char cPatchLength = lpOverlay[ 0 ];
  547.                 lpOverlay += 1;
  548.  
  549.                 //
  550.                 // Read patch replacement data.
  551.                 // ------------------------------------------------------------------
  552.  
  553.                 cPatchEntry.ReplaceData.resize( static_cast< size_t >( cPatchLength ), 0x00 );
  554.                 memcpy( &cPatchEntry.ReplaceData[ 0 ], lpOverlay, static_cast< size_t >( cPatchLength ) );
  555.                 lpOverlay += cPatchLength;
  556.  
  557.                 //
  558.                 // Decrypt replacement data.
  559.                 //
  560.                 if( this->m_vOverlay.Encrypted )
  561.                     DecryptVector( cPatchLength, cPatchEntry.ReplaceData );
  562.  
  563.                 //
  564.                 // Read pattern length.
  565.                 // ------------------------------------------------------------------
  566.  
  567.                 unsigned char cPatternLength = lpOverlay[ 0 ];
  568.                 lpOverlay += 1;
  569.  
  570.                 //
  571.                 // Read pattern data.
  572.                 // ------------------------------------------------------------------
  573.  
  574.                 cPatchEntry.FindData.resize( static_cast< size_t >( cPatternLength ), 0x00 );
  575.                 memcpy( &cPatchEntry.FindData[ 0 ], lpOverlay, static_cast< size_t >( cPatternLength ) );
  576.                 lpOverlay += cPatternLength;
  577.  
  578.                 //
  579.                 // Decrypt pattern data.
  580.                 //
  581.                 if( this->m_vOverlay.Encrypted )
  582.                     DecryptVector( cPatternLength, cPatchEntry.FindData );
  583.             }
  584.  
  585.             //
  586.             // Patch Type 5 = Truncate EOF
  587.             //
  588.             // Patch type 5 truncates a file to the given offset
  589.             // replacing the original end of file position.
  590.             //
  591.             // ------------------------------------------------------------------
  592.             else if( cPatchEntry.PatchType == 5 )
  593.             {
  594.                 //
  595.                 // Read patch offset.
  596.                 // ------------------------------------------------------------------
  597.  
  598.                 cPatchEntry.PatchOffset = *(DWORD*)( reinterpret_cast< DWORD >( lpOverlay ) );
  599.                 lpOverlay += 4;
  600.  
  601.                 lpOverlay += 2; // Theres two 0x00 0x00 bytes, not sure what they are for.
  602.             }
  603.            
  604.             //
  605.             // Unknown Patch Type
  606.             //
  607.             // For any other patch types that we are unsure
  608.             // about yet, we must fail. We cannot determine
  609.             // the size of the unknown entry so all patches
  610.             // behind this point would be unaligned.
  611.             //
  612.             // ------------------------------------------------------------------
  613.             else
  614.             {
  615.                 LogMessage( _T( "ERROR: Unknown patch type found:\r\nType: 0x%08X\r\nUnable to continue dumping!\r\n" ), cPatchEntry.PatchType );
  616.                 return E_FAIL;
  617.             }
  618.  
  619.             //
  620.             // Push back patch enter.
  621.             // ------------------------------------------------------------------
  622.  
  623.             cFileEntry.PatchEntries.push_back( cPatchEntry );
  624.         }
  625.  
  626.         //
  627.         // Push back file entry.
  628.         // ------------------------------------------------------------------
  629.  
  630.         this->m_vOverlay.FileEntries.push_back( cFileEntry );
  631.     }
  632.  
  633.     LogMessage( _T( "Overlay Dump Successful!\r\n" ) );
  634.  
  635.     if( FAILED( this->SaveOverlay() ) )
  636.     {
  637.         LogMessage( _T( "ERROR: Failed to save log of dumped overlay.\r\n" ) );
  638.         return E_FAIL;
  639.     }
  640.  
  641.     return S_OK;
  642. }
  643.  
  644.  
  645. HRESULT CFileDump::SaveOverlay( void )
  646. {
  647.  
  648.     // Some basic checks.
  649.     if( ! this->m_vFileDump )
  650.         return E_FAIL;
  651.     if( ! this->m_vFileSize )
  652.         return E_FAIL;
  653.     if( this->m_vOverlay.FilesToPatch == 0 )
  654.         return E_FAIL;
  655.     if( this->m_vSaveMethod > 1 )
  656.         return E_FAIL;
  657.    
  658.     //
  659.     // Create dump log file name.
  660.     // ------------------------------------------------------------------
  661.    
  662.     std::string strFileName = PathFindFileName( this->m_vFilePath.c_str() );
  663.  
  664.     time_t tTime = { 0 };
  665.     time( & tTime );
  666.  
  667.     TCHAR tszTime[ 1024 ] = { 0 };
  668.     _stprintf_s( tszTime, 1024, _T( ".%d.txt" ), tTime );
  669.  
  670.     strFileName += tszTime;
  671.  
  672.     //
  673.     // Create dump log file and begin writing.
  674.     // ------------------------------------------------------------------
  675.  
  676.     HANDLE hFileHandle = CreateFile( strFileName.c_str(), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
  677.     if( hFileHandle == INVALID_HANDLE_VALUE )
  678.     {
  679.         LogMessage( _T( "ERROR: Failed to create dump log file.\r\n" ) );
  680.         return E_FAIL;
  681.     }
  682.    
  683.     // Buffer for internal function use.
  684.     TCHAR tszOutput[ 1024 ] = { 0 };
  685.  
  686.     //
  687.     // Prepare overview information.
  688.     // ------------------------------------------------------------------
  689.  
  690.     std::string strOverview = TXT_OVERVIEW_HEADER;
  691.  
  692.     ReplaceString( strOverview, "{FILE_PATH}", this->m_vFilePath );
  693.  
  694.     _stprintf_s( tszOutput, 1024, _T( "%d" ), this->m_vFileSize );
  695.     ReplaceString( strOverview, "{FILE_SIZE}", tszOutput );
  696.  
  697.     _stprintf_s( tszOutput, 1024, _T( "%d" ), this->m_vOverlaySize );
  698.     ReplaceString( strOverview, "{OVERLAY_SIZE}", tszOutput );
  699.  
  700.     _stprintf_s( tszOutput, 1024, _T( "%s" ), ( this->m_vOverlay.Encrypted == 0 ) ? "False" : "True" );
  701.     ReplaceString( strOverview, "{OVERLAY_ENCRYPTED}", tszOutput );
  702.  
  703.  
  704.     //
  705.     // Prepare main window information.
  706.     // ------------------------------------------------------------------
  707.  
  708.     std::string strMainWindow = TXT_MAINWINDOW_HEADER;
  709.  
  710.     ReplaceString( strMainWindow, "{WINDOW_TITLE}", this->m_vOverlay.WindowTitle );
  711.     ReplaceString( strMainWindow, "{WINDOW_DESCRIPTION}", this->m_vOverlay.PatchDescription );
  712.     ReplaceString( strMainWindow, "{WINDOW_NOTES}", this->m_vOverlay.PatchNotes );
  713.  
  714.     //
  715.     // Prepare about window information.
  716.     // ------------------------------------------------------------------
  717.  
  718.     std::string strAboutWindow = TXT_ABOUTWINDOW_HEADER;
  719.  
  720.     ReplaceString( strAboutWindow, "{ABOUT_BUTTON_ONE_TEXT}", this->m_vOverlay.ButtonOneText );
  721.     ReplaceString( strAboutWindow, "{ABOUT_BUTTON_ONE_ACTION}", this->m_vOverlay.ButtonOneAction );
  722.     ReplaceString( strAboutWindow, "{ABOUT_BUTTON_TWO_TEXT}", this->m_vOverlay.ButtonTwoText );
  723.     ReplaceString( strAboutWindow, "{ABOUT_BUTTON_TWO_ACTION}", this->m_vOverlay.ButtonTwoAction );
  724.     ReplaceString( strAboutWindow, "{ABOUT_BOX_TEXT}", this->m_vOverlay.AboutBox );
  725.  
  726.     //
  727.     // Loop overview file entries and prepare file patches.
  728.     // ------------------------------------------------------------------
  729.  
  730.     std::string strPatchInfo = TXT_PATCHINFO_HEADER;
  731.  
  732.     _stprintf_s( tszOutput, 1024, _T( "%d" ), this->m_vOverlay.FilesToPatch );
  733.     ReplaceString( strPatchInfo, "{FILE_PATCH_COUNT}", tszOutput );
  734.  
  735.     for( int x = 0; x < this->m_vOverlay.FilesToPatch; x++ )
  736.     {
  737.         std::string strFileEntryHeader = TXT_FILEENTRY_HEADER;
  738.  
  739.         _stprintf_s( tszOutput, 1024, _T( "%d" ), ( x + 1 ) );
  740.         ReplaceString( strFileEntryHeader, "{FILE_ENTRY_NUMBER}", tszOutput );
  741.         ReplaceString( strFileEntryHeader, "{FILE_ENTRY_NAME}", this->m_vOverlay.FileEntries[x].FileName );
  742.         _stprintf_s( tszOutput, 1024, _T( "%d" ), this->m_vOverlay.FileEntries[x].FilePatchCount );
  743.         ReplaceString( strFileEntryHeader, "{FILE_ENTRY_PATCH_COUNT}", tszOutput );
  744.  
  745.         for( unsigned int y = 0; y < this->m_vOverlay.FileEntries[x].FilePatchCount; y++ )
  746.         {
  747.             std::string strFilePatchEntry;
  748.             switch( this->m_vOverlay.FileEntries[x].PatchEntries[y].PatchType )
  749.             {
  750.             case 0: strFilePatchEntry = TXT_FILEPATCHENTRY( 0 ); break;
  751.             case 1: strFilePatchEntry = TXT_FILEPATCHENTRY( 1 ); break;
  752.             case 2: strFilePatchEntry = TXT_FILEPATCHENTRY( 2 ); break;
  753.             case 3: strFilePatchEntry = TXT_FILEPATCHENTRY( 3 ); break;
  754.             case 4: strFilePatchEntry = TXT_FILEPATCHENTRY( 4 ); break;
  755.             case 5: strFilePatchEntry = TXT_FILEPATCHENTRY( 5 ); break;
  756.             }
  757.            
  758.             //
  759.             // Insert Count and Offset
  760.             // -------------------------------------
  761.  
  762.             _stprintf_s( tszOutput, 1024, _T( "%d" ), ( y + 1 ) );
  763.             ReplaceString( strFilePatchEntry, "{PATCH_ENTRY_NUMBER}", tszOutput );
  764.  
  765.             _stprintf_s( tszOutput, 1024, _T( "0x%08X" ),  this->m_vOverlay.FileEntries[x].PatchEntries[y].PatchOffset );
  766.             ReplaceString( strFilePatchEntry, "{PATCH_OFFSET}", tszOutput );
  767.  
  768.             //
  769.             // Insert Patch Specific Info
  770.             // -------------------------------------
  771.  
  772.             std::string strOrigData;
  773.             std::string strPatchData;
  774.  
  775.             switch( this->m_vOverlay.FileEntries[x].PatchEntries[y].PatchType )
  776.             {
  777.             case 0:
  778.                 ConvertVector( strPatchData, this->m_vOverlay.FileEntries[x].PatchEntries[y].PatchData );
  779.                 ReplaceString( strFilePatchEntry, "{PATCH_DATA}", strPatchData );
  780.                 break;
  781.  
  782.             case 1:
  783.             case 2:
  784.             case 3:
  785.                 ConvertVector( strOrigData, this->m_vOverlay.FileEntries[x].PatchEntries[y].FindData );
  786.                 ConvertVector( strPatchData, this->m_vOverlay.FileEntries[x].PatchEntries[y].ReplaceData );
  787.                 ReplaceString( strFilePatchEntry, "{PATCH_FIND_DATA}", strOrigData );
  788.                 ReplaceString( strFilePatchEntry, "{PATCH_REPLACE_DATA}", strPatchData );
  789.                 break;
  790.  
  791.             case 4:
  792.             case 5:
  793.                 break;
  794.             }
  795.  
  796.             strFileEntryHeader += strFilePatchEntry;
  797.         }
  798.  
  799.         strPatchInfo += strFileEntryHeader;
  800.     }
  801.  
  802.     //
  803.     // Write Info To file
  804.     // -------------------------------------
  805.  
  806.     DWORD dwWritten = 0;
  807.  
  808.     WriteFile( hFileHandle, strOverview.c_str(), strOverview.size(), &dwWritten, 0 );
  809.     WriteFile( hFileHandle, strMainWindow.c_str(), strMainWindow.size(), &dwWritten, 0 );
  810.     WriteFile( hFileHandle, strAboutWindow.c_str(), strAboutWindow.size(), &dwWritten, 0 );
  811.     WriteFile( hFileHandle, strPatchInfo.c_str(), strPatchInfo.size(), &dwWritten, 0 );
  812.  
  813.     //
  814.     // Cleanup and Return
  815.     // -------------------------------------
  816.  
  817.     CloseHandle( hFileHandle );
  818.     hFileHandle = NULL;
  819.  
  820.     return S_OK;
  821. }
Derp~
Need a great web host? Check out: AnHonestHost.com


Donations can be made via Paypal:
https://www.paypal.me/atom0s
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests