nasm

changing global variables in NASM assembly

百般思念 提交于 2019-12-25 03:03:16
问题 I've defined these global variables but I cant seem to change their value in the code. I need other C modules to have access to these variables. global base global freep SECTION .data base: dd 0 freep: dd 0 The code below gives this error: :173: error: invalid combination of opcode and operands So my question is how to a mov values into global variables? mov freep, esi 回答1: From the NASM manual: 2.2.2 NASM Requires Square Brackets For Memory References The rule is simply that any access to

Simple “Hello-World”, null-free shellcode for Windows needed

主宰稳场 提交于 2019-12-25 02:34:32
问题 I would like to test a buffer-overflow by writing "Hello World" to console (using Windows XP 32-Bit). The shellcode needs to be null-free in order to be passed by "scanf" into the program I want to overflow. I've found plenty of assembly-tutorials for Linux, however none for Windows. Could someone please step me through this using NASM? Thxxx! 回答1: Assembly opcodes are the same, so the regular tricks to produce null-free shellcodes still apply, but the way to make system calls is different.

Where are the system codes coming from in x86-64 Assembly?

寵の児 提交于 2019-12-25 01:22:01
问题 I am looking through some demos of assembly (using NASM on a Mac, I am new to assembly) and seeing things like this: ; read a byte from stdin mov eax, 3 ; 3 is recognized by the system as meaning "read" mov ebx, 0 ; read from standard input mov ecx, variable ; address to pass to mov edx, 1 ; input length (one byte) int 0x80 ; call the kernel I am beginning to understand that eax , ebx , etc. are "general registers", which is where you store common things. Still have more to learn there but I

Printing a number in assembly NASM using printf

非 Y 不嫁゛ 提交于 2019-12-25 00:39:16
问题 I've been trying to get this to print 12345 for a while now. Can anyone provide a hint as to what I should do? It will print the three lines of text, then on the fourth line prints "age", which I'm guessing is a remnant in the stack from line 2. bits 64 global main extern printf section .text main: ; function setup push rbp mov rbp, rsp sub rsp, 32 ; lea rdi, [rel message] mov al, 0 call printf ;above code correctly prints message ;where the issue lies push rbp mov rbp, rsp ;sub rsp, 32 mov

relocation truncated to fit r_386_8 against .bss'

。_饼干妹妹 提交于 2019-12-24 21:42:27
问题 When i type ld -m elf_i386 -o loop loop.asm, i get the error stated in the title, any idea what causes it? Sorry if the code looks bad, fairly new to assembly. cr equ 13 lf equ 10 section .bss numA resb 1 section .text global _start: mov [numA],byte 0 call loop1 jmp endend loop1: xor cx,cx mov al, $numA cmp cx, 0x0A jle else inc al jmp end else: dec al jmp end end: mov [$numA], al inc cx cmp cx,20 jle loop1 endend: mov dl,$numA mov ah,2 int 21h 回答1: In NASM, $numA is the same as numA . A

Python ctypes how to read a byte from a character array passed to NASM

拟墨画扇 提交于 2019-12-24 20:43:47
问题 UPDATE: I solved this problem with the help of Mark Tolonen's answer below. Here is the solution (but I'm puzzled by one thing): I begin with the encoding string shown in Mark Tolonen's answer below (UTF-8): CA_f1 = (ctypes.c_char_p * len(f1))(*(name.encode() for name in f1)) With optimizations off, I always store rcx into a memory variable on entry. Later in the program when I need to use the pointer in rcx, I read it from memory. That works for a single pointer, but doesn't work for

Multicore in NASM Windows: lpParameter data are wrong on entry

无人久伴 提交于 2019-12-24 18:13:10
问题 I have code in NASM (64 bit) in Windows to run four simultaneous threads (each assigned to a separate core) on a four-core Windows x86-64 machine. The lpParameter is passed in r9 (the data variables for each thread to pass to the function). I am passing a pointer to an 8-element internal array (ThreadInfo) which contains variables to put into registers on entry to the function (variables are stored in registers for optimization purposes). All four threads call the same function. The problem

NASM TO GAS: counterpart of resw in GAS

邮差的信 提交于 2019-12-24 16:58:27
问题 I am tasked to convert my assembly program which uses NASM to GAS. Unfortunately there are lots of mismatched statements. I have converted some of them but I am still having trouble on how to convert this statement min resw 1 回答1: You could try: .lcomm min, 2 or .comm min, 2 to put aside space for two bytes (one word) in the bss section. The point of the bss section is that the loader will allocate space and set the content to zero on load, but it won't take up space in your file on disk.

Jump to Protected Mode not working after linking the kernel

南笙酒味 提交于 2019-12-24 14:43:10
问题 I have been developing a Bootloader and have run into a problem when linking c++ code to my assembly stage2 code before I linked the files the second stage would jump to protected mode then to long mode without any problems but now after I have linked it there seems to be a problem when jumping to protected mode Here is the code I use to jump to protected mode: main: ;first stage of bootloader is loaded at the address 0x07c0:0 ;second stage of bootloader is loaded at address 0x200:0x0 cli xor

error: unrecognised directive [ORG]

人盡茶涼 提交于 2019-12-24 10:57:26
问题 I was trying to write a boot-loader to use in dos-box I wrote the following code [BITS 16] ;tell the assembler that its a 16 bit code [ORG 0x7C00] ;Origin, tell the assembler that where the code will ;be in memory after it is been loaded JMP $ ;infinite loop TIMES 510 - ($ - $$) db 0 ;fill the rest of sector with 0 DW 0xAA55 ; add boot signature at the end of bootloader I was trying to assemble it using nasm by the following command nasm -f elf myfile.asm Then I see that error error: