Skip to content

Instantly share code, notes, and snippets.

View yellowbyte's full-sized avatar

Yu-Jye Tung yellowbyte

View GitHub Profile
@yellowbyte
yellowbyte / git.md
Last active December 24, 2021 09:08
useful but easily forgotten git commands

add: Add file contents to the index

  • Stage files with confirmation (commit only part of a file)
    • git add --patch (git add -p)

branch: List, create, or delete branches

  • Delete local branch if it has already been fully merged in its upstream branch
    • git branch -d <branch_name>
  • Delete local branch, irrespective of its merged status
    • git branch -D <branch_name>
@yellowbyte
yellowbyte / inline_asm.md
Last active September 15, 2022 17:42
inline assembly with gcc

Definition: assembly routines written as an inline function. Allows one to access architecture dependent instructions not available in C.

Form: must be inside of a function beginning with either 'asm' or '__asm__'

int main(){
    // volatile keyword tells the compiler to not optimize this area of code. The compiled binary will contain this exact sequence of code
    // optional: output operands, input operands, or clobbered registers
    __asm__ __volatile__ (
        <assembler template>
 ; 
@yellowbyte
yellowbyte / compiling_asm.md
Last active June 4, 2024 20:17
how to assemble assembly with NASM assembler to 32-bit or 64-bit ELF binary with or without libc

32-bit ELF binary

how to assemble and link:

nasm -f elf32 -o <filename>.o <filename>.asm
ld -m elf_i386 -o <filename> <filename>.o

template code (hello world):

section .text
global _start
@yellowbyte
yellowbyte / dynamic_loading.c
Last active May 2, 2024 13:23
example of using dlopen and dlsym to dynamically resolve call to `puts`. String reference to `puts` is also obfuscated.
// how to compile: gcc dynamic_loading.c -o dynamic_loading -ldl
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <string.h>
int main(int argc, char **argv) {
void *handle;
void (*go)(char *);
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
// use current time to seed the prng used by rand()
// if srand is not called (default: srand(1)), rand() will always generate the same sequence
srand(time(0));
for(int i=0; i<3; i++)
printf("%d\n", rand());