![]() |
| [[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]] |
|
|
#1 |
|
DevMaster Staff
Join Date: Sep 2003
Location: Hell
Posts: 1,109
|
A while back I started a type of c++ quiz thread - here. One of the forum members - Nick, asked a question of how to get a pointer to an objects constructor. A solution to the *problem* was presented, but it wasnt actually getting the address of the objects constructor. Anyway, quite recently, I was playing around with one of the Code Spotlight submissions: Nick's x86 Decoder, and with that, it is possible to get the actual address of an objects constructor. Now I dont really know how much use this actually is, but I figure it's a pretty neat trick.
So anyway, first of all you need to modify the x86 Decoder a bit. And you need to be able to resolve jmp instructions for this to work in debug builds. Code:
Next I present the modified x86 decoder, which now calculates the size of a single instruction and returns the actual opcode, and the GetActualAddrOfFunction which resolves the jmp instruction (in vc++7 builds at least) to get the actual address of a function. Code:
|
|
|
|
|
|
#2 |
|
Valued Member
Join Date: Aug 2004
Posts: 120
|
I might be ignorant, but why is this useful? Or is not? And just nifty?
|
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Aug 2004
Location: Ghent, Belgium
Posts: 1,056
|
Very creative!
![]() SnprBoB86, indeed the usefulness is practically zero. A static function can just create any object you need and you can take the pointer of the static function. Anyway, ideas like these can become useful in rare situations like when writing your own debugger or profiling tool, or it can be used to fool crackers, etc. So it's valuable as an excercise and source of inspiration. |
|
|
|
|
|
#4 | ||
|
DevMaster Staff
Join Date: Sep 2003
Location: Hell
Posts: 1,109
|
Quote:
Quote:
![]() |
||
|
|
|
|
|
#5 |
|
Valued Member
Join Date: Aug 2004
Posts: 120
|
lol, by the time I skimmed the code to the bottom, I had forgotten reading that.
I'm a dope hehe |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Aug 2004
Location: Århus, Denmark
Posts: 688
|
There is always the __ctor and __dtor, but MSVC won't allow me to take the address of them...
Time fer some hacking ![]()
___________________________________________
"Stupid bug! You go squish now!!" - Homer Simpson |
|
|
|
|
|
#7 |
|
New Member
Join Date: Jul 2005
Posts: 6
|
or as nick hinted you could do the following:
Code:
used as: Code:
or: Code:
Last edited by {FluffysWhole} : 09-19-2005 at 04:49 PM. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|