Skip to content

Instantly share code, notes, and snippets.

#![allow(non_snake_case)]
use std::path::Path;
use std::cell::Cell;
use std::ffi::c_void;
use std::sync::atomic::{AtomicU32, Ordering};
use bindings::Windows::Win32::{
Foundation::{HWND, LPARAM, PWSTR, WPARAM, E_UNEXPECTED, E_NOTIMPL},
Media::{Audio::CoreAudio::GUID_NULL, MediaFoundation::*},
System::LibraryLoader::GetModuleHandleW,
@Plecra
Plecra / concvec.rs
Created April 7, 2021 11:41
Rust Concurrent Monotonic list
use core::ptr;
use core::sync::atomic::{fence, AtomicPtr, AtomicUsize, Ordering};
use std::alloc;
#[cfg(not(target_pointer_width = "32"))]
const DIVISIONS: usize = 24;
#[cfg(target_pointer_width = "32")]
const DIVISIONS: usize = 12;
struct MonotonicVec<T> {
@Plecra
Plecra / Cargo.toml
Created November 16, 2020 14:24
Logging demo
[package]
name = "keylogger"
version = "0.1.0"
authors = ["..."]
edition = "2018"
[dependencies]
winit = { version = "0.23.0", features = ["serde"] }
chrono = { version = "0.4.19", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
@Plecra
Plecra / modified-utf-8.rs
Last active June 14, 2020 13:24
A Rust Modified Utf-8 decoder
pub enum ModifiedUtf8Error {
Incomplete,
Malformed,
}
/// Decode a Modified UTF-8 encoded string.
///
/// This encoding is used by Java for fast serialization of its strings, and
/// has some minor deviations from standard UTF-8.
pub fn from_modified_utf8(mut bytes: &[u8]) -> Result<String, ModifiedUtf8Error> {
@Plecra
Plecra / leb128.rs
Created June 1, 2020 20:48
LEB128 VarInt decoding
const HIGH_BIT: u8 = 0b10000000;
fn hi_bit_set(byte: u8) -> bool {
byte & HIGH_BIT != 0
}
pub fn naive(buf: &mut &[u8]) -> Result<u64, ()> {
let mut value = 0;
let mut iter = buf.iter();
for (count, &byte) in (&mut iter).enumerate().take(10) {
value += u64::from(byte & !HIGH_BIT) << (count * 7);
@Plecra
Plecra / nom_complete.rs
Created May 9, 2020 21:37
Annotate your nom inputs to use complete parsers
use error::*;
use nom::*;
#[derive(Debug, Clone)]
struct Complete<T>(T);
impl<T> Complete<T> {
fn into_inner(self) -> T {
self.0
}
}
@Plecra
Plecra / proxy.rs
Created May 3, 2020 17:00
A smol proxy server
use anyhow::*;
use futures::io::{copy, AsyncReadExt, AsyncWriteExt};
use futures::stream::StreamExt;
use log::*;
use smol::Async;
use std::net;
const PORT: u16 = 5000;
@Plecra
Plecra / xinput_audio.cpp
Created April 21, 2020 17:20
Adventures into the cursed land of c++ #NaN.
#include <iostream>
#include <Windows.h>
#include <Xinput.h>
#pragma comment (lib, "xinput.lib")
int main()
{
std::cout << "Hello World!\n";

Keybase proof

I hereby claim:

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

To claim this, I am signing this object: