Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Fiddle, passing a pointer to an int. This gets the current process command
module Hacks
include Fiddle
func = "_NSGetExecutablePath"
path_ptr = Fiddle::Handle::DEFAULT[func]
path = Function.new path_ptr, [TYPE_VOIDP, TYPE_INTPTR_T], TYPE_INT, name: func
define_singleton_method(func, &path.to_proc)
func_name = "_dyld_image_count"
ptr = Fiddle::Handle::DEFAULT[func_name]
func = Function.new ptr, [], TYPE_INT32_T, name: func_name
define_singleton_method(func_name, &func.to_proc)
func_name = "_dyld_get_image_name"
ptr = Fiddle::Handle::DEFAULT[func_name]
func = Function.new ptr, [TYPE_INT32_T], TYPE_CONST_STRING, name: func_name
define_singleton_method(func_name, &func.to_proc)
func_name = "_dyld_get_image_vmaddr_slide"
ptr = Fiddle::Handle::DEFAULT[func_name]
func = Function.new ptr, [TYPE_INT32_T], TYPE_INTPTR_T, name: func_name
define_singleton_method(func_name, &func.to_proc)
def self.executable
str = Fiddle::Pointer.malloc(256, Fiddle::RUBY_FREE)
int = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT32_T, Fiddle::RUBY_FREE)
int[0, 4] = [256].pack("L")
if _NSGetExecutablePath(str, int) == 0
str[0, 256].unpack1("Z*")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment