1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[xp] Add rdisk() masquerading

* Also add MBR support from resource file
* Also fix an issue with WDK
This commit is contained in:
Pete Batard 2012-03-25 22:09:24 +01:00
parent d87f069963
commit 04a20922d5
3 changed files with 48 additions and 11 deletions

View file

@ -399,6 +399,33 @@ static BOOL ClearMBR(HANDLE hPhysicalDrive)
return clear_mbr(&fake_fd); 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 * Process the Master Boot Record
*/ */
@ -448,7 +475,8 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
break; break;
} }
if (IsChecked(IDC_DOS)) { 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)) { if (!write_sectors(hPhysicalDrive, SecSize, 0, nSecs, buf)) {
@ -466,7 +494,7 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
} else { } else {
if (IsChecked(IDC_RUFUS_MBR)) { if (IsChecked(IDC_RUFUS_MBR)) {
uprintf("Using Rufus bootable USB selection MBR\n"); uprintf("Using Rufus bootable USB selection MBR\n");
r = write_rufus_mbr(&fake_fd); r = WriteRufusMBR(&fake_fd);
} else { } else {
uprintf("Using Windows 7 MBR\n"); uprintf("Using Windows 7 MBR\n");
r = write_win7_mbr(&fake_fd); 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_org[] = { "\\minint\\txtsetup.sif", "\\minint\\system32\\" };
const char* patch_str_rep[] = { "\\$\\i386\\txtsetup.sif", "\\$\\i386\\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 *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 char* winnt_sif = "[Data]\n msdosinitiated = \"1\"\n";
const wchar_t* win_nt_ls = L"$win_nt$.~ls"; const wchar_t* win_nt_ls = L"$win_nt$.~ls";
STARTUPINFOA si; STARTUPINFOA si;
@ -570,7 +599,7 @@ static BOOL SetupWinPE(char drive_letter)
buf = get_token_data(src, "OsLoadOptions"); buf = get_token_data(src, "OsLoadOptions");
if (buf != NULL) { if (buf != NULL) {
for (i=0; i<strlen(buf); i++) for (i=0; i<strlen(buf); i++)
buf[i] = tolower(buf[i]); buf[i] = (char)tolower(buf[i]);
uprintf("OsLoadOptions = %s\n", buf); uprintf("OsLoadOptions = %s\n", buf);
minint = (strstr(buf, "/minint") != NULL); minint = (strstr(buf, "/minint") != NULL);
} }
@ -635,12 +664,19 @@ static BOOL SetupWinPE(char drive_letter)
}else { }else {
// Finish patching \bootmgr // Finish patching \bootmgr
for (i=0; i<size-32; i++) { for (i=0; i<size-32; i++) {
// $WIN_NT$_~BT -> $\i386
if (safe_strnicmp(&buf[i], win_nt_bt_org, strlen(win_nt_bt_org)-1) == 0) { 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)]); 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); 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)] = buf[i+strlen(win_nt_bt_org)];
buf[i+strlen(win_nt_bt_rep)+1] = 0; 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)) { 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..."); PrintStatus(0, TRUE, "Writing master boot record...");
if (!WriteMBR(hPhysicalDrive)) { if (!WriteMBR(hPhysicalDrive)) {
// Errorcode has already been set if (!FormatStatus)
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;
goto out; goto out;
} }
UpdateProgress(OP_FIX_MBR, -1.0f); UpdateProgress(OP_FIX_MBR, -1.0f);

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 289 IDD_DIALOG DIALOGEX 12, 12, 206, 289
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW EXSTYLE WS_EX_APPWINDOW
CAPTION "Rufus v1.1.6.158" CAPTION "Rufus v1.1.6.159"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,248,50,14 DEFPUSHBUTTON "Start",IDC_START,94,248,50,14
@ -74,7 +74,7 @@ BEGIN
DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP
CONTROL "<a href=""http://rufus.akeo.ie"">http://rufus.akeo.ie</a>",IDC_ABOUT_RUFUS_URL, CONTROL "<a href=""http://rufus.akeo.ie"">http://rufus.akeo.ie</a>",IDC_ABOUT_RUFUS_URL,
"SysLink",WS_TABSTOP,46,47,114,9 "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 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 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 LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8
@ -224,8 +224,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,1,6,158 FILEVERSION 1,1,6,159
PRODUCTVERSION 1,1,6,158 PRODUCTVERSION 1,1,6,159
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -242,13 +242,13 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "akeo.ie" VALUE "CompanyName", "akeo.ie"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.1.6.158" VALUE "FileVersion", "1.1.6.159"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe" VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.1.6.158" VALUE "ProductVersion", "1.1.6.159"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"