19-10-2018, 08:22 PM
قراءة سريال الهارد من MBR مباشرة دون استعمال GetVolumeInformation API
الكود يشرح نفسه بنفسه
procedure TForm1.FormCreate(Sender: TObject);
var
RawMBR: array[0..511] of Byte;
btsIO: DWORD;
hDevice: THandle;
Serial: string[9];
begin
//PhysicalDrive0 or C:
hDevice := CreateFile('\\.\C:', GENERIC_READ,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hDevice <> INVALID_HANDLE_VALUE then
begin
// each sector has 512 Bytes
// replace 0 with sector that you wish to read
SetFilePointer(hDevice, 512 * 0, nil, FILE_BEGIN);
ReadFile(hDevice, RawMBR[0], 512, btsIO, nil);
CloseHandle(hDevice);
Serial := Format('%x%x%x%x', [RawMBR[75], RawMBR[74], RawMBR[73],
RawMBR[72]]);
ShowMessage(Serial);
ShowMessage(IntToStr(btsIO));
//WriteFile!(0,rawmbr[72],4,btsIO,nil);
end;
end;
يرجى الحدر عند الكتابة في هده المنطقة(ان كنت لا تعرف مادا تفعل)
Function GetHDDSerial: String;
var
RawMBR: array[0..511] of Byte;
btsIO: DWORD;
hDevice: THandle;
Serial: string[9];
begin
Result := '';
//PhysicalDrive0 or C:
hDevice := CreateFile('\\.\C:', GENERIC_READ,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hDevice <> INVALID_HANDLE_VALUE then
begin
// each sector has 512 Bytes
// replace 0 with sector that you wish to read
SetFilePointer(hDevice, 512 * 0, nil, FILE_BEGIN);
ReadFile(hDevice, RawMBR[0], 512, btsIO, nil);
CloseHandle(hDevice);
Serial := Format('%x%x%x%x', [RawMBR[75], RawMBR[74], RawMBR[73],
RawMBR[72]]);
Result := Serial;
//ShowMessage(Serial);
//ShowMessage(IntToStr(btsIO));
//WriteFile!(0,rawmbr[72],4,btsIO,nil);
end;
end;