├── testdylib ├── main.cpp └── testdylib.xcodeproj │ ├── xcuserdata │ └── scen.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── testdylib.xcscheme │ └── project.pbxproj ├── .gitignore ├── osxinj.xcworkspace ├── xcuserdata │ └── scen.xcuserdatad │ │ ├── UserInterfaceState.xcuserstate │ │ └── WorkspaceSettings.xcsettings ├── contents.xcworkspacedata └── xcshareddata │ └── osxinj.xccheckout ├── osxinj ├── injector.h ├── osxinj.xcodeproj │ ├── xcuserdata │ │ └── scen.xcuserdatad │ │ │ └── xcschemes │ │ │ ├── xcschememanagement.plist │ │ │ └── osxinj.xcscheme │ └── project.pbxproj ├── main.cpp ├── injector.cpp ├── mach_inject.h └── mach_inject.c ├── README.md ├── testapp ├── testapp.xcodeproj │ ├── xcuserdata │ │ └── scen.xcuserdatad │ │ │ └── xcschemes │ │ │ ├── xcschememanagement.plist │ │ │ └── testapp.xcscheme │ └── project.pbxproj └── main.cpp ├── bootstrap ├── bootstrap.xcodeproj │ ├── xcuserdata │ │ └── scen.xcuserdatad │ │ │ └── xcschemes │ │ │ ├── xcschememanagement.plist │ │ │ ├── bootstrap.xcscheme │ │ │ └── BuildAll.xcscheme │ └── project.pbxproj └── main.cpp └── LICENSE.md /testdylib/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void install(void) __attribute__ ((constructor)); 4 | 5 | void install() 6 | { 7 | printf("hello, world!\n"); 8 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .qmake.cache 3 | *.o 4 | *.app 5 | Debug/* 6 | Release/* 7 | *.build 8 | bin/* 9 | build/* 10 | osxinj/build* 11 | osxinj/bin* 12 | testapp/testapp 13 | -------------------------------------------------------------------------------- /osxinj.xcworkspace/xcuserdata/scen.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scen/osxinj/HEAD/osxinj.xcworkspace/xcuserdata/scen.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /osxinj/injector.h: -------------------------------------------------------------------------------- 1 | #ifndef _INJECTOR_H_ 2 | #define _INJECTOR_H_ 3 | 4 | #include "mach_inject.h" 5 | 6 | class Injector 7 | { 8 | public: 9 | Injector(); 10 | ~Injector(); 11 | 12 | void inject(pid_t pid, const char* lib); 13 | pid_t getProcessByName(const char *name); 14 | private: 15 | void *module; 16 | void *bootstrapfn; 17 | }; 18 | 19 | #endif -------------------------------------------------------------------------------- /osxinj.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | osxinj 2 | ====== 3 | 4 | Another dylib injector. Uses a bootstrapping module since `mach_inject` doesn't fully emulate library loading and crashes when loading complex modules. 5 | 6 | - `mach_inject` was taken from `rentzsch/mach_inject`. Thanks! 7 | - `testapp` is a sample app to inject into 8 | - `testdylib` is a sample dylib to inject into an app 9 | - `bootstrap` is a dylib that is initially injected to load another dylib (e.g. `testdylib`) 10 | 11 | Released under the MIT License. 12 | 13 | Notes 14 | ----- 15 | 16 | - Build with scheme `BuildAll` 17 | -------------------------------------------------------------------------------- /osxinj/osxinj.xcodeproj/xcuserdata/scen.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | osxinj.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | C46F6D1F17B41A53000369C2 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /testapp/testapp.xcodeproj/xcuserdata/scen.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | testapp.xcscheme 8 | 9 | orderHint 10 | 1 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | C46F6D7517B41D6E000369C2 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /testdylib/testdylib.xcodeproj/xcuserdata/scen.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | testdylib.xcscheme 8 | 9 | orderHint 10 | 2 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | C46F6D8C17B41DD4000369C2 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /bootstrap/bootstrap.xcodeproj/xcuserdata/scen.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | BuildAll.xcscheme 8 | 9 | orderHint 10 | 4 11 | 12 | bootstrap.xcscheme 13 | 14 | orderHint 15 | 3 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | C46F6D9C17B41DE2000369C2 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /osxinj/main.cpp: -------------------------------------------------------------------------------- 1 | #include "injector.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int main(int argc, char* argv[]) 12 | { 13 | if (argc < 3) 14 | { 15 | fprintf(stderr, "Usage: ./osxinj [proc_name] [lib]\n"); 16 | return -1; 17 | } 18 | 19 | if (getuid() > 0) { 20 | fprintf(stderr, "please run me as root\n"); 21 | return -1; 22 | } 23 | 24 | char path[4096]; 25 | realpath(argv[2], path); 26 | 27 | fprintf(stderr, "%s\n", path); 28 | 29 | Injector inj; 30 | 31 | pid_t pid = inj.getProcessByName(argv[1]); 32 | if (!pid) 33 | { 34 | fprintf(stderr, "process %s not found\n", argv[1]); 35 | return 0; 36 | } 37 | fprintf(stderr, "pid: %u\n", pid); 38 | 39 | inj.inject(pid, path); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /osxinj.xcworkspace/xcuserdata/scen.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildLocationStyle 6 | CustomLocation 7 | CustomBuildIntermediatesPath 8 | bin/intermediate 9 | CustomBuildLocationType 10 | RelativeToWorkspace 11 | CustomBuildProductsPath 12 | bin/ 13 | DerivedDataLocationStyle 14 | Default 15 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 16 | 17 | IssueFilterStyle 18 | ShowActiveSchemeOnly 19 | LiveSourceIssuesEnabled 20 | 21 | SnapshotAutomaticallyBeforeSignificantChanges 22 | 23 | SnapshotLocationStyle 24 | Default 25 | 26 | 27 | -------------------------------------------------------------------------------- /testapp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int sigscan_me() 5 | { 6 | int ret = printf("sigscan_me()\n"); 7 | ret += 3; 8 | ret *= 3; 9 | ret ^= 3; 10 | ret &= 3; 11 | return ret; 12 | } 13 | 14 | //class entity 15 | //{ 16 | //public: 17 | // entity(int x) { a = x; } 18 | // 19 | // virtual void aa() {} 20 | // virtual int bb(int cc){return cc;} 21 | // virtual void cc(int dd) {return;} 22 | // virtual float ff(int ee) {return (float)ee;} 23 | // virtual double lol(int test) {return (double)test;} 24 | // virtual void test(int x, int y, int z, int zz) { printf("abcd %d %d %d %d %d\n", a, x, y, z, zz); } 25 | // virtual long long gg(int jj) { return jj + 3; } 26 | // 27 | // int a, b, c, d, e; 28 | //}; 29 | 30 | int main(int argc, char* argv[]) 31 | { 32 | printf("testapp reporting in!\n"); 33 | // int x; 34 | // scanf("%d", &x); 35 | // entity* e = new entity(x); 36 | // e->test(1, 2, 3, 4); 37 | sleep(100000000); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Stanley Cen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /osxinj.xcworkspace/xcshareddata/osxinj.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 8422E8CE-DDB7-4D5C-91DD-CCE19A234689 9 | IDESourceControlProjectName 10 | osxinj 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 4EBDBDD317D21AE7E468312BA9AE520C830CFE3A 14 | https://github.com/scen/osxinj.git 15 | 16 | IDESourceControlProjectPath 17 | osxinj.xcworkspace 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 4EBDBDD317D21AE7E468312BA9AE520C830CFE3A 21 | .. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/scen/osxinj.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 4EBDBDD317D21AE7E468312BA9AE520C830CFE3A 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 4EBDBDD317D21AE7E468312BA9AE520C830CFE3A 36 | IDESourceControlWCCName 37 | osxinj 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /bootstrap/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define DLLEXPORT __attribute__((visibility("default"))) 18 | 19 | #if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_12 20 | #define PTHREAD_SET_SELF _pthread_set_self 21 | #else 22 | #define PTHREAD_SET_SELF __pthread_set_self 23 | #endif 24 | 25 | extern "C" void PTHREAD_SET_SELF(void*); 26 | 27 | extern "C" void bootstrap(ptrdiff_t offset, void *param, size_t psize, void *dummy) DLLEXPORT; 28 | 29 | void *loaderThread(void *patch_bundle) 30 | { 31 | void *bundle = dlopen((char *)patch_bundle, RTLD_NOW); 32 | if (!bundle) 33 | fprintf(stderr, "Could not load patch bundle: %s\n", dlerror()); 34 | return 0; 35 | } 36 | 37 | void bootstrap(ptrdiff_t offset, void *param, size_t psize, void *dummy) 38 | { 39 | PTHREAD_SET_SELF(dummy); 40 | 41 | pthread_attr_t attr; 42 | pthread_attr_init(&attr); 43 | 44 | int policy; 45 | pthread_attr_getschedpolicy(&attr, &policy); 46 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 47 | pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); 48 | 49 | struct sched_param sched; 50 | sched.sched_priority = sched_get_priority_max(policy); 51 | pthread_attr_setschedparam(&attr, &sched); 52 | 53 | pthread_t thread; 54 | pthread_create(&thread, &attr, 55 | (void * (*)(void *))((long)loaderThread), 56 | (void *)param); 57 | pthread_attr_destroy(&attr); 58 | 59 | thread_suspend(mach_thread_self()); 60 | } 61 | -------------------------------------------------------------------------------- /osxinj/injector.cpp: -------------------------------------------------------------------------------- 1 | #include "injector.h" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | Injector::Injector() : module(0), bootstrapfn(0) 16 | { 17 | module = dlopen("bootstrap.dylib", 18 | RTLD_NOW | RTLD_LOCAL); 19 | 20 | printf("module: 0x%X\n", module); 21 | if (!module) 22 | { 23 | fprintf(stderr, "dlopen error: %s\n", dlerror()); 24 | return; 25 | } 26 | 27 | bootstrapfn = dlsym(module, "bootstrap"); 28 | printf("bootstrapfn: 0x%X\n", bootstrapfn); 29 | 30 | if (!bootstrapfn) 31 | { 32 | fprintf(stderr, "could not locate bootstrap fn\n"); 33 | return; 34 | } 35 | } 36 | 37 | Injector::~Injector() 38 | { 39 | if (module) 40 | { 41 | dlclose(module); 42 | module = NULL; 43 | } 44 | } 45 | 46 | void Injector::inject(pid_t pid, const char* lib) 47 | { 48 | if (!module || !bootstrapfn) 49 | { 50 | fprintf(stderr, "failed to inject: module:0x%X bootstrapfn:0x%X\n", module, bootstrapfn); 51 | return; 52 | } 53 | mach_error_t err = mach_inject((mach_inject_entry)bootstrapfn, lib, strlen(lib) + 1, pid, 0); 54 | } 55 | 56 | pid_t Injector::getProcessByName(const char *name) 57 | { 58 | int procCnt = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0); 59 | pid_t pids[1024]; 60 | memset(pids, 0, sizeof pids); 61 | proc_listpids(PROC_ALL_PIDS, 0, pids, sizeof(pids)); 62 | 63 | for (int i = 0; i < procCnt; i++) 64 | { 65 | if (!pids[i]) continue; 66 | char curPath[PROC_PIDPATHINFO_MAXSIZE]; 67 | char curName[PROC_PIDPATHINFO_MAXSIZE]; 68 | memset(curPath, 0, sizeof curPath); 69 | proc_pidpath(pids[i], curPath, sizeof curPath); 70 | int len = strlen(curPath); 71 | if (len) 72 | { 73 | int pos = len; 74 | while (pos && curPath[pos] != '/') --pos; 75 | strcpy(curName, curPath + pos + 1); 76 | if (!strcmp(curName, name)) 77 | { 78 | return pids[i]; 79 | } 80 | } 81 | } 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /bootstrap/bootstrap.xcodeproj/xcuserdata/scen.xcuserdatad/xcschemes/bootstrap.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 42 | 43 | 44 | 45 | 51 | 52 | 54 | 55 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /testdylib/testdylib.xcodeproj/xcuserdata/scen.xcuserdatad/xcschemes/testdylib.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 42 | 43 | 44 | 45 | 51 | 52 | 54 | 55 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /osxinj/mach_inject.h: -------------------------------------------------------------------------------- 1 | // mach_inject.h semver:1.2.0 2 | // Copyright (c) 2003-2012 Jonathan 'Wolf' Rentzsch: http://rentzsch.com 3 | // Some rights reserved: http://opensource.org/licenses/mit 4 | // https://github.com/rentzsch/mach_inject 5 | 6 | #ifndef _mach_inject_ 7 | #define _mach_inject_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include // for ptrdiff_t 13 | 14 | #define err_threadEntry_image_not_found (err_local|1) 15 | 16 | #define INJECT_ENTRY injectEntry 17 | #define INJECT_ENTRY_SYMBOL "injectEntry" 18 | 19 | typedef void (*mach_inject_entry)( ptrdiff_t codeOffset, void *paramBlock, 20 | size_t paramSize, void* dummy_pthread_data ); 21 | 22 | __BEGIN_DECLS 23 | 24 | /******************************************************************************* 25 | Starts executing threadEntry in a new thread in the process specified by 26 | targetProcess. 27 | 28 | @param threadEntry -> Required pointer to injected thread's entry 29 | point. 30 | @param paramBlock -> Optional pointer to block of memory to pass to 31 | the injected thread. 32 | @param paramSize -> Optional size of paramBlock. 33 | @param targetProcess -> Required target process ID. 34 | @param stackSize -> Optional stack size of threadEntry's thread. Set 35 | to zero for default (currently 8K usable). 36 | @result <- mach_error_t 37 | 38 | ***************************************************************************/ 39 | 40 | mach_error_t 41 | mach_inject( 42 | const mach_inject_entry threadEntry, 43 | const void *paramBlock, 44 | size_t paramSize, 45 | pid_t targetProcess, 46 | vm_size_t stackSize ); 47 | 48 | /******************************************************************************* 49 | Given a pointer, returns its Mach-O image and image size. 50 | 51 | @param pointer -> Required pointer. 52 | @param image <- Optional returned pointer to image (really a 53 | mach_header). 54 | @param size <- Optional returned size of the image. 55 | @param jumpTableOffset <- Optional returned offset of jump table within image (useful on intel) 56 | @param jumpTableSize <- Optional returned size of jump table (useful on intel) 57 | @result <- mach_error_t 58 | 59 | ***************************************************************************/ 60 | 61 | mach_error_t 62 | machImageForPointer( 63 | const void *pointer, 64 | const void **image, 65 | unsigned long *size, 66 | unsigned int *jumpTableOffset, 67 | unsigned int *jumpTableSize ); 68 | 69 | __END_DECLS 70 | #endif // _mach_inject_ -------------------------------------------------------------------------------- /osxinj/osxinj.xcodeproj/xcuserdata/scen.xcuserdatad/xcschemes/osxinj.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /testapp/testapp.xcodeproj/xcuserdata/scen.xcuserdatad/xcschemes/testapp.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /bootstrap/bootstrap.xcodeproj/xcuserdata/scen.xcuserdatad/xcschemes/BuildAll.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 57 | 63 | 64 | 65 | 66 | 67 | 72 | 73 | 74 | 75 | 81 | 82 | 83 | 84 | 94 | 95 | 101 | 102 | 103 | 104 | 105 | 106 | 112 | 113 | 115 | 116 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /testdylib/testdylib.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C46F6DA717B41E21000369C2 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C46F6DA617B41E21000369C2 /* main.cpp */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXFileReference section */ 14 | C46F6D8D17B41DD4000369C2 /* testdylib.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = testdylib.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; 15 | C46F6DA617B41E21000369C2 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 16 | /* End PBXFileReference section */ 17 | 18 | /* Begin PBXFrameworksBuildPhase section */ 19 | C46F6D8A17B41DD4000369C2 /* Frameworks */ = { 20 | isa = PBXFrameworksBuildPhase; 21 | buildActionMask = 2147483647; 22 | files = ( 23 | ); 24 | runOnlyForDeploymentPostprocessing = 0; 25 | }; 26 | /* End PBXFrameworksBuildPhase section */ 27 | 28 | /* Begin PBXGroup section */ 29 | C46F6D8417B41DD4000369C2 = { 30 | isa = PBXGroup; 31 | children = ( 32 | C46F6DA417B41E0C000369C2 /* Source */, 33 | C46F6D8E17B41DD4000369C2 /* Products */, 34 | ); 35 | sourceTree = ""; 36 | }; 37 | C46F6D8E17B41DD4000369C2 /* Products */ = { 38 | isa = PBXGroup; 39 | children = ( 40 | C46F6D8D17B41DD4000369C2 /* testdylib.dylib */, 41 | ); 42 | name = Products; 43 | sourceTree = ""; 44 | }; 45 | C46F6DA417B41E0C000369C2 /* Source */ = { 46 | isa = PBXGroup; 47 | children = ( 48 | C46F6DA617B41E21000369C2 /* main.cpp */, 49 | ); 50 | name = Source; 51 | sourceTree = ""; 52 | }; 53 | /* End PBXGroup section */ 54 | 55 | /* Begin PBXHeadersBuildPhase section */ 56 | C46F6D8B17B41DD4000369C2 /* Headers */ = { 57 | isa = PBXHeadersBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | /* End PBXHeadersBuildPhase section */ 64 | 65 | /* Begin PBXNativeTarget section */ 66 | C46F6D8C17B41DD4000369C2 /* testdylib */ = { 67 | isa = PBXNativeTarget; 68 | buildConfigurationList = C46F6D9117B41DD4000369C2 /* Build configuration list for PBXNativeTarget "testdylib" */; 69 | buildPhases = ( 70 | C46F6D8917B41DD4000369C2 /* Sources */, 71 | C46F6D8A17B41DD4000369C2 /* Frameworks */, 72 | C46F6D8B17B41DD4000369C2 /* Headers */, 73 | ); 74 | buildRules = ( 75 | ); 76 | dependencies = ( 77 | ); 78 | name = testdylib; 79 | productName = testdylib; 80 | productReference = C46F6D8D17B41DD4000369C2 /* testdylib.dylib */; 81 | productType = "com.apple.product-type.library.dynamic"; 82 | }; 83 | /* End PBXNativeTarget section */ 84 | 85 | /* Begin PBXProject section */ 86 | C46F6D8517B41DD4000369C2 /* Project object */ = { 87 | isa = PBXProject; 88 | attributes = { 89 | LastUpgradeCheck = 0460; 90 | ORGANIZATIONNAME = stanleycen; 91 | }; 92 | buildConfigurationList = C46F6D8817B41DD4000369C2 /* Build configuration list for PBXProject "testdylib" */; 93 | compatibilityVersion = "Xcode 3.2"; 94 | developmentRegion = English; 95 | hasScannedForEncodings = 0; 96 | knownRegions = ( 97 | en, 98 | ); 99 | mainGroup = C46F6D8417B41DD4000369C2; 100 | productRefGroup = C46F6D8E17B41DD4000369C2 /* Products */; 101 | projectDirPath = ""; 102 | projectRoot = ""; 103 | targets = ( 104 | C46F6D8C17B41DD4000369C2 /* testdylib */, 105 | ); 106 | }; 107 | /* End PBXProject section */ 108 | 109 | /* Begin PBXSourcesBuildPhase section */ 110 | C46F6D8917B41DD4000369C2 /* Sources */ = { 111 | isa = PBXSourcesBuildPhase; 112 | buildActionMask = 2147483647; 113 | files = ( 114 | C46F6DA717B41E21000369C2 /* main.cpp in Sources */, 115 | ); 116 | runOnlyForDeploymentPostprocessing = 0; 117 | }; 118 | /* End PBXSourcesBuildPhase section */ 119 | 120 | /* Begin XCBuildConfiguration section */ 121 | C46F6D8F17B41DD4000369C2 /* Debug */ = { 122 | isa = XCBuildConfiguration; 123 | buildSettings = { 124 | ALWAYS_SEARCH_USER_PATHS = NO; 125 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 126 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 127 | CLANG_CXX_LIBRARY = "libc++"; 128 | CLANG_WARN_CONSTANT_CONVERSION = YES; 129 | CLANG_WARN_EMPTY_BODY = YES; 130 | CLANG_WARN_ENUM_CONVERSION = YES; 131 | CLANG_WARN_INT_CONVERSION = YES; 132 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 133 | COPY_PHASE_STRIP = NO; 134 | GCC_C_LANGUAGE_STANDARD = gnu99; 135 | GCC_DYNAMIC_NO_PIC = NO; 136 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 137 | GCC_OPTIMIZATION_LEVEL = 0; 138 | GCC_PREPROCESSOR_DEFINITIONS = ( 139 | "DEBUG=1", 140 | "$(inherited)", 141 | ); 142 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 143 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 144 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 145 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 146 | GCC_WARN_UNUSED_VARIABLE = YES; 147 | MACOSX_DEPLOYMENT_TARGET = 10.8; 148 | ONLY_ACTIVE_ARCH = YES; 149 | SDKROOT = macosx; 150 | }; 151 | name = Debug; 152 | }; 153 | C46F6D9017B41DD4000369C2 /* Release */ = { 154 | isa = XCBuildConfiguration; 155 | buildSettings = { 156 | ALWAYS_SEARCH_USER_PATHS = NO; 157 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 158 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 159 | CLANG_CXX_LIBRARY = "libc++"; 160 | CLANG_WARN_CONSTANT_CONVERSION = YES; 161 | CLANG_WARN_EMPTY_BODY = YES; 162 | CLANG_WARN_ENUM_CONVERSION = YES; 163 | CLANG_WARN_INT_CONVERSION = YES; 164 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 165 | COPY_PHASE_STRIP = YES; 166 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 167 | GCC_C_LANGUAGE_STANDARD = gnu99; 168 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 169 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 170 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 171 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 172 | GCC_WARN_UNUSED_VARIABLE = YES; 173 | MACOSX_DEPLOYMENT_TARGET = 10.8; 174 | SDKROOT = macosx; 175 | }; 176 | name = Release; 177 | }; 178 | C46F6D9217B41DD4000369C2 /* Debug */ = { 179 | isa = XCBuildConfiguration; 180 | buildSettings = { 181 | ARCHS = "$(ARCHS_STANDARD)"; 182 | PRODUCT_NAME = "$(TARGET_NAME)"; 183 | }; 184 | name = Debug; 185 | }; 186 | C46F6D9317B41DD4000369C2 /* Release */ = { 187 | isa = XCBuildConfiguration; 188 | buildSettings = { 189 | ARCHS = "$(ARCHS_STANDARD)"; 190 | PRODUCT_NAME = "$(TARGET_NAME)"; 191 | }; 192 | name = Release; 193 | }; 194 | /* End XCBuildConfiguration section */ 195 | 196 | /* Begin XCConfigurationList section */ 197 | C46F6D8817B41DD4000369C2 /* Build configuration list for PBXProject "testdylib" */ = { 198 | isa = XCConfigurationList; 199 | buildConfigurations = ( 200 | C46F6D8F17B41DD4000369C2 /* Debug */, 201 | C46F6D9017B41DD4000369C2 /* Release */, 202 | ); 203 | defaultConfigurationIsVisible = 0; 204 | defaultConfigurationName = Release; 205 | }; 206 | C46F6D9117B41DD4000369C2 /* Build configuration list for PBXNativeTarget "testdylib" */ = { 207 | isa = XCConfigurationList; 208 | buildConfigurations = ( 209 | C46F6D9217B41DD4000369C2 /* Debug */, 210 | C46F6D9317B41DD4000369C2 /* Release */, 211 | ); 212 | defaultConfigurationIsVisible = 0; 213 | defaultConfigurationName = Release; 214 | }; 215 | /* End XCConfigurationList section */ 216 | }; 217 | rootObject = C46F6D8517B41DD4000369C2 /* Project object */; 218 | } 219 | -------------------------------------------------------------------------------- /testapp/testapp.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C46F6D8317B41DC2000369C2 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C46F6D8217B41DC2000369C2 /* main.cpp */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | C46F6D7417B41D6E000369C2 /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = /usr/share/man/man1/; 18 | dstSubfolderSpec = 0; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 1; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | C46F6D7617B41D6E000369C2 /* testapp */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testapp; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | C46F6D8217B41DC2000369C2 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = SOURCE_ROOT; }; 28 | /* End PBXFileReference section */ 29 | 30 | /* Begin PBXFrameworksBuildPhase section */ 31 | C46F6D7317B41D6E000369C2 /* Frameworks */ = { 32 | isa = PBXFrameworksBuildPhase; 33 | buildActionMask = 2147483647; 34 | files = ( 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXFrameworksBuildPhase section */ 39 | 40 | /* Begin PBXGroup section */ 41 | C46F6D6D17B41D6E000369C2 = { 42 | isa = PBXGroup; 43 | children = ( 44 | C46F6D7817B41D6E000369C2 /* Source */, 45 | C46F6D7717B41D6E000369C2 /* Products */, 46 | ); 47 | sourceTree = ""; 48 | }; 49 | C46F6D7717B41D6E000369C2 /* Products */ = { 50 | isa = PBXGroup; 51 | children = ( 52 | C46F6D7617B41D6E000369C2 /* testapp */, 53 | ); 54 | name = Products; 55 | sourceTree = ""; 56 | }; 57 | C46F6D7817B41D6E000369C2 /* Source */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | C46F6D8217B41DC2000369C2 /* main.cpp */, 61 | ); 62 | name = Source; 63 | path = testapp; 64 | sourceTree = ""; 65 | }; 66 | /* End PBXGroup section */ 67 | 68 | /* Begin PBXNativeTarget section */ 69 | C46F6D7517B41D6E000369C2 /* testapp */ = { 70 | isa = PBXNativeTarget; 71 | buildConfigurationList = C46F6D7F17B41D6E000369C2 /* Build configuration list for PBXNativeTarget "testapp" */; 72 | buildPhases = ( 73 | C46F6D7217B41D6E000369C2 /* Sources */, 74 | C46F6D7317B41D6E000369C2 /* Frameworks */, 75 | C46F6D7417B41D6E000369C2 /* CopyFiles */, 76 | ); 77 | buildRules = ( 78 | ); 79 | dependencies = ( 80 | ); 81 | name = testapp; 82 | productName = testapp; 83 | productReference = C46F6D7617B41D6E000369C2 /* testapp */; 84 | productType = "com.apple.product-type.tool"; 85 | }; 86 | /* End PBXNativeTarget section */ 87 | 88 | /* Begin PBXProject section */ 89 | C46F6D6E17B41D6E000369C2 /* Project object */ = { 90 | isa = PBXProject; 91 | attributes = { 92 | LastUpgradeCheck = 0460; 93 | ORGANIZATIONNAME = stanleycen; 94 | }; 95 | buildConfigurationList = C46F6D7117B41D6E000369C2 /* Build configuration list for PBXProject "testapp" */; 96 | compatibilityVersion = "Xcode 3.2"; 97 | developmentRegion = English; 98 | hasScannedForEncodings = 0; 99 | knownRegions = ( 100 | en, 101 | ); 102 | mainGroup = C46F6D6D17B41D6E000369C2; 103 | productRefGroup = C46F6D7717B41D6E000369C2 /* Products */; 104 | projectDirPath = ""; 105 | projectRoot = ""; 106 | targets = ( 107 | C46F6D7517B41D6E000369C2 /* testapp */, 108 | ); 109 | }; 110 | /* End PBXProject section */ 111 | 112 | /* Begin PBXSourcesBuildPhase section */ 113 | C46F6D7217B41D6E000369C2 /* Sources */ = { 114 | isa = PBXSourcesBuildPhase; 115 | buildActionMask = 2147483647; 116 | files = ( 117 | C46F6D8317B41DC2000369C2 /* main.cpp in Sources */, 118 | ); 119 | runOnlyForDeploymentPostprocessing = 0; 120 | }; 121 | /* End PBXSourcesBuildPhase section */ 122 | 123 | /* Begin XCBuildConfiguration section */ 124 | C46F6D7D17B41D6E000369C2 /* Debug */ = { 125 | isa = XCBuildConfiguration; 126 | buildSettings = { 127 | ALWAYS_SEARCH_USER_PATHS = NO; 128 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 129 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 130 | CLANG_CXX_LIBRARY = "libc++"; 131 | CLANG_WARN_CONSTANT_CONVERSION = YES; 132 | CLANG_WARN_EMPTY_BODY = YES; 133 | CLANG_WARN_ENUM_CONVERSION = YES; 134 | CLANG_WARN_INT_CONVERSION = YES; 135 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 136 | COPY_PHASE_STRIP = NO; 137 | GCC_C_LANGUAGE_STANDARD = gnu99; 138 | GCC_DYNAMIC_NO_PIC = NO; 139 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 140 | GCC_OPTIMIZATION_LEVEL = 0; 141 | GCC_PREPROCESSOR_DEFINITIONS = ( 142 | "DEBUG=1", 143 | "$(inherited)", 144 | ); 145 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 146 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 147 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 148 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 149 | GCC_WARN_UNUSED_VARIABLE = YES; 150 | MACOSX_DEPLOYMENT_TARGET = 10.8; 151 | ONLY_ACTIVE_ARCH = YES; 152 | SDKROOT = macosx; 153 | }; 154 | name = Debug; 155 | }; 156 | C46F6D7E17B41D6E000369C2 /* Release */ = { 157 | isa = XCBuildConfiguration; 158 | buildSettings = { 159 | ALWAYS_SEARCH_USER_PATHS = NO; 160 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 161 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 162 | CLANG_CXX_LIBRARY = "libc++"; 163 | CLANG_WARN_CONSTANT_CONVERSION = YES; 164 | CLANG_WARN_EMPTY_BODY = YES; 165 | CLANG_WARN_ENUM_CONVERSION = YES; 166 | CLANG_WARN_INT_CONVERSION = YES; 167 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 168 | COPY_PHASE_STRIP = YES; 169 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 170 | GCC_C_LANGUAGE_STANDARD = gnu99; 171 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 172 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 173 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 174 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 175 | GCC_WARN_UNUSED_VARIABLE = YES; 176 | MACOSX_DEPLOYMENT_TARGET = 10.8; 177 | SDKROOT = macosx; 178 | }; 179 | name = Release; 180 | }; 181 | C46F6D8017B41D6E000369C2 /* Debug */ = { 182 | isa = XCBuildConfiguration; 183 | buildSettings = { 184 | ARCHS = "$(ARCHS_STANDARD)"; 185 | PRODUCT_NAME = "$(TARGET_NAME)"; 186 | }; 187 | name = Debug; 188 | }; 189 | C46F6D8117B41D6E000369C2 /* Release */ = { 190 | isa = XCBuildConfiguration; 191 | buildSettings = { 192 | ARCHS = "$(ARCHS_STANDARD)"; 193 | PRODUCT_NAME = "$(TARGET_NAME)"; 194 | }; 195 | name = Release; 196 | }; 197 | /* End XCBuildConfiguration section */ 198 | 199 | /* Begin XCConfigurationList section */ 200 | C46F6D7117B41D6E000369C2 /* Build configuration list for PBXProject "testapp" */ = { 201 | isa = XCConfigurationList; 202 | buildConfigurations = ( 203 | C46F6D7D17B41D6E000369C2 /* Debug */, 204 | C46F6D7E17B41D6E000369C2 /* Release */, 205 | ); 206 | defaultConfigurationIsVisible = 0; 207 | defaultConfigurationName = Release; 208 | }; 209 | C46F6D7F17B41D6E000369C2 /* Build configuration list for PBXNativeTarget "testapp" */ = { 210 | isa = XCConfigurationList; 211 | buildConfigurations = ( 212 | C46F6D8017B41D6E000369C2 /* Debug */, 213 | C46F6D8117B41D6E000369C2 /* Release */, 214 | ); 215 | defaultConfigurationIsVisible = 0; 216 | defaultConfigurationName = Release; 217 | }; 218 | /* End XCConfigurationList section */ 219 | }; 220 | rootObject = C46F6D6E17B41D6E000369C2 /* Project object */; 221 | } 222 | -------------------------------------------------------------------------------- /bootstrap/bootstrap.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C46F6DA917B41E29000369C2 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C46F6DA817B41E29000369C2 /* main.cpp */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXFileReference section */ 14 | C46F6D9D17B41DE2000369C2 /* bootstrap.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = bootstrap.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; 15 | C46F6DA817B41E29000369C2 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 16 | /* End PBXFileReference section */ 17 | 18 | /* Begin PBXFrameworksBuildPhase section */ 19 | C46F6D9A17B41DE2000369C2 /* Frameworks */ = { 20 | isa = PBXFrameworksBuildPhase; 21 | buildActionMask = 2147483647; 22 | files = ( 23 | ); 24 | runOnlyForDeploymentPostprocessing = 0; 25 | }; 26 | /* End PBXFrameworksBuildPhase section */ 27 | 28 | /* Begin PBXGroup section */ 29 | C46F6D9417B41DE2000369C2 = { 30 | isa = PBXGroup; 31 | children = ( 32 | C46F6DA517B41E15000369C2 /* Source */, 33 | C46F6D9E17B41DE2000369C2 /* Products */, 34 | ); 35 | sourceTree = ""; 36 | }; 37 | C46F6D9E17B41DE2000369C2 /* Products */ = { 38 | isa = PBXGroup; 39 | children = ( 40 | C46F6D9D17B41DE2000369C2 /* bootstrap.dylib */, 41 | ); 42 | name = Products; 43 | sourceTree = ""; 44 | }; 45 | C46F6DA517B41E15000369C2 /* Source */ = { 46 | isa = PBXGroup; 47 | children = ( 48 | C46F6DA817B41E29000369C2 /* main.cpp */, 49 | ); 50 | name = Source; 51 | sourceTree = ""; 52 | }; 53 | /* End PBXGroup section */ 54 | 55 | /* Begin PBXHeadersBuildPhase section */ 56 | C46F6D9B17B41DE2000369C2 /* Headers */ = { 57 | isa = PBXHeadersBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | /* End PBXHeadersBuildPhase section */ 64 | 65 | /* Begin PBXNativeTarget section */ 66 | C46F6D9C17B41DE2000369C2 /* bootstrap */ = { 67 | isa = PBXNativeTarget; 68 | buildConfigurationList = C46F6DA117B41DE2000369C2 /* Build configuration list for PBXNativeTarget "bootstrap" */; 69 | buildPhases = ( 70 | C46F6D9917B41DE2000369C2 /* Sources */, 71 | C46F6D9A17B41DE2000369C2 /* Frameworks */, 72 | C46F6D9B17B41DE2000369C2 /* Headers */, 73 | ); 74 | buildRules = ( 75 | ); 76 | dependencies = ( 77 | ); 78 | name = bootstrap; 79 | productName = bootstrap; 80 | productReference = C46F6D9D17B41DE2000369C2 /* bootstrap.dylib */; 81 | productType = "com.apple.product-type.library.dynamic"; 82 | }; 83 | /* End PBXNativeTarget section */ 84 | 85 | /* Begin PBXProject section */ 86 | C46F6D9517B41DE2000369C2 /* Project object */ = { 87 | isa = PBXProject; 88 | attributes = { 89 | LastUpgradeCheck = 0460; 90 | ORGANIZATIONNAME = stanleycen; 91 | }; 92 | buildConfigurationList = C46F6D9817B41DE2000369C2 /* Build configuration list for PBXProject "bootstrap" */; 93 | compatibilityVersion = "Xcode 3.2"; 94 | developmentRegion = English; 95 | hasScannedForEncodings = 0; 96 | knownRegions = ( 97 | en, 98 | ); 99 | mainGroup = C46F6D9417B41DE2000369C2; 100 | productRefGroup = C46F6D9E17B41DE2000369C2 /* Products */; 101 | projectDirPath = ""; 102 | projectRoot = ""; 103 | targets = ( 104 | C46F6D9C17B41DE2000369C2 /* bootstrap */, 105 | ); 106 | }; 107 | /* End PBXProject section */ 108 | 109 | /* Begin PBXSourcesBuildPhase section */ 110 | C46F6D9917B41DE2000369C2 /* Sources */ = { 111 | isa = PBXSourcesBuildPhase; 112 | buildActionMask = 2147483647; 113 | files = ( 114 | C46F6DA917B41E29000369C2 /* main.cpp in Sources */, 115 | ); 116 | runOnlyForDeploymentPostprocessing = 0; 117 | }; 118 | /* End PBXSourcesBuildPhase section */ 119 | 120 | /* Begin XCBuildConfiguration section */ 121 | C46F6D9F17B41DE2000369C2 /* Debug */ = { 122 | isa = XCBuildConfiguration; 123 | buildSettings = { 124 | ALWAYS_SEARCH_USER_PATHS = NO; 125 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 126 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 127 | CLANG_CXX_LIBRARY = "libc++"; 128 | CLANG_WARN_CONSTANT_CONVERSION = YES; 129 | CLANG_WARN_EMPTY_BODY = YES; 130 | CLANG_WARN_ENUM_CONVERSION = YES; 131 | CLANG_WARN_INT_CONVERSION = YES; 132 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 133 | COPY_PHASE_STRIP = NO; 134 | GCC_C_LANGUAGE_STANDARD = gnu99; 135 | GCC_DYNAMIC_NO_PIC = NO; 136 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 137 | GCC_OPTIMIZATION_LEVEL = 0; 138 | GCC_PREPROCESSOR_DEFINITIONS = ( 139 | "DEBUG=1", 140 | "$(inherited)", 141 | ); 142 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 143 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 144 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 145 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 146 | GCC_WARN_UNUSED_VARIABLE = YES; 147 | MACOSX_DEPLOYMENT_TARGET = 10.12; 148 | ONLY_ACTIVE_ARCH = YES; 149 | SDKROOT = macosx; 150 | }; 151 | name = Debug; 152 | }; 153 | C46F6DA017B41DE2000369C2 /* Release */ = { 154 | isa = XCBuildConfiguration; 155 | buildSettings = { 156 | ALWAYS_SEARCH_USER_PATHS = NO; 157 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 158 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 159 | CLANG_CXX_LIBRARY = "libc++"; 160 | CLANG_WARN_CONSTANT_CONVERSION = YES; 161 | CLANG_WARN_EMPTY_BODY = YES; 162 | CLANG_WARN_ENUM_CONVERSION = YES; 163 | CLANG_WARN_INT_CONVERSION = YES; 164 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 165 | COPY_PHASE_STRIP = YES; 166 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 167 | GCC_C_LANGUAGE_STANDARD = gnu99; 168 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 169 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 170 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 171 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 172 | GCC_WARN_UNUSED_VARIABLE = YES; 173 | MACOSX_DEPLOYMENT_TARGET = 10.12; 174 | SDKROOT = macosx; 175 | }; 176 | name = Release; 177 | }; 178 | C46F6DA217B41DE2000369C2 /* Debug */ = { 179 | isa = XCBuildConfiguration; 180 | buildSettings = { 181 | ARCHS = "$(ARCHS_STANDARD)"; 182 | EXECUTABLE_PREFIX = ""; 183 | PRODUCT_NAME = "$(TARGET_NAME)"; 184 | }; 185 | name = Debug; 186 | }; 187 | C46F6DA317B41DE2000369C2 /* Release */ = { 188 | isa = XCBuildConfiguration; 189 | buildSettings = { 190 | ARCHS = "$(ARCHS_STANDARD)"; 191 | EXECUTABLE_PREFIX = ""; 192 | PRODUCT_NAME = "$(TARGET_NAME)"; 193 | }; 194 | name = Release; 195 | }; 196 | /* End XCBuildConfiguration section */ 197 | 198 | /* Begin XCConfigurationList section */ 199 | C46F6D9817B41DE2000369C2 /* Build configuration list for PBXProject "bootstrap" */ = { 200 | isa = XCConfigurationList; 201 | buildConfigurations = ( 202 | C46F6D9F17B41DE2000369C2 /* Debug */, 203 | C46F6DA017B41DE2000369C2 /* Release */, 204 | ); 205 | defaultConfigurationIsVisible = 0; 206 | defaultConfigurationName = Release; 207 | }; 208 | C46F6DA117B41DE2000369C2 /* Build configuration list for PBXNativeTarget "bootstrap" */ = { 209 | isa = XCConfigurationList; 210 | buildConfigurations = ( 211 | C46F6DA217B41DE2000369C2 /* Debug */, 212 | C46F6DA317B41DE2000369C2 /* Release */, 213 | ); 214 | defaultConfigurationIsVisible = 0; 215 | defaultConfigurationName = Release; 216 | }; 217 | /* End XCConfigurationList section */ 218 | }; 219 | rootObject = C46F6D9517B41DE2000369C2 /* Project object */; 220 | } 221 | -------------------------------------------------------------------------------- /osxinj/osxinj.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C438F97217B4222E00C028FE /* injector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C46F6D6717B41D33000369C2 /* injector.cpp */; }; 11 | C438F97317B4222E00C028FE /* injector.h in Sources */ = {isa = PBXBuildFile; fileRef = C46F6D6817B41D33000369C2 /* injector.h */; }; 12 | C438F97417B4222E00C028FE /* mach_inject.c in Sources */ = {isa = PBXBuildFile; fileRef = C46F6D6917B41D33000369C2 /* mach_inject.c */; }; 13 | C438F97517B4222E00C028FE /* mach_inject.h in Sources */ = {isa = PBXBuildFile; fileRef = C46F6D6A17B41D33000369C2 /* mach_inject.h */; }; 14 | C438F97617B4222E00C028FE /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C46F6D6B17B41D33000369C2 /* main.cpp */; }; 15 | C438F97717B4246F00C028FE /* osxinj in CopyFiles */ = {isa = PBXBuildFile; fileRef = C46F6D2017B41A53000369C2 /* osxinj */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXCopyFilesBuildPhase section */ 19 | C46F6D1E17B41A53000369C2 /* CopyFiles */ = { 20 | isa = PBXCopyFilesBuildPhase; 21 | buildActionMask = 8; 22 | dstPath = bin; 23 | dstSubfolderSpec = 0; 24 | files = ( 25 | C438F97717B4246F00C028FE /* osxinj in CopyFiles */, 26 | ); 27 | runOnlyForDeploymentPostprocessing = 1; 28 | }; 29 | /* End PBXCopyFilesBuildPhase section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | C46F6D2017B41A53000369C2 /* osxinj */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = osxinj; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | C46F6D6717B41D33000369C2 /* injector.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = injector.cpp; sourceTree = SOURCE_ROOT; }; 34 | C46F6D6817B41D33000369C2 /* injector.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = injector.h; sourceTree = SOURCE_ROOT; }; 35 | C46F6D6917B41D33000369C2 /* mach_inject.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = mach_inject.c; sourceTree = SOURCE_ROOT; }; 36 | C46F6D6A17B41D33000369C2 /* mach_inject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mach_inject.h; sourceTree = SOURCE_ROOT; }; 37 | C46F6D6B17B41D33000369C2 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = SOURCE_ROOT; }; 38 | /* End PBXFileReference section */ 39 | 40 | /* Begin PBXFrameworksBuildPhase section */ 41 | C46F6D1D17B41A53000369C2 /* Frameworks */ = { 42 | isa = PBXFrameworksBuildPhase; 43 | buildActionMask = 2147483647; 44 | files = ( 45 | ); 46 | runOnlyForDeploymentPostprocessing = 0; 47 | }; 48 | /* End PBXFrameworksBuildPhase section */ 49 | 50 | /* Begin PBXGroup section */ 51 | C46F6D1717B41A53000369C2 = { 52 | isa = PBXGroup; 53 | children = ( 54 | C46F6D2217B41A53000369C2 /* Source */, 55 | C46F6D2117B41A53000369C2 /* Products */, 56 | ); 57 | sourceTree = ""; 58 | }; 59 | C46F6D2117B41A53000369C2 /* Products */ = { 60 | isa = PBXGroup; 61 | children = ( 62 | C46F6D2017B41A53000369C2 /* osxinj */, 63 | ); 64 | name = Products; 65 | sourceTree = ""; 66 | }; 67 | C46F6D2217B41A53000369C2 /* Source */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | C46F6D6717B41D33000369C2 /* injector.cpp */, 71 | C46F6D6817B41D33000369C2 /* injector.h */, 72 | C46F6D6917B41D33000369C2 /* mach_inject.c */, 73 | C46F6D6A17B41D33000369C2 /* mach_inject.h */, 74 | C46F6D6B17B41D33000369C2 /* main.cpp */, 75 | ); 76 | name = Source; 77 | path = osxinj; 78 | sourceTree = ""; 79 | }; 80 | /* End PBXGroup section */ 81 | 82 | /* Begin PBXNativeTarget section */ 83 | C46F6D1F17B41A53000369C2 /* osxinj */ = { 84 | isa = PBXNativeTarget; 85 | buildConfigurationList = C46F6D2917B41A53000369C2 /* Build configuration list for PBXNativeTarget "osxinj" */; 86 | buildPhases = ( 87 | C46F6D1C17B41A53000369C2 /* Sources */, 88 | C46F6D1D17B41A53000369C2 /* Frameworks */, 89 | C46F6D1E17B41A53000369C2 /* CopyFiles */, 90 | ); 91 | buildRules = ( 92 | ); 93 | dependencies = ( 94 | ); 95 | name = osxinj; 96 | productName = osxinj; 97 | productReference = C46F6D2017B41A53000369C2 /* osxinj */; 98 | productType = "com.apple.product-type.tool"; 99 | }; 100 | /* End PBXNativeTarget section */ 101 | 102 | /* Begin PBXProject section */ 103 | C46F6D1817B41A53000369C2 /* Project object */ = { 104 | isa = PBXProject; 105 | attributes = { 106 | LastUpgradeCheck = 0460; 107 | ORGANIZATIONNAME = stanleycen; 108 | }; 109 | buildConfigurationList = C46F6D1B17B41A53000369C2 /* Build configuration list for PBXProject "osxinj" */; 110 | compatibilityVersion = "Xcode 3.2"; 111 | developmentRegion = English; 112 | hasScannedForEncodings = 0; 113 | knownRegions = ( 114 | en, 115 | ); 116 | mainGroup = C46F6D1717B41A53000369C2; 117 | productRefGroup = C46F6D2117B41A53000369C2 /* Products */; 118 | projectDirPath = ""; 119 | projectRoot = ""; 120 | targets = ( 121 | C46F6D1F17B41A53000369C2 /* osxinj */, 122 | ); 123 | }; 124 | /* End PBXProject section */ 125 | 126 | /* Begin PBXSourcesBuildPhase section */ 127 | C46F6D1C17B41A53000369C2 /* Sources */ = { 128 | isa = PBXSourcesBuildPhase; 129 | buildActionMask = 2147483647; 130 | files = ( 131 | C438F97217B4222E00C028FE /* injector.cpp in Sources */, 132 | C438F97317B4222E00C028FE /* injector.h in Sources */, 133 | C438F97417B4222E00C028FE /* mach_inject.c in Sources */, 134 | C438F97517B4222E00C028FE /* mach_inject.h in Sources */, 135 | C438F97617B4222E00C028FE /* main.cpp in Sources */, 136 | ); 137 | runOnlyForDeploymentPostprocessing = 0; 138 | }; 139 | /* End PBXSourcesBuildPhase section */ 140 | 141 | /* Begin XCBuildConfiguration section */ 142 | C46F6D2717B41A53000369C2 /* Debug */ = { 143 | isa = XCBuildConfiguration; 144 | buildSettings = { 145 | ALWAYS_SEARCH_USER_PATHS = NO; 146 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 147 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 148 | CLANG_CXX_LIBRARY = "libc++"; 149 | CLANG_ENABLE_OBJC_ARC = YES; 150 | CLANG_WARN_CONSTANT_CONVERSION = YES; 151 | CLANG_WARN_EMPTY_BODY = YES; 152 | CLANG_WARN_ENUM_CONVERSION = YES; 153 | CLANG_WARN_INT_CONVERSION = YES; 154 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 155 | COPY_PHASE_STRIP = NO; 156 | GCC_C_LANGUAGE_STANDARD = gnu99; 157 | GCC_DYNAMIC_NO_PIC = NO; 158 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 159 | GCC_OPTIMIZATION_LEVEL = 0; 160 | GCC_PREPROCESSOR_DEFINITIONS = ( 161 | "DEBUG=1", 162 | "$(inherited)", 163 | ); 164 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 165 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 166 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 167 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 168 | GCC_WARN_UNUSED_VARIABLE = YES; 169 | MACOSX_DEPLOYMENT_TARGET = 10.8; 170 | ONLY_ACTIVE_ARCH = YES; 171 | SDKROOT = macosx; 172 | }; 173 | name = Debug; 174 | }; 175 | C46F6D2817B41A53000369C2 /* Release */ = { 176 | isa = XCBuildConfiguration; 177 | buildSettings = { 178 | ALWAYS_SEARCH_USER_PATHS = NO; 179 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 180 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 181 | CLANG_CXX_LIBRARY = "libc++"; 182 | CLANG_ENABLE_OBJC_ARC = YES; 183 | CLANG_WARN_CONSTANT_CONVERSION = YES; 184 | CLANG_WARN_EMPTY_BODY = YES; 185 | CLANG_WARN_ENUM_CONVERSION = YES; 186 | CLANG_WARN_INT_CONVERSION = YES; 187 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 188 | COPY_PHASE_STRIP = YES; 189 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 190 | GCC_C_LANGUAGE_STANDARD = gnu99; 191 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 192 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 193 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 194 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 195 | GCC_WARN_UNUSED_VARIABLE = YES; 196 | MACOSX_DEPLOYMENT_TARGET = 10.8; 197 | SDKROOT = macosx; 198 | }; 199 | name = Release; 200 | }; 201 | C46F6D2A17B41A53000369C2 /* Debug */ = { 202 | isa = XCBuildConfiguration; 203 | buildSettings = { 204 | ARCHS = "$(ARCHS_STANDARD)"; 205 | PRODUCT_NAME = "$(TARGET_NAME)"; 206 | }; 207 | name = Debug; 208 | }; 209 | C46F6D2B17B41A53000369C2 /* Release */ = { 210 | isa = XCBuildConfiguration; 211 | buildSettings = { 212 | ARCHS = "$(ARCHS_STANDARD)"; 213 | PRODUCT_NAME = "$(TARGET_NAME)"; 214 | }; 215 | name = Release; 216 | }; 217 | /* End XCBuildConfiguration section */ 218 | 219 | /* Begin XCConfigurationList section */ 220 | C46F6D1B17B41A53000369C2 /* Build configuration list for PBXProject "osxinj" */ = { 221 | isa = XCConfigurationList; 222 | buildConfigurations = ( 223 | C46F6D2717B41A53000369C2 /* Debug */, 224 | C46F6D2817B41A53000369C2 /* Release */, 225 | ); 226 | defaultConfigurationIsVisible = 0; 227 | defaultConfigurationName = Release; 228 | }; 229 | C46F6D2917B41A53000369C2 /* Build configuration list for PBXNativeTarget "osxinj" */ = { 230 | isa = XCConfigurationList; 231 | buildConfigurations = ( 232 | C46F6D2A17B41A53000369C2 /* Debug */, 233 | C46F6D2B17B41A53000369C2 /* Release */, 234 | ); 235 | defaultConfigurationIsVisible = 0; 236 | defaultConfigurationName = Release; 237 | }; 238 | /* End XCConfigurationList section */ 239 | }; 240 | rootObject = C46F6D1817B41A53000369C2 /* Project object */; 241 | } 242 | -------------------------------------------------------------------------------- /osxinj/mach_inject.c: -------------------------------------------------------------------------------- 1 | // mach_inject.c semver:1.2.0 2 | // Copyright (c) 2003-2012 Jonathan 'Wolf' Rentzsch: http://rentzsch.com 3 | // Some rights reserved: http://opensource.org/licenses/mit 4 | // https://github.com/rentzsch/mach_inject 5 | 6 | #include "mach_inject.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include // for malloc() 15 | #include // for printf() 16 | #include // for fat structure decoding 17 | #include // to know which is local arch 18 | #include // for open/close 19 | // for mmap() 20 | #include 21 | #include 22 | 23 | #ifndef COMPILE_TIME_ASSERT( exp ) 24 | #define COMPILE_TIME_ASSERT( exp ) { switch (0) { case 0: case (exp):; } } 25 | #endif 26 | #define ASSERT_CAST( CAST_TO, CAST_FROM ) \ 27 | COMPILE_TIME_ASSERT( sizeof(CAST_TO)==sizeof(CAST_FROM) ) 28 | 29 | #if defined(__i386__) 30 | void* fixedUpImageFromImage ( 31 | const void *image, 32 | unsigned long imageSize, 33 | unsigned int jumpTableOffset, 34 | unsigned int jumpTableSize, 35 | ptrdiff_t fixUpOffset); 36 | #endif /* __i386__ */ 37 | 38 | #include 39 | #define MACH_ERROR(msg, err) { if(err != err_none) mach_error(msg, err); } 40 | 41 | /******************************************************************************* 42 | * 43 | * Interface 44 | * 45 | *******************************************************************************/ 46 | #pragma mark - 47 | #pragma mark (Interface) 48 | 49 | mach_error_t 50 | mach_inject( 51 | const mach_inject_entry threadEntry, 52 | const void *paramBlock, 53 | size_t paramSize, 54 | pid_t targetProcess, 55 | vm_size_t stackSize ) 56 | { 57 | assert( threadEntry ); 58 | assert( targetProcess > 0 ); 59 | assert( stackSize == 0 || stackSize > 1024 ); 60 | 61 | // Find the image. 62 | const void *image; 63 | unsigned long imageSize; 64 | unsigned int jumpTableOffset; 65 | unsigned int jumpTableSize; 66 | mach_error_t err = machImageForPointer( threadEntry, &image, &imageSize, &jumpTableOffset, &jumpTableSize ); 67 | fprintf(stderr, "mach_inject: found threadEntry image at: %p with size: %lu\n", image, imageSize); 68 | 69 | // Initialize stackSize to default if requested. 70 | if( stackSize == 0 ) 71 | /** @bug 72 | We only want an 8K default, fix the plop-in-the-middle code below. 73 | */ 74 | stackSize = 16 * 1024; 75 | 76 | // Convert PID to Mach Task ref. 77 | mach_port_t remoteTask = 0; 78 | if( !err ) { 79 | err = task_for_pid( mach_task_self(), targetProcess, &remoteTask ); 80 | #if defined(__i386__) || defined(__x86_64__) 81 | if (err == 5) fprintf(stderr, "Could not access task for pid %d. You probably need to add user to procmod group\n", targetProcess); 82 | #endif 83 | } 84 | 85 | /** @todo 86 | Would be nice to just allocate one block for both the remote stack 87 | *and* the remoteCode (including the parameter data block once that's 88 | written. 89 | */ 90 | 91 | // Allocate the remoteStack. 92 | vm_address_t remoteStack = (vm_address_t)NULL; 93 | if( !err ) 94 | err = vm_allocate( remoteTask, &remoteStack, stackSize, 1 ); 95 | 96 | vm_protect(remoteTask, remoteStack, stackSize, 0, VM_PROT_WRITE | VM_PROT_READ); 97 | 98 | // Allocate the code. 99 | vm_address_t remoteCode = (vm_address_t)NULL; 100 | if( !err ) 101 | err = vm_allocate( remoteTask, &remoteCode, imageSize, 1 ); 102 | err = vm_protect(remoteTask, remoteCode, imageSize, 0, VM_PROT_EXECUTE | VM_PROT_WRITE | VM_PROT_READ); 103 | if( !err ) { 104 | ASSERT_CAST( pointer_t, image ); 105 | #if defined (__ppc__) || defined (__ppc64__) || defined(__x86_64__) 106 | err = vm_write( remoteTask, remoteCode, (pointer_t) image, imageSize ); 107 | #elif defined (__i386__) 108 | // on x86, jump table use relative jump instructions (jmp), which means 109 | // the offset needs to be corrected. We thus copy the image and fix the offset by hand. 110 | ptrdiff_t fixUpOffset = (ptrdiff_t) (image - remoteCode); 111 | // printf("image=0x%X remoteCode=0x%X delta=%d\n", image, remoteCode, fixUpOffset); 112 | void * fixedUpImage = fixedUpImageFromImage(image, imageSize, jumpTableOffset, jumpTableSize, fixUpOffset); 113 | err = vm_write( remoteTask, remoteCode, (pointer_t) fixedUpImage, imageSize ); 114 | free(fixedUpImage); 115 | #endif 116 | } 117 | 118 | // Allocate the paramBlock if specified. 119 | vm_address_t remoteParamBlock = (vm_address_t)NULL; 120 | if( !err && paramBlock != NULL && paramSize ) { 121 | err = vm_allocate( remoteTask, &remoteParamBlock, paramSize, 1 ); 122 | if( !err ) { 123 | ASSERT_CAST( pointer_t, paramBlock ); 124 | err = vm_write( remoteTask, remoteParamBlock, 125 | (pointer_t) paramBlock, paramSize ); 126 | printf("wrote param with size %d\n", paramSize); 127 | } 128 | } 129 | 130 | // Calculate offsets. 131 | ptrdiff_t threadEntryOffset, imageOffset; 132 | if( !err ) { 133 | assert( (void*)threadEntry >= image && (void*)threadEntry <= (image+imageSize) ); 134 | ASSERT_CAST( void*, threadEntry ); 135 | threadEntryOffset = ((void*) threadEntry) - image; 136 | 137 | #if defined(__x86_64__) 138 | imageOffset = 0; // RIP-relative addressing 139 | #else 140 | //ASSERT_CAST( void*, remoteCode ); 141 | //imageOffset = ((void*) remoteCode) - image; 142 | // WARNING: See bug https://github.com/rentzsch/mach_star/issues/11 . Not sure about this. 143 | imageOffset = 0; 144 | #endif 145 | } 146 | 147 | // Allocate the thread. 148 | thread_act_t remoteThread; 149 | 150 | #if defined (__i386__) 151 | if( !err ) { 152 | 153 | i386_thread_state_t remoteThreadState; 154 | bzero( &remoteThreadState, sizeof(remoteThreadState) ); 155 | 156 | vm_address_t dummy_thread_struct = remoteStack; 157 | remoteStack += (stackSize / 2); // this is the real stack 158 | // (*) increase the stack, since we're simulating a CALL instruction, which normally pushes return address on the stack 159 | remoteStack -= 4; 160 | 161 | #define PARAM_COUNT 4 162 | #define STACK_CONTENTS_SIZE ((1+PARAM_COUNT) * sizeof(unsigned int)) 163 | unsigned int stackContents[1 + PARAM_COUNT]; // 1 for the return address and 1 for each param 164 | // first entry is return address (see above *) 165 | stackContents[0] = 0xDEADBEEF; // invalid return address. 166 | // then we push function parameters one by one. 167 | stackContents[1] = imageOffset; 168 | stackContents[2] = remoteParamBlock; 169 | stackContents[3] = paramSize; 170 | // We use the remote stack we allocated as the fake thread struct. We should probably use a dedicated memory zone. 171 | // We don't fill it with 0, vm_allocate did it for us 172 | stackContents[4] = dummy_thread_struct; 173 | 174 | // push stackContents 175 | err = vm_write( remoteTask, remoteStack, 176 | (pointer_t) stackContents, STACK_CONTENTS_SIZE); 177 | 178 | // set remote Program Counter 179 | remoteThreadState.__eip = (unsigned int) (remoteCode); 180 | remoteThreadState.__eip += threadEntryOffset; 181 | 182 | // set remote Stack Pointer 183 | ASSERT_CAST( unsigned int, remoteStack ); 184 | remoteThreadState.__esp = (unsigned int) remoteStack; 185 | 186 | // create thread and launch it 187 | err = thread_create_running( remoteTask, i386_THREAD_STATE, 188 | (thread_state_t) &remoteThreadState, i386_THREAD_STATE_COUNT, 189 | &remoteThread ); 190 | } 191 | #elif defined(__x86_64__) 192 | if( !err ) { 193 | 194 | x86_thread_state64_t remoteThreadState; 195 | bzero( &remoteThreadState, sizeof(remoteThreadState) ); 196 | 197 | vm_address_t dummy_thread_struct = remoteStack; 198 | remoteStack += (stackSize / 2); // this is the real stack 199 | // (*) increase the stack, since we're simulating a CALL instruction, which normally pushes return address on the stack 200 | remoteStack -= 4; 201 | 202 | #define PARAM_COUNT 0 203 | #define STACK_CONTENTS_SIZE ((1+PARAM_COUNT) * sizeof(unsigned long long)) 204 | unsigned long long stackContents[1 + PARAM_COUNT]; // 1 for the return address and 1 for each param 205 | // first entry is return address (see above *) 206 | stackContents[0] = 0x00000DEADBEA7DAD; // invalid return address. 207 | 208 | // push stackContents 209 | err = vm_write( remoteTask, remoteStack, 210 | (pointer_t) stackContents, STACK_CONTENTS_SIZE); 211 | 212 | remoteThreadState.__rdi = (unsigned long long) (imageOffset); 213 | remoteThreadState.__rsi = (unsigned long long) (remoteParamBlock); 214 | remoteThreadState.__rdx = (unsigned long long) (paramSize); 215 | remoteThreadState.__rcx = (unsigned long long) (dummy_thread_struct); 216 | 217 | // set remote Program Counter 218 | remoteThreadState.__rip = (unsigned long long) (remoteCode); 219 | remoteThreadState.__rip += threadEntryOffset; 220 | 221 | // set remote Stack Pointer 222 | ASSERT_CAST( unsigned long long, remoteStack ); 223 | remoteThreadState.__rsp = (unsigned long long) remoteStack; 224 | 225 | // create thread and launch it 226 | err = thread_create_running( remoteTask, x86_THREAD_STATE64, 227 | (thread_state_t) &remoteThreadState, x86_THREAD_STATE64_COUNT, 228 | &remoteThread ); 229 | } 230 | #else 231 | #error architecture not supported 232 | #endif 233 | 234 | if( err ) { 235 | MACH_ERROR("mach_inject failing..", err); 236 | if( remoteParamBlock ) 237 | vm_deallocate( remoteTask, remoteParamBlock, paramSize ); 238 | if( remoteCode ) 239 | vm_deallocate( remoteTask, remoteCode, imageSize ); 240 | if( remoteStack ) 241 | vm_deallocate( remoteTask, remoteStack, stackSize ); 242 | } 243 | 244 | return err; 245 | } 246 | 247 | mach_error_t 248 | machImageForPointer( 249 | const void *pointer, 250 | const void **image, 251 | unsigned long *size, 252 | unsigned int *jumpTableOffset, 253 | unsigned int *jumpTableSize ) 254 | { 255 | assert( pointer ); 256 | assert( image ); 257 | assert( size ); 258 | 259 | unsigned long p = (unsigned long) pointer; 260 | 261 | if (jumpTableOffset && jumpTableSize) { 262 | *jumpTableOffset = 0; 263 | *jumpTableSize = 0; 264 | } 265 | 266 | unsigned long imageIndex, imageCount = _dyld_image_count(); 267 | for( imageIndex = 0; imageIndex < imageCount; imageIndex++ ) { 268 | #if defined(__x86_64__) 269 | const struct mach_header_64 *header = (const struct mach_header_64 *)_dyld_get_image_header( imageIndex ); // why no function that returns mach_header_64 270 | const struct section_64 *section = getsectbynamefromheader_64( header, SEG_TEXT, SECT_TEXT ); 271 | #else 272 | const struct mach_header *header = (const struct mach_header *)_dyld_get_image_header( imageIndex ); 273 | const struct section *section = getsectbynamefromheader( header, SEG_TEXT, SECT_TEXT ); 274 | #endif 275 | if (section == 0) continue; 276 | long start = section->addr + _dyld_get_image_vmaddr_slide( imageIndex ); 277 | long stop = start + section->size; 278 | // printf("start %ld %p %s b\n", start, header, _dyld_get_image_name(imageIndex)); 279 | if( p >= start && p <= stop ) { 280 | // It is truely insane we have to stat() the file system in order 281 | // to discover the size of an in-memory data structure. 282 | const char *imageName = _dyld_get_image_name( imageIndex ); 283 | printf("image name: %s\n", imageName); 284 | assert( imageName ); 285 | struct stat sb; 286 | if( stat( imageName, &sb ) ) 287 | return unix_err( errno ); 288 | if( image ) { 289 | ASSERT_CAST( void*, header ); 290 | *image = (void*) header; 291 | } 292 | if( size ) { 293 | ;//assertUInt32( st_size ); 294 | *size = sb.st_size; 295 | 296 | // needed for Universal binaries. Check if file is fat and get image size from there. 297 | int fd = open (imageName, O_RDONLY); 298 | size_t mapSize = *size; 299 | char * fileImage = mmap (NULL, mapSize, PROT_READ, MAP_FILE|MAP_SHARED, fd, 0); 300 | 301 | assert(fileImage != MAP_FAILED); 302 | struct fat_header* fatHeader = (struct fat_header *)fileImage; 303 | if (fatHeader->magic == OSSwapBigToHostInt32(FAT_MAGIC)) { 304 | //printf("This is a fat binary\n"); 305 | uint32_t archCount = OSSwapBigToHostInt32(fatHeader->nfat_arch); 306 | 307 | NXArchInfo const *localArchInfo = NXGetLocalArchInfo(); 308 | 309 | struct fat_arch* arch = (struct fat_arch *)(fileImage + sizeof(struct fat_header)); 310 | struct fat_arch* matchingArch = NULL; 311 | 312 | int archIndex = 0; 313 | for (archIndex = 0; archIndex < archCount; archIndex++) { 314 | cpu_type_t cpuType = OSSwapBigToHostInt32(arch[archIndex].cputype); 315 | cpu_subtype_t cpuSubtype = OSSwapBigToHostInt32(arch[archIndex].cpusubtype); 316 | 317 | if (localArchInfo->cputype == cpuType) { 318 | matchingArch = arch + archIndex; 319 | if (localArchInfo->cpusubtype == cpuSubtype) break; 320 | } 321 | } 322 | 323 | if (matchingArch) { 324 | *size = OSSwapBigToHostInt32(matchingArch->size); 325 | //printf ("found arch-specific size : %p\n", *size); 326 | } 327 | } 328 | 329 | munmap (fileImage, mapSize); 330 | close (fd); 331 | } 332 | #if defined(__i386__) // this segment is only available on IA-32 333 | if (jumpTableOffset && jumpTableSize) { 334 | const struct section * jumpTableSection = getsectbynamefromheader( header, SEG_IMPORT, "__jump_table" ); 335 | if (!jumpTableSection) { 336 | unsigned char *start, *end; 337 | jumpTableSection = getsectbynamefromheader( header, SEG_TEXT, "__symbol_stub" ); 338 | /* 339 | start = end = (char *) header + jumpTableSection->offset; 340 | end += jumpTableSection->size; 341 | 342 | fprintf(stderr, "start: %p\n", start); 343 | for (; start < end; start += 6) { 344 | fprintf(stderr, "%p: %p: %p\n", 345 | start, 346 | *(void **)(start+2), 347 | **(void ***)(start+2)); 348 | } 349 | */ 350 | } 351 | 352 | if (jumpTableSection) { 353 | *jumpTableOffset = jumpTableSection->offset; 354 | *jumpTableSize = jumpTableSection->size; 355 | } 356 | } 357 | #endif 358 | return err_none; 359 | } 360 | } 361 | 362 | return err_threadEntry_image_not_found; 363 | } 364 | 365 | #if defined(__i386__) 366 | void* fixedUpImageFromImage ( 367 | const void *image, 368 | unsigned long imageSize, 369 | unsigned int jumpTableOffset, 370 | unsigned int jumpTableSize, 371 | ptrdiff_t fixUpOffset) 372 | { 373 | // first copy the full image 374 | void *fixedUpImage = (void *) malloc ((size_t)imageSize); 375 | bcopy(image, fixedUpImage, imageSize); 376 | 377 | // address of jump table in copied image 378 | void *jumpTable = fixedUpImage + jumpTableOffset; 379 | 380 | /* indirect jump table */ 381 | if (*(unsigned char *) jumpTable == 0xff) { 382 | // each indirect JMP instruction is 6 bytes (FF xx xx xx xx xx) where FF is the opcode for JMP 383 | int jumpTableCount = jumpTableSize / 6; 384 | 385 | // skip first "ff xx" 386 | // jumpTable += 2; 387 | 388 | int entry=0; 389 | for (entry = 0; entry < jumpTableCount; entry++) { 390 | assert(*(unsigned char*)jumpTable == 0xff); 391 | //skip ff xx 392 | jumpTable += 2; 393 | unsigned char *jmpValue = *((unsigned char **)jumpTable); 394 | 395 | fprintf(stderr, "at %p correcting %p to %p\n", 396 | (char *)jumpTable -2, 397 | jmpValue, jmpValue - fixUpOffset); 398 | 399 | jmpValue -= fixUpOffset; 400 | *((unsigned char **)jumpTable) = jmpValue; 401 | jumpTable+=4; //skip address 402 | } 403 | } 404 | else { 405 | // each JMP instruction is 5 bytes (E9 xx xx xx xx) where E9 is the opcode for JMP 406 | int jumpTableCount = jumpTableSize / 5; 407 | 408 | // skip first "E9" 409 | jumpTable++; 410 | 411 | int entry=0; 412 | for (entry = 0; entry < jumpTableCount; entry++) { 413 | unsigned int jmpValue = *((unsigned int *)jumpTable); 414 | jmpValue += fixUpOffset; 415 | *((unsigned int *)jumpTable) = jmpValue; 416 | jumpTable+=5; 417 | } 418 | } 419 | 420 | return fixedUpImage; 421 | } 422 | #endif /* __i386__ */ 423 | --------------------------------------------------------------------------------