Open sdwannfv opened 1 year ago
I just tried your testcase on macOS 12.6.3 and 13.2, with HookCase 7.1.1 (the current version), and had no problems.
Remember that you need to codesign hook.dylib
if you haven't completely disabled SIP -- if you've used csrutil enable --without kext
instead of csrutil disable
.
hook.dylib is codesigned, the Terminal process self not quit, but i can't input any commmand, here is log
(Wed Feb 1 14:25:37 2023) /usr/bin/login[1702] [0x11130f600] [open](/usr/bin, 0x0)-->3
(Wed Feb 1 14:25:37 2023) /usr/bin/login[1702] [0x11130f600] [open](/usr/bin/Info.plist, 0x0)-->-1
(Wed Feb 1 14:25:37 2023) /usr/bin/login[1702] [0x11130f600] [open](/etc/nologin, 0x0)-->-1
(Wed Feb 1 14:25:37 2023) /usr/bin/login[1702] [0x11130f600] [open](/System/Library/OpenDirectory/request-schema.plist, 0x0)-->3
Last login: Wed Feb 1 14:25:14 on ttys004
[Process completed]
Now I see your problem. It seems that every time you click on the second Terminal window (the one you just spawned), the whole Terminal app restarts and the (second) window disappears.
I haven't found out why this happens, but I do have a workaround. Add HC_NOKIDS=1
to the command you use to start a second instance of Terminal:
HC_NOKIDS=1 HC_INSERT_LIBRARY=/path/to/hook.dylib /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
I don't understand why this works.
It's entirely possible that your problem isn't a bug in HookCase. But I'll leave this issue open until I know more. It will probably stay open for quite a long time.
Possible causes that I've already ruled out:
LogWithFormat()
gets re-entered: But preventing this doesn't get rid of the problem.LogWithFormat()
: But it also happens with printf()
.__open()
.One more thing: The problem goes away if the hook library doesn't do any logging from its open()
hook (using either LogWithFormat()
or printf()
). This is a clue to what's going wrong. But clearly it isn't a viable solution.
This problem may be specific to open()
. It doesn't happen hooking some other system calls, like read()
and proc_pidinfo()
.
And, interestingly, it also happens with Alacritty.
it might have had something to do with LogWithFormat, when VIRTUAL_SERIAL_PORT is not defined and LogWithFormat to stdout, it will cause xpc Connection interrupted, it looked like that
2023-02-02 15:42:49.150 TextEdit[2774:66898] +[NSXPCSharedListener endpointForReply:withListenerName:]: an error occurred while attempting to obtain endpoint for listener '': Connection interrupted
2023-02-02 15:42:49.150 TextEdit[2774:66898] failed to warm up class NSOpenAndSavePanelService in service com.apple.appkit.xpc.openAndSavePanelService due to Error Domain=NSCocoaErrorDomain Code=4099 "<dictionary: 0x7ff856cee6c0> { count = 1, transaction: 0, voucher = 0x0, contents =
"XPCErrorDescription" => <string: 0x7ff856cee8b0> { length = 22, contents = "Connection interrupted" }
} for listener for whole-service management; BEFORE ASSIGNING A BUG TO ANYONE ELSE, search backward for earlier logging regarding service/extension 'com.apple.appkit.xpc.openAndSavePanelService'" UserInfo={NSDebugDescription=<dictionary: 0x7ff856cee6c0> { count = 1, transaction: 0, voucher = 0x0, contents =
"XPCErrorDescription" => <string: 0x7ff856cee8b0> { length = 22, contents = "Connection interrupted" }
} for listener for whole-service management; BEFORE ASSIGNING A BUG TO ANYONE ELSE, search backward for earlier logging regarding service/extension 'com.apple.appkit.xpc.openAndSavePanelService'}
meanwhile when VIRTUAL_SERIAL_PORT is defined and LogWithFormat to PySerialPortLogger opened tty, xpc Connection interrupted will not occur
Thanks for this information. I'll keep it in mind.
hook lib
command