this repo has no description
1
fork

Configure Feed

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

Fixes & little improvements

+157 -27
+3 -1
src/CoreFoundation/AppleCFString.h
··· 2 2 #define APPLECFSTRING_H 3 3 #include <stdint.h> 4 4 #include <limits.h> 5 - #import <Foundation/NSString.h> 5 + #include <CoreFoundation/CFString.h> 6 + #include <Foundation/NSString.h> 6 7 7 8 #pragma pack(1) 8 9 @interface AppleCFString : NSString ··· 31 32 - (void) release; 32 33 - (id) autorelease; 33 34 - (NSZone*) zone; 35 + - (CFTypeID) _cfTypeID; 34 36 @end 35 37 #pragma pack() 36 38
+13
src/CoreFoundation/AppleCFString.mm
··· 7 7 8 8 Class* __CFConstantStringClassReference __attribute__ ((weak, alias ("_OBJC_CLASS_AppleCFString"))); 9 9 10 + __attribute__((constructor)) static void forceAppleCFStringLoad() 11 + { 12 + // The runtime seems to expect at least one instance of AppleCFString to be created 13 + // before it starts working. Since constant string in application images are not 14 + // "created", random failures occured. 15 + [[AppleCFString alloc] dealloc]; 16 + } 17 + 10 18 @implementation AppleCFString 11 19 - (NSUInteger)length 12 20 { ··· 70 78 - (NSZone*) zone 71 79 { 72 80 return NSDefaultMallocZone(); 81 + } 82 + 83 + - (CFTypeID) _cfTypeID 84 + { 85 + return CFStringGetTypeID(); 73 86 } 74 87 75 88 @end
+13 -18
src/dyld/DylibSearch.cpp
··· 12 12 namespace Darling { 13 13 14 14 DylibSearch::DylibSearch() 15 + : m_reFrameworkPath("/System/Library/Frameworks/([a-zA-Z0-9\\.]+)/Versions/([a-zA-Z0-9\\.]+)/.*") 15 16 { 16 17 try 17 18 { 18 - int rv = regcomp(&m_reFrameworkPath, "/System/Library/Frameworks/([a-zA-Z0-9\\.]+)/Versions/([a-zA-Z0-9\\.]+)/.*", REG_EXTENDED); 19 - assert(rv == 0); 20 - 21 19 m_config = new IniConfig(ETC_DARLING_PATH "/dylib.conf"); 22 20 } 23 21 catch (const std::exception& e) ··· 119 117 if (it != m->end()) 120 118 return it->second.c_str(); 121 119 } 122 - if (library.compare(0, 27, "/System/Library/Frameworks/", 27) == 0) 120 + 121 + if (m_reFrameworkPath.matches(library)) 123 122 { 124 - regmatch_t match[3]; 125 - if (regexec(&m_reFrameworkPath, library.c_str(), sizeof(match)/sizeof(match[0]), match, 0) != REG_NOMATCH) 123 + std::string name, version; 124 + 125 + name = m_reFrameworkPath.group(1); 126 + version = m_reFrameworkPath.group(2); 127 + 128 + if (m_config->hasSection(name)) 126 129 { 127 - std::string name, version; 128 - 129 - name = library.substr(match[1].rm_so, match[1].rm_eo - match[1].rm_so); 130 - version = library.substr(match[2].rm_so, match[2].rm_eo - match[2].rm_so); 131 - 132 - if (m_config->hasSection(name)) 133 - { 134 - const IniConfig::ValueMap* m = m_config->getSection(name); 135 - auto it = m->find(version); 130 + const IniConfig::ValueMap* m = m_config->getSection(name); 131 + auto it = m->find(version); 136 132 137 - if (it != m->end()) 138 - return it->second.c_str(); 139 - } 133 + if (it != m->end()) 134 + return it->second.c_str(); 140 135 } 141 136 } 142 137 return nullptr;
+2 -2
src/dyld/DylibSearch.h
··· 2 2 #define DYLIBSEARCH_H 3 3 #include <util/IniConfig.h> 4 4 #include <string> 5 - #include <regex.h> 5 + #include <util/Regexp.h> 6 6 7 7 namespace Darling { 8 8 ··· 23 23 static std::string filenameFromPath(const std::string& path); 24 24 private: 25 25 IniConfig* m_config; 26 - regex_t m_reFrameworkPath; 26 + Regexp m_reFrameworkPath; 27 27 }; 28 28 29 29 }
+33 -3
src/dyld/dyld.cpp
··· 3 3 #include <iostream> 4 4 #include <stdexcept> 5 5 #include <cstdlib> 6 + #include <string> 7 + #include <sstream> 8 + #include <util/stlutils.h> 9 + #include <util/Regexp.h> 6 10 #include "arch.h" 7 11 8 12 static void printHelp(const char* argv0); 13 + static std::string locateBundleExecutable(const std::string& bundlePath); 9 14 10 15 using namespace Darling; 11 16 ··· 21 26 { 22 27 MachOObject* obj; 23 28 MachOMgr* mgr = MachOMgr::instance(); 24 - 29 + std::string executable; 30 + 31 + executable = locateBundleExecutable(argv[1]); 32 + argv[1] = const_cast<char*>(executable.c_str()); 33 + 25 34 mgr->detectSysRootFromPath(argv[1]); 35 + 26 36 mgr->setPrintInitializers(getenv("DYLD_PRINT_INITIALIZERS") != nullptr); 27 37 mgr->setPrintLibraries(getenv("DYLD_PRINT_LIBRARIES") != nullptr); 28 38 mgr->setBindAtLaunch(getenv("DYLD_BIND_AT_LAUNCH") != nullptr); ··· 46 56 } 47 57 catch (const std::exception& e) 48 58 { 49 - std::cerr << e.what() << std::endl; 50 - return 1; 59 + std::cerr << "dyld: Cannot execute binary file: " << e.what() << std::endl; 60 + return ENOSYS; 51 61 } 52 62 } 53 63 ··· 72 82 "\tDYLD_PRINT_RPATHS - print @rpath resolution attempts\n\n"; 73 83 } 74 84 85 + static std::string locateBundleExecutable(const std::string& bundlePath) 86 + { 87 + Regexp re(".*/([^\\.]+)\\.app/?$", true); 88 + if (re.matches(bundlePath)) 89 + { 90 + std::stringstream ss; 91 + ss << bundlePath; 92 + 93 + if (bundlePath.back() != '/') 94 + ss << '/'; 95 + 96 + ss << "Contents/MacOS/"; 97 + ss << re.group(1); 98 + 99 + return ss.str(); 100 + } 101 + else 102 + return bundlePath; 103 + } 104 +
+2 -2
src/libmach-o/MachO.cpp
··· 37 37 int fd = ::open(path.c_str(), O_RDONLY); 38 38 if (fd < 0) 39 39 { 40 - std::cerr << path << ": " << strerror(errno) << std::endl; 41 - return 0; 40 + //std::cerr << path << ": " << strerror(errno) << std::endl; 41 + return nullptr; 42 42 } 43 43 44 44 size_t offset = 0, len = 0;
+3 -1
src/libobjcdarwin/old/class.cpp
··· 124 124 cls->super_class.clsNew = c; 125 125 } 126 126 127 - std::transform(mapClassNames.begin(), mapClassNames.end(), vecClassNames.begin(), [](const std::pair<const char*,old_class*>& p) { return p.first; }); 127 + //std::transform(mapClassNames.begin(), mapClassNames.end(), vecClassNames.begin(), [](const std::pair<const char*,old_class*>& p) { return p.first; }); 128 + for (auto it = mapClassNames.begin(); it != mapClassNames.end(); it++) 129 + vecClassNames.push_back(it->first); 128 130 129 131 return vecClassNames; 130 132 }
+1
src/util/CMakeLists.txt
··· 10 10 debug.cpp 11 11 stlutils.cpp 12 12 IniConfig.cpp 13 + Regexp.cpp 13 14 leb.cpp 14 15 ) 15 16
+58
src/util/Regexp.cpp
··· 1 + #include "Regexp.h" 2 + #include <stdexcept> 3 + 4 + namespace Darling { 5 + 6 + Regexp::Regexp(const std::string& re, bool caseInsensitive) 7 + { 8 + int flags, rv; 9 + 10 + flags = REG_EXTENDED; 11 + 12 + if (caseInsensitive) 13 + flags |= REG_ICASE; 14 + 15 + rv = ::regcomp(&m_regex, re.c_str(), flags); 16 + if (rv) 17 + throwError(rv); 18 + } 19 + 20 + Regexp::~Regexp() 21 + { 22 + regfree(&m_regex); 23 + } 24 + 25 + void Regexp::throwError(int code) 26 + { 27 + char buffer[512]; 28 + 29 + ::regerror(code, &m_regex, buffer, sizeof(buffer)); 30 + 31 + throw std::invalid_argument(buffer); 32 + } 33 + 34 + bool Regexp::matches(const std::string& input) 35 + { 36 + int rv; 37 + regmatch_t matches[50]; 38 + 39 + m_matches.clear(); 40 + 41 + rv = ::regexec(&m_regex, input.c_str(), sizeof(matches)/sizeof(matches[0]), matches, 0); 42 + 43 + if (rv == REG_NOMATCH) 44 + return false; 45 + else if (rv == REG_NOERROR) 46 + { 47 + for (int i = 0; i < sizeof(matches)/sizeof(matches[0]) && matches[i].rm_so != -1; i++) 48 + { 49 + m_matches.push_back(input.substr(matches[i].rm_so, matches[i].rm_eo - matches[i].rm_so)); 50 + } 51 + return true; 52 + } 53 + else 54 + throwError(rv); 55 + } 56 + 57 + } 58 +
+29
src/util/Regexp.h
··· 1 + #ifndef REGEXP_H 2 + #define REGEXP_H 3 + #include <regex.h> 4 + #include <string> 5 + #include <vector> 6 + 7 + namespace Darling { 8 + 9 + class Regexp 10 + { 11 + public: 12 + Regexp(const std::string& re, bool caseInsensitive = false); 13 + ~Regexp(); 14 + 15 + bool matches(const std::string& input); 16 + 17 + inline size_t groups() const { return m_matches.size(); } 18 + inline std::string group(size_t index) const { return m_matches.at(index); } 19 + private: 20 + void throwError(int code) __attribute__((noreturn)); 21 + private: 22 + regex_t m_regex; 23 + std::vector<std::string> m_matches; 24 + }; 25 + 26 + } // namespace Darling 27 + 28 + #endif 29 +