Пример #1
0
int lua_panic_function(lua_State *state){
	std::stringstream stream;
	stream << "Lua threw an error: " << lua_tostring(state, -1);
	auto interpreter = get_interpreter(state);
	interpreter->message_box(nullptr, stream.str().c_str(), true);
	throw LuaStackUnwind();
	return 0;
}
Пример #2
0
void handle_call_to_c_error(lua_State *state, const char *function, const char *msg){
	lua_Debug debug;
	lua_getstack(state, 1, &debug);
	lua_getinfo(state, "nSl", &debug);
	int line = debug.currentline;
	std::stringstream stream;
	stream << "ERROR at line " << line << " calling function " << function << "(): " << msg;
	auto interpreter = get_interpreter(state);
	interpreter->message_box("Error executing Lua script.", stream.str().c_str(), true);
}
Пример #3
0
parse_errors_e fnc_unconditional_branching::execute_gotoline()
{
  static const int PAR_LINENO = 1;

  interpreter_t *_int = get_interpreter();

  long lineno = compel_string_tokenizer_t::parse_number(_int->evaluate_at(PAR_LINENO));
  
  if (lineno > 0)
    lineno--;
  else
    return parse_stop_parsing;

  _int->set_cur_src_line(lineno);

  return parse_branch_to;
}
Пример #4
0
parse_errors_e fnc_unconditional_branching::execute_goto()
{
  interpreter_t *_int = get_interpreter();

  const char *labelname = _int->get_const_at(1);

  if (!_int->is_variable_name(labelname))
    return parse_error_variable_expected;

  // check if label already defined
  // if not so, then error!
  value_t *val = _int->get_value_at(1);
  if (val == 0)
    return parse_error_symbol_not_in_table;

  _int->set_cur_src_line(val->get_int_value());

  return parse_branch_to;
}
Пример #5
0
parse_errors_e fnc_binary_arith::execute_expr()
{
  interpreter_t *_int = get_interpreter();

  value_t *var_dest = _int->get_value_at(1);

  if (var_dest == 0)
    return parse_error_symbol_not_in_table;

  long r;
  std::string expr;
  function_helper::eval_from_to(_int, 2, _int->get_fnc_arg_count(), expr, false, 0);

  if (ExpressionEvaluator::calculateLong(expr, r) != ExpressionEvaluator::eval_ok)
    return parse_error_wrong_syntax;

  var_dest->set_int_value(r);

  return parse_error_none;
}
Пример #6
0
parse_errors_e fnc_unconditional_branching::prepare(size_t passno, int &start_or_failing_line)
{
  if (passno != cc_nbpasses)
    return parse_error_none;

  interpreter_t *_int = get_interpreter();

  interpreter_helper_t inthlp(_int);

  lines_container_type_t &lines = inthlp.get_interpreter_lines().get_string_list();

  compel_string_tokenizer_t slp;

	lines_container_type_t::iterator it = lines.begin();
  size_t lineno = start_or_failing_line;

	std::advance(it, lineno);

	for (;
      it != lines.end();++it, lineno++)
  {
    std::string &line = *it;
    size_t pcount = slp.parse(line.c_str());
    if (pcount <= 1)
      continue;

    if (stricmp(slp.get_string(0), s_cmd_label) != 0)
      continue;

    parse_errors_e err = _int->interpreter_line_at(lineno);

    if (err != parse_error_none)
    {
      start_or_failing_line = (int) lineno;
      return err;
    }
  }

  return parse_error_none;
}
Пример #7
0
parse_errors_e fnc_com::execute_free()
{
  static const int PAR_OBJ = 1;

  interpreter_t *_int = get_interpreter();

  // Is it a variable name?
  const char *objname = _int->get_const_at(PAR_OBJ);
  if (!_int->is_variable_name(objname))
    return parse_error_variable_expected;

  // Does the object exist?
  com_object_t *obj = dynamic_cast<com_object_t *>(_int->find_symbol(objname));
  if (obj == 0)
  {
    return parse_error_symbol_type_mismatch;
  }

  _int->remove_symbol(objname);

  return parse_error_none;
}
Пример #8
0
parse_errors_e fnc_com::execute_create()
{
  static const int PAR_OBJ    = 1;
  static const int PAR_PROGID = 2;
  static const int PAR_CLSCTX = 3;

  interpreter_t *_int = get_interpreter();

  // Is it a variable name?
  const char *objname = _int->get_const_at(PAR_OBJ);
  if (!_int->is_variable_name(objname))
    return parse_error_variable_expected;

  // Does the object exist?
  object_t *obj = dynamic_cast<object_t *>(_int->find_symbol(objname));
  if (obj == 0)
  {
    obj = new com_object_t;
    _int->add_symbol(objname, obj);
  }
  // Correct object kind?
  else if (obj->get_obj_kind() != object_com)
  {
    return parse_error_symbol_type_mismatch;
  }

  // Get COM OBJECT
  com_object_t *comobj = dynamic_cast<com_object_t *>(obj);

  if (_int->get_fnc_arg_count() > PAR_CLSCTX)
  {
    comobj->_attr_clsctx->set_str_value(_int->evaluate_at(PAR_CLSCTX));
  }

  comobj->create((char *)_int->evaluate_at(PAR_PROGID));

  return parse_error_none;
}
Пример #9
0
parse_errors_e fnc_binary_arith::execute()
{
  if (_op == ba_expr)
    return execute_expr();

  interpreter_t *_int = get_interpreter();

  value_t *var_dest = _int->get_value_at(1);
  if (var_dest == 0)
    return parse_error_symbol_not_in_table;

  long n_src = compel_string_tokenizer_t::parse_number(_int->evaluate_at(2));
  long n_dest = var_dest->get_int_value();

  long result;

  switch (_op)
  {
  case ba_sub:
    result = n_dest - n_src;
    break;
  case ba_mul:
    result = n_dest * n_src;
    break;
  case ba_div:
    if (n_dest == 0)
      return parse_error_divide_by_zero_detected;
    result = n_src / n_dest;
  case ba_add:
    result = n_src + n_dest;
    break;
  }

  var_dest->set_int_value(result);

  return parse_error_none;
}
Пример #10
0
PyObject *install(PyObject *s, PyObject *arg) {
    Tcl_Interp *trp = get_interpreter(arg);
    if(!trp) {
        PyErr_SetString(PyExc_TypeError, "get_interpreter() returned NULL");
        return NULL;
    }
    if (Tcl_InitStubs(trp, "8.1", 0) == NULL) 
    {
        PyErr_SetString(PyExc_RuntimeError, "Tcl_InitStubs returned NULL");
        return NULL;
    }
    if (Tk_InitStubs(trp, "8.1", 0) == NULL) 
    {
        PyErr_SetString(PyExc_RuntimeError, "Tk_InitStubs returned NULL");
        return NULL;
    }
    if (Tcl_PkgPresent(trp, "Togl", TOGL_VERSION, 0)) {
        Py_INCREF(Py_None);
        return Py_None;
    }
    if (Tcl_PkgProvide(trp, "Togl", TOGL_VERSION) != TCL_OK) {
        PyErr_Format(PyExc_RuntimeError, "Tcl_PkgProvide failed: %s", Tcl_GetStringResult(trp));
        return NULL;
    }

    Tcl_CreateCommand(trp, "togl", (Tcl_CmdProc *)Togl_Cmd,
                      (ClientData) Tk_MainWindow(trp), NULL);

    if(first_time) {
        Tcl_InitHashTable(&CommandTable, TCL_STRING_KEYS);
        first_time = 0;
    }

    Py_INCREF(Py_None);
    return Py_None;
}
Пример #11
0
parse_errors_e fnc_unconditional_branching::execute_label()
{
  interpreter_t *_int = get_interpreter();

  const char *labelname = _int->get_const_at(1);

  if (!_int->is_variable_name(labelname))
    return parse_error_variable_expected;

  size_t curlineno = _int->get_cur_source_lineno();

  if (_int->is_deferred_line())
  {
    int deferredline = _int->find_deferred_line();
    if (deferredline != -1)
    {
      parse_errors_e err = _int->interpreter_line_at(deferredline);
      _int->void_line(curlineno);
      return err;
    }
  }

  // check if label already defined
  // set mark label starting at next line
  // ;! beware: setting a label at the end of file!
  // ;! beware: if someone branches to a location above the label definition
  value_t *newval = new value_t((long)curlineno+1);
  symbol_t *sym = _int->add_symbol(labelname, newval);
  if (sym == 0)
  {
    delete newval;
    return parse_error_symbol_redefinition;
  }
  _int->void_line(curlineno);
  return parse_error_none;
}
Пример #12
0
/**
   This function is executed by the child process created by a call to
   fork(). It should be called after \c setup_child_process. It calls
   execve to replace the fish process image with the command specified
   in \c p. It never returns.
*/
static void launch_process( process_t *p )
{
    FILE* f;
	int err;
	
//	debug( 1, L"exec '%ls'", p->argv[0] );

	char **argv = wcsv2strv( (const wchar_t **) p->argv);
	char **envv = env_export_arr( 0 );
	
	execve ( wcs2str(p->actual_cmd), 
		 argv,
		 envv );
	
	err = errno;
	
	/* 
	   Something went wrong with execve, check for a ":", and run
	   /bin/sh if encountered. This is a weird predecessor to the shebang
	   that is still sometimes used since it is supported on Windows.
	*/
	f = wfopen(p->actual_cmd, "r");
	if( f )
	{
		char begin[1] = {0};
		size_t read;
		
		read = fread(begin, 1, 1, f);
		fclose( f );
		
		if( (read==1) && (begin[0] == ':') )
		{
			int count = 0;
			int i = 1;
			wchar_t **res;
            char **res_real;
			
			while( p->argv[count] != 0 )
				count++;
			
			res = malloc( sizeof(wchar_t*)*(count+2));
			
			res[0] = L"/bin/sh";
			res[1] = p->actual_cmd;
			
			for( i=1;  p->argv[i]; i++ ){
				res[i+1] = p->argv[i];
			}
			
			res[i+1] = 0;
			p->argv = res;
			p->actual_cmd = L"/bin/sh";

			res_real = wcsv2strv( (const wchar_t **) res);
			
			execve ( wcs2str(p->actual_cmd), 
				 res_real,
				 envv );
		}
	}
	
	errno = err;
	debug( 0, 
	       _( L"Failed to execute process '%ls'. Reason:" ),
	       p->actual_cmd );
	
	switch( errno )
	{
		
		case E2BIG:
		{
			size_t sz = 0;
			char **p;

			string_buffer_t sz1;
			string_buffer_t sz2;
			
			long arg_max = -1;
						
			sb_init( &sz1 );
			sb_init( &sz2 );
						
			for(p=argv; *p; p++)
			{
				sz += strlen(*p)+1;
			}
			
			for(p=envv; *p; p++)
			{
				sz += strlen(*p)+1;
			}
			
			sb_format_size( &sz1, sz );

			arg_max = sysconf( _SC_ARG_MAX );
			
			if( arg_max > 0 )
			{
				
				sb_format_size( &sz2, arg_max );
				
				debug( 0,
				       L"The total size of the argument and environment lists (%ls) exceeds the operating system limit of %ls.",
				       (wchar_t *)sz1.buff,
				       (wchar_t *)sz2.buff);
			}
			else
			{
				debug( 0,
				       L"The total size of the argument and environment lists (%ls) exceeds the operating system limit.",
				       (wchar_t *)sz1.buff);
			}
			
			debug( 0, 
			       L"Try running the command again with fewer arguments.");
			sb_destroy( &sz1 );
			sb_destroy( &sz2 );
			
			exit(STATUS_EXEC_FAIL);
			
			break;
		}

		case ENOEXEC:
		{
			wperror(L"exec");
			
			debug(0, L"The file '%ls' is marked as an executable but could not be run by the operating system.", p->actual_cmd);
			exit(STATUS_EXEC_FAIL);
		}

		case ENOENT:
		{
			wchar_t *interpreter = get_interpreter( p->actual_cmd );
			
			if( interpreter && waccess( interpreter, X_OK ) )
			{
				debug(0, L"The file '%ls' specified the interpreter '%ls', which is not an executable command.", p->actual_cmd, interpreter );
			}
			else
			{
				debug(0, L"The file '%ls' or a script or ELF interpreter does not exist, or a shared library needed for file or interpreter cannot be found.", p->actual_cmd);
			}
			
			exit(STATUS_EXEC_FAIL);
		}

		case ENOMEM:
		{
			debug(0, L"Out of memory");
			exit(STATUS_EXEC_FAIL);
		}

		default:
		{
			wperror(L"exec");
			
			//		debug(0, L"The file '%ls' is marked as an executable but could not be run by the operating system.", p->actual_cmd);
			exit(STATUS_EXEC_FAIL);
		}
	}
	
}
Пример #13
0
static int
interpret_extensions(uchar_t *ext,
			int regext_size,
			enum EXT_TYPE etype) {

	int curr_size  =  regext_size; /* remaining total for all exts */
	exthdr_t *exthdr;
	gen_exthdr_t *gen_exthdr;
	const char *st;
	uchar_t	*p;
	interpreter_f *f;
	uint8_t	ext_type;
	uint16_t ext_len;
	uint_t ext_hdrlen;

	show_space();
	exthdr = (exthdr_t *)ALIGN(ext);


	do {
	    ext_type = exthdr->type;
	    if (ext_type == GEN_AUTH) {
		gen_exthdr = (gen_exthdr_t *)exthdr;
		ext_hdrlen = sizeof (gen_exthdr_t);
		ext_len = ntohs(gen_exthdr->length);
	    } else {
		ext_hdrlen = sizeof (exthdr_t);
		ext_len = exthdr->length;
	    }

	    if (!((etype == ADV && ext_type == ICMP_ADV_MSG_PADDING_EXT &&
		curr_size >= 1) ||
		curr_size >= ext_hdrlen + ext_len))
		    break;

	    /* Print description for this extension */
	    if (etype == ADV) {
		st = get_desc(adv_desc, ext_type, ADV_TBL_LEN);
	    } else /* REG */ {
		st = get_desc(reg_desc, ext_type, REG_TBL_LEN);
	    }

	    (void) sprintf(get_line((char *)exthdr-dlc_header, 1),
			"Extension header type = %d  %s", ext_type, st);

	    if (ext_type == GEN_AUTH) {
		st = get_desc(genauth_desc, gen_exthdr->subtype,
		    GENAUTH_TBL_LEN);
		(void) sprintf(get_line((char *)exthdr-dlc_header, 1),
		    "Subtype = %d %s", gen_exthdr->subtype, st);
	    }

	    /* Special case for 1-byte padding */
	    if (etype == ADV && ext_type == ICMP_ADV_MSG_PADDING_EXT) {
		exthdr = (exthdr_t *)((uchar_t *)exthdr + 1);
		curr_size--;
		continue;
	    }

	    (void) sprintf(get_line((char *)&exthdr->length-dlc_header, 1),
			"Length = %d", ext_len);

	    /* Parse out the extension's payload */
	    p = (uchar_t *)exthdr + ext_hdrlen;
	    curr_size -= (ext_hdrlen + ext_len);

	    if (etype == ADV) {
		f = get_interpreter(adv_dispatch, ext_type, ADV_TBL_LEN);
	    } else /* REG */ {
		f = get_interpreter(reg_dispatch, ext_type, REG_TBL_LEN);
	    }

	    f(ext_type, ext_len, p);

	    show_space();
	    exthdr = (exthdr_t *)(p + ext_len);
	} while (B_TRUE);

	return (0);
}
Пример #14
0
void safe_report_exec_error(int err, const char *actual_cmd, const char *const *argv,
                            const char *const *envv) {
    debug_safe(0, "Failed to execute process '%s'. Reason:", actual_cmd);

    switch (err) {
        case E2BIG: {
            char sz1[128], sz2[128];

            long arg_max = -1;

            size_t sz = 0;
            const char *const *p;
            for (p = argv; *p; p++) {
                sz += strlen(*p) + 1;
            }

            for (p = envv; *p; p++) {
                sz += strlen(*p) + 1;
            }

            format_size_safe(sz1, sz);
            arg_max = sysconf(_SC_ARG_MAX);

            if (arg_max > 0) {
                format_size_safe(sz2, static_cast<unsigned long long>(arg_max));
                debug_safe(0,
                           "The total size of the argument and environment lists %s exceeds the "
                           "operating system limit of %s.",
                           sz1, sz2);
            } else {
                debug_safe(0,
                           "The total size of the argument and environment lists (%s) exceeds the "
                           "operating system limit.",
                           sz1);
            }

            debug_safe(0, "Try running the command again with fewer arguments.");
            break;
        }

        case ENOEXEC: {
            const char *err = safe_strerror(errno);
            debug_safe(0, "exec: %s", err);

            debug_safe(0,
                       "The file '%s' is marked as an executable but could not be run by the "
                       "operating system.",
                       actual_cmd);
            break;
        }

        case ENOENT: {
            // ENOENT is returned by exec() when the path fails, but also returned by posix_spawn if
            // an open file action fails. These cases appear to be impossible to distinguish. We
            // address this by not using posix_spawn for file redirections, so all the ENOENTs we
            // find must be errors from exec().
            char interpreter_buff[128] = {}, *interpreter;
            interpreter = get_interpreter(actual_cmd, interpreter_buff, sizeof interpreter_buff);
            if (interpreter && 0 != access(interpreter, X_OK)) {
                debug_safe(0,
                           "The file '%s' specified the interpreter '%s', which is not an "
                           "executable command.",
                           actual_cmd, interpreter);
            } else {
                debug_safe(0, "The file '%s' does not exist or could not be executed.", actual_cmd);
            }
            break;
        }

        case ENOMEM: {
            debug_safe(0, "Out of memory");
            break;
        }

        default: {
            const char *err = safe_strerror(errno);
            debug_safe(0, "exec: %s", err);

            // debug(0, L"The file '%ls' is marked as an executable but could not be run by the
            // operating system.", p->actual_cmd);
            break;
        }
    }
}
Пример #15
0
parse_errors_e fnc_binary_comparison::execute()
{
  static const int PAR_OPR1 = 1;
  static const int PAR_OPR2 = 2;
  static const int PAR_ACTION = 3;

  interpreter_t *_int = get_interpreter();

  const char *symname = _int->get_const_at(PAR_ACTION);

  bool bBranch;

  bBranch = do_comparison(_int, _op, PAR_OPR1, PAR_OPR2);

  if (!bBranch)
    return parse_error_none;

  // Label?
  if (_int->is_variable_name(symname))
  {
    // check if label already defined, if not so then error!
    value_t *val = _int->get_value_at(PAR_ACTION);
    if (val == 0)
      return parse_error_symbol_not_in_table;

    if (bBranch)
    {
      // branch!
      _int->set_cur_src_line(val->get_int_value());
      return parse_branch_to;
    }
  }

  if (function_t *fnc = _int->get_function(symname))
  {
    // we need a helper
    interpreter_helper_t helper(_int);

    // save old tokenizer
    compel_string_tokenizer_t *old_tokenizer = helper.get_tokenizer();

    // create new tokenizer for the action passed to the if_xx
    compel_string_tokenizer_t new_tokenizer;

    // get the action
    const char *action_str = old_tokenizer->join_from(PAR_ACTION);

    // parse the action
    new_tokenizer.parse(action_str);

    // set new tokenizer (temp)
    helper.set_tokenizer(&new_tokenizer);

    // execute the function
    parse_errors_e err = fnc->execute();

    // restore old tokenizer
    helper.set_tokenizer(old_tokenizer);

    return err;
  }
  else
    return parse_error_function_expected;

  // do not branch, execute next line
  return parse_error_none;
}