tries to solve the symbol issue with Keystone, which apparently originates from LLVM-MC.
21{
22 std::string RawAsm =
AsmRaw;
23
24
25
26
27 RawAsm.erase(std::remove(RawAsm.begin(), RawAsm.end(), '\n'), RawAsm.end());
28
29
30
31
32 std::regex MultipleSpaces(" +");
33 RawAsm = std::regex_replace(RawAsm, MultipleSpaces, " ");
34
35
36
37
38 std::vector<std::string> AssemblyInstructions;
39 size_t Pos = 0;
40 std::string Delimiter = ";";
41 while ((Pos = RawAsm.find(Delimiter)) != std::string::npos)
42 {
43 std::string Token = RawAsm.substr(0, Pos);
44 if (!Token.empty())
45 {
46 AssemblyInstructions.push_back(Token);
47 }
48 RawAsm.erase(0, Pos + Delimiter.length());
49 }
50 if (!RawAsm.empty())
51 {
52 AssemblyInstructions.push_back(RawAsm);
53 }
54
55
56
57
58 for (auto & InstructionLine : AssemblyInstructions)
59 {
60 std::string Expr {};
62 size_t Start {};
63
64 while ((Start = InstructionLine.find('<', Start)) != std::string::npos)
65 {
66 size_t End = InstructionLine.find('>', Start);
67 if (End != std::string::npos)
68 {
69 std::string Expr = InstructionLine.substr(Start + 1, End - Start - 1);
71 {
72 ShowMessages(
"err, failed to resolve the symbol [ %s ].\n", Expr.c_str());
73 Start += Expr.size() + 2;
74 continue;
75 }
76
77 std::ostringstream Oss;
78 Oss << std::hex << std::showbase << ExprAddr;
79 InstructionLine.replace(Start, End - Start + 1, Oss.str());
80 }
81 else
82 {
83
84
85
86 break;
87 }
88 Start += Expr.size() + 2;
89 }
90 }
91
92
93
94
95 auto ApndSemCln = [](std::string a, std::string b) {
96 return std::move(a) + ';' + std::move(b);
97 };
98
99
100
101
102 AsmFixed = std::accumulate(std::next(AssemblyInstructions.begin()), AssemblyInstructions.end(), AssemblyInstructions.at(0), ApndSemCln);
103
105 {
106
107
108
110 }
111
113 {
115 }
116}
std::string AsmRaw
Definition assembler.h:18
BOOLEAN SymbolConvertNameOrExprToAddress(const string &TextToConvert, PUINT64 Result)
check and convert string to a 64 bit unsigned integer and also check for symbol object names and eval...
Definition symbol.cpp:360