Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int __cdecl main(int argc, char** argv)
- {
- if (argc < 2) {
- printf("Usage: %s <input file>\n", argv[0]);
- return 0;
- }
- FILE * file;
- JsRuntimeHandle runtime;
- JsContextRef context;
- JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &runtime);
- JsCreateContext(runtime, &context);
- JsSetCurrentContext(context);
- JsValueRef WebAssembly, funcPropId, global, undefined, result;
- JsGetGlobalObject(&global);
- JsGetUndefinedValue(&undefined);
- const char* funcString = "WebAssembly";
- JsCreatePropertyId(funcString, strlen(funcString), &funcPropId);
- JsGetProperty(global, funcPropId, &WebAssembly);
- JsErrorCode errcode;
- JsValueRef compilefunc, compilefuncPropId;
- const char* compilefuncString = "compile";
- errcode = JsCreatePropertyId(compilefuncString, strlen(compilefuncString), &compilefuncPropId);
- errcode = JsGetProperty(WebAssembly, compilefuncPropId, &compilefunc);
- JsValueRef ArrayBuffer;
- BYTE* ArrayBufferpointer=NULL;
- unsigned int ArrayBufferLen;
- file=fopen(argv[1], "rb");
- if(file==NULL)
- {
- return 0;
- }
- char *fileContent;
- LoadBinaryFile(file, fileContent, ArrayBufferLen);
- if(fileContent && ArrayBufferLen>10)
- {
- fileContent[0]=0x00;
- fileContent[0]=0x61;
- fileContent[0]=0x73;
- fileContent[0]=0x6d;
- }
- /* FILE* wfile;
- char name[100] = { 0 };
- milliseconds ms = duration_cast< milliseconds >(
- system_clock::now().time_since_epoch()
- );*/
- /* sprintf_s(name, "array%lld.wasm", ms.count());
- fopen_s(&wfile,name, "wb");
- fwrite(fileContent, sizeof(char), ArrayBufferLen, wfile);
- fclose(wfile);*/
- JsCreateExternalArrayBuffer(fileContent,ArrayBufferLen,NULL,NULL,&ArrayBuffer);
- JsValueRef args[] = { undefined,ArrayBuffer };
- errcode = JsCallFunction(compilefunc, args, 2, &result);
- fclose(file);
- if (fileContent)
- {
- free(fileContent);
- fileContent = nullptr;
- }
- JsSetCurrentContext(JS_INVALID_REFERENCE);
- JsDisposeRuntime(runtime);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement