Skip to content

Instantly share code, notes, and snippets.

View alanduan's full-sized avatar

Alan Duan alanduan

View GitHub Profile
#include <stdio.h>
int main()
{
long long a = -1ll;
unsigned b = 0xff;
a &= ~b;
// what is a now?
printf("0x%016llx\n", a);
}
; yasm -o %:r.o % -f elf32 -g stabs
; ld -m elf_i386 %:r.o -o %:r -lc --dynamic-linker /lib/ld-linux.so.2
section .data
dividend dq 0xdeadbeef12
divisor dd 0x100
quotient dd 0
remainder dd 0
; yasm -o %:r.o % -f elf32 -g stabs
; ld -m elf_i386 %:r.o -o %:r -lc --dynamic-linker /lib/ld-linux.so.2
section .text
msg db "hello world!",10,0
extern puts
extern exit
int8_t c2hex(int8_t c)
{
return (unsigned) (c - '0') < 10 ? c - '0' : ((unsigned) (c | 0x20) - 'a' < 6 ? 9 + (c&7) : -1);
}
int8_t _c2hex(int8_t c)
{
if (c - '0' >= 0 && c - '0' < 10) return c - '0';
if (c - 'a' >= 0 && c - 'a' < 7) return c - 'a' + 10;
if (c - 'A' >= 0 && c - 'A' < 7) return c - 'A' + 10;
extern uint32_t crc32_table[];
uint32_t
crc32(uint8_t *buf, size_t count, uint32_t crc)
{
while (count--)
crc = crc32_table[(crc32 ^ *buf++) & 0xff] ^ crc32 >> 8;
return crc;
}
uint32_t
hash(uint8_t const *buff, size_t count, uint32_t hash, uint8_t bits)
{
for (size_t i = 0; i < count; i++)
{
hash = ((hash << bits) | (hash >> (32 - bits))) ^ buf[i];
}
return hash;
}
@alanduan
alanduan / dlist.c
Last active August 14, 2016 02:19
[structure] dlist
typedef struct dlist_s dlist_t;
struct dlist_s
{
dlist_t *next;
dlist_t *prev;
};
void dlist_init(dlist_t *list)
{
@alanduan
alanduan / div.asm
Created August 13, 2016 03:02
[INSTRUCTION] DIV
; get value_addr % 0x10
;
; yasm -f elf32 -o div.o -g stabs div.asm
; or
; yasm -f elf32 -o div.o -g dwarf2 div.asm
;
; ld -m elf_i386 -o div div.o
;
; run the program
; ./div
import time
from random import randint
import curses
from console import ConsoleDisplay
if __name__ == '__main__':
rows, cols = (25, 80)
def func(stdscr, rows, cols):
console = ConsoleDisplay(stdscr, rows, cols)
from itertools import product
class ConsoleDisplay(object):
def __init__(self, win, rows, cols):
win.resize(rows, cols)
self._win = win
self.rows = rows
self.cols = cols