xref: /haiku/src/tools/elfsymbolpatcher/ElfImage.h (revision 239222b2369c39dc52df52b0a7cdd6cc0a91bc92)
1e79e4e7cSIngo Weinhold //------------------------------------------------------------------------------
2e79e4e7cSIngo Weinhold //	Copyright (c) 2003, Ingo Weinhold
3e79e4e7cSIngo Weinhold //
4e79e4e7cSIngo Weinhold //	Permission is hereby granted, free of charge, to any person obtaining a
5e79e4e7cSIngo Weinhold //	copy of this software and associated documentation files (the "Software"),
6e79e4e7cSIngo Weinhold //	to deal in the Software without restriction, including without limitation
7e79e4e7cSIngo Weinhold //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8e79e4e7cSIngo Weinhold //	and/or sell copies of the Software, and to permit persons to whom the
9e79e4e7cSIngo Weinhold //	Software is furnished to do so, subject to the following conditions:
10e79e4e7cSIngo Weinhold //
11e79e4e7cSIngo Weinhold //	The above copyright notice and this permission notice shall be included in
12e79e4e7cSIngo Weinhold //	all copies or substantial portions of the Software.
13e79e4e7cSIngo Weinhold //
14e79e4e7cSIngo Weinhold //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15e79e4e7cSIngo Weinhold //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16e79e4e7cSIngo Weinhold //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17e79e4e7cSIngo Weinhold //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18e79e4e7cSIngo Weinhold //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19e79e4e7cSIngo Weinhold //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20e79e4e7cSIngo Weinhold //	DEALINGS IN THE SOFTWARE.
21e79e4e7cSIngo Weinhold //
22e79e4e7cSIngo Weinhold //	File Name:		ElfImage.h
23e79e4e7cSIngo Weinhold //	Author:			Ingo Weinhold (bonefish@users.sf.net)
24e79e4e7cSIngo Weinhold //	Description:	Interface declaration of ElfImage, a class encapsulating
25e79e4e7cSIngo Weinhold //					a loaded ELF image, providing support for accessing the
26e79e4e7cSIngo Weinhold //					image's symbols and their relocation entries.
27e79e4e7cSIngo Weinhold //------------------------------------------------------------------------------
28e79e4e7cSIngo Weinhold 
29e79e4e7cSIngo Weinhold #ifndef ELF_IMAGE_H
30e79e4e7cSIngo Weinhold #define ELF_IMAGE_H
31e79e4e7cSIngo Weinhold 
32e79e4e7cSIngo Weinhold #include <File.h>
33e79e4e7cSIngo Weinhold #include <image.h>
34e79e4e7cSIngo Weinhold 
35e79e4e7cSIngo Weinhold #include "ElfFile.h"
36e79e4e7cSIngo Weinhold 
37e79e4e7cSIngo Weinhold class BList;
38*239222b2SIngo Weinhold 
39*239222b2SIngo Weinhold namespace SymbolPatcher {
40*239222b2SIngo Weinhold 
41e79e4e7cSIngo Weinhold class ElfSection;
42e79e4e7cSIngo Weinhold class ElfSymbol;
43e79e4e7cSIngo Weinhold 
44e79e4e7cSIngo Weinhold // ElfImage
45e79e4e7cSIngo Weinhold class ElfImage {
46e79e4e7cSIngo Weinhold public:
47e79e4e7cSIngo Weinhold 								ElfImage();
48e79e4e7cSIngo Weinhold 								~ElfImage();
49e79e4e7cSIngo Weinhold 			status_t			SetTo(image_id image);
50e79e4e7cSIngo Weinhold 			void				Unset();
51e79e4e7cSIngo Weinhold 			void				Unload();
52e79e4e7cSIngo Weinhold 
GetID()53e79e4e7cSIngo Weinhold 			image_id			GetID() const	{ return fImage; }
54e79e4e7cSIngo Weinhold 
55e79e4e7cSIngo Weinhold 			status_t			FindSymbol(const char* symbolName,
56e79e4e7cSIngo Weinhold 										   void** address);
57e79e4e7cSIngo Weinhold 			status_t			GetSymbolRelocations(const char* symbolName,
58e79e4e7cSIngo Weinhold 													 BList* relocations);
59e79e4e7cSIngo Weinhold 
60e79e4e7cSIngo Weinhold private:
61e79e4e7cSIngo Weinhold 			status_t			_SetTo(image_id image);
62e79e4e7cSIngo Weinhold 
63e79e4e7cSIngo Weinhold private:
64e79e4e7cSIngo Weinhold 			image_id			fImage;
65e79e4e7cSIngo Weinhold 			ElfFile				fFile;
66e79e4e7cSIngo Weinhold 			uint8*				fTextAddress;
67e79e4e7cSIngo Weinhold 			uint8*				fDataAddress;
68e79e4e7cSIngo Weinhold 			uint8*				fGotAddress;
69e79e4e7cSIngo Weinhold };
70e79e4e7cSIngo Weinhold 
71*239222b2SIngo Weinhold } // namespace SymbolPatcher
72*239222b2SIngo Weinhold 
73*239222b2SIngo Weinhold using namespace SymbolPatcher;
74*239222b2SIngo Weinhold 
75*239222b2SIngo Weinhold 
76e79e4e7cSIngo Weinhold #endif	// ELF_IMAGE_H
77