Post

Replies

Boosts

Views

Activity

Create a dmg file from a sandboxed application
Hello, I am trying to create a dmg file by launching hdiutil through my swift program. This swift program is sandboxed. Here is what i've done: let hdd_file:String = NSHomeDirectory() + "hdd.dmg.sparseimage" let process = Process() process.launchPath = "/usr/bin/hdiutil" process.arguments = ["create", "-size", "30g", "-fs", "'APFS'", "-volname", "myvolume", "-type", "SPARSE", hdd_file] let pipe = Pipe() process.standardOutput = pipe process.launch() let data = try pipe.fileHandleForReading.readToEnd() print(data) I get this error: hdiutil: create failed - Device not configured I don't understand why i get this error because the dmg file is created in application's sandbox home directory. Or maybe hdiutil is forbidden but i am just creating a dmg file. I am not trying to mount a device. Do you have any idea of how i can create a dmg file from my sandboxed application ? Thanks
1
0
648
Nov ’23
Getting IP address of VZVirtioNetworkDeviceConfiguration
Hello, I am setting up a Linux virtual machine with Virtualization framework. It works fine. Here is how i am creating a network interface: let network_device = VZVirtioNetworkDeviceConfiguration() network_device.attachment = VZNATNetworkDeviceAttachment() vm_config.networkDevices = [network_device] As you can see, this is a NAT network. I would like to know the IP address assigned to this interface. macOS emulates a DHCP server and i would like to know the IP in my Xcode program. How can i do that ? Thanks
3
0
862
Nov ’23
Which application is taken in consideration with TCC
Hello, Let's imagine an application (Application A) which launch another application (Application B). These applications are bundle apps. What happens if Application B tries to read a file in current user's Documents folder ? TCC will check if the application is allowed to access to Documents folder. But will it check this right for application A or application B (or both ?) I have tried to run an application from Terminal. My terminal is authorized to access to Documents folder. And i am surprised because TCC did not asked me to allow the application itself. It seems TCC is looking for parent process rights. Can you confirm ? Thanks
1
0
479
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
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, &regs); ptrace(PTRACE_SETREGS, child_pid, NULL, &regs); kill(child_pid, SIGCONT); So my question is: How does lldb managed to change ARM64 registers of a remote process ? Thanks
2
0
1k
Nov ’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
1.7k
Nov ’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
445
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
947
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
826
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
463
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
972
Oct ’23