Skip to content

Instantly share code, notes, and snippets.

@DerekSelander
Last active September 27, 2019 15:59
Show Gist options
  • Select an option

  • Save DerekSelander/ff9c72e303a8957a059cade6826f988a to your computer and use it in GitHub Desktop.

Select an option

Save DerekSelander/ff9c72e303a8957a059cade6826f988a to your computer and use it in GitHub Desktop.
Fixing Scansnap's code
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <mach/mach.h>
#include <mach/mach_vm.h>
#include <assert.h>
#include <unistd.h>
__attribute__((constructor)) static void patch_assert() {
printf("test test \n");
if (strcmp(getprogname(), "Scan to Evernote2") != 0) { return; }
char *out_path = getenv("DS_TTY");
if (!out_path) { printf("Expects you to set DS_TTY env var for Terminal\n"); return; }
int fd = open(out_path, O_WRONLY);
if (fd) { return; }
dprintf(fd, "We're live calling from proc %d\n", getpid());
vm_address_t addr = (vm_address_t)__assert_rtn;
dprintf(fd, "__assert_rtn address found: %p\n", (void*)addr);
kern_return_t k = mach_vm_protect(mach_task_self(), addr, 1, FALSE, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);
assert(k == KERN_SUCCESS);
char data = 0xc3;
k = mach_vm_write(mach_task_self(), addr, (vm_offset_t)&data, sizeof(char));
mach_error("err ", k);
assert(k == KERN_SUCCESS);
dprintf(fd, "patching address: %p\n", (void*)addr);
k = mach_vm_msync(mach_task_self(), addr, 1, VM_SYNC_SYNCHRONOUS|VM_SYNC_INVALIDATE);
assert(k == KERN_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment