Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 26th, 2007, 7:28 PM   #1
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 171
Rep Power: 3 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
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.
PhilBon is offline   Reply With Quote
Old Dec 26th, 2007, 10:34 PM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 928
Rep Power: 4 lectricpharaoh will become famous soon enough
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.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp
lectricpharaoh is online now   Reply With Quote
Old Dec 27th, 2007, 12:30 PM   #3
Alias
Newbie
 
Join Date: Oct 2007
Posts: 29
Rep Power: 0 Alias is on a distinguished road
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;
        }
 ....
Alias is offline   Reply With Quote
Old Dec 27th, 2007, 6:55 PM   #4
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 171
Rep Power: 3 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
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
PhilBon is offline   Reply With Quote
Old Dec 28th, 2007, 12:23 AM   #5
Kuryn
Newbie
 
Join Date: Dec 2007
Posts: 14
Rep Power: 0 Kuryn is on a distinguished road
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/
Kuryn is offline   Reply With Quote
Old Dec 28th, 2007, 9:31 AM   #6
null_ptr0
11 years old
 
Join Date: Nov 2007
Posts: 79
Rep Power: 1 null_ptr0 is on a distinguished road
Re: Read a bit on the hard drive

PhilBon, just read bytes, then convert them to binary strings.
__________________
iload_0 iconst_1 ishl or
iload_0 iconst_2 idiv or
iload_0 iconst_2 iconst_1 imul idiv
[1] & [2] use the smallest stack size
null_ptr0 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:48 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC