nasm

How to link C language libraries?

喜欢而已 提交于 2021-02-05 08:09:10
问题 I am interested in executing a function which is written in C language:- //filename "CLang.c" #include<stdio.h> void fun() { printf("Hello World"); } I want to call this fun() through assembly language which i have written:- (NASM 64bit) ; filename "MyASM.asm" section .data section .bss section .text global _start _start: call fun mov rax,60 ; exit mov rdi,1 syscall I have created object file by using these commands nasm -f elf64 MyAsm.asm and gcc -c CLang.c . When I merge these two file with

How to link C language libraries?

微笑、不失礼 提交于 2021-02-05 08:05:58
问题 I am interested in executing a function which is written in C language:- //filename "CLang.c" #include<stdio.h> void fun() { printf("Hello World"); } I want to call this fun() through assembly language which i have written:- (NASM 64bit) ; filename "MyASM.asm" section .data section .bss section .text global _start _start: call fun mov rax,60 ; exit mov rdi,1 syscall I have created object file by using these commands nasm -f elf64 MyAsm.asm and gcc -c CLang.c . When I merge these two file with

Why syscall doesn't work?

若如初见. 提交于 2021-02-05 07:11:07
问题 I'm on MAC OSX and I'm trying to call through assembly the execve syscall.. His opcode is 59 . In linux I have to set opcode into eax, then parameters into the others registers, but here I have to put the opcode into eax and push parameters into the stack from right to left. So I need execve("/bin/sh",NULL,NULL), I found somewhere that with assembly null=0, so I put null into 2nd and 3rd parameters. global start section .text start: jmp string main: ; 59 opcode ; int execve(char *fname, char

NASM should I pop function argument after calling a function?

女生的网名这么多〃 提交于 2021-02-05 06:51:29
问题 Let's say I have a nasm function like this: inc: mov rax,[rsp + 8] add [rax],BYTE 1 ret And I am calling this function like this: push some_var call inc I want to pass an argument to the function through the stack, so I push some_var and then call my function. In the function my item is second on the stack so I take it like: mov rax,[rsp+8] My question is: after calling function should I somehow pop my argument from the stack? If so, can I somehow delete it from the stack, I mean pop it, but

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

NASM Assembly - what is the “, 0” after this variable for?

大兔子大兔子 提交于 2021-02-04 07:25:10
问题 Just before I was following a guide to use the MessageBoxA function in assembly, and when creating variables, they used a ", 0" after the variable contents. What is this for? The code looks like this: paramText db "this is text", 0 回答1: db is "define byte" and this code will produce these bytes (in hexadecimal formatting): 74 68 69 73 20 69 73 20 74 65 78 74 00 The "string" in quotes is split into ASCII character codes (UTF8 in NASM is possible too I believe, so then one character may produce

NASM Assembly - what is the “, 0” after this variable for?

梦想与她 提交于 2021-02-04 07:22:05
问题 Just before I was following a guide to use the MessageBoxA function in assembly, and when creating variables, they used a ", 0" after the variable contents. What is this for? The code looks like this: paramText db "this is text", 0 回答1: db is "define byte" and this code will produce these bytes (in hexadecimal formatting): 74 68 69 73 20 69 73 20 74 65 78 74 00 The "string" in quotes is split into ASCII character codes (UTF8 in NASM is possible too I believe, so then one character may produce

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

How i can access a variable data using a variable value in adress like [ var_+[second_byte] ]?

社会主义新天地 提交于 2021-01-29 11:00:55
问题 I got this code: BITS 16 data: bytemap: db 0x0, 0x1, 0x4; pixel_x: db 2; to return the 0x4 value main: ; code... mov al, [bytemap+[pixel_x]]; i need that byte in al register ; more code... jmp main; but nasm returns "expression syntax error", i tryed using mov bl, [pixel_x]; mov al, [bytemap+bl] , but don't work, how the right way to do it? ( if it exists )... 回答1: You need to use pointer-width registers in addressing modes . x86 doesn't have memory-indirect addressing modes, only register