WerWolv / ImHex

🔍 A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM.
https://imhex.werwolv.net
GNU General Public License v2.0
44.73k stars 1.95k forks source link

[Bug] MacOs Build from source doesn't run, EXC_BAD_ACCESS #874

Closed thestumbler closed 1 year ago

thestumbler commented 1 year ago

Operating System

MacOS

What's the issue you encountered?

Upon building branch 1f6acc10 on MacOs Ventura 13.1, the resulting executable fails to run with an EXC_BAD_ACCESS Code Signature Invalid error. This could well be my mistake, as I've never compiled a program into an app before, and I might be missing an obvious step. The problem report follows:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               imhex [13283]
Path:                  /Applications/imhex.app/Contents/MacOS/imhex
Identifier:            net.WerWolv.ImHex
Version:               1.26 (1.26.2)
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2023-01-13 06:46:55.8768 +0900
OS Version:            macOS 13.1 (22C65)
Report Version:        12
Anonymous UUID:        80E20766-2F00-7E83-6B39-409472C905B9

Time Awake Since Boot: 340000 seconds

System Integrity Protection: enabled

Crashed Thread:        0

Exception Type:        EXC_BAD_ACCESS (SIGKILL (Code Signature Invalid))
Exception Codes:       UNKNOWN_0x32 at 0x0000000102a80000
Exception Codes:       0x0000000000000032, 0x0000000102a80000

Termination Reason:    Namespace CODESIGNING, Code 2 Invalid Page

VM Region Info: 0x102a80000 is in 0x102a80000-0x102b1c000;  bytes after start: 0  bytes before end: 638975
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      dyld private memory         102a40000-102a80000    [  256K] rw-/rwx SM=PRV  
--->  mapped file                 102a80000-102b1c000    [  624K] r--/rwx SM=COW  ...t_id=af1d518b
      GAP OF 0xbcc000 BYTES
      mapped file                 1036e8000-104214000    [ 11.2M] r-x/rwx SM=COW  ...t_id=ab8ba68b

Thread 0 Crashed:
0   dyld                                   0x1aa0923b0 dyld3::MachOFile::hasMachOMagic() const + 0
1   dyld                                   0x1aa0696c4 dyld4::SyscallDelegate::mapFileReadOnly(Diagnostics&, char const*, unsigned long*, dyld4::FileID*, bool*, char*) const + 228
2   dyld                                   0x1aa069028 dyld4::SyscallDelegate::withReadOnlyMappedFile(Diagnostics&, char const*, bool, void (void const*, unsigned long, bool, dyld4::FileID const&, char const*) block_pointer) const + 88
3   dyld                                   0x1aa062184 dyld4::JustInTimeLoader::makeJustInTimeLoaderDisk(Diagnostics&, dyld4::RuntimeState&, char const*, dyld4::Loader::LoadOptions const&, bool, unsigned int, mach_o::Layout const*) + 208
4   dyld                                   0x1aa05910c invocation function for block in dyld4::Loader::getLoader(Diagnostics&, dyld4::RuntimeState&, char const*, dyld4::Loader::LoadOptions const&) + 1260
5   dyld                                   0x1aa058604 dyld4::Loader::forEachResolvedAtPathVar(dyld4::RuntimeState&, char const*, dyld4::Loader::LoadOptions const&, dyld4::ProcessConfig::PathOverrides::Type, bool&, void (char const*, dyld4::ProcessConfig::PathOverrides::Type, bool&) block_pointer) + 776
6   dyld                                   0x1aa0469b4 dyld4::ProcessConfig::PathOverrides::forEachPathVariant(char const*, dyld3::Platform, bool, bool, bool&, void (char const*, dyld4::ProcessConfig::PathOverrides::Type, bool&) block_pointer) const + 688
7   dyld                                   0x1aa05813c dyld4::Loader::forEachPath(Diagnostics&, dyld4::RuntimeState&, char const*, dyld4::Loader::LoadOptions const&, void (char const*, dyld4::ProcessConfig::PathOverrides::Type, bool&) block_pointer) + 248
8   dyld                                   0x1aa05888c dyld4::Loader::getLoader(Diagnostics&, dyld4::RuntimeState&, char const*, dyld4::Loader::LoadOptions const&) + 584
9   dyld                                   0x1aa060174 invocation function for block in dyld4::JustInTimeLoader::loadDependents(Diagnostics&, dyld4::RuntimeState&, dyld4::Loader::LoadOptions const&) + 408
10  dyld                                   0x1aa092b64 invocation function for block in dyld3::MachOFile::forEachDependentDylib(void (char const*, bool, bool, bool, unsigned int, unsigned int, bool&) block_pointer) const + 148
11  dyld                                   0x1aa0402d8 dyld3::MachOFile::forEachLoadCommand(Diagnostics&, void (load_command const*, bool&) block_pointer) const + 296
12  dyld                                   0x1aa0929ac dyld3::MachOFile::forEachDependentDylib(void (char const*, bool, bool, bool, unsigned int, unsigned int, bool&) block_pointer) const + 172
13  dyld                                   0x1aa05fec0 dyld4::JustInTimeLoader::loadDependents(Diagnostics&, dyld4::RuntimeState&, dyld4::Loader::LoadOptions const&) + 164
14  dyld                                   0x1aa044500 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 1236
15  dyld                                   0x1aa043dc4 start + 2404

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000102a80000   x1: 0x0000000000000000   x2: 0x000000016d4cdb88   x3: 0x0000000000040002
    x4: 0x0000000000000003   x5: 0x0000000000000000   x6: 0x000000016d4cdb88   x7: 0x00000000000008b0
    x8: 0x000000016d4cda20   x9: 0x000000016d4cda28  x10: 0x0000000001000011  x11: 0x0000000000000001
   x12: 0x000000016d4ce1b2  x13: 0x0000000000000000  x14: 0x0000000246c0408a  x15: 0x0000000000008000
   x16: 0x000000000000005c  x17: 0x00000001aa041e7c  x18: 0x0000000000000000  x19: 0x000000016d4ce0b0
   x20: 0x0000000000000003  x21: 0x000000016d4cdb5f  x22: 0x0000000102a80000  x23: 0x000000016d4cdb88
   x24: 0x000000016d4cdb60  x25: 0x000000016d4cdb80  x26: 0x000000016d4ce020  x27: 0x0000000000000000
   x28: 0x0000000000000000   fp: 0x000000016d4cdb40   lr: 0x00000001aa0696c4
    sp: 0x000000016d4cda20   pc: 0x00000001aa0923b0 cpsr: 0x80001000
   far: 0x0000000102a80000  esr: 0x92000007 (Data Abort) byte read Translation fault

Binary Images:
       0x1aa03e000 -        0x1aa0c8b63 dyld (*) <487cfdeb-9b07-39bf-bfb9-970b61aea2d1> /usr/lib/dyld
               0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=767.8M resident=0K(0%) swapped_out_or_unallocated=767.8M(100%)
Writable regions: Total=10.3M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=10.3M(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
STACK GUARD                       56.0M        1 
Stack                             8176K        1 
VM_ALLOCATE (reserved)            1872K        1         reserved VM address space (unallocated)
__DATA                             427K        2 
__DATA_CONST                        38K        2 
__DATA_DIRTY                         7K        1 
__LINKEDIT                       766.9M        2 
__TEXT                             892K        2 
dyld private memory                512K        2 
mapped file                       13.0M        4 
===========                     =======  ======= 
TOTAL                            847.6M       18 
TOTAL, minus reserved VM space   845.7M       18 

-----------
Full Report
-----------

{"app_name":"imhex","timestamp":"2023-01-13 06:46:56.00 +0900","app_version":"1.26","slice_uuid":"fd0b3ed4-0383-32e5-9dc4-4b352cd293f1","build_version":"1.26.2","platform":1,"bundleID":"net.WerWolv.ImHex","share_with_app_devs":0,"is_first_party":0,"bug_type":"309","os_version":"macOS 13.1 (22C65)","roots_installed":0,"name":"imhex","incident_id":"4205BDA7-A022-43B1-A397-2AD41CE23C06"}
{
  "uptime" : 340000,
  "procRole" : "Default",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "Macmini9,1",
  "coalitionID" : 17282,
  "osVersion" : {
    "train" : "macOS 13.1",
    "build" : "22C65",
    "releaseType" : "User"
  },
  "captureTime" : "2023-01-13 06:46:55.8768 +0900",
  "incident" : "4205BDA7-A022-43B1-A397-2AD41CE23C06",
  "pid" : 13283,
  "translated" : false,
  "cpuType" : "ARM-64",
  "roots_installed" : 0,
  "bug_type" : "309",
  "procLaunch" : "2023-01-13 06:46:55.8646 +0900",
  "procStartAbsTime" : 8294568133242,
  "procExitAbsTime" : 8294568420990,
  "procName" : "imhex",
  "procPath" : "\/Applications\/imhex.app\/Contents\/MacOS\/imhex",
  "bundleInfo" : {"CFBundleShortVersionString":"1.26","CFBundleVersion":"1.26.2","CFBundleIdentifier":"net.WerWolv.ImHex"},
  "storeInfo" : {"deviceIdentifierForVendor":"9E5FC6BB-C69F-5F00-B9C7-D03E0C1AF391","thirdParty":true},
  "parentProc" : "launchd",
  "parentPid" : 1,
  "coalitionName" : "net.WerWolv.ImHex",
  "crashReporterKey" : "80E20766-2F00-7E83-6B39-409472C905B9",
  "throttleTimeout" : 2147483647,
  "sip" : "enabled",
  "vmRegionInfo" : "0x102a80000 is in 0x102a80000-0x102b1c000;  bytes after start: 0  bytes before end: 638975\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      dyld private memory         102a40000-102a80000    [  256K] rw-\/rwx SM=PRV  \n--->  mapped file                 102a80000-102b1c000    [  624K] r--\/rwx SM=COW  ...t_id=af1d518b\n      GAP OF 0xbcc000 BYTES\n      mapped file                 1036e8000-104214000    [ 11.2M] r-x\/rwx SM=COW  ...t_id=ab8ba68b",
  "exception" : {"codes":"0x0000000000000032, 0x0000000102a80000","rawCodes":[50,4339531776],"type":"EXC_BAD_ACCESS","signal":"SIGKILL (Code Signature Invalid)","subtype":"UNKNOWN_0x32 at 0x0000000102a80000"},
  "termination" : {"flags":0,"code":2,"namespace":"CODESIGNING","indicator":"Invalid Page"},
  "vmregioninfo" : "0x102a80000 is in 0x102a80000-0x102b1c000;  bytes after start: 0  bytes before end: 638975\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      dyld private memory         102a40000-102a80000    [  256K] rw-\/rwx SM=PRV  \n--->  mapped file                 102a80000-102b1c000    [  624K] r--\/rwx SM=COW  ...t_id=af1d518b\n      GAP OF 0xbcc000 BYTES\n      mapped file                 1036e8000-104214000    [ 11.2M] r-x\/rwx SM=COW  ...t_id=ab8ba68b",
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "faultingThread" : 0,
  "threads" : [{"triggered":true,"id":6474432,"threadState":{"x":[{"value":4339531776},{"value":0},{"value":6128720776},{"value":262146},{"value":3},{"value":0},{"value":6128720776},{"value":2224},{"value":6128720416},{"value":6128720424},{"value":16777233},{"value":1},{"value":6128722354},{"value":0},{"value":9776939146},{"value":32768},{"value":92},{"value":7147363964,"symbolLocation":56,"symbol":"fcntl"},{"value":0},{"value":6128722096},{"value":3},{"value":6128720735},{"value":4339531776},{"value":6128720776},{"value":6128720736},{"value":6128720768},{"value":6128721952},{"value":0},{"value":0}],"flavor":"ARM_THREAD_STATE64","lr":{"value":7147525828},"cpsr":{"value":2147487744},"fp":{"value":6128720704},"sp":{"value":6128720416},"esr":{"value":2449473543,"description":"(Data Abort) byte read Translation fault"},"pc":{"value":7147692976,"matchesCrashFrame":1},"far":{"value":4339531776}},"frames":[{"imageOffset":345008,"symbol":"dyld3::MachOFile::hasMachOMagic() const","symbolLocation":0,"imageIndex":0},{"imageOffset":177860,"symbol":"dyld4::SyscallDelegate::mapFileReadOnly(Diagnostics&, char const*, unsigned long*, dyld4::FileID*, bool*, char*) const","symbolLocation":228,"imageIndex":0},{"imageOffset":176168,"symbol":"dyld4::SyscallDelegate::withReadOnlyMappedFile(Diagnostics&, char const*, bool, void (void const*, unsigned long, bool, dyld4::FileID const&, char const*) block_pointer) const","symbolLocation":88,"imageIndex":0},{"imageOffset":147844,"symbol":"dyld4::JustInTimeLoader::makeJustInTimeLoaderDisk(Diagnostics&, dyld4::RuntimeState&, char const*, dyld4::Loader::LoadOptions const&, bool, unsigned int, mach_o::Layout const*)","symbolLocation":208,"imageIndex":0},{"imageOffset":110860,"symbol":"invocation function for block in dyld4::Loader::getLoader(Diagnostics&, dyld4::RuntimeState&, char const*, dyld4::Loader::LoadOptions const&)","symbolLocation":1260,"imageIndex":0},{"imageOffset":108036,"symbol":"dyld4::Loader::forEachResolvedAtPathVar(dyld4::RuntimeState&, char const*, dyld4::Loader::LoadOptions const&, dyld4::ProcessConfig::PathOverrides::Type, bool&, void (char const*, dyld4::ProcessConfig::PathOverrides::Type, bool&) block_pointer)","symbolLocation":776,"imageIndex":0},{"imageOffset":35252,"symbol":"dyld4::ProcessConfig::PathOverrides::forEachPathVariant(char const*, dyld3::Platform, bool, bool, bool&, void (char const*, dyld4::ProcessConfig::PathOverrides::Type, bool&) block_pointer) const","symbolLocation":688,"imageIndex":0},{"imageOffset":106812,"symbol":"dyld4::Loader::forEachPath(Diagnostics&, dyld4::RuntimeState&, char const*, dyld4::Loader::LoadOptions const&, void (char const*, dyld4::ProcessConfig::PathOverrides::Type, bool&) block_pointer)","symbolLocation":248,"imageIndex":0},{"imageOffset":108684,"symbol":"dyld4::Loader::getLoader(Diagnostics&, dyld4::RuntimeState&, char const*, dyld4::Loader::LoadOptions const&)","symbolLocation":584,"imageIndex":0},{"imageOffset":139636,"symbol":"invocation function for block in dyld4::JustInTimeLoader::loadDependents(Diagnostics&, dyld4::RuntimeState&, dyld4::Loader::LoadOptions const&)","symbolLocation":408,"imageIndex":0},{"imageOffset":346980,"symbol":"invocation function for block in dyld3::MachOFile::forEachDependentDylib(void (char const*, bool, bool, bool, unsigned int, unsigned int, bool&) block_pointer) const","symbolLocation":148,"imageIndex":0},{"imageOffset":8920,"symbol":"dyld3::MachOFile::forEachLoadCommand(Diagnostics&, void (load_command const*, bool&) block_pointer) const","symbolLocation":296,"imageIndex":0},{"imageOffset":346540,"symbol":"dyld3::MachOFile::forEachDependentDylib(void (char const*, bool, bool, bool, unsigned int, unsigned int, bool&) block_pointer) const","symbolLocation":172,"imageIndex":0},{"imageOffset":138944,"symbol":"dyld4::JustInTimeLoader::loadDependents(Diagnostics&, dyld4::RuntimeState&, dyld4::Loader::LoadOptions const&)","symbolLocation":164,"imageIndex":0},{"imageOffset":25856,"symbol":"dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*)","symbolLocation":1236,"imageIndex":0},{"imageOffset":24004,"symbol":"start","symbolLocation":2404,"imageIndex":0}]}],
  "usedImages" : [
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 7147347968,
    "size" : 568164,
    "uuid" : "487cfdeb-9b07-39bf-bfb9-970b61aea2d1",
    "path" : "\/usr\/lib\/dyld",
    "name" : "dyld"
  },
  {
    "size" : 0,
    "source" : "A",
    "base" : 0,
    "uuid" : "00000000-0000-0000-0000-000000000000"
  }
],
  "sharedCache" : {
  "base" : 7146700800,
  "size" : 3434283008,
  "uuid" : "00a1fbb6-43e1-3c11-8483-faf0db659249"
},
  "vmSummary" : "ReadOnly portion of Libraries: Total=767.8M resident=0K(0%) swapped_out_or_unallocated=767.8M(100%)\nWritable regions: Total=10.3M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=10.3M(100%)\n\n                                VIRTUAL   REGION \nREGION TYPE                        SIZE    COUNT (non-coalesced) \n===========                     =======  ======= \nSTACK GUARD                       56.0M        1 \nStack                             8176K        1 \nVM_ALLOCATE (reserved)            1872K        1         reserved VM address space (unallocated)\n__DATA                             427K        2 \n__DATA_CONST                        38K        2 \n__DATA_DIRTY                         7K        1 \n__LINKEDIT                       766.9M        2 \n__TEXT                             892K        2 \ndyld private memory                512K        2 \nmapped file                       13.0M        4 \n===========                     =======  ======= \nTOTAL                            847.6M       18 \nTOTAL, minus reserved VM space   845.7M       18 \n",
  "legacyInfo" : {
  "threadTriggered" : {

  }
},
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "60da5e84ab0ca017dace9abf",
      "factorPackIds" : {

      },
      "deploymentId" : 240000008
    },
    {
      "rolloutId" : "63582c5f8a53461413999550",
      "factorPackIds" : {

      },
      "deploymentId" : 240000002
    }
  ],
  "experiments" : [

  ]
}
}

Model: Macmini9,1, BootROM 8419.60.44, proc 8:4:4 processors, 16 GB, SMC 
Graphics: Apple M1, Apple M1, Built-In
Display: X27Q75, 2048 x 1152, Main, MirrorOff, Online
Display: X27Q75, 2048 x 1152, MirrorOff, Online
Memory Module: LPDDR4, Hynix
AirPort: spairport_wireless_card_type_wifi (0x14E4, 0x4378), wl0: Sep  3 2022 03:37:22 version 18.20.379.4.7.8.143 FWID 01-e3c71b50
Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports
Network Service: Ethernet, Ethernet, en0
USB Device: USB31Bus
USB Device: USB-C to 3.5mm Headphone Jack Adapter
USB Device: USB31Bus
USB Device: SOHO USB 3.2 Hub
USB Device: USB-C SOHO Card Reader
USB Device: USB3.1 Hub
USB Device: USB3.1 Hub
USB Device: SOHO USB 2.0 Hub
USB Device: USB2.1 Hub
USB Device: Microsoft® LifeCam HD-3000
USB Device: USB2.1 Hub
USB Device: USB-C SOHO Dock
USB Device: USB30Bus
USB Device: USB3.0 Hub
USB Device: USB2.0 Hub
USB Device: HID Keyboard
USB Device: Kensington Expert Mouse
Thunderbolt Bus: Mac mini, Apple Inc.
Thunderbolt Bus: Mac mini, Apple Inc.

How can the issue be reproduced?

Built the application using the instructions, trying to run the resulting app caused a crash.

ImHex Version

nightly 1f6acc10

ImHex Build Type

Installation type

cloned git repository, compiled per the instructions

Additional context?

No response

WerWolv commented 1 year ago

Hey That crash seems to be happening somewhere deep inside of macOS's dynamic linker so I'll assume this isn't an issue with my code directly.

Have you tried using the latest nightly that was built by GitHub actions? Does the same error occur there as well?

thestumbler commented 1 year ago

I wondered if there was a pre-built image of nightlies. I'm searching for that now.

thestumbler commented 1 year ago

Okay, the pre-built 1f6acc10 nightly did the trick. I think I see the mixup, based on the filename of the nightly image, this is an x86_64 compilation, and I'm running on an M1. The pre-built runs transparently under Rosetta. The version I compiled was done as a native M1 ARM program.

WerWolv commented 1 year ago

Here's some explaination about the issue you're getting: https://developer.apple.com/library/archive/qa/qa1884/_index.html Looks like macOS weirdness to me and not something I can do anything about

thestumbler commented 1 year ago

Indeed, and I'm not inclined to pursue it, either. If you later need a guinea pig with an M1 to run test, shout at me. Thanks.

WerWolv commented 1 year ago

Sure thank you! We probably won't officially be targetting M1s until GitHub has native macOS ARM runners available to build ImHex on but if it ever happens I'll let you know

Code wise, ImHex should run just fine on ARM

tavdog commented 1 year ago

This tip got it compiled for me but now when I try to launch it the process is immediately killed. tavis@M1Pro ~/c/I/b/i/C/MacOS> ./imhex 1f6acc10 [1] 47771 killed ./imhex tavis@M1Pro ~/c/I/b/i/C/MacOS> sudo ./imhex 137 1f6acc10 Password: [1] 47813 killed sudo ./imhex tavis@M1Pro ~/c/I/b/i/C/MacOS>