diff options
-rw-r--r-- | ddk_directory.vsprops | 12 | ||||
-rw-r--r-- | driver-install_2008.vcproj | 10 | ||||
-rw-r--r-- | driver-resources_2008.vcproj | 307 | ||||
-rw-r--r-- | examples/lsusb.c | 2 | ||||
-rw-r--r-- | examples/lsusb_2008.vcproj | 16 | ||||
-rw-r--r-- | libusb/os/driver_install.c | 112 | ||||
-rw-r--r-- | libusb_2008.sln | 8 | ||||
-rw-r--r-- | msvc/driver_resources.rc | 125 |
8 files changed, 576 insertions, 16 deletions
diff --git a/ddk_directory.vsprops b/ddk_directory.vsprops new file mode 100644 index 0000000..4d0a293 --- /dev/null +++ b/ddk_directory.vsprops @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioPropertySheet + ProjectType="Visual C++" + Version="8.00" + Name="ddk_directory" + > + <UserMacro + Name="DDKDir" + Value="E:\WinDDK\7600.16385.0" + PerformEnvironmentSet="true" + /> +</VisualStudioPropertySheet> diff --git a/driver-install_2008.vcproj b/driver-install_2008.vcproj index b87b03b..b902484 100644 --- a/driver-install_2008.vcproj +++ b/driver-install_2008.vcproj @@ -275,16 +275,14 @@ > </File> <File + RelativePath=".\msvc\resource.h" + > + </File> + <File RelativePath="libusb\os\windows_usb.h" > </File> </Filter> - <Filter - Name="Resource Files" - Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" - UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" - > - </Filter> </Files> <Globals> </Globals> diff --git a/driver-resources_2008.vcproj b/driver-resources_2008.vcproj new file mode 100644 index 0000000..32c38bc --- /dev/null +++ b/driver-resources_2008.vcproj @@ -0,0 +1,307 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="9.00" + Name="driver-resources" + ProjectGUID="{BA852F82-4329-4CBE-82AA-9947FB48AD83}" + RootNamespace="driverresources" + 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-resources" + ConfigurationType="1" + InheritedPropertySheets=".\ddk_directory.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + WarningLevel="3" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + ShowProgress="true" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + GenerateDebugInformation="true" + 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-resources" + ConfigurationType="1" + InheritedPropertySheets=".\ddk_directory.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TargetEnvironment="3" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + ShowProgress="true" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + GenerateDebugInformation="true" + 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|Win32" + OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib" + IntermediateDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib\driver-resources" + ConfigurationType="4" + InheritedPropertySheets=".\ddk_directory.vsprops" + CharacterSet="2" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + CommandLine="" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + EnableIntrinsicFunctions="true" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + ShowProgress="true" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|x64" + OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib" + IntermediateDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib\driver-resources" + ConfigurationType="4" + InheritedPropertySheets=".\ddk_directory.vsprops" + CharacterSet="2" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + CommandLine="" + /> + <Tool + Name="VCCustomBuildTool" + CommandLine="" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TargetEnvironment="3" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + EnableIntrinsicFunctions="true" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + ShowProgress="true" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Resource Files" + > + <File + RelativePath="..\libusb-pbatard\msvc\driver_resources.rc" + > + </File> + </Filter> + <File + RelativePath=".\msvc\resource.h" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/examples/lsusb.c b/examples/lsusb.c index 61d278a..f08b7cc 100644 --- a/examples/lsusb.c +++ b/examples/lsusb.c @@ -60,7 +60,7 @@ main(void) } } -// return 0; + return 0; r = libusb_init(NULL); if (r < 0) diff --git a/examples/lsusb_2008.vcproj b/examples/lsusb_2008.vcproj index f0d13a0..fa0991f 100644 --- a/examples/lsusb_2008.vcproj +++ b/examples/lsusb_2008.vcproj @@ -65,9 +65,9 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2.lib" + AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib difxapi.lib driver_resources.res" LinkIncremental="2" - AdditionalLibraryDirectories="..\msvc" + AdditionalLibraryDirectories="..\msvc;$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib\driver-resources" GenerateDebugInformation="true" ProgramDatabaseFile="$(TargetDir)$(ProjectName).pdb" SubSystem="1" @@ -142,9 +142,9 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib" + AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib difxapi.lib driver_resources.res" LinkIncremental="2" - AdditionalLibraryDirectories="..\msvc" + AdditionalLibraryDirectories="..\msvc;$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib\driver-resources" GenerateDebugInformation="true" ProgramDatabaseFile="$(TargetDir)$(ProjectName).pdb" SubSystem="1" @@ -219,9 +219,9 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2.lib difxapi.lib" + AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib difxapi.lib driver_resources.res" LinkIncremental="1" - AdditionalLibraryDirectories="..\msvc" + AdditionalLibraryDirectories="..\msvc;$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib\driver-resources" GenerateDebugInformation="true" ProgramDatabaseFile="$(TargetDir)$(ProjectName).pdb" SubSystem="1" @@ -299,9 +299,9 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib difxapi.lib" + AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib difxapi.lib driver_resources.res" LinkIncremental="1" - AdditionalLibraryDirectories="..\msvc" + AdditionalLibraryDirectories="..\msvc;$(SolutionDir)$(PlatformName)\$(ConfigurationName)\lib\driver-resources" GenerateDebugInformation="true" ProgramDatabaseFile="$(TargetDir)$(ProjectName).pdb" SubSystem="1" diff --git a/libusb/os/driver_install.c b/libusb/os/driver_install.c index 3af21f2..5c5cc43 100644 --- a/libusb/os/driver_install.c +++ b/libusb/os/driver_install.c @@ -79,6 +79,19 @@ const char inf[] = "DeviceClassGUID = \"{78a1c341-4539-11d3-b88d-00c04fad5171}\" "WinUSBCoInstaller2.dll=2\n" \ "WdfCoInstaller01009.dll=2\n"; + +struct res { + char* id; + char* subdir; + char* name; +}; + +const struct res resource[] = { {"AMD64_DLL1" , "amd64", "WdfCoInstaller01009.dll"}, + {"AMD64_DLL2" , "amd64", "winusbcoinstaller2.dll"}, + {"X86_DLL1", "x86", "WdfCoInstaller01009.dll"}, + {"X86_DLL2", "x86", "winusbcoinstaller2.dll"} }; +const int nb_resources = sizeof(resource)/sizeof(resource[0]); + char* guid_to_string(const GUID guid) { static char guid_string[MAX_GUID_STRING_LENGTH]; @@ -157,11 +170,12 @@ struct driver_info* list_driverless(void) continue; } */ + // TODO: can't always get a device desc => provide one if ( (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_DEVICEDESC, ®_type, (BYTE*)desc, MAX_KEY_LENGTH, &size)) ) { usbi_warn(NULL, "could not read device description for %d: %s", i, windows_error_str(0)); - continue; +// continue; } r = CM_Get_Device_ID(dev_info_data.DevInst, path, MAX_PATH_LENGTH, 0); @@ -217,6 +231,66 @@ struct driver_info* list_driverless(void) return ret; } +// TODO: dynamic res addon +int extract_dlls(char* path) +{ + HANDLE h; + HGLOBAL h_load; + void *data; + DWORD size; + char filename[MAX_PATH_LENGTH]; + FILE* fd; + int i; + + for (i=0; i< nb_resources; i++) { + h = FindResource(NULL, resource[i].id, "DLL"); + if (h == NULL) { + usbi_dbg("could not find resource %s", resource[i].id); + return -1; + } + h_load = LoadResource(NULL, h); + if (h_load == NULL) { + usbi_dbg("could not load resource %s", resource[i].id); + return -1; + } + data = LockResource(h_load); + if (data == NULL) { + usbi_dbg("could not access data for %s", resource[i].id); + return -1; + } + size = SizeofResource(NULL, h); + if (size == 0) { + usbi_dbg("could not access size of %s", resource[i].id); + return -1; + } + + safe_strcpy(filename, MAX_PATH_LENGTH, path); + safe_strcat(filename, MAX_PATH_LENGTH, "\\"); + safe_strcat(filename, MAX_PATH_LENGTH, resource[i].subdir); + + if ( (_access(filename, 02) != 0) && (CreateDirectory(filename, 0) == 0) ) { + usbi_err(NULL, "could not access directory: %s", filename); + return -1; + } + safe_strcat(filename, MAX_PATH_LENGTH, "\\"); + safe_strcat(filename, MAX_PATH_LENGTH, resource[i].name); + + + fd = fopen(filename, "wb"); + if (fd == NULL) { + usbi_err(NULL, "failed to create file: %s", filename); + return -1; + } + + fwrite(data, size, 1, fd); + fclose(fd); + } + + usbi_dbg("so far, so good"); + return 0; + +} + // Create an inf and extract coinstallers in the directory pointed by path int create_inf(struct driver_info* drv_info, char* path) { @@ -234,6 +308,8 @@ int create_inf(struct driver_info* drv_info, char* path) return -1; } + extract_dlls(path); + safe_strcpy(filename, MAX_PATH_LENGTH, path); safe_strcat(filename, MAX_PATH_LENGTH, "\\libusb_device.inf"); @@ -263,6 +339,8 @@ int create_inf(struct driver_info* drv_info, char* path) 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. @@ -274,7 +352,39 @@ int install_device(char* path) // 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; + } + // TODO: use + r = DriverPackageInstall(path, DRIVER_PACKAGE_LEGACY_MODE|DRIVER_PACKAGE_REPAIR, + NULL, &reboot_needed); usbi_dbg("ret = %X", r); + return 0; }
\ No newline at end of file diff --git a/libusb_2008.sln b/libusb_2008.sln index 04c2e15..e51ad31 100644 --- a/libusb_2008.sln +++ b/libusb_2008.sln @@ -17,6 +17,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xusb", "examples\xusb_2008. EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "driver-install", "driver-install_2008.vcproj", "{9AA0E745-1A0A-4700-8ECB-6A6DE9DBF8B9}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "driver-resources", "driver-resources_2008.vcproj", "{BA852F82-4329-4CBE-82AA-9947FB48AD83}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -60,6 +62,12 @@ Global {9AA0E745-1A0A-4700-8ECB-6A6DE9DBF8B9}.Release|Win32.Build.0 = Release|Win32 {9AA0E745-1A0A-4700-8ECB-6A6DE9DBF8B9}.Release|x64.ActiveCfg = Release|x64 {9AA0E745-1A0A-4700-8ECB-6A6DE9DBF8B9}.Release|x64.Build.0 = Release|x64 + {BA852F82-4329-4CBE-82AA-9947FB48AD83}.Debug|Win32.ActiveCfg = Debug|Win32 + {BA852F82-4329-4CBE-82AA-9947FB48AD83}.Debug|Win32.Build.0 = Debug|Win32 + {BA852F82-4329-4CBE-82AA-9947FB48AD83}.Debug|x64.ActiveCfg = Debug|Win32 + {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/msvc/driver_resources.rc b/msvc/driver_resources.rc new file mode 100644 index 0000000..b74831d --- /dev/null +++ b/msvc/driver_resources.rc @@ -0,0 +1,125 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// DLL +// + +AMD64_DLL1 DLL "E:\\WinDDK\\7600.16385.0\\redist\\wdf\\amd64\\WdfCoInstaller01009.dll" +AMD64_DLL2 DLL "E:\\WinDDK\\7600.16385.0\\redist\\winusb\\amd64\\winusbcoinstaller2.dll" +X86_DLL1 DLL "E:\\WinDDK\\7600.16385.0\\redist\\wdf\\x86\\WdfCoInstaller01009.dll" +X86_DLL2 DLL "E:\\WinDDK\\7600.16385.0\\redist\\winusb\\x86\\winusbcoinstaller2.dll" +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////// +// English (Ireland) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENI) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_EIRE +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,7,0 + PRODUCTVERSION 1,0,7,0 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "libusb.org" + VALUE "FileDescription", "driver_install" + VALUE "FileVersion", "1, 0, 7, 0" + VALUE "InternalName", "driver_install" + VALUE "LegalCopyright", "See individual source files, GNU LGPL v2.1 or later." + VALUE "LegalTrademarks", "http://www.gnu.org/licenses/lgpl-2.1.html" + VALUE "OriginalFilename", "driver_install.dll" + VALUE "ProductName", "driver_install" + VALUE "ProductVersion", "1, 0, 7, 0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // English (Ireland) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + |