Skip to content

Instantly share code, notes, and snippets.

@Silica163
Last active May 19, 2025 11:40
Show Gist options
  • Select an option

  • Save Silica163/ba63b304ef8f798bac3b5fedb9064b10 to your computer and use it in GitHub Desktop.

Select an option

Save Silica163/ba63b304ef8f798bac3b5fedb9064b10 to your computer and use it in GitHub Desktop.
c without stdlib and libc
void exit(int code);
int write(int fd, const void * buff, int count);
int strlen(char * str){
char * end = str;
while(*(end++));
return end - str;
}
int main(int argc, char ** argv, char ** envp){
for(;argc > 0;argc--,argv++){
int len = strlen(*argv);
write(1, *argv, len);
write(1, "\n", 1);
}
for(;*envp != 0;){
int len = strlen(*envp);
write(1, *envp, len);
write(1, "\n", 1);
envp++;
}
return 0;
}
; nasm -f elf64 -o nolibc_starter.o nolibc_starter.s
; gcc main.c -o main -nolibc -nostdlib -fno-builtin nolibc_starter.o
global exit, _start, write
extern main
section .text
_start:
xor rbp, rbp
mov rdi, [rsp] ; 1st argc
lea rsi, [rsp+8] ; 2nd argv
lea rdx, [rsp+16+8*rdi] ; 3rd envp
call main
mov rdi, rax
call exit
exit:
mov rax, 60
syscall
write:
push rbp
mov rbp, rsp
mov rax, 1
syscall
pop rbp
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment