Esempio n. 1
0
bool CFileGroups::AddFile(HWND hwndTVCtrl, HTREEITEM hGroup, const char *filepath) {
	_ASSERTE(hGroup != NULL);
	_ASSERTE(filepath != 0);
	_ASSERTE(qfileexist(filepath));
	if (hGroup == NULL || filepath == 0 || !qfileexist(filepath)) return false;
	for (HTREEITEM hChild = TreeView_GetChild(hwndTVCtrl, hGroup);
		hChild != NULL; hChild = TreeView_GetNextSibling(hwndTVCtrl, hChild)) {
		char text[MAX_PATH];
		TVITEMEX tvi;
		tvi.mask = TVIF_HANDLE | TVIF_TEXT;
		tvi.hItem = hGroup;
		tvi.pszText = text;
		tvi.cchTextMax = sizeof text;
		if (TreeView_GetItem(hwndTVCtrl, &tvi)) {
			if (_stricmp(filepath, text) == 0) return false; // no dupes!
		}
#ifdef _DEBUG
		else
			_RPTF4(_CRT_ERROR, "%s(%08X, ..., \"%s\"): TreeView_GetItem(%08X, ...) returned NULL",
				__FUNCTION__, hwndTVCtrl, filepath, hwndTVCtrl);
#endif // _DEBUG
	}
	TVINSERTSTRUCT tvis;
	tvis.hParent = hGroup;
	tvis.hInsertAfter = TVI_SORT;
	tvis.itemex.mask = TVIF_TEXT;
	tvis.itemex.pszText = const_cast<LPTSTR>(filepath);
	const HTREEITEM hti(TreeView_InsertItem(hwndTVCtrl, &tvis));
	_ASSERTE(hti != NULL);
	return hti != NULL;
}
Esempio n. 2
0
//------------------------------------------------------------------------
static bool py_load_and_run_plugin(const char *name, size_t arg)
{
  if ( qfileexist(name) )
    prepare_programmatic_plugin_load(name);
  bool rc = load_and_run_plugin(name, arg);
  prepare_programmatic_plugin_load(NULL);
  return rc;
}
Esempio n. 3
0
/*
#<pydoc>
def load_plugin(name):
    """
    Loads a plugin
    @return:
        - None if plugin could not be loaded
        - An opaque object representing the loaded plugin
    """
    pass
#</pydoc>
*/
static PyObject *py_load_plugin(const char *name)
{
  if ( qfileexist(name) )
    prepare_programmatic_plugin_load(name);
  plugin_t *r = load_plugin(name);
  PYW_GIL_CHECK_LOCKED_SCOPE();
  prepare_programmatic_plugin_load(NULL);
  if ( r == NULL )
    Py_RETURN_NONE;
  else
    return PyCObject_FromVoidPtr(r, NULL);
}
Esempio n. 4
0
//--------------------------------------------------------------------------
// ipath==input file path
static bool ask_user_and_copy(const char *ipath)
{
  // check if the input file exists at the current dir of the remote host
  const char *input_file = ipath;
#if DEBUGGER_ID != DEBUGGER_ID_ARM_EPOC_USER
  input_file = qbasename(input_file);
#endif
  int fn = -1;
  // try to open remote file in the current dir if not tried before
  if ( input_file != ipath )
    fn = s_open_file(input_file, NULL, true);
  if ( fn != -1 )
  {
    s_close_file(fn);
    switch ( askbuttons_c("~U~se found",
                          "~C~opy new",
                          "Cancel",
                          1,
                          "IDA could not find the remote file %s.\n"
                          "But it could find remote file %s.\n"
                          "Do you want to use the found file?",
                          ipath, input_file) )
    {
      case 1:
        set_root_filename(input_file);
        return true;
      case -1:
        return false;
    }
    // the user wants to overwrite the old file
  }
  else
  {
    if ( askyn_c(1, "HIDECANCEL\n"
                    "The remote file %s could not be found.\n"
                    "Do you want IDA to copy the executable to the remote computer?",
                    ipath) <= 0 )
      return false;
  }

  // We are to copy the input file to the remote computer's current directory
  const char *lname = ipath;
  // check if the file path is valid on the local system
  if ( !qfileexist(lname) )
  {
    lname = askfile_c(false, lname, "Please select the file to copy");
    if ( lname == NULL )
      return false;
  }
#if DEBUGGER_ID == DEBUGGER_ID_ARM_EPOC_USER
  const char *rname = input_file;
#else
  const char *rname = qbasename(lname);
#endif
  int code = copy_to_remote(lname, rname);
  if ( code != 0 )
  {
#if DEBUGGER_ID == DEBUGGER_ID_ARM_WINCE_USER
    // Windows CE does not have errno and uses GetLastError()
    const char *err = winerr(code);
#else
    const char *err = qerrstr(code);
#endif
    warning("Failed to copy %s -> %s\n%s", lname, rname, err);
  }
  set_root_filename(rname);
  return true;
}
Esempio n. 5
0
int idaapi maclnx_launch_process(
        debmod_t *debmod,
        const char *path,
        const char *args,
        const char *startdir,
        int flags,
        const char *input_path,
        uint32 input_file_crc32,
        void **child_pid)
{
  // immediately switch to the startdir because path/input_path may be relative.
  if ( startdir[0] != '\0' && chdir(startdir) == -1 )
  {
    debmod->dmsg("chdir '%s': %s\n", startdir, winerr(errno));
    return -2;
  }

  // input file specified in the database does not exist
  if ( input_path[0] != '\0' && !qfileexist(input_path) )
    return -2;

  // temporary thing, later we will retrieve the real file name
  // based on the process id
  debmod->input_file_path = input_path;
  debmod->is_dll = (flags & DBG_PROC_IS_DLL) != 0;

  // Parse the program path and extract in/out redirection info
  qstring wpath, redir_in, redir_out;
  bool append_out;
  if ( parse_apppath(path, &wpath, &redir_in, &redir_out, &append_out) )
    path = wpath.c_str();

  if ( !qfileexist(path) )
  {
    debmod->dmsg("%s: %s\n", path, winerr(errno));
    return -1;
  }

  int mismatch = 0;
  if ( !debmod->check_input_file_crc32(input_file_crc32) )
    mismatch = CRC32_MISMATCH;

  launch_process_params_t lpi;
  lpi.cb = sizeof(lpi);

  // Input redir?
  if ( !redir_in.empty() )
  {
    lpi.in_handle = open(redir_in.c_str(), O_RDONLY);
    if ( lpi.in_handle == -1 )
    {
      debmod->dmsg("Failed to open input redirection file '%s': %s\n", redir_in.c_str(), winerr(errno));
      return -1;
    }
  }

  // Output redir?
  if ( !redir_out.empty() )
  {
    lpi.out_handle = open(
      redir_out.c_str(),
      O_CREAT | O_WRONLY | (append_out ? O_APPEND : 0),
      S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    if ( lpi.out_handle == -1 )
    {
      if ( lpi.in_handle != -1 )
        close(lpi.in_handle);

      debmod->dmsg("Failed to open output redirection file '%s': %s\n", redir_out.c_str(), winerr(errno));
      return -1;
    }
    lpi.err_handle = lpi.out_handle;
  }

  qstring errbuf;
  lpi.path = path;
  lpi.args = args;
  lpi.flags = LP_TRACE;
  *child_pid = launch_process(lpi, &errbuf);

  // Close redir files
  if ( lpi.in_handle != -1 )
    close(lpi.in_handle);
  if ( lpi.out_handle != -1 )
    close(lpi.out_handle);

  if ( *child_pid == NULL )
  {
    debmod->dmsg("launch_process: %s", errbuf.c_str());
    return -1;
  }
  return 1 | mismatch;
}
Esempio n. 6
0
int idaapi maclnx_launch_process(
        debmod_t *debmod,
        const char *path,
        const char *args,
        const char *startdir,
        int flags,
        const char *input_path,
        uint32 input_file_crc32,
        void **child_pid)
{
  // prepare full path if the input_path is relative
  char full_input[QMAXPATH];
  if ( startdir[0] != '\0' && !qisabspath(input_path) )
  {
    qmake_full_path(full_input, sizeof(full_input), input_path);
    input_path = full_input;
  }

  // input file specified in the database does not exist
  if ( input_path[0] != '\0' && !qfileexist(input_path) )
  {
    debmod->dwarning("AUTOHIDE NONE\nInput file is missing: %s", input_path);
    return -2;
  }

  // temporary thing, later we will retrieve the real file name
  // based on the process id
  debmod->input_file_path = input_path;
  debmod->is_dll = (flags & DBG_PROC_IS_DLL) != 0;

  if ( !qfileexist(path) )
  {
    debmod->dmsg("%s: %s\n", path, winerr(errno));
    return -1;
  }

  int mismatch = 0;
  if ( !debmod->check_input_file_crc32(input_file_crc32) )
    mismatch = CRC32_MISMATCH;

#ifdef __EA64__
  bool dbg_srv_64 = true;
#else
  bool dbg_srv_64 = false;
  if ( (flags & DBG_PROC_64BIT) != 0 )
  {
    debmod->dwarning("Cannot debug a 64bit process with the 32bit debugger server, sorry\n");
    return -1;
  }
#endif

  launch_process_params_t lpi;
  lpi.path = path;
  lpi.args = args;
  lpi.startdir = startdir[0] != '\0' ? startdir : NULL;
  lpi.flags = LP_NO_ASLR | LP_DETACH_TTY;
  if ( (flags & DBG_NO_TRACE) == 0 )
    lpi.flags |= LP_TRACE;

  if ( (flags & DBG_PROC_64BIT) != 0 )
  {
    lpi.flags |= LP_LAUNCH_64_BIT;
  }
  else if ( (flags & DBG_PROC_32BIT) != 0 )
  {
    lpi.flags |= LP_LAUNCH_32_BIT;
  }
  else
  {
    lpi.flags |= dbg_srv_64 ? LP_LAUNCH_64_BIT : LP_LAUNCH_32_BIT;
    debmod->dmsg("Launching as %sbit process\n", dbg_srv_64 ? "64" : "32");
  }

  qstring errbuf;
  *child_pid = launch_process(lpi, &errbuf);

  if ( *child_pid == NULL )
  {
    debmod->dmsg("launch_process: %s", errbuf.c_str());
    return -1;
  }
  return 1 | mismatch;
}