Reading Sectors in Binaries from Hard disk.

Can anyone provide me an information as to how can i proceed to read sectors one by one of 512 bytes in binary format from a Hard disk with single partition?

Hello,

If you want to do it in user mode, i think you can do it with
CreateFile / SetFilePointer / ReadFile. Something like this:

hDevice = CreateFile(“\\.\c:”,GENERIC_READ, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);

if (hDevice != INVALID_HANDLE_VALUE)
{
SetFilePointer (hDevice, (isector*512), NULL, FILE_BEGIN);
if (ReadFile (hDevice, buffer, 512*nsectors2read, &bytesread, NULL) )
{

}
}

To do it in kernel mode, here is a example project with a user mode
part and a driver:

http://www.codeproject.com/Articles/28314/Reading-and-Writing-to-Raw-Disk-Sectors

On Mon, Jun 8, 2015 at 2:32 PM, wrote:
> Can anyone provide me an information as to how can i proceed to read sectors one by one of 512 bytes in binary format from a Hard disk with single partition?
>
>
>
>
>
> —
> NTFSD is sponsored by OSR
>
> OSR is hiring!! Info at http://www.osr.com/careers
>
> For our schedule of debugging and file system seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Javier Vicente Vallejo
http://www.vallejo.cc

Thanks for the information Javier.
I checked out but i am getting an output in text format. I need it in Binary.
Do i have to convert it in binary format or store it in *.bin file?
Please correct me if i am wrong.

Hey there.
What do you mean by binary ? What you think binary means ?
You read sequences of bytes of raw data. What you want to do with it ?
On Jun 9, 2015 09:14, wrote:

> Thanks for the information Javier.
> I checked out but i am getting an output in text format. I need it in
> Binary.
> Do i have to convert it in binary format or store it in *.bin file?
> Please correct me if i am wrong.
>
> —
> NTFSD is sponsored by OSR
>
> OSR is hiring!! Info at http://www.osr.com/careers
>
> For our schedule of debugging and file system seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

I want to read it in 0’s and 1’s form. That’s what binary is.
I need it to read it and keep it in a file.
I know its a sequence of bytes.

I really don’t know how to respond to that :slight_smile:

Thanks Gabriel for an input :slight_smile:

I am not sure what the context of the post is
but reading \.\PhysicalDrive0 in older os used to be 3 lines of python

import binascii
disk = r"\.\PhysicalDrive0"
with open(disk, ‘rb’) as f:
f.seek(0)
partdata = f.read(512)
print binascii.hexlify(partdata)

python getphydri.py
33c08ed0bc007cfb5007
cut off
0000055aa

On 6/9/15, xxxxx@gmail.com wrote:
> Thanks Gabriel for an input :slight_smile:
>
> —
> NTFSD is sponsored by OSR
>
> OSR is hiring!! Info at http://www.osr.com/careers
>
> For our schedule of debugging and file system seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Just open \.\c: or \.\PhysicalDrive%d (0, 1 etc).

For C runtime call, you need “rb” or "wb mode.

For CreateFile, you do not need any.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntfsd…
> Can anyone provide me an information as to how can i proceed to read sectors one by one of 512 bytes in binary format from a Hard disk with single partition?
>
>
>
>
>

Thanks guys for all inputs.