少年修仙传客户端基础资源
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
#include "MSVCSectionParser.h"
#include "../ParseBuffer.h"
#include <stdexcept>
#include <sstream>
#include <cstring>
#include <cstdio>
 
using std::stringstream;
 
namespace mapfileparser
{
//  0001:00000000 0096f9beH .text                   CODE
    Section MSVCSectionParser::Parse(const std::string& line)
    {
        int32_t segmentName;
        int32_t start;
        int32_t length;
 
        size_t lineLength = line.length();
        ParseBuffer name(lineLength);
        ParseBuffer segmentType(lineLength);
 
        int fieldsParsed = sscanf(line.c_str(), "%X:%X %XH %s %s", &segmentName, &start, &length, name.buffer, segmentType.buffer);
        if (fieldsParsed != 5)
            throw std::runtime_error(std::string("Unable to parse section: ") + line);
 
        stringstream segmentNameStream;
        segmentNameStream << segmentName;
 
        Section section = { start, length, name.buffer, segmentNameStream.str(), strcmp(segmentType.buffer, "DATA") == 0 ? kSegmentTypeData : kSegmentTypeCode };
        return section;
    }
}