Skip to content

Commit 241bd25

Browse files
committed
Clean code, require latest r2 from git and add class+method info
1 parent 340df50 commit 241bd25

File tree

1 file changed

+24
-38
lines changed

1 file changed

+24
-38
lines changed

blutter/src/DartDumper.cpp

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -110,48 +110,41 @@ void DartDumper::Dump4Radare2(std::filesystem::path outDir)
110110
std::ofstream of((outDir / "addNames.r2").string());
111111
of << "# create flags for libraries, classes and methods\n";
112112

113+
of << "e emu.str=true\n";
113114
of << std::format("f app.base = {:#x}\n", app.base());
114115
of << std::format("f app.heap_base = {:#x}\n", app.heap_base());
115116

116117
bool show_library = true;
117118
bool show_class = true;
118119
for (auto lib : app.libs) {
119120
std::string lib_prefix = lib->GetName();
120-
121-
std::replace(lib_prefix.begin(), lib_prefix.end(), '$', '_');
122-
std::replace(lib_prefix.begin(), lib_prefix.end(), '&', '_');
123-
std::replace(lib_prefix.begin(), lib_prefix.end(), '-', '_');
124-
std::replace(lib_prefix.begin(), lib_prefix.end(), '+', '_');
121+
filterString(lib_prefix);
125122
for (auto cls : lib->classes) {
126123
std::string cls_prefix = cls->Name();
127-
std::replace(cls_prefix.begin(), cls_prefix.end(), '$', '_');
128-
std::replace(cls_prefix.begin(), cls_prefix.end(), '&', '_');
129-
std::replace(cls_prefix.begin(), cls_prefix.end(), '-', '_');
130-
std::replace(cls_prefix.begin(), cls_prefix.end(), '+', '_');
124+
filterString(cls_prefix);
131125
for (auto dartFn : cls->Functions()) {
132126
const auto ep = dartFn->Address();
133-
auto name = getFunctionName4Ida(*dartFn, cls_prefix);
134-
std::replace(name.begin(), name.end(), '$', '_');
135-
std::replace(name.begin(), name.end(), '&', '_');
136-
std::replace(name.begin(), name.end(), '-', '_');
137-
std::replace(name.begin(), name.end(), '+', '_');
138-
std::replace(name.begin(), name.end(), '?', '_');
127+
std::string name = getFunctionName4Ida(*dartFn, cls_prefix);
128+
filterString(name);
139129
if (show_library) {
140-
of << std::format("CC Library({:#x}) = {} @ {}\n", lib->id, lib_prefix, ep);
141-
of << std::format("f lib.{}={:#x} # {:#x}\n", lib_prefix, ep, lib->id);
130+
of << std::format("'@{:#x}'CC Library({:#x}) = {}\n", ep, lib->id, lib->GetName());
131+
of << std::format("'@{:#x}'f lib.{}\n", ep, lib_prefix);
142132
show_library = false;
143133
}
144134
if (show_class) {
145-
of << std::format("CC Class({:#x}) = {} @ {}\n", cls->Id(), cls_prefix, ep);
146-
of << std::format("f class.{}.{}={:#x} # {:#x}\n", lib_prefix, cls_prefix, ep, cls->Id());
135+
of << std::format("'@{:#x}'CC Class({:#x}) = {}\n", ep, cls->Id(), cls->Name());
136+
of << std::format("'@{:#x}'f class.{}.{}\n", ep, lib_prefix, cls_prefix);
147137
show_class = false;
148138
}
149-
of << std::format("f method.{}.{}.{}_{:x}={:#x}\n", lib_prefix, cls_prefix, name.c_str(), ep, ep);
139+
of << std::format("'@{:#x}'f method.{}.{}.{}\n", ep, lib_prefix, cls_prefix, name);
140+
of << std::format("'@{:#x}'ic+{}.{}\n", ep, cls_prefix, name);
150141
if (dartFn->HasMorphicCode()) {
151-
of << std::format("f method.{}.{}.{}.miss={:#x}\n", lib_prefix, cls_prefix, name.c_str(),
152-
dartFn->PayloadAddress());
153-
of << std::format("f method.{}.{}.{}.check={:#x}\n", lib_prefix, cls_prefix, name.c_str(),
154-
dartFn->MonomorphicAddress());
142+
of << std::format("'@{:#x}'f method.{}.{}.{}.miss\n",
143+
dartFn->PayloadAddress(),
144+
lib_prefix, cls_prefix, name);
145+
of << std::format("'@{:#x}'f method.{}.{}.{}.check\n",
146+
dartFn->MonomorphicAddress(),
147+
lib_prefix, cls_prefix, name);
155148
}
156149
}
157150
show_class = true;
@@ -162,26 +155,19 @@ void DartDumper::Dump4Radare2(std::filesystem::path outDir)
162155
auto stub = item.second;
163156
const auto ep = stub->Address();
164157
std::string name = stub->FullName();
165-
std::replace(name.begin(), name.end(), '<', '_');
166-
std::replace(name.begin(), name.end(), '>', '_');
167-
std::replace(name.begin(), name.end(), ',', '_');
168-
std::replace(name.begin(), name.end(), ' ', '_');
169-
std::replace(name.begin(), name.end(), '$', '_');
170-
std::replace(name.begin(), name.end(), '&', '_');
171-
std::replace(name.begin(), name.end(), '-', '_');
172-
std::replace(name.begin(), name.end(), '+', '_');
173-
std::replace(name.begin(), name.end(), '?', '_');
174-
of << std::format("f method.stub.{}_{:x}={:#x}\n", name.c_str(), ep, ep);
158+
std::string flagName = name;
159+
filterString(flagName);
160+
of << std::format("'@{:#x}'f method.stub.{}\n", ep, flagName);
175161
}
176-
177-
of << "f pptr=x27\n"; // TODO: hardcoded value
162+
of << "dr x27=`e anal.gp`\n";
163+
of << "'f PP=x27\n";
178164
auto comments = DumpStructHeaderFile((outDir / "r2_dart_struct.h").string());
179165
for (const auto& [offset, comment] : comments) {
180166
if (comment.find("String:") != -1) {
181167
std::string flagFromComment = comment;
182168
filterString(flagFromComment);
183-
of << "f pp." << flagFromComment << "=pptr+" << offset << "\n";
184-
of << "'@0x0+" << offset << "'CC " << comment << "\n";
169+
of << "f pp." << flagFromComment << "=PP+" << offset << "\n";
170+
of << "'@PP+" << offset << "'CC " << comment << "\n";
185171
}
186172
}
187173
}

0 commit comments

Comments
 (0)