Skip to content

Commit

Permalink
code cleanup & revert
Browse files Browse the repository at this point in the history
- by @truefae worawit#104
- revert base & heap_base comment
- needs latest r2 from git
  • Loading branch information
AbhiTheModder committed Sep 21, 2024
1 parent 8990db3 commit ed2dc7d
Showing 1 changed file with 29 additions and 44 deletions.
73 changes: 29 additions & 44 deletions blutter/src/DartDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,51 +132,45 @@ void DartDumper::Dump4Radare2(std::filesystem::path outDir)
std::filesystem::create_directory(outDir);
std::ofstream of((outDir / "addNames.r2").string());
of << "# create flags for libraries, classes and methods\n";

// app base & heap base address values changes on every run i.e, setting flag names for them is of no use

// of << fmt::format("f app.base = {:#x}\n", app.base());
// of << fmt::format("f app.heap_base = {:#x}\n", app.heap_base());
of << "e emu.str=true\n";
// app base & heap base address values changes on every run i.e, setting flag names for them is of no use
// but since right now r2 bases it to address 0 let's leave it as it is
// https://github.com/worawit/blutter/pull/104#discussion_r1769637361
of << fmt::format("f app.base = {:#x}\n", app.base());
of << fmt::format("f app.heap_base = {:#x}\n", app.heap_base());

bool show_library = true;
bool show_class = true;
for (auto lib : app.libs) {
std::string lib_prefix = lib->GetName();

std::replace(lib_prefix.begin(), lib_prefix.end(), '$', '_');
std::replace(lib_prefix.begin(), lib_prefix.end(), '&', '_');
std::replace(lib_prefix.begin(), lib_prefix.end(), '-', '_');
std::replace(lib_prefix.begin(), lib_prefix.end(), '+', '_');
filterString(lib_prefix);
for (auto cls : lib->classes) {
std::string cls_prefix = cls->Name();
std::replace(cls_prefix.begin(), cls_prefix.end(), '$', '_');
std::replace(cls_prefix.begin(), cls_prefix.end(), '&', '_');
std::replace(cls_prefix.begin(), cls_prefix.end(), '-', '_');
std::replace(cls_prefix.begin(), cls_prefix.end(), '+', '_');
filterString(cls_prefix);
for (auto dartFn : cls->Functions()) {
const auto ep = dartFn->Address();
auto name = getFunctionName4Ida(*dartFn, cls_prefix);
std::replace(name.begin(), name.end(), '$', '_');
std::replace(name.begin(), name.end(), '&', '_');
std::replace(name.begin(), name.end(), '-', '_');
std::replace(name.begin(), name.end(), '+', '_');
std::replace(name.begin(), name.end(), '?', '_');
std::string name = getFunctionName4Ida(*dartFn, cls_prefix);
filterString(name);
if (show_library) {
of << fmt::format("CC Library({:#x}) = {} @ {}\n", lib->id, lib_prefix, ep);
of << fmt::format("f lib.{}={:#x} # {:#x}\n", lib_prefix, ep, lib->id);
of << fmt::format("'@{:#x}'CC Library({:#x}) = {}\n", ep, lib->id, lib->GetName());
of << fmt::format("'@{:#x}'f lib.{}\n", ep, lib_prefix);
show_library = false;
}
if (show_class) {
of << fmt::format("CC Class({:#x}) = {} @ {}\n", cls->Id(), cls_prefix, ep);
of << fmt::format("f class.{}.{}={:#x} # {:#x}\n", lib_prefix, cls_prefix, ep, cls->Id());
of << fmt::format("'@{:#x}'CC Class({:#x}) = {}\n", ep, cls->Id(), cls->Name());
of << fmt::format("'@{:#x}'f class.{}.{}\n", ep, lib_prefix, cls_prefix);
show_class = false;
}
of << fmt::format("f method.{}.{}.{}_{:x}={:#x}\n", lib_prefix, cls_prefix, name.c_str(), ep, ep);
of << fmt::format("'@{:#x}'f method.{}.{}.{}\n", ep, lib_prefix, cls_prefix, name);
of << fmt::format("'@{:#x}'ic+{}.{}\n", ep, cls_prefix, name);
if (dartFn->HasMorphicCode()) {
of << fmt::format("f method.{}.{}.{}.miss={:#x}\n", lib_prefix, cls_prefix, name.c_str(),
dartFn->PayloadAddress());
of << fmt::format("f method.{}.{}.{}.check={:#x}\n", lib_prefix, cls_prefix, name.c_str(),
dartFn->MonomorphicAddress());
of << fmt::format("'@{:#x}'f method.{}.{}.{}.miss\n",
dartFn->PayloadAddress(),
lib_prefix, cls_prefix, name);
of << fmt::format("'@{:#x}'f method.{}.{}.{}.check\n",
dartFn->MonomorphicAddress(),
lib_prefix, cls_prefix, name);
}
}
show_class = true;
Expand All @@ -187,28 +181,19 @@ void DartDumper::Dump4Radare2(std::filesystem::path outDir)
auto stub = item.second;
const auto ep = stub->Address();
std::string name = stub->FullName();
std::replace(name.begin(), name.end(), '<', '_');
std::replace(name.begin(), name.end(), '>', '_');
std::replace(name.begin(), name.end(), ',', '_');
std::replace(name.begin(), name.end(), ' ', '_');
std::replace(name.begin(), name.end(), '$', '_');
std::replace(name.begin(), name.end(), '&', '_');
std::replace(name.begin(), name.end(), '-', '_');
std::replace(name.begin(), name.end(), '+', '_');
std::replace(name.begin(), name.end(), '?', '_');
std::replace(name.begin(), name.end(), '(', '_'); // https://github.com/AbhiTheModder/blutter-termux/issues/6
std::replace(name.begin(), name.end(), ')', '_');
of << fmt::format("f method.stub.{}_{:x}={:#x}\n", name.c_str(), ep, ep);
std::string flagName = name;
filterString(flagName);
of << fmt::format("'@{:#x}'f method.stub.{}\n", ep, flagName);
}

of << "f pptr=x27\n"; // TODO: hardcoded value
of << "dr x27=`e anal.gp`\n";
of << "'f PP=x27\n";
auto comments = DumpStructHeaderFile((outDir / "r2_dart_struct.h").string());
for (const auto& [offset, comment] : comments) {
if (comment.find("String:") != -1) {
std::string flagFromComment = comment;
filterString(flagFromComment);
of << "f pp." << flagFromComment << "=pptr+" << offset << "\n";
of << "'@0x0+" << offset << "'CC " << comment << "\n";
of << "f pp." << flagFromComment << "=PP+" << offset << "\n";
of << "'@PP+" << offset << "'CC " << comment << "\n";
}
}
}
Expand Down

0 comments on commit ed2dc7d

Please sign in to comment.