Jump to content

The value of ESP was not properly saved across a function call...


Recommended Posts

LOL Aight, Im Kinda Not The Best At This Stuff. BUT It Deals With Assembly From OllyDBG And A Game Called GunZ.

Im Trying To Figure Out A Way To Get This

typedef void (__cdecl* ZChatOutputFunction)(const char* lpcMsg, int iType,int iLoc,DWORD dwColor);

ZChatOutputFunction ZChatOutput = (ZChatOutputFunction)ZChat;

void EchoOutput(const char *szMsg, ...)

{

char szBuf[0x4000];

va_list vaArgs;

va_start(vaArgs, szMsg);

_vsnprintf(szBuf, sizeof(szBuf), szMsg, vaArgs);

va_end(vaArgs);

ZChatOutput(szBuf, 2, 0, 0xFFFFFFFF);//ZChatOutput You Get From An Address In OllyDBG, That Works...

}

To Work In Inline asm

Like So

#define ZChatOutput 0x0042ABC0;//This Is The Address

void Echo(const char *szMsg, ...){

_asm{

pushad

PUSH eax

mov eax,ZChatOutput

PUSH 0xFFFFFFFF

PUSH 0

PUSH 2

PUSH szMsg

call eax

pop eax

popad

}}

Now... It Works, Somewhat

It Outputs A Sample Message Lets Say When I Call It Like So

Echo("Hello, This Is Testing ZChatOutput!");

It Outputs That String In-Game

But Then A Second Later It Crashes, And I Get This Message [image Attached]

The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with calling convention with a function pointer declared with a different calling convention.

errorvu8.png

Any Help is Appreciated!

Thanks~

-Marneus901

Link to comment
Share on other sites


When I see code like that, it reminds me that you can have buffer overrun issues when using char *, and also, you should really be using stdcall instead of a C calling convention (like you are doing). It would be interesting for you to try and have it compile in VS 2005 or 2008.

Link to comment
Share on other sites

Well The Thing Is, I Want To Use Inline asm, Not The Calling Conventions. With The Inline asm, I Have No Calling Conventions, It Works Like I Said, It Outputs, Then Gives Me That ESP Error >.>

So, It Shouldnt* Have To Deal With The Calling Conventions.

An Example Of Perfect Working Code Is

void SetAP(){
if(InGame()){//Check If In Game So We Dont Crash
_asm{
mov ecx,MyZChar //Get Our Character ID
mov eax,ZCharacter__SetAPOffset //Get The SetAP Offset
PUSH 999 //Push The Value We Want Our AP At
call eax //And Send To The Offset
}
}
}

It Perfectly Sets My AP, With No Errors. Which Is Weird Why Output Gives Me An Error...

Edited by Marneus901
Link to comment
Share on other sites

It is odd, and your initial post of sample code above doesn't have any glaring errors I can see. However, you may want to consider trying to save the register before you go in, and restore it on your way out. It's something you could try, although I'm thinking the compiler should catch it for you.

Again, not sure - it's not obvious what the problem is.

Link to comment
Share on other sites

It is odd, and your initial post of sample code above doesn't have any glaring errors I can see. However, you may want to consider trying to save the register before you go in, and restore it on your way out. It's something you could try, although I'm thinking the compiler should catch it for you.

Again, not sure - it's not obvious what the problem is.

Yeah, I told him basically the same thing, I figured it was something with the way the call was returning, since it executes all the code just fine. I myself have only looked at it for a few minutes here and there, but I agree that nothing jumped out at me. I'll have to remember that we have some ASM gurus out there too, been so long since I've used anything besides VBScript or C# that I almost forgot other languages existed.

Link to comment
Share on other sites

Ok, I Found The Solution, And I Got It To Work.

I Needed To Clean Up The Stack Using

add esp,[# of pushed values * 4]

I Found The Solution Here: http://www.codeproject.com/cpp/calling_con...demystified.asp

The Way It Should Look Like Is Like So

void Echo(const char *szMsg, ...){ 
_asm{
mov eax,ZChatOutput
PUSH 0xFFFFFFFF
PUSH 0
PUSH 2
PUSH szMsg
call eax
add esp,16
}}

I Had To add esp,16, 16 Because 4 Pushed Values * 4 = 16, Hence add esp,16

Thanks For Your Attempts To Help Otherwise!

-Marneus901

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...