阅读:1665回复:8
如何读取优盘的某个扇区?
比如,我想读取优盘的引导扇区
应该怎么做哪? |
|
最新喜欢:![]() |
沙发#
发布于:2005-01-25 11:00
我写个看code笔记:
//////////////////////////////////////////////////// //这段就是核心了 :-) ///////////////////////////////////// // win 2k code HANDLE hDevice; DWORD bytesread; // Creating a handle to drive a: using CreateFile () function .. char _devicename[] = "\\.\A:"; //这个根据你的需要来,如果你的U盘是K盘, 就是"\\.\K:",硬盘是\\\\.\\PhysicalDrive%d _devicename[4] += drive; hDevice = CreateFile( _devicename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hDevice == INVALID_HANDLE_VALUE) return false; // Setting the pointer to point to the start of the sector we want to read .. SetFilePointer (hDevice, (logicalsector*512), NULL, FILE_BEGIN); if (!ReadFile (hDevice, secbuf, 512, &bytesread, NULL) ) return false; |
|
|
板凳#
发布于:2005-01-23 14:28
给分吧
可读98或2k下读任意磁盘逻辑扇区 bool CFormatDisk::ReadSector(int drive, DWORD logicalsector, unsigned char *secbuf ) { #pragma pack (1) struct { DWORD StartingSector ; WORD NumberOfSectors ; DWORD pBuffer; }ControlBlock; #pragma pack () #pragma pack (1) typedef struct _DIOC_REGISTERS { DWORD reg_EBX; DWORD reg_EDX; DWORD reg_ECX; DWORD reg_EAX; DWORD reg_EDI; DWORD reg_ESI; DWORD reg_Flags; } DIOC_REGISTERS ; #pragma pack () DIOC_REGISTERS reg ; HANDLE hDevice ; BOOL fResult ; DWORD cb ; hDevice = CreateFile ( "\\\\.\\vwin32", 0, 0, NULL, 0, FILE_FLAG_DELETE_ON_CLOSE, NULL ); if ( hDevice == INVALID_HANDLE_VALUE ) { // win 2k code HANDLE hDevice; DWORD bytesread; // Creating a handle to drive a: using CreateFile () function .. char _devicename[] = "\\\\.\\A:"; _devicename[4] += drive; hDevice = CreateFile( _devicename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hDevice == INVALID_HANDLE_VALUE) return false; // Setting the pointer to point to the start of the sector we want to read .. SetFilePointer (hDevice, (logicalsector*512), NULL, FILE_BEGIN); if (!ReadFile (hDevice, secbuf, 512, &bytesread, NULL) ) return false; } else { // code for win 95/98 ControlBlock.StartingSector = (DWORD)logicalsector; ControlBlock.NumberOfSectors = 1; ControlBlock.pBuffer = (DWORD)secbuf ; //----------------------------------------------------------- // SI contains read/write mode flags // SI=0h for read and SI=1h for write // CX must be equal to ffffh for // int 21h's 7305h extention // DS:BX -> base addr of the // control block structure // DL must contain the drive number // (01h=A:, 02h=B: etc) //----------------------------------------------------------- reg.reg_ESI = 0x00 ; reg.reg_ECX = -1 ; reg.reg_EBX = (DWORD)(&ControlBlock); reg.reg_EDX = drive+1; reg.reg_EAX = 0x7305 ; // 6 == VWIN32_DIOC_DOS_DRIVEINFO fResult = DeviceIoControl ( hDevice, 6, &(reg), sizeof (reg), &(reg), sizeof (reg), &cb, 0); if (!fResult || (reg.reg_Flags & 0x0001)) return false; } CloseHandle(hDevice); return true; } |
|
地板#
发布于:2005-01-22 20:26
优盘的盘符和硬盘的盘符是不同的。
如果把物理盘看成设备的话, 优盘对应的设备符号是什么? 硬盘对应的设备符号是什么? 能否说的详细一点,优盘的设备符该怎么读取?[/quote] |
|
地下室#
发布于:2005-01-22 18:20
能否说的详细一点,优盘的设备符该怎么读取?[/quote] 设备符跟引导扇区不是一类东西。 把问题说清楚一点,到底想读取什么。谢谢。 |
|
|
5楼#
发布于:2005-01-21 15:25
能否说的详细一点,优盘的设备符该怎么读取?
做法和读取硬盘的扇区没有区别. |
|
6楼#
发布于:2005-01-21 10:57
做法和读取硬盘的扇区没有区别.
CreateFile SetFilePointer ReadFile就可以了 |
|
|
7楼#
发布于:2005-01-17 21:53
也许可以发个CBW,模拟read10命令就能读取u盘所有信息了
通过bulkin口 |
|
|
8楼#
发布于:2005-01-17 14:26
WinHex
|
|
|