diff --git a/p/core_pdd.c b/p/core_pdd.c index 48866a8..1a1bdb3 100644 --- a/p/core_pdd.c +++ b/p/core_pdd.c @@ -200,11 +200,19 @@ static void duk_jsdec(RzCore *core, const char *input) { duk_jsdec_init(ctx, &jsdec_ctx); eval_file(ctx, "require.js"); eval_file(ctx, "jsdec-duk.js"); +#ifdef USE_JSC + if (*input) { + snprintf(args, sizeof(args), "try{if(typeof jsdec_main == 'function'){jsdec_main(\"%s\".split(/\\s+/));}else{console.log('Fatal error. Cannot call jsdec_main.');}}catch(_____e){console.log(_____e.stack||_____e);}", input); + } else { + snprintf(args, sizeof(args), "try{if(typeof jsdec_main == 'function'){jsdec_main([]);}else{console.log('Fatal error. Cannot call jsdec_main.');}}catch(_____e){console.log(_____e.stack||_____e);}"); + } +#else if (*input) { snprintf(args, sizeof(args), "try{if(typeof jsdec_main == 'function'){jsdec_main(\"%s\".split(/\\s+/));}else{console.log('Fatal error. Cannot use RZ_HOME_DATADIR or JSDEC_HOME.');}}catch(_____e){console.log(_____e.stack||_____e);}", input); } else { snprintf(args, sizeof(args), "try{if(typeof jsdec_main == 'function'){jsdec_main([]);}else{console.log('Fatal error. Cannot use RZ_HOME_DATADIR or JSDEC_HOME.');}}catch(_____e){console.log(_____e.stack||_____e);}"); } +#endif duk_eval_string_noresult(ctx, args); //duk_rizin_debug_stack(ctx); duk_destroy_heap(ctx); diff --git a/p/make_jsc.py b/p/make_jsc.py index 60ee6bc..0f6d2cf 100644 --- a/p/make_jsc.py +++ b/p/make_jsc.py @@ -14,13 +14,13 @@ def main(argc, argv): print("usage: {} ".format(argv[0])) sys.exit(1) path = os.path.join(argv[1]) - path_len = len(argv[1]) + path_len = len(path) js_files = glob.glob(os.path.join(path, '**/*.js'), recursive=True) js_files.remove(os.path.join(path, 'jsdec-test.js')) for file in js_files: - vname = const_var_name(file[path_len + 1:]) + vname = const_var_name(file.replace(path, "")) code = '' count = 0 with open(file, "rb") as f: @@ -35,8 +35,10 @@ def main(argc, argv): print('\n#define RZ_JSC_SIZE ({})\n\n'.format(len(js_files))) print('const RzJSC rz_jsc_file[RZ_JSC_SIZE] = {') for file in js_files: - name = file[path_len + 1:].replace(os.sep, '/') - vname = const_var_name(file[path_len + 1:]) + name = file.replace(path, "").replace(os.sep, '/') + if name.startswith("/"): + name = name[1:] + vname = const_var_name(file.replace(path, "")) print('\t{ .name = "' + name + '", .code = (const char *)' + vname + ' },') print('};')