MCPcopy Create free account
hub / github.com/clementgallet/libTAS / getSymbolAddress

Function getSymbolAddress

src/program/utils.cpp:199–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197}
198
199uint64_t getSymbolAddress(const char* symbol, const char* file)
200{
201 static std::string symbol_file;
202 static std::map<std::string, uint64_t> symbol_addresses;
203
204 if (symbol_file.compare(file) != 0) {
205 symbol_file = file;
206 symbol_addresses.clear();
207
208 std::ostringstream cmd;
209 cmd << "readelf -Ws \"" << file << "\" | awk '{print $2 " " $8}'";
210
211 std::string outputstr;
212 FILE *output = popen(cmd.str().c_str(), "r");
213 if (output != NULL) {
214 char buf[256];
215 while (fgets(buf, 256, output) != nullptr) {
216 std::istringstream iss(buf);
217 uint64_t addr;
218 std::string sym;
219 iss >> std::hex >> addr >> sym;
220 symbol_addresses[sym] = addr;
221 }
222 pclose(output);
223 }
224 }
225
226 auto search = symbol_addresses.find(std::string(symbol));
227 if (search != symbol_addresses.end())
228 return search->second;
229
230 return 0;
231}

Callers 3

initProcessMessagesMethod · 0.85
startFrameMessagesMethod · 0.85

Calls 4

clearMethod · 0.45
c_strMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected