Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions include/libkdb/bit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
#include <cstring>

namespace kdb {
template <typename T> T from_bytes(std::byte *bytes) {
T res;
std::memcpy(&res, bytes, sizeof(T));
return res;
}

template <typename T> std::byte *as_bytes(T &t) {
return std::static_cast<void *>(static_cast<std::byte *>(t));
}

template <typename T> const std::byte *as_bytes(const T &t) {
return std::static_cast<void *>(std::static_cast<const std::byte *>(t));
}

template <typename T> byte128 to_byte128(T src) {
byte128 res{};
std::memcpy(&res, src, sizeof(T));
return res;
}

template <typename T> byte64 to_byte64(T src) {
byte64 res{};
std::memcpy(&res, src, sizeof(T));
return res;
}

} // namespace kdb
1 change: 0 additions & 1 deletion include/libkdb/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace kdb {
[[noexcept]] static void send_error_no(const std::string &prefix) {
throw std::runtime_error(prefix + ": " + std::strerror(errno));
}

};

} // namespace kdb
23 changes: 13 additions & 10 deletions include/libkdb/ksyscall.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#include<iostream>
#include<syscall.h>
#include "ksyscall.hpp"
#include <cstring>
#include <iostream>
#include <stdexcept>
#include <string>
#include "ksyscall.cpp"

namespace kdb {

namespace kdb{




}//namespace kdb
void ktrace(ptrace_args &args) {
#ifdef __linux__
args.result = ptrace(args.req, args.pid, args.args.addr, args.data);

#elif defined(__APPLE__)
args.result = ptrace(args.req, args.pid, args.addr, args.data);
#endif
}

} // namespace kdb
69 changes: 34 additions & 35 deletions include/libkdb/ksyscall.hpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
#pragma once
#include <sys/ptrace.h>

/*
* This library creates an abstraction for the syscalls.
* Usage should be simple, just call the abstracted syscall and it will figure
* out based on OS which one to call.
*/
namespace kdb {
/*
* This library creates an abstraction for the syscalls.
* Usage should be simple, just call the abstracted syscall and it will figure
* out based on OS which one to call.
*/

#ifdef __linux__
/*
* long ptrace(enum __ptrace_request op, pid_t pid,
void *addr, void *data);
*/
struct ptrace_args {
enum __ptrace__req;
pid_t pid;
void *addr;
void *data;
long result;
};
/*
* long ptrace(enum __ptrace_request op, pid_t pid,
void *addr, void *data);
*/
struct ptrace_args {
enum __ptrace__req;
pid_t pid;
void *addr;
void *data;
long result;
};

#elif defined(__APPLE__)
/*
*int
ptrace(int request, pid_t pid, caddr_t addr, int data);
*/
struct ptrace_args {
int req;
pid_t pid;
caddr_t addr;
int data;
int result;
};
/*
*int
ptrace(int request, pid_t pid, caddr_t addr, int data);
*/
struct ptrace_args {
int req;
pid_t pid;
caddr_t addr;
int data;
int result;
};
#endif

void ktrace(ptrace_args &args) {
#ifdef __linux__
args.result = ptrace(args.req, args.pid, args.args.addr, args.data);

#elif defined(__APPLE__)
args.result = ptrace(args.req, args.pid, args.addr, args.data);
#endif
}
struct pip_args {
inn

}

void
ptrace(ptrace_args &args);
} // namespace kdb
12 changes: 6 additions & 6 deletions include/libkdb/libkdb.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef KDB_LIBKDB_HPP
#ifndef KDB_LIBKDB_HPP
#define KDB_LIBKDB_HPP

namespace kdb{
void say_hello();
}// namespace kdb
namespace kdb {

void say_hello();

} // namespace kdb

#endif
3 changes: 1 addition & 2 deletions include/libkdb/pipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ namespace kdb {
int release_write();
void close_read();
void close_write();

std::vector<std::byte> read();
void write(std::byte *from, std::size_t bytes);

};

} // namespace kdb
6 changes: 4 additions & 2 deletions include/libkdb/process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ namespace kdb {
process_state state_ = process_state::stopped;
bool is_attached = true;
process(pid_t pid, bool terminate_on_end, bool is_attached)
: pid_(pid), terminate_on_end(terminate_on_end), is_attached(is_attached) {}
: pid_(pid), terminate_on_end(terminate_on_end),
is_attached(is_attached) {}

public:
process() = delete;
process(const process &) = delete;
process &operator=(const process &) = delete;

~process();
static std::unique_ptr<process> launch(std::filesystem::path path, bool debug = true);
static std::unique_ptr<process> launch(std::filesystem::path path,
bool debug = true);
static std::unique_ptr<process> attach(pid_t pid);

pid_t pid() const { return pid_; }
Expand Down
Loading
Loading