Skip to content

Commit

Permalink
namespace refactor fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
YungRaj committed Dec 17, 2024
1 parent 502ae76 commit caf8aa9
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 24 deletions.
48 changes: 47 additions & 1 deletion arm64/breakpoint_arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,50 @@ _pop_registers_arm64:
ldp x0, x1, [sp, 0x100]
add sp, sp, 0x110
_pop_registers_arm64_end:
nop
nop
_start_coverage:
.rept 10000
sub sp, sp, 0x110
stp x0, x1, [sp, 0x100]
stp x2, x3, [sp, 0xF0]
stp x4, x5, [sp, 0xE0]
stp x6, x7, [sp, 0xD0]
stp x8, x9, [sp, 0xC0]
stp x10, x11, [sp, 0xB0]
stp x12, x13, [sp, 0xA0]
stp x14, x15, [sp, 0x90]
stp x16, x17, [sp, 0x80]
stp x18, x19, [sp, 0x70]
stp x20, x21, [sp, 0x60]
stp x22, x23, [sp, 0x50]
stp x24, x25, [sp, 0x40]
stp x26, x27, [sp, 0x30]
stp x28, x29, [sp, 0x20]
stp x30, x31, [sp, 0x10]
nop
nop
nop
cmp x0, 1
b.ne 0x4
nop
brk #0
nop
ldp x30, x31, [sp, 0x10]
ldp x28, x29, [sp, 0x20]
ldp x26, x27, [sp, 0x30]
ldp x24, x25, [sp, 0x40]
ldp x22, x23, [sp, 0x50]
ldp x20, x21, [sp, 0x60]
ldp x18, x19, [sp, 0x70]
ldp x16, x17, [sp, 0x80]
ldp x14, x15, [sp, 0x90]
ldp x12, x13, [sp, 0xA0]
ldp x10, x11, [sp, 0xB0]
ldp x8, x9, [sp, 0xC0]
ldp x6, x7, [sp, 0xD0]
ldp x4, x5, [sp, 0xE0]
ldp x2, x3, [sp, 0xF0]
ldp x0, x1, [sp, 0x100]
add sp, sp, 0x110
nop
.endr
2 changes: 2 additions & 0 deletions darwinkit/basic_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class BasicBlock {

explicit BasicBlock() {}

~BasicBlock() = default;

Bin* GetBinary() { return bin; }

InstructionList& GetInstructions() { return instructions; }
Expand Down
2 changes: 1 addition & 1 deletion darwinkit/disassembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ xnu::mach::VmAddress Disassembler::DisassembleSignature(xnu::mach::VmAddress add
}

return 0;
}
}
5 changes: 4 additions & 1 deletion darwinkit/hook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@

#include "arch.h"

using namespace darwin;
using namespace xnu;

namespace darwin {

static constexpr UInt64 kBaseKernelAddress = 0xfffffe0000000000;

Hook::Hook(Patcher* patcher, enum HookType hooktype)
Expand Down Expand Up @@ -413,3 +414,5 @@ void Hook::AddBreakpoint(xnu::mach::VmAddress breakpoint_hook, enum HookType hoo
void Hook::RemoveBreakpoint() {

}

}
3 changes: 3 additions & 0 deletions darwinkit/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ template <typename T = struct HookPatch*>
using HookArray = std::vector<T>;

namespace darwin {

void InstrumentTrampoline();

class Hook {
public:
explicit Hook(darwin::Patcher* patcher, enum HookType hooktype);
Expand Down
7 changes: 5 additions & 2 deletions darwinkit/patcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

#include "hook.h"

using namespace darwin;
namespace darwin {

void Patcher::FindAndReplace(void* data, Size data_size, const void* find, Size find_size,
const void* replace, Size replace_size) {}

void Patcher::OnKextLoad(void* kext, kmod_info_t* kmod) {}
void Patcher::OnKextLoad(void* kext, kmod_info_t* kmod) {
}

void Patcher::RouteFunction(Hook* hook) {
hooks.push_back(hook);
Expand Down Expand Up @@ -111,4 +112,6 @@ void Patcher::RemoveHook(Hook* hook) {
hooks.erase(std::remove(hooks.begin(), hooks.end(), hook), hooks.end());

delete hook;
}

}
8 changes: 5 additions & 3 deletions kernel/device_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#include "log.h"

using namespace xnu;

Bool is_ascii(char* c, Size len) {
UInt32 zeros = 0;

Expand All @@ -39,6 +37,8 @@ Bool is_ascii(char* c, Size len) {
return zeros < 3 ? true : false;
}

namespace xnu {

Bool DeviceTree::IterateNodeProperties(void** data, void* data_end, UInt32* depth,
DeviceTreeNode* node, dt_property_callback_t prop_cb,
Bool* success) {
Expand Down Expand Up @@ -375,7 +375,7 @@ T DeviceTree::Dump() {
return reinterpret_cast<T>(device_tree);
}

PE_state_t* xnu::PlatformExpertState(xnu::Kernel* kernel) {
PE_state_t* PlatformExpertState(xnu::Kernel* kernel) {
uintptr_t device_tree;

UInt64 deviceTreeHead;
Expand Down Expand Up @@ -411,4 +411,6 @@ PE_state_t* xnu::PlatformExpertState(xnu::Kernel* kernel) {
return reinterpret_cast<PE_state_t*>(PE_state);
}

}

#endif
2 changes: 1 addition & 1 deletion kernel/kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1482,4 +1482,4 @@ xnu::mach::VmAddress Kernel::GetSymbolAddressByName(char* symbolname) {
return symbolAddress;
}

}
} // namespace xnu
7 changes: 5 additions & 2 deletions kernel/kernel_patcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ using namespace arch::x86_64::patchfinder;
#endif

using namespace arch;
using namespace darwin;

namespace darwin {

static KernelPatcher* that = nullptr;

Expand Down Expand Up @@ -884,4 +885,6 @@ void KernelPatcher::RemoveKextPatch(struct KextPatch* patch) {
}

kextPatches.push_back(patch);
}
}

} // namespace darwin
4 changes: 3 additions & 1 deletion kernel/kext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "macho.h"

using namespace xnu;
namespace xnu {

Kext::Kext(Kernel* kernel, xnu::mach::VmAddress base, char* identifier)
: kernel(kernel), address(base), identifier(identifier) {
Expand Down Expand Up @@ -84,3 +84,5 @@ Kext* Kext::FindKextWithId(Kernel* kernel, UInt32 kext_id) {
void Kext::OnKextLoad(void* kext, xnu::KmodInfo* kmod_info) {
return;
}

} // namespace xnu
12 changes: 9 additions & 3 deletions kernel/plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@

#include "plugin.h"

using namespace darwin;
namespace darwin {

Plugin::Plugin(IOService* service, char* product, Size version, UInt32 runmode,
const char** disableArg, Size disableArgNum, const char** debugArg, Size debugArgNum,
const char** betaArg, Size betaArgNum)
: service(service), product(product), version(version), runmode(runmode),
disableArg(disableArg), disableArgNum(disableArgNum), debugArg(debugArg),
debugArgNum(debugArgNum), betaArg(betaArg), betaArgNum(betaArgNum) {}
debugArgNum(debugArgNum), betaArg(betaArg), betaArgNum(betaArgNum) {

}

Plugin::Plugin(char* product, Size version, UInt32 runmode, const char** disableArg,
Size disableArgNum, const char** debugArg, Size debugArgNum, const char** betaArg,
Size betaArgNum)
: service(nullptr), product(product), version(version), runmode(runmode), disableArg(disableArg),
disableArgNum(disableArgNum), debugArg(debugArg), debugArgNum(debugArgNum), betaArg(betaArg),
betaArgNum(betaArgNum) {}
betaArgNum(betaArgNum) {

}

} // namespace darwin
4 changes: 3 additions & 1 deletion user/loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

namespace fuzzer {

void Module::Load() {}
void Module::Load() {

}

/*
template<typename Sym>
Expand Down
4 changes: 3 additions & 1 deletion user/macho_userspace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "dyld.h"
#include "task.h"

using namespace darwin;
namespace darwin {

MachOUserspace::MachOUserspace(const char* path) : objc(nullptr), file_path(strdup(path)) {
WithFilePath(path);
Expand Down Expand Up @@ -843,3 +843,5 @@ void MachOUserspace::ParseHeader() {
void MachOUserspace::ParseMachO() {
ParseHeader();
}

} // namespace darwin
7 changes: 5 additions & 2 deletions user/task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "dyld.h"
#include "task.h"

using namespace xnu;
namespace xnu {

static int EndsWith(const char* str, const char* suffix) {
if (!str || !suffix)
Expand Down Expand Up @@ -552,4 +552,7 @@ xnu::mach::VmAddress Task::GetImageLoadedAt(char* image_name, char** image_path)
return image;
}

void Task::PrintLoadedImages() {}
void Task::PrintLoadedImages() {
}

} // namespace xnu
12 changes: 8 additions & 4 deletions user/user_patcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
#include "payload.h"

void UserPatcher::FindAndReplace(void* data, Size dataSize, const void* find, Size findSize,
const void* replace, Size replaceSize) {}
const void* replace, Size replaceSize) {
}

void UserPatcher::RouteFunction(Hook* hook) {}
void UserPatcher::RouteFunction(Hook* hook) {
}

void UserPatcher::OnKextLoad(void* kext, kmod_info_t* kmod) {}
void UserPatcher::OnKextLoad(void* kext, kmod_info_t* kmod) {
}

void UserPatcher::OnExec(char* name, int pid, xnu::mach::Port port, xnu::mach::VmAddress task,
xnu::mach::VmAddress proc) {}
xnu::mach::VmAddress proc) {
}

xnu::mach::VmAddress UserPatcher::InjectPayload(xnu::mach::VmAddress address, Payload* payload) {
return 0;
Expand Down
46 changes: 45 additions & 1 deletion x86_64/breakpoint_x86_64.s
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,48 @@ _pop_registers_x86_64:
pop rbp
pop rsp
_pop_registers_x86_64_end:
nop
nop
_start_coverage:
.rept 10000
push rsp
push rbp
push rax
push rbx
push rcx
push rdx
push rdi
push rsi
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
nop
lea rdi, [rsp + 0x80]
nop
cmp rax, 1
jne short $+4h
nop
int3
nop
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rsi
pop rdi
pop rdx
pop rcx
pop rbx
pop rax
pop rbp
pop rsp
nop
.endr

0 comments on commit caf8aa9

Please sign in to comment.