Post

Replies

Boosts

Views

Activity

Get Window Number from Keyboard Event Using addGlobalMonitorForEventsMatchingMask and addLocalMonitorForEventsMatchingMask (Objective-C)
I am using addGlobalMonitorForEventsMatchingMask and addLocalMonitorForEventsMatchingMask to monitor the global as well as local keyboard events by providing a mask as NSEventMaskKeyDown. As global event monitoring requires accessibility permission, I am providing that as well, but the window number I am getting from the NSEvent* passed to the monitor as an argument as 0 always. Also, the window object in the event object is null (0x0). I also tried to get the window number from the CGEvent object in the NSEvent object, and the window number is still 0. Please help me with where I am wrong. This is my main file for a headless application: main.m #import <Foundation/Foundation.h> #include "keylogger.h" int main(int argc, const char * argv[]) {   @autoreleasepool {     AppDelegate *delegate = [[AppDelegate alloc] init];     NSApplication * application = [NSApplication sharedApplication];     [application setDelegate:delegate];     [NSApp run];   } } Header file: keylogger.h #import <AppKit/AppKit.h> #import <Foundation/Foundation.h> @interface AppDelegate : NSObject <NSApplicationDelegate> - (void)applicationDidFinishLaunching:(NSNotification *)aNotification; @end File in which I am adding the monitors: keylogger.m #import "keylogger.h" @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {   [NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask                      handler:^(NSEvent *event) {     NSLog(@"%lld", (long long)event.windowNumber);   }];   [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask handler:^NSEvent * _Nullable(NSEvent *event) {     NSLog(@"%lld", (long long)event.windowNumber);     return event;   }]; } @end Note: In order to run it, please create a command line tool application in Xcode.
3
0
787
Feb ’23
AXUIElementCopyAttributeValues crashing on macOS Sonoma
Stack trace OS Version: macOS 14.1 (23B74) Report Version: 104 Crashed Thread: 1622089 Application Specific Information: Fatal Error: EXC_BAD_ACCESS / KERN_PROTECTION_FAILURE / 0x16c91ffc0 Thread 1622089 Crashed: 0 libsystem_malloc.dylib 0x189cfcbc4 tiny_malloc_from_free_list 1 libsystem_malloc.dylib 0x189cfb2c4 szone_malloc_should_clear 2 Electron Framework 0x10e39f904 allocator_shim::MallocZoneFunctionsToReplaceDefault::lambda::__invoke (allocator_shim.cc:232) 3 CoreFoundation 0x189f5273c __CFStrAllocateMutableContents 4 CoreFoundation 0x189f52028 __CFStringChangeSizeMultiple 5 CoreFoundation 0x189f6d62c __CFStringAppendBytes 6 CoreFoundation 0x189f6c454 __CFStringAppendFormatCore 7 CoreFoundation 0x18a0a0ad0 _CFStringCreateWithFormatAndArgumentsReturningMetadata 8 CoreFoundation 0x189fb3e48 CFStringCreateWithFormatAndArguments 9 CoreFoundation 0x189f69e1c CFStringCreateWithFormat 10 HIServices 0x1903291a8 setWasOnceAuthorizeForAccessibility 11 HIServices 0x1903235a0 AXUIElementCopyAttributeValues
2
1
667
Nov ’23
Accessibility permission corrupted AXWebArea not found
I have an application that uses Accessibility APIs to determine if a browser tab with website content is present by checking for the AXWebArea role element. However, some users have reported that the app is not working after a recent update. When I check for permission using the following code, the result is YES, but the app still cannot detect the AXWebArea element in the browser though other elements like AXButton were there: NSDictionary *options = @{(__bridge id)kAXTrustedCheckOptionPrompt : @YES}; NSLog(@“%d”, AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)options)); The issue is resolved when the app is removed and re-added to the Accessibility permissions list in the System settings. I would appreciate a detailed explanation of what could be causing this issue.
1
1
906
Nov ’23
Mac app crashing in CF_IS_OBJC function on macOS Sonoma
I have an Electron app on macOS Sonoma (Intel arch). It has a native addon (app.node) using node-addon-api. Recently it crashed, with the stack trace (given below). What is the CF_IS_OBJC function inside the CFDataGetBytePtr function, and why did it crash there? [NSEvent addGlobalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:^(NSEvent *event) { // code using CFDataGetBytePtr function }]; [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:^NSEvent *_Nullable(NSEvent *event) { // code using CFDataGetBytePtr function return event; }]; I have key events monitors attached using addGlobalMonitorForEventsMatchingMask and addLocalMonitorForEventsMatchingMask in my native code and they use the CFDataGetBytePtr function there. So I think the issue happened in the key event monitor handler when calling the CFDataGetBytePtr function because my native addon app.node is also present in the trace. Also from the third and fourth entry in the stack trace, it seems like it happened while the app was updating. OS Version: macOS 14.4 (23E214) Report Version: 104 Crashed Thread: 5490 Application Specific Information: Fatal Error: EXC_BAD_ACCESS / KERN_INVALID_ADDRESS / 0x0 Thread 5490 Crashed: 0 CoreFoundation 0x19c970118 CF_IS_OBJC 1 CoreFoundation 0x19c83b280 CFDataGetBytePtr 2 .app.desktop.1inmRz 0x104a5bec0 &lt;unknown&gt; 3 .app.desktop.1inmRz 0x104a57b28 &lt;unknown&gt; 4 app.node 0x104a80a7c [inlined] Napi::details::CallbackData&lt;T&gt;::Wrapper::lambda::operator() (napi-inl.h:117) 5 app.node 0x104a80a7c Napi::details::WrapCallback&lt;T&gt; (napi-inl.h:79) 6 app.node 0x104a80a24 Napi::details::CallbackData&lt;T&gt;::Wrapper (napi-inl.h:112) 7 Electron Framework 0x11472e5e0 v8impl::(anonymous namespace)::FunctionCallbackWrapper::Invoke (js_native_api_v8.cc:441) 8 &lt;unknown&gt; 0x147e105f8 &lt;unknown&gt; 9 &lt;unknown&gt; 0x1401d0814 &lt;unknown&gt; 10 &lt;unknown&gt; 0x1401d0a9c &lt;unknown&gt; 11 &lt;unknown&gt; 0x147f19368 &lt;unknown&gt; 12 &lt;unknown&gt; 0x147e0aab0 &lt;unknown&gt; 13 &lt;unknown&gt; 0x1401d0e00 &lt;unknown&gt; 14 &lt;unknown&gt; 0x1401d1ac0 &lt;unknown&gt; 15 &lt;unknown&gt; 0x147f19368 &lt;unknown&gt; 16 &lt;unknown&gt; 0x147e0aab0 &lt;unknown&gt; 17 &lt;unknown&gt; 0x1401d1494 &lt;unknown&gt; 18 &lt;unknown&gt; 0x1401d20dc &lt;unknown&gt; 19 &lt;unknown&gt; 0x147e4c1b4 &lt;unknown&gt; 20 &lt;unknown&gt; 0x147f1b5f8 &lt;unknown&gt; 21 &lt;unknown&gt; 0x147e3b754 &lt;unknown&gt; 22 &lt;unknown&gt; 0x147e0b618 &lt;unknown&gt; 23 Electron Framework 0x10ee0c49c v8::internal::(anonymous namespace)::Invoke (simulator.h:178) 24 Electron Framework 0x10ee0d08c v8::internal::(anonymous namespace)::InvokeWithTryCatch (execution.cc:475) 25 Electron Framework 0x10ee0d1e0 v8::internal::Execution::TryRunMicrotasks (execution.cc:576) 26 Electron Framework 0x10ee37364 v8::internal::MicrotaskQueue::PerformCheckpoint (microtask-queue.cc:176) 27 Electron Framework 0x1146cce9c node::InternalCallbackScope::Close (callback.cc:137) 28 Electron Framework 0x1146ccb64 node::InternalCallbackScope::~InternalCallbackScope (callback.cc:92) 29 Electron Framework 0x1147112b4 node::Environment::RunTimers (env.cc:1376) 30 Electron Framework 0x10daf9980 uv__run_timers (timer.c:178) 31 Electron Framework 0x10dafcb3c uv_run (core.c:465) 32 Electron Framework 0x10dc944d4 electron::NodeBindings::UvRunOnce (node_bindings.cc:891) 33 Electron Framework 0x110e2016c base::TaskAnnotator::RunTaskImpl (callback.h:156) 34 Electron Framework 0x110e3cea4 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork (task_annotator.h:89) 35 Electron Framework 0x110e8851c base::MessagePumpCFRunLoopBase::RunWorkSource (message_pump_apple.mm:444) 36 Electron Framework 0x10da7ad7c base::apple::CallWithEHFrame 37 Electron Framework 0x110e876a4 base::MessagePumpCFRunLoopBase::RunWorkSource (message_pump_apple.mm:415) 38 CoreFoundation 0x19c89deac __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ 39 CoreFoundation 0x19c89de40 __CFRunLoopDoSource0 40 CoreFoundation 0x19c89dbb0 __CFRunLoopDoSources0 41 CoreFoundation 0x19c89c79c __CFRunLoopRun 42 CoreFoundation 0x19c89be08 CFRunLoopRunSpecific 43 HIToolbox 0x1a7036ffc RunCurrentEventLoopInMode 44 HIToolbox 0x1a7036e38 ReceiveNextEventCommon 45 HIToolbox 0x1a7036b90 _BlockUntilNextEventMatchingListInModeWithFilter 46 AppKit 0x1a00f496c _DPSNextEvent 47 AppKit 0x1a08e6de8 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] 48 AppKit 0x1a00e7cb4 -[NSApplication run] 49 Electron Framework 0x110e89244 base::MessagePumpNSApplication::DoRun (message_pump_apple.mm:805) 50 Electron Framework 0x110e87068 base::MessagePumpCFRunLoopBase::Run (message_pump_apple.mm:156) 51 Electron Framework 0x110e3d9a0 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run (thread_controller_with_message_pump_impl.cc:646) 52 Electron Framework 0x110e05a98 base::RunLoop::Run (run_loop.cc:134) 53 Electron Framework 0x10ffcbcd0 content::BrowserMainLoop::RunMainMessageLoop (browser_main_loop.cc:1094) 54 Electron Framework 0x10ffcd744 content::BrowserMainRunnerImpl::Run (browser_main_runner_impl.cc:158) 55 Electron Framework 0x10ffc964c content::BrowserMain (browser_main.cc:34) 56 Electron Framework 0x10de12aa8 content::RunBrowserProcessMain (content_main_runner_impl.cc:712) 57 Electron Framework 0x10de13b1c content::ContentMainRunnerImpl::RunBrowser (content_main_runner_impl.cc:1299) ...
9
1
1.2k
May ’24
Is it possible for an app in the Mac App Store to obtain Accessibility permissions?
I have an app developed using ElectronJS that requires Accessibility permission to monitor mouse and keyboard events through the iohook package. I want to publish it on the Mac App Store, but it seems that: The Mac App Store mandates Sandboxing, and Sandboxing prohibits Accessibility permission. As a result, it seems that an app on the Mac App Store cannot obtain Accessibility permission. Can someone confirm if this is accurate or if there's a workaround?
4
1
756
May ’24
EXC_BAD_ACCESS in AXSerializeCFType
I have an Electron app on macOS Sonoma (arm64 arch). It has a native addon (app.node) using node-addon-api. Recently it crashed, with the stack trace (given below). What is the AXSerializeCFType function inside the AXUIElementCopyAttributeValue function, and why did it crash there? AXUIElementRef systemWideElement = AXUIElementCreateSystemWide(); AXUIElementRef focusedApp = NULL; AXError error = AXUIElementCopyAttributeValue(systemWideElement, kAXFocusedApplicationAttribute, (CFTypeRef *)&focusedApp); The crash appears to be occurring in the last line of the code, where I am retrieving the focused app AXUIElementRef using AXUIElementCopyAttributeValue. I have already attempted to manually set systemWideElement to NULL, but AXUIElementCopyAttributeValue is not crashing; it is just returning an error kAXErrorIllegalArgument. OS Version: macOS 14.5 (23F79) Report Version: 104 Crashed Thread: 344454 Application Specific Information: Fatal Error: EXC_BAD_ACCESS / KERN_INVALID_ADDRESS / 0x102674000 Thread 344454 Crashed: 0 HIServices 0x18cb5d970 AXSerializeCFType 1 HIServices 0x18cb7ca24 serializeWrapper 2 HIServices 0x18cb7cd40 _AXXMIGCopyAttributeValue 3 HIServices 0x18cb74884 _AXUIElementCopyAttributeValue 4 HIServices 0x18cb74a04 AXUIElementCopyAttributeValue 5 HIServices 0x18cb747fc _AXUIElementCopyAttributeValue 6 HIServices 0x18cb74a04 AXUIElementCopyAttributeValue 7 app.node 0x1027a56f4 getFocusedApplication
2
1
468
Jul ’24