Post

Replies

Boosts

Views

Activity

How to make SimpleFirewall work as expected?
I am trying to use the example of the network extension. Now I have completed the necessary profile configuration and other content. After I try to run, a corresponding small window will pop up, but no matter how long after I click start, no matter what connection I send, it does not respond and display. I would like to know how to open a connection on the port being filtered? And then to make the SimpleFirewall work as expected?
1
0
531
Jul ’23
Two problems in the program compilation of the new version of xcode (the target code is the content filter of the network extension)
I'm trying to debug the official network extension sample code simplefirewall. Although it has been able to run normally and pops up user pop-up windows for the specified filter conditions, there are still two warnings and errors: [Window] Warning: Window NSWindow 0x1007315f0 ordered front from a non-active application and may order beneath the active application's windows. [default] CGSWindowShmemCreateWithPort failed on port 0 For the first warning, I followed the method given in https://developer.apple.com/forums/thread/729496 and added windo.makeKey() and window.orderFrontRegardless(), but this warning didn't go away. As for the second default, I haven't been able to find the corresponding root cause and solution of the problem. I would like to ask, can anyone give me some advice? Xcode:Version 14.3.1 (14E300c)
1
1
919
Aug ’23
SimpleFirewall not working after stop and restart
Although I was able to get simplefirewall to work, I still have a problem. When I start it for the first time (start button), every target traffic will be captured normally, but when I pause (stop button) and start again (start button), the same target traffic will not be captured. If I want it to work again, I need to stop it from xcode start the program again. What is the reason? Any suggestions?
7
1
907
Aug ’23
Unable to get local ip and port correctly
Why is the local ip and port obtained through localEndpoint 0.0.0.0:0 when handlenewflow (outbound flow), the remote ip and port are normal, and the local/remote ip and port for the inbound flow are normal. override func handleNewFlow(_ flow: NEFilterFlow) -> NEFilterNewFlowVerdict { guard let socketFlow = flow as? NEFilterSocketFlow, let remoteEndpoint = socketFlow.remoteEndpoint as? NWHostEndpoint, let localEndpoint = socketFlow.localEndpoint as? NWHostEndpoint else { return .allow() } os_log("Got a new flow with local endpoint %@, remote endpoint %@", localEndpoint, remoteEndpoint) let flowInfo = [ FlowInfoKey.localPort.rawValue: localEndpoint.port, FlowInfoKey.remoteAddress.rawValue: remoteEndpoint.hostname ] let flowInfo2 = [ FlowInfoKey2.localAddress.rawValue: localEndpoint.hostname, FlowInfoKey2.remotePort.rawValue: remoteEndpoint.port ] …………………… }
1
0
535
Aug ’23
How to correctly use the developer ID to implement program distribution
Currently, I have implemented a project that includes network extension and system extension entitlements. When I create the profile using the development method, I get exactly the right entitlement matching. For example: create app id (identifier) create a profile, associate with the corresponding app id, generate the profile and download it locally. In xcode, fill in the corresponding app id in Bundle Identifier, such as com.***.test.app, and fill in the corresponding development profile in Provisioning Profile. At this point I was able to achieve a complete and correct program compiling and running. Now, I want to distribute this app by developer id. According to https://developer.apple.com/developer-id/ , I have several questions remain: I followed this method https://developer.apple.com/help/account/create-certificates/create-developer-id-certificates/ to create a distribution certificate and created two new profiles (distribute- developer id), which is associated with the existing bundle ID (com.***.test.app, com.***.test.extension). But when I import the corresponding provisioning profile in xcode, it shows error: Provisioning profile "***" doesn’t match the entitlement file’s value for the com.apple.developer.networking.networkextension entitlement. But isn't the corresponding entitlement information already selected when the app id is set? Why is the profile of the development type feasible, but the profile of the developer id is not feasible? I have made relevant settings according to this method https://developer.apple.com/documentation/xcode/preparing-your-app-for-distribution/, and I don’t seem to need the hardened runtime and sandbox related content, so I don't have any settings. Maybe apple events in hardened runtime is necessary? Submitting software to apple notarization seems to be a more trustworthy behavior for users, but at this stage I just want to simply implement distribution for program testing, so I chose export in archives-distribute app-developer id, and in the follow-up The same error as in question 1 appeared in the profile selection of the profile: Profile doesn't match the entitlements file's value for the com.apple.developer.networking.networkextension entitlement. So, overall: One is how to create the correct developer id profile? My two entitlements files are as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.developer.networking.networkextension</key> <array> <string>content-filter-provider</string> </array> <key>com.apple.developer.system-extension.install</key> <true/> <key>com.apple.security.app-sandbox</key> <false/> <key>com.apple.security.files.user-selected.read-only</key> <true/> </dict> </plist> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.developer.networking.networkextension</key> <array> <string>content-filter-provider</string> </array> <key>com.apple.security.app-sandbox</key> <false/> <key>com.apple.security.application-groups</key> <array> <string>$(TeamIdentifierPrefix)com.example.app-group</string> </array> </dict> </plist> Second, is Apple notarization necessary?
4
0
1.2k
Aug ’23
AXUIElementCopyAttributeValue failed: kAXErrorCannotComplete
I'm trying to write a program where I want to get the text content selected by the mouse by detecting mouse movements. My main code is as follows: #import "AppDelegate.h" #import <Cocoa/Cocoa.h> @interface AppDelegate () @property (strong) IBOutlet NSWindow *window; @property (nonatomic) CFMachPortRef eventTap; @end CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) { if (type == kCGEventLeftMouseDown) { NSLog(@"Mouse down."); } else if (type == kCGEventLeftMouseUp) { NSLog(@"Mouse up."); NSRunningApplication *currentApp = [[NSWorkspace sharedWorkspace] frontmostApplication]; AXUIElementRef appElement = AXUIElementCreateApplication(currentApp.processIdentifier); AXUIElementRef windowElement; AXError error = AXUIElementCopyAttributeValue(appElement, kAXFocusedWindowAttribute, (CFTypeRef *)&windowElement); if (error != kAXErrorSuccess) { NSLog(@"Could not get focused window. Error code: %d", error); return event; } AXValueRef selectedTextValue; error = AXUIElementCopyAttributeValue(windowElement, kAXSelectedTextAttribute, (CFTypeRef *)&selectedTextValue); if (error != kAXErrorSuccess) { NSLog(@"Could not get selected text. Error code: %d", error); return event; } NSString *selectedText = (__bridge_transfer NSString *)selectedTextValue; NSLog(@"Selected text: %@", selectedText); } return event; } @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application self.eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, CGEventMaskBit(kCGEventLeftMouseDown) | CGEventMaskBit(kCGEventLeftMouseUp), myCGEventCallback, NULL); if (self.eventTap) { CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, self.eventTap, 0); CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes); CGEventTapEnable(self.eventTap, true); CFRelease(runLoopSource); // Don't release eventTap here } else { NSLog(@"Failed to create event tap"); } } - (void)applicationWillTerminate:(NSNotification *)aNotification { // Insert code here to tear down your application if (self.eventTap) { CFRelease(self.eventTap); } } - (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app { return YES; } @end I confirmed that I have granted "Accessibility" permissions to my program and the application I am trying to access is xcode or when I try to access the chrome interface I get the same error kAXErrorCannotComplete. So how do I deal with this problem? Or is there any other way to achieve my target function? PS: I solved the above error by set App Sandbox Value (NO) in the entitlements, but I don't know if this is a reasonable solution. And then AXUIElementCopyAttributeValue generated another error kAXErrorFailure. How should I troubleshoot this problem ?
1
0
678
Oct ’23
How to correctly add accessibility permissions to a program
I'm writing a program that requires accessibility permissions, and I use AXIsProcessTrustedWithOptions to confirm and direct the user to the accessibility interface for authorization. According to conventional implementation, after the accessibility interface is opened, the system will automatically add the corresponding program, and the user only needs to turn on the permissions. But now, with accessibility turned on, I don't see my program loading automatically. Next, I tried to add it manually, click + on the accessibility interface, select the program I built and then add it. But when I clicked Add, my program was not successfully added. The accessibility interface still did not see my program being loaded, and the user could not open permissions for it. I think this has nothing to do with whether it is a development version, because I tried other debug programs developed and compiled with xcode and they were able to be added normally. So I want to know, what are the reasons why it cannot be added? Which parts should I check from?
1
0
549
Dec ’23
returned NO from -[NSWindow canBecomeKeyWindow]
There is a tips popup window in my program, I set it to close after 3 seconds, and the makeKeyAndOrderFront function is never called on it. However, the following error will appear during operation: Warning: -[NSWindow makeKeyWindow] called on NSWindow 0x7fb... which returned NO from -[NSWindow canBecomeKeyWindow] I'd like to know if there are any other function calls that would cause the above warning? Or how can I troubleshoot and remove this warning.
1
0
1.1k
Dec ’23
window component input problem in macos program (xcode-objectivec++)
In my program, I overridden the NSTextField as follows: @interface CustomTextField:NSTextField @end @implementation CustomTextField - (BOOL)performKeyEquivalent:(NSEvent *)event { NSUInteger flags = [event modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask; NSString *modifierFlagsString = @""; if ((flags & NSEventModifierFlagControl) != 0) { modifierFlagsString = [modifierFlagsString stringByAppendingString:@"Control+"]; } NSString *key = [[event charactersIgnoringModifiers] uppercaseString]; NSString *hkString = [modifierFlagsString stringByAppendingString:key]; self.stringValue = [NSString stringWithFormat:@"*%@", hkString]; return YES; } In short, my goal is to capture the function key + key event when NSTextField is entered, and then display it in the specified format. But if the key pressed does not contain a shortcut, I want no input. How can I achieve this? Because I tried keydown and other methods but none of them seemed correct.
0
0
295
Jan ’24