Skip to content

Instantly share code, notes, and snippets.

#include <windows.h>
typedef unsigned char byte;
typedef unsigned short uint16;
typedef unsigned int uint32;
void* get_proc_addr(byte *base, byte *name)
{
byte *pe_header = base+*(uint32*)(base+0x3c);
byte *exports = base+*(uint32*)(pe_header+0x78);
@MicahElliott
MicahElliott / colortrans.py
Created November 29, 2010 07:57
Convert values between RGB hex codes and xterm-256 color codes.
#! /usr/bin/env python
""" Convert values between RGB hex codes and xterm-256 color codes.
Nice long listing of all 256 colors and their codes. Useful for
developing console color themes, or even script output schemes.
Resources:
* http://en.wikipedia.org/wiki/8-bit_color
* http://en.wikipedia.org/wiki/ANSI_escape_code
@amr
amr / find-futex-wait.sh
Created November 30, 2010 18:37
Find processes executing futex with FUTEX_WAIT (helps find deadlock-ed processes)
#!/bin/bash
#
# Find all processes that are executing a futex(2) call with op=FUTEX_WAIT
# In some cases this can be helpful in finding deadlock-ed processes.
#
test ! $UID -eq 0 && echo -e "WARNING: Not running as root, only processes for this user are being scanned\n" >&2;
pids=$(ps -u $UID -opid --no-headers)
for pid in $pids; do
@msantos
msantos / bpf.c
Last active April 2, 2024 18:54
Example of using bpf to capture packets
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <err.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
@hSATAC
hSATAC / 256color.pl
Created July 20, 2011 14:48
256color.pl
#!/usr/bin/perl
# Author: Todd Larason <jtl@molehill.org>
# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.2 2002/03/26 01:46:43 dickey Exp $
# use the resources for colors 0-15 - usually more-or-less a
# reproduction of the standard ANSI colors, but possibly more
# pleasing shades
# colors 16-231 are a 6x6x6 color cube
for ($red = 0; $red < 6; $red++) {
@chenkaie
chenkaie / fdhijack.sh
Created December 2, 2011 18:00
Redirect stdin, stdout, stderr of a daemon to /dev/pts/#
#!/bin/sh
#
# Redirect stdin, stdout, stderr of a daemon to /dev/pts/#
#
#################################################################################################################
# Ref: stdio buffering: http://www.pixelbeat.org/programming/stdio_buffering/
# Default Buffering modes:
# stdin -> is always buffered
# stderr -> is always unbuffered
# if stdout is a terminal then buffering is automatically set to line buffered, else it is set to buffered
@crimsonwoods
crimsonwoods / backtrace.c
Created November 21, 2012 03:16
A sample code for ARM processor to handle the abnormal termination and display backtrace.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <endian.h>
@yegle
yegle / how-kernel-handles-send-system-call.md
Last active August 6, 2021 09:32
How Linux kernel handles the send system call

This is a brief introduction about how Linux kernel handles the send system call.

This study is based on kernel version 3.7.2, which is the latest stable kernel when writing this study.

How system call is defined

In the latest kernel, the system call is defined using the SYSCALL_DEFINEx macro, in which x is the number of arguments. For example, in order to find the definition of asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);, you need to grep for SYSCALL_DEFINE6 because it has 6 arguments.

The definition of the system call send can be found at net/socket.c.

@rlamana
rlamana / extract-sf2.sh
Created May 30, 2013 11:30
Convert a SoundFont + MIDI file to a CAF audio file. Based on https://github.com/neonichu/Core-Audio-Samples
#!/bin/sh
#
## Convert a SoundFont + MIDI file to a CAF audio file.
##
## needs:
## fluidsynth, sox (installable via brew)
## afconvert (part of OS X)
#
@jhass
jhass / dump_socket.sh
Last active June 11, 2024 13:15
Capture unix socket to pcap file with socat and tshark
#!/bin/bash
# Parameters
socket="/run/foo.sock"
dump="/tmp/capture.pcap"
# Extract repetition
port=9876
source_socket="$(dirname "${socket}")/$(basename "${socket}").orig"