![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
Read a bit on the hard drive
What language would be the best language to read the hard drive bit by bit and then display it. for example I'd have a layout of the whole hard drive and then i could select a sector and it'd display the bits and each value. With the possibility of being able to write specifically to the bit. I'm used to VB.Net so if there is any chance it could be done in that, that'd be cool, if not I'm guessing C and C++ would be the way to go.
|
|
|
|
|
|
#2 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,031
Rep Power: 5
![]() |
Re: Read a bit on the hard drive
The system usually accesses hard drive data in units of sectors, with sectors often being 512 bytes. There is also a logical unit, typically called a cluster, which is the smallest logical unit the OS deals with (it allocates space on disk as a number of clusters). You won't have bit-level addressability of disk contents; you won't even have this fine access to memory contents (for memory, a byte is the smallest addressable unit).
I'm not sure what your final goal is, but you can read in the contents of a file and display the data. How you display it is entirely up to you; you can display individual bits if that's what you want to do. Writing to an individual bit will entail reading in the cluster (into a buffer), locating the byte and bit within the byte, setting or clearing the bit with a bitwise operation, and then writing the buffer back to disk. However, there is a catch. As far as most application software is concerned, the disk exists in terms of files, and not absolute sectors. Some software, notably disk tools such as defragmenters, imagers, and partitioning tools, will operate at a level below that of the file system in question. I'm not sure how this is done, but in order to accomplish it from application code, you'd doubtless need special permissions from the OS to obtain this level of access. To answer your question, though, assuming you can call whatever API you need from the language in question, any language would be fine. C and C++ both make it easy to call native Win32 API methods, but you can also do it from the .NET family of languages through the use of p/invoke.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2007
Posts: 29
Rep Power: 0
![]() |
Re: Read a bit on the hard drive
Here's an example from my blog using C# and as lectricpharaoh brings up, it uses Win32 API calls to function since the .NET framework classes available do not support such behaviour, seemingly by design. Anyway here it is, almost guaranteed to break your system with even slight changes...
....
public static unsafe byte[] ReadSector(char drive, long startingsector, int numberofsectors)
{
IntPtr handle;
byte[] buffer;
int bytesread = 0;
//create a handle to the device
handle = CreateFile(
"\\\\.\\" + drive + ":", FileAccess.Read, FileShare.ReadWrite, 0, FileMode.Open, 0, 0);
if (handle == IntPtr.Zero)
return null;
//setting the pointer to point to the start of the sector to read
SetFilePointer(handle, (startingsector * 512), 0, 0);
//allocate buffer length in a managed context
buffer = new byte[512 * numberofsectors];
fixed (byte* p = buffer)
{
//attempt to read file contents into buffer
if (!ReadFile(handle, p, 512 * numberofsectors, &bytesread, 0))
{
CloseHandle(handle);
return null;
}
}
CloseHandle(handle);
return buffer;
}
.... |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
Re: Read a bit on the hard drive
I want to be able to have this:
Input: StartReadSector EndReadSector For each sector between StartReadSector and EndReadSector Display bit values of the sector, in a binary form. I want to be able to extract an image of the hard drive into the binary form. so 101010111010101010010101010101, etc. But on the Fly and based on where I start and stop. next |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Dec 2007
Posts: 14
Rep Power: 0
![]() |
Re: Read a bit on the hard drive
I know this isn't what you preferred. But I have one for floppy, maybe you can figure it out for hdd.
http://www.codeguru.com/cpp/cpp/cpp_...le.php/c13809/ |
|
|
|
|
|
#6 |
|
12 years old
Join Date: Nov 2007
Posts: 93
Rep Power: 1
![]() |
Re: Read a bit on the hard drive
PhilBon, just read bytes, then convert them to binary strings.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Installing Wondows XP from hard drive | Indigno | Coder's Corner Lounge | 9 | Jan 1st, 2007 12:09 AM |
| Read hard disk NTFS file system. | hvcong | C++ | 6 | May 12th, 2006 10:39 AM |
| Second Hard Drive Issues... | ViOLATiON | Coder's Corner Lounge | 2 | Dec 31st, 2005 12:45 AM |
| format hard drive | arod199113 | Coder's Corner Lounge | 19 | Dec 13th, 2005 10:29 PM |
| minimizing hard drive activity? | chepfaust | Coder's Corner Lounge | 3 | Mar 25th, 2005 10:49 PM |