MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / ResolveSymbol

Method ResolveSymbol

core/logic/MemoryUtils.cpp:116–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
117{
118#ifdef PLATFORM_WINDOWS
119
120 /* Add this this library into the cache */
121 GetLibraryInfo(handle);
122 return GetProcAddress((HMODULE)handle, symbol);
123
124#elif defined PLATFORM_LINUX
125
126#ifdef KE_ARCH_X86
127 typedef Elf32_Ehdr ElfHeader;
128 typedef Elf32_Shdr ElfSHeader;
129 typedef Elf32_Sym ElfSymbol;
130 #define ELF_SYM_TYPE ELF32_ST_TYPE
131#else
132 typedef Elf64_Ehdr ElfHeader;
133 typedef Elf64_Shdr ElfSHeader;
134 typedef Elf64_Sym ElfSymbol;
135 #define ELF_SYM_TYPE ELF64_ST_TYPE
136#endif
137
138 struct link_map *dlmap;
139 struct stat dlstat;
140 int dlfile;
141 uintptr_t map_base;
142 ElfHeader *file_hdr;
143 ElfSHeader *sections, *shstrtab_hdr, *symtab_hdr, *strtab_hdr;
144 ElfSymbol *symtab;
145 const char *shstrtab, *strtab;
146 uint16_t section_count;
147 uint32_t symbol_count;
148 LibSymbolTable *libtable;
149 SymbolTable *table;
150 Symbol *symbol_entry;
151
152 dlmap = (struct link_map *)handle;
153 symtab_hdr = NULL;
154 strtab_hdr = NULL;
155 table = NULL;
156
157 /* See if we already have a symbol table for this library */
158 for (size_t i = 0; i < m_SymTables.size(); i++)
159 {
160 libtable = m_SymTables[i];
161 if (libtable->lib_base == dlmap->l_addr)
162 {
163 table = &libtable->table;
164 break;
165 }
166 }
167
168 /* Add this this library into the cache */
169 GetLibraryInfo((void *)dlmap->l_addr);
170
171 /* If we don't have a symbol table for this library, then create one */
172 if (table == NULL)
173 {

Callers 1

Calls 5

push_backMethod · 0.80
sizeMethod · 0.45
InitializeMethod · 0.45
FindSymbolMethod · 0.45
InternSymbolMethod · 0.45

Tested by

no test coverage detected