Do the boot loader experiment, but use it on a USB drive formatted as FAT32.
* Use Winhex to fill all the bytes of the U disk into 0.
* Format the USB stick into FAT32 with the format function in UltraISO, the allocation unit is 4KB
* Use the Write MBR function provided by UltraISO to write the bootable MBR to the USB drive with the parameter usb-hdd.
This problem comes, MBR in 0 sectors, we can write the MBR by reverse ultraiso, rewrite MBR + USB stick formatted well after the partition table (16 * 4 bytes), form its own MBR.
But we can't change the other sectors that are used. Otherwise, the partition information is destroyed, after the USB stick is inserted, Win7 prompts "This USB flash drive is not formatted, is now formatted."
Once in a row, we can click to turn off this hint. It's a long time to do the experiment and I can't stand the hint.
There are 2 ways to solve this problem:
* Study partition table information, make a self-starter USB flash drive like old Peaches. But my goal is only to do the boot loader experiment, now the time and ability are not allowed to do so
* Find unused sectors (all 0 sectors), after our own MBR execution completes, jump directly to our custom first sector (also not used by the Windows partition to determine the use of sectors), by this sector to load we do the experiment of the subsequent sectors to memory. This method is highly operable and can avoid annoying hints.
In the end can be done in the experiment of the U disk INSERT, let Win7 not pop-up hints, I have not experimented.
Now write a test program to find out exactly those sectors are used, the number of sectors used, using Winhex manual view, the number is still relatively small.
Afraid to see the blurred, with the test program to find.
Test program Download point: Src_find_used_sectors.zip
:
Project preview:
[CPP]View Plaincopy
- @file Find_used_sectors.cpp
- @brief Find out if the FAT32 file system uses a sector to do the boot loader experiment
- Prevent u disk after the experiment, insert a USB flash drive, was Win7 prompted "This USB flash drive is not formatted, is now formatted"
- Every time you insert a USB flash drive, you are prompted with information, annoying
- #include "stdafx.h"
- First use Winhex to fill the USB stick 0
- The USB flash drive in ultraios format, parameters: FAT32, 4KB
- Write mbr, parameter: USB-HDD
- Copy the contents of the USB drive to a file with Winhex
- Using this test program to find those sectors is used (there are not 0 bytes)
- When we do a U disk experiment, we can determine in which sector write things, will not let Win7 pop "USB stick Invalid" prompt
- #define Obj_file_to_parse L "D:\\udiskbk\\udisk_format_ok_write_mbr_by_ultra_iso.bin"
- #define SECTOR_SIZE 512
- BOOL Findandshownozerocontentsectorsindex (handle& hfile, longlong llfilesize); ///< Lookup shows sectors with non-0 content
- BOOL judgesectorwasused (byte* pcsectorbegin, int ilensector);
- int _tmain (int argc, _tchar* argv[])
- {
- HANDLE hfile = Invalid_handle_value;
- Longlong llfilesize = 0;
- Do
- {
- if (!ns_base::isfileexist (obj_file_to_parse))
- {
- _tprintf (L"File not exist[%s]\r\n", obj_file_to_parse);
- Break ;
- }
- Llfilesize = Ns_base::getfilesize (obj_file_to_parse);
- if (llfilesize < 0)
- {
- _tprintf (L"File size [0x%i64x] invalid\r\n", llfilesize);
- Break ;
- }
- if (0! = (llfilesize%))
- {
- _tprintf (L"File can ' t mod by sector size (bytes\r\n");
- }
- if (!ns_base::openfilereadbinary (Obj_file_to_parse, hfile))
- Break ;
- if (! Findandshownozerocontentsectorsindex (hfile, llfilesize))
- {
- _tprintf (L"FALSE findandshownozerocontentsectorsindex () \ r \ n");
- }
- Safe_close_handle (hfile);
- } while (0);
- _tprintf (L"END, press any key to quit\r\n");
- #ifdef _DEBUG
- Getwchar ();
- #endif
- Getwchar ();
- return 0;
- }
- BOOL Findandshownozerocontentsectorsindex (handle& hfile, longlong llfilesize)
- {
- BOOL bRc = FALSE;
- BYTE Cbufrd[sector_size];
- DWORD dwrdback = 0;
- long lsectorindexcur = 0;
- long lsectorwasused = 0;
- Longlong llfilesizerd = 0;
- Longlong llposbegin = 0;
- Longlong llposend = 0;
- Do
- {
- if (Invalid_set_file_pointer = = SetFilePointer (hfile, 0, 0, file_begin))
- Break ;
- Do
- {
- :: ZeroMemory (CBUFRD, sizeof (CBUFRD)); ///<!
- if (!::readfile (hfile, &CBUFRD, sizeof (CBUFRD), &dwrdback, NULL))
- Break ;
- if (dwrdback! = sizeof (CBUFRD))
- Break ;
- if (judgesectorwasused (CBUFRD, sizeof (CBUFRD)))
- {
- lsectorwasused++;
- Llposbegin = (longlong) lsectorindexcur * sector_size;
- Llposend = llposbegin + sizeof (CBUFRD)-1;
- _tprintf (L"sector[0x%.8i 64x-0x%.8i 64X] Sector index[%ld] was used\r\n ",
- Llposbegin,
- Llposend,
- Lsectorindexcur);
- }
- Llfilesizerd + = Dwrdback;
- if (llfilesizerd = = llfilesize)
- {
- BRc = TRUE;
- Break ;
- }
- lsectorindexcur++;
- } while (1);
- } while (0);
- if (bRc)
- {
- _tprintf (L"lsectorwasused =%ld\r\n", lsectorwasused);
- }
- return bRc;
- }
- BOOL judgesectorwasused (byte* pcsectorbegin, int ilensector)
- {
- BOOL bRc = FALSE;
- int iIndex = 0;
- Do
- {
- if ((NULL = = Pcsectorbegin)
- || (sector_size! = ilensector))
- {
- Break ;
- }
- For (iIndex = 0; IIndex < sector_size; iindex++)
- {
- if (0! = * (Pcsectorbegin + iIndex))
- {
- BRc = TRUE;
- Break ;
- }
- }
- } while (0);
- return bRc;
- }
http://blog.csdn.net/lostspeed/article/details/48804455
http://download.csdn.net/detail/lostspeed/9146699
Write a test program to see which sectors in the disk image file can be used?