LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2004, 11:52 PM   #1
Damaged Soul
LQ Newbie
 
Registered: Nov 2004
Posts: 8

Rep: Reputation: 0
Reading Memory Value from ELF Binary


Ok, here's my situation. I am writing a module (in C/C++) for something called AMX Mod X (amxmodx.org). AMX Mod X is a server-side administration tool for Half-Life based game servers. It allows plugins to be written (in a language called Small) that extend the base server functionality of the server as well as modify the way the game is played to some extent due to the use of the Half-Life SDK. Modules add functions that can be used in these plugins. And that is what I'm coding, a module.

I'm trying to create a function to read memory values from the server SO binary. You see there is an hlds (Half Life Dedicated Server) binary which in itself allows a server to be run. This would be considered the process that I am trying mess with you could say. And there is also a SO binary which contains all the server-related code for the particular game (whether it be Counter-Strike, Half-Life Deathmatch, Day of Defeat, etc). I wish to read a value from that SO file, but while the server is running, so this would be done in memory obviously.

So the hlds process relies on the this server binary. AMX Mod X and it's modules hook into the server binary and so it should have sufficient access to the process's memory space.

With all that information aside, I'm wondering how I can do this. How can I read a value from the server binary? The value I want would be in the .data section of this binary, by the way. Due to the nature of loading a binary on demand under Linux, this seems to be tricky to me. I have done some reading on the ELF file format. I was thinking that I might be able to access the Global Offset Table of the hlds process and use that to find out where the ELF header of the server binary SO is in memory. And then using that I could find out where the .data section of this SO is located. And finally with that information, I could just read the value I want using an offset I have derived in a disassembler.

The problem with this, however, is that I'm not entirely sure how I can accomplish this with code. There's not a whole lot of information on doing this as far as I can tell, especially doing this sort of thing in memory. Also my conclusions on how to do this in the first place might be wrong as well. I have already been able to read the value I want in a Windows server binary, but I didn't need to go to great lengths to accomplish it. So I'd appreciate some help in this area on doing this under Linux. Thanks in advance.
 
Old 11-23-2004, 04:40 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
If what you are looking for is a symbol (text, function entry point)
dlsym() will find it in process memory. Assuming your plugin doesn't end up as a child process.
 
Old 11-23-2004, 07:44 PM   #3
Damaged Soul
LQ Newbie
 
Registered: Nov 2004
Posts: 8

Original Poster
Rep: Reputation: 0
To be honest I'm not sure what it is. Although it certainly isn't a function pointer. It's just a piece of data in the .data section of the binary. I'm not sure what the symbol name is if any. There doesn't seem to be any relevant names in the list of strings for the binary that are related to what this data is used for. The data I'm trying to read, is the cost of a weapon in Counter-Strike. Eventually I'd like to change this value. But for now I just want to be able to read it. I just hoped there was a way I could use the ELF headers to locate it in memory in the way I described earlier.
 
Old 11-24-2004, 08:32 PM   #4
Damaged Soul
LQ Newbie
 
Registered: Nov 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Doesn't anyone have any ideas about this? I realize that this whole thing is quite hackish. The value I am trying to read does not seem to have a public symbol that can easily be retrieved via dlsym. The only thing I've been able to figure it out is that it is in the .data section with the use of a disassembler. But there must some way I can read this value with use the ELF header and/or the GOT. Reading that header in memory versus directly from the binary file on the hard drive is quite different as I have found.
 
Old 11-24-2004, 11:52 PM   #5
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
You might want to look into libbfd.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Binary reading/writing in cpp kornerr Programming 1 11-27-2005 07:09 PM
Reading/Modifying .rcc file (believe to be ELF) chrisrock79 Linux - Newbie 1 09-12-2005 02:59 PM
How to compile into ELF binary? kornerr Programming 3 06-29-2005 11:37 AM
Distro: Less scripting. Looking for mainly Elf binary based distro Z505 Linux - General 1 04-02-2005 11:33 PM
depmod: error reading ELF section data Commish66 Mandriva 1 02-12-2004 12:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration