vtable.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
#include <stdio.h>
#include <stdint.h>
class A { public:
virtual void doThing() {
printf("I'm an A\n");
}
};
void dynamicOverride(A* a) {
printf("I'm an imposter!\n");
}
int main(int argc, char *argv[]) {
A* a = new A();
// grab the vtable for the A class
void** vtable = *(void***)a;
a->doThing();
// out: "I'm an A"
void (A::* ptr)() = &A::doThing;
void* offset = *(void**)&ptr;
vtable[((uintptr_t)offset)/sizeof(void*)] = (void*)&dynamicOverride;
a->doThing();
// out: "I'm an imposter!"
// affects future instances as well
A* a2 = new A();
a->doThing();
// out: "I'm an imposter!"
return 0;
}
source & further reading
gist.github.com — original article
.htaccess (mashup)
Build a beautiful TV home screen with AI — Samraaj’s prompt, camera watcher workflow, and Samsung / Android TV references
Finding and fixing asyncio event-loop stalls in a streaming gateway: a stack-capturing watchdog, per-process shared resources, and the benchmark behind the numbers.