Skip to content

Instantly share code, notes, and snippets.

View FergusInLondon's full-sized avatar
😑

Fergus FergusInLondon

😑
View GitHub Profile
@FergusInLondon
FergusInLondon / roller.js
Last active April 27, 2017 17:04
Simple Rolling Average function
/* Fergus In London - https://fergus.london - <fergus@fergus.london>
*
* Simple little function for calculating rolling averages, both simple and
* weighted. Example can be found on the GitHub Gist, or on my website.
*
* Do as you please, no rights reserved and no warranties provided. :)
*/
/**
@FergusInLondon
FergusInLondon / rolling_average.js
Last active October 3, 2018 14:28
A little JS object for calculating rolling averages, complete with callbacks upon update.
/* Fergus In London - https://fergus.london - <fergus@fergus.london>
*
* Simple little function for calculating rolling averages, both simple and
* weighted. Example can be found on the GitHub Gist, or on my website.
*
* Do as you please, no rights reserved and no warranties provided. :)
*/
@FergusInLondon
FergusInLondon / events.h
Last active April 27, 2017 20:13
Really simple events/listeners registry in C
/**
* Simple little event registry built around the worlds most simplistic
* linked list implementation. Allows you to register a function (void())
* against a integer value, and provides a mechanism for triggering the
* associated functions for an integer.
*
* Not a great deal of use beyond those fun little weekend Arduino type
* projects.
*
* @see example.c
@FergusInLondon
FergusInLondon / base64_encode.c
Last active April 17, 2017 01:01
Base 64 Encoding in C
#include <stdio.h>
#include <stdlib.h>
#define FIRST_SIX_INDEX (buf[0] & 0xfc) >> 2
#define SECOND_SIX_INDEX ((buf[0] & 0x03) << 4) + ((buf[1] & 0xf0) >> 4)
#define THIRD_SIX_INDEX ((buf[1] & 0x0f) << 2) + ((buf[2] & 0xc0) >> 6)
#define FOURTH_SIX_INDEX buf[2] & 0x3f
char base64_map[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
@FergusInLondon
FergusInLondon / shuffler.js
Last active April 14, 2017 22:47
Simple array shuffler example.
/**
* shuffle(array[]) - Shuffles an array via a simplistic
* algo, not too dissimilar to Fisher-Yates.
*
* Ignore the -ahem- "clever" variable swapping one-liner,
* that's all it does.
*
* @param array
* @return array
*/
@FergusInLondon
FergusInLondon / filesnooper.c
Last active September 24, 2021 16:20
LD_PRELOAD Code Injection and Hooking
/* filesnooper.c - Fergus In London <fergus@fergus.london>
*
* Similar to snoopy.c, wrote to scratch an itch and demonstrate how LD_PRELOAD
* can be used for injecting code and/or hooking/wrapping around function calls.
*
* This is actually a good example, because if you try and use it with different
* ways of writing files, you'll see that to actually do this effectively you'd
* need to examine the target binary with strace, and potentially implement
* signatures from other libraries. (i.e a binary calling fprintf() may not be
* be effected by this.)
@FergusInLondon
FergusInLondon / snoopy.c
Created March 28, 2017 07:02
snoopy.c - process_vm_readv() demonstration.
/**
* snoopy.c - Snoop on another tasks memory.
* Fergus In London <fergus@fergus.london>
*
* This is a pretty basic demo of the process_vm_readv syscall, a syscall which
* provides a nicer interface than ptrace for accessing memory used by another
* task.
*
* To play with simply use `ps` to get a PID for the process you'd like to snoop
* on, and `pmap` for the relevant memory address.
### Keybase proof
I hereby claim:
* I am fergusinlondon on github.
* I am fergusinlondon (https://keybase.io/fergusinlondon) on keybase.
* I have a public key ASAZUkUuHB0BhpbpaL2yBsfar2Rj2ATeaS2RfjJMaiFkpQo
To claim this, I am signing this object: