Skip to content

Instantly share code, notes, and snippets.

@rweichler
Created December 23, 2013 22:14
Show Gist options
  • Save rweichler/8105758 to your computer and use it in GitHub Desktop.
Save rweichler/8105758 to your computer and use it in GitHub Desktop.
//
// main.c
// c4pture
//
// Created by Sam Marshall on 12/22/13.
// Copyright (c) 2013 Sam Marshall. All rights reserved.
//
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#define TAIG_START 0x8faeac
#define TAIG_LENGTH 0xd134f5
#define CYDIA_START 0x1a842d
#define CYDIA_LENGTH 0x6d24ff
size_t replace_bytes(int fd, uint32_t srcStart, uint32_t srcLen, uint32_t destStart, uint32_t destLen);
int main(int argc, const char *argv[]) {
int status = 0x0;
if (argc != 0x2 || strcmp(argv[1], "--help") == 0)
{
printf("usage: %s <evasi0n executable path>\n", argv[0]);
return 0x1;
}
struct stat fs;
char *path = (char *)argv[0x1];
int statResult = stat(path, &fs);
if (statResult != 0x0)
{
printf("error: file %s not found\n", argv[1]);
return 0x1;
}
int fd = open(path, O_RDWR);
size_t length = replace_bytes(fd, CYDIA_START, CYDIA_LENGTH, TAIG_START, TAIG_LENGTH);
if (length == -1) {
printf("error: (%i) %s\n",errno,strerror(errno));
status = 0x1;
} else {
printf("successfully patched evasi0n7!\n");
}
close(fd);
return status;
}
size_t replace_bytes(int fd, uint32_t srcStart, uint32_t srcLen, uint32_t destStart, uint32_t destLen)
{
if(srcLen > destLen)
{
printf("error: replace_bytes: srcLen > destLen\n");
exit(1);
return -1;
}
//zero out the place you want to copy to
lseek(fd, destStart, SEEK_SET);
uint32_t *zero = calloc(0x1, destLen);
write(fd, zero, destLen);
//get data to copy
lseek(fd, srcStart, SEEK_SET);
char *buffer = calloc(0x1, srcLen);
read(fd, buffer, srcLen);
//replace that shit
lseek(fd, destStart, SEEK_SET);
size_t length = write(fd, buffer, srcLen);
free(zero);
free(buffer);
return length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment