Skip to content

Commit

Permalink
Add an option for only checking the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Toasterbirb committed Aug 20, 2024
1 parent 58aaa87 commit e3f0606
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/Memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace harava
class memory
{
public:
memory(const i32 pid);
memory(const i32 pid, const options opts);

__attribute__((warn_unused_result))
std::vector<result> search(const options opts, const filter filter, const type_bundle value, const comparison comparison);
Expand Down
1 change: 1 addition & 0 deletions include/Options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ namespace harava
bool skip_volatile = false;
bool skip_zeroes = false;
bool skip_null_regions = false;
bool stack_scan = false;
};
}
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ int main(int argc, char** argv)
(clipp::option("--memory", "-m") & clipp::number("GB").set(opts.memory_limit)) % "set the maximum memory usage in gigabytes",
clipp::option("--skip-volatile").set(opts.skip_volatile) % "during the initial search scan each region twice and skip values that change between the two scans",
clipp::option("--skip-zeroes").set(opts.skip_zeroes) % "skip zeroes during the initial search to lower the memory usage (only really works for comparison searches)",
clipp::option("--skip-null-regions").set(opts.skip_null_regions) % "skip memory regions that are full of zeroes during the initial search"
clipp::option("--skip-null-regions").set(opts.skip_null_regions) % "skip memory regions that are full of zeroes during the initial search",
clipp::option("--stack").set(opts.stack_scan) % "only scan the stack of the process"
);

if (!clipp::parse(argc, argv, cli))
Expand Down
5 changes: 4 additions & 1 deletion src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace harava
return match;
}

memory::memory(const i32 pid)
memory::memory(const i32 pid, const options opts)
:pid(pid), proc_path("/proc/" + std::to_string(pid)), mem_path(proc_path + "/mem")
{
// Find suitable memory regions
Expand All @@ -132,6 +132,9 @@ namespace harava
ss << line;
ss >> range >> perms >> offset >> ids >> inode_id >> file_path;

if (opts.stack_scan && file_path != "[stack]")
continue;

// Skip memory regions that are not writable
if (!perms.starts_with("rw"))
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace harava

void run_shell(const options opts)
{
std::unique_ptr<harava::memory> process_memory = std::make_unique<harava::memory>(opts.pid);
std::unique_ptr<harava::memory> process_memory = std::make_unique<harava::memory>(opts.pid, opts);

harava::filter filter;

Expand Down Expand Up @@ -470,7 +470,7 @@ namespace harava
first_search = true;

process_memory.reset();
process_memory = std::make_unique<harava::memory>(opts.pid);
process_memory = std::make_unique<harava::memory>(opts.pid, opts);
}
}
};
Expand Down

0 comments on commit e3f0606

Please sign in to comment.