Skip to content

Instantly share code, notes, and snippets.

@ashafq
Last active October 29, 2023 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashafq/fd6923d19752fc989d7b49f06b2bac3e to your computer and use it in GitHub Desktop.
Save ashafq/fd6923d19752fc989d7b49f06b2bac3e to your computer and use it in GitHub Desktop.
Enterprise C
__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