ring3級下直接讀寫硬碟
C程式碼
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "user32.lib");
#pragma comment(lib, "kernel32.lib");
const UINT uSectorSize = 512 ;
const UINT uBegSector = 0 ;
const UINT uSectorNum = 1 ;
const UINT uReadSize = uSectorSize * uSectorNum ;
BYTE bBuffer[uReadSize] = {0} ;
const char pDiskPath[] = "//./PHYSICALDRIVE0" ;
void ShowByteInform ( PBYTE pBuf, UINT uSize )
{
for ( UINT i = 1 ; i <= uSize; i++ )
{
printf ( " %02X", pBuf[i-1] ) ;
if ( i % 16 == 0 )
printf ( " " ) ;
else if ( i % 8 == 0 )
printf ( " " ) ;
}
}
int main()
{
HANDLE hDisk ;
__try {
hDisk = CreateFile ( pDiskPath, GENERIC_READ,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ) ;
if ( hDisk == INVALID_HANDLE_VALUE )
{
MessageBox ( 0, "磁碟開啟錯誤!", 0, 0 ) ;
return 0;
}
SetFilePointer ( hDisk, uBegSector * uSectorSize, 0, FILE_BEGIN ) ;
DWORD dwReadByte ;
ReadFile ( hDisk, (LPVOID)bBuffer, uReadSize, &dwReadByte, NULL ) ;
if ( dwReadByte == 0 )
{
MessageBox ( 0, "磁碟讀取錯誤!", 0, 0 ) ;
return 0;
}
ShowByteInform ( bBuffer, uReadSize ) ;
}
__finally {
CloseHandle ( hDisk ) ;
}
return 0;
}
#include <stdio.h>
#pragma comment(lib, "user32.lib");
#pragma comment(lib, "kernel32.lib");
const UINT uSectorSize = 512 ;
const UINT uBegSector = 0 ;
const UINT uSectorNum = 1 ;
const UINT uReadSize = uSectorSize * uSectorNum ;
BYTE bBuffer[uReadSize] = {0} ;
const char pDiskPath[] = "//./PHYSICALDRIVE0" ;
void ShowByteInform ( PBYTE pBuf, UINT uSize )
{
for ( UINT i = 1 ; i <= uSize; i++ )
{
printf ( " %02X", pBuf[i-1] ) ;
if ( i % 16 == 0 )
printf ( " " ) ;
else if ( i % 8 == 0 )
printf ( " " ) ;
}
}
int main()
{
HANDLE hDisk ;
__try {
hDisk = CreateFile ( pDiskPath, GENERIC_READ,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ) ;
if ( hDisk == INVALID_HANDLE_VALUE )
{
MessageBox ( 0, "磁碟開啟錯誤!", 0, 0 ) ;
return 0;
}
SetFilePointer ( hDisk, uBegSector * uSectorSize, 0, FILE_BEGIN ) ;
DWORD dwReadByte ;
ReadFile ( hDisk, (LPVOID)bBuffer, uReadSize, &dwReadByte, NULL ) ;
if ( dwReadByte == 0 )
{
MessageBox ( 0, "磁碟讀取錯誤!", 0, 0 ) ;
return 0;
}
ShowByteInform ( bBuffer, uReadSize ) ;
}
__finally {
CloseHandle ( hDisk ) ;
}
return 0;
}
Delphi程式碼
program Project1;
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
{$R *.RES}
const
BytesPerSector =512;
SectorCount =1;
SectorStart =0;
drive ='/.PHYSICALDRIVE0';
var
str :string;
p :pchar;
i :Cardinal;
hDeviceHandle :Thandle;
begin
hDeviceHandle := CreateFile(drive, GENERIC_READ,
FILE_SHARE_READ OR FILE_SHARE_WRITE, nil, OPEN_EXISTING,0, 0);
if (hDeviceHandle <> INVALID_HANDLE_VALUE) then
begin
p:=allocmem(SectorCount*BytesPerSector);
FileSeek(hDevicehandle,SectorStart*BytesPerSector,0);
if FileRead(hDevicehandle,p[0],SectorCount*BytesPerSector)<>SectorCount*BytesPerSector then
raise exception.create('讀取錯誤');
str:='';
for i:=0 to 512-1 do
begin
if i mod 16=0 then
str:=str+format('0x%.8x ',[i]);
str:=str+format(' %.2x',[integer(p[i])]);
if i mod 16=15 then
str:=str+#13#10;
end;
ShowMessage( str);
freemem(p,SectorCount*BytesPerSector);
closehandle(hDeviceHandle);
end;
end.
{END}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
{$R *.RES}
const
BytesPerSector =512;
SectorCount =1;
SectorStart =0;
drive ='/.PHYSICALDRIVE0';
var
str :string;
p :pchar;
i :Cardinal;
hDeviceHandle :Thandle;
begin
hDeviceHandle := CreateFile(drive, GENERIC_READ,
FILE_SHARE_READ OR FILE_SHARE_WRITE, nil, OPEN_EXISTING,0, 0);
if (hDeviceHandle <> INVALID_HANDLE_VALUE) then
begin
p:=allocmem(SectorCount*BytesPerSector);
FileSeek(hDevicehandle,SectorStart*BytesPerSector,0);
if FileRead(hDevicehandle,p[0],SectorCount*BytesPerSector)<>SectorCount*BytesPerSector then
raise exception.create('讀取錯誤');
str:='';
for i:=0 to 512-1 do
begin
if i mod 16=0 then
str:=str+format('0x%.8x ',[i]);
str:=str+format(' %.2x',[integer(p[i])]);
if i mod 16=15 then
str:=str+#13#10;
end;
ShowMessage( str);
freemem(p,SectorCount*BytesPerSector);
closehandle(hDeviceHandle);
end;
end.
{END}
相關文章
- Mac如何讀寫NTFS硬碟?NTFSTool讓Mac讀寫NTFS硬碟Mac硬碟
- MacBook讀寫行動硬碟Mac硬碟
- Linux下FrameBuffer直接寫屏(轉)Linux
- hdparm 測試硬碟讀寫速度I/O硬碟
- Linux系統硬碟讀寫測試Linux硬碟
- 直接透過DAO讀、寫Access檔案 (轉)
- linux dd 測試硬碟的讀寫效能Linux硬碟
- Windows10系統下檢視硬碟讀寫速度的方法【圖文教程】Windows硬碟
- Mac上如何讀寫行動硬碟?三款NTFS讀寫軟體分享給大家Mac硬碟
- Mac電腦怎麼在ntfs硬碟上讀寫Mac硬碟
- 蘋果mac筆記本讀寫不出行動硬碟蘋果Mac筆記硬碟
- 讀寫硬碟扇區的C語言程式 (轉)硬碟C語言
- window10系統下空閒時偷偷一直讀寫硬碟如何解決硬碟
- 伺服器硬碟讀寫大檔案速度測試伺服器硬碟
- Win95/98/NT 下對記憶體、埠、中斷的直接控制和讀寫 (轉)記憶體
- win10硬碟一直讀寫怎麼辦_win10電腦一直在讀寫硬碟的解決方法Win10硬碟
- 硬碟韌體升級-希捷硬碟硬碟希捷
- win10 1909瘋狂讀硬碟怎麼解決_win10電腦硬碟瘋狂讀寫修復方法Win10硬碟
- NPOI 2.0 – Excel讀寫神器再次升級薦Excel
- Windows 直接訪問 WSL2 路徑並直接進行讀寫操作,許可權不足解決方法Windows
- 文字直接寫資料庫資料庫
- Django 直接使用資料庫連線和遊標讀寫資料庫Django資料庫
- 原始碼分析:升級版的讀寫鎖 StampedLock原始碼
- win10系統下如何使用硬碟重灌win7系統_win10自帶硬碟直接安裝win7的方法Win10硬碟Win7
- C++Builder下實現埠讀寫 (轉)C++UI
- solaris 下增加新硬碟硬碟
- matplotlib 畫圖直接寫入excelExcel
- 物件直接量內方法的寫法物件
- 讀寫
- ubuntu下無法掛載硬碟以及行動硬碟Ubuntu硬碟
- Epoll在LT和ET模式下的讀寫方式模式
- java讀取excel層級結構的遞迴寫法JavaExcel遞迴
- 設定transaction的讀寫屬性與隔離級別
- 新手安裝控制皮膚+掛載硬碟3條命令直接搞定硬碟
- win10空閒狀態時硬碟會自動讀寫的原因和解決教程Win10硬碟
- 機械硬碟讀不出來找到方案硬碟
- 硬碟預讀引數變化分析硬碟
- hacmp環境下新增硬碟ACM硬碟