Skip to content

Instantly share code, notes, and snippets.

View ALSchwalm's full-sized avatar

Adam Schwalm ALSchwalm

View GitHub Profile
num test_enum
{
A,
B,
C
};
template<test_enum T>
int f(int x);
template<typename T>
class Foo {
public:
Foo() {
++c;
}
private:
thread_local static int c;
};
@ALSchwalm
ALSchwalm / movc++
Last active February 2, 2024 01:39
Proof of concept that llvm bytecode can be used as an intermediary to compile many languages using movfuscator
# Compile c++ to llvm bytecode
clang++ -S -emit-llvm -o bytecode.ll $1
# Convert bytecode to C
llc -march=c -o code.c bytecode.ll
# 'fix' static inline. This is a workaround for a bug
# in one of the parsers, I think.
sed -i 's/static inline.*//' code.c
#include <cstdlib>
#include <iostream>
struct Mammal {
Mammal() { std::cout << "Mammal::Mammal\n"; }
virtual ~Mammal() { std::cout << "Mammal::~Mammal\n"; };
virtual void run() = 0;
virtual void walk() = 0;
virtual void move() { walk(); }
};
int main() {
Mammal *m;
if (rand() % 2) {
m = new Cat();
} else {
m = new Dog();
}
m->walk();
delete m;
#include <iostream>
#include <cstdlib>
struct Mammal {
Mammal() { std::cout << "Mammal::Mammal\n"; }
virtual ~Mammal() {}
virtual void walk() { std::cout << "Mammal::walk\n"; }
};
struct Cat : Mammal {
Bat* bat = new Bat();
Bird* b = bat;
Mammal* m = bat;
""" A simple script to locate vtable groups in binaries with the Itanium ABI.
Note that this script does not account for virtual inheritance or (more notably),
cases were the vtable contains null pointers. This may happen in more recent
compilers with purely abstract types.
"""
import idaapi
import idautils
struct CloningLab {
subjects: Vec<Box<Mammal>>,
}
trait Mammal {
fn walk(&self);
fn run(&self);
}
#[derive(Clone)]
struct CloningLab {
subjects: Vec<Box<Mammal + Clone>>,
}
impl CloningLab {
fn clone_subjects(&self) -> Vec<Box<Mammal + Clone>> {
self.subjects.clone()
}
}