Skip to content

Instantly share code, notes, and snippets.

@hackcasual
Created April 22, 2016 21:06
Show Gist options
  • Save hackcasual/413277eb8f2c19c5b3e6bac0303b083c to your computer and use it in GitHub Desktop.
Save hackcasual/413277eb8f2c19c5b3e6bac0303b083c to your computer and use it in GitHub Desktop.
#include <emscripten/bind.h>
#include <stdio.h>
#include <string.h>
using namespace emscripten;
int send_ajax_request(char *url, char *message) {
printf("Calling ajax: %s %s\n", url, message);
return 0;
}
int login_handler1(char *username, char *pwd) {
printf("Logging in user (1): %s -- %s\n", username, pwd);
return 0;
}
int login_handler2(char *username, char *pwd) {
printf("Logging in user (2): %s -- %s\n", username, pwd);
return 0;
}
struct sketchy_struct {
char un[20];
char pw[20];
int (*lh)(char *a, char *b);
};
void run_handler(sketchy_struct &ss) {
(ss.lh)(ss.un, ss.pw);
}
void sketchy(int fbuffer, int login_handler) {
char *buffer = &((char *)0)[fbuffer];
sketchy_struct ss;
char topsecret[] = "This is a top secret token, hope no-one gets it";
if (login_handler == 1) {
ss.lh = login_handler1;
} else {
ss.lh = login_handler2;
}
memcpy(ss.un, buffer, strlen(buffer));
memcpy(ss.pw, buffer + strlen(ss.un) + 1, strlen(buffer + strlen(ss.un) + 1));
run_handler(ss);
}
EMSCRIPTEN_BINDINGS(my_module) {
function("sketchy", &sketchy);
function("send_ajax_request", &send_ajax_request, allow_raw_pointers());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment