Skip to content

Instantly share code, notes, and snippets.

@absoIute
Created April 6, 2018 20:51
Show Gist options
  • Save absoIute/e2ffbc95461dc7e7f7e0d7f11fcb9fe2 to your computer and use it in GitHub Desktop.
Save absoIute/e2ffbc95461dc7e7f7e0d7f11fcb9fe2 to your computer and use it in GitHub Desktop.
//
// main.c
// NoClip
//
// Created by Ben Stafford on 31/03/2018.
// Copyright © 2018 Ben Stafford. All rights reserved.
//
#include <stdlib.h>
#include <stdio.h>
#include <mach/mach.h>
#include <mach/mach_vm.h>
#include <sys/proc_info.h>
#include <libproc.h>
#define PRINT_ERROR(x) printf("%s failed with error %d (%s)\n", x, err, mach_error_string(err));
int pid_from_name(const char *proc_name);
kern_return_t get_task_base(task_t task, uint64_t *base);
int main(int argc, const char *argv[])
{
printf("gd 2.113 noclip (macos/osx) - absolute\n");
int pid = pid_from_name("Geometry Dash");
if (pid)
{
printf("target pid: %d\n", pid);
kern_return_t err;
mach_port_t task;
uint64_t slide;
//noclip
char patch_1[6] = {0xE9, 0x81, 0x07, 0x00, 0x00, 0x90};
mach_vm_address_t address_1 = 0x7ABBC;
//ac bypass
mach_vm_address_t address_2 = 0x72351;
char patch_2[2] = {0x90, 0x90};
if ((err = task_for_pid(mach_task_self(), pid, &task)) != KERN_SUCCESS)
{
PRINT_ERROR("task_for_pid");
return 0;
}
if ((err = get_task_base(task, &slide)) != KERN_SUCCESS)
{
PRINT_ERROR("mach_vm_recurse");
return 0;
}
address_1 += slide;
address_2 += slide;
if ((err = mach_vm_protect(task, address_1, 6, FALSE, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE)))
{
PRINT_ERROR("mach_vm_protect");
return 0;
}
if ((err = mach_vm_write(task, address_1, (vm_offset_t)&patch_1, 6)) != KERN_SUCCESS)
{
PRINT_ERROR("mach_vm_write");
return 0;
}
if ((err = mach_vm_protect(task, address_2, 2, FALSE, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE)))
{
PRINT_ERROR("mach_vm_protect");
return 0;
}
if ((err = mach_vm_write(task, address_2, (vm_offset_t)&patch_2, 2)) != KERN_SUCCESS)
{
PRINT_ERROR("mach_vm_write");
return 0;
}
printf("success\n");
}
else printf("failed to find process\n");
return 0;
}
int pid_from_name(const char *proc_name)
{
int proc_count = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0);
pid_t *pids = malloc(sizeof(pid_t) * proc_count);
if (proc_listpids(PROC_ALL_PIDS, 0, pids, sizeof(pid_t) * proc_count))
{
for (int i = 0; i < proc_count; ++i)
{
if (pids[i])
{
char buf[PROC_PIDPATHINFO_MAXSIZE];
if (proc_pidpath(pids[i], buf, sizeof(buf)) && strlen(buf) && !strcmp(proc_name, strrchr(buf, '/') + 1))
{
int pid = pids[i];
free(pids);
return pid;
}
}
}
}
free(pids);
return 0;
}
kern_return_t get_task_base(mach_port_t task, uint64_t *base)
{
vm_map_size_t size;
uint32_t depth;
struct vm_region_submap_info_64 vbr;
mach_msg_type_number_t count = 16;
return mach_vm_region_recurse(task, base, &size, &depth, (vm_region_recurse_info_t)&vbr, &count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment