x86-64

Instructions after a ;\ comment don't execute? What's special about backslash in comments in NASM? [duplicate]

半腔热情 提交于 2019-12-11 05:28:58
问题 This question already has an answer here : NASM/Yasm drops CALL after comment ending with backslash (1 answer) Closed last month . I was programming an ASCII to decimal converter in ASM and after an edit, it just didn't add to rax , this caused an infinite loop. GDB says that rax wasn't accepting ANY numbers, even when moved from memory and other registers. I have tried moving things into rax with mov and I have also tried the inc operation. Here is the asciiToDec function, well commented, I

Converting 32-bit Fibonacci nasm code to 64-bit

帅比萌擦擦* 提交于 2019-12-11 05:13:41
问题 I'm a newbie in writing assembly code and I need some help. My task is to write a program in NASM (on Linux), which computes n-th Fibonacci number, where n is read from STDIN with read syscall and converted to int/long with C atoi/atol. The calculated number will be written to STDOUT (I can use C printf). I managed to write the working 32-bit code and I'm stuck at converting it to 64-bit (using 64-bit registers, 64-bit long int). I tried to do it naively (changing eax -> rax, esp -> rsp and

Dividing with a negative number gives me an overflow in NASM

ⅰ亾dé卋堺 提交于 2019-12-11 05:00:03
问题 I'm teaching myself some assembly programming with x86-64 Mac OS. I'm trying to figure out why when it comes to dividing a positive integer with a negative integer gives me an overflow. For example, 5/-2 must return -2 . However, in my case, it returns a 2147483371 when I do -554/2 instead of -277 ... This is what I have in my assembly file: ; compiling using: nasm -f macho64 -o divide.o divide.s [bits 64] global _divide section .text ; int divide(int dividend, int divisor) _divide: xor rdx,

Function called in a file without a prototype produce different results on ARM and x86-64

北慕城南 提交于 2019-12-11 04:48:14
问题 We have 3 files: main.c , lib.h and lib.c : main.c: #include <stdio.h> #include <stdlib.h> /* #include "lib.h" */ int main(void) { printf("sizeof unsigned long long: %zu\n", sizeof(unsigned long long)); printf("sizeof int: %zu\n", sizeof(int)); unsigned long long slot = 0; int pon_off = 1; lib_fn(slot, pon_off); return EXIT_SUCCESS; } lib.h: void lib_fn(unsigned slot, int pon_off); lib.c: #include <stdio.h> #include <stdlib.h> void lib_fn(unsigned slot, int pon_off) { printf("slot: %d\n",

How to run program using angr after loading with the elfcore backend?

孤街浪徒 提交于 2019-12-11 04:47:00
问题 I am attempting to write a python script using the angr binary analysis library (http://angr.io/). I have written code that successfully loads a core dump of the process I want to play with by using the ElfCore back end (http://angr.io/api-doc/cle.html#cle.backends.elf.elfcore.ELFCore) passed to the project constructor, doing something like the following: ap = angr.Project("corefile", main_opts={'backend': 'elfcore'}) What I am wondering is, how do I now "run" the program forward from the

How C structures get passed to function in assembly?

左心房为你撑大大i 提交于 2019-12-11 03:05:03
问题 1)How C structures get passed to function in assembly. I mean pass by value, not pass by reference. 2)By the way, how callees return structure to its callers? I'm so sorry for the poor expression since I'm not a native English speaker. I wrote a simple program to testify how C structures get passed to function. But the result was quite surpirsed. Some value was passed by register, but some value was passed by pushing them into stack. Here is the code. source code #include <stdio.h> typedef

Linux AMD64 call C library functions from copied assembly

烂漫一生 提交于 2019-12-11 02:42:12
问题 How do I call from an memcpy'ed assembly function a C library functions? I'm making an example test code how one can allocate and change memory protection on Linux, AMD64 to run arbitrarily generated code from C. What I done is that I compile an small GAS assembly function along side my main program (written in C) and then copy the assembly binary blob onto piece executable memory in run-time and jump into it. This part works OK. But I if call C library puts() from the copied assembly blob it

Finding mapped memory from inside a process

橙三吉。 提交于 2019-12-11 02:33:03
问题 Setup: Ubuntu 18x64 x86_64 application Arbitrary code execution from inside the application I'm trying to write code which should be able to find structures in memory even with ASLR enabled. Sadly, I couldn't find any static references to those regions, so I'm guessing I have to use the bruteforce way and scan the process memory. What I tried to do was to scan the whole address space of the application, but that doesn't work as some memory areas are not allocated and therefore yield SIGSEGV

How to compare a char in a string with another char in NASM x86_64 Linux Assembly

假装没事ソ 提交于 2019-12-11 02:22:12
问题 I'm actually trying to understand the basic concepts of NASM Assembly in Intel x64 syntax but facing an issue while trying to make a strchr equivalent... I've been sailing the web to get the maximum information but I can't understand how to compare the current char of a string (like str[i]) with a simple char. Here is the test main : #include <stdio.h> extern char* my_strchr(char*, char); int main(void) { char* str; str = my_strchr("foobar", 'b'); printf("%s\n", str); return 0; } And here is

Using scanf with x86-64 GAS assembly

旧巷老猫 提交于 2019-12-11 01:35:36
问题 I have been having loads of issues trying to get a call the the system function scanf to work in my x86 assembly program. Currently I have got it to read from standard in however, it only will read chars without a segfault (I have no idea why, the specifying string is %d). The examples I've seen of scanf in x86 online use quarky or are written with NASM syntax, thus I have tried to adapt them for my program. f: .string "%d" _main: movq $0, %rax #Clean rax movq $f, %rdi #Load string format