Skip to content

Instantly share code, notes, and snippets.

@scottt
scottt / div0.c
Last active February 26, 2023 13:05
Generate SIGFPE through integer division by zero
volatile int a, b, out;
__attribute__((noclone,noinline))
void g(void)
{
a = -1;
b = 0;
out = a/b;
}
@scottt
scottt / Session
Created January 28, 2015 14:14
compilefunc var-arg.c
# Grab 'compilefunc' here:
# https://github.com/scottt/scottt-bin/blob/master/compilefunc
$ CFLAGS='-O0' compilefunc -s -l var-arg.c main
28 {
0x0000000000400823 <+0>: push %rbp
0x0000000000400824 <+1>: mov %rsp,%rbp
29 /* See 3.5.7 Variable Arugment Lists in http://www.x86-64.org/documentation/abi.pdf
30 * "When a function taking variable-arguments is called, %rax must be set to the
#!/usr/bin/env python2
from __future__ import print_function
import sys
import collections
d = collections.defaultdict(int)
fin = sys.stdin
n = int(fin.readline())
@scottt
scottt / malloc-perturb.c
Created July 21, 2014 16:01
Test the GLIBC MALLOC_PERTURB_ feature
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <malloc.h>
struct Rect {
char a, b;
};
typedef struct Rect Rect;
@scottt
scottt / t.py
Created July 15, 2014 14:19
Filter out deleted entries
import json
l = json.loads(open('t.json').read())
l0 = [ x for x in l if u'delete' not in x ]
@scottt
scottt / t.py
Created July 15, 2014 08:42
Filter out deleted uses from twitter stream
l = [ {'created_at': None, 'foo': 'bar'}, {'delete': 1 } ]
[ x for x in l if 'delete' not in x ]
# Out: [{'created_at': None, 'foo': 'bar'}]
@scottt
scottt / array-to-ogg.c
Created April 24, 2014 16:05
Extract audio tracks from netcat-cpi-kernel-module to OGG files
/* Usage:
* $ git clone https://github.com/usrbinnc/netcat-cpi-kernel-module.git
* $ gcc array-to-ogg.c -o array-to-ogg
* $ ./array-to-ogg netcat-cpi-kernel-module/tracks/*data.h
* $ ls netcat-cpi-kernel-module/tracks/*data.ogg
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#!/bin/sh
while true; do
time curl http://api.plate.tw/menu.php?rest_id=2
sleep 1
done
package tw.plate;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
SSLSocketFactory goodSslSocketFactory(Context context) {
KeyStore trusted = KeyStore.getInstance("BKS");
InputStream in = context.getResources().openRawResource(R.raw.truststore);
trusted.load(in, TRUST_STORE_PASSWORD);
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trusted);
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
return sslContext.getSocketFactory();