DYLDSharedCache.hopperLoader icon indicating copy to clipboard operation
DYLDSharedCache.hopperLoader copied to clipboard

Doesn't seem to be loading in Hopper v4

Open darknoon opened this issue 7 years ago • 7 comments

When I drag in a dyld_shared_cache file, the loader doesn't show up:

screen shot 2017-07-31 at 2 32 14 pm

Here are my build logs: logs.txt

darknoon avatar Jul 31 '17 21:07 darknoon

Just ran into this after compiling for the first time. Log indicates Hopper v4 is not happy with it using external functions:

ERROR: Cannot load ~/Library/Application Support/Hopper/PlugIns/v4/Loaders/DYLDSharedCache.hopperLoader,
plugin makes use of external function(s), and may be too slow for a Loader plugin.
Also, make sure that plugin is compiled for OS X 10.9, or higher.

error: Plugin uses symbol _open

Not sure how to resolve this, but likely to help in debugging.

bruienne avatar Aug 01 '17 05:08 bruienne

Thanks for the report!

For the quick workaround you could patch dyld/launch-cache/dsc_extractor.cpp with the following patch:

diff --git a/launch-cache/dsc_extractor.cpp b/launch-cache/dsc_extractor.cpp
index e21a0f6..b5ce054 100644
--- a/launch-cache/dsc_extractor.cpp
+++ b/launch-cache/dsc_extractor.cpp
@@ -493,7 +493,7 @@ int dyld_shared_cache_extract_dylibs_progress(const char* shared_cache_file_path
                return -1;
        }

-       int cache_fd = open(shared_cache_file_path, O_RDONLY);
+       int cache_fd = -1;
        if (cache_fd < 0) {
                fprintf(stderr, "Error: failed to open shared cache file at %s\n", shared_cache_file_path);
                return -1;
@@ -565,7 +565,7 @@ int dyld_shared_cache_extract_dylibs_progress(const char* shared_cache_file_path
             make_dirs(dylib_path);

             // open file, create if does not already exist
-            int fd = ::open(dylib_path, O_CREAT | O_EXLOCK | O_RDWR, 0644);
+            int fd = -1;
             if ( fd == -1 ) {
                 fprintf(stderr, "can't open or create dylib file %s, errnor=%d\n", dylib_path, errno);
                 result    = -1;

Also, please rename DYLDSharedCacheLoader to something like DYLDSharedCacheLoaderPlugin in DYLDSharedCacheLoader.mm, there seem to be a name collision in the most recent version of Hopper:

diff --git a/DYLDSharedCacheLoader.mm b/DYLDSharedCacheLoader.mm
index d08e556..b3fe025 100644
--- a/DYLDSharedCacheLoader.mm
+++ b/DYLDSharedCacheLoader.mm
@@ -2,11 +2,11 @@
 #import <Hopper/Hopper.h>
 #import "DYLD.hpp"

-@interface DYLDSharedCacheLoader : NSObject<FileLoader>
+@interface DYLDSharedCacheLoaderPlugin : NSObject<FileLoader>

 @end

-@implementation DYLDSharedCacheLoader {
+@implementation DYLDSharedCacheLoaderPlugin {
   NSObject<HPHopperServices> *_services;
 }

I'll look at the proper fix later.

0xc010d avatar Aug 01 '17 09:08 0xc010d

Just applied the workaround, including renaming DYLDSharedCacheLoader and it seems to work now. The plugin loads and a dylib loaded from a dyld_shared_cache_arm64 that previously had most of its symbols listed as <redacted> now looks normal.

Thanks for the fast reply, much obliged! 👍

bruienne avatar Aug 01 '17 20:08 bruienne

Good to hear!

0xc010d avatar Aug 01 '17 22:08 0xc010d

Hey, it's working for me now. I just had to apply the patches and change the install path.

darknoon avatar Aug 02 '17 17:08 darknoon

Cool! I have symlinks in ~/Library/Application Support/Hopper/PlugIns/v4 to old Loaders and Tools locations. It's probably not a bad idea to use proper paths in the plugin though.

0xc010d avatar Aug 02 '17 18:08 0xc010d

An update to Hopper came out today mentioning dyld. I gave it a try using the dyld_cache from iOS11b4 and doesn't appear to be generating valid pseudo code.

5/8/2017 Hopper Version 4.2.11

  • Complete rewrite of the DYLD shared cache loader

malhal avatar Aug 05 '17 18:08 malhal