AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Read Absolute Disk Sector

Ein Thema von tcoman · begonnen am 30. Sep 2015 · letzter Beitrag vom 4. Okt 2015
Antwort Antwort
tcoman
(Gast)

n/a Beiträge
 
#1

Read Absolute Disk Sector

  Alt 30. Sep 2015, 18:41
hello dear DP people,
is there anybody how can me tell,
what i must do to read the data from
a disk sector ?
Wbw,
terence
  Mit Zitat antworten Zitat
Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#2

AW: Read Absolute Disk Sector

  Alt 30. Sep 2015, 20:05
You can use MSDN-Library durchsuchenCreateFile with "\\.\PhysicalDrive0" as filename argument (requires administrator privileges). This would open the first physical drive on your computer.
Projekte:
- GitHub (Profil, zyantific)
- zYan Disassembler Engine ( Zydis Online, Zydis GitHub)
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#3

AW: Read Absolute Disk Sector

  Alt 1. Okt 2015, 00:45
http://stackoverflow.com/questions/7...ce-with-delphi
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#4

AW: Read Absolute Disk Sector

  Alt 1. Okt 2015, 01:01
http://michael-puff.de/Programmierung/Delphi/Programme/-> DiskImageNT
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
tcoman
(Gast)

n/a Beiträge
 
#5

AW: Read Absolute Disk Sector

  Alt 3. Okt 2015, 14:15
Hello and thanks for your answers.
In the meanwhile i have check out
some freeware stuff from other people.

It works fine on floppy drives and
usb drives. Under win vista i've to
run the executable with admin rights
to read drive c: without errors.
But that's okay.

Here are my results.
Wbw,
terence.
Miniaturansicht angehängter Grafiken
prawdisk-test_2015_10_03.jpg  
Angehängte Dateien
Dateityp: zip PRawDisk-Test_2015_10_03.zip (276,9 KB, 52x aufgerufen)
  Mit Zitat antworten Zitat
tcoman
(Gast)

n/a Beiträge
 
#6

AW: Read Absolute Disk Sector

  Alt 3. Okt 2015, 18:00
You can use MSDN-Library durchsuchenCreateFile with "\\.\PhysicalDrive0" as filename argument (requires administrator privileges). This would open the first physical drive on your computer.
Thank you dear Zacherl,
have some tries at this afternoon,
using your idea of "createfile()".

Works fine with "\\.\A:" for floppy
and "\\.\F:" for mounted usb drive under
win vista.
Failed on hdd drives like "\\.\C:" using
administrator privileges, of coz.

But i'm still on the way to solve this.
Here my attempts with a simple test program.

Wbw,
have a nice weekend,
terence.
Miniaturansicht angehängter Grafiken
prawdisk2_test_floppy_2015_10_03.jpg   prawdisk2_test_hdd_drive_2015_10_03.jpg   prawdisk2_test_usb_drive_2015_10_03.jpg  
Angehängte Dateien
Dateityp: zip PRawDisk2-Test_2015_10_03.zip (244,9 KB, 39x aufgerufen)
  Mit Zitat antworten Zitat
Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#7

AW: Read Absolute Disk Sector

  Alt 4. Okt 2015, 17:04
If hDevice is valid, the static sector size might be your problem. You should call RaiseLastOSError() after a failed API call to display a specific error message.

Zitat von MSDN:
You can open a physical or logical drive using the CreateFile() application programming interface (API) with these device names provided that you have the appropriate access rights to the drive (that is, you must be an administrator). You must use both the CreateFile() FILE_SHARE_READ and FILE_SHARE_WRITE flags to gain access to the drive.

Once the logical or physical drive has been opened, you can then perform direct I/O to the data on the entire drive. When performing direct disk I/O, you must seek, read, and write in multiples of sector sizes of the device and on sector boundaries. Call DeviceIoControl() using IOCTL_DISK_GET_DRIVE_GEOMETRY to get the bytes per sector, number of sectors, sectors per track, and so forth, so that you can compute the size of the buffer that you will need.
Projekte:
- GitHub (Profil, zyantific)
- zYan Disassembler Engine ( Zydis Online, Zydis GitHub)
  Mit Zitat antworten Zitat
hathor
(Gast)

n/a Beiträge
 
#8

AW: Read Absolute Disk Sector

  Alt 4. Okt 2015, 17:23
EXE appended.

Delphi-Quellcode:
procedure TForm1.bReadBootSectorClick(Sender: TObject);
begin
prvSector:=0;
EBSectorNumber.Text:=IntToStr(prvSector);
_read_sector2(prvSector); // <------------------
end;

function ReadNTSectors(Drive: Byte; FirstSector: DWord; SectorCount: Word; Buffer: Pointer): Boolean;
var
  hDrive: THandle;
  DriveRoot: string;
  BytesRead: Cardinal;
  ReadCount: Cardinal;
begin
  Result := False;
  ReadCount := 512 * SectorCount;
  DriveRoot := '\\.\' + Chr(64 + Drive) + ':';
  hDrive := CreateFile(PChar(DriveRoot), GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE,
    nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  if (hDrive <> INVALID_HANDLE_VALUE) then
  begin
    FileSeek(hDrive, Int64(FirstSector * 512), 0);
    BytesRead := FileRead(hDrive, Buffer^, ReadCount);
    Result := (BytesRead = (512 * SectorCount));
    FileClose(hDrive);
  end;
end;

procedure TForm1._read_sector2(mySector: cardinal);
var dr : byte;
        Buf : array[0..511] of byte;
        i : integer;
        s : string[32];
        ok : boolean;
begin
    LBSectorData.Clear;
    FillChar(Buf, SizeOf(Buf), 0);
    dr:=Ord(UpCase(DCBDrive.Drive)) - Ord('A') + 1;
    ok:= ReadNTSectors(dr, mySector, 1, @Buf);
    if ok then begin
       s:='';
       for i:=0 to 511 do begin
           if ((buf[i] > 31) and (buf[i] < 128)) then s:=s+Chr(buf[i]) else s:=s+'.';
           case i of
               31,63,95,127,159,191,223,255,287,319,351,383,415,447,479,511:
               begin LBSectorData.Items.Add(s); s:=''; end;
           end; {case}
       end;
    end else begin
       LBSectorData.Items.Add('Error Read Sector '+IntToStr(mySector));
    end;
end;
Miniaturansicht angehängter Grafiken
rawdisk.jpg  
Angehängte Dateien
Dateityp: zip PRawDisk2.zip (576,8 KB, 57x aufgerufen)

Geändert von hathor ( 4. Okt 2015 um 17:32 Uhr)
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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 15:09 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