Einzelnen Beitrag anzeigen

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, 61x aufgerufen)

Geändert von hathor ( 4. Okt 2015 um 17:32 Uhr)
  Mit Zitat antworten Zitat