Crates.io | getargv-sys |
lib.rs | getargv-sys |
version | 0.5.5 |
source | src |
created_at | 2022-11-07 18:04:46.577051 |
updated_at | 2024-08-09 20:39:42.458207 |
description | FFI bindings for libgetargv on macOS |
homepage | https://getargv.narzt.cam/ |
repository | https://github.com/getargv/getargv-sys/ |
max_upload_size | |
id | 707371 |
size | 327,494 |
libgetargv
is a library that allows you to get the arguments that were passed to another running process on macOS. It is intended to provide roughly the same functionality as reading from /proc/<pid>/cmdline
on Linux. On macOS this is done by parsing the output of the KERN_PROCARGS2
sysctl, which is very often implemented incorrectly, due to the overlooked possibility of leading empty arguments passed to the target process. This crate is the Rust bindings for the libgetargv
library.
libgetargv
can only see processes running as the same user by default, so be sure your process runs as the desired user (setuid
, launchd.plist
, sudo
) or can elevate privileges; n.b. elevating privileges safely is extremely complicated, and will be a target of privilege escalation attacks on macOS so be extremely careful if you go this route, better to defer to the user to elevate privileges for you as needed.
macOS is required as this is a macOS specific sysctl
, even BSD does not implement it. Your system must support sysctl
and KERN_PROCARGS2
, which probably means macOS 10.3 or later, though I haven't tested versions older than 10.7. You'll also need a non-ancient clang (c99 is required) or you'll have to override the compiler flags with CC
, EXTRA_CPPFLAGS
, and EXTRA_CFLAGS
.
getargv-sys
To make getargv-sys
:
libgetargv
to your system (see below).cargo build
orgetargv-sys = "0.5.1"
to your Cargo.toml
file dependencies.libgetargv
To get access to libgetargv
, sign up for an appropriate sponsorship tier.
Clone the libgetargv
repo: git clone https://github.com/getargv/getargv.git
.
Running make install_dylib
, installs the library to the /usr/local/
prefix by default; you can change the install location with the PREFIX
make
variable: make PREFIX=/opt install_dylib
.
I'm working on building binary artifacts to install without compilation, using pkg
installers, however even once that's done, depending on your system, it may still be necessary to compile from source; eg. if you have built your own xnu kernel with a custom PID_MAX
value.
libgetargv
I've built libgetargv
on macOS 10.7-13, using only the CLT package, not the full Xcode install. If you need to override variables, do so inside the make
command, eg: make EXTRA_CPPFLAGS=-DMACRO EXTRA_CFLAGS=-std=c17 dylib
. If you are trying to build on a version of macOS earlier than 10.7, let me know how it goes.