Raised This Month: $51 Target: $400
 12% 

Get access to function fields


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 03-08-2014 , 06:00   Get access to function fields
Reply With Quote #1

Function detour

CBaseServer::ForwardPacketsFromMasterServerUp dater(void)
PHP Code:
DETOUR_DECL_MEMBER0(DetourForwardPacketsFromMasterServerUpdaterint)
{
    
int r DETOUR_MEMBER_CALL(DetourForwardPacketsFromMasterServerUpdater)();
    return 
r;

I want to rewrite this function. I have a pseudoсode:

PHP Code:
int __cdecl CBaseServer::ForwardPacketsFromMasterServerUpdater(int a1)
{
  
int result// eax@1
  
int v2// esi@1
  
int v3// ST2C_4@3
  
__int16 v4// ST28_2@3
  
int buf// [sp+3Ch] [bp-402Ch]@3
  
int v6// [sp+403Ch] [bp-2Ch]@3
  
int v7// [sp+4048h] [bp-20h]@3
  
__int16 v8// [sp+404Eh] [bp-1Ah]@3

  
result Steam3Server();
  
v2 = *(_DWORD *)result;
  if ( *(
_DWORD *)result )
  {
    while ( 
)
    {
      
result = (*(int (__cdecl **)(intint *, signed intint *, __int16 *))(*(_DWORD *)v2 152))(
                 
v2,
                 &
buf,
                 
16384,
                 &
v7,
                 &
v8);
      if ( 
result <= )
        break;
      
v3 result;
      
v4 v8;
      
netadr_s::SetIP(&v6v7);
      
netadr_s::SetPort(&v6v4);
      
netadr_s::SetType(&v63);
      
NET_SendPacket(0, *(_DWORD *)(a1 8), (int)&v6, (int)&bufv300);
    }
  }
  return 
result;

How can I get access to result, v6, a1 from Detour ? It is necessary to make calls: netadr_s::SetIP(&v6, v7) ....
And how can I get the address of the function ForwardPacketsFromMasterServerUpdater in DETOUR_DECL_MEMBER0() {..} ?

Last edited by kadet.89; 03-08-2014 at 06:37.
kadet.89 is offline
Send a message via Skype™ to kadet.89
donrevan
AlliedModders Donor
Join Date: Jul 2010
Old 03-08-2014 , 16:06   Re: Get access to function fields
Reply With Quote #2

What do you want to accomplish? There are maybe other ways to do this more easily.

Anyway, let's see what I can do

The function basicly looks for pending packets it needs to send. In this process are 2 calls involved.
The first is GetNextOutgoingPacket to get the next packet it needs and NET_SendPacket to send it.

You can see that this calls GetNextOutgoingPacket because it's doing:
Code:
ASM:
call dword ptr [eax+98h]

pseudocode:
result = (*(int (__cdecl **)(int, int *, signed int, int *, __int16 *))(*(_DWORD *)v2 + 152))(
                 v2,
                 &buf,
                 16384,
                 &v7,
                 &v8); //152 == 0x98
which means call function at vtable index 38. Thanks to OSW we've this. Count the virtual functions and you'll know that 38 is our match.
You want to change result, v6 and a1.
a1 is CBaseServer, v6 clearly is the netadr struct and result is the packet length.

I don't know if this is a really good idea because the function is called alot but you can hook NET_SendPacket and check if the return address == ForwardPacketsFromMasterServerUpdater and modify the params if so.

Last edited by donrevan; 03-08-2014 at 16:11.
donrevan is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 03-09-2014 , 06:42   Re: Get access to function fields
Reply With Quote #3

Thanks for the reply. I solved the problem in another way. I replaced the address of the called function NET_SendPacket with the address of mine function.
kadet.89 is offline
Send a message via Skype™ to kadet.89
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode