Skip to content

Commit

Permalink
Add support for ASLR on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
cvuchener committed Sep 9, 2023
1 parent 5e0873c commit 30596f1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/dfinstancelinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ THE SOFTWARE.
#include <sys/uio.h>
#include <elf.h>

#define DEFAULT_BASE_ADDR 0x555555554000ull

DFInstanceLinux::DFInstanceLinux(QObject* parent)
: DFInstance(parent)
{
Expand Down Expand Up @@ -231,6 +233,33 @@ void DFInstanceLinux::find_running_copy() {
return;
}

auto exe_path = QFileInfo(QString::fromStdString(proc_path) + "/exe").symLinkTarget();
std::regex procmaps_re(
"([0-9a-f]+)-([0-9a-f]+)" // address
" ([-r][-w][-x][sp])" // perms
" ([0-9a-f]+)" // offset
" ([0-9a-f]+):([0-9a-f]+)" // dev
" ([0-9]+)" // inode
"(?:\\s*(.+))"); // pathname
if (auto maps = std::ifstream(proc_path + "/maps")) {
std::string line;
while (std::getline(maps, line)) {
std::smatch res;
if (!std::regex_search(line, res, procmaps_re))
continue;
auto start_address = std::stoull(res[1], nullptr, 16);
auto offset = std::stoull(res[4], nullptr, 16);
auto pathname = QString::fromStdString(res[8]);
if (pathname == exe_path && offset == 0) {
m_base_addr = start_address - DEFAULT_BASE_ADDR;
break;
}
}
}
else {
LOGE << "Failed to open memory maps";
}

m_status = DFS_CONNECTED;
set_memory_layout(md5);
}
Expand Down

0 comments on commit 30596f1

Please sign in to comment.