Skip to content

Instantly share code, notes, and snippets.

View rbran's full-sized avatar
🦜

Rubens Brandão rbran

🦜
View GitHub Profile
pub struct Architecture {
pub name: String,
}
#[derive(Clone, Copy)]
pub struct RegisterInfo;
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub struct Register;
#[derive(Clone, Copy)]
pub struct RegisterStackInfo;
// This code demonstrate how to break a simple disassembler.
// you may need to build with "-no-pie"
// gcc -o get_key get_key.c -no-pie
#include <stdio.h>
const char reveal_key[] = "The key is '%x'\n";
int get_key(int argc) {
int key = 0;
__asm__(
@rbran
rbran / cases.md
Created June 13, 2023 14:16
x86-64 icicle pattern matchers ordering

table instruction

id location context pattern
355 ia.sinc:1558:1 ________________________________!_______________________!!_____! !!!!!!!!________________________________________________________
356 ia.sinc:1559:1 ________________________________!_________________________!!___! !!!!!!!!________________________________________________________
370 ia.sinc:1634:1 ________________________________!__________!!____!!!___________! !!!!!!!!______!!!!______________________________________________
371 ia.sinc:1636:1 ________________________________!__________!!____!!!___________! !!!!!!!!______!!!!______________________________________________
372 ia.sinc:1638:1 ________________________________!__________!!____!!!___________! !!!!!!!!______!!!!______________________________________________
373 ia.sinc:1640:1 ________________________________!__________!!____!!!___________! `!!!!!!!!______!!!!
@rbran
rbran / generic_borrow_forced.rs
Created May 14, 2023 11:46
Avoid using a blanket implementations by forcing the user to provide a reference in the first place.
use std::borrow::Cow;
/// A trait for things that can speak.
trait Speaker {
fn speak(&self);
}
/// BasicSpeaker is an empty struct that exists only to implement Speaker.
#[derive(Clone)]
struct BasicSpeaker;
@rbran
rbran / generic_borrow.rs
Created May 14, 2023 11:38
Avoid using a blanket implementations by using Borrow instead.
use std::borrow::{Borrow, Cow};
/// A trait for things that can speak.
trait Speaker {
fn speak(&self);
}
/// BasicSpeaker is an empty struct that exists only to implement Speaker.
#[derive(Clone)]
struct BasicSpeaker;
@rbran
rbran / deku_reader.rs
Created January 26, 2023 16:11
Deku read from std::io::Read proposal
use deku::prelude::*;
#[derive(Debug, PartialEq, DekuRead)]
struct DekuStruct {
field_a: u8,
field_b: u16,
field_c: DekuEnum,
}
#[derive(Debug, PartialEq, DekuRead)]
#[deku(type = "u8")]
@rbran
rbran / downcast-rc.rs
Last active July 5, 2022 13:02
if you already have an Rc, downcast is cheap on Rust
use std::any::Any;
use std::collections::HashMap;
use std::rc::Rc;
struct Foo {
id: u8,
name: String,
value: u128,
}
@rbran
rbran / gist:88b8a19050a92d161ea52b78f28fb5f9
Created December 16, 2021 11:37
lapce Arch Linux PKGBUILD
# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Modified: Rubens Brandao <git@rubens.io>
pkgname=lapce
pkgver=0.0.4
pkgrel=1
pkgdesc="Lightning-fast and Powerful Code Editor"
arch=('x86_64')
url="https://github.com/lapce/lapce"
license=('Apache')
depends=('gcc-libs' 'libxcb' 'expat' 'freetype2' 'libxkbcommon')
@rbran
rbran / create-my-signed-boot-cert.sh
Created December 6, 2021 17:54
My UEFI signed Kernel stub
#!/bin/bash
# Copyright (c) 2015 by Roderick W. Smith
# Licensed under the terms of the GPL v3
NAME=$(cat /etc/hostname)
if [ -z "$NAME" ]; then
echo -n "Enter a Common Name to embed in the keys: "
read NAME

Keybase proof

I hereby claim:

  • I am rbran on github.
  • I am rbran (https://keybase.io/rbran) on keybase.
  • I have a public key ASA38TR1IBL3NpGfEZMGg0LyQ3MUpTpp9WF1VJHb5cj2Swo

To claim this, I am signing this object: