Comment: | Obfuscate tagged pointers |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | tagged-pointers |
Files: | files | file ages | folders |
SHA3-256: |
0bfac2b513ffa8da5f5e30d98283ac93 |
User & Date: | js on 2020-07-12 11:50:29 |
Other Links: | branch diff | manifest | tags |
2020-07-12
| ||
13:31 | lookup-asm-arm-elf.S: Obfuscate tagged pointers check-in: 761d528376 user: js tags: tagged-pointers | |
11:50 | Obfuscate tagged pointers check-in: 0bfac2b513 user: js tags: tagged-pointers | |
10:54 | Merge trunk into branch "tagged-pointers" check-in: be250b4fb3 user: js tags: tagged-pointers | |
Modified src/OFObject.m from [f5834cd36c] to [a224615e89].
︙ | ︙ | |||
325 326 327 328 329 330 331 332 333 334 335 336 337 338 | #endif objc_setEnumerationMutationHandler(enumerationMutationHandler); do { of_hash_seed = of_random32(); } while (of_hash_seed == 0); } + (void)unload { } + (void)initialize | > > > > > | 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | #endif objc_setEnumerationMutationHandler(enumerationMutationHandler); do { of_hash_seed = of_random32(); } while (of_hash_seed == 0); #ifdef OF_OBJFW_RUNTIME objc_setTaggedPointerSecret(sizeof(uintptr_t) == 4 ? (uintptr_t)of_random32() : (uintptr_t)of_random64()); #endif } + (void)unload { } + (void)initialize |
︙ | ︙ |
Modified src/runtime/ObjFWRT.h from [852e5138d0] to [b42f831278].
︙ | ︙ | |||
240 241 242 243 244 245 246 247 248 249 250 251 252 253 | objc_enumeration_mutation_handler_t _Nullable handler); extern id _Nullable objc_constructInstance(Class _Nullable class_, void *_Nullable bytes); extern void *_Nullable objc_destructInstance(id _Nullable object); extern void *_Null_unspecified objc_autoreleasePoolPush(void); extern void objc_autoreleasePoolPop(void *_Null_unspecified pool); extern id _Nullable _objc_rootAutorelease(id _Nullable object); extern int objc_registerTaggedPointerClass(Class _Nonnull class); extern Class _Nullable object_getTaggedPointerClass(id _Nonnull object); extern uintptr_t object_getTaggedPointerValue(id _Nonnull object); extern id _Nullable objc_createTaggedPointer(int class, uintptr_t value); /* * Used by the compiler, but can also be called manually. | > | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | objc_enumeration_mutation_handler_t _Nullable handler); extern id _Nullable objc_constructInstance(Class _Nullable class_, void *_Nullable bytes); extern void *_Nullable objc_destructInstance(id _Nullable object); extern void *_Null_unspecified objc_autoreleasePoolPush(void); extern void objc_autoreleasePoolPop(void *_Null_unspecified pool); extern id _Nullable _objc_rootAutorelease(id _Nullable object); extern void objc_setTaggedPointerSecret(uintptr_t secret); extern int objc_registerTaggedPointerClass(Class _Nonnull class); extern Class _Nullable object_getTaggedPointerClass(id _Nonnull object); extern uintptr_t object_getTaggedPointerValue(id _Nonnull object); extern id _Nullable objc_createTaggedPointer(int class, uintptr_t value); /* * Used by the compiler, but can also be called manually. |
︙ | ︙ |
Modified src/runtime/amiga-glue.m from [3dbec0ba16] to [d21e9a60b6].
︙ | ︙ | |||
796 797 798 799 800 801 802 | glue_objc_hashtable_free PPC_PARAMS(struct objc_hashtable *table) { M68K_ARG(struct objc_hashtable *, table, a0) objc_hashtable_free(table); } | > > > > > > > > | | | | | 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 | glue_objc_hashtable_free PPC_PARAMS(struct objc_hashtable *table) { M68K_ARG(struct objc_hashtable *, table, a0) objc_hashtable_free(table); } void __saveds glue_objc_setTaggedPointerSecret PPC_PARAMS(uintptr_t secret) { M68K_ARG(uintptr_t, secret, d0) objc_setTaggedPointerSecret(secret); } int __saveds glue_objc_registerTaggedPointerClass PPC_PARAMS(Class class) { M68K_ARG(Class, class, a0) return objc_registerTaggedPointerClass(class); } Class __saveds glue_object_getTaggedPointerClass PPC_PARAMS(id object) { M68K_ARG(id, object, a0) return object_getTaggedPointerClass(object); } uintptr_t __saveds glue_object_getTaggedPointerValue PPC_PARAMS(id object) { M68K_ARG(id, object, a0) return object_getTaggedPointerValue(object); } id __saveds glue_objc_createTaggedPointer PPC_PARAMS(int class, uintptr_t value) { M68K_ARG(int, class, d0) M68K_ARG(uintptr_t, value, d1) return objc_createTaggedPointer(class, value); } |
Modified src/runtime/amiga-library.m from [7a20b4c30e] to [8a86d7c3a3].
︙ | ︙ | |||
143 144 145 146 147 148 149 150 151 152 153 154 155 156 | extern void glue_objc_autoreleasePoolPop(void); extern id glue__objc_rootAutorelease(void); extern struct objc_hashtable *glue_objc_hashtable_new(void); extern void glue_objc_hashtable_set(void); extern void *glue_objc_hashtable_get(void); extern void glue_objc_hashtable_delete(void); extern void glue_objc_hashtable_free(void); extern int glue_objc_registerTaggedPointerClass(void); extern Class _Nullable glue_object_getTaggedPointerClass(void); extern uintptr_t glue_object_getTaggedPointerValue(void); extern id _Nullable glue_objc_createTaggedPointer(void); #ifdef OF_MORPHOS const ULONG __abox__ = 1; | > | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | extern void glue_objc_autoreleasePoolPop(void); extern id glue__objc_rootAutorelease(void); extern struct objc_hashtable *glue_objc_hashtable_new(void); extern void glue_objc_hashtable_set(void); extern void *glue_objc_hashtable_get(void); extern void glue_objc_hashtable_delete(void); extern void glue_objc_hashtable_free(void); extern void glue_objc_setTaggedPointerSecret(void); extern int glue_objc_registerTaggedPointerClass(void); extern Class _Nullable glue_object_getTaggedPointerClass(void); extern uintptr_t glue_object_getTaggedPointerValue(void); extern id _Nullable glue_objc_createTaggedPointer(void); #ifdef OF_MORPHOS const ULONG __abox__ = 1; |
︙ | ︙ | |||
673 674 675 676 677 678 679 680 681 682 683 684 685 686 | (CONST_APTR)glue_objc_autoreleasePoolPop, (CONST_APTR)glue__objc_rootAutorelease, (CONST_APTR)glue_objc_hashtable_new, (CONST_APTR)glue_objc_hashtable_set, (CONST_APTR)glue_objc_hashtable_get, (CONST_APTR)glue_objc_hashtable_delete, (CONST_APTR)glue_objc_hashtable_free, (CONST_APTR)glue_objc_registerTaggedPointerClass, (CONST_APTR)glue_object_getTaggedPointerClass, (CONST_APTR)glue_object_getTaggedPointerValue, (CONST_APTR)glue_objc_createTaggedPointer, (CONST_APTR)-1, #ifdef OF_MORPHOS (CONST_APTR)FUNCARRAY_END | > | 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 | (CONST_APTR)glue_objc_autoreleasePoolPop, (CONST_APTR)glue__objc_rootAutorelease, (CONST_APTR)glue_objc_hashtable_new, (CONST_APTR)glue_objc_hashtable_set, (CONST_APTR)glue_objc_hashtable_get, (CONST_APTR)glue_objc_hashtable_delete, (CONST_APTR)glue_objc_hashtable_free, (CONST_APTR)glue_objc_setTaggedPointerSecret, (CONST_APTR)glue_objc_registerTaggedPointerClass, (CONST_APTR)glue_object_getTaggedPointerClass, (CONST_APTR)glue_object_getTaggedPointerValue, (CONST_APTR)glue_objc_createTaggedPointer, (CONST_APTR)-1, #ifdef OF_MORPHOS (CONST_APTR)FUNCARRAY_END |
︙ | ︙ |
Modified src/runtime/amigaos3.sfd from [a0d1b4c012] to [5fcef80cc6].
︙ | ︙ | |||
86 87 88 89 90 91 92 93 94 95 96 97 | * The following functions are private! Don't use! struct objc_hashtable *_Nonnull glue_objc_hashtable_new(objc_hashtable_hash_func hash, objc_hashtable_equal_func equal, uint32_t size)(a0,a1,d0) void glue_objc_hashtable_set(struct objc_hashtable *_Nonnull table, const void *_Nonnull key, const void *_Nonnull object)(a0,a1,a2) void *_Nullable glue_objc_hashtable_get(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1) void glue_objc_hashtable_delete(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1) void glue_objc_hashtable_free(struct objc_hashtable *_Nonnull table)(a0) * Public functions again int glue_objc_registerTaggedPointerClass(Class _Nonnull class_)(a0) Class _Nullable glue_object_getTaggedPointerClass(id _Nonnull object)(a0) uintptr_t glue_object_getTaggedPointerValue(id _Nonnull object)(a0) id _Nullable glue_objc_createTaggedPointer(int class_, uintptr_t value)(d0,d1) ==end | > | 86 87 88 89 90 91 92 93 94 95 96 97 98 | * The following functions are private! Don't use! struct objc_hashtable *_Nonnull glue_objc_hashtable_new(objc_hashtable_hash_func hash, objc_hashtable_equal_func equal, uint32_t size)(a0,a1,d0) void glue_objc_hashtable_set(struct objc_hashtable *_Nonnull table, const void *_Nonnull key, const void *_Nonnull object)(a0,a1,a2) void *_Nullable glue_objc_hashtable_get(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1) void glue_objc_hashtable_delete(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1) void glue_objc_hashtable_free(struct objc_hashtable *_Nonnull table)(a0) * Public functions again void glue_objc_setTaggedPointerSecret(uintptr_t secret)(d0) int glue_objc_registerTaggedPointerClass(Class _Nonnull class_)(a0) Class _Nullable glue_object_getTaggedPointerClass(id _Nonnull object)(a0) uintptr_t glue_object_getTaggedPointerValue(id _Nonnull object)(a0) id _Nullable glue_objc_createTaggedPointer(int class_, uintptr_t value)(d0,d1) ==end |
Modified src/runtime/lookup-asm/lookup-asm-x86-elf.S from [d8beb6d9cc] to [3e4a512a7a].
︙ | ︙ | |||
59 60 61 62 63 64 65 | 0: call get_eip add eax, offset _GLOBAL_OFFSET_TABLE_ lea eax, [eax+\not_found@GOTOFF] jmp eax .Ltagged_pointer_\name: | < < < > > > > > | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 0: call get_eip add eax, offset _GLOBAL_OFFSET_TABLE_ lea eax, [eax+\not_found@GOTOFF] jmp eax .Ltagged_pointer_\name: call get_eip add eax, offset _GLOBAL_OFFSET_TABLE_ lea ecx, [eax+objc_tagged_pointer_secret@GOTOFF] xor edx, [ecx] and dl, 0xE movzx edx, dl lea eax, [eax+objc_tagged_pointer_classes@GOTOFF] mov edx, [eax+edx*2] mov edx, [edx+32] jmp short .Lmain_\name .type \name, %function |
︙ | ︙ |
Modified src/runtime/lookup-asm/lookup-asm-x86_64-elf.S from [82960b8628] to [1f89a766d7].
︙ | ︙ | |||
52 53 54 55 56 57 58 59 60 61 62 63 64 65 | test rax, rax jz short \not_found@PLT ret .Ltagged_pointer_\name: and dil, 0xE movzx r8, dil mov rax, [rip+objc_tagged_pointer_classes@GOTPCREL] mov r8, [rax+r8*4] mov r8, [r8+64] | > > | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | test rax, rax jz short \not_found@PLT ret .Ltagged_pointer_\name: mov rax, [rip+objc_tagged_pointer_secret@GOTPCREL] xor rdi, [rax] and dil, 0xE movzx r8, dil mov rax, [rip+objc_tagged_pointer_classes@GOTPCREL] mov r8, [rax+r8*4] mov r8, [r8+64] |
︙ | ︙ |
Modified src/runtime/lookup-asm/lookup-asm-x86_64-macho.S from [b9237d1cde] to [e2943741c9].
︙ | ︙ | |||
50 51 52 53 54 55 56 57 58 59 60 61 62 63 | test rax, rax jz $1 ret Ltagged_pointer_$0: and dil, 0xE movzx r8, dil mov rax, [rip+_objc_tagged_pointer_classes] mov r8, [rax+r8*4] mov r8, [r8+64] | > > | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | test rax, rax jz $1 ret Ltagged_pointer_$0: mov rax, [rip+objc_tagged_pointer_secret@GOTPCREL] xor rdi, [rax] and dil, 0xE movzx r8, dil mov rax, [rip+_objc_tagged_pointer_classes] mov r8, [rax+r8*4] mov r8, [r8+64] |
︙ | ︙ |
Modified src/runtime/morphos-clib.h from [003198598f] to [f477f1a478].
︙ | ︙ | |||
81 82 83 84 85 86 87 88 89 90 91 | /* The following functions are private! Don't use! */ struct objc_hashtable *glue_objc_hashtable_new(objc_hashtable_hash_func, objc_hashtable_equal_func, uint32_t); void glue_objc_hashtable_set(struct objc_hashtable *, const void *, const void *); void *glue_objc_hashtable_get(struct objc_hashtable *, const void *); void glue_objc_hashtable_delete(struct objc_hashtable *, const void *); void glue_objc_hashtable_free(struct objc_hashtable *); /* Public functions again */ int glue_objc_registerTaggedPointerClass(Class); Class _Nullable glue_object_getTaggedPointerClass(id); uintptr_t glue_object_getTaggedPointerValue(id); id glue_objc_createTaggedPointer(int, uintptr_t); | > | 81 82 83 84 85 86 87 88 89 90 91 92 | /* The following functions are private! Don't use! */ struct objc_hashtable *glue_objc_hashtable_new(objc_hashtable_hash_func, objc_hashtable_equal_func, uint32_t); void glue_objc_hashtable_set(struct objc_hashtable *, const void *, const void *); void *glue_objc_hashtable_get(struct objc_hashtable *, const void *); void glue_objc_hashtable_delete(struct objc_hashtable *, const void *); void glue_objc_hashtable_free(struct objc_hashtable *); /* Public functions again */ void glue_objc_setTaggedPointerSecret(uintptr_t); int glue_objc_registerTaggedPointerClass(Class); Class _Nullable glue_object_getTaggedPointerClass(id); uintptr_t glue_object_getTaggedPointerValue(id); id glue_objc_createTaggedPointer(int, uintptr_t); |
Modified src/runtime/morphos.fd from [705f1d62db] to [43f04663ca].
︙ | ︙ | |||
84 85 86 87 88 89 90 91 92 93 94 95 | * The following functions are private! Don't use! glue_objc_hashtable_new(hash,equal,size)(sysv,r12base) glue_objc_hashtable_set(table,key,object)(sysv,r12base) glue_objc_hashtable_get(table,key)(sysv,r12base) glue_objc_hashtable_delete(table,key)(sysv,r12base) glue_objc_hashtable_free(table)(sysv,r12base) * Public functions again glue_objc_registerTaggedPointerClass(class_)(sysv,r12base) glue_object_getTaggedPointerClass(object)(sysv,r12base) glue_object_getTaggedPointerValue(object)(sysv,r12base) glue_objc_createTaggedPointer(class_,value)(sysv,r12base) ##end | > | 84 85 86 87 88 89 90 91 92 93 94 95 96 | * The following functions are private! Don't use! glue_objc_hashtable_new(hash,equal,size)(sysv,r12base) glue_objc_hashtable_set(table,key,object)(sysv,r12base) glue_objc_hashtable_get(table,key)(sysv,r12base) glue_objc_hashtable_delete(table,key)(sysv,r12base) glue_objc_hashtable_free(table)(sysv,r12base) * Public functions again glue_objc_setTaggedPointerSecret(secret)(sysv,r12base) glue_objc_registerTaggedPointerClass(class_)(sysv,r12base) glue_object_getTaggedPointerClass(object)(sysv,r12base) glue_object_getTaggedPointerValue(object)(sysv,r12base) glue_objc_createTaggedPointer(class_,value)(sysv,r12base) ##end |
Modified src/runtime/tagged-pointer.m from [eeba4c306c] to [696420866c].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #import "private.h" #define TAGGED_POINTER_BITS 4 #define NUM_TAGGED_POINTER_CLASSES (1 << (TAGGED_POINTER_BITS - 1)) Class objc_tagged_pointer_classes[NUM_TAGGED_POINTER_CLASSES]; static int taggedPointerClassesCount; int objc_registerTaggedPointerClass(Class class) { int i; objc_global_mutex_lock(); | > > > > > > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #import "private.h" #define TAGGED_POINTER_BITS 4 #define NUM_TAGGED_POINTER_CLASSES (1 << (TAGGED_POINTER_BITS - 1)) Class objc_tagged_pointer_classes[NUM_TAGGED_POINTER_CLASSES]; static int taggedPointerClassesCount; uintptr_t objc_tagged_pointer_secret; void objc_setTaggedPointerSecret(uintptr_t secret) { objc_tagged_pointer_secret = secret & ~(uintptr_t)1; } int objc_registerTaggedPointerClass(Class class) { int i; objc_global_mutex_lock(); |
︙ | ︙ | |||
44 45 46 47 48 49 50 | return i; } Class object_getTaggedPointerClass(id object) { | | | | | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | return i; } Class object_getTaggedPointerClass(id object) { uintptr_t pointer = (uintptr_t)object ^ objc_tagged_pointer_secret; pointer &= (1 << TAGGED_POINTER_BITS) - 1; pointer >>= 1; if (pointer >= NUM_TAGGED_POINTER_CLASSES) return Nil; return objc_tagged_pointer_classes[pointer]; } uintptr_t object_getTaggedPointerValue(id object) { uintptr_t pointer = (uintptr_t)object ^ objc_tagged_pointer_secret; pointer >>= TAGGED_POINTER_BITS; return pointer; } id objc_createTaggedPointer(int class, uintptr_t value) { uintptr_t pointer; if (class < 0 || class >= NUM_TAGGED_POINTER_CLASSES) return nil; if (value > (UINTPTR_MAX >> TAGGED_POINTER_BITS)) return nil; pointer = (class << 1) | 1; pointer |= (value << TAGGED_POINTER_BITS); return (id)(pointer ^ objc_tagged_pointer_secret); } |