ESP corruption

I need to use a function in an OBJ file for which I don't have the source code. This function is poorly written and corrupts the stack (The value of ESP was not properly saved across a function call... error on visual studio 2010). It does what its supposed to do when I call it, but when it returns the program crashes since the program is lost. I have tried with __cdecl and __stdcall, no difference. I've seen the source code, but I don't have it, the author use call without ret, which I think is the source of the problem. Considering the function does what its supposed to do, id like to keep using it. Is there anything I can do to patch this problem?

Thank you
You're talking about essentially "breaking" the program at this point. Depending on the specific error this is probably possible but it will need to be rebroken for everyother update applied on the system it is running on. I strongly suggest against doing this.

How is it you have access to the funtion but not the source code? That seems odd to me. Is it part of a DLL?
Sort of, it's an obj file. This is interesting computergeek, can you please elaborate some more or give some keywords to google for?

In case you're wondering about the call and ret I was talking about, the function is written in assembler and compiled into an obj file
Last edited on
You can try looking up "Function Attributes" for your compiler, there is one for GCC\MingW that declares a function will not be returned from but I always have to fight with it to get it working. As for the error you may have to try to intercept the system call at the point it crashes, I'm not too good at this part though, and only have limited success using the programs destructor to "recover" from the errors.

This is mostly Black Hat stuff right now. I don't mean Black Hat as in hacker, I mean it as in a hackers tendency to work around the system as oppsed to inside of it. Black Hat's tend to be better with "Dirty Hacks" then they are with proper coding.

EDIT: I should reenforce that this is NOT the proper way to do things. This is not only platform specific but also COMPILER specific code you'll be writing and honestly unless the origional author is dead it would probably be easier to contact them for some help.
Last edited on
Would it be possible for you to look at the disassembly and figure out how to write a wrapper function in Assembly that follows proper calling conventions?
Topic archived. No new replies allowed.