Skip to content

Commit

Permalink
formatte
Browse files Browse the repository at this point in the history
  • Loading branch information
rxOred committed Dec 26, 2022
1 parent fe79757 commit 38995d4
Show file tree
Hide file tree
Showing 20 changed files with 183 additions and 173 deletions.
16 changes: 9 additions & 7 deletions include/zkelf.hh
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ public:

[[nodiscard]] void *get_memory_map() const;
[[nodiscard]] std::size_t get_map_size() const;
[[nodiscard]] std::variant<const char *, pid_t> get_elf_source(
) const;
[[nodiscard]] std::variant<const char *, pid_t> get_elf_source() const;

[[nodiscard]] ehdr_t<T> *get_elf_header() const;
[[nodiscard]] phdr_t<T> *get_program_header_table() const;
Expand Down Expand Up @@ -521,9 +520,10 @@ enum class elf_options : zktypes::u8_t {
// ElfObj by default
class ZkElf {
public:
ZkElf(std::variant<ElfObj<x64>, ElfObj<x86>> obj,
std::variant<elf_read_only, elf_read_write> options = elf_read_only{},
std::optional<zklog::ZkLog *> log = std::nullopt);
ZkElf(std::variant<ElfObj<x64>, ElfObj<x86>> obj,
std::variant<elf_read_only, elf_read_write> options =
elf_read_only{},
std::optional<zklog::ZkLog *> log = std::nullopt);
ZkElf(const ZkElf &) = delete;
ZkElf(ZkElf &&) = delete;

Expand Down Expand Up @@ -855,7 +855,7 @@ public:
friend std::shared_ptr<ZkElf> load_elf_writable_from_file(
const char *path, std::optional<elf_save_options> save_options,
std::optional<zklog::ZkLog *> log);

friend void load_elf_from_memory();

private:
Expand All @@ -868,7 +868,9 @@ std::shared_ptr<ZkElf> load_elf_from_file(
const char *path, std::optional<zklog::ZkLog *> log = std::nullopt);

std::shared_ptr<ZkElf> load_elf_writable_from_file(
const char *path, std::optional<elf_save_options> save_options = elf_save_options::ELF_AUTO_SAVE,
const char *path,
std::optional<elf_save_options> save_options =
elf_save_options::ELF_AUTO_SAVE,
std::optional<zklog::ZkLog *> log = std::nullopt);

void load_elf_from_memory();
Expand Down
2 changes: 1 addition & 1 deletion include/zkhooks.hh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef ZKHOOKS_HH
#define ZKHOOKS_HH

#endif // ZKHOOKS_HH
#endif // ZKHOOKS_HH
6 changes: 2 additions & 4 deletions include/zklog.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public:

inline std::string get_log_message(void) { return l_string; }
inline log_level get_log_level(void) { return l_level; }
inline log_error_code get_log_error_code(void) {
return l_error_code;
}
inline log_error_code get_log_error_code(void) { return l_error_code; }

private:
std::string l_string;
Expand All @@ -56,7 +54,7 @@ public:
void push_log(std::string log_string, log_level level,
std::optional<log_error_code> error_code =
log_error_code::LOG_ERROR_NONE);
std::tuple<std::string, log_level, log_error_code> pop_log(void);
std::tuple<std::string, log_level, log_error_code> pop_log(void);
log_level peek_log_level(void);

private:
Expand Down
22 changes: 11 additions & 11 deletions include/zkmemorymap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public:
page_t(typename T::addr_t saddr, typename T::addr_t eaddr,
std::string permissions,
std::optional<std::string> name = std::nullopt)
:page_saddr(saddr),
page_eaddr(eaddr),
page_permissions(std::move(permissions)),
page_name(std::move(name)) {}
: page_saddr(saddr),
page_eaddr(eaddr),
page_permissions(std::move(permissions)),
page_name(std::move(name)) {}

page_t(const page_t&) = default;
page_t(page_t&&) noexcept = default;
page_t(page_t&&) noexcept = default;

inline typename T::addr_t get_page_start_address() const {
return page_saddr;
Expand All @@ -39,8 +39,8 @@ public:
return page_permissions;
}
[[nodiscard]] inline std::string get_page_name() const {
return page_name.value_or("");
}
return page_name.value_or("");
}

private:
typename T::addr_t page_saddr;
Expand All @@ -54,7 +54,7 @@ class MemoryMap {
public:
explicit MemoryMap(pid_t pid);
void parse_memory_map();
std::vector<page_t<T>> get_memory_map() const;
std::vector<page_t<T>> get_memory_map() const;
std::optional<typename T::addr_t> get_module_start_address(
const char* module_name) const;
std::optional<typename T::addr_t> get_module_end_address(
Expand All @@ -70,8 +70,8 @@ public:
inline const page_t<T>& get_end_page() const {
return *mm_pageinfo.end();
}
inline typename std::vector<page_t<T>>::const_iterator get_iterator_begin(
) const {
inline typename std::vector<page_t<T>>::const_iterator
get_iterator_begin() const {
return mm_pageinfo.begin();
}

Expand Down
17 changes: 10 additions & 7 deletions include/zkptrace.hh
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,19 @@ public:
~Ptrace();

explicit Ptrace(char *const *path,
std::optional<zktypes::u8_t> flags = PTRACE_START_NOW |
PTRACE_DISABLE_ASLR,
std::optional<zklog::ZkLog *> log = std::nullopt);
std::optional<zktypes::u8_t> flags =
PTRACE_START_NOW | PTRACE_DISABLE_ASLR,
std::optional<zklog::ZkLog *> log = std::nullopt);
explicit Ptrace(pid_t pid,
std::optional<zktypes::u8_t> flags = PTRACE_ATTACH_NOW,
std::optional<zklog::ZkLog *> log = std::nullopt);
std::optional<zktypes::u8_t> flags = PTRACE_ATTACH_NOW,
std::optional<zklog::ZkLog *> log = std::nullopt);

[[nodiscard]] inline pid_t get_pid() const { return p_pid; }
[[nodiscard]] inline PROCESS_STATE get_process_state() const { return p_state; }
[[nodiscard]] inline PROCESS_STATE_INFO get_process_state_info() const {
[[nodiscard]] inline PROCESS_STATE get_process_state() const {
return p_state;
}
[[nodiscard]] inline PROCESS_STATE_INFO get_process_state_info()
const {
return p_state_info;
}

Expand Down
52 changes: 25 additions & 27 deletions include/zksignal.hh
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
#ifndef ZKSIG_HH
#define ZKSIG_HH

#include "zktypes.hh"
#include <signal.h>
#include <sys/types.h>

#include "zktypes.hh"

namespace ZkProcess {
class Signal {
public:
Signal(pid_t pid);
Signal(const Signal&) =default;
Signal(Signal&&) =default;
class Signal {
public:
Signal(pid_t pid);
Signal(const Signal&) = default;
Signal(Signal&&) = default;

bool SignalProcess(int signal) const;
inline bool SignalStopProcess(void) const {
return SignalProcess(SIGSTOP);
}
inline bool SignalKillProcess(void) const {
return SignalProcess(SIGKILL);
}
inline bool SignalContinueProcess(void) const {
return SignalProcess(SIGCONT);
}
inline bool SignalTrapProcess(void) const {
return SignalProcess(SIGTRAP);
}

bool SignalProcess(int signal) const;
inline bool SignalStopProcess(void) const
{
return SignalProcess(SIGSTOP);
}
inline bool SignalKillProcess(void) const
{
return SignalProcess(SIGKILL);
}
inline bool SignalContinueProcess(void) const
{
return SignalProcess(SIGCONT);
}
inline bool SignalTrapProcess(void) const
{
return SignalProcess(SIGTRAP);
}
private:
pid_t s_pid;
};
private:
pid_t s_pid;
};
}; // namespace ZkProcess

#endif // ZKSIG_HH
#endif // ZKSIG_HH
6 changes: 3 additions & 3 deletions include/zksnapshot.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public:
snapshot_t(zktypes::u8_t flags, registers_t *regs, void *stack,
void *instr);
snapshot_t(const snapshot_t &) = default;
snapshot_t(snapshot_t &&) = default;
snapshot_t(snapshot_t &&) = default;

~snapshot_t();

Expand All @@ -51,8 +51,8 @@ public:
std::optional<zktypes::u8_t> count = DEFAULT_SNAPSHOT_COUNT,
std::optional<zklog::ZkLog *> log = std::nullopt);
Snapshot(const Snapshot &) = default;
Snapshot(Snapshot &&) = default;
Snapshot(Snapshot &&) = default;

~Snapshot() = default;
bool save_snapshot(zktypes::u8_t flags);
bool restore_snapshot(void);
Expand Down
4 changes: 2 additions & 2 deletions include/zktypes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct x64 : public zktypes {
using off_t = std::uint64_t;
};

using eventcodes_t = __ptrace_eventcodes;
using eventcodes_t = __ptrace_eventcodes;
// TODO make this independant
using registers_t = struct user_regs_struct;
using registers_t = struct user_regs_struct;

#endif // ZKTYPES_HH
26 changes: 13 additions & 13 deletions include/zkutils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@

namespace zkutils {

std::pair<void *, std::size_t> open_file(const char *path, bool should_writable = false);
std::pair<void *, std::size_t> open_file(const char *path,
bool should_writable = false);

template <typename T, int size>
bool validate_magic_number(T a[size], T b[size])
{
for (int i = 0; i < size; ++i) {
if (a[i] != b[i]) {
return false;
}
}
return true;
bool validate_magic_number(T a[size], T b[size]) {
for (int i = 0; i < size; ++i) {
if (a[i] != b[i]) {
return false;
}
}
return true;
}

inline void save_memory_map(const char *path, void *memory_map,
Expand All @@ -48,8 +48,8 @@ inline void save_memory_map(const char *path, void *memory_map,
}
}

inline void save_buffer_to_file(const char *path, off_t offset, void *buffer,
int buffer_size) noexcept {
inline void save_buffer_to_file(const char *path, off_t offset,
void *buffer, int buffer_size) noexcept {
int fd = open(path, O_CREAT | O_WRONLY, 0666);
if (fd < 0) {
throw zkexcept::file_not_found_error();
Expand All @@ -63,8 +63,8 @@ inline void save_buffer_to_file(const char *path, off_t offset, void *buffer,
}

template <typename T = x64>
int patch_address(typename T::u8_t *buffer, size_t len, typename T::addr_t addr,
typename T::u8_t *magic) {
int patch_address(typename T::u8_t *buffer, size_t len,
typename T::addr_t addr, typename T::u8_t *magic) {
int count = 0;
for (int i = 0; i < len; i++) {
printf("%x\n", buffer[i]);
Expand Down
Loading

0 comments on commit 38995d4

Please sign in to comment.