Skip to content

Commit

Permalink
bazel: Fix issues introduced after migration
Browse files Browse the repository at this point in the history
  • Loading branch information
YungRaj committed Dec 14, 2024
1 parent 02ac860 commit 554740c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 40 deletions.
6 changes: 3 additions & 3 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<key>CFBundleIdentifier</key>
<string>com.YungRaj.DarwinKit</string>
<key>IOClass</key>
<string>IOKernelRootKitService</string>
<string>IOKernelDarwinKitService</string>
<key>IOMatchCategory</key>
<string>IOKernelRootKitService</string>
<string>IOKernelDarwinKitService</string>
<key>IOProviderClass</key>
<string>IOResources</string>
<key>IOUserClientClass</key>
<string>IOKernelRootKitUserClient</string>
<string>IOKernelDarwinKitUserClient</string>
<key>IOResourceMatch</key>
<string>IOBSD</string>
</dict>
Expand Down
11 changes: 3 additions & 8 deletions darwinkit/pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

template <typename T>
static void emptyDeleter(T t) {
/* do nothing here because we don't wanna destroy the T object */
/* we just wanna destroy the Pair */
/* Does nothing here because we don't wanna destroy the T object */
/* We just wanna destroy the Pair */
}

template <typename T, typename Y, void (*deleterT)(T) = emptyDeleter<T>,
Expand All @@ -32,10 +32,7 @@ class Pair {
T first;
Y second;

explicit Pair(T first, Y second) {
first = first;
second = second;
}
Pair(T first, Y second) : first(first), second(second) {}

~Pair() {
deleter(this);
Expand All @@ -48,7 +45,5 @@ class Pair {
static void deleter(Pair<T, Y>* pair) {
deleterT(pair->first);
deleterY(pair->second);

delete pair;
}
};
2 changes: 1 addition & 1 deletion darwinkit/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class vector {
};

public:
explicit vector() : head(nullptr), tail(nullptr), sz(0) {}
vector() : head(nullptr), tail(nullptr), sz(0) {}

~vector() {
clear();
Expand Down
3 changes: 2 additions & 1 deletion fuzzers/target.lldb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# command source -e false ~/path/to/MacRootKit/fuzzers/target.lldb
# command source -e false ~/path/to/DarwinKit/fuzzers/target.lldb

target create -s /Library/Developer/KDKs/KDK_14.4_23E214.kdk/System/Library/Kernels/kernel.release.vmapple.dSYM /Library/Developer/KDKs/KDK_14.4_23E214.kdk/System/Library/Kernels/kernel.release.vmapple

Expand Down Expand Up @@ -1179,6 +1179,7 @@ image add /Library/Developer/KDKs/KDK_14.4_23E214.kdk/System/Library/Extensions/
image add /Library/Developer/KDKs/KDK_14.4_23E214.kdk/System/Library/Extensions/cddafs.kext/Contents/MacOS/cddafs
image add /Library/Developer/KDKs/KDK_14.4_23E214.kdk/System/Library/Extensions/AppleMobileDispT600X-DCP.kext/Contents/MacOS/AppleMobileDispT600X-DCP
image add /Library/Developer/KDKs/KDK_14.4_23E214.kdk/System/Library/Extensions/AppleD1755PMU.kext/Contents/MacOS/AppleD1755PMU
image add /Users/ilhanraja/Downloads/Files/Code/projects/DarwinKit/DarwinKit.kext/Contents/MacOS/DarwinKit

settings set target.process.optimization-warnings false

Expand Down
2 changes: 1 addition & 1 deletion kernel/darwin_kit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void DarwinKit::OnKextLoad(void* loaded_kext, xnu::KmodInfo* kmod_info) {
kext = new xnu::Kext(GetKernel(), loaded_kext, kmod_info);
} else {
kext = new xnu::Kext(GetKernel(), kmod_info->address,
reinterpret_cast<char*>(&kmod_info->name));
reinterpret_cast<char*>(kmod_info->name));
}

kexts.push_back(kext);
Expand Down
4 changes: 2 additions & 2 deletions kernel/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class Kernel : public xnu::Task {

virtual Offset GetSlide();

void SetDarwinKit(darwin::DarwinKit* darwinkit) {
darwinkit = darwinkit;
void SetDarwinKit(darwin::DarwinKit* kit) {
darwinkit = kit;
}

darwin::DarwinKit* GetDarwinKit() {
Expand Down
42 changes: 20 additions & 22 deletions kernel/kernel_patcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ void KernelPatcher::Initialize() {

waitingForAlreadyLoadedKexts = false;

InstallCopyClientEntitlementHook();
// InstallCopyClientEntitlementHook();

#ifdef __x86_64__
// binary load hook does not work on arm64 because symbol to hook does not exist
// The binary load hook does not work on arm64 because symbol to hook does not exist
InstallBinaryLoadHook();

// kext load hook does not work on arm64 because symbol to hook does not exist
// The kext load hook does not work on arm64 because symbol to hook does not exist
InstallKextLoadHook();
#endif

// installDummyBreakpoint();
// InstallDummyBreakpoint();
}

bool KernelPatcher::DummyBreakpoint(union arch::RegisterState* state) {
Expand Down Expand Up @@ -458,13 +458,11 @@ void KernelPatcher::ProcessKext(xnu::KmodInfo* kmod, bool loaded) {

void* OSKext;

StoredArray<DarwinKit::KextLoadCallback>* kextLoadCallbacks;

xnu::mach::VmAddress kmod_address = (xnu::mach::VmAddress)kmod->address;

darwinkit = GetKernel()->GetDarwinKit();

kextLoadCallbacks = &darwinkit->GetKextLoadCallbacks();
StoredArray<DarwinKit::KextLoadCallback> *kextLoadCallbacks = &darwinkit->GetKextLoadCallbacks();

OSKext = KernelPatcher::OSKextLookupKextWithIdentifier(static_cast<char*>(kmod->name));

Expand Down Expand Up @@ -620,7 +618,7 @@ void KernelPatcher::ApplyKernelPatch(struct KernelPatch* patch) {
offset = patch->offset;

if (!symbol) {
// patch everything you can N times;
// Patches everything you can N times;

xnu::mach::VmAddress base = kernel->GetBase();

Expand All @@ -640,13 +638,13 @@ void KernelPatcher::ApplyKernelPatch(struct KernelPatch* patch) {
}

} else {
// patch the function directed by symbol
// Patches the function directed by symbol

xnu::mach::VmAddress address = symbol->GetAddress();

if (find) {
// search up to N bytes from beginning of function
// use patchfinder::findFunctionEnd() to get ending point
// Searches up to N bytes from beginning of function
// Uses patchfinder::findFunctionEnd() to get ending point

xnu::mach::VmAddress current_address = address;

Expand All @@ -658,7 +656,7 @@ void KernelPatcher::ApplyKernelPatch(struct KernelPatch* patch) {
current_address++;
}
} else {
// use offset provided by user to patch bytes in function
// Uses offset provided by user to patch bytes in function

kernel->Write(address + offset, (void*)replace, size);
}
Expand Down Expand Up @@ -694,7 +692,7 @@ void KernelPatcher::ApplyKextPatch(struct KextPatch* patch) {
offset = patch->offset;

if (!symbol) {
// patch everything you can N times;
// Patches everything you can N times;

xnu::mach::VmAddress base = kext->GetBase();

Expand All @@ -714,13 +712,13 @@ void KernelPatcher::ApplyKextPatch(struct KextPatch* patch) {
}

} else {
// patch the function directed by symbol
// Patches the function directed by symbol

xnu::mach::VmAddress address = symbol->GetAddress();

if (find) {
// search up to N bytes from beginning of function
// use patchfinder::findFunctionEnd() to get ending point
// Searches up to N bytes from beginning of function
// Uses patchfinder::findFunctionEnd() to get ending point

xnu::mach::VmAddress current_address = address;

Expand All @@ -732,7 +730,7 @@ void KernelPatcher::ApplyKextPatch(struct KextPatch* patch) {
current_address++;
}
} else {
// use offset provided by user to patch bytes in function
// Uses offset provided by user to patch bytes in function

kernel->Write(address + offset, (void*)replace, size);
}
Expand Down Expand Up @@ -768,7 +766,7 @@ void KernelPatcher::RemoveKernelPatch(struct KernelPatch* patch) {
offset = patch->offset;

if (!symbol) {
// patch everything you can N times;
// Patches everything you can N times;

xnu::mach::VmAddress base = kernel->GetBase();

Expand All @@ -788,13 +786,13 @@ void KernelPatcher::RemoveKernelPatch(struct KernelPatch* patch) {
}

} else {
// patch the function directed by symbol
// Patches the function directed by symbol

xnu::mach::VmAddress address = symbol->GetAddress();

if (find) {
// search up to N bytes from beginning of function
// use patchfinder::findFunctionEnd() to get ending point
// Searches up to N bytes from beginning of function
// Uses patchfinder::findFunctionEnd() to get ending point

xnu::mach::VmAddress current_address = address;

Expand All @@ -806,7 +804,7 @@ void KernelPatcher::RemoveKernelPatch(struct KernelPatch* patch) {
current_address++;
}
} else {
// use offset provided by user to patch bytes in function
// Uses offset provided by user to patch bytes in function

kernel->Write(address + offset, (void*)find, size);
}
Expand Down
4 changes: 2 additions & 2 deletions kernel/start.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
darwin::DarwinKit* darwinkit = nullptr;

darwin::DarwinKit* darwinkit_get_darwinkit() {
if (darwinkit)
if (darwinkit) {
return darwinkit;

}
return nullptr;
}

Expand Down

0 comments on commit 554740c

Please sign in to comment.