Skip to content

Instantly share code, notes, and snippets.

@vesim987
Created October 20, 2016 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vesim987/30cb3d9810f465557dffee903fd8143a to your computer and use it in GitHub Desktop.
Save vesim987/30cb3d9810f465557dffee903fd8143a to your computer and use it in GitHub Desktop.
section .data
error_msg db 'error while opening file', 10, 0 ;25 length
file dd 0x2 ;stdin
section .bss
buffer resb 64
section .text
global main
main:
mov ebp, esp
cmp dword [ebp+0x4], 1
je main_loop
;open file
mov ebx, [ebp+0x8]
mov ebx, [ebx+0x4] ;filename = file path
mov ecx, 0x0 ;flags = O_RDONLY
mov edx, 0x0000444 ;mode = S_IRUSR | S_IRGRP | S_IROTH
mov eax, 0x05 ;sys_open
int 0x80
mov dword [file], eax
;int 3
cmp eax, 0
jg main_loop
;print error
mov ebx, 0x1 ;fd = stdout
mov ecx, error_msg ;buf = error_msg
mov edx, 25 ;count = 25
mov eax, 0x4 ;sys_write
int 0x80
jmp end
main_loop:
mov ebx, dword [file] ;fd = file
mov ecx, buffer ;buf = buffer
mov edx, 64 ;count = 64
mov eax, 0x3 ;sys_read
int 0x80
test eax, eax
jz end
mov ebx, 0x1 ;fd = stdout
mov ecx, buffer ;buf = buffer
mov edx, 64 ;count = 64
mov eax, 0x4 ;sys_write
int 0x80
jmp main_loop
end:
xor eax, eax
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment