少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "ClangMapFileParser.h"
#include "ClangSectionParser.h"
#include "ClangSymbolParser.h"
#include <sstream>
#include <algorithm>
#include <cstdio>
#include "../ParseBuffer.h"
 
namespace mapfileparser
{
    static std::string ReadUntilLine(std::istream& is, const char* delimiterLine)
    {
        std::string line;
        std::getline(is, line);
        while (!is.eof() && line != delimiterLine)
            std::getline(is, line);
 
        return line;
    }
 
    static void ReadObjectFiles(std::istream& is, std::vector<std::string>& objectFiles)
    {
        std::string line;
        const char* symbolsHeader = "# Sections:";
 
        std::getline(is, line);
        while (!is.eof() && line != symbolsHeader)
        {
            int32_t objectFileIndex = 0;
            size_t lineLength = line.length();
            ParseBuffer name(lineLength);
 
            sscanf(line.c_str(), "[%d] %s", &objectFileIndex, name.buffer);
            objectFiles.push_back(std::string(name.buffer));
 
            std::getline(is, line);
        }
    }
 
    static void ReadSections(std::istream& is, std::vector<Section>& sections)
    {
        std::string line;
        const char* symbolsHeader = "# Symbols:";
 
        std::getline(is, line);
        while (!is.eof() && line != symbolsHeader)
        {
            sections.push_back(ClangSectionParser::Parse(line));
 
            std::getline(is, line);
        }
    }
 
    static void ReadSymbols(std::istream& is, std::vector<Symbol>& symbols, const std::vector<std::string>& objectFiles)
    {
        std::string line;
        while (!is.eof())
        {
            std::getline(is, line);
            if (line.length() == 0)
                continue;
 
            if (line == "# Dead Stripped Symbols:")
                break;
 
            // Each managed method has _m in its name, so only record those.
            if (line.find("_m") == std::string::npos)
                continue;
 
            ClangSymbol clangSymbol = ClangSymbolParser::Parse(line);
            clangSymbol.symbol.segmentType = kSegmentTypeCode;
            clangSymbol.symbol.objectFile = objectFiles[clangSymbol.objectFileIndex];
 
            symbols.push_back(clangSymbol.symbol);
        }
    }
 
    MapFile ClangMapFileParser::Parse(std::istream& is)
    {
        MapFile mapFile;
        std::string line;
 
        ReadUntilLine(is, "# Object files:");
        std::vector<std::string> objectFiles;
        ReadObjectFiles(is, objectFiles);
 
        // Read sections headers line
        std::getline(is, line);
 
        ReadSections(is, mapFile.sections);
 
        // Read symbols headers line
        std::getline(is, line);
 
        ReadSymbols(is, mapFile.symbols, objectFiles);
 
        return mapFile;
    }
}