Esempio n. 1
0
int __cdecl wmain(int argc, PWCHAR argv[]) {
  size_t i;
  WCHAR fileName[MAX_PATH];
  WCHAR driverFullPath[MAX_PATH] = {0};
  PVOID wow64OldValue;
  BOOL isAdmin;

  isAdmin = IsUserAnAdmin();

  DokanUseStdErr(TRUE); // Set dokan library debug output

  Wow64DisableWow64FsRedirection(&wow64OldValue); // Disable system32 direct
  // setlocale(LC_ALL, "");

  GetModuleFileName(NULL, fileName, MAX_PATH);

  // search the last "\"
  for (i = wcslen(fileName) - 1; i > 0 && fileName[i] != L'\\'; --i) {
    ;
  }
  fileName[i] = L'\0';

  ExpandEnvironmentStringsW(DOKAN_DRIVER_FULL_PATH, driverFullPath, MAX_PATH);

  fwprintf(stdout, L"Driver path: '%s'\n", driverFullPath);

  WCHAR option = GetOption(argc, argv, 1);
  if (option == L'\0' || option == L'?') {
    return ShowUsage();
  }

  if (!isAdmin &&
      (option == L'i' || option == L'r' || option == L'd' || option == L'u')) {
    fprintf(stderr, "Admin rights required to process this operation\n");
    return EXIT_FAILURE;
  }

  switch (option) {
  // Admin rights required
  case L'i': {
    WCHAR type = towlower(argv[2][0]);
    if (type == L'd') {
      return InstallDriver(driverFullPath);
    } else if (type == L'n') {
      if (DokanNetworkProviderInstall())
        fprintf(stdout, "network provider install ok\n");
      else
        fprintf(stderr, "network provider install failed\n");
    } else {
      goto DEFAULT;
    }
  } break;

  case L'r': {
    WCHAR type = towlower(argv[2][0]);
    if (type == L'd') {
      return DeleteDokanService(DOKAN_DRIVER_SERVICE);
    } else if (type == L'n') {
      if (DokanNetworkProviderUninstall())
        fprintf(stdout, "network provider remove ok\n");
      else
        fprintf(stderr, "network provider remove failed\n");
    } else {
      goto DEFAULT;
    }
  } break;

  case L'd': {
    WCHAR type = towlower(argv[2][0]);
    if (L'0' > type || type > L'9')
      goto DEFAULT;

    ULONG mode = type - L'0';
    if (DokanSetDebugMode(mode)) {
      fprintf(stdout, "set debug mode ok\n");
    } else {
      fprintf(stderr, "set debug mode failed\n");
    }
  } break;

  case L'u': {
    if (argc < 3) {
      goto DEFAULT;
    }
    return Unmount(argv[2]);
  } break;

  // No admin rights required
  case L'l': {
    ULONG nbRead = 0;
    PDOKAN_CONTROL dokanControl =
        malloc(DOKAN_MAX_INSTANCES * sizeof(*dokanControl));
    if (dokanControl == NULL) {
      fprintf(stderr, "Failed to allocate dokanControl\n");
      return EXIT_FAILURE;
    }

    ZeroMemory(dokanControl, DOKAN_MAX_INSTANCES * sizeof(*dokanControl));
    if (DokanGetMountPointList(dokanControl, DOKAN_MAX_INSTANCES, FALSE,
                               &nbRead)) {
      fwprintf(stdout, L"  Mount points: %d\n", nbRead);
      for (unsigned int p = 0; p < nbRead; ++p) {
        fwprintf(stdout, L"  %u# MountPoint: %s - UNC: %s - DeviceName: %s\n",
                 p, dokanControl[p].MountPoint, dokanControl[p].UNCName,
                 dokanControl[p].DeviceName);
      }
    } else {
      fwprintf(stderr, L"  Cannot retrieve mount point list.\n");
    }
    free(dokanControl);
  } break;

  case L'v': {
    fprintf(stdout, "dokanctl : %s %s\n", __DATE__, __TIME__);
    fprintf(stdout, "Dokan version : %d\n", DokanVersion());
    fprintf(stdout, "Dokan driver version : 0x%lx\n", DokanDriverVersion());
  } break;

  DEFAULT:
  default:
    fprintf(stderr, "Unknown option - Use /? to show usage\n");
  }

  return EXIT_SUCCESS;
}
Esempio n. 2
0
int __cdecl wmain(int argc, PWCHAR argv[]) {
  size_t i;
  WCHAR fileName[MAX_PATH];
  WCHAR driverFullPath[MAX_PATH] = {0};
  WCHAR type;
  PVOID wow64OldValue;

  DokanUseStdErr(TRUE); // Set dokan library debug output

  Wow64DisableWow64FsRedirection(&wow64OldValue); // Disable system32 direct
  // setlocale(LC_ALL, "");

  GetModuleFileName(NULL, fileName, MAX_PATH);

  // search the last "\"
  for (i = wcslen(fileName) - 1; i > 0 && fileName[i] != L'\\'; --i) {
    ;
  }
  fileName[i] = L'\0';

  ExpandEnvironmentStringsW(DOKAN_DRIVER_FULL_PATH, driverFullPath, MAX_PATH);

  fwprintf(stdout, L"Driver path: '%s'\n", driverFullPath);

  if (GetOption(argc, argv, 1) == L'v') {
    fprintf(stdout, "dokanctl : %s %s\n", __DATE__, __TIME__);
    fprintf(stdout, "Dokan version : %d\n", DokanVersion());
    fprintf(stdout, "Dokan driver version : 0x%lx\n", DokanDriverVersion());
    return EXIT_SUCCESS;

  } else if (GetOption(argc, argv, 1) == L'u' && argc == 3) {
    return Unmount(argv[2], FALSE);

  } else if (GetOption(argc, argv, 1) == L'u' &&
             GetOption(argc, argv, 3) == L'f' && argc == 4) {
    return Unmount(argv[2], TRUE);

  } else if (argc < 3 || wcslen(argv[1]) != 2 || argv[1][0] != L'/') {
    return ShowUsage();
  }

  type = towlower(argv[2][0]);

  switch (towlower(argv[1][1])) {
  case L'i':
    if (type == L'd') {

      return InstallDriver(driverFullPath);

    } else if (type == L'n') {
      if (DokanNetworkProviderInstall())
        fprintf(stdout, "network provider install ok\n");
      else
        fprintf(stderr, "network provider install failed\n");
    }
    break;

  case L'r':
    if (type == L'd') {

      return DeleteDokanService(DOKAN_DRIVER_SERVICE);

    } else if (type == L'n') {
      if (DokanNetworkProviderUninstall())
        fprintf(stdout, "network provider remove ok\n");
      else
        fprintf(stderr, "network provider remove failed\n");
    }
    break;

  case L'd':
    if (L'0' <= type && type <= L'9') {
      ULONG mode = type - L'0';
      if (DokanSetDebugMode(mode)) {
        fprintf(stdout, "set debug mode ok\n");
      } else {
        fprintf(stderr, "set debug mode failed\n");
      }
    }
    break;

  case L'l': {
    ULONG nbRead = 0;
    DOKAN_CONTROL dokanControl[DOKAN_MAX_INSTANCES];
    if (DokanGetMountPointList(dokanControl, DOKAN_MAX_INSTANCES, FALSE,
                               &nbRead)) {
      fwprintf(stdout, L"  Mount points: %d\n", nbRead);
      for (unsigned int p = 0; p < nbRead; ++p) {
        fwprintf(stdout, L"  %d# MountPoint: %s - UNC: %s - DeviceName: %s\n",
                 p, dokanControl[p].MountPoint, dokanControl[p].UNCName,
                 dokanControl[p].DeviceName);
      }
    } else {
      fwprintf(stderr, L"  Cannot retrieve mount point list.\n");
    }
  } break;

  default:
    fprintf(stderr, "unknown option\n");
  }

  return EXIT_SUCCESS;
}
Esempio n. 3
0
int __cdecl
wmain(int argc, PWCHAR argv[])
{
	size_t	i;
    WCHAR	fileName[MAX_PATH];
    WCHAR	driverFullPath[MAX_PATH] = { 0 };
    WCHAR	mounterFullPath[MAX_PATH] = { 0 };
    WCHAR	type;

    //setlocale(LC_ALL, "");

    GetModuleFileName(NULL, fileName, MAX_PATH);
    
    // search the last "\"
    for(i = wcslen(fileName) - 1; i > 0 && fileName[i] != L'\\'; --i)
    {
        ;
    }
    fileName[i] = L'\0';

    wcscpy_s(mounterFullPath, MAX_PATH, fileName);
    wcscat_s(mounterFullPath, MAX_PATH, L"\\mounter.exe");
    fwprintf(stderr, L"mounter path %s\n", mounterFullPath);

    GetSystemDirectory(driverFullPath, MAX_PATH);
    wcscat_s(driverFullPath, MAX_PATH, L"\\drivers\\dokan.sys");

    fwprintf(stderr, L"driver path %s\n", driverFullPath);
    

    if (GetOption(argc, argv, 1) == L'v') {
        fprintf(stderr, "dokanctl : %s %s\n", __DATE__, __TIME__);
        fprintf(stderr, "Dokan version : %d\n", DokanVersion());
        fprintf(stderr, "Dokan driver version : 0x%X\n", DokanDriverVersion());
        return 0;
    
    } else if (GetOption(argc, argv, 1) == L'm') {
        return ShowMountList();

    } else if (GetOption(argc, argv, 1) == L'u' && argc == 3) {
        return Unmount(argv[2], FALSE);

    } else if (GetOption(argc, argv, 1) == L'u' &&
                GetOption(argc, argv, 3) == L'f' && argc == 4) {
        return Unmount(argv[2], TRUE);

    } else if (argc < 3 || wcslen(argv[1]) != 2 || argv[1][0] != L'/' ) {
        return ShowUsage();
    }

    type = towlower(argv[2][0]);

    switch(towlower(argv[1][1])) {
    case L'i':
        if (type ==  L'd') {
            if (DokanServiceInstall(DOKAN_DRIVER_SERVICE,
                                    SERVICE_FILE_SYSTEM_DRIVER,
                                    driverFullPath))
                fprintf(stderr, "driver install ok");
            else
                fprintf(stderr, "driver install failed");

        } else if (type == L's') {
            if (DokanServiceInstall(DOKAN_MOUNTER_SERVICE,
                                    SERVICE_WIN32_OWN_PROCESS,
                                    mounterFullPath))
                fprintf(stderr, "mounter install ok");
            else
                fprintf(stderr, "mounter install failed");
        
        } else if (type == L'a') {
            if (DokanServiceInstall(DOKAN_DRIVER_SERVICE,
                                    SERVICE_FILE_SYSTEM_DRIVER,
                                    driverFullPath))
                fprintf(stderr, "driver install ok");
            else
                fprintf(stderr, "driver install failed");

            if (DokanServiceInstall(DOKAN_MOUNTER_SERVICE,
                                    SERVICE_WIN32_OWN_PROCESS,
                                    mounterFullPath))
                fprintf(stderr, "mounter install ok");
            else
                fprintf(stderr, "mounter install failed");
        } else if (type == L'n') {
            if (DokanNetworkProviderInstall())
                fprintf(stderr, "network provider install ok");
            else
                fprintf(stderr, "network provider install failed");
        }
        break;

    case L'r':
        if (type == L'd') {
            if (DokanServiceDelete(DOKAN_DRIVER_SERVICE))
                fprintf(stderr, "driver remove ok");
            else
                fprintf(stderr, "driver remvoe failed");
        
        } else if (type == L's') {
            if (DokanServiceDelete(DOKAN_MOUNTER_SERVICE))
                fprintf(stderr, "mounter remove ok");
            else
                fprintf(stderr, "mounter remvoe failed");	
        
        } else if (type == L'a') {
            if (DokanServiceDelete(DOKAN_MOUNTER_SERVICE))
                fprintf(stderr, "mounter remove ok");
            else
                fprintf(stderr, "mounter remvoe failed");	

            if (DokanServiceDelete(DOKAN_DRIVER_SERVICE))
                fprintf(stderr, "driver remove ok");
            else
                fprintf(stderr, "driver remvoe failed");
        } else if (type == L'n') {
            if (DokanNetworkProviderUninstall())
                fprintf(stderr, "network provider remove ok");
            else
                fprintf(stderr, "network provider remove failed");
        }
        break;
    case L'd':
        if (L'0' <= type && type <= L'9') {
            ULONG mode = type - L'0';
            if (DokanSetDebugMode(mode)) {
                fprintf(stderr, "set debug mode ok");
            } else {
                fprintf(stderr, "set debug mode failed");
            }
        }
        break;
    default:
        fprintf(stderr, "unknown option");
    }
    

    return 0;
}
Esempio n. 4
0
int __cdecl wmain(int argc, PWCHAR argv[]) {
  size_t i;
  WCHAR fileName[MAX_PATH];
  WCHAR driverFullPath[MAX_PATH] = {0};
  WCHAR mounterFullPath[MAX_PATH] = {0};
  WCHAR type;
  PVOID wow64OldValue;

  DokanUseStdErr(TRUE); // Set dokan library debug output

  Wow64DisableWow64FsRedirection(&wow64OldValue); //Disable system32 direct
  // setlocale(LC_ALL, "");

  GetModuleFileName(NULL, fileName, MAX_PATH);

  // search the last "\"
  for (i = wcslen(fileName) - 1; i > 0 && fileName[i] != L'\\'; --i) {
    ;
  }
  fileName[i] = L'\0';

  wcscpy_s(mounterFullPath, MAX_PATH, fileName);
  wcscat_s(mounterFullPath, MAX_PATH, L"\\mounter.exe");
  fwprintf(stderr, L"Mounter path: '%s'\n", mounterFullPath);

  ExpandEnvironmentStringsW(DOKAN_DRIVER_FULL_PATH, driverFullPath, MAX_PATH);

  fwprintf(stderr, L"Driver path: '%s'\n", driverFullPath);

  if (GetOption(argc, argv, 1) == L'v') {
    fprintf(stderr, "dokanctl : %s %s\n", __DATE__, __TIME__);
    fprintf(stderr, "Dokan version : %d\n", DokanVersion());
    fprintf(stderr, "Dokan driver version : 0x%lx\n", DokanDriverVersion());
    return EXIT_SUCCESS;

  } else if (GetOption(argc, argv, 1) == L'm') {
    return ShowMountList();

  } else if (GetOption(argc, argv, 1) == L'u' && argc == 3) {
    return Unmount(argv[2], FALSE);

  } else if (GetOption(argc, argv, 1) == L'u' &&
             GetOption(argc, argv, 3) == L'f' && argc == 4) {
    return Unmount(argv[2], TRUE);

  } else if (argc < 3 || wcslen(argv[1]) != 2 || argv[1][0] != L'/') {
    return ShowUsage();
  }

  type = towlower(argv[2][0]);

  switch (towlower(argv[1][1])) {
  case L'i':
    if (type == L'd') {

      return InstallDriver(driverFullPath);

    } else if (type == L's') {

      return InstallMounter(mounterFullPath);

    } else if (type == L'a') {

      if (InstallDriver(driverFullPath) == EXIT_FAILURE)
        return EXIT_FAILURE;

      if (InstallMounter(mounterFullPath) == EXIT_FAILURE)
        return EXIT_FAILURE;

    } else if (type == L'n') {
      if (DokanNetworkProviderInstall())
        fprintf(stderr, "network provider install ok\n");
      else
        fprintf(stderr, "network provider install failed\n");
    }
    break;

  case L'r':
    if (type == L'd') {

      return DeleteDokanService(DOKAN_DRIVER_SERVICE);

    } else if (type == L's') {

      return DeleteDokanService(DOKAN_MOUNTER_SERVICE);

    } else if (type == L'a') {

      if (DeleteDokanService(DOKAN_MOUNTER_SERVICE) == EXIT_FAILURE)
        return EXIT_FAILURE;

      if (DeleteDokanService(DOKAN_DRIVER_SERVICE) == EXIT_FAILURE)
        return EXIT_FAILURE;

    } else if (type == L'n') {
      if (DokanNetworkProviderUninstall())
        fprintf(stderr, "network provider remove ok\n");
      else
        fprintf(stderr, "network provider remove failed\n");
    }
    break;
  case L'd':
    if (L'0' <= type && type <= L'9') {
      ULONG mode = type - L'0';
      if (DokanSetDebugMode(mode)) {
        fprintf(stderr, "set debug mode ok\n");
      } else {
        fprintf(stderr, "set debug mode failed\n");
      }
    }
    break;
  default:
    fprintf(stderr, "unknown option\n");
  }

  return EXIT_SUCCESS;
}