Last active
October 29, 2023 17:54
-
-
Save ashafq/fd6923d19752fc989d7b49f06b2bac3e to your computer and use it in GitHub Desktop.
Enterprise C
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
__attribute__((section(".text"))) | |
const char fun_impl[] = | |
"\x8eGlsbVdoZEV3cGw=" | |
"R2xhZEkgQ2FuIEg=" | |
"\x8d\x04\x37\xc3" | |
"ZWxwIHlvdSBvdXQ=" | |
"VGhpcyBpcyBBU0N=" | |
"SUkgQXJ0ISAgICA="; | |
typedef int (*fun_t)(int, int); | |
enum fun_factory_id { | |
ADD_FUNCTION = 0, | |
NOT_IMPLEMENTED, | |
INVALID = -1, | |
}; | |
fun_t fun_factory(int x, int license_key) { | |
switch (x) { | |
case ADD_FUNCTION: | |
unsigned offset = fun_impl[ADD_FUNCTION] ^ license_key; | |
return (fun_t)(fun_impl + offset); | |
default: | |
break; | |
} | |
fun_factory(INVALID, license_key); | |
} | |
#define OUR_LICENSE_KEY (0xAE) | |
int main() { | |
fun_t add_fun = fun_factory(ADD_FUNCTION, OUR_LICENSE_KEY); | |
return add_fun(40, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment