Post not yet marked as solved
Hi guys, I am working with NASM version 2.15.05 and ld64-711 BUILD 21:57:11 on a MacOS Monterey.
I wrote a simple 'Hello World' program in assembly and I receive a segmentation fault I cannot really understand. Would you be so kind to help me?
The code is:
global _main
; in the .text section, we define the program
section .text
_main:
mov rax, 0x2000004
mov rdi, 1
mov rsi, helloMessage
mov rdx, helloMessage.size
syscall
mov rax, 0x2000004
xor rdi, rdi
syscall
section .data
helloMessage: db "Hello, World!", 10
.size equ $ - helloMessage
I compile it as follows:
gbiondo@******* ASM % nasm -f macho64 hello.asm
and I link it like this:
gbiondo@******* ASM % ld hello.o -o hello1 -lc -L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
When I run the executable, I get:
gbiondo@******* ASM % ./hello1
Hello, World!
zsh: segmentation fault ./hello1
Coming from the Linux ASM, I had these problems when I forgot the syscall to exit (in this case, the second block, starting with mov rax, 0x2000004) and ending with the syscall instruction, but here? What happens?
Thanks.
Post not yet marked as solved
Hi all.I have a problem with the sandbox. I would like to run a simple shell command on a file I select with an "open" dialog, and I receive the usual "xcrun: error: cannot be used within an App Sandbox".Basically my code does this:if (targetFilePath != ""){
let path = "/usr/bin/strings"
let arguments = [targetFilePath]
let task = Process()
task.arguments = arguments
task.executableURL = URL(fileURLWithPath: path)
let outputPipe = Pipe()
let errorPipe = Pipe()
task.standardOutput = outputPipe
task.standardError = errorPipe
do {
try task.run()
let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
let errorData = errorPipe.fileHandleForReading.readDataToEndOfFile()
let output = String(decoding: outputData, as: UTF8.self)
let error = String(decoding: errorData, as: UTF8.self)
let outputString = "\(path) \(targetFilePath)\nSTDOUT: \(output)\n\nSTDERR: \(error)"
outputField.string = outputString
} catch {
outputField.string="Error somewhere"
}
} else {
outputField.string = "Choose a file!"
}outputField being a normal text field, and targetFilePath is a global variable of type String. The entitlements I have chosen are as follows:<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.debugger</key>
<true/>
<key>com.apple.security.cs.disable-executable-page-protection</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.files.downloads.read-only</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.temporary-exception.files.absolute-path.read-only</key>
<true/>
</dict>Did I miss something? I understood that choosing a file from the Dialog would give my app the permissions to access it.What am I doing wrong?Thanks