x86-64

Instructions to copy the low byte from an int to a char: Simpler to just do a byte load?

≯℡__Kan透↙ 提交于 2021-02-05 06:39:28
问题 I was reading a text book and it has an exercise that write x86-64 assembly code based on C code //Assume that the values of sp and dp are stored in registers %rdi and %rsi int *sp; char *dp; *dp = (char) *sp; and the answer is: //first approach movl (%rdi), %eax //Read 4 bytes movb %al, (%rsi) //Store low-order byte I can understand it but just wondering can't we do sth simple in the first place as: //second approach movb (%rdi), %al //Read one bytes only rather than read all four bytes movb

Pointer to string in stand-alone binary code without .data section

别来无恙 提交于 2021-02-04 19:43:06
问题 I'm trying to write kind of exploit and have a problem with making my asm code run anywhere on the stack. Here's it: BITS 64 global _start _start: mov rax, 59 jmp short file c1: pop rdi jmp short argv c2: pop rsi mov rdx, 0 syscall ret file: call c1 db '/bin/sh',0 argv: call c2 dq arg, 0 <- problem arg: db 'sh',0 This code won't work anywhere on the stack due to selected line because this code can be executed anywhere on the stack so nasm can't correctly compute arg's address. (This is a

Hello world in NASM with LINK.EXE and WinAPI

允我心安 提交于 2021-02-04 08:05:32
问题 I'm trying to get a simple Hello world program in NASM to run. I want to print to the console without using C-Libraries, interfacing directly with WinAPI. I am using the Visual Studio provided LINK.EXE for linking. Here's my code so far: section .data message: db 'Hello world!',10 ; 'Hello world!' plus a linefeed character messageLen: db $-message ; Length of the 'Hello world!' string global _start extern GetStdHandle extern WriteConsoleW extern ExitProcess section .text _start: ; DWORD bytes

What are the 128-bit to 512-bit registers used for?

我们两清 提交于 2021-02-04 07:14:02
问题 After looking at a table of registers in the x86/x64 architecture, I noticed that there's a whole section of 128, 256, and 512-bit registers that I've never seen them being used in assembly, or decompiled C/C++ code: XMM(0-15) for 128, YMM(0-15) for 256, ZMM(0-31) 512. After doing a bit of digging what I've gathered is that you have to use 2 64 bit operations in order to perform math on a 128 bit number, instead of using generic add , sub , mul , div operations. If this is the case, then what

What are the 128-bit to 512-bit registers used for?

二次信任 提交于 2021-02-04 07:13:24
问题 After looking at a table of registers in the x86/x64 architecture, I noticed that there's a whole section of 128, 256, and 512-bit registers that I've never seen them being used in assembly, or decompiled C/C++ code: XMM(0-15) for 128, YMM(0-15) for 256, ZMM(0-31) 512. After doing a bit of digging what I've gathered is that you have to use 2 64 bit operations in order to perform math on a 128 bit number, instead of using generic add , sub , mul , div operations. If this is the case, then what

What are the 128-bit to 512-bit registers used for?

泪湿孤枕 提交于 2021-02-04 07:13:15
问题 After looking at a table of registers in the x86/x64 architecture, I noticed that there's a whole section of 128, 256, and 512-bit registers that I've never seen them being used in assembly, or decompiled C/C++ code: XMM(0-15) for 128, YMM(0-15) for 256, ZMM(0-31) 512. After doing a bit of digging what I've gathered is that you have to use 2 64 bit operations in order to perform math on a 128 bit number, instead of using generic add , sub , mul , div operations. If this is the case, then what

What are the 128-bit to 512-bit registers used for?

大城市里の小女人 提交于 2021-02-04 07:12:47
问题 After looking at a table of registers in the x86/x64 architecture, I noticed that there's a whole section of 128, 256, and 512-bit registers that I've never seen them being used in assembly, or decompiled C/C++ code: XMM(0-15) for 128, YMM(0-15) for 256, ZMM(0-31) 512. After doing a bit of digging what I've gathered is that you have to use 2 64 bit operations in order to perform math on a 128 bit number, instead of using generic add , sub , mul , div operations. If this is the case, then what

What are the 128-bit to 512-bit registers used for?

不羁的心 提交于 2021-02-04 07:12:39
问题 After looking at a table of registers in the x86/x64 architecture, I noticed that there's a whole section of 128, 256, and 512-bit registers that I've never seen them being used in assembly, or decompiled C/C++ code: XMM(0-15) for 128, YMM(0-15) for 256, ZMM(0-31) 512. After doing a bit of digging what I've gathered is that you have to use 2 64 bit operations in order to perform math on a 128 bit number, instead of using generic add , sub , mul , div operations. If this is the case, then what

Reverse byte order in XMM or YMM register?

你说的曾经没有我的故事 提交于 2021-02-04 06:30:06
问题 Let's say I want to reverse the byte order of a very large byte array. I can do this the slow way using the main registers but I would like to speed it up using the XMM or YMM registers. Is there a way to reverse the byte order in an XMM or YMM register? 回答1: Yes, use SSSE3 _mm_shuffle_epi8 or AVX2 _mm256_shuffle_epi8 to shuffle bytes within 16-byte AVX2 "lanes". Depending on the shuffle control vector, you can swap pairs of bytes, reverse 4-byte units, or reverse 8-byte units. Or reverse all

Calling sprintf in x64 assembly

老子叫甜甜 提交于 2021-01-29 19:18:22
问题 It seems that I can't call sprintf() correctly in assembly. When I try to dprintf() my buffer that should now be formatted, all I get is: (null) and a segmentation fault. When running lldb with my program, strlen() is the reason of the fail as it can't find a \0 in my buffer. Here's my code: mov rdi, buff mov rsi, 0 mov rdx, 17 call memset lea rsi, [rel n_head] mov rdx, rax call sprintf mov rdx, rdi lea rsi, [rel fmt] mov rdi, 1 call dprintf ... section .data n_head: db "Low battery: %d%%", 0