Skip to content

Instantly share code, notes, and snippets.

View exc
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <spawn.h>
#include <sys/wait.h>
#ifndef _POSIX_SPAWN_DISABLE_ASLR
#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
#endif
View machdemo
/*
Copyright (c) 2003, Brian Alliet. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
View machdemo32
/*
Copyright (c) 2003, Brian Alliet. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@0x75
0x75 / machdemo64
Created Jun 28, 2013
mach demo 64 bit
View machdemo64
/*
Copyright (c) 2003, Brian Alliet. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
View gist:5877105
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include <grp.h>
#include <sys/user.h>
#include <assert.h>
// mach
#include <mach/mach.h>
#include <mach/mach_init.h>
@0x75
0x75 / gist:5876878
Created Jun 27, 2013
debug port installation routine
View gist:5876878
mach_port_t install_debug_port(void) {
mach_port_t *exceptionPort = (mach_port_t *) malloc(sizeof(mach_port_t));
mach_port_t me;
exception_mask_t mask = EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION | EXC_MASK_ARITHMETIC | EXC_MASK_SOFTWARE | EXC_MASK_BREAKPOINT | EXC_MASK_SYSCALL;
// Create a port by allocating a receive right, and then create a send right
// accessible under the same name.
me = mach_task_self();
mach_assert("mach_port_allocate()", mach_port_allocate(me, MACH_PORT_RIGHT_RECEIVE, exceptionPort));
mach_assert("mach_port_insert_right()", mach_port_insert_right(me, *exceptionPort, *exceptionPort, MACH_MSG_TYPE_MAKE_SEND));
@0x75
0x75 / gist:5876556
Created Jun 27, 2013
mach msg server
View gist:5876556
void mach_msg_server(mach_port_t exception_port) {
mach_msg_return_t r;
r = mach_msg(&msg.head, MACH_RCV_MSG|MACH_RCV_LARGE|MACH_RCV_TIMEOUT, 0, sizeof(msg), exception_port, 0, MACH_PORT_NULL);
assert(r != MACH_RCV_TIMED_OUT);
assert (r == MACH_MSG_SUCCESS);
mach_exc_server(&msg.head, &reply.head);
r = mach_msg(&reply.head, MACH_SEND_MSG|MACH_SEND_TIMEOUT, reply.head.msgh_size, 0, MACH_PORT_NULL, 0 ,MACH_PORT_NULL);
View gist:5868699
int SetBreakPoint(uint64_t Address) {
BPID++;
Breakpoint B;
B.ID = BPID;
B.address = Address;
B.active = true;
B.max_hits = -1;
B.description = "";
B.BP_Inst = REGULAR;
View uuencoded ls binary
begin 555 /dev/stdout
MROZZO@````(!```'@````P``$````)J@````#`````<````#``"P````BW``
M```,````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
@0x75
0x75 / main.c
Created May 4, 2013
parse fat macho binary
View main.c
#include <iostream>
#include <math.h>
#include <mach-o/loader.h>
#include <mach-o/nlist.h>
#include <mach-o/fat.h>