this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Initial DBGCopyFullDSYMURLForUUID() implementation, add the getuuid tool (will be used for dSYM symlink generation) (#403)

+234 -10
+1
src/CMakeLists.txt
··· 53 53 #add_subdirectory(util) 54 54 #add_subdirectory(libmach-o) 55 55 #add_subdirectory(libdyld) 56 + add_subdirectory(DebugSymbols/getuuid) 56 57 add_subdirectory(libelfloader/wrapgen) 57 58 add_subdirectory(startup) 58 59
+2 -1
src/DebugSymbols/CMakeLists.txt
··· 19 19 20 20 SOURCES 21 21 functions.c 22 - copy.c 22 + DebugSymbols.c 23 23 24 24 DEPENDENCIES 25 25 system 26 + CoreFoundation 26 27 )
+49
src/DebugSymbols/DebugSymbols.c
··· 1 + #include <DebugSymbols/DebugSymbols.h> 2 + 3 + const char* SYSTEM_DSYMS_DIR = "/System/Library/Caches/dsym/uuid"; 4 + 5 + CFURLRef DBGCopyFullDSYMURLForUUID(CFUUIDRef uuid, CFURLRef exec_url) 6 + { 7 + // Look up by UUID 8 + if (uuid != NULL) 9 + { 10 + CFStringRef uuidString = CFUUIDCreateString(NULL, uuid); 11 + CFStringRef dsymPath = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/%@.dSYM"), SYSTEM_DSYMS_DIR, uuidString); 12 + 13 + CFRelease(uuidString); 14 + 15 + if (access(CFStringGetCStringPtr(dsymPath, kCFStringEncodingUTF8), F_OK) == 0) 16 + { 17 + // printf("Found debug symbols: %s\n", CFStringGetCStringPtr(dsymPath, kCFStringEncodingUTF8)); 18 + CFURLRef url = CFURLCreateWithFileSystemPath(NULL, dsymPath, kCFURLPOSIXPathStyle, false); 19 + CFRelease(dsymPath); 20 + return url; 21 + } 22 + CFRelease(dsymPath); 23 + } 24 + 25 + 26 + // Try looking next to the executable 27 + if (exec_url != NULL) 28 + { 29 + CFStringRef exec_path = CFURLCopyFileSystemPath(exec_url, kCFURLPOSIXPathStyle); 30 + CFStringRef dsymPath = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@.dSYM"), exec_path); 31 + CFRelease(exec_path); 32 + 33 + if (access(CFStringGetCStringPtr(dsymPath, kCFStringEncodingUTF8), F_OK) == 0) 34 + { 35 + CFURLRef url = CFURLCreateWithFileSystemPath(NULL, dsymPath, kCFURLPOSIXPathStyle, false); 36 + CFRelease(dsymPath); 37 + return url; 38 + } 39 + 40 + CFRelease(dsymPath); 41 + } 42 + 43 + return NULL; 44 + } 45 + 46 + CFDictionaryRef DBGCopyDSYMPropertyLists(CFURLRef dsym_url) 47 + { 48 + return NULL; 49 + }
-9
src/DebugSymbols/copy.c
··· 1 - #include <DebugSymbols/DebugSymbols.h> 2 - 3 - CFURLRef DBGCopyFullDSYMURLForUUID(CFUUIDRef uuid, CFURLRef exec_url) { 4 - return NULL; 5 - } 6 - 7 - CFDictionaryRef DBGCopyDSYMPropertyLists(CFURLRef dsym_url) { 8 - return NULL; 9 - }
+6
src/DebugSymbols/getuuid/CMakeLists.txt
··· 1 + project(getuuid) 2 + 3 + include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 4 + 5 + add_executable(getuuid getuuid.c) 6 +
+174
src/DebugSymbols/getuuid/getuuid.c
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2018 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + #include <stdio.h> 20 + #include <unistd.h> 21 + #include <fcntl.h> 22 + #include <sys/mman.h> 23 + #include <stdint.h> 24 + #include <stdbool.h> 25 + #include <stdlib.h> 26 + #include <mach-o/loader.h> 27 + #include <mach-o/fat.h> 28 + #include <string.h> 29 + #include <errno.h> 30 + 31 + bool printUuidAny(const void* mem); 32 + bool printUuidMH(const struct mach_header* mhdr); 33 + bool printUuidMH64(const struct mach_header_64* mhdr); 34 + bool printFat(const struct fat_header* fhdr); 35 + bool printTaf(const struct fat_header* fhdr); 36 + 37 + int main(int argc, const char** argv) 38 + { 39 + if (argc != 2) 40 + { 41 + fprintf(stderr, "getuuid: Prints the UUID(s) of a Mach-O file, separated by semicolons (in case of fat files)\n"); 42 + fprintf(stderr, "Usage: getuuid <macho-file>\n"); 43 + return EXIT_FAILURE; 44 + } 45 + 46 + int fd = open(argv[1], O_RDONLY); 47 + if (fd == -1) 48 + { 49 + fprintf(stderr, "Cannot open %s: %s", argv[1], strerror(errno)); 50 + return EXIT_FAILURE; 51 + } 52 + 53 + size_t length = lseek(fd, 0, SEEK_END); 54 + 55 + void* mem = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0); 56 + if (mem == MAP_FAILED) 57 + { 58 + perror("mmap"); 59 + return EXIT_FAILURE; 60 + } 61 + 62 + close(fd); 63 + 64 + int rv = EXIT_FAILURE; 65 + 66 + if (printUuidAny(mem)) 67 + rv = EXIT_SUCCESS; 68 + 69 + munmap(mem, length); 70 + 71 + return rv; 72 + } 73 + 74 + bool printUuidAny(const void* mem) 75 + { 76 + const struct mach_header* mhdr = (struct mach_header*) mem; 77 + 78 + if (mhdr->magic == MH_MAGIC) 79 + return printUuidMH(mhdr); 80 + else if (mhdr->magic == MH_MAGIC_64) 81 + return printUuidMH64((struct mach_header_64*) mhdr); 82 + else if (mhdr->magic == FAT_MAGIC) 83 + return printFat((struct fat_header*) mhdr); 84 + else if (mhdr->magic == FAT_CIGAM) 85 + return printTaf((struct fat_header*) mhdr); 86 + else 87 + { 88 + fprintf(stderr, "File format not recognized\n"); 89 + exit(1); 90 + } 91 + } 92 + 93 + bool printUuid(const struct load_command* lc) 94 + { 95 + static bool hadUuid = false; 96 + if (lc->cmd == LC_UUID) 97 + { 98 + const struct uuid_command* uuid = (const struct uuid_command*) lc; 99 + 100 + if (hadUuid) 101 + putchar(';'); 102 + 103 + printf("%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", 104 + uuid->uuid[0], 105 + uuid->uuid[1], 106 + uuid->uuid[2], 107 + uuid->uuid[3], 108 + uuid->uuid[4], 109 + uuid->uuid[5], 110 + uuid->uuid[6], 111 + uuid->uuid[7], 112 + uuid->uuid[8], 113 + uuid->uuid[9], 114 + uuid->uuid[10], 115 + uuid->uuid[11], 116 + uuid->uuid[12], 117 + uuid->uuid[13], 118 + uuid->uuid[14], 119 + uuid->uuid[15]); 120 + 121 + hadUuid = true; 122 + return true; 123 + } 124 + return false; 125 + } 126 + 127 + bool printUuidMH(const struct mach_header* mhdr) 128 + { 129 + const uint8_t* command = (const uint8_t*)(mhdr + 1); 130 + for (uint32_t i = 0; i < mhdr->ncmds; i++) 131 + { 132 + if (printUuid((const struct load_command*) command)) 133 + return true; 134 + else 135 + command += ((const struct load_command*)command)->cmdsize; 136 + } 137 + return false; 138 + } 139 + 140 + bool printUuidMH64(const struct mach_header_64* mhdr) 141 + { 142 + const uint8_t* command = (const uint8_t*)(mhdr + 1); 143 + for (uint32_t i = 0; i < mhdr->ncmds; i++) 144 + { 145 + if (printUuid((const struct load_command*) command)) 146 + return true; 147 + else 148 + command += ((const struct load_command*)command)->cmdsize; 149 + } 150 + return false; 151 + } 152 + 153 + bool printFat(const struct fat_header* fhdr) 154 + { 155 + const struct fat_arch* fa = ((const struct fat_arch*) (fhdr+1)); 156 + bool rv = false; 157 + 158 + for (uint32_t i = 0; i < fhdr->nfat_arch; i++) 159 + rv |= printUuidAny(((char*) fhdr) + fa[i].offset); 160 + 161 + return rv; 162 + } 163 + 164 + bool printTaf(const struct fat_header* fhdr) 165 + { 166 + const struct fat_arch* fa = ((const struct fat_arch*) (fhdr+1)); 167 + bool rv = false; 168 + 169 + for (uint32_t i = 0; i < __builtin_bswap32(fhdr->nfat_arch); i++) 170 + rv |= printUuidAny(((char*) fhdr) + __builtin_bswap32(fa[i].offset)); 171 + 172 + return rv; 173 + } 174 +
+1
src/DebugSymbols/getuuid/mach
··· 1 + ../../../platform-include/mach
+1
src/DebugSymbols/getuuid/mach-o
··· 1 + ../../../platform-include/mach-o