assembly

How do I read a file with ReadFile onto the stack in NASM x86 assembly?

[亡魂溺海] 提交于 2020-05-24 07:42:43
问题 I have opened a file with OpenFile, and gotten its size with GetFileSize. I wish to use ReadFile and use the stack as the buffer it requires, allocating enough room on the stack with the size of the file returned from GetFileSize. When I run this I get no output. Here is my code... extern GetStdHandle extern GetModuleFileNameA extern OpenFile extern ReadFile extern WriteFile extern CloseHandle extern GetFileSize extern ExitProcess import GetStdHandle kernel32.dll import GetModuleFileNameA

How to interpret objdump disassembly output columns?

こ雲淡風輕ζ 提交于 2020-05-24 07:31:09
问题 I wrote a simple program in c which calls a function called while_loop with arguments 4,3,2. The function is just basically a while loop, I don't think it's really that relevant to my question since it's more of a generic question. I was told to run objdump -d, so I did. I have multiple questions so here it goes: I understand that in the leftmost column there are addresses and they increment according to the number of bytes in front. What I don't understand very well is the second column. Is

How to interpret objdump disassembly output columns?

妖精的绣舞 提交于 2020-05-24 07:30:10
问题 I wrote a simple program in c which calls a function called while_loop with arguments 4,3,2. The function is just basically a while loop, I don't think it's really that relevant to my question since it's more of a generic question. I was told to run objdump -d, so I did. I have multiple questions so here it goes: I understand that in the leftmost column there are addresses and they increment according to the number of bytes in front. What I don't understand very well is the second column. Is

How to write a several values on the screen using C printf function?

梦想与她 提交于 2020-05-24 05:34:12
问题 I have a program that counts root of quadratic equation. And I have a problem with printing the results on the screen, because I can print only one value. This is my code below, could you please tell me what should I do to pass two result to expression "x1 = ... ". [bits 32] call getaddr format db "x1 = %lf, x2 = %lf", 0xA, 0 offset equ $ - format a dq 1.0 ; b dq -11.0 c dq 28.0 minusfour dq -4.0 getaddr: finit mov eax, [esp] lea eax, [eax+offset] ; eax = a mov edx, [esp] lea edx, [edx+offset

Running data shellcode in c executable

ぃ、小莉子 提交于 2020-05-24 04:35:09
问题 I am working on this c program. I am compiling it with gcc on a 64 bits x64 linux: #include <stdio.h> char buffer[]={0x90,0x90,0xC3}; int main(int argc, char *argv[]) { void (*fct)(); fct=buffer; fct(); return 0; } 0x90 opcode is NOP 0xC3 opcode is RET I want to know what i should do in order to run this program. I get a segfault when running it... Thanks 回答1: TL;DR Compile with -z execstack to enable Linux's read-implies-exec feature for your executable. Despite the name, it applies to all

Running data shellcode in c executable

*爱你&永不变心* 提交于 2020-05-24 04:34:29
问题 I am working on this c program. I am compiling it with gcc on a 64 bits x64 linux: #include <stdio.h> char buffer[]={0x90,0x90,0xC3}; int main(int argc, char *argv[]) { void (*fct)(); fct=buffer; fct(); return 0; } 0x90 opcode is NOP 0xC3 opcode is RET I want to know what i should do in order to run this program. I get a segfault when running it... Thanks 回答1: TL;DR Compile with -z execstack to enable Linux's read-implies-exec feature for your executable. Despite the name, it applies to all

What does ADD al, '0' do, and why use it before printing an integer digit?

耗尽温柔 提交于 2020-05-24 03:45:14
问题 I am a novice in assembly language programming I searched for binary search program and found this and I tried understand the program. It's working fine but I couldn't understand the success part of the code: what is ADD al,'0' and what is mov res,al ? .model small .stack 100h .data ARR DW 1000H,2000H,3000H,4000H,5000H,6000H LEN DW ($-ARR)/2 KEY EQU 2000H SUC DB "KEY IS FOUND AT$" FAILURE DB "KEY IS NOT FOUND$" RES DB "POSITION",13,10,"$" .CODE START: MOV AX,@data MOV DS,AX MOV BX,00 ;LOW MOV

What does ADD al, '0' do, and why use it before printing an integer digit?

∥☆過路亽.° 提交于 2020-05-24 03:45:07
问题 I am a novice in assembly language programming I searched for binary search program and found this and I tried understand the program. It's working fine but I couldn't understand the success part of the code: what is ADD al,'0' and what is mov res,al ? .model small .stack 100h .data ARR DW 1000H,2000H,3000H,4000H,5000H,6000H LEN DW ($-ARR)/2 KEY EQU 2000H SUC DB "KEY IS FOUND AT$" FAILURE DB "KEY IS NOT FOUND$" RES DB "POSITION",13,10,"$" .CODE START: MOV AX,@data MOV DS,AX MOV BX,00 ;LOW MOV

Is it possible to get LLVM-IR from Assembly file?

我与影子孤独终老i 提交于 2020-05-23 21:43:11
问题 I compiled .S file using command: clang-8 -c funcs.s -o funcs.o -emit-llvm I found, that .o file was generated in ELF format. I was expected to see llvm-ir format (with "BC" characters at the beginning of resulting file). Seems, Clang ignores "-emit-llvm" flag. 回答1: Your question isn't fundamentally different from Is it possible to translate an assembly language to LLVM IR, optimize it and then recompile it to a different architecture?. asm source and binary executables / object files are

NASM Assembler, how to define label twice?

﹥>﹥吖頭↗ 提交于 2020-05-23 10:53:54
问题 I have different "*.asm" files that need to be included in the "main.asm" file. The problem I'm facing is that: In many files I have declared labels like "loop", "forLoop", "whileTag" etc... in the same way ( i.e. with the same name ) And when I try to %include "file1.asm" and %include "file2.asm" it gives me a compilation error. It says that I can't declare the same label twice ( i.e. file1.asm and file2.asm, both have "loopHere" label declared ). How do I solve this ? Thanks The problem