diff --git a/res/mbr/mbr.S b/res/mbr/mbr.S index 21f7c682..3b20c903 100644 --- a/res/mbr/mbr.S +++ b/res/mbr/mbr.S @@ -309,18 +309,15 @@ dsk_interrupt: pushf cli call disk_swap - mov cs:[int13_cmd], ah # Keep a copy of the command for later referal dsk_interrupt_org = .+1 call 0:INT_DSK*4 # These CS:IP values will be changed at runtime - push ax - mov ah, cs:[int13_cmd] # Check the original command for swap exceptions - cmp ah, 0x08 # LILO's mapper has these 2 exceptions - je 0f - cmp ah, 0x15 - je 0f + # NB: subcommands 0x08 and 0x15 (disk props) modify DL, but they only + # do so to return the number of drives => unless your computer has 128 + # or 129 drives, disk_swap will not touch those values. + pushf # Don't modify the returned flags call disk_swap -0: pop ax + popf iret @@ -328,11 +325,10 @@ dsk_interrupt_org = .+1 /* Data section */ /********************************************************************************/ -int13_cmd: .byte 0x00 -prompt_string: .string "\r\nPress any key to boot from USB." -dot_string = .-2 # Reuse the end of previous string counter_timeout:.byte DOT_NUMBER*DOT_TIMEOUT + 1 counter_dot: .byte DOT_TIMEOUT +prompt_string: .string "\r\nPress any key to boot from USB." +dot_string = .-2 # Reuse the end of previous string /********************************************************************************/ diff --git a/res/mbr/mbr.bin b/res/mbr/mbr.bin index c58f3159..41c40e14 100644 Binary files a/res/mbr/mbr.bin and b/res/mbr/mbr.bin differ diff --git a/src/format.c b/src/format.c index 3140d36f..a9e7ca76 100644 --- a/src/format.c +++ b/src/format.c @@ -464,7 +464,13 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) if ((dt == DT_ISO) && ((fs == FS_FAT16) || (fs == FS_FAT32))) { r = write_syslinux_mbr(&fake_fd); } else { - r = write_win7_mbr(&fake_fd); + if (IsChecked(IDC_RUFUS_MBR)) { + uprintf("Using Rufus bootable USB selection MBR\n"); + r = write_rufus_mbr(&fake_fd); + } else { + uprintf("Using Windows 7 MBR\n"); + r = write_win7_mbr(&fake_fd); + } } out: diff --git a/src/ms-sys/.msvc/ms-sys.vcxproj b/src/ms-sys/.msvc/ms-sys.vcxproj index 0de43532..a749930e 100644 --- a/src/ms-sys/.msvc/ms-sys.vcxproj +++ b/src/ms-sys/.msvc/ms-sys.vcxproj @@ -45,6 +45,7 @@ + diff --git a/src/ms-sys/.msvc/ms-sys.vcxproj.filters b/src/ms-sys/.msvc/ms-sys.vcxproj.filters index 3dd1e24c..cbf09424 100644 --- a/src/ms-sys/.msvc/ms-sys.vcxproj.filters +++ b/src/ms-sys/.msvc/ms-sys.vcxproj.filters @@ -107,6 +107,9 @@ Header Files + + Header Files + diff --git a/src/ms-sys/br.c b/src/ms-sys/br.c index 86379856..4b9891c3 100644 --- a/src/ms-sys/br.c +++ b/src/ms-sys/br.c @@ -100,6 +100,16 @@ int is_win7_mbr(FILE *fp) contains_data(fp, 0x1FE, aucRef, sizeof(aucRef)); } /* is_win7_mbr */ +int is_rufus_mbr(FILE *fp) +{ + #include "mbr_rufus.h" + unsigned char aucRef[] = {0x55, 0xAA}; + + return + contains_data(fp, 0x0, mbr_rufus_0x0, sizeof(mbr_rufus_0x0)) && + contains_data(fp, 0x1FE, aucRef, sizeof(aucRef)); +} /* is_rufus_mbr */ + int is_syslinux_mbr(FILE *fp) { #include "mbr_syslinux.h" @@ -170,6 +180,16 @@ int write_win7_mbr(FILE *fp) write_data(fp, 0x1FE, aucRef, sizeof(aucRef)); } /* write_win7_mbr */ +int write_rufus_mbr(FILE *fp) +{ + #include "mbr_rufus.h" + unsigned char aucRef[] = {0x55, 0xAA}; + + return + write_data(fp, 0x0, mbr_rufus_0x0, sizeof(mbr_rufus_0x0)) && + write_data(fp, 0x1FE, aucRef, sizeof(aucRef)); +} /* write_rufus_mbr */ + int write_syslinux_mbr(FILE *fp) { #include "mbr_syslinux.h" diff --git a/src/ms-sys/inc/br.h b/src/ms-sys/inc/br.h index 9d477f72..1ff14f3b 100644 --- a/src/ms-sys/inc/br.h +++ b/src/ms-sys/inc/br.h @@ -36,6 +36,10 @@ int is_vista_mbr(FILE *fp); FALSE.The file position will change when this function is called! */ int is_win7_mbr(FILE *fp); +/* returns TRUE if the file has a Rufus master boot record, otherwise + FALSE.The file position will change when this function is called! */ +int is_rufus_mbr(FILE *fp); + /* returns TRUE if the file has a syslinux master boot record, otherwise FALSE.The file position will change when this function is called! */ int is_syslinux_mbr(FILE *fp); @@ -64,6 +68,10 @@ int write_vista_mbr(FILE *fp); FALSE */ int write_win7_mbr(FILE *fp); +/* Writes a Rufus master boot record to a file, returns TRUE on success, otherwise + FALSE */ +int write_rufus_mbr(FILE *fp); + /* Writes a syslinux master boot record to a file, returns TRUE on success, otherwise FALSE */ int write_syslinux_mbr(FILE *fp); diff --git a/src/ms-sys/inc/mbr_rufus.h b/src/ms-sys/inc/mbr_rufus.h new file mode 100644 index 00000000..2a097843 --- /dev/null +++ b/src/ms-sys/inc/mbr_rufus.h @@ -0,0 +1,40 @@ +/* First 446 bytes of boot selection MBR from Rufus */ +unsigned char mbr_rufus_0x0[440] = { + 0x41, 0x4b, 0x45, 0x4f, 0xfc, 0x31, 0xc0, 0xfa, 0x8e, 0xd0, 0xbc, 0x00, + 0x7c, 0xfb, 0x89, 0xe6, 0x89, 0xe7, 0x1e, 0x06, 0x8e, 0xd8, 0xbb, 0x13, + 0x04, 0x8b, 0x07, 0x48, 0x89, 0x07, 0xc1, 0xe0, 0x06, 0x2d, 0xc0, 0x07, + 0x8e, 0xc0, 0xb9, 0x00, 0x02, 0xf3, 0xa4, 0x50, 0x68, 0x30, 0x7c, 0xcb, + 0x8e, 0xd8, 0x6a, 0x00, 0x07, 0x66, 0x31, 0xdb, 0xb9, 0x01, 0x00, 0xba, + 0x81, 0x00, 0xe8, 0x80, 0x00, 0x72, 0x67, 0xbb, 0xbe, 0x7d, 0xb9, 0x04, + 0x00, 0x26, 0x80, 0x3f, 0x00, 0x7c, 0x09, 0x75, 0x05, 0x83, 0xc3, 0x10, + 0xe2, 0xf3, 0xeb, 0x52, 0xbe, 0x78, 0x7d, 0xe8, 0xd1, 0x00, 0xe8, 0xc1, + 0x00, 0xba, 0x4c, 0x7d, 0xbe, 0x61, 0x7d, 0xe8, 0x97, 0x00, 0xb4, 0x01, + 0xcd, 0x16, 0x75, 0x37, 0xb4, 0x02, 0xcd, 0x16, 0x24, 0x04, 0x75, 0x32, + 0x80, 0x3e, 0x77, 0x7d, 0x00, 0x7f, 0x0b, 0xbe, 0x98, 0x7d, 0xe8, 0xaa, + 0x00, 0xc6, 0x06, 0x77, 0x7d, 0x12, 0x80, 0x3e, 0x76, 0x7d, 0x00, 0x75, + 0xd9, 0xe8, 0x80, 0x00, 0xba, 0x66, 0x7d, 0xbe, 0x6c, 0x7d, 0xe8, 0x64, + 0x00, 0x07, 0x1f, 0xba, 0x80, 0x00, 0xea, 0x00, 0x7c, 0x00, 0x00, 0xe8, + 0x6a, 0x00, 0xe8, 0x75, 0x00, 0xbb, 0xbe, 0x7d, 0x8b, 0x17, 0x8b, 0x4f, + 0x02, 0x66, 0x8b, 0x5f, 0x08, 0xe8, 0x05, 0x00, 0x73, 0xdf, 0x07, 0x1f, + 0xcb, 0x60, 0xb4, 0x41, 0xbb, 0xaa, 0x55, 0xcd, 0x13, 0x72, 0x2c, 0x81, + 0xfb, 0x55, 0xaa, 0x75, 0x26, 0xf7, 0xc1, 0x01, 0x00, 0x74, 0x20, 0x61, + 0x1e, 0x66, 0x31, 0xc0, 0x8e, 0xd8, 0x66, 0x50, 0x66, 0x53, 0x50, 0x68, + 0x00, 0x7c, 0x40, 0x50, 0x6a, 0x10, 0x89, 0xe6, 0xb4, 0x42, 0xcd, 0x13, + 0x9f, 0x83, 0xc4, 0x10, 0x9e, 0x1f, 0xc3, 0x61, 0xbb, 0x00, 0x7c, 0xb8, + 0x01, 0x02, 0xcd, 0x13, 0xc3, 0xfa, 0x8b, 0x1c, 0x26, 0x66, 0x8b, 0x07, + 0x66, 0x89, 0x04, 0x26, 0x89, 0x17, 0x26, 0x8c, 0x4f, 0x02, 0xfb, 0xc3, + 0xfa, 0xbb, 0x20, 0x00, 0x66, 0xa1, 0x61, 0x7d, 0x26, 0x66, 0x89, 0x07, + 0xfb, 0xc3, 0xb4, 0x01, 0xcd, 0x16, 0x74, 0x06, 0xb4, 0x00, 0xcd, 0x16, + 0xe2, 0xf4, 0xc3, 0xac, 0x3c, 0x00, 0x74, 0x09, 0xb4, 0x0e, 0xbb, 0x07, + 0x00, 0xcd, 0x10, 0xeb, 0xf2, 0xc3, 0x52, 0x80, 0xe2, 0xfe, 0x80, 0xfa, + 0x80, 0x5a, 0x75, 0x03, 0x80, 0xf2, 0x01, 0xc3, 0x9c, 0xfa, 0x2e, 0x80, + 0x3e, 0x76, 0x7d, 0x00, 0x74, 0x0a, 0x2e, 0xfe, 0x0e, 0x77, 0x7d, 0x2e, + 0xfe, 0x0e, 0x76, 0x7d, 0x9a, 0x20, 0x00, 0x00, 0x00, 0xcf, 0x9c, 0xfa, + 0xe8, 0xd3, 0xff, 0x9a, 0x4c, 0x00, 0x00, 0x00, 0x9c, 0xe8, 0xca, 0xff, + 0x9d, 0xcf, 0x49, 0x12, 0x0d, 0x0a, 0x50, 0x72, 0x65, 0x73, 0x73, 0x20, + 0x61, 0x6e, 0x79, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x74, 0x6f, 0x20, 0x62, + 0x6f, 0x6f, 0x74, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x55, 0x53, 0x42, + 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; diff --git a/src/resource.h b/src/resource.h index 2b201193..b26f92f2 100644 --- a/src/resource.h +++ b/src/resource.h @@ -56,6 +56,7 @@ #define IDC_TEST 1015 #define IDC_SELECT_ISO 1016 #define IDC_SET_ICON 1017 +#define IDC_RUFUS_MBR 1018 #define IDC_ISO_PROGRESS 1020 #define IDC_ISO_FILENAME 1021 #define IDC_ISO_ABORT 1022 diff --git a/src/rufus.c b/src/rufus.c index bfde4c52..0b417b7d 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -944,6 +944,7 @@ static void EnableControls(BOOL bEnable) EnableWindow(GetDlgItem(hMainDialog, IDC_SELECT_ISO), bEnable); EnableWindow(GetDlgItem(hMainDialog, IDC_NBPASSES), bEnable); EnableWindow(GetDlgItem(hMainDialog, IDC_SET_ICON), bEnable); + EnableWindow(GetDlgItem(hMainDialog, IDC_RUFUS_MBR), bEnable); SetDlgItemTextA(hMainDialog, IDCANCEL, bEnable?"Close":"Cancel"); } @@ -1050,6 +1051,9 @@ DWORD WINAPI ISOScanThread(LPVOID param) "This ISO image doesn't appear to use either...", "Unsupported ISO", MB_OK|MB_ICONINFORMATION); safe_free(iso_path); } else { + EnableWindow(GetDlgItem(hMainDialog, IDC_RUFUS_MBR), (iso_report.has_bootmgr) || (IS_WINPE(iso_report.winpe))); + CheckDlgButton(hMainDialog, IDC_RUFUS_MBR, + ((iso_report.winpe&WINPE_I386)==WINPE_I386)?BST_CHECKED:BST_UNCHECKED); if (iso_report.has_old_vesamenu) { fd = fopen(vesamenu_filename, "rb"); if (fd != NULL) { @@ -1347,8 +1351,13 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA IGNORE_RETVAL(ComboBox_SetItemData(hDOSType, ComboBox_AddStringU(hDOSType, "FreeDOS"), DT_FREEDOS)); } IGNORE_RETVAL(ComboBox_SetItemData(hDOSType, ComboBox_AddStringU(hDOSType, "ISO Image"), DT_ISO)); - if ((selection_default == DT_ISO) && (iso_path == NULL)) - selection_default = (bWithFreeDOS)?DT_FREEDOS:DT_WINME; + if (selection_default == DT_ISO) { + if (iso_path == NULL) + selection_default = (bWithFreeDOS)?DT_FREEDOS:DT_WINME; + else + EnableWindow(GetDlgItem(hMainDialog, IDC_RUFUS_MBR), + (iso_report.has_bootmgr) || (IS_WINPE(iso_report.winpe))); + } for (i=0; ihttp://rufus.akeo.ie",IDC_ABOUT_RUFUS_URL, "SysLink",WS_TABSTOP,46,47,114,9 - LTEXT "Version 1.1.6 (Build 156)",IDC_STATIC,46,19,78,8 + LTEXT "Version 1.1.6 (Build 157)",IDC_STATIC,46,19,78,8 PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8 @@ -223,8 +224,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,1,6,156 - PRODUCTVERSION 1,1,6,156 + FILEVERSION 1,1,6,157 + PRODUCTVERSION 1,1,6,157 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -241,13 +242,13 @@ BEGIN BEGIN VALUE "CompanyName", "akeo.ie" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "1.1.6.156" + VALUE "FileVersion", "1.1.6.157" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "1.1.6.156" + VALUE "ProductVersion", "1.1.6.157" END END BLOCK "VarFileInfo"