Skip to content

Commit

Permalink
Fixed script bug on ../ path
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Nov 18, 2021
1 parent 6bcdd15 commit 7aa6e58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 8 additions & 0 deletions p/core_pdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions p/make_jsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def main(argc, argv):
print("usage: {} <path/to/js/files>".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:
Expand All @@ -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('};')

Expand Down

0 comments on commit 7aa6e58

Please sign in to comment.