Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Exploring Syscalls on MacOS

Syscall numbers on Mac are obviously different than Windows and Linux, and there aren't that many resources available. In general, much of the tech enthusiast world focuses on Windows.

This is similar to Syswhispers, but for MacOS - the goal here is to run a program that can dynamically pull the information easily. This could be done per major version for static lists & headers, param types, etc...

sys/syscalls.h
example path:
Quote:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/


Example...
delete 0x020000e2 226

Format:
0x02 << 24 = UNIX class tag
0x000000E2 = decimal 226
0x020000E2 == DARWIN_UNIX_SYSCALL(226)

We can verify this with the static header file in the path above
[Image: SL4AH3B.png]


An example use, assuming this syscall1 function is defined for params:
Quote:long r = do_syscall1(0x020000E2, (long)path);


This instead of using a more public API from userland to kernel, like with the function unlink(path) instead.

We can also call unlinkat. Here is an example of those syscalls:
Quote:long r = do_syscall1(0x0200000A, (long)path); // unlink(path), unix_n=10
// or unlinkat(dirfd, path, 0) => unix_n=472 → 0x020001D8 with 3 args


I am focused on dynamically finding this info from a program, but here is a clear definition from apple oss repo:
https://github.com/apple-oss-distributio...unlinkat.c

Once you have the internal numbers for a specific build/os version, you still need to handle param types, output handling, etc.

I am using some data from apple-oss-distributions for now, but would like to make this dynamic to the compiler OR runtime host.
Code
int sw_kill(int pid, int signum, int posix);
// ...
int sw_kill(int pid, int signum, int posix) { return ( int)mos_syscall3(0x02000025,(long)pid,(long)signum,(long)posix); }

This is what I came up with, and I confirmed it here, for kill function:
https://github.com/apple-oss-distributio...ers/kill.c

Quote:Class tag: 0x02 << 24 = 0x02000000
Number: 0x02000025 & 0x00FFFFFF = 0x25 = 37



I hope this thread is helpful for anyone diving into MacOS. Keep in mind that the numbers & info below may not match your specific Mac version!

Data dump:
Spoiler (Click to View)

There are also many definitions here:
https://raw.githubusercontent.com/apple-...lls.master


Spoiler (Click to View)

Another file that may be useful in the future is this script that constructs the syscall files for a distribution:
https://github.com/apple-oss-distributio...yscalls.sh

It was fun to learn a bit more MacOS.
I was able to create wrapper functions easily to avoid well-known & documented API / defined funcs, using direct syscalls instead.
I did not use this for any sort of hacking, as I am just learning the arch still & figured I would share what I discovered for Mac specifically.


Specs for these tests / syscalls:
Mac mini, with Apple M4 / silicon, with Sequoia 15.3.1

- I will be testing shortly with Sequoia 15.7x, followed by Tahoe 26x


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by arsiumSep 6, 2022 07:06 AM 0 217 Sep 6, 2022 07:06 AM
Last Post: arsium
[C] by JatamanoAug 19, 2020 12:43 PM 5 224 Aug 19, 2020 12:43 PM
Last Post: HFDone
[C#] by gigajewSep 20, 2018 03:40 AM 16 1,497 Sep 20, 2018 03:40 AM
Last Post: SaketSaket