AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Direktes lesen auf dem physischen Datenträger
Thema durchsuchen
Ansicht
Themen-Optionen

Direktes lesen auf dem physischen Datenträger

Ein Thema von Delphi-Delphin · begonnen am 10. Jun 2018 · letzter Beitrag vom 20. Jun 2018
Antwort Antwort
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.690 Beiträge
 
Delphi 11 Alexandria
 
#1

AW: Direktes lesen auf dem physischen Datenträger

  Alt 12. Jun 2018, 10:41
dass er auf den MBR zugreifen möchte
Delphi-Quellcode:
type
  TMBR = Array of Byte;

Function GetMBR (const DiskNumber: Byte; const MBRSize: Cardinal; out MBR: TMBR): Boolean;
var
  nBytesRead ,
  fHandle : Cardinal;
begin
  fHandle := CreateFile(
    PChar('\\.\PHYSICALDRIVE'+IntToStr(DiskNumber)),
    GENERIC_READ, FILE_SHARE_WRITE,
    nil,
    OPEN_EXISTING,
    0, 0);
  if fHandle = INVALID_HANDLE_VALUE then
  begin
    Result := False;
    ShowMessage('CreateFile - Fehler: Invalid Handle' +#13#10#13#10+
                'Hinweis: liegen Admin-Rechte vor?');
    exit;
  end;
  SetLength(MBR, MBRSize);
  Result := ReadFile(fHandle, MBR[0], MBRSize, nBytesRead, nil);
  if nBytesRead-1 <> High(MBR) then Result := False;
  if not Result then
  begin
    ShowMessage('ReadFile - Fehler' +#13#10#13#10+
                'Es sollten '+IntToStr(High(MBR))+ ' bytes gelesen werden' +#13#10+
                'aber nur '+ IntToStr(nBytesRead-1) +' bytes waren lesbar!');
  end;
  CloseHandle(fHandle);
end;
So könnte ein möglicher Aufruf aussehen:
Delphi-Quellcode:
procedure x;
var
  MyMBR: TMBR;
begin
  if GetMBR(0, 512, MyMBR) then // <<-- 512 als MBR Größe ist nicht immer korrekt, also vorher diesen Wert ermitteln, das dient nur als Beispiel
  begin
   // mach was mit MyMBR
  end;
end;
So könnte ein möglicher Ansatz für MBR sein.
Gruß vom KodeZwerg

Geändert von KodeZwerg (12. Jun 2018 um 11:11 Uhr) Grund: Code optimiert
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.690 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: Direktes lesen auf dem physischen Datenträger

  Alt 12. Jun 2018, 17:15
Ich bin gerade den Code nochmal durchgegangen, es kann sehr gut möglich sein das ich  if nBytesRead-1 <> High(MBR) then Result := False; das falsch habe und es  if nBytesRead <> High(MBR)+1 then Result := False; lauten müsste, beim weiteren nBytesRead das -1 dann weglassen aber beim High(MBR) ein +1 ranbaumeln.
Gruß vom KodeZwerg

Geändert von KodeZwerg (12. Jun 2018 um 19:04 Uhr)
  Mit Zitat antworten Zitat
Delphi-Delphin

Registriert seit: 23. Feb 2010
10 Beiträge
 
FreePascal / Lazarus
 
#3

AW: Direktes lesen auf dem physischen Datenträger

  Alt 18. Jun 2018, 12:26
Vielen Dank, für deine großartige Hilfe.

Deine Exe liefert sogar noch viel mehr Informationen, als ich brauche.

Mit dem Code lässt sich also sehr gut was anfangen. Der verlinkte Code ließ sich auch fehlerfrei im Lazarus kompilieren.

Edit: Hab auch noch einen Fehler im Code gefunden.
Bei Writeln(Format('Size %d',[VarToInt(FWbemObject.Size)]));// Uint64 kommt es zu einem Überlauf, da die Funktion selbst nur einen 32 Bit Integer verwendet.

Angepasst:
Delphi-Quellcode:
//-----------------------------------------------------------------------------------------------------
// This code was generated by the Wmi Delphi Code Creator http://theroadtodelphi.wordpress.com
// Version: 1.8.3.0
// LIABILITY DISCLAIMER
// THIS GENERATED CODE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.
// YOU USE IT AT YOUR OWN RISK. THE AUTHOR NOT WILL BE LIABLE FOR DATA LOSS,
// DAMAGES AND LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS CODE.
//----------------------------------------------------------------------------------------------------
program GetWMI_DiskDriveInfo;

{$APPTYPE CONSOLE}

uses
 // SysUtils, ActiveX, ComObj, Variants;
  SysUtils,
  ActiveX,
  ComObj,
  Variants;

function VarToInt(const AVariant: Variant): integer;
begin Result := StrToIntDef(Trim(VarToStr(AVariant)), 0); end;

function VarToQWord(const AVariant: Variant): QWord;
begin Result := StrToQWordDef(Trim(VarToStr(AVariant)), 0); end;

// Die Klasse "Win32_DiskDrive" stellt ein physikalisches Laufwerk eines Computer dar,
// auf dem das Win32-Betriebssystem ausgeführt wird. Jede Schnittstelle zu einem physikalischen
// Win32-Laufwerk ist ein Mitglied dieser Klasse. Die Funktionen des Laufwerks in diesem
// Objekt entsprechen den logischen Laufwerkmerkmalen. Ein Objekt, das auf einem anderen logischen Gerät basiert,
// ist kein Mitglied dieser Klasse.
// Beispiel: IDE-Festplatte.

procedure GetWin32_DiskDriveInfo;
const
  WbemUser ='';
  WbemPassword ='';
  WbemComputer ='localhost';
  wbemFlagForwardOnly = $00000020;
var
  FSWbemLocator : OLEVariant;
  FWMIService : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject : OLEVariant;
  oEnum : IEnumvariant;
  iValue : LongWord;
  i: integer;
begin
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
  FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_DiskDrive','WQL',wbemFlagForwardOnly);
  oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  i:=0;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    Writeln(Format('*** DISK %d ***',[i]));
    Writeln(Format('Availability %d',[VarToInt(FWbemObject.Availability)]));// Uint16
    Writeln(Format('BytesPerSector %d',[VarToInt(FWbemObject.BytesPerSector)]));// Uint32
// Writeln(Format('Capabilities %d',[VarToInt(FWbemObject.Capabilities)]));// Array of Uint16
// Writeln(Format('CapabilityDescriptions %s',[VarToStr(FWbemObject.CapabilityDescriptions)]));// Array of VarToStr
    Writeln(Format('Caption %s',[VarToStr(FWbemObject.Caption)]));// VarToStr
    Writeln(Format('CompressionMethod %s',[VarToStr(FWbemObject.CompressionMethod)]));// String
    Writeln(Format('ConfigManagerErrorCode %d',[VarToInt(FWbemObject.ConfigManagerErrorCode)]));// Uint32
    Writeln(Format('ConfigManagerUserConfig %s',[VarToStr(FWbemObject.ConfigManagerUserConfig)]));// Boolean
    Writeln(Format('CreationClassName %s',[VarToStr(FWbemObject.CreationClassName)]));// String
    Writeln(Format('DefaultBlockSize %d',[VarToInt(FWbemObject.DefaultBlockSize)]));// Uint64
    Writeln(Format('Description %s',[VarToStr(FWbemObject.Description)]));// String
    Writeln(Format('DeviceID %s',[VarToStr(FWbemObject.DeviceID)]));// String
    Writeln(Format('ErrorCleared %s',[VarToStr(FWbemObject.ErrorCleared)]));// Boolean
    Writeln(Format('ErrorDescription %s',[VarToStr(FWbemObject.ErrorDescription)]));// String
    Writeln(Format('ErrorMethodology %s',[VarToStr(FWbemObject.ErrorMethodology)]));// String
    Writeln(Format('FirmwareRevision %s',[VarToStr(FWbemObject.FirmwareRevision)]));// String
    Writeln(Format('Index %d',[VarToInt(FWbemObject.Index)]));// Uint32
    Writeln(Format('InstallDate %s',[VarToStr(FWbemObject.InstallDate)]));// Datetime
    Writeln(Format('InterfaceType %s',[VarToStr(FWbemObject.InterfaceType)]));// String
    Writeln(Format('LastErrorCode %d',[VarToInt(FWbemObject.LastErrorCode)]));// Uint32
    Writeln(Format('Manufacturer %s',[VarToStr(FWbemObject.Manufacturer)]));// String
    Writeln(Format('MaxBlockSize %d',[VarToInt(FWbemObject.MaxBlockSize)]));// Uint64
    Writeln(Format('MaxMediaSize %d',[VarToInt(FWbemObject.MaxMediaSize)]));// Uint64
    Writeln(Format('MediaLoaded %s',[VarToStr(FWbemObject.MediaLoaded)]));// Boolean
    Writeln(Format('MediaType %s',[VarToStr(FWbemObject.MediaType)]));// String
    Writeln(Format('MinBlockSize %d',[VarToInt(FWbemObject.MinBlockSize)]));// Uint64
    Writeln(Format('Model %s',[VarToStr(FWbemObject.Model)]));// String
    Writeln(Format('Name %s',[VarToStr(FWbemObject.Name)]));// String
    Writeln(Format('NeedsCleaning %s',[VarToStr(FWbemObject.NeedsCleaning)]));// Boolean
    Writeln(Format('NumberOfMediaSupported %d',[VarToInt(FWbemObject.NumberOfMediaSupported)]));// Uint32
    Writeln(Format('Partitions %d',[VarToInt(FWbemObject.Partitions)]));// Uint32
    Writeln(Format('PNPDeviceID %s',[VarToStr(FWbemObject.PNPDeviceID)]));// String
    Writeln(Format('PowerManagementCapabilities %d',[VarToInt(FWbemObject.PowerManagementCapabilities)]));// Array of Uint16
    Writeln(Format('PowerManagementSupported %s',[VarToStr(FWbemObject.PowerManagementSupported)]));// Boolean
    Writeln(Format('SCSIBus %d',[VarToInt(FWbemObject.SCSIBus)]));// Uint32
    Writeln(Format('SCSILogicalUnit %d',[VarToInt(FWbemObject.SCSILogicalUnit)]));// Uint16
    Writeln(Format('SCSIPort %d',[VarToInt(FWbemObject.SCSIPort)]));// Uint16
    Writeln(Format('SCSITargetId %d',[VarToInt(FWbemObject.SCSITargetId)]));// Uint16
    Writeln(Format('SectorsPerTrack %d',[VarToInt(FWbemObject.SectorsPerTrack)]));// Uint32
    Writeln(Format('SerialNumber %s',[TRIM(VarToStr(FWbemObject.SerialNumber))]));// String
    Writeln(Format('Signature %d',[VarToInt(FWbemObject.Signature)]));// Uint32
    Writeln(Format('Size %d Byte = %f GB',[VarToQWord(FWbemObject.Size),VarToQWord(FWbemObject.Size)/(1000000000)]));// Uint64
    Writeln(Format('Status %s',[VarToStr(FWbemObject.Status)]));// String
    Writeln(Format('StatusInfo %d',[VarToInt(FWbemObject.StatusInfo)]));// Uint16
    Writeln(Format('SystemCreationClassName %s',[VarToStr(FWbemObject.SystemCreationClassName)]));// String
    Writeln(Format('SystemName %s',[VarToStr(FWbemObject.SystemName)]));// String
    Writeln(Format('TotalCylinders %d',[VarToInt(FWbemObject.TotalCylinders)]));// Uint64
    Writeln(Format('TotalHeads %d',[VarToInt(FWbemObject.TotalHeads)]));// Uint32
    Writeln(Format('TotalSectors %d',[VarToInt(FWbemObject.TotalSectors)]));// Uint64
    Writeln(Format('TotalTracks %d',[VarToInt(FWbemObject.TotalTracks)]));// Uint64
    Writeln(Format('TracksPerCylinder %d',[VarToInt(FWbemObject.TracksPerCylinder)]));// Uint32

    Writeln('----------------------------------------------------------------------------');
    FWbemObject:=Unassigned;

    inc(i);
  end;
end;


begin
 try
    CoInitialize(nil);
    try
      GetWin32_DiskDriveInfo;
    finally
      CoUninitialize;
    end;
 except
    on E:EOleException do
        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;
end.
Künstliche Intelligenz ist gar nichts - verglichen mit natürlicher Dummheit

Geändert von Delphi-Delphin (18. Jun 2018 um 13:09 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.690 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: Direktes lesen auf dem physischen Datenträger

  Alt 18. Jun 2018, 13:22
Bei Writeln(Format('Size %d',[VarToInt(FWbemObject.Size)]));// Uint64 kommt es zu einem Überlauf, da die Funktion selbst nur einen 32 Bit Integer verwendet.
Es freut mich wenn es das macht was Du wolltest, Danke für Fehler-Report!
Delphi-Quellcode:
function VarToInt64(const AVariant: Variant): Int64;
begin Result := StrToInt64Def(Trim(VarToStr(AVariant)), 0); end;
    Writeln(Format('Size %d Byte = %f GB',[VarToInt64(FWbemObject.Size),VarToInt64(FWbemObject.Size)/(1000*1000*1000)]));// Uint64 Habe es mit Delphi so abgeändert, vielen Dank!

edit
Delphi-Quellcode:
program GetWMI_DiskDriveInfo;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ActiveX,
  ComObj,
  Variants;

function VarToInt(const AVariant: Variant): integer;
begin Result := StrToIntDef(Trim(VarToStr(AVariant)), 0); end;

function VarToInt64(const AVariant: Variant): Int64;
begin Result := StrToInt64Def(Trim(VarToStr(AVariant)), 0); end;

procedure GetWin32_DiskDriveInfo;
const
  WbemUser ='';
  WbemPassword ='';
  WbemComputer ='localhost';
  wbemFlagForwardOnly = $00000020;
var
  FSWbemLocator : OLEVariant;
  FWMIService : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject : OLEVariant;
  oEnum : IEnumvariant;
  iValue : LongWord;
begin;
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
  FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_DiskDrive','WQL',wbemFlagForwardOnly);
  oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    Writeln(Format('Availability %d',[VarToInt(FWbemObject.Availability)]));// Uint16
    Writeln(Format('BytesPerSector %d',[VarToInt(FWbemObject.BytesPerSector)]));// Uint32
// Writeln(Format('Capabilities %d',[VarToInt(FWbemObject.Capabilities)]));// Array of Uint16
// Writeln(Format('CapabilityDescriptions %s',[VarToStr(FWbemObject.CapabilityDescriptions)]));// Array of VarToStr
    Writeln(Format('Caption %s',[VarToStr(FWbemObject.Caption)]));// VarToStr
    Writeln(Format('CompressionMethod %s',[VarToStr(FWbemObject.CompressionMethod)]));// String
    Writeln(Format('ConfigManagerErrorCode %d',[VarToInt(FWbemObject.ConfigManagerErrorCode)]));// Uint32
    Writeln(Format('ConfigManagerUserConfig %s',[VarToStr(FWbemObject.ConfigManagerUserConfig)]));// Boolean
    Writeln(Format('CreationClassName %s',[VarToStr(FWbemObject.CreationClassName)]));// String
    Writeln(Format('DefaultBlockSize %d',[VarToInt64(FWbemObject.DefaultBlockSize)]));// Uint64
    Writeln(Format('Description %s',[VarToStr(FWbemObject.Description)]));// String
    Writeln(Format('DeviceID %s',[VarToStr(FWbemObject.DeviceID)]));// String
    Writeln(Format('ErrorCleared %s',[VarToStr(FWbemObject.ErrorCleared)]));// Boolean
    Writeln(Format('ErrorDescription %s',[VarToStr(FWbemObject.ErrorDescription)]));// String
    Writeln(Format('ErrorMethodology %s',[VarToStr(FWbemObject.ErrorMethodology)]));// String
    Writeln(Format('FirmwareRevision %s',[VarToStr(FWbemObject.FirmwareRevision)]));// String
    Writeln(Format('Index %d',[VarToInt(FWbemObject.Index)]));// Uint32
    Writeln(Format('InstallDate %s',[VarToStr(FWbemObject.InstallDate)]));// Datetime
    Writeln(Format('InterfaceType %s',[VarToStr(FWbemObject.InterfaceType)]));// String
    Writeln(Format('LastErrorCode %d',[VarToInt(FWbemObject.LastErrorCode)]));// Uint32
    Writeln(Format('Manufacturer %s',[VarToStr(FWbemObject.Manufacturer)]));// String
    Writeln(Format('MaxBlockSize %d',[VarToInt64(FWbemObject.MaxBlockSize)]));// Uint64
    Writeln(Format('MaxMediaSize %d',[VarToInt64(FWbemObject.MaxMediaSize)]));// Uint64
    Writeln(Format('MediaLoaded %s',[VarToStr(FWbemObject.MediaLoaded)]));// Boolean
    Writeln(Format('MediaType %s',[VarToStr(FWbemObject.MediaType)]));// String
    Writeln(Format('MinBlockSize %d',[VarToInt64(FWbemObject.MinBlockSize)]));// Uint64
    Writeln(Format('Model %s',[VarToStr(FWbemObject.Model)]));// String
    Writeln(Format('Name %s',[VarToStr(FWbemObject.Name)]));// String
    Writeln(Format('NeedsCleaning %s',[VarToStr(FWbemObject.NeedsCleaning)]));// Boolean
    Writeln(Format('NumberOfMediaSupported %d',[VarToInt(FWbemObject.NumberOfMediaSupported)]));// Uint32
    Writeln(Format('Partitions %d',[VarToInt(FWbemObject.Partitions)]));// Uint32
    Writeln(Format('PNPDeviceID %s',[VarToStr(FWbemObject.PNPDeviceID)]));// String
    Writeln(Format('PowerManagementCapabilities %d',[VarToInt(FWbemObject.PowerManagementCapabilities)]));// Array of Uint16
    Writeln(Format('PowerManagementSupported %s',[VarToStr(FWbemObject.PowerManagementSupported)]));// Boolean
    Writeln(Format('SCSIBus %d',[VarToInt(FWbemObject.SCSIBus)]));// Uint32
    Writeln(Format('SCSILogicalUnit %d',[VarToInt(FWbemObject.SCSILogicalUnit)]));// Uint16
    Writeln(Format('SCSIPort %d',[VarToInt(FWbemObject.SCSIPort)]));// Uint16
    Writeln(Format('SCSITargetId %d',[VarToInt(FWbemObject.SCSITargetId)]));// Uint16
    Writeln(Format('SectorsPerTrack %d',[VarToInt(FWbemObject.SectorsPerTrack)]));// Uint32
    Writeln(Format('SerialNumber %s',[TRIM(VarToStr(FWbemObject.SerialNumber))]));// String
    Writeln(Format('Signature %d',[VarToInt(FWbemObject.Signature)]));// Uint32
// Writeln(Format('Size %d',[VarToInt(FWbemObject.Size)]));// Uint64
    Writeln(Format('Size %d Byte = %f GB',[VarToInt64(FWbemObject.Size),VarToInt64(FWbemObject.Size)/(1000*1000*1000)]));// Uint64
    Writeln(Format('Status %s',[VarToStr(FWbemObject.Status)]));// String
    Writeln(Format('StatusInfo %d',[VarToInt(FWbemObject.StatusInfo)]));// Uint16
    Writeln(Format('SystemCreationClassName %s',[VarToStr(FWbemObject.SystemCreationClassName)]));// String
    Writeln(Format('SystemName %s',[VarToStr(FWbemObject.SystemName)]));// String
    Writeln(Format('TotalCylinders %d',[VarToInt64(FWbemObject.TotalCylinders)]));// Uint64
    Writeln(Format('TotalHeads %d',[VarToInt(FWbemObject.TotalHeads)]));// Uint32
    Writeln(Format('TotalSectors %d',[VarToInt64(FWbemObject.TotalSectors)]));// Uint64
    Writeln(Format('TotalTracks %d',[VarToInt64(FWbemObject.TotalTracks)]));// Uint64
    Writeln(Format('TracksPerCylinder %d',[VarToInt(FWbemObject.TracksPerCylinder)]));// Uint32
    Writeln('----------------------------------------------------------------------------');
    FWbemObject:=Unassigned;
  end;
end;


begin
 try
    CoInitialize(nil);
    try
      GetWin32_DiskDriveInfo;
    finally
      CoUninitialize;
    end;
 except
    on E:EOleException do
        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;
end.
Nun haben alle Int64 Typen ihren Ansprechpartner
Gruß vom KodeZwerg

Geändert von KodeZwerg (18. Jun 2018 um 13:58 Uhr)
  Mit Zitat antworten Zitat
Delphi-Delphin

Registriert seit: 23. Feb 2010
10 Beiträge
 
FreePascal / Lazarus
 
#5

AW: Direktes lesen auf dem physischen Datenträger

  Alt 19. Jun 2018, 16:10
Leider fehlt mir gerade noch die Zuordnung von logischen Laufwerksbuchstaben der Partitionen zu den physischen Drives, um dann auf den jeweiligen Bootsektor der Partition zugreifen zu können.
Also z.B. "C:\" -> "\\.\PhysicalDrive1: Partition 1"

Hier mal ein Screenshot von OSForensics:
Drive.jpg
Künstliche Intelligenz ist gar nichts - verglichen mit natürlicher Dummheit

Geändert von Delphi-Delphin (19. Jun 2018 um 16:13 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.690 Beiträge
 
Delphi 11 Alexandria
 
#6

AW: Direktes lesen auf dem physischen Datenträger

  Alt 19. Jun 2018, 16:28
Hier stellte ich Source Code zur Verfügung der vielleicht das macht was Du möchtest, DriveLetter einer Drive# zuordnen.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
Delphi-Delphin

Registriert seit: 23. Feb 2010
10 Beiträge
 
FreePascal / Lazarus
 
#7

AW: Direktes lesen auf dem physischen Datenträger

  Alt 19. Jun 2018, 21:54
Das Programm ist jetzt so weit, das die Infos zur Partition angezeigt werden und nach der Auswahl der erste Sektor ausgelesen wird.
Siehe Screenshot.

MBR_Auslesen.png

Allerdings funktioniert das Offset bei ReadFile nicht richtig, bzw. ich konnte nicht wirklich finden, womit der Record von ^Overlapped befüllt werden muss.

Delphi-Quellcode:
type TSECTOR= Array[0..511] of Byte;

const SectorSize = 512;

var Sector: TSector;
  nBytesRead ,
  fHandle : Cardinal;
theOverlapped: Overlapped;

//funktioniert:
Result := ReadFile(fHandle, Sector[0], SectorSize, nBytesRead, nil);

//funktioniert nicht:
theOverlapped.OffsetHigh:=0;
theOverlapped.Offset:=Offset*SectorSize;

Result := ReadFile(fHandle, Sector[0], SectorSize, nBytesRead, @theOverlapped);
Komplette Funktion:
Delphi-Quellcode:
Function GetSector (const PhysDrive: String; const Offset: DWord; out Sector: TSector): Boolean;
const SectorSize = 512;
var
  nBytesRead ,
  fHandle : Cardinal;
  theOverlapped: Overlapped;
begin
  fHandle := CreateFile(
    PChar(PhysDrive), //PChar('\\.\PHYSICALDRIVE'+IntToStr(DiskNumber)),
    GENERIC_READ, FILE_SHARE_WRITE,
    nil,
    OPEN_EXISTING,
    0,
    0);
  if fHandle = INVALID_HANDLE_VALUE then
  begin
    Result := False;
    ShowMessage('CreateFile - Fehler: Invalid Handle' +#13#10#13#10+
                'Hinweis: liegen Admin-Rechte vor?');
    exit;
  end;

  Result := ReadFile(fHandle, Sector[0], SectorSize, nBytesRead, nil);
  if nBytesRead-1 <> High(Sector) then Result := False;
  if not Result then
  begin
    ShowMessage('ReadFile - Fehler' +#13#10#13#10+
                'Es sollten '+IntToStr(High(Sector))+ ' bytes gelesen werden' +#13#10+
                'aber nur '+ IntToStr(nBytesRead-1) +' bytes waren lesbar!');
  end;
  CloseHandle(fHandle);
end;
https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
Künstliche Intelligenz ist gar nichts - verglichen mit natürlicher Dummheit

Geändert von Delphi-Delphin (19. Jun 2018 um 22:15 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz