/* getboot.c - Copia el sector de arranque a un archivo Copyright (C) 2000-2002, Luis Carlos 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 Version para Win32 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("GBOOT32 - Copy a boot sector from to a file (Win32 version).\n"); if (argc != 3) { printf("Usage: getboot drive filename\n\n"); exit(1); } drive = argv[1]; drive[0] = toupper(drive[0]); strcpy(device, "\\\\.\\x:"); device[4] = drive[0]; pathname = argv[2]; printf("Reading boot sector 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("\nwriting bootprogram %s...", pathname); hFile = CreateFile(pathname, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) { printf("\nError opening %s\n", pathname); exit(1); } bytes = 0; WriteFile(hFile, bootsect, 512, &bytes, NULL); CloseHandle(hFile); printf("\n"); return 0; }