Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env perl
# Memoize function persistently
# klg, Feb 2014
use strict;
use warnings 'all';
use Storable qw/freeze thaw/;
use Compress::Zlib;
use Fcntl ':flock';
sub pmemz($&) {
#!/usr/bin/env perl
# CRC32 preimage with fixed prefix/suffix.
# klg, Feb 2014
use strict;
# CRC32 table
my @crc_table;
for my $n (0 .. 255) {
my $c = $n;
@mwgamera
mwgamera / gzhdr.pl
Last active October 13, 2021 21:53
#!/usr/bin/perl
# Analyze GZIP header for anything unusual, -v to print the usual too.
# klg, Dec 2013
use strict;
use constant GZIP_ID => 0x8b1f;
use constant {
FLG_FTEXT => (1 << 0),
FLG_FHCRC => (1 << 1),
#!/usr/bin/env perl
# Analyze header of CRX packages (Chrome extensions).
# klg, Feb 2014
use strict;
use open IO => ':bytes';
use Digest::SHA 'sha256_hex';
use MIME::Base64;
use Crypt::OpenSSL::RSA;
use constant CRX_MAGIC => 0x34327243;
@mwgamera
mwgamera / hb-test.py
Last active August 29, 2015 13:58 — forked from takeshixx/hb-test.py
OpenSSL heartbeat PoC with SMTP and XMPP STARTTLS support.
#!/usr/bin/env python2
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford ([email protected])
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
% echo "I'm late to the party :( -- [email protected]" | openssl sha1 -sign server.key -sha1 | openssl enc -base64
GebyG5i9chR3KftgifswQELVMhxK+CzuKp/gXb8K9nAtNu7i/Vz9pv28PaxOLRUd
jotryjgjvwB1T4lGkUBF+3eVvTP9xlQ7lgT6jvm1JEGsFMT806uLWAgWh7YVnzhm
H8r1exl7mCYWeYvmR6YgVk9ImUbTRmMwt1XX39M6IDiw9o3Rss9txAURwdDoECjK
coaBhrS6LwWqh1Tm2TfnywjuAUTUZnqeuLyj1UoYjfy+yneofhl8W7FmD0hiAp+v
9SmGJvVAoY1peJbdYKQ9us8jJMuMs+75be2/erNMCdHAZWOD8QnaliE5dNZrlwiY
QkHBqNtaes1ti2y/fCzOcA==
dnl The Game of Life in POSIX macro processor M4
dnl klg, Apr 2014
dnl
divert(-1)
define(`local',`pushdef(`$1',`$2')`'$3`'popdef(`$1')')
define(`silent',
`local(`__divnum',divnum,`divert(-1)$*`'divert(__divnum)')')
define(`for',`ifelse(eval(`$2'<`$3'),`1',dnl
`local(`$1',`$2',`$4')`'$0(`$1',incr(`$2'),`$3',`$4')')')
#!/usr/bin/env perl
# Store in GZIP (RFC 1952) format uncompressed.
# klg, May 2014
use strict;
use open ':std', IO => ':bytes';
use Compress::Zlib 'crc32';
push @ARGV, '-' if $#ARGV < 0;
for my $file (@ARGV) {
@mwgamera
mwgamera / gist:364c4193fb54225b446a
Last active January 5, 2021 12:00
List all fonts known to fontconfig that provide glyph for given characters.
#!/usr/bin/env python3
# klg, May 2014
import fontconfig
import sys
chars = list(''.join(sys.argv[1:]))
if not len(chars):
sys.exit(0)
fonts = fontconfig.query()
#include "gophernicus.h"
#include <assert.h>
int main() {
int shmid;
shm_state *shm;
shmid = shmget(SHM_KEY, sizeof(shm_state), 0);
assert(shmid != -1);
shm = shmat(shmid, NULL, 0);
assert(shm != (void*) -1);