/* mkboot32.c - Reescribe el sector de arranque a partir de un archivo (Version para Win32) Copyright (C) 1999-2002 Luis C. Castro Skertchly This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Versiones Corriendo: 1.0 22 de Mayo de 2000 1.1 13 de Diciembre de 2002 - Se agrego el uso de FILE_SHARE_WRITE */ #define _CRT_SECURE_NO_DEPRECATE #define _WIN32_WINNT 0x0501 #define WIN32_LEAN_AND_MEAN #include #include #include #include #define BEGIN_BPB 0x0b #define END_BPB 0x3d char *pathname; char *drive; char device[32]; char bootsect[512]; char bootprog[512]; DWORD bytes; WORD i; HANDLE hFile; int main(int argc, char **argv) { printf("MKBOOT32 - Writes a boot sector from a file (Win32 version).\n"); if (argc != 3) { printf("Usage: mkboot32 bootprogram drive\n\n"); exit(1); } pathname = argv[1]; drive = argv[2]; drive[0] = toupper(drive[0]); strcpy(device, "\\\\.\\x:"); device[4] = drive[0]; printf("Reading BPB from %s...", device); hFile = CreateFile(device, GENERIC_READ, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) { printf("\nError opening %s\n", device); exit(1); } ReadFile(hFile, bootsect, 512, &bytes, NULL); CloseHandle(hFile); printf("\nReading bootprogram %s...", pathname); CreateFile(pathname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) { printf("\nError opening %s\n", pathname); exit(1); } bytes = 0; ReadFile(hFile, bootprog, 512, &bytes, NULL); CloseHandle(hFile); bootprog[0] = 0xEB; bootprog[1] = 0x3C; bootprog[2] = 0x90; for (i = BEGIN_BPB; i <= END_BPB; i++) bootprog[i] = bootsect[i]; printf("\nWriting new boot sector on %s...", device); hFile = CreateFile(device, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) { printf("\nError opening %s\n", device); exit(1); } WriteFile(hFile, bootprog, 512, &bytes, NULL); CloseHandle(hFile); printf("\n"); return 0; }