|
IMHO (I'm not expert about), you need to hack DLL (or executable) internals, i.e. you need to know PE file format, have a look at http://msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx[^]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
The only way would be a loop that reads through the assembly code looking for the next ret . This would only work with simple functions having only one ret . Once you put the code in a file it would be useless anyway because code with jump instructions in it (most code) is usually address dependent. ie. if you don't load the code back at the same address it won't work anymore. As you can never gaurentee to do this in any future instance of the process it would be of no use to have the unbased machine code in a file, except possibly for comparison to detect a code modifying virus attack or something. There are better ways to do that anyway like security cookie checks which are already built into every function for you by the MS Compiler. See the /GS compiler switch. If you want to know more have a look at some disassemblers which turn compiled code back into something almost readable.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Caveat: This is dubious practice. The memory layout is not guaranteed and should not be relied upon. Pointer arithmatic is not good. It is mostly just an "irresistible" question.
Given the above: an old technique is to use two function pointers
void functionA()
{
}
void functionB()
{
}
void dontdothis()
{
void * p1 = functionA;
void * p2 = functionB;
char * p3 = static_cast<char *>(p1);
char * p4 = static_cast<char *>(p2);
size_t sizeFn = p4 - p3;
}
There is little, if anything, that can be done with this.
|
|
|
|
|
can u kindly explain more what the meaning by ur code ??
you just sub. two addr of two pointer of two function !! how this be the size and size of which one ..
i really misunderstand
thx
|
|
|
|
|
Assuming the two functions are back-to-back in memory, you can simply take the difference of their addresses to obtain the size. In other words, if functionA() is at 0x1234 and functionB() is at 0x2345, then the size of functionA() would be 4,369 bytes.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Nicely said.
This is precisely what is happening.
Once more, don't do this.
|
|
|
|
|
Member 754960 wrote: Once more, don't do this.
I wouldn't. I was just explaining to Adore what was happening.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
ooh sure should not be used !!
nothing can guaranty that the two functions are above each other in the memory !!!
see no way here ..
indeed its a client request for what i don't know !
thx all
|
|
|
|
|
Since that won't do, try this:
Load the program in a debugger and read the starting and ending address of the function and do the math.
Otherwise you need to do a lot more research before you can ask your question.
|
|
|
|
|
I am adapting for Visual C++ 2008 a Borland C++ 4.5 program which includes this function:
int is_dir(char*path){struct stat i; stat(path,&i); return i.st_mode&S_IFDIR;}
which returns non-zero if path is the name of a directory. But Visual C++ does not know the type struct stat. Please how could I do this in Visual C++ (preferably without using classes)?
|
|
|
|
|
|
That help page describes a function PathIsDirectory() ; howeer, the result was
\2d\ppp_vc\ppp_vc\mwproc.cpp(396) : error C3861: 'PathIsDirectory': identifier not found
|
|
|
|
|
Look at the bottom of the doc page. It will list the header and lib file needed to use the function.
Judy
|
|
|
|
|
Did you include header file?
|
|
|
|
|
As stated in the documentation, you have to include shlwapi.h header file and link with shlwapi.lib library.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Why you didn't write it needs to the header file? 
|
|
|
|
|
OMG, I also forgot to tell him he needs a compiler (perhaps a computer too)!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
I saw your answers they are nice;) .
|
|
|
|
|
Thank you very much.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Hello world!
How to detect if a windows named pipe is FULL
I use a overlapped structure and the GetOverlappedResult function (for asynchronous I/O).
When my named pipe is full I want to wait free space to continue writing data (like a FIFO).
But I don't know how to detect if my pipe is full?
Thanks for any help, advices, etc...
Hello World!!!
from Raphaël
|
|
|
|
|
You can't.
One of the ideas of overlapped I/O is so that you don't
have to wait. Overlapped I/O is also FIFO already.
If you want to wait, don't use overlapped I/O.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your reply...
My problem is that I've a first process that writes data (raw image) to a pipe and a second process which connects to this pipe and reads data from the pipe.
I want to use overlapped structure to let the first process write the next data without waiting until the second process read the old data.
It's important for the first process to know when the pipe is full because at this time It can skip images.
If you have any suggestions to do that...
Thanks in advance.
Hello World!!!
from Raphaël
|
|
|
|
|
Throttling data stream rate can be complex. You could establish a
constant rate or use an adjustable/variable rate based on comm
conditions, which are continuously monitored.
You'll maybe want to somehow keep track of how many overlapped operations
are pending. If this value keeps increasing, then you need to slow
the send rate until the amount of pending ops stays constant.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all,
I'm going to learn a new subject on C++. Working with Windows API. Since I work with Java there is no API used, but I feel it is better to work a little with APIs.
Here is my attempt for that.
I want to read the system time zones and display on the console. Basically in two columns, City and the Time offset. From where I should start work. Can you guys give some clues. Following week I'm free because of Christmas, so I can do some work on it.
Thanks
I appreciate your help all the time...
Eranga
|
|
|
|
|
Can you use of GetSystemTime?
|
|
|
|