如何使用Delphi从USB存储设备读取原始块? [英] How to read raw block from an USB storage device with Delphi?

查看:235
本文介绍了如何使用Delphi从USB存储设备读取原始块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个包含专有文件系统的USB存储设备。所以,我需要读取这些设备的512字节块来实现这个文件系统的查看器。



我该怎么做?是否有一些材料使用Delphi?

解决方案

我讨厌组件,所以这里是一些代码

  var 
RawMBR:字节数组[0..511]
btsIO:DWORD;
begin
hDevice:= CreateFile('\\.\PHYSICALDRIVE1',GENERIC_READ,
FILE_SHARE_READ或FILE_SHARE_WRITE,nil,OPEN_EXISTING,0,0);
如果hDevice<> INVALID_HANDLE_VALUE然后
begin
SetFilePointer(hDevice,512 * 0,nil,FILE_BEGIN); //将0替换为要读取的扇区
ReadFile(hDevice,RawMBR [0],512,btsIO,nil);
CloseHandle(hDevice);
结束
结束


I'm dealing with an USB storage device that contains a proprietary file system. So, I need to read these device's 512 bytes blocks to implement a viewer for this filesystem.

How should I go about this? Is there some material on it using Delphi?

解决方案

I hate components so here is some code

 var 
    RawMBR : array [0..511] of byte;
    btsIO  : DWORD;
 begin
  hDevice := CreateFile('\\.\PHYSICALDRIVE1', GENERIC_READ,
      FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
    if hDevice <> INVALID_HANDLE_VALUE then
    begin
      SetFilePointer(hDevice,512 * 0,nil,FILE_BEGIN); // replace 0 with sector that you wish to read
      ReadFile(hDevice, RawMBR[0], 512, btsIO, nil);
      CloseHandle(hDevice);
    end;
  end;

这篇关于如何使用Delphi从USB存储设备读取原始块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆