Post

Replies

Boosts

Views

Activity

How virtualization framework works internally
Hello, I am trying to understand how macOS virtualization framework and Virtualization products work on M1 chips. I have tried Parallels Desktop. There are no third party kernel extensions (kext) installed with this product. When i plug an USB device on my mac, i get a popup asking me if i want to plug this device to my host mac or to the current Parallels virtual machine. How can this be possible without kext ? Device management is handled at kernel level... and there are no virtualization framework API for that... I have create a Linux virtual machine with Virtualization framework (similar to GNULinuxVirtualMachineSampleApp project): It works but I don't understand why i can't run Windows Virtual machines. Parallels Desktop seems to work with Virtualization framework too and this product can run ARM Windows Virtual Machine. How can they do that ? Is there a way to simulate key sending with Virtualization framework ? I have create a 64Gb disk (VZDiskImageStorageDeviceAttachment). I have a 64Gb file on my host mac, but i am using only 10Gb on the virtual machine at this moment. Is there a way to optimize the disk image file size ? VZVirtualMachine provides a "pause" method. I don't understand where the virtual machine state (RAM memory, ...) is saved on the host. Thanks a lot
2
0
2.8k
Oct ’23
Simulate sending key to an NSView on a macOS application
Hello, I am trying to simulate a keystroke inside a macOS application. Here is what i've done: let src = CGEventSource(stateID: CGEventSourceStateID.hidSystemState) let cmd_down = CGEvent(keyboardEventSource: src, virtualKey: 0x38, keyDown: true) let cmd_up = CGEvent(keyboardEventSource: src, virtualKey: 0x38, keyDown: false) cmd_down?.post(tap: .cghidEventTap) cmd_up?.post(tap: .cghidEventTap) macOS is asking me to allow my application on TCC accessibility. This is a global privilege and needs admin rights. And i want to avoid that. Is there an alternative to simulate a key stroke inside my application ? Thanks
2
0
874
Oct ’23
Mount a dmg programmatically
Hello, I have an encrypted dmg file containing a secret file. When a user want's to see the secret, he must mount the dmg and provide password. When the dmg is mounted, every user connected to the computer can see the secret file ! And i don't want this. Is there a way to open a dmg file with swift language, without mounting it ? Thanks
1
0
784
Oct ’23
TCC Databases
Hello, There is something i do not understand about TCC: I have allowed Terminal app to Full Disk Access. I was able to open my current user's TCC.db file with sqlite3 from terminal. I was able to delete entries in access table with sqlite3. I had no errors, but these changes haven't been applied. My question is why was I able to modify TCC.db file ? Is there a specific thing to do to flush privileges ? I have a second question: When an application fires an NSOPenDialog on a cocoa application, the selected file access rule bypasses TCC. This is normal because this is an intent from user. But this file access seems to be stored somewhere because if i reboot computer, my cocoa application can read this file again, without NSOpenDialog opening. I have tried to look in current user's TCC.db file but i did not found anything. My question is: where is this information stored ? Thanks
2
0
1.4k
Oct ’23
SwiftUI error when using NumberFormatter
Hello, I do not understand something in my code bellow: @Observable class Dog: Identifiable { var name = "Test" var age = 3 } struct ContentView: View { @State private var model = Dog() let nf = NumberFormatter() var body: some View { Form { Section { TextField("Name", text: $model.name) } Section { TextField("Age", text: $model.age, formatter: nf) } } } } I have a compilation error: "Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure" If i remove the age TextField, everything works fine. Do you have any idea ? Maybe i have made something wrong with text formatter ? Thanks
1
0
549
Oct ’23
SwiftUI Closures return value
Hello, Look at this SwiftUI view: struct ContentView: View { var body: some View { Text("Hello !") } } The Text("Hello") line is a closure. Am I wrong ? There is an implicit return. I can write this: struct ContentView: View { var body: some View { return Text("Hello !") } } I can put multiple lines like this: struct ContentView: View { var body: some View { Text("Hello !") Text("Hello2 !") } } I don't understand how works internally the implicit return in this case because we have 2 components. Also, can you explain me why i can't put a basic swift line code like this: struct ContentView: View { var body: some View { Text("Hello !") print("Hello") Text("Hello2 !") } } Thanks
2
0
1k
Oct ’23
Bypass ASLR for debugging purposes
Hello, Look at this basic C program: #include <stdio.h> int main() { printf("%llx\n", main); return 0; } The displayed address change on each run. This is due to ASLR. Is there a way to launch a program by forcing the main module's base address I would like to do something like that in my terminal: $ BASE_ADDRESS=0x10000 ./a.out How can i do that on mac os ? Is it possible to force base address loading for shared libraries too ? Thanks
3
0
1.2k
Oct ’23
swift autorelease value-add
Hello, I am wondering the value-add of autorelease in swift. Look at this code: for i in (0...10) { autorelease { let obj1=MyClass() ... } } obj1 will be released at the end of autorelease block. But i can also work with a function like this (or a closure): func test() { let obj1=MyClass() ... } for i in (0...10) { test() } obj1 will be released at the end of the test function. Do you agree we have the same result in memory in both cases ? If so, when should we work with autorelease ? Thanks
1
0
544
Oct ’23
Gatekeeper and code signing
Hello, I have made a basic c program and i have compiled it with gcc. This program has not been signed (i didn't run codesign). When i am trying to run this program from terminal, i don't get any Gatekeeper popup. My first question is... why ? I have create a SwiftUI project with Xcode (Xcode 15). I have set signing settings to "Sign to run locally" (by the way, can you tell me how i can disable signing in Xcode ?) I have opened terminal and i have changed current directory to ~/Library/Developer/Xcode/DerivatedData/..../Products/Debug/MyApp.app/Contents/MacOS folder. Now i get a gatekeeper confirmation popup if run "./Myapp" from terminal. My second question is... Why ? Does that mean Gatekeeper only checks signed binaries ? Thanks
3
0
2.1k
Nov ’23
Debug a process by hand from a c program on an Apple Silicon CPU
Hello, My purpose is to understand how macOS works. Here is what i've done: I have wrote a c program on a M1 CPU with this lines: printf("Before breakpoint\n"); asm volatile("brk #0"); printf("After breakpoint\n"); When i run this program with lldb, a breakpoint is hit on the second line. So i suppose lldb is writing a "brk #0" instruction when we put a breakpoint manually. I can't continue to next line with lldb "c" command. PC stays on the brk instruction. I need to manually set PC to next instruction in lldb. Now, what i want to do is to create my own debugger. (I want to understand how lldb works). I have managed to ptrace the target program and i was able to catch an event with waitpid when "brk #0" is hit. But i don't know how i can increase PC value and continue execution because i can't do this on Silicon CPU: ptrace(PTRACE_GETREGS, child_pid, NULL, &amp;regs); ptrace(PTRACE_SETREGS, child_pid, NULL, &amp;regs); kill(child_pid, SIGCONT); So my question is: How does lldb managed to change ARM64 registers of a remote process ? Thanks
2
0
1.2k
Nov ’23
Load a library with LC_LOAD_DYLIB instead of LC_LOAD_WEAK_DYLIB
Hello, I have create a dynamic library with gcc: gcc -dynamiclib liblib1.c -o liblib1.dylib I have create a binary which needs this dynamic library: gcc -L./ -llib1 test.c -o test I have looked at mach-o commands in test binary. I have seen the library is loaded with LC_LOAD_WEAK_DYLIB. How can i load the library with LC_LOAD_DYLIB instead of LC_LOAD_WEAK_DYLIB ? And i have a second question: Is it possible to compile the binary with a static linking of the library ? I have tried with -static option, like i do on Linux but it does not work on macOS and i don't understand why... Thanks
1
0
1.3k
Nov ’23