Permalink
Browse files

I don't remember what all this is

  • Loading branch information...
1 parent 7d7e7f1 commit 0257a5bc9cda4da1a7b03b388471b1fed3cecd2a @comex committed Mar 12, 2011
Showing with 218 additions and 4,466 deletions.
  1. +4 −2 Makefile
  2. +0 −1 creep.c
  3. +20 −52 kcode.c
  4. +30 −10 kinc.h
  5. +0 −2 mem.c
  6. +123 −6 milk.c
  7. +0 −1 protoss.c
  8. +41 −1 stuff.c
  9. +0 −4,391 syms.txt
View
@@ -1,4 +1,4 @@
-GCC ?= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/ -mapcs-frame -fomit-frame-pointer -mthumb
+GCC ?= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/ -mapcs-frame -fomit-frame-pointer -mthumb
CFLAGS += -g3 -std=gnu99 -Os -I. -fno-builtin-printf -fno-builtin-memset -fno-builtin-memcpy -Wall -Wno-parentheses -Wno-pointer-to-int-cast
all: stuff white_loader kcode.dylib mem.dylib serialplease.dylib
%.o: %.c kinc.h
@@ -24,8 +24,10 @@ chain-kern.dylib: chain-kern.c kinc.h
chain-user: chain-user.c
$(GCC) $(CFLAGS) -o chain-user chain-user.c
-white_loader: white_loader.o data/libdata.a
+data/libdata.a: data/*.c data/*.h
make -C data GCC="$(GCC)"
+
+white_loader: white_loader.o data/libdata.a
$(GCC) $(CFLAGS) -o $@ white_loader.o -Ldata -ldata
ifneq ($(shell which lipo),)
bash -c 'if [ -n "`lipo -info $@ | grep arm`" ]; then ldid -Sent.plist $@; fi'
View
@@ -58,7 +58,6 @@ int creep_go(void *start, int size) {
}
void creep_get_records(user_addr_t buf, uint32_t bufsize) {
- struct record *record = record_start;
for(struct record *record = record_start; record; record = record->next) {
size_t sz = 2 * sizeof(uint32_t);
if(bufsize < sz) return;
View
72 kcode.c
@@ -26,12 +26,13 @@ struct mysyscall_args {
uint32_t f;
};
-#define VOID_STAR_A1_THROUGH_7 void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, void *a7
+#define VOID_STAR_A1_THROUGH_12 void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, void *a7, void *a8, void *a9, void *a10, void *a11, void *a12
#define A1_THROUGH_7 a1, a2, a3, a4, a5, a6, a7
+#define A1_THROUGH_12 a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12
-static void *(*vt_old)(VOID_STAR_A1_THROUGH_7);
-static void *vt_hook(VOID_STAR_A1_THROUGH_7) {
- void *result = vt_old(A1_THROUGH_7);
+static void *(*vt_old)(VOID_STAR_A1_THROUGH_12);
+static void *vt_hook(VOID_STAR_A1_THROUGH_12) {
+ void *result = vt_old(A1_THROUGH_12);
IOLog("vt_hook: from:%p <- %p <- %p <- %p <- %p <- %p r0=%p r1=%p r2=%p r3=%p a5=%p a6=%p a7=%p vt=%p result=%p\n",
__builtin_return_address(0),
__builtin_return_address(1),
@@ -43,18 +44,18 @@ static void *vt_hook(VOID_STAR_A1_THROUGH_7) {
return result;
}
-static void *(*ttbr_old)(VOID_STAR_A1_THROUGH_7);
-static void *ttbr_hook(VOID_STAR_A1_THROUGH_7) {
+static void *(*ttbr_old)(VOID_STAR_A1_THROUGH_12);
+static void *ttbr_hook(VOID_STAR_A1_THROUGH_12) {
uint32_t ttbr0, ttbr1;
asm("mrc p15, 0, %0, c2, c0, 0" :"=r"(ttbr0));
asm("mrc p15, 0, %0, c2, c0, 1" :"=r"(ttbr1));
IOLog("ttbr_hook: from:%p <- %p <- %p r0=%p r1=%p r2=%p r3=%p a5=%p a6=%p a7=%p ttbr0=%x ttbr1=%x\n", __builtin_return_address(0), __builtin_return_address(1), __builtin_return_address(2), A1_THROUGH_7, ttbr0, ttbr1);
- return ttbr_old(A1_THROUGH_7);
+ return ttbr_old(A1_THROUGH_12);
}
-static void *(*logger_old)(VOID_STAR_A1_THROUGH_7);
-static void *logger_hook(VOID_STAR_A1_THROUGH_7) {
- void *result = logger_old(A1_THROUGH_7);
+static void *(*logger_old)(VOID_STAR_A1_THROUGH_12);
+static void *logger_hook(VOID_STAR_A1_THROUGH_12) {
+ void *result = logger_old(A1_THROUGH_12);
IOLog("logger_hook: from:%p <- %p <- %p <- %p <- %p <- %p r0=%p r1=%p r2=%p r3=%p a5=%p a6=%p a7=%p result=%p pid=%d\n",
__builtin_return_address(0),
__builtin_return_address(1),
@@ -67,13 +68,13 @@ static void *logger_hook(VOID_STAR_A1_THROUGH_7) {
return result;
}
-static void *(*tracer_old)(VOID_STAR_A1_THROUGH_7);
+static void *(*tracer_old)(VOID_STAR_A1_THROUGH_12);
static bool tracer_did_trace;
-static void *tracer_hook(VOID_STAR_A1_THROUGH_7) {
+static void *tracer_hook(VOID_STAR_A1_THROUGH_12) {
bool should_trace = !tracer_did_trace;
tracer_did_trace = true;
if(should_trace) protoss_go();
- void *result = tracer_old(A1_THROUGH_7);
+ void *result = tracer_old(A1_THROUGH_12);
if(should_trace) protoss_stop();
IOLog("tracer_hook: from:%p <- %p <- %p r0=%p r1=%p r2=%p r3=%p a5=%p a6=%p a7=%p result=%p\n", __builtin_return_address(0), __builtin_return_address(1), __builtin_return_address(2), A1_THROUGH_7, result);
return result;
@@ -100,36 +101,6 @@ int weird_hook(char *buf, int size) {
return ret;
}
-static int list_iosurfaces() {
- void *reg_entry = IORegistryEntry_fromPath("IOService:/IOResources/IOCoreSurfaceRoot", NULL, NULL, NULL, NULL);
- if(!reg_entry) {
- IOLog("No reg_entry...\n");
- return 1;
- }
- int highest_number = prop(reg_entry, 0x84, int);
- void **root = prop(reg_entry, 0x80, void **);
- IOLog("highest_number: %d\n", highest_number);
- //IOLog("root: %p\n", root);
- for(int i = 0; i < highest_number; i++) {
- void *surface = root[i];
- if(!surface) continue;
- int its_id = prop(surface, 8, int);
- char global = prop(surface, 0x15, char);
- int owner = prop(surface, 0x44, int);
- int width = prop(surface, 0x58, int);
- int height = prop(surface, 0x5c, int);
- int allocsize = prop(surface, 0x74, int);
- void *vt = prop(surface, 0, void *);
-
- void *md = prop(surface, 0x24, void *);
- void *phys = (md && prop(md, 0, unsigned int) == 0x802340e4) ? IOMemoryDescriptor_getPhysicalAddress(md) : NULL;
- unsigned int vram = phys ? ((unsigned int) phys - 0x4fd00000) : (unsigned int) -1;
-
- IOLog("%d: %p vt=%p id=%d global=%d owner=%x %dx%d allocsize=%d @vram=%u\n", i, surface, vt, its_id, (int) global, owner, width, height, allocsize, vram);
- }
- return 0;
-}
-
static int do_something_usb_related() {
char *base = (void *) 0xd3edc000;
for(int i = 0; i < 8; i++) {
@@ -179,8 +150,8 @@ static int ioreg(uint32_t type, user_addr_t path) {
IOLog("- %p\n", object);
}
IOLog("\n");
- release_object(iterator);
- release_object(matching);
+ OSObject_release(iterator);
+ OSObject_release(matching);
}
return (int) regentry;
}
@@ -191,7 +162,7 @@ static uint32_t lookup_metaclass(user_addr_t name) {
copyinstr(name, buf, sizeof(buf), &done);
void *symbol = OSSymbol_withCString(buf);
uint32_t result = (uint32_t) OSMetaClass_getMetaClassWithName(symbol);
- release_object(symbol);
+ OSObject_release(symbol);
return result;
}
@@ -217,8 +188,8 @@ static int poke_mem(void *kaddr, uint32_t uaddr, uint32_t size, bool write, bool
}
if(phys) {
- release_object(map);
- release_object(descriptor);
+ OSObject_release(map);
+ OSObject_release(descriptor);
}
return retval;
}
@@ -311,9 +282,6 @@ int mysyscall(void *p, struct mysyscall_args *uap, int32_t *retval)
((void (*)()) 0xdeadbeef)();
*retval = 0;
break;
- case 5: // list IOSurfaces
- *retval = list_iosurfaces();
- break;
case 6: // unhook
fini_();
break;
@@ -390,7 +358,7 @@ int mysyscall(void *p, struct mysyscall_args *uap, int32_t *retval)
break;
case 25: {
void *metaclass;
- if(run_failsafe(&metaclass, &get_metaclass, uap->b, 0)) {
+ if(run_failsafe(&metaclass, &OSObject_getMetaClass, uap->b, 0)) {
*retval = 5;
} else {
const char *name = OSMetaClass_getClassName(metaclass);
View
40 kinc.h
@@ -5,11 +5,16 @@
#define METACALL(typ, method_name, object, args...) METACALL2(__LINE__, typ, method_name, object, ##args)
#define METACALL2(line, typ, method_name, object, args...) METACALL3(line, typ, method_name, object, ##args)
#define METACALL3(line, typ, method_name, object, args...) ({ \
- extern uint32_t vt_offset_##line asm("$vt_" method_name); \
+ extern void *vt_offset_##line asm("$vt_" method_name); \
+ uint32_t vt_offset = (uint32_t) &vt_offset_##line; \
void *_o = (object); \
- ((typ (***)(void *, ...)) _o)[0][vt_offset_##line/4](_o, ##args); \
+ ((typ (***)(void *, ...)) _o)[0][vt_offset/4](_o, ##args); \
})
// the above is based on some magic in link.c
+#define FIXED_METACALL(typ, num, object, args...) ({ \
+ void *_o = (object); \
+ ((typ (***)(void *, ...)) _o)[0][(num)/4](_o, ##args); \
+})
typedef uint32_t user_addr_t;
typedef uint32_t vm_size_t, vm_address_t, boolean_t, size_t, vm_offset_t, vm_prot_t, vm_map_size_t;
@@ -122,6 +127,8 @@ LC int proc_pid(struct proc *proc);
LC struct proc *current_proc();
+LC task_t current_task();
+
LC void panic(const char *string, ...);
static inline void flush_cache(void *addr, unsigned cnt) {
@@ -161,6 +168,9 @@ asm("__ZN9IOService12nameMatchingEPKcP12OSDictionary");
LC void *IOService_getMatchingServices(void *matching)
asm("__ZN9IOService19getMatchingServicesEP12OSDictionary");
+LC void *IOService_waitForMatchingService(void *matching, uint64_t timeout)
+asm("__ZN9IOService22waitForMatchingServiceEP12OSDictionaryy");
+
static inline void *OSIterator_getNextObject(void *iterator) {
return METACALL(void *, "__ZN18IORegistryIterator13getNextObjectEv", iterator);
}
@@ -180,19 +190,20 @@ asm("__ZN11OSMetaClass20getMetaClassWithNameEPK8OSSymbol");
LC void *OSMetaClass_getClassName(void *metaclass)
asm("__ZNK11OSMetaClass12getClassNameEv");
-static inline void *get_metaclass(void *object) {
- return METACALL(void *, "__ZNK11OSMetaClass12getMetaClassEv", object);
+static inline void *OSObject_getMetaClass(void *object) {
+ return FIXED_METACALL(void *, 7, object);
}
-LC int OSObject_getRetainCount(void *object)
-asm("__ZNK8OSObject14getRetainCountEv");
+static inline int OSObject_getRetainCount(void *object) {
+ return FIXED_METACALL(int, 3, object);
+}
-static inline void release_object(void *object) {
- return METACALL(void, "__ZNK8OSObject7releaseEi", object);
+static inline void OSObject_release(void *object) {
+ return FIXED_METACALL(void, 2, object);
}
-static inline void *retain_object(void *object) {
- return METACALL(void *, "__ZNK11OSMetaClass6retainEv", object);
+static inline void *OSObject_retain(void *object) {
+ return FIXED_METACALL(void *, 4, object);
}
struct IOExternalMethodArguments {
@@ -223,15 +234,24 @@ struct IOExternalMethodArguments {
uint32_t __reserved[32];
};
+LC void *OSUnserializeXML(const char *buffer, void **errorString)
+asm("__Z16OSUnserializeXMLPKcPP8OSString");
static inline int IOService_newUserClient(void *service, task_t owningTask, void *securityID, uint32_t type, void *properties, void **client) {
return METACALL(int, "__ZN9IOService13newUserClientEP4taskPvmP12OSDictionaryPP12IOUserClient", service, owningTask, securityID, type, properties, client);
}
+static inline int IORegistryEntry_setProperties(void *entry, void *properties) {
+ return METACALL(int, "__ZN15IORegistryEntry13setPropertiesEP8OSObject", entry, properties);
+}
+
static inline int IOUserClient_externalMethod(void *client, uint32_t selector, struct IOExternalMethodArguments *arguments) {
return METACALL(int, "__ZN12IOUserClient14externalMethodEjP25IOExternalMethodArgumentsP24IOExternalMethodDispatchP8OSObjectPv", client, selector, arguments, 0, 0, 0);
}
+static inline int IOUserClient_clientClose(void *client) {
+ return METACALL(int, "__ZN12IOUserClient11clientCloseEv", client);
+}
// copied from xnu
View
2 mem.c
@@ -141,8 +141,6 @@ mmrw(dev, uio, rw)
int error = 0;
vm_offset_t where;
- int aa = ((int *) uio)[0x18/4];
-
while (uio_resid(uio) > 0 && error == 0) {
uio_update(uio, 0);
Oops, something went wrong.

0 comments on commit 0257a5b

Please sign in to comment.