Skip to content

Instantly share code, notes, and snippets.

View novafacing's full-sized avatar
dilly dally shilly shally

Rowan Hart novafacing

dilly dally shilly shally
View GitHub Profile
@novafacing
novafacing / dump-riscv-firmware.c
Created August 28, 2024 05:54
Demo QEMU plugin that dumps the first 256 bytes of firmware when booting a BIOS on RISC-V
/*
* Copyright (C) 2018, Emilio G. Cota <cota@braap.org>
*
* License: GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#include <inttypes.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

Using autounattend.xml in 2024 to create a customized VirtualBox image with SSH

<?xml version="1.0" encoding="utf-8"?>
<unattend
	xmlns="urn:schemas-microsoft-com:unattend"
	xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
	<!--https://schneegans.de/windows/unattend-generator/?LanguageMode=Unattended&UILanguage=en-US&Locale=en-US&Keyboard=00000409&GeoLocation=244&ProcessorArchitecture=amd64&BypassRequirementsCheck=true&ComputerNameMode=Custom&ComputerName=test&TimeZoneMode=Implicit&PartitionMode=Unattended&EspSize=300&PartitionLayout=MBR&RecoveryMode=Partition&RecoverySize=1000&WindowsEditionMode=Unattended&WindowsEdition=pro&UserAccountMode=Unattended&AccountName0=user&AccountPassword0=password&AccountGroup0=Administrators&AccountName1=&AccountName2=&AccountName3=&AccountName4=&AutoLogonMode=Own&PasswordExpirationMode=Unlimited&LockoutMode=Disabled&DisableDefender=true&DisableDefenderPE=true&DisableSystemRestore=true&EnableLongPaths=true&EnableRemoteDesktop=true&AllowPowerShellScripts
#[macro_export]
// https://stackoverflow.com/a/70222282
macro_rules! field_size {
($t:ident :: $field:ident) => {{
let m = core::mem::MaybeUninit::<$t>::uninit();
// According to https://doc.rust-lang.org/stable/std/ptr/macro.addr_of_mut.html#examples,
// you can dereference an uninitialized MaybeUninit pointer in addr_of!
// Raw pointer deref in const contexts is stabilized in 1.58:
// https://github.com/rust-lang/rust/pull/89551
let p = unsafe { core::ptr::addr_of!((*(&m as *const _ as *const $t)).$field) };
@novafacing
novafacing / parse_macro.rs
Last active July 9, 2024 06:43
Declarative macro to parse an enum item completely including generic parameters, where clauses and bounds, and attributes.
macro_rules! parse_enum_variant {
{
$(#[$enum_meta:meta])*,
$vis:vis,
$name:ident,
$(<$($generic_param:tt),*>)?,
@where_clauses {$($where:tt)*},
@parse {$($eout:tt)*},
#[$variant_meta:meta]
$($rest:tt)*
@novafacing
novafacing / ago-downloader.js
Last active November 28, 2023 19:51
ago-downloader.js
const puppeteer = require("puppeteer");
const child_process = require("child_process");
const fs = require("fs");
async function sh(cmd) {
return new Promise(function (resolve, reject) {
child_process.exec(cmd, (err, stdout, stderr) => {
if (err) {
resolve(err);
} else {
@novafacing
novafacing / BUILDING_FEDORA_LINUX_KERNEL_WITH_RUST_SUPPORT.md
Last active December 12, 2023 17:28
Building the Fedora Linux Kernel with Rust Support!

Building the Fedora Linux Kernel with Rust Support

I've been using Fedora Linux for a couple years now, and this week I wanted to write a kernel module for some reasons. Of course, I try to write all software I possibly can in Rust, and Linux recently has support for writing modules, including out of tree modules, in Rust! Great, so it should be really easy, just copy the rust-out-of-tree-module Makefile and Kbuild, run make, and

@novafacing
novafacing / NOTES_ON_OOT_KMOD_WITH_BUILDROOT.md
Created November 1, 2023 18:30
Some Notes On Building Out-Of-Tree Kernel Modules With Buildroot

Note 1

Your Config.in file...it needs to have a newline after endmenu, if you have menu. So basically:

menu "Kernel Modules"
    source "$BR2_EXTERNAL_TEST_KERNEL_MODULES_PATH/package/kernel-modules/test-mod/Config.in"
endmenu
@novafacing
novafacing / RUST_OPTION_RESULT_CONVERSIONS.md
Created October 17, 2023 23:13
Rust Option/Result conversion functions

I used to have a site bookmarked with a table of all these functions, but the link is dead. Here's a matrix of Option and Result conversion functions. These become second nature once you have used Rust for any significant length of time, but it's useful to have a table reference.

For each of the below:

  • T is the value possibly contained in an input Ok Result or Some Option.
  • U is a new value created by transforming or replacing an input T. Note that when U appears in methods like map, U ?= T, for example by calling
@novafacing
novafacing / RUST_LIBRARY_NAMING.md
Last active August 31, 2023 00:31
Rust's Expected/Produced Library naming

Rust's expected/produced library naming

What rustc/your linker expects

Rust handles libraries that it links with in a somewhat "magical" way, in that if you want to link to libpixman-1.so.0 you would just write:

println!("cargo:rustc-link-lib=pixman-1");
@novafacing
novafacing / RPATH_VS_RUNPATH.md
Last active August 29, 2023 23:04
RPATH vs RUNPATH in readelf

RPATH vs RUNPATH

I'm doing some ELF parsing and I need to simulate ld.so's lookup routine (man ld.so). To do that, I need to grab RPATH as well as RUNPATH from binaries, so to test my tool I naturally need to make some binaries with each of those. Here's how you do it.

cat <<EOF > /tmp/a.c
int main(){}
EOF