Skip to content

Instantly share code, notes, and snippets.

@warabanshi
warabanshi / base_asm.s
Created October 8, 2012 06:35
python-JIT
.intel_syntax noprefix
.globl main
main:
push r12
push r13
push rbx
mov r13, 0x123456789abcdef0
mov r12, 26
@warabanshi
warabanshi / gist:3946847
Last active October 12, 2015 00:57
python-JIT brainf*ck
import sys, struct
from ctypes import *
libc = cdll.LoadLibrary("libc.so.6")
free = libc.free
printf = libc.printf
putchar = libc.putchar
getchar = libc.getchar
mmap = libc.mmap
@warabanshi
warabanshi / tiny1.c
Created November 22, 2012 17:41
ELF sample1
int main () { return 42; }
@warabanshi
warabanshi / tiny2.s
Created November 23, 2012 05:09
ELF sample2
BITS 64
EXTERN _exit
GLOBAL _start
SECTION .text
_start:
mov edi, 42
call _exit
@warabanshi
warabanshi / tiny3.s
Created November 23, 2012 05:24
ELF sample3
BITS 64
GLOBAL _start
SECTION .text
_start:
mov eax, 60
mov edi, 42
syscall
@warabanshi
warabanshi / elf64-base.s
Created November 24, 2012 14:34
ELF sample4
BITS 64
org 0x08048000
ehdr: ; ELF64_Ehdr(ELF header)
db 0x7f, "ELF", 2, 1, 1 ; e_ident
times 9 db 0 ; e_ident
dw 2 ; u16 e_type
dw 0x3e ; u16 e_machine /usr/include/linux/elf-em.h
; 62 = x86-64
dd 0x01 ; u32 e_version
BITS 64
org 0x08048000
ehdr: ; ELF64_Ehdr(ELF header)
db 0x7f, "ELF", 2, 1, 1 ; e_ident
times 9 db 0 ; e_ident
dw 2 ; u16 e_type
dw 0x3e ; u16 e_machine /usr/include/linux/elf-em.h
; 62 = x86-64
dd 0x01 ; u32 e_version
@warabanshi
warabanshi / write.s
Last active December 10, 2015 12:28
write character for stdout by system call
.intel_syntax noprefix
.comm mem, 30000
.globl main
main:
lea rbx, mem
mov byte ptr [rbx], 0x41
mov rax, 1 # specify write system call
mov edx, 0x1 # 3nd argument (count)
mov rsi, rbx # 2nd argument (string pointer)
@warabanshi
warabanshi / echo.s
Last active December 10, 2015 12:28
read character from stdin and write stdout by system call
.intel_syntax noprefix
.comm mem, 30000
.globl main
main:
lea rbx, mem
# read systemcall
mov rax, 0 # specify read system call
mov edx, 0x1 # 3nd argument (count)
@warabanshi
warabanshi / elf64-bss.asm
Last active March 8, 2023 18:33
ELF sample6 bss division
BITS 64
org 0x08048000
ehdr: ; ELF64_Ehdr(ELF header)
db 0x7f, "ELF", 2, 1, 1 ; e_ident
times 9 db 0 ; e_ident
dw 2 ; u16 e_type
dw 0x3e ; u16 e_machine /usr/include/linux/elf-em.h
; 62 = x86-64
dd 0x01 ; u32 e_version