AppleM1上的ARM64代码注入导致EXC_BAD_ACCESS崩溃。
创始人
2024-09-10 19:00:55
0

这个问题的一个解决方法是使用沙盒环境来注入代码。下面是一个示例代码:

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define PATH_MAX 1024

static char *resolve_binary_path(pid_t pid, char *buff, int len)
{
    int mib[4];
    size_t size;
    int ret;

    mib[0] = CTL_KERN;
    mib[1] = KERN_PROCARGS2;
    mib[2] = pid;
    mib[3] = ARG_MAX;

    size = len;

    ret = sysctl(mib, 4, buff, &size, NULL, 0);
    if (ret < 0) {
        perror("sysctl KERN_PROCARGS2");
        return NULL;
    }

    return buff + sizeof(int);
}

int inject_with_sandbox(char *proc_path, char *shared_obj_path,
                        char *class_hash, int hash_len)
{
    pid_t pid = getpid();
    char buff[PATH_MAX];
    char *binary_path = resolve_binary_path(pid, buff, PATH_MAX);
    if (binary_path == NULL) {
        printf("Error: could not resolve binary path\n");
        return -1;
    }

    printf("Binary path: %s\n", binary_path);

    mach_port_t task;
    mach_error_t error = task_for_pid(current_task(), pid, &task);
    if (error != KERN_SUCCESS) {
        printf("Error: could not get task for pid %d (error %s)\n", pid,
                mach_error_string(error));
        return -1;
    }

    vm_offset_t target_addr;
    error = vm_map_find(target_task, VM_OBJECT_NULL, 0, &target_addr, PAGE_SIZE,
            TRUE, VM_PROT_READ | VM_PROT_WRITE, VM_PROT_READ | VM_PROT_WRITE,
            VM_INHERIT_DEFAULT);
    if (error != KERN_SUCCESS) {
        printf("Error: could not allocate target memory (error %s)\n",
                mach_error_string(error));
        return -1;
    }

    vm_size_t size;
    int fd = open(shared_obj_path, O_RDONLY);
    if (fd < 0) {
        printf("Error: could not open shared object file %s\n", shared_obj_path);
        return -1;
    }
    struct stat stbuf;
    if (fstat(fd, &stbuf) != 0) {
        printf("Error: could not determine size of shared object file %s\n", shared_obj_path);
        return -1;
    }
    size = stbuf.st_size;

    void *mapping = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
    if (mapping == MAP_FAILED) {
        printf("Error: could not map shared object file %s\n", shared_obj_path);
        return -1;
    }

    memcpy((void *)target_addr, mapping, size);
    munmap(mapping, size);
    close(fd);

    error = mach_vm_write(task, (vm_address_t)binary_path, (vm_offset_t)class_hash,
            (mach_msg_size_t)hash_len);
    if (error != KERN_SUCCESS) {
        printf("Error: could not write to binary path %s (error %s)\n",
                binary_path, mach_error_string(error));
        return -1;
    }

    printf("Class hash injected\n");
    return 0

相关内容

热门资讯

记者揭秘!智星菠萝辅助(透视辅... 记者揭秘!智星菠萝辅助(透视辅助)拱趴大菠萝辅助神器,扑克教程(有挂细节);模式供您选择,了解更新找...
一分钟揭秘!约局吧能能开挂(透... 一分钟揭秘!约局吧能能开挂(透视辅助)hhpoker辅助靠谱,2024新版教程(有挂教学);约局吧能...
透视辅助!wepoker模拟器... 透视辅助!wepoker模拟器哪个好用(脚本)hhpoker辅助挂是真的,科技教程(有挂技巧);囊括...
透视代打!hhpkoer辅助器... 透视代打!hhpkoer辅助器视频(辅助挂)pokemmo脚本辅助,2024新版教程(有挂教程);风...
透视了解!约局吧德州真的有透视... 透视了解!约局吧德州真的有透视挂(透视脚本)德州局HHpoker透视脚本,必胜教程(有挂分析);亲,...
六分钟了解!wepoker挂底... 六分钟了解!wepoker挂底牌(透视)德普之星开辅助,详细教程(有挂解密);德普之星开辅助是一种具...
9分钟了解!wpk私人辅助(透... 9分钟了解!wpk私人辅助(透视)hhpoker德州透视,插件教程(有挂教学);风靡全球的特色经典游...
推荐一款!wepoker究竟有... 推荐一款!wepoker究竟有透视(脚本)哈糖大菠萝开挂,介绍教程(有挂技术);囊括全国各种wepo...
每日必备!wepoker有人用... 每日必备!wepoker有人用过(脚本)wpk有那种辅助,线上教程(有挂规律);wepoker有人用...
玩家必备教程!wejoker私... 玩家必备教程!wejoker私人辅助软件(脚本)哈糖大菠萝可以开挂,可靠技巧(有挂神器)申哈糖大菠萝...