x86-64

Calling C function in assembly code (gas)

寵の児 提交于 2019-12-02 10:08:06
问题 I found an example and was editing it for gas. extern printf .global _start .data hello: db "Hello", 0xa, 0 .text _start: mov %rdi, hello mov %rax, 0 call printf mov %rax, 0 ret But it doesn't work. What's wrong? What does this mean: hello: db "Hello", 0xa, 0 I understand what it scope of memory, but I don't understand this string db "Hello", 0xa, 0 And here _start: mov %rdi, hello mov %rax, 0 call printf mov %rax, 0 ret os: linux (debian). intel 64-bit 回答1: It's is the null-byte-terminattor.

There is an assembly code written for Windows API, how to compile it on Linux and run with Wine

倾然丶 夕夏残阳落幕 提交于 2019-12-02 10:07:58
问题 There is an example code in this introduction, like below: ; Sample x64 Assembly Program ; Chris Lomont 2009 www.lomont.org extrn ExitProcess: PROC ; external functions in system libraries extrn MessageBoxA: PROC .data caption db '64-bit hello!', 0 message db 'Hello World!', 0 .code Start PROC sub rsp,28h ; shadow space, aligns stack mov rcx, 0 ; hWnd = HWND_DESKTOP lea rdx, message ; LPCSTR lpText lea r8, caption ; LPCSTR lpCaption mov r9d, 0 ; uType = MB_OK call MessageBoxA ; call

NASM 2 lines of db (initialized data) seemingly not working

拜拜、爱过 提交于 2019-12-02 09:49:37
问题 I have the following x86-64 code, which I can run on OSX Yosemite: global _main extern _exit extern _puts DEFAULT REL section .data putsmsg: db 'Puts message...',0 another: db 0 section .text _main: push rbp mov rbp, rsp ; print a string using PUTS lea rdi, [putsmsg] call _puts ; call EXIT(0) c function mov rdi, 0 call _exit I compile, link, and run as follows (where the source is a.asm): nasm -f macho64 a.asm ; gcc a.o -o a.bin ;./a.bin It does not print the message 'Puts message...',

Question about setg and comparison in Assembly

你说的曾经没有我的故事 提交于 2019-12-02 09:27:23
I'm having problem understanding this exercise. I'll try my best to give my reasoning and I hope you guys can give me an idea what each line of code demonstrates. The Assembly we use is x86 assume the value stored in %rax = x xorq %rax, %rax // value stored in %rax: x ^ x = 0 addq $-1, %rax // value stored in %rax: 0 - 1 = -1 movq %rax, %rbx // value stored in %rbx: -1 or 0xFFFFFFFF shlq $2, %rbx shrq $1, %rbx // left shift by 3 total, so value stored in %rbx: 0x7fffffff8 addq %rbx, %rax // value stored in %rax: 0x7fffffff9 For the last line, my professor says we actually computing (TMax-1)-1,

x86_64 Executing Shellcode fails:

风格不统一 提交于 2019-12-02 09:06:38
I'm using Python 2.7 on 64-bit Linux. I have the following Python script witch should execute a simple Hello World shellcode. import urllib2 import ctypes shellcode = "\xb8\x01\x00\x00\x00\xbf\x01\x00\x00\x00\x48\xbe\xd8\x00\x60\x00\x00\x00\x00\xba\x0e\x00\x00\x00\x0f\x05\xb8\x3c\x00\x00\x00\xbf\x00\x00\x00\x00\x0f\x05" #Create buffer in memory shellcode_buffer = ctypes.create_string_buffer(shellcode, len(shellcode)) #Funktionszeiger shellcode_func = ctypes.cast(shellcode_buffer, ctypes.CFUNCTYPE(ctypes.c_void_p)) #Shellcode execute shellcode_func() If i run python Scriptname.py I get a memory

General structure for executing system commands from x86-64 assembly (NASM)?

三世轮回 提交于 2019-12-02 08:18:28
I am trying to make some basic system calls in assembly (x86-64 in NASM on OSX), but have so far been unsuccessful. The only examples I have seen on the web so far are for reading from stdin or writing to stdout, such as this: global main section .text main: call write write: mov rax, 0x2000004 mov rdi, 1 mov rsi, message mov rdx, length syscall section .data message: db 'Hello, world!', 0xa length: equ $ - message However, when I try to use that same pattern to make another system call, it doesn't work (it's saying Bus error: 10 ): global main section .text main: call mkdir mkdir: mov rax,

Trying to install pyaudio using pip

陌路散爱 提交于 2019-12-02 07:45:06
I try to install pyaudio in pycharm, and I get this error error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2 I used pip install pyaudio command. Copy comment: I downloaded PyAudio‑0.2.11‑cp37‑cp37m‑win_amd64.whl try to install it using this command pip install PyAudio‑0.2.11‑cp37‑cp37m‑win_amd64 but it does not work and get this error ERROR: Could not find a version that satisfies the requirement PyAudio-0.2.11-cp37-cp37m-win_amd64 (from versions: none) ERROR: No matching distribution found for PyAudio-0.2.11-cp37-cp37m-win_amd64

Why parameters stored in registers and not on the stack in x86-64 Assembly?

元气小坏坏 提交于 2019-12-02 07:06:21
问题 In x86-32 assembly, parameters are stored on the stack but in x86-64, parameters stored in registers. What is the reason for this? 回答1: It is (a lot) faster to access CPU registers than to access RAM. Since 64bit CPU have a lot more general purpose registers (has nothing to do with being 64bit, it's just because they are newer/bigger), it makes sense to make use of them. 回答2: Store/reload round trips take instructions and cost ~6 cycles of store-forwarding latency, so modern calling

using printf before and inside a loop x86-64 assembly

孤街醉人 提交于 2019-12-02 06:55:21
I'm having trouble figuring out how to use printf correctly in this function. So the function is called multInts and is supposed to multiply the first element of the first array with the first element of the second array and continue through the whole array. However, the lab instructions specify that I can't call printf in the main function. So, I need to print out the word "Products:\n" and then in each new line after that, print out the product. I don't know how to use printf within the loop, however. The instructor said that we should "call printf in the loop after calculating product" and

Calling C function in assembly code (gas)

社会主义新天地 提交于 2019-12-02 06:12:04
I found an example and was editing it for gas. extern printf .global _start .data hello: db "Hello", 0xa, 0 .text _start: mov %rdi, hello mov %rax, 0 call printf mov %rax, 0 ret But it doesn't work. What's wrong? What does this mean: hello: db "Hello", 0xa, 0 I understand what it scope of memory, but I don't understand this string db "Hello", 0xa, 0 And here _start: mov %rdi, hello mov %rax, 0 call printf mov %rax, 0 ret os: linux (debian). intel 64-bit It's is the null-byte-terminattor . Well-know as C-string.Such byte at end-of-string say where the string ends. For example,you pass the