Quote:
Originally Posted by { Angelius }
Plenty of other problems in the bits of asm you posted but I really don't have time to go over them all, However very quickly.
Code:
MOV ESI, Properties::Inventory_Base_address// PUSHAD?
LEA EDI,DWORD PTR SS:[EBP-0x1C]//Does EBP really point to where you think it points? I think this is where my problem lies.
MOVS DWORD PTR ES:[EDI],DWORD PTR DS:[ESI]//What does ESI point to an array? ESI pointing to the array that contains Inventory Item pointer information. This location is correct as I'm getting the correct values.
MOVS DWORD PTR ES:[EDI],DWORD PTR DS:[ESI]//This is doing exactly what the instruction above it already did so whats the point? Each time this is called EDI and ESI are increased by 0x4. Essentially increasing the index of the array
PUSH TIndex//Are you sure Inventory_Deque_Function_address actually pops this before it returns? Doesn't look like it POPs it but it copies the value using a MOV and the stack pointer + offset.
LEA ECX, DWORD PTR SS:[EBP-0x1C]//Does Inventory_Deque_Function_address use EDI or ECX? Looks like it uses ECX.
MOVS DWORD PTR ES:[EDI],DWORD PTR DS:[ESI]
MOVS DWORD PTR ES:[EDI],DWORD PTR DS:[ESI]//useless duplicate, same as above.
CALL Properties::Inventory_Deque_Function_address
MOV _TTReturn, EAX
//Where is the RET instruction? This function needs to return somewhere. Do I need a return when the function isn't naked?
|
You are totally right. Though at one point I was pushing and popping all the data and it was still crashing. I think my real issues lies in me not knowing what I am doing with managing the stack. All of the other functions that I have used I've never needed to allocate space and de-allocate space as its all handled with the PUSH and POPing (right? thought I had noticed this). The part that is throwing me for a loop is why does it only become a problem when I call two of my functions one after the other? If I repeatedly called my "display message" function that calls the ItemCount function I have zero issues. I can also call both of the functions separately and they work just fine.
Here are the functions that I am using.
Code:
void Client::DisplayMessage(int TChatType, string _TTMessage)
{
__asm{
PUSHAD
PUSHFD
PUSH 0
PUSH 0
PUSH 0xFFFF00
PUSH TChatType
PUSH DWORD PTR DS:[_TTMessage]
MOV ECX, 0x508D10
CALL Properties::ScreenMessage_Function_address
POPFD
POPAD
}
}
Code:
int Client::GetInvetoryItemCount(){
int _TReturn = 0;
__asm {
PUSHAD
PUSHFD
MOV EBX, Properties::Inventory_Base_address
PUSH EBX
MOV ECX, Properties::Inventory_Sub_address
CALL Properties::Inventory_Count_Function_address
MOV _TReturn, EAX
POPFD
POPAD
}
return _TReturn;
}
Code:
int Client::GetInventoryItemAddress(int TIndex){
int _TTReturn = 0;
__asm{
PUSHAD
PUSHFD
MOV ESI, Properties::Inventory_Base_address
LEA EDI,DWORD PTR SS:[EBP-0x1C]
MOVS DWORD PTR ES:[EDI],DWORD PTR DS:[ESI]
MOVS DWORD PTR ES:[EDI],DWORD PTR DS:[ESI]
PUSH TIndex
LEA ECX, DWORD PTR SS:[EBP-0x1C]
MOVS DWORD PTR ES:[EDI],DWORD PTR DS:[ESI]
MOVS DWORD PTR ES:[EDI],DWORD PTR DS:[ESI]
CALL Properties::Inventory_Deque_Function_address
MOV _TTReturn, EAX
POPFD
POPAD
}
return _TTReturn;
}
I'm calling the function kinda of like this:
Code:
void HandleCommand(int Cmd)
{
switch(Cmd)
Case 1:
DisplayMessage(2006, "Testing message");
switch(Cmd)
Case 2:
DisplayMessage(2006, "Item Count:" + GetInventoryItemCount());
switch(Cmd)
Case 3:
cout << hex << "Address: " << GetInventoryItemAddress(3) << endl;
switch(Cmd)
Case 4:
DisplayMessage(2006, "Testing message");
GetInventoryItemAddress(3);
}
I can use commands 1 through 3 but when I call 4 it causes a crash. And it does appear to crash when it uses anything EBP. You asked above, "Is this where you think EBP points?" And, honestly, I'm not even sure how to answer that question. I think my issue is stack management in my GetInventoryItemAddress.
I appreciate you taking the time to look this over.
Edit:
So I have been messing around with this more throughout the day and I have made some changes. I really tried to make the functions something that I understand a little better and I feel like I did a decent job in that.
My deque function now looks like this:
Code:
int Client::GetInventoryItemAddress(int TIndex){
int _TTReturn = 0;
int adr1 = *reinterpret_cast<int*>(0x050BDF8);
int adr2 = *reinterpret_cast<int*>(0x050BDFC);
int adr3 = *reinterpret_cast<int*>(0x050BE00);
int adr4 = *reinterpret_cast<int*>(0x050BE04);
__asm{
PUSHAD
PUSHFD
PUSH adr4
PUSH adr3
PUSH adr2
PUSH adr1
PUSH TIndex
MOV ECX, ESP //ECX need to the the address of the first Address on the stack.
ADD ECX, 0x4
CALL Properties::Inventory_Deque_Function_address;
ADD ESP, 0x10 //Because the values are not popped off the stack need to 'reset' the stack pointer
MOV _TTReturn, EAX
POPFD
POPAD // After this the stack and registers looked like they did before it started.
}
return _TTReturn;
}
When I was rewriting the function I took extra care to make sure that the registers and the stack looked exactly like they did before the ASM portion of the code was executed. With this new function I am still having troubles when I try to call my displaymessage function right after this one. Even Ollydbg seems to be acting strange (Actually i don't know what I'm doing :D)
When I look at the registers I see that:
Code:
EAX 02A5FAF8 ASCII "Testing Message"
And when I "follow in stack" I see:
Code:
02A5FAF8 74736554 MSVCRT.74736554
And if I instead "follow in dump" I see:
Code:
02A5FAF8 54 65 73 74 69 6E 67 20 4D 65 73 73 61 67 65 Testing Message