summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-03-11 02:32:26 +0000
committerPete Batard <pbatard@gmail.com>2010-03-11 02:32:26 +0000
commit53110b64d149ffd63320dcef3a706d94ebd40d10 (patch)
tree6012ac5c4b333ff99b44b77dfa5904bdc2f81f79
parent9d1d3d72eeff7bbdd08caca54ac77152a7d9a69b (diff)
downloadlibusb-a165.tar.gz
added Vista/7 privilege escalation (WIP)a165
-rw-r--r--driver-installer_2008.vcproj345
-rw-r--r--examples/lsusb.c2
-rw-r--r--libusb/os/driver_install.c69
-rw-r--r--libusb/os/driver_installer.c75
-rw-r--r--libusb_2008.sln8
5 files changed, 449 insertions, 50 deletions
diff --git a/driver-installer_2008.vcproj b/driver-installer_2008.vcproj
new file mode 100644
index 0000000..99ca40a
--- /dev/null
+++ b/driver-installer_2008.vcproj
@@ -0,0 +1,345 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="driver-installer"
+ ProjectGUID="{9B1C561E-F95B-4849-A7AA-A4350E227C20}"
+ RootNamespace="libusbinstaller"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ <Platform
+ Name="x64"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib"
+ IntermediateDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib\driver-installer"
+ ConfigurationType="1"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=".\msvc;.\libusb;.\"
+ PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="difxapi.lib"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib"
+ IntermediateDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib\driver-installer"
+ ConfigurationType="1"
+ CharacterSet="2"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ AdditionalIncludeDirectories=".\msvc;.\libusb;.\"
+ PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="difxapi.lib"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug|x64"
+ OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib"
+ IntermediateDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib\driver-installer"
+ ConfigurationType="1"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=".\msvc;.\libusb;.\"
+ PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="difxapi.lib"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="17"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|x64"
+ OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib"
+ IntermediateDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib\driver-installer"
+ ConfigurationType="1"
+ CharacterSet="2"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ AdditionalIncludeDirectories=".\msvc;.\libusb;.\"
+ PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="difxapi.lib"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="17"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\libusb\os\driver_installer.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/examples/lsusb.c b/examples/lsusb.c
index eb3855a..488de4e 100644
--- a/examples/lsusb.c
+++ b/examples/lsusb.c
@@ -55,7 +55,7 @@ main(void)
drv_info = list_driverless();
for (; drv_info != NULL; drv_info = drv_info->next) {
if (create_inf(drv_info, "C:\\test") == 0) {
- install_device("C:\\test\\libusb_device.inf");
+ install_device("C:\\test");
}
}
diff --git a/libusb/os/driver_install.c b/libusb/os/driver_install.c
index e4338ff..3c2cc36 100644
--- a/libusb/os/driver_install.c
+++ b/libusb/os/driver_install.c
@@ -6,11 +6,13 @@
#include <inttypes.h>
#include <objbase.h> // for GUID ops. requires libole32.a
#include <api/difxapi.h>
+#include <api/shellapi.h>
#include "libusbi.h"
#include "windows_usb.h"
#include "driver_install.h"
+
const char inf[] = "Date = \"03/08/2010\"\n\n" \
"ProviderName = \"libusb 1.0\"\n" \
"WinUSB_SvcDesc = \"WinUSB Driver Service\"\n" \
@@ -352,60 +354,29 @@ int create_inf(struct driver_info* drv_info, char* path)
fprintf(fd, "DeviceGUID = \"%s\"\n", guid_to_string(guid));
fwrite(inf, sizeof(inf)-1, 1, fd);
return 0;
-
- // TODO: extract coinstaller files from resource
- // TODO: create cat file for XP?
}
+// TODO: extract driver-installer.exe into the dest dir
int install_device(char* path)
{
- DWORD r;
- BOOL reboot_needed;
-// INSTALLERINFO installer_info;
-
- r = DriverPackagePreinstall(path, DRIVER_PACKAGE_LEGACY_MODE|DRIVER_PACKAGE_REPAIR);
- // Will fail if inf not signed, unless DRIVER_PACKAGE_LEGACY_MODE is specified.
- // r = 87 ERROR_INVALID_PARAMETER on path == NULL
- // r = 2 ERROR_FILE_NOT_FOUND if no inf in path
- // r = 5 ERROR_ACCESS_DENIED if needs admin elevation
- // r = 0xE0000003 ERROR_GENERAL_SYNTAX the syntax of the inf is invalid
- // r = 0xE0000304 ERROR_INVALID_CATALOG_DATA => no cat
- // r = 0xE0000247 if user decided not to install on warnings
- // r = 0x800B0100 ERROR_WRONG_INF_STYLE => missing cat entry in inf
- // r = 0xB7 => missing DRIVER_PACKAGE_REPAIR flag
- switch(r) {
- case ERROR_INVALID_PARAMETER:
- usbi_err(NULL, "invalid path");
- return -1;
- case ERROR_FILE_NOT_FOUND:
- usbi_err(NULL, "unable to find inf file on %s", path);
- return -1;
- case ERROR_ACCESS_DENIED:
- usbi_err(NULL, "this process needs to be run with administrative privileges");
- return -1;
- case ERROR_WRONG_INF_STYLE:
- case ERROR_GENERAL_SYNTAX:
- usbi_err(NULL, "the syntax of the inf is invalid");
- return -1;
- case ERROR_INVALID_CATALOG_DATA:
- usbi_err(NULL, "unable to locate cat file");
- return -1;
- case ERROR_DRIVER_STORE_ADD_FAILED:
- usbi_err(NULL, "cancelled by user");
- return -1;
- // TODO: make DRIVER_PACKAGE_REPAIR optional
- case ERROR_ALREADY_EXISTS:
- usbi_err(NULL, "driver already exists");
- return -1;
- default:
- usbi_err(NULL, "unhandled error %X", r);
- return -1;
- }
+ SHELLEXECUTEINFO shExecInfo;
+ char exename[MAX_PATH_LENGTH];
+ safe_strcpy(exename, MAX_PATH_LENGTH, path);
+ safe_strcat(exename, MAX_PATH_LENGTH, "\\driver-installer.exe");
+
+ shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
+
+ shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
+ shExecInfo.hwnd = NULL;
+ shExecInfo.lpVerb = "runas";
+ shExecInfo.lpFile = exename;
+ shExecInfo.lpParameters = NULL;
+ shExecInfo.lpDirectory = path;
+ shExecInfo.nShow = SW_MAXIMIZE;
+ shExecInfo.hInstApp = NULL;
- // TODO: use
- r = DriverPackageInstall(path, DRIVER_PACKAGE_LEGACY_MODE|DRIVER_PACKAGE_REPAIR,
- NULL, &reboot_needed);
- usbi_dbg("ret = %X", r);
+ ShellExecuteEx(&shExecInfo);
+ usbi_dbg("hProcess = %p", shExecInfo.hProcess);
return 0;
} \ No newline at end of file
diff --git a/libusb/os/driver_installer.c b/libusb/os/driver_installer.c
new file mode 100644
index 0000000..7f58d92
--- /dev/null
+++ b/libusb/os/driver_installer.c
@@ -0,0 +1,75 @@
+// This standalone installer is a separate exe, as it needs to be run
+// through ShellExecuteEx() for UAC elevation
+
+#include <config.h>
+#include <windows.h>
+#include <setupapi.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <direct.h>
+#include <api/difxapi.h>
+
+
+#define MAX_PATH_LENGTH 128
+#define safe_strncat(dst, dst_max, src, count) strncat(dst, src, min(count, dst_max - strlen(dst) - 1))
+#define safe_strcat(dst, dst_max, src) safe_strncat(dst, dst_max, src, strlen(src)+1)
+
+
+int main(int argc, char** argv)
+{
+ DWORD r;
+ BOOL reboot_needed;
+ char path[MAX_PATH_LENGTH];
+// INSTALLERINFO installer_info;
+
+ _getcwd(path, MAX_PATH_LENGTH);
+ safe_strcat(path, MAX_PATH_LENGTH, "\\libusb_device.inf");
+
+
+ r = DriverPackagePreinstall(path, DRIVER_PACKAGE_LEGACY_MODE|DRIVER_PACKAGE_REPAIR);
+ // Will fail if inf not signed, unless DRIVER_PACKAGE_LEGACY_MODE is specified.
+ // r = 87 ERROR_INVALID_PARAMETER on path == NULL
+ // r = 2 ERROR_FILE_NOT_FOUND if no inf in path
+ // r = 5 ERROR_ACCESS_DENIED if needs admin elevation
+ // r = 0xE0000003 ERROR_GENERAL_SYNTAX the syntax of the inf is invalid
+ // r = 0xE0000304 ERROR_INVALID_CATALOG_DATA => no cat
+ // r = 0xE0000247 if user decided not to install on warnings
+ // r = 0x800B0100 ERROR_WRONG_INF_STYLE => missing cat entry in inf
+ // r = 0xB7 => missing DRIVER_PACKAGE_REPAIR flag
+ switch(r) {
+ case ERROR_INVALID_PARAMETER:
+ printf("invalid path\n");
+ return -1;
+ case ERROR_FILE_NOT_FOUND:
+ printf("unable to find inf file on %s\n", path);
+ return -1;
+ case ERROR_ACCESS_DENIED:
+ printf("this process needs to be run with administrative privileges\n");
+ return -1;
+ case ERROR_WRONG_INF_STYLE:
+ case ERROR_GENERAL_SYNTAX:
+ printf("the syntax of the inf is invalid\n");
+ return -1;
+ case ERROR_INVALID_CATALOG_DATA:
+ printf("unable to locate cat file\n");
+ return -1;
+ case ERROR_DRIVER_STORE_ADD_FAILED:
+ printf("cancelled by user\n");
+ return -1;
+ // TODO: make DRIVER_PACKAGE_REPAIR optional
+ case ERROR_ALREADY_EXISTS:
+ printf("driver already exists\n");
+ return -1;
+ default:
+ printf("unhandled error %X\n", r);
+ return -1;
+ }
+
+ // TODO: use
+ r = DriverPackageInstall(path, DRIVER_PACKAGE_LEGACY_MODE|DRIVER_PACKAGE_REPAIR,
+ NULL, &reboot_needed);
+ printf("ret = %X\n", r);
+
+ return 0;
+} \ No newline at end of file
diff --git a/libusb_2008.sln b/libusb_2008.sln
index 15eae8d..fed9d0b 100644
--- a/libusb_2008.sln
+++ b/libusb_2008.sln
@@ -23,6 +23,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "driver-install", "driver-in
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "driver-resources", "driver-resources_2008.vcproj", "{BA852F82-4329-4CBE-82AA-9947FB48AD83}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "driver-installer", "driver-installer_2008.vcproj", "{9B1C561E-F95B-4849-A7AA-A4350E227C20}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -70,6 +72,12 @@ Global
{BA852F82-4329-4CBE-82AA-9947FB48AD83}.Release|Win32.ActiveCfg = Release|Win32
{BA852F82-4329-4CBE-82AA-9947FB48AD83}.Release|Win32.Build.0 = Release|Win32
{BA852F82-4329-4CBE-82AA-9947FB48AD83}.Release|x64.ActiveCfg = Release|x64
+ {9B1C561E-F95B-4849-A7AA-A4350E227C20}.Debug|Win32.ActiveCfg = Debug|Win32
+ {9B1C561E-F95B-4849-A7AA-A4350E227C20}.Debug|Win32.Build.0 = Debug|Win32
+ {9B1C561E-F95B-4849-A7AA-A4350E227C20}.Debug|x64.ActiveCfg = Debug|Win32
+ {9B1C561E-F95B-4849-A7AA-A4350E227C20}.Release|Win32.ActiveCfg = Release|Win32
+ {9B1C561E-F95B-4849-A7AA-A4350E227C20}.Release|Win32.Build.0 = Release|Win32
+ {9B1C561E-F95B-4849-A7AA-A4350E227C20}.Release|x64.ActiveCfg = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE