Created
July 25, 2020 10:13
-
-
Save six519/b1f0145f137fb191048ededd989c9c53 to your computer and use it in GitHub Desktop.
Get Information About Current Linux Kernel In Assembly Language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;macro, struct and syscall uname | |
;just practicing programming in assembly language (Ferdinand Silva) | |
%macro print_info 3 | |
mov r13, %1 | |
mov r14, %2 | |
call print | |
mov r13, utsname + %3 | |
mov r14, 24 | |
call print | |
mov r13, NEW_LINE | |
mov r14, 1 | |
call print | |
%endmacro | |
section .data | |
SYS_EXIT: equ 60 | |
SYS_UNAME: equ 63 | |
SYS_WRITE: equ 1 | |
STD_IN: equ 1 | |
NEW_LINE: db 10 | |
sname: db "System Name: " | |
nname: db "Node Name: " | |
rname: db "Release: " | |
vname: db "Version: " | |
mname: db "Machine: " | |
struc UTSNAME | |
sysname: resb 64 | |
nodename: resb 64 | |
release: resb 64 | |
version: resb 64 | |
machine: resb 64 | |
endstruc | |
utsname: istruc UTSNAME | |
at sysname, db "" | |
at nodename, db "" | |
at release, db "" | |
at version, db "" | |
at machine, db "" | |
iend | |
global _start | |
section .text | |
_start: | |
call uname | |
;sysname | |
print_info sname, 13, sysname | |
;nodename | |
print_info nname, 11, nodename | |
;release | |
print_info rname, 9, release | |
;version | |
print_info vname, 9, version | |
;machine | |
print_info mname, 9, machine | |
jmp exit | |
uname: | |
mov rax, SYS_UNAME | |
mov rdi, utsname | |
syscall | |
ret | |
print: | |
mov rax, SYS_WRITE | |
mov rdi, STD_IN | |
mov rsi, r13 | |
mov rdx, r14 | |
syscall | |
ret | |
exit: | |
mov rax, SYS_EXIT | |
mov rdi, 0 | |
syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment