Skip to content

Instantly share code, notes, and snippets.

View ioncodes's full-sized avatar
😴
Playing with memory regions...

Layle ioncodes

😴
Playing with memory regions...
View GitHub Profile
@ioncodes
ioncodes / encode_positive_jump.py
Created February 24, 2018 13:33
Calculates the bytes used for a positve relative jump over 129 bytes in x64 asm (e.g: je $+300)
loc = 300
asm = [-0x06, 0x00, 0x00, 0x00]
for i in range(0, loc):
if asm[0] == 0xff:
if asm[1] == 0xff:
if asm[2] == 0xff:
asm[3] += 1
asm[2] = 0x00
asm[1] = 0x00
@ioncodes
ioncodes / encode_negative_jump.py
Last active February 24, 2018 14:06
Calculates the bytes used for a negative relative jump over 126 bytes in x64 asm (e.g: je $-300)
loc = 200
asm = [0xfa, 0xff, 0xff, 0xff]
for i in range(0, loc):
if asm[0] == 0x00:
if asm[1] == 0x00:
if asm[2] == 0x00:
asm[3] -= 1
asm[2] = 0xff
asm[1] = 0xff
@ioncodes
ioncodes / gist:a8fb16c25b2b043834f5451ecbcd630e
Created February 11, 2018 13:59 — forked from Bouke/gist:11261620
Multiple Python installations on OS X

Previous versions used homebrew to install the various versions. As suggested in the comments, it's better to use pyenv instead. If you are looking for the previous version of this document, see the revision history.

$ brew update
$ brew install pyenv
$ pyenv install 3.5.0
$ pyenv install 3.4.3
$ pyenv install 3.3.6
$ pyenv install 3.2.6
$ pyenv install 2.7.10

$ pyenv install 2.6.9

@ioncodes
ioncodes / bad_combinations.rs
Created February 9, 2018 16:26
Combination generator which does NOT work. This has a reference issue. This is just to show the difference between a good structure and a bad structure. For @mortoray. (Not that your structure is bad <3)
use std::ops::{Index, IndexMut};
struct Combinations<T> {
combinations: Vec<Vec<T>>
}
impl<T> Combinations<T> {
pub fn new() -> Combinations<T> {
Combinations {
combinations: Vec::<Vec<T>>::new()
@ioncodes
ioncodes / combinations.rs
Last active February 9, 2018 16:31
Generic combinations generator in Rust with iterator. Created for @mortoray.
use std::ops::{Index, IndexMut};
struct Combinations<T> {
combinations: Vec<Vec<T>>,
index: usize,
}
impl<T> Combinations<T> {
pub fn new() -> Combinations<T> {
Combinations {
@ioncodes
ioncodes / pair_gen.rs
Last active February 9, 2018 16:20
combination gen for mortoray
#[derive(Debug)]
struct Pair {
pub x: usize,
pub y: usize,
}
fn combs(v: Vec<usize>) -> Vec<Pair> {
let mut t = &v[1..];
let mut combinations = Vec::<Pair>::new();
let mut w = trucks[i].weight;
let mut h = trucks[i].height;
w = 10;
h = 10;
trucks[i].weight = w;
trucks[i].height = h;
@ioncodes
ioncodes / sign.sh
Created February 6, 2018 15:19
Fix .app is damaged in Mac OS X without disabling Gatekeeper. Also fixes "code object is not signed at all"
sudo codesign --force --sign --deep - /Applications/YourApp.app
@ioncodes
ioncodes / convert.rs
Created February 5, 2018 19:57
Convert u32 to u8 slice with Big Endian and Little Endian support!
let bytes: [u8; 4] = unsafe { transmute(0u32.to_le()) }; // or to_be
@ioncodes
ioncodes / lifetime.rs
Created February 5, 2018 09:55
Small explanation how lifetimes work for @mortoray
struct Crate {
pub weight: f64,
}
/*
Rust can handle memory management on it's own.
However, Rust doesn't know how long a reference should live in a struct.
The reference may also depend on other references, etc.
Therefore we must let the compiler know how long the reference should live.
This is done with the 'lifetime specifiers'/'lifetime parameters'.