Beispiel #1
0
void host_configure(void)
{
  char **pext;
  HKEY  key;
  DWORD disposition;
  char *u3_host_exec_path;
  char *u3_device_exec_path;
  char *u3_device_serial;
  char *u3_device_document_path;
  char wireshark_path[MAX_PATH+1];
  char winpcap_path[MAX_PATH+1];
  char vcredist_path[MAX_PATH+1];
  char my_captures_path[MAX_PATH+1];
  char reg_key[BUFSIZ];
  char buffer[BUFSIZ];
  int  buflen = BUFSIZ;
  boolean hasWinPcap = FALSE;
  boolean hasRedist = FALSE;

  /* CREATE THE U3 Wireshark TYPE */
  if(RegCreateKeyEx(HKEY_CLASSES_ROOT, WIRESHARK_ASSOC, 0, NULL, 0,
		    (KEY_READ | KEY_WRITE), NULL, &key, &disposition) == ERROR_SUCCESS) {

    (void)RegSetValueEx(key, "", 0, REG_SZ, WIRESHARK_DESC, strlen(WIRESHARK_DESC) + 1);

    RegCloseKey(key);
  }

  /* compute the U3 path to wireshark */
  u3_host_exec_path = getenv("U3_HOST_EXEC_PATH");
  strncpy(wireshark_path, u3_host_exec_path, strlen(u3_host_exec_path) + 1);
  strncat(wireshark_path, U3UTIL_APPSTART, strlen(U3UTIL_APPSTART) + 1);

  strncpy(reg_key, WIRESHARK_ASSOC, strlen(WIRESHARK_ASSOC) + 1);
  strncat(reg_key, SHELL_OPEN_COMMAND, strlen(SHELL_OPEN_COMMAND) + 1);

  /* associate the application */
  if(RegCreateKeyEx(HKEY_CLASSES_ROOT, reg_key, 0, NULL, 0,
		    (KEY_READ | KEY_WRITE), NULL, &key, &disposition) == ERROR_SUCCESS) {
    (void)RegSetValueEx(key, "", 0, REG_SZ, wireshark_path, strlen(wireshark_path) + 1);

    RegCloseKey(key);

  }

  /* associate the icon */
  strncpy(reg_key, WIRESHARK_ASSOC, strlen(WIRESHARK_ASSOC) + 1);
  strncat(reg_key, DEFAULT_ICON, strlen(DEFAULT_ICON) + 1);

  /* the icon is in the exe */
  strncpy(wireshark_path, u3_host_exec_path, strlen(u3_host_exec_path) + 1);
  strncat(wireshark_path, WIRESHARK_EXE, strlen(WIRESHARK_EXE) + 1);
  strncat(wireshark_path, ",1", 3);

  /* associate the application */
  if(RegCreateKeyEx(HKEY_CLASSES_ROOT, reg_key, 0, NULL, 0,
		    (KEY_READ | KEY_WRITE), NULL, &key, &disposition) == ERROR_SUCCESS) {

    (void)RegSetValueEx(key, "", 0, REG_SZ, wireshark_path, strlen(wireshark_path) + 1);

    RegCloseKey(key);
  }

  /* CREATE THE FILE ASSOCIATIONS */

  for(pext = extensions; *pext; pext++)
    associate(*pext);

  /* update icons */
  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);

  /* START WINPCAP INSTALLATION IF NOT ALREADY INSTALLED */

  if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, WINPCAP_KEY, 0, (KEY_READ), &key) == ERROR_SUCCESS) {

    if(RegQueryValueEx(key, WINPCAP_UNINSTALL, NULL, NULL, buffer, &buflen) == ERROR_SUCCESS) {

      if(buffer[0] != '\0')
	hasWinPcap = TRUE;
    }

    RegCloseKey(key);
  }

  if(!hasWinPcap &&
     (MessageBox(NULL,
		 TEXT("If you want to capture packets from the network you will need to install WinPcap.\nIt will be uninstalled when you remove your U3 device.\n\nDo you want to install WinPcap?"),
		 TEXT("U3 Wireshark: Install WinPcap?"),
		 MB_YESNO|MB_TOPMOST|MB_ICONQUESTION) == IDYES)) {

    /* compute the U3 path to the WinPcap installation package - it stays on the device */
    u3_device_exec_path = getenv("U3_DEVICE_EXEC_PATH");
    strncpy(winpcap_path, "\"", 2);
    strncat(winpcap_path, u3_device_exec_path, strlen(u3_device_exec_path) + 1);
    strncat(winpcap_path, WINPCAP_PACKAGE, strlen(WINPCAP_PACKAGE) + 1);
    strncat(winpcap_path, "\"", 2);

    ExecuteAndWait(winpcap_path);

    /* if installation was successful this key will now exist */
    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, WINPCAP_KEY, 0, (KEY_READ | KEY_WRITE), &key) == ERROR_SUCCESS) {

      u3_device_serial = getenv("U3_DEVICE_SERIAL");

      (void)RegSetValueEx(key, WINPCAP_U3INSTALLED, 0, REG_SZ, u3_device_serial, strlen(u3_device_serial) + 1);

      winpcap_auto_start();

    }
  }

  /* START VCREDIST INSTALLATION IF NOT ALREADY INSTALLED */

  if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, VCREDIST_KEY, 0, (KEY_READ), &key) == ERROR_SUCCESS) {

    buflen = BUFSIZ;

    if(RegQueryValueEx(key, VCREDIST_UNINSTALL, NULL, NULL, buffer, &buflen) == ERROR_SUCCESS) {

      if(buffer[0] != '\0')
	hasRedist = TRUE;
    }

    RegCloseKey(key);

  } 

  if(!hasRedist) {

    /* compute the U3 path to the Visual C++  redistributables package - it stays on the device */
    u3_device_exec_path = getenv("U3_DEVICE_EXEC_PATH");
    strncpy(vcredist_path, "\"", 2);
    strncat(vcredist_path, u3_device_exec_path, strlen(u3_device_exec_path) + 1);
    strncat(vcredist_path, VCREDIST_PACKAGE, strlen(VCREDIST_PACKAGE) + 1);
    strncat(vcredist_path, "\" /q", 5); /* do things quietly */

    ExecuteAndWait(vcredist_path);

    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, VCREDIST_KEY, 0, (KEY_READ | KEY_WRITE), &key) == ERROR_SUCCESS) {

      u3_device_serial = getenv("U3_DEVICE_SERIAL");

      (void)RegSetValueEx(key, VCREDIST_U3INSTALLED, 0, REG_SZ, u3_device_serial, strlen(u3_device_serial) + 1);

    }
  }


  /* CREATE THE "My Captures" FOLDER IF IT DOESN'T ALREADY EXIST */

  u3_device_document_path = getenv("U3_DEVICE_DOCUMENT_PATH");
  strncpy(my_captures_path, u3_device_document_path, strlen(u3_device_document_path) + 1);
  strncat(my_captures_path, MY_CAPTURES, strlen(MY_CAPTURES) + 1);

  /* don't care if it succeeds or fails */
  (void) CreateDirectory(my_captures_path, NULL);

  /* Save the environment so we can use it in the file assocation */
  save_environment();
}
Beispiel #2
0
void uninstall(char *regkey, char *u3installed, char *uninstall)
{
  char buffer[BUFSIZ];
  int buflen = BUFSIZ;
  char *u3_device_serial;
  char reg_key[BUFSIZ];
  HKEY  key;

  /* UNINSTALL ONLY IF WE INSTALLED IT */
  buffer[0] = '\0';

  /* see if it is installed */
  if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey, 0, (KEY_READ | KEY_WRITE), &key) == ERROR_SUCCESS) {

    buflen = BUFSIZ;

    /* see if a U3 device installed the package */
    if(RegQueryValueEx(key, u3installed, NULL, NULL, buffer, &buflen) == ERROR_SUCCESS) {

      u3_device_serial = getenv("U3_DEVICE_SERIAL");

      /* see if this U3 device installed the package */
      if(!strncmp(buffer, u3_device_serial, strlen(u3_device_serial) + 1)) {

	buffer[0] = '"';
	buflen = BUFSIZ-1;
	/* we installed WinPcap - we should now uninstall it - read the uninstall string */
	(void) RegQueryValueEx(key, uninstall, NULL, NULL, &buffer[1], &buflen);


	if(!strncmp(buffer, "\"MsiExec.exe", 12)) {
	  /* run msiexec.exe quietly */
	  strncat(buffer, " /qn", 5);

	}

	strncat(buffer, "\"", 2); /* close the quotes */

	/* delete our value */
	RegDeleteValue(key, u3installed);

      } else {
	/* empty the buffer */
	buffer[0] = '\0';
      }
    }

    RegCloseKey(key);
  }

  if(*buffer) {
#if 0
    MessageBox(NULL,
	       buffer,
	       "Uninstall",
	       MB_YESNO|MB_TOPMOST|MB_ICONQUESTION);
#endif 

    /* we have an uninstall string */
    ExecuteAndWait(buffer);
  }
}
Beispiel #3
0
void app_start(int argc, char *argv[])
{
  char *u3hostexecpath;
  char *envvar;
  char *end;
  char buffer[BUFSIZ+1];
  char inBuffer[FILEBUFSIZ+1];
  HANDLE *file;
  DWORD numRead = 0;
  int i;

  /* read any environment variables that may be set as we are probably running this from a file association */

  buffer[0] = '\0';
  strncat(buffer, argv[0], strlen(argv[0]) + 1);

  /* truncate at last \\ */
  if(end = strrchr(buffer, '\\'))
    *end = '\0';

  strncat(buffer, ENV_FILENAME, strlen(ENV_FILENAME) + 1);

  /* open the file */
  if((file = CreateFile(buffer, FILE_READ_DATA, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE) {

    /* read the whole file in in one go */
    if(ReadFile(file, &inBuffer, FILEBUFSIZ, &numRead, NULL) != 0) {
      /* we were successful - parse the lines */
      inBuffer[numRead] = '\0'; /* null terminate the data */

      envvar = inBuffer;

      while(end = strchr(envvar, '\n')) {
	/* we have a line */
	*end++ = '\0';

	_putenv(envvar);

	/* point the next envar to the end */
	envvar = end;
      }
    }

    /* close the file */
    CloseHandle(file);

  }

  /* exec wireshark */
  if((u3hostexecpath = getenv("U3_HOST_EXEC_PATH")) != NULL) {

    buffer[0] = '\0';
    strncat(buffer, u3hostexecpath, strlen(u3hostexecpath) + 1);
    strncat(buffer, WIRESHARK_EXE, strlen(WIRESHARK_EXE) + 1);

    /* copy the remaining arguments across */
    for(i = 2; i < argc; i++) {
      strncat(buffer, " ", 2);
      strncat(buffer, argv[i], strlen(argv[i]) + 1);
    }

    ExecuteAndWait(buffer);

  }

}
Beispiel #4
0
	/**
	 *	Executes a named file.  It may be a program or a script.
	 *	Free's args
	 *
	 *	@param		a null terminated vector of arguments created with strdup
	 *	@return		return code from program
	 */
	int execp(std::vector<char*> &args)
	{
		return ExecuteAndWait(execvp, "execvp", args);
	}