diff --git a/src/format.c b/src/format.c index a9e7ca76..e0c5df33 100644 --- a/src/format.c +++ b/src/format.c @@ -399,6 +399,33 @@ static BOOL ClearMBR(HANDLE hPhysicalDrive) return clear_mbr(&fake_fd); } +/* + * Our own MBR, not in ms-sys + */ +BOOL WriteRufusMBR(FILE *fp) +{ + HGLOBAL res_handle; + HRSRC res; + unsigned char aucRef[] = {0x55, 0xAA}; + unsigned char* rufus_mbr; + + res = FindResource(hMainInstance, MAKEINTRESOURCE(IDR_BR_MBR_BIN), RT_RCDATA); + if (res == NULL) { + uprintf("Unable to locate mbr.bin resource: %s\n", WindowsErrorString()); + return FALSE; + } + res_handle = LoadResource(NULL, res); + if (res_handle == NULL) { + uprintf("Unable to load mbr.bin resource: %s\n", WindowsErrorString()); + return FALSE; + } + rufus_mbr = (unsigned char*)LockResource(res_handle); + + return + write_data(fp, 0x0, rufus_mbr, 0x1b8) && + write_data(fp, 0x1fe, aucRef, sizeof(aucRef)); +} + /* * Process the Master Boot Record */ @@ -448,7 +475,8 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) break; } if (IsChecked(IDC_DOS)) { - buf[0x1be] = 0x80; // Set first partition bootable + // Set first partition bootable - masquerade as 0x81 for XP + buf[0x1be] = ((iso_report.winpe&WINPE_I386)==WINPE_I386)?0x81:0x80; } if (!write_sectors(hPhysicalDrive, SecSize, 0, nSecs, buf)) { @@ -466,7 +494,7 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) } else { if (IsChecked(IDC_RUFUS_MBR)) { uprintf("Using Rufus bootable USB selection MBR\n"); - r = write_rufus_mbr(&fake_fd); + r = WriteRufusMBR(&fake_fd); } else { uprintf("Using Windows 7 MBR\n"); r = write_win7_mbr(&fake_fd); @@ -554,6 +582,7 @@ static BOOL SetupWinPE(char drive_letter) const char* patch_str_org[] = { "\\minint\\txtsetup.sif", "\\minint\\system32\\" }; const char* patch_str_rep[] = { "\\$\\i386\\txtsetup.sif", "\\$\\i386\\system32\\" }; const char *win_nt_bt_org = "$win_nt$.~bt", *win_nt_bt_rep = "$\\i386"; + const char *rdisk_zero = "rdisk(0)"; const char* winnt_sif = "[Data]\n msdosinitiated = \"1\"\n"; const wchar_t* win_nt_ls = L"$win_nt$.~ls"; STARTUPINFOA si; @@ -570,7 +599,7 @@ static BOOL SetupWinPE(char drive_letter) buf = get_token_data(src, "OsLoadOptions"); if (buf != NULL) { for (i=0; i $\i386 if (safe_strnicmp(&buf[i], win_nt_bt_org, strlen(win_nt_bt_org)-1) == 0) { uprintf(" 0x%08X: '%s' -> '%s%s'\n", i, &buf[i], win_nt_bt_rep, &buf[i+strlen(win_nt_bt_org)]); strcpy(&buf[i], win_nt_bt_rep); buf[i+strlen(win_nt_bt_rep)] = buf[i+strlen(win_nt_bt_org)]; buf[i+strlen(win_nt_bt_rep)+1] = 0; } + // rdisk(0) -> rdisk(1) (MBR disk masquerading) + // TODO: only the first one seems to be needed + if (safe_strnicmp(&buf[i], rdisk_zero, strlen(rdisk_zero)-1) == 0) { + buf[i+6] = '1'; + uprintf(" 0x%08X: '%s' -> 'rdisk(1)'\n", i, rdisk_zero); + } } if ((!WriteFile(handle, buf, size, &rw_size, NULL)) || (size != rw_size)) { @@ -919,7 +955,8 @@ DWORD WINAPI FormatThread(LPVOID param) PrintStatus(0, TRUE, "Writing master boot record..."); if (!WriteMBR(hPhysicalDrive)) { - // Errorcode has already been set + if (!FormatStatus) + FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; goto out; } UpdateProgress(OP_FIX_MBR, -1.0f); diff --git a/src/rufus.h b/src/rufus.h index 5e8b7e5e..24b034ab 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -144,7 +144,7 @@ typedef struct { /* ISO details that the application may want */ #define WINPE_MININT 0x2A #define WINPE_I386 0x15 -#define IS_WINPE(r) (((r&WINPE_MININT) == WINPE_MININT)||((r&WINPE_I386)==WINPE_I386)) +#define IS_WINPE(r) (((r&WINPE_MININT) == WINPE_MININT)||((r&WINPE_I386) == WINPE_I386)) typedef struct { char label[192]; /* 3*64 to account for UTF-8 */ char usb_label[192]; /* converted USB label for workaround */ diff --git a/src/rufus.rc b/src/rufus.rc index 24a6e6c9..e597b927 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 206, 289 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW -CAPTION "Rufus v1.1.6.158" +CAPTION "Rufus v1.1.6.159" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN DEFPUSHBUTTON "Start",IDC_START,94,248,50,14 @@ -74,7 +74,7 @@ BEGIN DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP CONTROL "http://rufus.akeo.ie",IDC_ABOUT_RUFUS_URL, "SysLink",WS_TABSTOP,46,47,114,9 - LTEXT "Version 1.1.6 (Build 158)",IDC_STATIC,46,19,78,8 + LTEXT "Version 1.1.6 (Build 159)",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 @@ -224,8 +224,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,1,6,158 - PRODUCTVERSION 1,1,6,158 + FILEVERSION 1,1,6,159 + PRODUCTVERSION 1,1,6,159 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -242,13 +242,13 @@ BEGIN BEGIN VALUE "CompanyName", "akeo.ie" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "1.1.6.158" + VALUE "FileVersion", "1.1.6.159" 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.158" + VALUE "ProductVersion", "1.1.6.159" END END BLOCK "VarFileInfo"