small-c / obj.h Goto Github PK
View Code? Open in Web Editor NEW๐ OOP in pure C with a single-header
License: MIT License
๐ OOP in pure C with a single-header
License: MIT License
I'm testing win32_app with Pelles C. It failed to compile with a bunch of errors I don't understand. Perhaps you should download Pelles C and playing a bit with it.
Is it possible @nomi-san? Or obj.h can only used on plain C?
Let a method template like this:
void foo() {
volatile size_t self = 0xFFFFFFFFFFFFDEAD;
printf("self: %p\n", (void *)self);
}
// mov x0, #0xDEAD
// movk x0, #0xFFFF, lsl #16
// movk x0, #0xFFFF, lsl #32
// movk x0, #0xFFFF, lsl #48
// str x0, [sp, #24]
Finding offset:
for (offset = 0; offset < LIMIT; offset++)
if ((ip[offset] >> 24) == 0xD2) // MOV
if (ip[offset + 1] >> 24) == 0xF2) // MOVK
if (((ip[offset] >> 5) & 0xFFFF) == 0xDEAD)
// found
Patching self data:
mov ?, [data & 0xFF]
movk ?, [data >> 16], lsl #16
movk ?, [data >> 32], lsl #32
movk ?, [data >> 48], lsl #48
; str ?, [sp, ?]
Trampoline:
; addr = proto + offset + 2 * sizeof(uint32_t) // 32bit fixed length instruction
mov x9, [addr & 0xFF]
movk x9, [addr >> 16], lsl #16
movk x9, [addr >> 32], lsl #32
movk x9, [addr >> 48], lsl #48
br x9
Result:
foo2 = bind(foo, 0xdeadbeef);
foo2();
// self: deadbeef
I want to use it in emscripten
Pelles C is Windows only. Able to generate both 32 bit and 64 bit binaries. Why Pelles C? Pelles C is small and lightweight. MSVC and mingw64 are beasts, eating gigabytes of precious disk space. Oh almost forgot, this is Pelles C: http://www.smorgasbordet.com/pellesc/
in the examples, either creating one class, or more than two but with overriding parent methods ...........
your header is very easy to use with examples, but the problems encountered baffle me
hope for help
As the title says, when I compile the foo.c with gcc foo.c
, there is no problem. But when I run the program, I got below output:
Clofn: could't change memory type of C.malloc allocated!
Clofn: could't change memory type of C.malloc allocated!
Segmentation fault (core dumped)
My OS:
$ uname -a
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Oct 4 20:48:51 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
I check the error message from the source, the problem comes from __wobj_ativ_mem
function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.