Archived

This topic is now archived and is closed to further replies.

Craazer

Ways around type safe VS?

Recommended Posts

Hi! Is there any known ways like some sort of hack's to code in Visual studio? Let me explain: One way is the _asm tag so you can write asm instead of c/c++. You can break the so called type safe whit it but you can't enter asm code some where around function call thru the parlist. Another way is very dangerous looking and it's a bit too much a hack to me... (I haven't even tested this code)
char x [5] = { /* Code here in hex... */ };
void main ()
{       
void (*f)() = x;       
f(); // I've only heard that it executes the x's hex code

}
void (*f)() = (void(*)())x; 
So how is there any other cool 'not so safe' procedures possible whit MS VS? [edited by - Craazer on September 1, 2003 9:30:16 AM]

Share this post


Link to post
Share on other sites

coding in assembler lets you break any type safety, that''s simply because it isn''t a strongly typed language so I''m not sure what your point is with that.

If you''re asking how to have a function which doesn''t need to have its parameters passed in C/C++ types and variable names, then look up __declspec(naked) on MSDN, that lets you do ALL the parameter fetching and stack tidy up work yourself.

--
Simon O''Connor
3D Programmer &
Microsoft DirectX MVP

Share this post


Link to post
Share on other sites
quote:
Original post by S1CA
look up __declspec(naked) on MSDN, that lets you do ALL the parameter fetching and stack tidy up work yourself.


Does that have any practical use?

--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]

Share this post


Link to post
Share on other sites
quote:
Original post by S1CA

coding in assembler lets you break any type safety, that''s simply because it isn''t a strongly typed language so I''m not sure what your point is with that.

If you''re asking how to have a function which doesn''t need to have its parameters passed in C/C++ types and variable names, then look up __declspec(naked) on MSDN, that lets you do ALL the parameter fetching and stack tidy up work yourself.

--
Simon O''Connor
3D Programmer &
Microsoft DirectX MVP



Im sorry, that was not what I ment and I''ve modified asm part of my post. But ya, you are in right tracks becose the reason of this post was to disguss about the options and the __declspec(naked) sure seems to be one, so thanks!

Share this post


Link to post
Share on other sites
Yeah... there are plenty of ways around type safe. Any type can be cast to a void, and from a void to any type... so I don''t really understand what you''re saying.

I had to use some asm hacks to get the address of a label to make a custom jump table, I could even jump from different functions to other functions as long as the return was the same.

Anyways, the point is... type safe is only safe if you chose it to be. You can easily use buffer-overruns to execute some code you want, change a function pointer to an array and call it, or you can jump to the array directly with a function pointer.

unsigned char SomeStuff[] = { //Hex code here };

__asm{
mov esi, byte ptr SomeStuff
mov eax, esi
jmp eax
};

Share this post


Link to post
Share on other sites
quote:
Original post by Ready4Dis
Yeah... there are plenty of ways around type safe. Any type can be cast to a void, and from a void to any type... so I don''t really understand what you''re saying.

I had to use some asm hacks to get the address of a label to make a custom jump table, I could even jump from different functions to other functions as long as the return was the same.

Anyways, the point is... type safe is only safe if you chose it to be. You can easily use buffer-overruns to execute some code you want, change a function pointer to an array and call it, or you can jump to the array directly with a function pointer.

unsigned char SomeStuff[] = { //Hex code here };

__asm{
mov esi, byte ptr SomeStuff
mov eax, esi
jmp eax
};


Ok thanks, I know now better what type safe means. However thoes hacks like you just shoved are very intresting!

Im specially intrested in function call hacks and other related asm. Like __declspec(naked) wich was nice but not very usefull if your not writing drivers, I think.

And what I have allways wanted to do is:
fnp(PushAnyParRequired());
But obiviously that doesn''t work like that becose even callit''s argument list would look like: (...) conversion is needed so compiler can build aprociate code.

Share this post


Link to post
Share on other sites