GithubHelp home page GithubHelp logo

nodejs / postject Goto Github PK

View Code? Open in Web Editor NEW
166.0 21.0 10.0 15.06 MB

Easily inject arbitrary read-only resources into executable formats (Mach-O, PE, ELF) and use it at runtime.

License: Other

C 20.16% CMake 4.05% JavaScript 43.37% C++ 30.69% Assembly 1.72%

postject's Introduction

postject

CircleCI npm version

Easily inject arbitrary read-only resources into executable formats (Mach-O, PE, ELF) and use it at runtime.

Install

npm i -g postject

Usage

Command line utility

$ postject -h
Usage: postject [options] <filename> <resource_name> <resource>

Inject arbitrary read-only resources into an executable for use at runtime

Arguments:
  filename                             The executable to inject into
  resource_name                        The resource name to use (section name on Mach-O and ELF, resource name for PE)
  resource                             The resource to inject

Options:
  --macho-segment-name <segment_name>  Name for the Mach-O segment (default: "__POSTJECT")
  --output-api-header                  Output the API header to stdout
  --overwrite                          Overwrite the resource if it already exists
  -h, --help                           display help for command

Using Programatically

const { inject } = require('postject');

await inject('a.out', 'lol', Buffer.from('Hello, world!'));

Building

Prerequisites

Build Command

$ npm run build

The final output is placed in dist/, with main.js being the entrypoint.

Testing

$ npm test

Design

To ensure maximum capatibility and head off unforeseen issues, the implementation for each format tries to use that format's standard practices for embedding binary data. As such, it should be possible to embed the binary data at build-time as well. The CLI provides the ability to inject the resources into pre-built executables, with the goal that the end result should be as close as possible to what is obtained by embedding them at build-time.

Note: Other runtime injection implementers should search the binary compiled with postject-api.h for the POSTJECT_SENTINEL_fce680ab2cc467b6e072b8b5df1996b2:0 fuse and flip the last character to 1 to indicate that a resource has been injected. A different fuse can also be used by defining the POSTJECT_SENTINEL_FUSE macro before including postject-api.h and passing the same string to postject with --sentinel-fuse <sentinel_fuse>.

Windows

For PE executables, the resources are added into the .rsrc section, with the RT_RCDATA (raw data) type.

The build-time equivalent is adding the binary data as a resource in the usual manner, such as the Resource Compiler, and marking it as RT_RCDATA.

The run-time lookup uses the FindResource and LoadResource APIs.

macOS

For Mach-O executables, the resources are added as sections inside a new segment.

The build-time equivalent of embedding binary data with this approach uses a linker flag: -sectcreate,__FOO,__foo,content.txt

The run-time lookup uses APIs from <mach-o/getsect.h>.

Linux

For ELF executables, the resources are added as notes.

The build-time equivalent is to use a linker script.

postject's People

Contributors

cjihrig avatar dfellis avatar dsanders11 avatar jviotti avatar raisinten avatar robertgzr avatar tony-go avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postject's Issues

Test Coverage for Real World Apps

Basic "Hello World" apps can provide smoke test coverage for issues, but we've found several issues that only surface when you start testing on real world apps which have larger and more complicated executable layouts as a result. Expand test coverage to include some real world apps, e.g. Node.js.

single executable applications with warning

CentOS 8

[admin tmp]$ uname -a
Linux git 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
[admin tmp]$ node -v
v18.16.0
[admins tmp]$ npm -v
9.5.1
[admin tmp]$ node hello.js
Hello, undefined!

[admin tmp]$ node hello.js foo
Hello, foo!

got error:

[admin tmp]$ npx postject hello NODE_JS_CODE hello.js \
>     --sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2

Need to install the following packages:
  [email protected]
Ok to proceed? (y)
Start injection of NODE_JS_CODE in hello...
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'

Refactor CLI

The current CLI is a bit awkward since it was thrown together for the proof-of-concept. Sub-commands could help clean it up a good amount:

  • postject inject <filename> <resourceName> <resource> [outputFilename] - the current functionality, but with optional output path
  • postject inspect <filename> - shows you a list of resources injected in the executable
  • postject view <filename> <resourceName> - shows you the contents of a resource
  • postject output-api - dumps the C run-time API to stdout

OOM abort error

System info

$ uname -a
Darwin Darshans-MacBook-Pro.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 x86_64

Versions

Node.js version: v14.18.2
Postject version: v1.0.0-alpha.1

Repro

npm init --yes
echo "Hello, world!" > index.js
npx asar pack . app.asar
cp $(command -v node) .
npx postject ./node NODE_JS_CODE app.asar

app.asar has a size of 4.0K.

Error logs

log.txt

TLDR, bottom section of the log:

...
RuntimeError: Aborted(OOM). Build with -sASSERTIONS for more info.
    at abort (/Users/raisinten/.npm/_npx/6914/lib/node_modules/postject/dist/postject.js:9:7843)
    at abortOnCannotGrowMemory (/Users/raisinten/.npm/_npx/6914/lib/node_modules/postject/dist/postject.js:9:92949)
    at _emscripten_resize_heap (/Users/raisinten/.npm/_npx/6914/lib/node_modules/postject/dist/postject.js:9:93068)
    at <anonymous>:wasm-function[438]:0x1d1fd
    at hb (<anonymous>:wasm-function[193]:0xc3c0)
    at <anonymous>:wasm-function[114]:0x3d87
    at <anonymous>:wasm-function[448]:0x1d9ba
    at <anonymous>:wasm-function[3035]:0x1b9507
    at <anonymous>:wasm-function[2373]:0x138308
    at Object.getExecutableFormat (eval at new_ (/Users/raisinten/.npm/_npx/6914/lib/node_modules/postject/dist/postject.js:9:73645), <anonymous>:8:10)

Additional info

This happens only while trying to embed data into the Node.js binary. This works:

npm init --yes
echo "Hello, world!" > index.js
npx asar pack . app.asar
echo "int main() {}" | gcc -x c -
npx postject ./a.out NODE_JS_CODE app.asar

This fails in https://github.com/postmanlabs/postject/blob/0035c074f43185546dd65a6bffcfe78ccc96382b/src/postject.cpp#L24.

After building with -sASSERTIONS, this is the readable part of the error:

Aborted(Cannot enlarge memory arrays to size 82239488 bytes (OOM). Either (1) compile with -sINITIAL_MEMORY=X with X higher than the current value 16777216, (2) compile with -sALLOW_MEMORY_GROWTH which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -sABORTING_MALLOC=0)
/Users/raisinten/Desktop/temp/project/trash/repro/test/node_modules/postject/dist/postject.js:9
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

RuntimeError: Aborted(Cannot enlarge memory arrays to size 82239488 bytes (OOM). Either (1) compile with -sINITIAL_MEMORY=X with X higher than the current value 16777216, (2) compile with -sALLOW_MEMORY_GROWTH which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -sABORTING_MALLOC=0)
    at abort (/Users/raisinten/Desktop/temp/project/trash/repro/test/node_modules/postject/dist/postject.js:9:17539)
    at abortOnCannotGrowMemory (/Users/raisinten/Desktop/temp/project/trash/repro/test/node_modules/postject/dist/postject.js:9:111870)
    at _emscripten_resize_heap (/Users/raisinten/Desktop/temp/project/trash/repro/test/node_modules/postject/dist/postject.js:9:112336)
    at <anonymous>:wasm-function[3035]:0x290b1c
    at malloc (<anonymous>:wasm-function[3030]:0x28eb99)
    at <anonymous>:wasm-function[3619]:0x2af135
    at <anonymous>:wasm-function[128]:0x1050c
    at <anonymous>:wasm-function[130]:0x1067f
    at <anonymous>:wasm-function[140]:0x1569f
    at Object.getExecutableFormat (eval at new_ (/Users/raisinten/Desktop/temp/project/trash/repro/test/node_modules/postject/dist/postject.js:9:91135), <anonymous>:8:10)

Provide a way to fetch the file offset of the embedded data

Problem

The current mechanism returns a pointer to the embedded data and its size. Passing it into V8 forces us to load the entire embedded data into a buffer in memory. It is not efficient to prematurely store the entire payload in memory, especially if the payload is huge.

See nodejs/node#42334 (comment).

Suggested solution

If the Postject Api returns the file offset of the embedded data, we will be able to parse only the parts that we are interested in.

Adding multiple sections to the `__POSTJECT` segment causes a crash

OS

Intel macOS Monterey Version 12.4

$ uname -a
Darwin Darshans-MacBook-Pro.local 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64

Repro

$ echo "int main() {}" | clang -x c -
$ postject.py --macho-segment-name __POSTJECT a.out NODE_JS_CODE <(shuf -n 100 /usr/share/dict/words | fmt -w 72)
$ postject.py --macho-segment-name __POSTJECT a.out NODE_JS_BOOTSTRAP <(shuf -n 100 /usr/share/dict/words | fmt -w 72)

Crash report

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

Process:               Python [13660]
Path:                  /usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python
Identifier:            org.python.python
Version:               3.9.12 (3.9.12)
Code Type:             X86-64 (Native)
Parent Process:        zsh [12922]
Responsible:           iTerm2 [748]
User ID:               501

Date/Time:             2022-07-13 15:45:24.4525 +0530
OS Version:            macOS 12.4 (21F79)
Report Version:        12
Bridge OS Version:     6.5 (19P5071)
Anonymous UUID:        CDD9CBE9-BEC3-A09F-0243-7CB482668B13

Sleep/Wake UUID:       F873FF55-8F77-43B0-9FFA-77CB2BE2243F

Time Awake Since Boot: 16000 seconds
Time Since Wake:       1529 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       UNKNOWN_0xD at 0x0000000000000000
Exception Codes:       0x000000000000000d, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [13660]

VM Region Info: 0 is not in any region.  Bytes before following region: 4415893504
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      107353000-107357000    [   16K] r-x/r-x SM=COW  .../MacOS/Python

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   Python                        	       0x107976785 collect + 199
1   Python                        	       0x10797655c collect_with_callback + 75
2   Python                        	       0x1079779c7 PyGC_Collect + 107
3   Python                        	       0x10794f097 Py_FinalizeEx + 413
4   Python                        	       0x107952805 Py_Exit + 13
5   Python                        	       0x1079561cf handle_system_exit + 35
6   Python                        	       0x107955bd6 _PyErr_PrintEx + 42
7   Python                        	       0x10795539c pyrun_simple_file + 455
8   Python                        	       0x1079551af PyRun_SimpleFileExFlags + 67
9   Python                        	       0x107974bfb pymain_run_file + 326
10  Python                        	       0x107974469 Py_RunMain + 993
11  Python                        	       0x1079757c4 Py_BytesMain + 42
12  dyld                          	       0x11135d51e start + 462


Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x6261737365737361  rbx: 0x0000000107482030  rcx: 0xa1bdc985c185b082  rdx: 0x6261737365737361
  rdi: 0x00007fc40a009698  rsi: 0x0000000000000000  rbp: 0x00007ff7b8bac1c0  rsp: 0x00007ff7b8bac100
   r8: 0x0000000107dc3540   r9: 0xffffffff00000000  r10: 0x0000000000000400  r11: 0x0000000000000206
  r12: 0x0000000000000002  r13: 0x00007fc40a0096b0  r14: 0x0000000000000003  r15: 0x0000000000000002
  rip: 0x0000000107976785  rfl: 0x0000000000010293  cr2: 0x000000010794f3ec
  
Logical CPU:     4
Error Code:      0x00000000 
Trap Number:     13

Thread 0 instruction stream:
  00 00 41 8d 47 01 4c 63-f0 83 f8 03 4c 89 bd 68  ..A.G.Lc....L..h
  ff ff ff 0f 8d 39 07 00-00 4b 8d 04 76 ff 84 c3  .....9...K..v...
  94 02 00 00 45 85 ff 0f-89 25 07 00 00 4d 63 e7  ....E....%...Mc.
  4b 8d 04 64 4c 8d ac c3-80 02 00 00 41 83 ff 02  K..dL.......A...
  4b 8d 04 76 48 8d 84 c3-80 02 00 00 49 0f 4d c5  K..vH.......I.M.
  48 89 45 98 49 8b 5d 00-49 39 dd 74 45 48 89 d8  H.E.I.].I9.tEH..
 [48]8b 48 10 48 8b 10 48-8b 70 08 83 e6 01 48 8d  H.H.H..H.p....H.	<==
  4c 8e 02 48 89 48 08 48-89 d0 49 39 d5 75 e1 4c  L..H.H.H..I9.u.L
  8d 35 ee 0f 00 00 48 8d-7b 10 48 8b 43 18 4c 89  .5....H.{.H.C.L.
  f6 48 89 fa ff 90 b8 00-00 00 48 8b 1b 49 39 dd  .H........H..I9.
  75 e4 4c 89 65 b8 48 8d-45 a0 48 89 40 08 48 89  u.L.e.H.E.H.@.H.
  00 49 8b 5d 00 4d 89 ec-49 39 dd 74 79 4c 8d 7d  .I.].M..I9.tyL.}

Binary Images:
       0x1077b9000 -        0x107a74fff org.python.python (3.9.12, (c) 2001-2021 Python Software Foundation.) <c9129da7-ee5b-3a6f-8129-d7a5b32b7a9c> /usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/Python
       0x111358000 -        0x1113c3fff dyld (*) <b70ce1ec-b902-3852-8268-05de00bfa8d5> /usr/lib/dyld

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=160.4M resident=0K(0%) swapped_out_or_unallocated=160.4M(100%)
Writable regions: Total=580.1M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=580.1M(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Kernel Alloc Once                    8K        1 
MALLOC                           173.8M       23 
MALLOC guard page                   16K        4 
MALLOC_LARGE (reserved)            384K        1         reserved VM address space (unallocated)
MALLOC_NANO (reserved)           384.0M        1         reserved VM address space (unallocated)
ObjC additional data                15K        1 
STACK GUARD                          4K        1 
Stack                             16.0M        1 
VM_ALLOCATE                       5896K       25 
__DATA                             771K       53 
__DATA_CONST                      3542K       49 
__DATA_DIRTY                        79K       24 
__LINKEDIT                       135.0M       13 
__TEXT                            25.4M       58 
__UNICODE                          592K        1 
dyld private memory               1024K        1 
shared memory                       12K        2 
===========                     =======  ======= 
TOTAL                            746.3M      259 
TOTAL, minus reserved VM space   361.9M      259 



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

{"app_name":"Python","timestamp":"2022-07-13 15:45:24.00 +0530","app_version":"3.9.12","slice_uuid":"04d90438-f1c2-3624-9931-dbecf8989ee4","build_version":"3.9.12","platform":1,"bundleID":"org.python.python","share_with_app_devs":1,"is_first_party":0,"bug_type":"309","os_version":"macOS 12.4 (21F79)","incident_id":"2DB42710-A91D-4518-AA34-7A22586154AB","name":"Python"}
{
  "uptime" : 16000,
  "procLaunch" : "2022-07-13 15:45:24.3640 +0530",
  "procRole" : "Unspecified",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "MacBookPro16,2",
  "procStartAbsTime" : 16957191655990,
  "coalitionID" : 726,
  "osVersion" : {
    "train" : "macOS 12.4",
    "build" : "21F79",
    "releaseType" : "User"
  },
  "captureTime" : "2022-07-13 15:45:24.4525 +0530",
  "incident" : "2DB42710-A91D-4518-AA34-7A22586154AB",
  "bug_type" : "309",
  "pid" : 13660,
  "procExitAbsTime" : 16957279541644,
  "cpuType" : "X86-64",
  "procName" : "Python",
  "procPath" : "\/usr\/local\/Cellar\/[email protected]\/3.9.12\/Frameworks\/Python.framework\/Versions\/3.9\/Resources\/Python.app\/Contents\/MacOS\/Python",
  "bundleInfo" : {"CFBundleShortVersionString":"3.9.12","CFBundleVersion":"3.9.12","CFBundleIdentifier":"org.python.python"},
  "storeInfo" : {"deviceIdentifierForVendor":"41426303-7475-557B-B1A1-DF62F151AC4C","thirdParty":true},
  "parentProc" : "zsh",
  "parentPid" : 12922,
  "coalitionName" : "com.googlecode.iterm2",
  "crashReporterKey" : "CDD9CBE9-BEC3-A09F-0243-7CB482668B13",
  "responsiblePid" : 748,
  "responsibleProc" : "iTerm2",
  "wakeTime" : 1529,
  "bridgeVersion" : {"build":"19P5071","train":"6.5"},
  "sleepWakeUUID" : "F873FF55-8F77-43B0-9FFA-77CB2BE2243F",
  "sip" : "enabled",
  "vmRegionInfo" : "0 is not in any region.  Bytes before following region: 4415893504\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  \n      __TEXT                      107353000-107357000    [   16K] r-x\/r-x SM=COW  ...\/MacOS\/Python",
  "isCorpse" : 1,
  "exception" : {"codes":"0x000000000000000d, 0x0000000000000000","rawCodes":[13,0],"type":"EXC_BAD_ACCESS","signal":"SIGSEGV","subtype":"UNKNOWN_0xD at 0x0000000000000000"},
  "termination" : {"flags":0,"code":11,"namespace":"SIGNAL","indicator":"Segmentation fault: 11","byProc":"exc handler","byPid":13660},
  "vmregioninfo" : "0 is not in any region.  Bytes before following region: 4415893504\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  \n      __TEXT                      107353000-107357000    [   16K] r-x\/r-x SM=COW  ...\/MacOS\/Python",
  "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":172215,"instructionState":{"instructionStream":{"bytes":[0,0,65,141,71,1,76,99,240,131,248,3,76,137,189,104,255,255,255,15,141,57,7,0,0,75,141,4,118,255,132,195,148,2,0,0,69,133,255,15,137,37,7,0,0,77,99,231,75,141,4,100,76,141,172,195,128,2,0,0,65,131,255,2,75,141,4,118,72,141,132,195,128,2,0,0,73,15,77,197,72,137,69,152,73,139,93,0,73,57,221,116,69,72,137,216,72,139,72,16,72,139,16,72,139,112,8,131,230,1,72,141,76,142,2,72,137,72,8,72,137,208,73,57,213,117,225,76,141,53,238,15,0,0,72,141,123,16,72,139,67,24,76,137,246,72,137,250,255,144,184,0,0,0,72,139,27,73,57,221,117,228,76,137,101,184,72,141,69,160,72,137,64,8,72,137,0,73,139,93,0,77,137,236,73,57,221,116,121,76,141,125],"offset":96}},"threadState":{"r13":{"value":140479958128304},"rax":{"value":7089074227918369633},"rflags":{"value":66195},"cpu":{"value":4},"r14":{"value":3},"rsi":{"value":0},"r8":{"value":4426839360},"cr2":{"value":4422169580},"rdx":{"value":7089074227918369633},"r10":{"value":1024},"r9":{"value":18446744069414584320},"r15":{"value":2},"rbx":{"value":4417134640},"trap":{"value":13},"err":{"value":0},"r11":{"value":518},"rip":{"value":4422330245,"matchesCrashFrame":1},"rbp":{"value":140701932896704},"rsp":{"value":140701932896512},"r12":{"value":2},"rcx":{"value":11654692987019309186},"flavor":"x86_THREAD_STATE","rdi":{"value":140479958128280}},"queue":"com.apple.main-thread","frames":[{"imageOffset":1824645,"symbol":"collect","symbolLocation":199,"imageIndex":0},{"imageOffset":1824092,"symbol":"collect_with_callback","symbolLocation":75,"imageIndex":0},{"imageOffset":1829319,"symbol":"PyGC_Collect","symbolLocation":107,"imageIndex":0},{"imageOffset":1663127,"symbol":"Py_FinalizeEx","symbolLocation":413,"imageIndex":0},{"imageOffset":1677317,"symbol":"Py_Exit","symbolLocation":13,"imageIndex":0},{"imageOffset":1692111,"symbol":"handle_system_exit","symbolLocation":35,"imageIndex":0},{"imageOffset":1690582,"symbol":"_PyErr_PrintEx","symbolLocation":42,"imageIndex":0},{"imageOffset":1688476,"symbol":"pyrun_simple_file","symbolLocation":455,"imageIndex":0},{"imageOffset":1687983,"symbol":"PyRun_SimpleFileExFlags","symbolLocation":67,"imageIndex":0},{"imageOffset":1817595,"symbol":"pymain_run_file","symbolLocation":326,"imageIndex":0},{"imageOffset":1815657,"symbol":"Py_RunMain","symbolLocation":993,"imageIndex":0},{"imageOffset":1820612,"symbol":"Py_BytesMain","symbolLocation":42,"imageIndex":0},{"imageOffset":21790,"symbol":"start","symbolLocation":462,"imageIndex":1}]}],
  "usedImages" : [
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 4420505600,
    "CFBundleShortVersionString" : "3.9.12, (c) 2001-2021 Python Software Foundation.",
    "CFBundleIdentifier" : "org.python.python",
    "size" : 2867200,
    "uuid" : "c9129da7-ee5b-3a6f-8129-d7a5b32b7a9c",
    "path" : "\/usr\/local\/Cellar\/[email protected]\/3.9.12\/Frameworks\/Python.framework\/Versions\/3.9\/Python",
    "name" : "Python",
    "CFBundleVersion" : "3.9.12"
  },
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 4583686144,
    "size" : 442368,
    "uuid" : "b70ce1ec-b902-3852-8268-05de00bfa8d5",
    "path" : "\/usr\/lib\/dyld",
    "name" : "dyld"
  }
],
  "sharedCache" : {
  "base" : 140703181619200,
  "size" : 15220686848,
  "uuid" : "398acfb4-57f6-31e0-bc82-e9959e5c92ce"
},
  "vmSummary" : "ReadOnly portion of Libraries: Total=160.4M resident=0K(0%) swapped_out_or_unallocated=160.4M(100%)\nWritable regions: Total=580.1M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=580.1M(100%)\n\n                                VIRTUAL   REGION \nREGION TYPE                        SIZE    COUNT (non-coalesced) \n===========                     =======  ======= \nKernel Alloc Once                    8K        1 \nMALLOC                           173.8M       23 \nMALLOC guard page                   16K        4 \nMALLOC_LARGE (reserved)            384K        1         reserved VM address space (unallocated)\nMALLOC_NANO (reserved)           384.0M        1         reserved VM address space (unallocated)\nObjC additional data                15K        1 \nSTACK GUARD                          4K        1 \nStack                             16.0M        1 \nVM_ALLOCATE                       5896K       25 \n__DATA                             771K       53 \n__DATA_CONST                      3542K       49 \n__DATA_DIRTY                        79K       24 \n__LINKEDIT                       135.0M       13 \n__TEXT                            25.4M       58 \n__UNICODE                          592K        1 \ndyld private memory               1024K        1 \nshared memory                       12K        2 \n===========                     =======  ======= \nTOTAL                            746.3M      259 \nTOTAL, minus reserved VM space   361.9M      259 \n",
  "legacyInfo" : {
  "threadTriggered" : {
    "queue" : "com.apple.main-thread"
  }
},
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "61301e3a61217b3110231469",
      "factorPackIds" : {
        "SIRI_FIND_MY_CONFIGURATION_FILES" : "6216ae152a40e71046e16225"
      },
      "deploymentId" : 240000016
    },
    {
      "rolloutId" : "6112e14f37f5d11121dcd519",
      "factorPackIds" : {
        "SIRI_TEXT_TO_SPEECH" : "62c4376c87beda2658c8f47d"
      },
      "deploymentId" : 240000176
    }
  ],
  "experiments" : [

  ]
}
}

Model: MacBookPro16,2, BootROM 1731.120.10.0.0 (iBridge: 19.16.15071.0.0,0), 4 processors, Quad-Core Intel Core i5, 2 GHz, 16 GB, SMC 
Graphics: Intel Iris Plus Graphics, Intel Iris Plus Graphics, Built-In
Display: Color LCD, 2560 x 1600 Retina, Main, MirrorOff, Online
Memory Module: BANK 0/ChannelA-DIMM0, 8 GB, LPDDR4X, 3733 MHz, Samsung, K4UBE3D4AA-MGCL
Memory Module: BANK 2/ChannelB-DIMM0, 8 GB, LPDDR4X, 3733 MHz, Samsung, K4UBE3D4AA-MGCL
AirPort: spairport_wireless_card_type_wifi (0x14E4, 0x7BF), wl0: Jul 12 2021 18:02:56 version 9.30.464.0.32.5.76 FWID 01-c081cfed
Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
USB Device: USB31Bus
USB Device: USB31Bus
USB Device: T2Bus
USB Device: Touch Bar Backlight
USB Device: Touch Bar Display
USB Device: Apple Internal Keyboard / Trackpad
USB Device: Headset
USB Device: Ambient Light Sensor
USB Device: FaceTime HD Camera (Built-in)
USB Device: Apple T2 Controller
Thunderbolt Bus: MacBook Pro, Apple Inc., 86.0
Thunderbolt Bus: MacBook Pro, Apple Inc., 86.0

Question about the sentinel fuse.

First, let me thank you guys for making this. It's really fun to work with and it certainly beats appending a zip to the executable. 😁

I'm unsure about the sentinel though. On one hand the goal is compatibility with build-time injection using the linker. On the other hand, the only thing that prevents me from loading link-time resources is the sentinel fuse. I'd have to run sed or something...

Looking at the test.cpp it would seem it is safe to ignore postject_has_resource() since postject_find_resource(...)will return null if no resource is found. And indeed my application works better without postject_has_resource(). Now I can load both, resources injected at build-time and resources injected using postject.

So, my question is what is the sentinel/fuse actually guarding against? It just seems odd to introduce this artificial string substitution step since it breaks one of the main design goals: compatibility with link-time injection.

Unless the fuse has a hidden purpose that I don't understand just yet, I feel postject would be better of without it.

Thanks for looking into this...

upx compatibility(Cannot pack after postject-ed)

I followed NodeJS Official SEA instructions and ended up with an executable that seems works fine.

After that I was advancing to pack the postject-ed executable with upx packer but it turns out to be failing with an error:
image

while the original node executable can be packed fine.

Don't know what's happening, I wonder is this a limitation or why is this be happening?

Signing a `darwin-x64` node executable on `darwin-arm64` leads to a segmentation fault when started [SOLVED]

macOS Ventura 13.6.4 (darwin-arm64)
MacBook Air M1
Node v20.11.1 (darwin-arm64)

Exactly following these docs I tried to inject a 7MB JS blob into a darwin-x64 node executable on the platform described above. This works without showing any error. But if I start the generated executable it fails with Segmentation fault: 11. It doesn't matter if I sign the generated executable or not, the error remains the same.

Doing the exact same thing but with a darwin-arm64 node executable works without problems. Below is the full content from the error report dialog which appears afterwards and shows a lot of V8 related error messages (note: the original app name has been replaced with [REDACTED]). Is it a known problem, that this kind of cross-platform doesn't work?

Edit: the same is true vice versa: injecting into a darwin-arm64 node executable on darwin-x64 also works but leads to the same error.

Full error report:

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

Process:               [REDACTED] [12252]
Path:                  /Users/USER/Desktop/*/[REDACTED]
Identifier:            [REDACTED]
Version:               ???
Code Type:             X86-64 (Translated)
Parent Process:        bash [32872]
Responsible:           Terminal [12207]
User ID:               501

Date/Time:             2024-03-25 22:42:21.6204 +0100
OS Version:            macOS 13.6.4 (22G513)
Report Version:        12
Anonymous UUID:        3CABB938-C8EF-4CBE-71AF-3607E1507D8F

Sleep/Wake UUID:       83FF30EA-4A13-45D7-9F61-B5DAF41335B4

Time Awake Since Boot: 1500000 seconds
Time Since Wake:       1324 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000e18
Exception Codes:       0x0000000000000001, 0x0000000000000e18

VM Region Info: 0xe18 is not in any region.  Bytes before following region: 140722841039336
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      mapped file              7ffc96f3c000-7ffcaa4d0000 [309.6M] r-x/r-x SM=COW  ...t_id=cb8ac79b

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   <translation info unavailable>	       0x10deeca30 ???
1   [REDACTED]                   	       0x10540529d v8::internal::HashTable<v8::internal::NameToIndexHashTable, v8::internal::NameToIndexShape>::Rehash(v8::internal::PtrComprCageBase) + 493
2   libsystem_platform.dylib      	    0x7ff808a7c603 _sigtramp + 51
3   [REDACTED]                   	       0x105404b30 void v8::internal::HeapObject::RehashBasedOnMap<v8::internal::Isolate>(v8::internal::Isolate*) + 240
4   [REDACTED]                   	       0x105585396 v8::internal::Deserializer<v8::internal::Isolate>::Rehash() + 70
5   [REDACTED]                   	       0x1055909ee v8::internal::ObjectDeserializer::Deserialize() + 142
6   [REDACTED]                   	       0x105590934 v8::internal::ObjectDeserializer::DeserializeSharedFunctionInfo(v8::internal::Isolate*, v8::internal::SerializedCodeData const*, v8::internal::Handle<v8::internal::String>) + 116
7   [REDACTED]                   	       0x105580490 v8::internal::CodeSerializer::Deserialize(v8::internal::Isolate*, v8::internal::AlignedCachedData*, v8::internal::Handle<v8::internal::String>, v8::ScriptOriginOptions, v8::internal::MaybeHandle<v8::internal::Script>) + 576
8   [REDACTED]                   	       0x104fd6fd1 v8::internal::Compiler::GetWrappedFunction(v8::internal::Handle<v8::internal::String>, v8::internal::Handle<v8::internal::FixedArray>, v8::internal::Handle<v8::internal::Context>, v8::internal::ScriptDetails const&, v8::internal::AlignedCachedData*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason) + 721
9   [REDACTED]                   	       0x104f2047a v8::ScriptCompiler::CompileFunctionInternal(v8::Local<v8::Context>, v8::ScriptCompiler::Source*, unsigned long, v8::Local<v8::String>*, unsigned long, v8::Local<v8::Object>*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason, v8::Local<v8::ScriptOrModule>*) + 778
10  [REDACTED]                   	       0x104f20169 v8::ScriptCompiler::CompileFunction(v8::Local<v8::Context>, v8::ScriptCompiler::Source*, unsigned long, v8::Local<v8::String>*, unsigned long, v8::Local<v8::Object>*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason) + 25
11  [REDACTED]                   	       0x104d57075 node::contextify::ContextifyContext::CompileFunctionAndCacheResult(node::Environment*, v8::Local<v8::Context>, v8::ScriptCompiler::Source*, std::__1::vector<v8::Local<v8::String>, std::__1::allocator<v8::Local<v8::String>>>, std::__1::vector<v8::Local<v8::Object>, std::__1::allocator<v8::Local<v8::Object>>>, v8::ScriptCompiler::CompileOptions, bool, v8::Local<v8::Symbol>, node::errors::TryCatchScope const&) + 101
12  [REDACTED]                   	       0x104d543a6 node::contextify::ContextifyContext::CompileFunction(v8::FunctionCallbackInfo<v8::Value> const&) + 2934
13  [REDACTED]                   	       0x104f7eda8 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, unsigned long*, int) + 856
14  [REDACTED]                   	       0x104f7e36a v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) + 186
15  [REDACTED]                   	       0x10592b1b6 Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit + 54
16  [REDACTED]                   	       0x10589cc9c Builtins_InterpreterEntryTrampoline + 220
17  [REDACTED]                   	       0x10589cc9c Builtins_InterpreterEntryTrampoline + 220
18  [REDACTED]                   	       0x10589cc9c Builtins_InterpreterEntryTrampoline + 220
19  [REDACTED]                   	       0x10589b05c Builtins_JSEntryTrampoline + 92
20  [REDACTED]                   	       0x10589ad83 Builtins_JSEntry + 131
21  [REDACTED]                   	       0x1050629df v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) + 3279
22  [REDACTED]                   	       0x105061cf5 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) + 213
23  [REDACTED]                   	       0x104f30a76 v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) + 502
24  [REDACTED]                   	       0x104c803d9 std::__1::__function::__func<node::LoadEnvironment(node::Environment*, std::__1::basic_string_view<char, std::__1::char_traits<char>>)::$_0, std::__1::allocator<node::LoadEnvironment(node::Environment*, std::__1::basic_string_view<char, std::__1::char_traits<char>>)::$_0>, v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>::operator()(node::StartExecutionCallbackInfo const&) + 153
25  [REDACTED]                   	       0x104e06789 node::RunEmbedderEntryPoint(v8::FunctionCallbackInfo<v8::Value> const&) + 249
26  [REDACTED]                   	       0x104f7eda8 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, unsigned long*, int) + 856
27  [REDACTED]                   	       0x104f7e36a v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) + 186
28  [REDACTED]                   	       0x10592b1b6 Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit + 54
29  [REDACTED]                   	       0x10589cc9c Builtins_InterpreterEntryTrampoline + 220
30  [REDACTED]                   	       0x10589b05c Builtins_JSEntryTrampoline + 92
31  [REDACTED]                   	       0x10589ad83 Builtins_JSEntry + 131
32  [REDACTED]                   	       0x1050629df v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) + 3279
33  [REDACTED]                   	       0x105061cf5 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) + 213
34  [REDACTED]                   	       0x104f30a76 v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) + 502
35  [REDACTED]                   	       0x104d44537 node::builtins::BuiltinLoader::CompileAndCall(v8::Local<v8::Context>, char const*, node::Realm*) + 311
36  [REDACTED]                   	       0x104de3ee0 node::Realm::ExecuteBootstrapper(char const*) + 64
37  [REDACTED]                   	       0x104d257c6 node::StartExecution(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) + 534
38  [REDACTED]                   	       0x104c7e846 node::LoadEnvironment(node::Environment*, std::__1::basic_string_view<char, std::__1::char_traits<char>>) + 182
39  [REDACTED]                   	       0x104dac933 node::NodeMainInstance::Run(node::ExitCode*, node::Environment*) + 147
40  [REDACTED]                   	       0x104dac6ac node::NodeMainInstance::Run() + 124
41  [REDACTED]                   	       0x104d28b93 node::Start(int, char**) + 883
42  dyld                          	       0x20ad0d41f start + 1903

Thread 1:: com.apple.rosetta.exceptionserver
0   runtime                       	    0x7ff7ffd35634 0x7ff7ffd31000 + 17972

Thread 2:
0   ???                           	    0x7ff8986669a8 ???
1   libsystem_kernel.dylib        	    0x7ff808a1518a kevent + 10
2   [REDACTED]                   	       0x1058901b9 uv__io_poll + 985
3   [REDACTED]                   	       0x10587cf36 uv_run + 566
4   [REDACTED]                   	       0x104dd58b2 node::WorkerThreadsTaskRunner::DelayedTaskScheduler::Run() + 338
5   libsystem_pthread.dylib       	    0x7ff808a4f1d3 _pthread_start + 125
6   libsystem_pthread.dylib       	    0x7ff808a4abd3 thread_start + 15

Thread 3:
0   ???                           	    0x7ff8986669a8 ???
1   libsystem_kernel.dylib        	    0x7ff808a1308e __psynch_cvwait + 10
2   libsystem_pthread.dylib       	    0x7ff808a4f758 _pthread_cond_wait + 1242
3   [REDACTED]                   	       0x10588b609 uv_cond_wait + 9
4   [REDACTED]                   	       0x104dd5ae8 node::TaskQueue<v8::Task>::BlockingPop() + 72
5   [REDACTED]                   	       0x104dd29fd node::(anonymous namespace)::PlatformWorkerThread(void*) + 317
6   libsystem_pthread.dylib       	    0x7ff808a4f1d3 _pthread_start + 125
7   libsystem_pthread.dylib       	    0x7ff808a4abd3 thread_start + 15

Thread 4:
0   ???                           	    0x7ff8986669a8 ???
1   libsystem_kernel.dylib        	    0x7ff808a1308e __psynch_cvwait + 10
2   libsystem_pthread.dylib       	    0x7ff808a4f758 _pthread_cond_wait + 1242
3   [REDACTED]                   	       0x10588b609 uv_cond_wait + 9
4   [REDACTED]                   	       0x104dd5ae8 node::TaskQueue<v8::Task>::BlockingPop() + 72
5   [REDACTED]                   	       0x104dd29fd node::(anonymous namespace)::PlatformWorkerThread(void*) + 317
6   libsystem_pthread.dylib       	    0x7ff808a4f1d3 _pthread_start + 125
7   libsystem_pthread.dylib       	    0x7ff808a4abd3 thread_start + 15

Thread 5:
0   ???                           	    0x7ff8986669a8 ???
1   libsystem_kernel.dylib        	    0x7ff808a1308e __psynch_cvwait + 10
2   libsystem_pthread.dylib       	    0x7ff808a4f758 _pthread_cond_wait + 1242
3   [REDACTED]                   	       0x10588b609 uv_cond_wait + 9
4   [REDACTED]                   	       0x104dd5ae8 node::TaskQueue<v8::Task>::BlockingPop() + 72
5   [REDACTED]                   	       0x104dd29fd node::(anonymous namespace)::PlatformWorkerThread(void*) + 317
6   libsystem_pthread.dylib       	    0x7ff808a4f1d3 _pthread_start + 125
7   libsystem_pthread.dylib       	    0x7ff808a4abd3 thread_start + 15

Thread 6:
0   ???                           	    0x7ff8986669a8 ???
1   libsystem_kernel.dylib        	    0x7ff808a1308e __psynch_cvwait + 10
2   libsystem_pthread.dylib       	    0x7ff808a4f758 _pthread_cond_wait + 1242
3   [REDACTED]                   	       0x10588b609 uv_cond_wait + 9
4   [REDACTED]                   	       0x104dd5ae8 node::TaskQueue<v8::Task>::BlockingPop() + 72
5   [REDACTED]                   	       0x104dd29fd node::(anonymous namespace)::PlatformWorkerThread(void*) + 317
6   libsystem_pthread.dylib       	    0x7ff808a4f1d3 _pthread_start + 125
7   libsystem_pthread.dylib       	    0x7ff808a4abd3 thread_start + 15

Thread 7:
0   ???                           	    0x7ff8986669a8 ???
1   libsystem_kernel.dylib        	    0x7ff808a104ce semaphore_wait_trap + 10
2   [REDACTED]                   	       0x10588b4b7 uv_sem_wait + 23
3   [REDACTED]                   	       0x104e62653 node::inspector::(anonymous namespace)::StartIoThreadMain(void*) + 19
4   libsystem_pthread.dylib       	    0x7ff808a4f1d3 _pthread_start + 125
5   libsystem_pthread.dylib       	    0x7ff808a4abd3 thread_start + 15


Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x000000000ba20029  rbx: 0x00000000000000db  rcx: 0x0000000000000000  rdx: 0x00003f51d935ae91
  rdi: 0x0000000313a7b998  rsi: 0x00003f51d935ae91  rbp: 0x0000000313a7b980  rsp: 0x0000000313a7b930
   r8: 0x0000000000001000   r9: 0x00007f9848218000  r10: 0x00000000000c7201  r11: 0x00000000000bd90e
  r12: 0x0000000000000015  r13: 0x0000000000000001  r14: 0x00007f9856813830  r15: 0x0000000313a7b998
  rip: <unavailable>       rfl: 0x0000000000000203
 tmp0: 0x00003f51ba2005b9 tmp1: 0x000000010540529d tmp2: 0x000000010b66c2a0


Binary Images:
       0x20ad07000 -        0x20ada2fff dyld (*) <8678e5e0-2643-3c19-8d09-b66e9040182c> /usr/lib/dyld
    0x7ff7ffd31000 -     0x7ff7ffd60fff runtime (*) <2583ff4d-96e5-316e-b62f-d032f09c96c6> /usr/libexec/rosetta/runtime
       0x115edc000 -        0x115f2ffff libRosettaRuntime (*) <429951a9-d91e-35d5-aaea-eecb0a38f677> /Library/Apple/*/libRosettaRuntime
       0x104c77000 -        0x109032fff [REDACTED] (*) <3c689eeb-7883-3908-a086-542366b40dad> /Users/USER/Desktop/*/[REDACTED]
               0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???
    0x7ff808a79000 -     0x7ff808a82fef libsystem_platform.dylib (*) <982c4eec-b380-3c37-ab95-14150e14dd61> /usr/lib/system/libsystem_platform.dylib
    0x7ff808a0f000 -     0x7ff808a48fff libsystem_kernel.dylib (*) <32a5f9a6-e115-35ca-a4a6-abee9ebfc910> /usr/lib/system/libsystem_kernel.dylib
    0x7ff808a49000 -     0x7ff808a54fff libsystem_pthread.dylib (*) <60b15e1f-39ea-33a1-8616-3af57dc1094a> /usr/lib/system/libsystem_pthread.dylib

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=378.4M resident=0K(0%) swapped_out_or_unallocated=378.4M(100%)
Writable regions: Total=1.0G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.0G(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Activity Tracing                   256K        1 
Kernel Alloc Once                    8K        1 
MALLOC                           162.1M       15 
MALLOC guard page                   96K        4 
MALLOC_MEDIUM (reserved)         240.0M        2         reserved VM address space (unallocated)
MALLOC_NANO (reserved)           384.0M        1         reserved VM address space (unallocated)
Memory Tag 255                   530.6M       28 
Memory Tag 255 (reserved)           16K        1         reserved VM address space (unallocated)
NODE_SEA                          7544K        1 
Rosetta Arena                     4096K        2 
Rosetta Generic                    760K      187 
Rosetta IndirectBranch              64K        1 
Rosetta JIT                      128.0M        1 
Rosetta Return Stack               140K       14 
Rosetta Thread Context             140K       14 
Stack                             48.0M        7 
Stack Guard                       56.0M        7 
VM_ALLOCATE                       13.1M        7 
__DATA                            3452K      142 
__DATA_CONST                      6827K       98 
__DATA_DIRTY                       348K       57 
__LINKEDIT                       188.8M        8 
__OBJC_RO                         66.3M        1 
__OBJC_RW                         2011K        2 
__TEXT                           189.6M      153 
dyld private memory                260K        2 
mapped file                        4.3G     1267 
shared memory                       32K        2 
unshared pmap                     2976K        2 
===========                     =======  ======= 
TOTAL                              6.3G     2028 
TOTAL, minus reserved VM space     5.7G     2028 



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

{"app_name":"[REDACTED]","timestamp":"2024-03-25 22:42:23.00 +0100","app_version":"","slice_uuid":"3c689eeb-7883-3908-a086-542366b40dad","build_version":"","platform":1,"share_with_app_devs":1,"is_first_party":1,"bug_type":"309","os_version":"macOS 13.6.4 (22G513)","roots_installed":0,"incident_id":"D31B3AC9-075E-4F82-BD7B-151A5E4E1C1D","name":"[REDACTED]"}
{
  "uptime" : 1500000,
  "procRole" : "Unspecified",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "MacBookAir10,1",
  "coalitionID" : 276958,
  "osVersion" : {
    "train" : "macOS 13.6.4",
    "build" : "22G513",
    "releaseType" : "User"
  },
  "captureTime" : "2024-03-25 22:42:21.6204 +0100",
  "incident" : "D31B3AC9-075E-4F82-BD7B-151A5E4E1C1D",
  "pid" : 12252,
  "translated" : true,
  "cpuType" : "X86-64",
  "roots_installed" : 0,
  "bug_type" : "309",
  "procLaunch" : "2024-03-25 22:42:17.6789 +0100",
  "procStartAbsTime" : 36615977491776,
  "procExitAbsTime" : 36616071188928,
  "procName" : "[REDACTED]",
  "procPath" : "\/Users\/USER\/Desktop\/*\/[REDACTED]",
  "parentProc" : "bash",
  "parentPid" : 32872,
  "coalitionName" : "com.apple.Terminal",
  "crashReporterKey" : "3CABB938-C8EF-4CBE-71AF-3607E1507D8F",
  "responsiblePid" : 12207,
  "responsibleProc" : "Terminal",
  "codeSigningID" : "",
  "codeSigningTeamID" : "",
  "codeSigningValidationCategory" : 0,
  "codeSigningTrustLevel" : 0,
  "wakeTime" : 1324,
  "sleepWakeUUID" : "83FF30EA-4A13-45D7-9F61-B5DAF41335B4",
  "sip" : "enabled",
  "vmRegionInfo" : "0xe18 is not in any region.  Bytes before following region: 140722841039336\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  \n      mapped file              7ffc96f3c000-7ffcaa4d0000 [309.6M] r-x\/r-x SM=COW  ...t_id=cb8ac79b",
  "exception" : {"codes":"0x0000000000000001, 0x0000000000000e18","rawCodes":[1,3608],"type":"EXC_BAD_ACCESS","signal":"SIGSEGV","subtype":"KERN_INVALID_ADDRESS at 0x0000000000000e18"},
  "vmregioninfo" : "0xe18 is not in any region.  Bytes before following region: 140722841039336\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  \n      mapped file              7ffc96f3c000-7ffcaa4d0000 [309.6M] r-x\/r-x SM=COW  ...t_id=cb8ac79b",
  "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":46093436,"threadState":{"flavor":"x86_THREAD_STATE","rbp":{"value":13214660992},"r12":{"value":21},"rosetta":{"tmp2":{"value":4486251168},"tmp1":{"value":4383068829},"tmp0":{"value":69620247561657}},"rbx":{"value":219},"r8":{"value":4096},"r15":{"value":13214661016},"r10":{"value":815617},"rdx":{"value":69620769074833},"rdi":{"value":13214661016},"r9":{"value":140292021911552},"r13":{"value":1},"rflags":{"value":515},"rax":{"value":195166249},"rsp":{"value":13214660912},"r11":{"value":776462},"rcx":{"value":0},"r14":{"value":140292263065648},"rsi":{"value":69620769074833}},"queue":"com.apple.main-thread","frames":[{"imageOffset":4528720432,"region":"<translation info unavailable>","imageIndex":4},{"imageOffset":7922333,"symbol":"v8::internal::HashTable<v8::internal::NameToIndexHashTable, v8::internal::NameToIndexShape>::Rehash(v8::internal::PtrComprCageBase)","symbolLocation":493,"imageIndex":3},{"imageOffset":13827,"symbol":"_sigtramp","symbolLocation":51,"imageIndex":5},{"imageOffset":7920432,"symbol":"void v8::internal::HeapObject::RehashBasedOnMap<v8::internal::Isolate>(v8::internal::Isolate*)","symbolLocation":240,"imageIndex":3},{"imageOffset":9495446,"symbol":"v8::internal::Deserializer<v8::internal::Isolate>::Rehash()","symbolLocation":70,"imageIndex":3},{"imageOffset":9542126,"symbol":"v8::internal::ObjectDeserializer::Deserialize()","symbolLocation":142,"imageIndex":3},{"imageOffset":9541940,"symbol":"v8::internal::ObjectDeserializer::DeserializeSharedFunctionInfo(v8::internal::Isolate*, v8::internal::SerializedCodeData const*, v8::internal::Handle<v8::internal::String>)","symbolLocation":116,"imageIndex":3},{"imageOffset":9475216,"symbol":"v8::internal::CodeSerializer::Deserialize(v8::internal::Isolate*, v8::internal::AlignedCachedData*, v8::internal::Handle<v8::internal::String>, v8::ScriptOriginOptions, v8::internal::MaybeHandle<v8::internal::Script>)","symbolLocation":576,"imageIndex":3},{"imageOffset":3538897,"symbol":"v8::internal::Compiler::GetWrappedFunction(v8::internal::Handle<v8::internal::String>, v8::internal::Handle<v8::internal::FixedArray>, v8::internal::Handle<v8::internal::Context>, v8::internal::ScriptDetails const&, v8::internal::AlignedCachedData*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason)","symbolLocation":721,"imageIndex":3},{"imageOffset":2790522,"symbol":"v8::ScriptCompiler::CompileFunctionInternal(v8::Local<v8::Context>, v8::ScriptCompiler::Source*, unsigned long, v8::Local<v8::String>*, unsigned long, v8::Local<v8::Object>*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason, v8::Local<v8::ScriptOrModule>*)","symbolLocation":778,"imageIndex":3},{"imageOffset":2789737,"symbol":"v8::ScriptCompiler::CompileFunction(v8::Local<v8::Context>, v8::ScriptCompiler::Source*, unsigned long, v8::Local<v8::String>*, unsigned long, v8::Local<v8::Object>*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason)","symbolLocation":25,"imageIndex":3},{"imageOffset":917621,"symbol":"node::contextify::ContextifyContext::CompileFunctionAndCacheResult(node::Environment*, v8::Local<v8::Context>, v8::ScriptCompiler::Source*, std::__1::vector<v8::Local<v8::String>, std::__1::allocator<v8::Local<v8::String>>>, std::__1::vector<v8::Local<v8::Object>, std::__1::allocator<v8::Local<v8::Object>>>, v8::ScriptCompiler::CompileOptions, bool, v8::Local<v8::Symbol>, node::errors::TryCatchScope const&)","symbolLocation":101,"imageIndex":3},{"imageOffset":906150,"symbol":"node::contextify::ContextifyContext::CompileFunction(v8::FunctionCallbackInfo<v8::Value> const&)","symbolLocation":2934,"imageIndex":3},{"imageOffset":3177896,"symbol":"v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, unsigned long*, int)","symbolLocation":856,"imageIndex":3},{"imageOffset":3175274,"symbol":"v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*)","symbolLocation":186,"imageIndex":3},{"imageOffset":13320630,"symbol":"Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit","symbolLocation":54,"imageIndex":3},{"imageOffset":12737692,"symbol":"Builtins_InterpreterEntryTrampoline","symbolLocation":220,"imageIndex":3},{"imageOffset":12737692,"symbol":"Builtins_InterpreterEntryTrampoline","symbolLocation":220,"imageIndex":3},{"imageOffset":12737692,"symbol":"Builtins_InterpreterEntryTrampoline","symbolLocation":220,"imageIndex":3},{"imageOffset":12730460,"symbol":"Builtins_JSEntryTrampoline","symbolLocation":92,"imageIndex":3},{"imageOffset":12729731,"symbol":"Builtins_JSEntry","symbolLocation":131,"imageIndex":3},{"imageOffset":4110815,"symbol":"v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&)","symbolLocation":3279,"imageIndex":3},{"imageOffset":4107509,"symbol":"v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*)","symbolLocation":213,"imageIndex":3},{"imageOffset":2857590,"symbol":"v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*)","symbolLocation":502,"imageIndex":3},{"imageOffset":37849,"symbol":"std::__1::__function::__func<node::LoadEnvironment(node::Environment*, std::__1::basic_string_view<char, std::__1::char_traits<char>>)::$_0, std::__1::allocator<node::LoadEnvironment(node::Environment*, std::__1::basic_string_view<char, std::__1::char_traits<char>>)::$_0>, v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>::operator()(node::StartExecutionCallbackInfo const&)","symbolLocation":153,"imageIndex":3},{"imageOffset":1636233,"symbol":"node::RunEmbedderEntryPoint(v8::FunctionCallbackInfo<v8::Value> const&)","symbolLocation":249,"imageIndex":3},{"imageOffset":3177896,"symbol":"v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, unsigned long*, int)","symbolLocation":856,"imageIndex":3},{"imageOffset":3175274,"symbol":"v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*)","symbolLocation":186,"imageIndex":3},{"imageOffset":13320630,"symbol":"Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit","symbolLocation":54,"imageIndex":3},{"imageOffset":12737692,"symbol":"Builtins_InterpreterEntryTrampoline","symbolLocation":220,"imageIndex":3},{"imageOffset":12730460,"symbol":"Builtins_JSEntryTrampoline","symbolLocation":92,"imageIndex":3},{"imageOffset":12729731,"symbol":"Builtins_JSEntry","symbolLocation":131,"imageIndex":3},{"imageOffset":4110815,"symbol":"v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&)","symbolLocation":3279,"imageIndex":3},{"imageOffset":4107509,"symbol":"v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*)","symbolLocation":213,"imageIndex":3},{"imageOffset":2857590,"symbol":"v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*)","symbolLocation":502,"imageIndex":3},{"imageOffset":841015,"symbol":"node::builtins::BuiltinLoader::CompileAndCall(v8::Local<v8::Context>, char const*, node::Realm*)","symbolLocation":311,"imageIndex":3},{"imageOffset":1494752,"symbol":"node::Realm::ExecuteBootstrapper(char const*)","symbolLocation":64,"imageIndex":3},{"imageOffset":714694,"symbol":"node::StartExecution(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>)","symbolLocation":534,"imageIndex":3},{"imageOffset":30790,"symbol":"node::LoadEnvironment(node::Environment*, std::__1::basic_string_view<char, std::__1::char_traits<char>>)","symbolLocation":182,"imageIndex":3},{"imageOffset":1268019,"symbol":"node::NodeMainInstance::Run(node::ExitCode*, node::Environment*)","symbolLocation":147,"imageIndex":3},{"imageOffset":1267372,"symbol":"node::NodeMainInstance::Run()","symbolLocation":124,"imageIndex":3},{"imageOffset":727955,"symbol":"node::Start(int, char**)","symbolLocation":883,"imageIndex":3},{"imageOffset":25631,"symbol":"start","symbolLocation":1903,"imageIndex":0}]},{"id":46093488,"name":"com.apple.rosetta.exceptionserver","frames":[{"imageOffset":17972,"imageIndex":1}]},{"id":46093489,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":24970,"symbol":"kevent","symbolLocation":10,"imageIndex":6},{"imageOffset":12685753,"symbol":"uv__io_poll","symbolLocation":985,"imageIndex":3},{"imageOffset":12607286,"symbol":"uv_run","symbolLocation":566,"imageIndex":3},{"imageOffset":1435826,"symbol":"node::WorkerThreadsTaskRunner::DelayedTaskScheduler::Run()","symbolLocation":338,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]},{"id":46093490,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":16526,"symbol":"__psynch_cvwait","symbolLocation":10,"imageIndex":6},{"imageOffset":26456,"symbol":"_pthread_cond_wait","symbolLocation":1242,"imageIndex":7},{"imageOffset":12666377,"symbol":"uv_cond_wait","symbolLocation":9,"imageIndex":3},{"imageOffset":1436392,"symbol":"node::TaskQueue<v8::Task>::BlockingPop()","symbolLocation":72,"imageIndex":3},{"imageOffset":1423869,"symbol":"node::(anonymous namespace)::PlatformWorkerThread(void*)","symbolLocation":317,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]},{"id":46093491,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":16526,"symbol":"__psynch_cvwait","symbolLocation":10,"imageIndex":6},{"imageOffset":26456,"symbol":"_pthread_cond_wait","symbolLocation":1242,"imageIndex":7},{"imageOffset":12666377,"symbol":"uv_cond_wait","symbolLocation":9,"imageIndex":3},{"imageOffset":1436392,"symbol":"node::TaskQueue<v8::Task>::BlockingPop()","symbolLocation":72,"imageIndex":3},{"imageOffset":1423869,"symbol":"node::(anonymous namespace)::PlatformWorkerThread(void*)","symbolLocation":317,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]},{"id":46093492,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":16526,"symbol":"__psynch_cvwait","symbolLocation":10,"imageIndex":6},{"imageOffset":26456,"symbol":"_pthread_cond_wait","symbolLocation":1242,"imageIndex":7},{"imageOffset":12666377,"symbol":"uv_cond_wait","symbolLocation":9,"imageIndex":3},{"imageOffset":1436392,"symbol":"node::TaskQueue<v8::Task>::BlockingPop()","symbolLocation":72,"imageIndex":3},{"imageOffset":1423869,"symbol":"node::(anonymous namespace)::PlatformWorkerThread(void*)","symbolLocation":317,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]},{"id":46093493,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":16526,"symbol":"__psynch_cvwait","symbolLocation":10,"imageIndex":6},{"imageOffset":26456,"symbol":"_pthread_cond_wait","symbolLocation":1242,"imageIndex":7},{"imageOffset":12666377,"symbol":"uv_cond_wait","symbolLocation":9,"imageIndex":3},{"imageOffset":1436392,"symbol":"node::TaskQueue<v8::Task>::BlockingPop()","symbolLocation":72,"imageIndex":3},{"imageOffset":1423869,"symbol":"node::(anonymous namespace)::PlatformWorkerThread(void*)","symbolLocation":317,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]},{"id":46093494,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":5326,"symbol":"semaphore_wait_trap","symbolLocation":10,"imageIndex":6},{"imageOffset":12666039,"symbol":"uv_sem_wait","symbolLocation":23,"imageIndex":3},{"imageOffset":2012755,"symbol":"node::inspector::(anonymous namespace)::StartIoThreadMain(void*)","symbolLocation":19,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]}],
  "usedImages" : [
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 8771366912,
    "size" : 638976,
    "uuid" : "8678e5e0-2643-3c19-8d09-b66e9040182c",
    "path" : "\/usr\/lib\/dyld",
    "name" : "dyld"
  },
  {
    "source" : "P",
    "arch" : "arm64",
    "base" : 140703125671936,
    "size" : 196608,
    "uuid" : "2583ff4d-96e5-316e-b62f-d032f09c96c6",
    "path" : "\/usr\/libexec\/rosetta\/runtime",
    "name" : "runtime"
  },
  {
    "source" : "P",
    "arch" : "arm64",
    "base" : 4662870016,
    "size" : 344064,
    "uuid" : "429951a9-d91e-35d5-aaea-eecb0a38f677",
    "path" : "\/Library\/Apple\/*\/libRosettaRuntime",
    "name" : "libRosettaRuntime"
  },
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 4375146496,
    "size" : 71024640,
    "uuid" : "3c689eeb-7883-3908-a086-542366b40dad",
    "path" : "\/Users\/USER\/Desktop\/*\/[REDACTED]",
    "name" : "[REDACTED]"
  },
  {
    "size" : 0,
    "source" : "A",
    "base" : 0,
    "uuid" : "00000000-0000-0000-0000-000000000000"
  },
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 140703273816064,
    "size" : 40944,
    "uuid" : "982c4eec-b380-3c37-ab95-14150e14dd61",
    "path" : "\/usr\/lib\/system\/libsystem_platform.dylib",
    "name" : "libsystem_platform.dylib"
  },
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 140703273381888,
    "size" : 237568,
    "uuid" : "32a5f9a6-e115-35ca-a4a6-abee9ebfc910",
    "path" : "\/usr\/lib\/system\/libsystem_kernel.dylib",
    "name" : "libsystem_kernel.dylib"
  },
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 140703273619456,
    "size" : 49152,
    "uuid" : "60b15e1f-39ea-33a1-8616-3af57dc1094a",
    "path" : "\/usr\/lib\/system\/libsystem_pthread.dylib",
    "name" : "libsystem_pthread.dylib"
  }
],
  "sharedCache" : {
  "base" : 140703269486592,
  "size" : 21474836480,
  "uuid" : "f923a52e-db00-3075-b1a9-3fdae7809671"
},
  "vmSummary" : "ReadOnly portion of Libraries: Total=378.4M resident=0K(0%) swapped_out_or_unallocated=378.4M(100%)\nWritable regions: Total=1.0G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.0G(100%)\n\n                                VIRTUAL   REGION \nREGION TYPE                        SIZE    COUNT (non-coalesced) \n===========                     =======  ======= \nActivity Tracing                   256K        1 \nKernel Alloc Once                    8K        1 \nMALLOC                           162.1M       15 \nMALLOC guard page                   96K        4 \nMALLOC_MEDIUM (reserved)         240.0M        2         reserved VM address space (unallocated)\nMALLOC_NANO (reserved)           384.0M        1         reserved VM address space (unallocated)\nMemory Tag 255                   530.6M       28 \nMemory Tag 255 (reserved)           16K        1         reserved VM address space (unallocated)\nNODE_SEA                          7544K        1 \nRosetta Arena                     4096K        2 \nRosetta Generic                    760K      187 \nRosetta IndirectBranch              64K        1 \nRosetta JIT                      128.0M        1 \nRosetta Return Stack               140K       14 \nRosetta Thread Context             140K       14 \nStack                             48.0M        7 \nStack Guard                       56.0M        7 \nVM_ALLOCATE                       13.1M        7 \n__DATA                            3452K      142 \n__DATA_CONST                      6827K       98 \n__DATA_DIRTY                       348K       57 \n__LINKEDIT                       188.8M        8 \n__OBJC_RO                         66.3M        1 \n__OBJC_RW                         2011K        2 \n__TEXT                           189.6M      153 \ndyld private memory                260K        2 \nmapped file                        4.3G     1267 \nshared memory                       32K        2 \nunshared pmap                     2976K        2 \n===========                     =======  ======= \nTOTAL                              6.3G     2028 \nTOTAL, minus reserved VM space     5.7G     2028 \n",
  "legacyInfo" : {
  "threadTriggered" : {
    "queue" : "com.apple.main-thread"
  }
},
  "logWritingSignature" : "33b38e69a85a97bad98f692555a076c7b41d047d",
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "62fe74515312cd4599bd3c80",
      "factorPackIds" : {
        "MYRIAD_BOOSTS" : "62fe74805312cd4599bd3c81"
      },
      "deploymentId" : 240000006
    },
    {
      "rolloutId" : "6425c75e4327780c10cc4252",
      "factorPackIds" : {
        "SIRI_HOME_AUTOMATION_INTENT_SELECTION_CACHE" : "642600a457e7664b1698eb32"
      },
      "deploymentId" : 240000004
    }
  ],
  "experiments" : [
    {
      "treatmentId" : "5d51a80d-93ec-47e1-9027-675002e78e4a",
      "experimentId" : "6384d56b96e8d228551ec182",
      "deploymentId" : 400000031
    },
    {
      "treatmentId" : "a3f9ec09-b145-49f3-8142-da4a1f338456",
      "experimentId" : "65f21aa774b6f500a45abd7d",
      "deploymentId" : 400000002
    }
  ]
}
}

Model: MacBookAir10,1, BootROM 10151.81.1, proc 8:4:4 processors, 16 GB, SMC 
Graphics: Apple M1, Apple M1, Built-In
Display: Retina-Display, 2560 x 1600 Retina, Main, MirrorOff, Online
Memory Module: LPDDR4, Hynix
AirPort: spairport_wireless_card_type_wifi (0x14E4, 0x4378), wl0: May 13 2023 07:20:48 version 18.20.383.15.7.8.150 FWID 01-b37727a5
Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
USB Device: USB31Bus
USB Device: USB31Bus
Thunderbolt Bus: MacBook Air, Apple Inc.
Thunderbolt Bus: MacBook Air, Apple Inc.

RuntimeError: Aborted when injecting into debug build of Node.js on Linux, Windows and macOS

System info

Linux

$ uname -a
Linux darshan-NUC11PAHi7 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Windows

 uname -a
MINGW64_NT-10.0-22000 DESKTOP-MDFU6BO 3.1.7-340.x86_64 2021-10-12 16:29 UTC x86_64 Msys

macOS

$ uname -a
Darwin Darshans-MacBook-Pro.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 x86_64

Versions

Node.js: v16.15.0 (debug build)
Postject: Built from #45

Repro

echo "Hello, world!" > file.txt
postject ./node lol ./file.txt

./node is a debug build of Node.js v16.15.0 and it has a size of 1.4G on Linux, 105M on Windows and 76M on Intel macOS.

Error logs

Linux

Aborted()	
/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9
var Module=typeof Module!="undefined"?Module:{}; ... more unreadable code ...

RuntimeError: Aborted(). Build with -sASSERTIONS for more info.
    at abort (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:7843)
    at _abort (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:92618)
    at wasm://wasm/00d4368e:wasm-function[114]:0x3da3
    at invoke_ii (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:113924)
    at wasm://wasm/00d4368e:wasm-function[3887]:0x2afb02
    at invoke_ii (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:113924)
    at wasm://wasm/00d4368e:wasm-function[2955]:0x1b1552
    at wasm://wasm/00d4368e:wasm-function[2346]:0x135036
    at Object.injectIntoELF (eval at new_ (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:73676), <anonymous>:11:10)
    at Command.main (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/main.js:89:38)

Windows

Aborted()	
C:\Users\admin\Desktop\git\starship\node_modules\@raisinten\postject\dist\postject.js:9
var Module=typeof Module!="undefined"?Module:{}; ... more unreadable code ...

RuntimeError: Aborted(). Build with -sASSERTIONS for more info.
    at abort (C:\Users\admin\Desktop\git\starship\node_modules\@raisinten\postject\dist\postject.js:9:7843)
    at _abort (C:\Users\admin\Desktop\git\starship\node_modules\@raisinten\postject\dist\postject.js:9:92618)
    at wasm://wasm/00d4368e:wasm-function[114]:0x3da3
    at wasm://wasm/00d4368e:wasm-function[419]:0x1b6b1
    at wasm://wasm/00d4368e:wasm-function[1559]:0xc64b4
    at invoke_vii (C:\Users\admin\Desktop\git\starship\node_modules\@raisinten\postject\dist\postject.js:9:113453)
    at wasm://wasm/00d4368e:wasm-function[1010]:0x5a689
    at wasm://wasm/00d4368e:wasm-function[2815]:0x1860f4
    at wasm://wasm/00d4368e:wasm-function[2346]:0x135036
    at Object.injectIntoPE (eval at new_ (C:\Users\admin\Desktop\git\starship\node_modules\@raisinten\postject\dist\postject.js:1:1), <anonymous>:11:10)

macOS

Aborted()	
/home/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9
var Module=typeof Module!="undefined"?Module:{}; ... more unreadable code ...

RuntimeError: Aborted(). Build with -sASSERTIONS for more info.
    at abort (/Users/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:7918)
    at _abort (/Users/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:92964)
    at wasm://wasm/00d4368e:wasm-function[114]:0x3da3
    at invoke_ii (/Users/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:114307)
    at wasm://wasm/00d4368e:wasm-function[2643]:0x149f63
    at invoke_iii (/Users/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:114155)
    at wasm://wasm/00d4368e:wasm-function[1427]:0x9c6d3
    at invoke_iii (/Users/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:114155)
    at wasm://wasm/00d4368e:wasm-function[2633]:0x149287
    at wasm://wasm/00d4368e:wasm-function[1507]:0xb624e

after building with -sASSERTIONS. the error looks like this:

Linux

Aborted(native code called abort())
/home/darshan/Desktop/git/postject/dist/postject.js:9
var Module=typeof Module!="undefined"?Module:{};... more unreadable code ...

RuntimeError: Aborted(native code called abort())
    at abort (/home/darshan/Desktop/git/postject/dist/postject.js:9:17627)
    at _abort (/home/darshan/Desktop/git/postject/dist/postject.js:9:111887)
    at <anonymous>:wasm-function[3619]:0x2af151
    at <anonymous>:wasm-function[877]:0x7ab90
    at invoke_iiiii (/home/darshan/Desktop/git/postject/dist/postject.js:9:136355)
    at <anonymous>:wasm-function[1269]:0xd8ca8
    at <anonymous>:wasm-function[532]:0x4c919
    at <anonymous>:wasm-function[554]:0x55102
    at dynCall_iiij (<anonymous>:wasm-function[3917]:0x2befaf)
    at /home/darshan/Desktop/git/postject/dist/postject.js:9:18225

Additional info

It works when I inject data into an official release build of the same version of Node.js which is 72M in size on Linux.

Handcrafted stack trace for Linux -

SEA issue at step running postject to inject the blob

OS: MacOS Sonoma 14.2.1
Processor: Intel

Completely follow the document
https://nodejs.org/api/single-executable-applications.html
Step 6. Inject the blob into the copied binary by running postject
Command:
npx postject hello NODE_SEA_BLOB sea-prep.blob \ --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \ --macho-segment-name NODE_SEA

Error:
Start injection of NODE_SEA_BLOB in hello...
Error: Multiple occurences of sentinel "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2" found in the binary

Anyone can help with this issue? Thanks!

`__dirname` and `__filename` in the JS wrapper around the WASM binary can't be used inside Node.js core

The JS wrapper around the WASM file that emscripten produces contains things like __dirname and __filename, like in here:
https://github.com/emscripten-core/emscripten/blob/929a6d5810908065bf23aa2af492da32ab572d57/src/shell.js#L199

scriptDirectory = __dirname + '/';

These symbols are not exposed to the internal files of Node.js, so I don't think Postject can be embedded into Node.js unless we find a way to get rid of these symbols.

Should we use the wasi-sdk to compile Postject instead of emscripten, so that the wasm binary doesn't expect us to provide a very complex wrapper that it expects now? That should make it possible for us to write the JS wrapper and maintain it. This would also give us more control. Undid follows the same approach and they compile llhttp like this - https://github.com/nodejs/undici/blob/d7c74f71634d8fdbfdb1807104020f2d3b02aed9/build/wasm.js#L53-L73

// Build wasm simd binary
execSync(`${WASI_ROOT}/bin/clang \
 --sysroot=${WASI_ROOT}/share/wasi-sysroot \
 -target wasm32-unknown-wasi \
 -msimd128 \
 -Ofast \
 -fno-exceptions \
 -fvisibility=hidden \
 -mexec-model=reactor \
 -Wl,-error-limit=0 \
 -Wl,-O3 \
 -Wl,--lto-O3 \
 -Wl,--strip-all \
 -Wl,--allow-undefined \
 -Wl,--export-dynamic \
 -Wl,--export-table \
 -Wl,--export=malloc \
 -Wl,--export=free \
 ${join(WASM_SRC, 'src')}/*.c \
 -I${join(WASM_SRC, 'include')} \
 -o ${join(WASM_OUT, 'llhttp_simd.wasm')}`, { stdio: 'inherit' })

Any better approach?

Document the postject API

Tests will cover the postject API, but it would help description is added to the API in header file.

Error: buffer[colonIndex].charCodeAt is not a function

I get this error

Start injection of NODE_SEA_BLOB in app.exe...
Error: buffer[colonIndex].charCodeAt is not a function
 ELIFECYCLE  Command failed with exit code 1.

from this command npx postject app.exe NODE_SEA_BLOB ./sea/sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b.

I'm using node v20.6.1 and [email protected]

Add a fuse to speed up resource access

See nodejs/node#45038 (comment) cc @mhdawson

I think we need the concept of a "fuse" here. Something like what I had in src/node_single_executable_application.cc on line 43, as borrowed from electron.

That ensures that if you are not using SEA, the overhead is as close to possible as 0. It does mean there is an extra step in the bundling but I don't see that as a big issue.

Do we want to solve this inside postject? It can speed up the resource access calls for the cases where you just wanna know if something has been injected instead of knowing what has been injected into a section.

The only problem I can think of here is that in case there is another occurrence of the sentinel string in the binary, this might confuse postject but that's probably gonna be unlikely if used carefully because the sentinel string is going to have some random bytes in the beginning which should make it hard for that to be repeated somewhere in the binary coincidentally by mistake.

Unable to make build on macOS 13 due to deprecated functions

Builds fail in macOS 13 due to deprecated functions getsectdatafromFramework and getsectdata,

The full error message:

Error: In file included from /Users/debadreechatterjee/Documents/Personal/postject/test/test.c:4:
/Users/debadreechatterjee/Documents/Personal/postject/test/../dist/postject-api.h:68:11: error: 'getsectdatafromFramework' is deprecated: first deprecated in macOS 13.0 - No longer supported [-Werror,-Wdeprecated-declarations]
    ptr = getsectdatafromFramework(options->macho_framework_name, segment_name,
          ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/mach-o/getsect.h:51:14: note: 'getsectdatafromFramework' has been explicitly marked deprecated here
extern char *getsectdatafromFramework(
             ^
In file included from /Users/debadreechatterjee/Documents/Personal/postject/test/test.c:4:
/Users/debadreechatterjee/Documents/Personal/postject/test/../dist/postject-api.h:72:11: error: 'getsectdata' is deprecated: first deprecated in macOS 13.0 [-Werror,-Wdeprecated-declarations]
    ptr = getsectdata(segment_name, section_name != NULL ? section_name : name,
          ^~~~~~~~~~~
          use getsectiondata()
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/mach-o/getsect.h:46:14: note: 'getsectdata' has been explicitly marked deprecated here
extern char *getsectdata(
             ^
2 errors generated.
make[2]: *** [CMakeFiles/c_test.dir/test.c.o] Error 1
make[1]: *** [CMakeFiles/c_test.dir/all] Error 2
make: *** [all] Error 2
    at file:///Users/debadreechatterjee/Documents/Personal/postject/scripts/build.mjs:58:8
    exit code: 2 (Misuse of shell builtins)

Calling `postject_find_resource()` segfaults on `rhel8-ppc64le`

The crash originates from here:

if (note->n_namesz != 0 && note->n_descsz != 0 &&

while dereferencing the note pointer. Note that note is not a null pointer here.

This is happening for the case where the resource hasn't been injected into the node binary.

This is one of the blockers for the single-executable PR in core - nodejs/node#45038. I think calling postject_has_resource() first would also unblock that PR.

Refs: nodejs/build#3168

Internally use `objcopy --add-section` on macOS and Linux

objcopy --add-section works on Linux - https://man7.org/linux/man-pages/man1/objcopy.1.html.

After https://reviews.llvm.org/D66283 landed, llvm-objcopy on macOS too started supporting this feature: https://llvm.org/docs/CommandGuide/llvm-objcopy.html#cmdoption-llvm-objcopy-add-section

This demo is using the Node.js binary that has been built from nodejs/node#45038 on macOS:

$ ls
index.js node
$ cat index.js
console.log('Hello, world!');
$ /usr/local/opt/llvm/bin/llvm-objcopy --add-section __POSTJECT,__NODE_JS_CODE=index.js node sea
$ ./sea
Hello, world!

Advantages:

  • We can avoid maintaining any complex code that adds a new section into a binary and reuse existing tools.
  • Much faster than the current state of postject.
    $ /usr/bin/time /usr/local/opt/llvm/bin/llvm-objcopy --add-section __POSTJECT,__NODE_JS_CODE=index.js node sea
            0.37 real         0.22 user         0.11 sys
    $ /usr/bin/time postject sea NODE_JS_CODE index.js
           37.59 real        40.05 user         1.12 sys
  • Possibly works on AIX also? I would need access to such a system to make sure.

Disadvantage:

  • objcopy is present by default on Linux but users would have to download it manually on macOS along with other tools using brew install llvm.

@nodejs/single-executable wdyt?

@bnoordhuis I'd also like to hear your thoughts on this since you were sharing some insights on the resource injection part in nodejs/node#45066.

Investigate why running the wasm blob in Postject is slow

See the discussion in nodejs/node#47741.


Measurements of injecting a 4KB resource into a Mach-O binary on an x86_64 macOS with Node.js v20.1.0:

TLDR -

std::vector<uint8_t> vec_from_val(const emscripten::val& value) {
// TODO(dsanders11) - vecFromJSArray incurs a copy, so memory usage is higher
// than it needs to be. Explore ways to access the memory
// directly and avoid the copy.
return emscripten::vecFromJSArray<uint8_t>(value);
}
is where the bottleneck is.

Replacing the emscripten::vecFromJSArray<uint8_t>(value) call at

return emscripten::vecFromJSArray<uint8_t>(value);
with a call to emscripten::vecFromJSArray<uint8_t>(value) reduces the time consumption from ~30s to ~6s.

Error: Multiple occurences of sentinel found in the binary

Hello,
I'm trying to build a single executable app and encountered this problem:

➜ echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js
➜ echo '{ "main": "hello.js", "output": "sea-prep.blob" }' > sea-config.json
➜ node --experimental-sea-config sea-config.json
Wrote single executable preparation blob to sea-prep.blob
➜ cp $(command -v node) hello
➜ codesign --remove-signature hello
➜ npx postject hello NODE_SEA_BLOB sea-prep.blob \
    --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \
    --macho-segment-name NODE_SEA
Start injection of NODE_SEA_BLOB in hello...
Error: Multiple occurences of sentinel "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2" found in the binary

I also tried with pnpx instead of npx.
Some information about my environment:

➜ uname -a 
Darwin istirs-Air.lan 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:34 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8103 arm64
➜ node -v 
v21.5.0
➜ npx -v 
10.2.4

Print a message when the build is successful

Currently, postject can print warnings. In this case, it should notify the users that the command was successful.

Another option is to clearly specify what is a warning and what is an error.

SEA created following Node.js documentation doesn't work

Doing exactly as documented in https://nodejs.org/api/single-executable-applications.html

On macOS arm64

$ cat hello.js
console.log(`Hello, ${process.argv[2]}!`);

$ ./hello -v
v19.7.0

$ npx postject hello NODE_JS_CODE hello.js \
    --sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \
    --macho-segment-name NODE_JS

$ ./hello
[1]    20992 killed     ./hello

$ ./hello world
[1]    21015 killed     ./hello world

On Linux x64

$ cat hello.js
console.log(`Hello, ${process.argv[2]}!`);

$ ./hello -v
v19.7.0

$ npx postject hello NODE_JS_CODE hello.js \
    --sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2
Can't find string offset for section name '.note.100'
Can't find string offset for section name '.note.100'
Can't find string offset for section name '.note.100'
Can't find string offset for section name '.note.100'
Can't find string offset for section name '.note.100'
Can't find string offset for section name '.note'
Can't find string offset for section name '.note.100'
Can't find string offset for section name '.note.100'
Can't find string offset for section name '.note.100'

$ ./hello
[1]    2517236 segmentation fault (core dumped)  ./hello

$ ./hello world
[1]    2517265 segmentation fault (core dumped)  ./hello world

What to use for CI

Postject was using CircleCI under the Postman account and it got disconnected after the repo got transferred to the nodejs org. Now that CI doesn't work anymore, it's time to reconsider what we should use for CI:

  • use a CircleCI account from Node.js on the free tier
  • switch to Node.js' Jenkins CI
  • use GitHub Actions
  • something else

@nodejs/single-executable wdyt?

stripping postjected executable causes segmentation fault

cp $(which node) .
npx postject node NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2

warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
💉 Injection done!

./node

hello

strip node

strip: stpmoKLq: section .text lma 0xb68000 adjusted to 0xb68418
strip: stpmoKLq: warning: allocated section `' not in segment
strip: stpmoKLq: warning: allocated section `' not in segment
strip: stpmoKLq: warning: allocated section `' not in segment
strip: stpmoKLq: warning: allocated section `' not in segment
strip: stpmoKLq: warning: allocated section `' not in segment
strip: stpmoKLq: warning: allocated section `' not in segment
strip: stpmoKLq: warning: allocated section `' not in segment
strip: stpmoKLq: warning: allocated section `' not in segment
strip: stpmoKLq: warning: allocated section `' not in segment

./node

Segmentation fault

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.