-
Notifications
You must be signed in to change notification settings - Fork 70
/
mapfileparser.cpp
75 lines (56 loc) · 1.6 KB
/
mapfileparser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "perses.hpp"
#include <regex>
using namespace perses;
bool MapFileParser::parse(std::filesystem::path filePath)
{
if (!std::filesystem::exists(filePath))
return false;
std::ifstream infile(filePath);
std::string line;
while (std::getline(infile, line))
{
parseLine(line);
}
return !_symbols.empty();
}
bool MSVCMapFileParser::parseLine(std::string_view line)
{
std::string s = line.data();
std::regex rgx (R"#(\s(\d+)\:([a-fA-F0-9]+)\s+(\S+)\s+([a-fA-F0-9]+)\s+(.+))#", std::regex_constants::ECMAScript);
if (std::regex_match(s, rgx))
{
for (std::smatch m; std::regex_search(s, m, rgx); s = m.suffix())
{
MapSymbol symbol { };
symbol.address = std::strtoull(m[4].str().c_str(), nullptr, 16);
if (symbol.address == 0ull)
continue;
symbol.sectionIndex = std::atoi(m[1].str().c_str());
symbol.sectionOffset = std::strtoul(m[2].str().c_str(), nullptr, 16);
symbol.name = m[3].str();
symbol.libobj = m[5].str();
_symbols.emplace_back(std::move(symbol));
}
return true;
}
return false;
}
bool IDAMapFileParser::parseLine(std::string_view line)
{
std::string s = line.data();
std::regex rgx(R"#(.(\d+)\:([a-fA-F0-9]+)\s+(\S+))#", std::regex_constants::ECMAScript);
if (std::regex_match(s, rgx))
{
for (std::smatch m; std::regex_search(s, m, rgx); s = m.suffix())
{
MapSymbol symbol{ };
symbol.address = 0ull;
symbol.sectionIndex = std::atoi(m[1].str().c_str());
symbol.sectionOffset = std::strtoul(m[2].str().c_str(), nullptr, 16);
symbol.name = m[3].str();
_symbols.emplace_back(std::move(symbol));
}
return true;
}
return false;
}