A
Ancient_Hacker
Dale Pennington wrote:
Not easily or portably, but here's a few hints:
(0) See if your debugger is smart enough to do this.
(1) First get the source to your C runtime library. Look at the code
for fopen() and particularly the declaration of a FILE structure. If
you don't have the code, step thru it with *horrors* a debugger.
Somewhere pretty early it will call the system API or the C open() to
open a file. Which in almost every OS, returns a small integer. Most
if not all fopens() nowadays put that thing, often called a "file
handle", into fopen's open file table, then fopen returns the address
into that table. Often if you look *horrors* at your link map,
you'll see fopen() exports that table. With a little peeking into the
FILE * structure you should be able to get a hold of the handle for the
file. Then many if not most systems have a "GetFileInfoFromHandle()"
API. Whew.
*Not* widely portable, but has been known to be doable and has saved
many a butt when the going got tough.
Not easily or portably, but here's a few hints:
(0) See if your debugger is smart enough to do this.
(1) First get the source to your C runtime library. Look at the code
for fopen() and particularly the declaration of a FILE structure. If
you don't have the code, step thru it with *horrors* a debugger.
Somewhere pretty early it will call the system API or the C open() to
open a file. Which in almost every OS, returns a small integer. Most
if not all fopens() nowadays put that thing, often called a "file
handle", into fopen's open file table, then fopen returns the address
into that table. Often if you look *horrors* at your link map,
you'll see fopen() exports that table. With a little peeking into the
FILE * structure you should be able to get a hold of the handle for the
file. Then many if not most systems have a "GetFileInfoFromHandle()"
API. Whew.
*Not* widely portable, but has been known to be doable and has saved
many a butt when the going got tough.