Raised This Month: $ Target: $400
 0% 

[RESOLVED] Linux Startup Binary


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Keeper
Senior Member
Join Date: Nov 2006
Old 09-09-2009 , 00:38   [RESOLVED] Linux Startup Binary
Reply With Quote #1

Is there any way at run time to know if srcds_i486 or srcds_i686 was run? It matters in the EP1 games when you try to reach into the engine_i486/i686.so.

Or am I going about it wrong?

TIA,
Keeper

Last edited by Keeper; 09-23-2009 at 11:05.
Keeper is offline
BAILOPAN
Join Date: Jan 2004
Old 09-09-2009 , 02:20   Re: Linux Startup Binary
Reply With Quote #2

Use dlinfo() and pass the address of something you know is in engine_mumble_grumble.so
__________________
egg
BAILOPAN is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 09-10-2009 , 17:28   Re: Linux Startup Binary
Reply With Quote #3

Ok, I said "worked like a charm" ... it showed what I thought it should show. For EP1 games, all I get for a response on engine_i486.so is:
Code:
Found gametypes for Half-Life 2 Deathmatch                        
1: ./bin/engine_i486.so                                           
Linux game binary @ ./hl2mp/bin/server_i486.so                    
Linux engine binary @ ./bin/engine_i686.so
Basically since it doesn't show any other libraries I consider it unused. Here's what it shows for engine_i686.so:
Code:
Found gametypes for Half-Life 2 Deathmatch                                      
1: bin/engine_i686.so                                                           
2: bin/libsteamvalidateuseridtickets_i486.so                                    
3: bin/steam_api_i486.so                                                        
4: bin/shaderapiempty_i486.so                                                   
5: /plugins/srcds_1/hl2mp/bin/server_i486.so                                    
6: /plugins/srcds_1/bin/scenefilecache_i486.so                                  
7: /plugins/srcds_1/bin/../hl2mp/addons/mani_admin_plugin_i486.so               
8: /lib/tls/i686/cmov/libnss_files.so.2                                         
Linux game binary @ ./hl2mp/bin/server_i486.so                                  
Linux engine binary @ ./bin/engine_i686.so
What's strange is if I test with the i486 then on the systems that run i686 the server crashes because a hook switches it back to _i486:
Code:
 (gdb) bt
bt
#0  0xb148e82c in Host_Client_Printf () from ./bin/engine_i486.so
#1  0xb14907d9 in Host_Status_f () from ./bin/engine_i486.so
#2  0xb1905ca8 in __SourceHook_FHCls_ConCommandDispatch0::Func (this=0xb16f16a0) at mani_sourcehook.cpp:125
#3  0xb72e626b in Cmd_ExecuteString () from bin/engine_i686.so
#4  0xb72e6576 in Cbuf_Execute () from bin/engine_i686.so
#5  0xb7349b2e in _Host_RunFrame () from bin/engine_i686.so
#6  0xb734a2b2 in Host_RunFrame () from bin/engine_i686.so
#7  0xb73543bc in CHostState::State_Run () from bin/engine_i686.so
#8  0xb7354661 in CHostState::FrameUpdate () from bin/engine_i686.so
#9  0xb73547e7 in HostState_Frame () from bin/engine_i686.so
#10 0xb73e9f94 in CEngine::Frame () from bin/engine_i686.so
#11 0xb73e7dae in CDedicatedServerAPI::RunFrame () from bin/engine_i686.so
#12 0xb7e6f0fd in RunServer () from bin/dedicated_i686.so
#13 0xb73e778e in CModAppSystemGroup::Main () from bin/engine_i686.so
#14 0xb74eebc3 in CAppSystemGroup::Run () from bin/engine_i686.so
#15 0xb73e89df in CDedicatedServerAPI::ModInit () from bin/engine_i686.so
#16 0xb7e6f34a in CDedicatedAppSystemGroup::Main () from bin/dedicated_i686.so
#17 0xb7ea6713 in CAppSystemGroup::Run () from bin/dedicated_i686.so
#18 0xb7ea6713 in CAppSystemGroup::Run () from bin/dedicated_i686.so
#19 0xb7e6f758 in main () from bin/dedicated_i686.so
#20 0x0804909e in main ()
Why would it do this?
Keeper is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 09-11-2009 , 12:28   Re: Linux Startup Binary
Reply With Quote #4

Ok, figured it out. It's actually easier than I thought. All you have to do is a dlopen with the RTLD_NOLOAD flag and if the handle is null, then it's not loaded.
Code:
void * handle;
handle = dlopen ( "./bin/engine_i486.so", RTLD_NOW | RTLD_NOLOAD );
If handle is null then you are using i686 otherwise it's i486.

Thanks!
Keeper
Keeper is offline
BAILOPAN
Join Date: Jan 2004
Old 09-15-2009 , 13:55   Re: Linux Startup Binary
Reply With Quote #5

I don't know why you say that's necessary. It shouldn't "switch" to i486 and I've not had that happen in my code before.

Regardless it's in poor form to re-dlopen() the executable. A few thoughts:

1. dlinfo() is a GNU-specific extension, it should get you the handle (I think).
2. I originally meant dladdr(), but I'm not sure if ::dli_fbase is a handle or the memory base of the library (I think the former).
3. We just parse /proc/<pid>/maps which is safest - but we use #2 for sanity checks. See sourcemod-central/core/MemoryUtils.cpp. But that's for signature scanning - if you need to use dlsym() then I guess you need a Handle.
__________________
egg

Last edited by BAILOPAN; 09-15-2009 at 14:06.
BAILOPAN is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 09-15-2009 , 14:39   Re: Linux Startup Binary
Reply With Quote #6

The newer version of the libraries support RTLD_SELF. Unfortunately it's not available to me, or else I'd use just dlinfo. I was using dlopen without the RTLD_NOLOAD which was causing the non loaded binary to be loaded which is why it switched and subsequently crashed.

Using RTLD_NOLOAD seems to work, but I will look at #3 to see if it would better suit our needs. If opening the binary even without loading it is bad form, then I don't want to do it. I'm using it to detour the ConnectClient in the engine. But I don't want to attempt to slap a detour on a non loaded binary, which is a possibility with EP1 games.

Thanks!

EDIT: I just looked in another of my older plugins. The code for the /proc/<pid>/maps is in there. I'll just use this since it will give me the info I need.

Last edited by Keeper; 09-15-2009 at 16:31.
Keeper is offline
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 12:24.


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