/////////////////////////////////////////////////////////////////////////////// // // Credits: TSCube (original source code) and Canterwood (xp style and more) // /////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include "resource.h" BOOL CALLBACK DialogProc (HWND, UINT, WPARAM, LPARAM) ; HINSTANCE hInst; OPENFILENAME ofn; DWORD getCrc32(HANDLE); int Patch(HWND); char szFileFilter[]="Executable Files " "*.*"; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { hInst = hInstance; InitCommonControls(); DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG),NULL,(DLGPROC)DialogProc,0); return 0; } BOOL CALLBACK DialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_BROWSE : ZeroMemory(&ofn,sizeof(ofn)); ofn.hwndOwner = hWnd; ofn.hInstance = hInst; ofn.lpstrFilter = szFileFilter; ofn.nMaxFile = 512; ofn.lpstrTitle = "Browse for..."; ofn.lpstrFile = "YTK Lite.exe"; ofn.nMaxFileTitle = 512; ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER | OFN_HIDEREADONLY; ofn.lStructSize = sizeof(ofn); if (GetOpenFileName(&ofn)){ SetWindowText(GetDlgItem(hWnd,IDC_FILE),ofn.lpstrFile); } break; case IDC_PATCH : Patch(hWnd); break; case IDC_ABOUT : MessageBox(hWnd,"Patch by: Ap0x\nPatch for: SomeFile v.1.0.0 \nWeb-site: http://ap0x.headcoders.net","About...",0x40); break; case IDC_EXIT : EndDialog(hWnd, TRUE); break; } return 0; break; case WM_CLOSE : EndDialog(hWnd,0); return 0 ; break; case WM_INITDIALOG : RECT DlgRect; RECT DesktopRect; HWND hWindow; SendMessage(hWnd, WM_SETICON, TRUE,(LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON))); SendDlgItemMessage(hWnd, IDC_FILE,EM_SETLIMITTEXT,512,0); SetDlgItemTextA (hWnd, IDC_FILE, "browse for file..."); CheckDlgButton(hWnd,IDC_CHECK1,BST_CHECKED); GetWindowRect(hWnd,&DlgRect); hWindow = GetDesktopWindow(); GetWindowRect(hWindow,&DesktopRect); int DlgHeight = DlgRect.bottom - DlgRect.top; int DlgWidth = DlgRect.right - DlgRect.left; int x=(DesktopRect.right+DesktopRect.left-DlgWidth)/2; int y =(DesktopRect.bottom+DesktopRect.top-DlgHeight)/2; MoveWindow(hWnd,x,y,DlgWidth,DlgHeight,FALSE); return 0 ; break; } return 0; } int Patch(HWND hWnd) { char szName[800] = ""; char szNameBackup[15] = "backup.bak"; BYTE patched[111] = {0x08,0x09,0x09,0x09,0x09,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x09,0x09,0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x09,0x09,0x08,0x09,0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x08,0x09,0x09,0x08,0x09,0x09,0x09,0x08,0x09,0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09}; LONG offset[111] = {0x17EE29,0x18095A,0x180A3A,0x180B0E,0x180C57,0x180D89,0x180ED5,0x180F0E,0x18124B,0x181280,0x18145F,0x181496,0x181566,0x181595,0x18167D,0x1816A9,0x181870,0x1818A6,0x181C92,0x181CBD,0x181D87,0x181DB0,0x181F76,0x181F7F,0x1820C7,0x1821BA,0x1821C3,0x182975,0x182A68,0x18466B,0x1846B3,0x184785,0x1847DA,0x184B21,0x184B7C,0x184C63,0x184C6C,0x185937,0x185975,0x185BBC,0x185C3D,0x185D18,0x185E01,0x185EFF,0x185FCD,0x187760,0x187798,0x187AC4,0x187B01,0x187BC8,0x187C1F,0x187DDC,0x187E1A,0x188002,0x188047,0x18F7E6,0x18F809,0x18FA12,0x18FA46,0x190DEA,0x190E19,0x190EF8,0x190F2A,0x19100C,0x19103C,0x191121,0x191156,0x192B62,0x192C33,0x192CF5,0x192D30,0x192E0C,0x192E2D,0x192F27,0x192FDF,0x19309C,0x19318D,0x193289,0x19338F,0x193810,0x193834,0x193920,0x193971,0x193B35,0x193B6D,0x193C33,0x193C61,0x194E78,0x195568,0x19559C,0x19560A,0x1956EE,0x1958EC,0x195922,0x195A0A,0x195A3B,0x195B34,0x195B3D,0x195D11,0x195F07,0x195FE5,0x1960CA,0x196532,0x196629,0x196759,0x196889,0x1969B7,0x196AA0,0x196B89,0x196C59,0x196D2D}; DWORD number=111; DWORD crc32 = 0xD20DBF5E; // Create file name GetWindowText(GetDlgItem(hWnd,IDC_FILE),szName,GetWindowTextLength(GetDlgItem(hWnd,IDC_FILE))+1); // check CRC32 of file : HANDLE hFile = CreateFile( szName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ( hFile == INVALID_HANDLE_VALUE ) { MessageBox(hWnd,"I can't access file or patch it!","CRC error",MB_ICONEXCLAMATION); return 1; } if (getCrc32(hFile) != crc32) { MessageBox(hWnd,"Incorrect version or file already patched !","CRC error",MB_ICONEXCLAMATION); CloseHandle(hFile); return 1; } // create backup : if (IsDlgButtonChecked(hWnd,IDC_CHECK1)==BST_CHECKED) { if (!CopyFile(szName,szNameBackup,FALSE)) { MessageBox(hWnd,"I can't find the original file !","Backup error",MB_ICONEXCLAMATION); CloseHandle(hFile); return 1; } } // Patch file DWORD nbWritten; // not used for (DWORD i=0;i0; j--) { if (crcTmp1&1) crcTmp1 = (crcTmp1 >> 1) ^ 0xEDB88320L; else crcTmp1 >>= 1; } crcTable[i] = crcTmp1; } //getfilesize : DWORD fileSize = GetFileSize(hFile,NULL); if (fileSize == 0xFFFFFFFF) return 0; //Compute CRC32 : HANDLE hFileMapping = CreateFileMapping( hFile, NULL,PAGE_READONLY, 0, 0, NULL); if (!hFileMapping) return 0; BYTE* ptr = (BYTE*)MapViewOfFile( hFileMapping, FILE_MAP_READ, 0, 0, 0); if (!ptr) { CloseHandle(hFileMapping); return 0; } BYTE* ptr_tmp = ptr; // save base pointer DWORD crcTmp2= 0xFFFFFFFF; while(fileSize--) { crcTmp2 = ((crcTmp2>>8) & 0x00FFFFFF) ^ crcTable[ (crcTmp2^(*ptr)) & 0xFF ]; ptr++; } UnmapViewOfFile(ptr_tmp); CloseHandle(hFileMapping); return (crcTmp2^0xFFFFFFFF); }