Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Getting a pointer to hard drive memory location?

Credits go to Arthur Kalliokoski for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
Getting a pointer to hard drive memory location?
verthex
Member #11,340
September 2009
avatar

Just wondering how it would be possible to create a file on the hard drive and use the addresses/offsets within the file to write/read from?

Arthur Kalliokoski
Second in Command
February 2005
avatar

You can't be serious, can you?

They all watch too much MSNBC... they get ideas.

verthex
Member #11,340
September 2009
avatar

C is for old people, I'm still a young guy.

Arthur Kalliokoski
Second in Command
February 2005
avatar

Just which magical presto-chango "Make Game" button type language did you have in mind?

They all watch too much MSNBC... they get ideas.

verthex
Member #11,340
September 2009
avatar

Just which magical presto-chango "Make Game" button type language did you have in mind?

Python. I also wonder, is this possible with assembler somehow?

Arthur Kalliokoski
Second in Command
February 2005
avatar

Google is your friend.

If it's possible in a higher level language, it's possible in assembler, and then some. It may take an unreasonably long time to write, though.

They all watch too much MSNBC... they get ideas.

verthex
Member #11,340
September 2009
avatar

It may take an unreasonably long time to write, though.

Thats why I prefer C over assembler sometimes.

Paul whoknows
Member #5,081
September 2004
avatar

verthex said:

C is for old people, I'm still a young guy.

Grow up kid, C turns children into men in the blink of an eye :P

Jokes aside, C is great when you need to work with files at low level.

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

bamccaig
Member #7,536
July 2006
avatar

Jokes aside, C is great when you need to work with anything[1] at low level.

FTFY.

References

  1. Save for the CPU itself...
Thomas Fjellstrom
Member #476
June 2000
avatar

For a second I thought he was talking about getting an actual pointer. In which case he'd want mmap.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

verthex
Member #11,340
September 2009
avatar

For a second I thought he was talking about getting an actual pointer. In which case he'd want mmap

That does sound interesting except I have Xp. Damm piece of sht. XP and Borland turbo assembler are very similar btw, neither will ever catch up with time.

I found this thread amusing.

Thomas Fjellstrom
Member #476
June 2000
avatar

verthex said:

That does sound interesting except I have Xp.

What makes you think windows doesn't have a similar feature? You did attempt to google it no?

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

relpatseht
Member #5,034
September 2004
avatar

VirtualAlloc/VirtualProtect is the windows equivalent of mmap. They cannot be used to get an actual pointer to the hard drive, as they only manage pages.

To directly access the hard drive on windows, one would use CreateFile, which, I suppose, is a bit like mmap.

van_houtte
Member #11,605
January 2010
avatar

Verthex, it's time you switch to an OS completely developed in assembly

http://mikeos.berlios.de/

-----
For assistance, please register and click on this link to PM a moderator

Sometimes you may have to send 3-4 messages

verthex
Member #11,340
September 2009
avatar

Verthex, it's time you switch to an OS completely developed in assembly

Its not the only one

To directly access the hard drive on windows, one would use CreateFile [msdn.microsoft.com], which, I suppose, is a bit like mmap.

I'll look into it, thanks.

Thomas Fjellstrom
Member #476
June 2000
avatar

VirtualAlloc/VirtualProtect is the windows equivalent of mmap. They cannot be used to get an actual pointer to the hard drive, as they only manage pages.

You get a virtual memory range that has a backing store on disk. It's more or less a pointer to data on the HD. Though the OS is free to also assign real memory as well.

Quote:

To directly access the hard drive on windows, one would use CreateFile [msdn.microsoft.com], which, I suppose, is a bit like mmap.

I thought CreateFile was like fopen or open. not mmap...

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

relpatseht
Member #5,034
September 2004
avatar

With VirtualAlloc, you don't get the ability to specify if the memory is swapped out or not. Writing to memory returned with VirtualAlloc might be writing to the disk, but that doesn't really mean it is anything like a pointer to the disk. (Your changes will be lost, they can only show up in the paging file, etc)

CreateFile can also be used for device access. To do so, you must specify the OPEN_EXISTING and FILE_SHARE_WRITE flags. Then, the device will be:
"\\.\PhysicalDrive#"
Where # is a 0-indexed number.

If you want access to a particular partition, it would be something like:
"\\.\C:"
Note, if you add a backslash to the end ("\\.\C:\"), you'll be opening the filesystem, not the partition.

Either way, the handle returned can be used with DeviceIoControl to directly read and modify data.

ImLeftFooted
Member #3,935
October 2003
avatar

For a second I thought he was talking about getting an actual pointer. In which case he'd want mmap

That's probably too advanced for the OP.

verthex
Member #11,340
September 2009
avatar

I think Arthur nailed this topic right of the bat though, his explanation is definitely superior to everyones elses.

That's probably too advanced for the OP.

How so, what other pointer can there be besides the one Arthur mentioned?

relpatseht
Member #5,034
September 2004
avatar

The ones Thomas Fjellstrom and I have mentioned are pointers to directly modify the hard drive with no filesystem interference. The pointers Arthur mentioned are for modifying files within the hard drive's filesystem.

verthex
Member #11,340
September 2009
avatar

The pointers Arthur mentioned are for modifying files within the hard drive's filesystem.

Are those the ones with virtual memory addresses?

Basically I want to be able to use memory on the disk that is a file called some name X for example and I want to be able to write to locations of that file, using pointers. Which approach is the better one, Arthurs or Thomas?

relpatseht
Member #5,034
September 2004
avatar

Arthur's, without a doubt. What Thomas and I were talking about would be more useful for creating filesystems, inspecting disks, and things of that nature.

verthex
Member #11,340
September 2009
avatar

Arthur's, without a doubt.

You derailed the thread and made me think otherwise, hisses at you and Dustin!

Slartibartfast
Member #8,789
June 2007
avatar

It rather sounds to me like MapViewOfFile is the functionality you are seeking as it allows you to map a file into memory and so you get pointers to the data (as it is in memory :P) and can manipulate them as regular memory (:)).
Of course, if you just meant "how do I open and manipulate a file" (which is what I see that Arthur answered) then you are asking that in a rather weird fashion.

verthex
Member #11,340
September 2009
avatar

It rather sounds to me like MapViewOfFile [msdn.microsoft.com] is the functionality you are seeking as it allows you to map a file into memory and so you get pointers to the data (as it is in memory ) and can manipulate them as regular memory (:)).
Of course, if you just meant "how do I open and manipulate a file" (which is what I see that Arthur answered) then you are asking that in a rather weird fashion.

The farther I stay from windows.h the better, at least I'm assuming thats where the function is.

 1   2 


Go to: