Skip to content

Instantly share code, notes, and snippets.

View ryankurte's full-sized avatar
🥔

ryan ryankurte

🥔
View GitHub Profile
@ryankurte
ryankurte / dlsym.rs
Created January 17, 2019 02:03
Dynamic library hooking experiments in rust
#![feature(never_type)]
use std::ffi::{CString, CStr, OsStr};
use std::ptr;
extern crate libc;
use libc::{c_void, c_char, c_int,};
#[repr(C)] pub struct Handle { _private: () }
@ryankurte
ryankurte / init.sh
Last active November 29, 2018 02:34
Helper script to setup a new debian machine
#!/bin/bash
set -e
# Update sources to nz mirrors
sudo sed -i"" 's|http://deb.debian.org|http://ftp.nz.debian.org|g' /etc/apt/sources.list.d/base.list
# Install backports
BACKPORT_FILE=/etc/apt/sources.list.d/debian-backports.list
if [ ! -f $BACKPORT_FILE ]; then
extern crate embedded_hal;
use embedded_hal::blocking::spi::{Write, Transfer};
extern crate embedded_hal_mock;
use embedded_hal_mock::MockError;
use embedded_hal_mock::spi::{Mock as SpiMock, Transaction as SpiTransaction};
enum Operation<'a> {
Write(&'a [u8]),
@ryankurte
ryankurte / build.rs
Last active September 4, 2018 18:30
Rust module cmake helper
// build.rs example for rust libraries to generate c headers
// https://gist.github.com/ryankurte/8d3abcb0249269d56e07b183aa06ba62
// Copyright 2018 Ryan Kurte
// Usage
// 1. Add rusty-binder and rusty-cheddar as build dependencies to your top level Cargo.toml
// [build-dependencies]
// rusty-binder = { git = "https://gitlab.com/rusty-binder/rusty-binder.git" }
// rusty-cheddar = { git = "https://gitlab.com/rusty-binder/rusty-cheddar.git" }
// 2. Set your crate type to static in Cargo.toml
@ryankurte
ryankurte / main.c
Last active April 13, 2024 07:50
Simple C FIFO Queues (aka Ring Buffers)
#define QUEUE_SIZE 16
int main(int argc, char** argv) {
queue_t example = {0, 0, QUEUE_SIZE, malloc(sizeof(void*) * QUEUE_SIZE)};
// Write until queue is full
for (int i=0; i<QUEUE_SIZE; i++) {
int res = queue_write(&example, (void*)(i+1));
assert((i == QUEUE_SIZE - 1) ? res == -1: res == 0);
}
@ryankurte
ryankurte / hardfault.c
Last active October 8, 2017 16:00
Cortex M Hardfault Handler
// A HardFault handler to make life easier when debugging
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/Cihcfefj.html
// The smol version
void HardFault_Handler(void) {
SCB_Type* scb = SCB;
(void*)scb;
__asm("BKPT #0");
while(1);
}
@ryankurte
ryankurte / crc16.c
Last active July 18, 2017 03:07
CRC Implementations
#include <stdint.h>
#include <stdbool.h>
uint16_t crc16_ccit_FFFF(uint32_t len, uint8_t* data) {
uint16_t crc = 0xFFFF;
for (uint32_t i=0; i<len; i++) {
uint16_t d = data[i];
d ^= crc >> 8;
@ryankurte
ryankurte / main.c
Created June 4, 2017 03:53
OzLockCon Badge Morse Firmware
#include <avr/io.h>
#include <util/delay.h>
// Board Definitions
#define LED0_PIN 0
#define LED1_PIN 3
#define SW_PIN 2
// IO Helpers
#define IO_PORT PORTB
@ryankurte
ryankurte / index.js
Created May 10, 2017 03:49
Super simple SQLi example in node.js
// Simple SQLi Example
// See:
// https://www.w3schools.com/sql/sql_injection.asp
// https://www.owasp.org/index.php/Testing_for_SQL_Injection_(OTG-INPVAL-005)
var express = require('express')
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('./test.db');
var app = express()
@ryankurte
ryankurte / demo2.c
Last active May 1, 2018 01:13
Buffer overflow example in C
// Demo 1
// clang -fno-stack-protector -fno-sanitize=safe-stack -D_FORTIFY_SOURCE=0 -m32 -Wl,-no_pie -O0 -g demo2.c -o demo2.o
#include <stdio.h>
#include <string.h>
char password[] = "password";
int get_password() {
int auth_ok = 0;