Skip to content

Instantly share code, notes, and snippets.

@inaz2
inaz2 / inlineasm.c
Last active August 29, 2015 13:58
GCCインラインアセンブラでスタックを見る
$ gcc -masm=intel inlineasm.c
$ ./a.out
saved_ebp = 0
saved_eip = b7e444d3
argc = 1
argv = bffff864
envp = bffff86c
$ objdump -d a.out | sed -n '/<main>:/,/^$/p'
@inaz2
inaz2 / test_malloc.c
Last active August 29, 2015 13:58
malloc and buffer over-read vulnerability
$ uname -a
Linux vm-ubuntu64 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$ gcc test_malloc.c
$ ./a.out
[+] allocate chunks: a = malloc(32), b = malloc(256), c = malloc(32)
a = 0x832010, b = 0x832040, c = 0x832150
*a = 41414141, *b = 42424242, *c = 45524548
[+] free the mid chunk: free(b)
@inaz2
inaz2 / yt2m4a.py
Last active August 29, 2015 13:58
wgetとavconvでYouTube URLをM4A (AAC) ファイルに変換
$ python yt2m4a.py "http://www.youtube.com/watch?v=4YMD6xELI_k"
--2014-04-11 02:25:26-- http://r2---sn-ogueyn7z.googlevideo.com/videoplayback?sparams=id%2Cip%2Cipbits%2Citag%2Cpcm2fr%2Cratebypass%2Csource%2Cupn%2Cexpire&ipbits=0&mt=1397150542&expire=1397173854&upn=15FckWnBsJw&fexp=927905%2C936905%2C901065%2C916623%2C945513%2C937417%2C913434%2C936916%2C934022%2C936921%2C936923&signature=A2B6A3A92CCB9F6F09EDEC21266137C2A09975DF.A94CC65958FD475F79CE18DDF05188C29591C7A0&key=yt5&ip=123.224.99.3&pcm2fr=yes&itag=22&source=youtube&sver=3&mv=u&ratebypass=yes&ms=au&id=o-ADTX4MBPHtBDylBsjOsDle1msEAsW4PTJ7EyQH0qyPo1
Resolving r2---sn-ogueyn7z.googlevideo.com (r2---sn-ogueyn7z.googlevideo.com)... 74.125.171.39
Connecting to r2---sn-ogueyn7z.googlevideo.com (r2---sn-ogueyn7z.googlevideo.com)|74.125.171.39|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://r13---sn-ogueyn7z.googlevideo.com/videoplayback?sparams=id%2Cip%2Cipbits%2Citag%2Cpcm2fr%2Cratebypass%2Csource%2Cupn%2Cexpire&ipbits=0&
@inaz2
inaz2 / rot.py
Created June 9, 2014 06:10
perform rot0 -- rot25
$ echo -n 'hello world' | python rot.py
hello world
ifmmp xpsme
jgnnq yqtnf
khoor zruog
lipps asvph
mjqqt btwqi
nkrru cuxrj
olssv dvysk
pmttw ewztl
@inaz2
inaz2 / ngram.py
Last active August 29, 2015 14:02
calculate n-gram statistics
$ wget http://printkjv.ifbweb.com/AV_txt.zip
2014-06-09 15:30:46 (535 KB/s) - `AV_txt.zip' saved [1262589/1262589]
$ unzip AV_txt.zip
Archive: AV_txt.zip
inflating: AV1611Bible.txt
$ python ngram.py < AV1611Bible.txt
1 gram result:
414963 'e'
@inaz2
inaz2 / auto_and_decltype.cpp
Created July 3, 2014 11:24
C++11: auto and decltype
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <functional>
using namespace std;
template <typename T>
auto cube(T x) -> decltype(x)
{
@inaz2
inaz2 / gist:8cc80f55d5f1a212ec15
Created July 9, 2014 01:41
seq, factor, awkで素数列挙
$ seq 100 | factor | awk 'NF==2{print $2}'
2
3
5
7
11
13
17
19
23
@inaz2
inaz2 / gist:65ef1d0cdcc32cf3c9bf
Created July 9, 2014 06:56
標準入力を1行ずつ処理する
$ while read; do echo -n "$REPLY" | od -tx1z; done
hoge
0000000 68 6f 67 65 >hoge<
0000004
fuga
0000000 66 75 67 61 >fuga<
0000004
@inaz2
inaz2 / gist:3baf5ae2dcb472b8afe4
Created July 18, 2014 02:26
バイナリファイルから特定のバイト列を検索し、オフセットを表示する
$ grep -boa $'\xc9\xc3' a.out | awk -F: '{printf "0x%x\n", $1}' # leave; ret
0x401
0x466
@inaz2
inaz2 / gist:fb306e4811e00d46ffff
Created July 21, 2014 13:35
curlで短縮URLの解決
$ curl -IL http://t.co/kzZyfMkRFl
HTTP/1.1 301 Moved Permanently
cache-control: private,max-age=300
content-length: 0
date: Mon, 21 Jul 2014 13:32:44 GMT
expires: Mon, 21 Jul 2014 13:37:44 GMT
location: http://htn.to/jKGE4e
server: tfe
set-cookie: muc=a00e470a-8304-4e1d-b87d-597a02b0a98f;Domain=t.co;Expires=Sat, 02-Jul-2016 13:32:44 GMT