Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embedder.exe fails when USER_DIR in config.h is defined #191

Closed
JSB2500 opened this issue Jun 9, 2020 · 10 comments
Closed

embedder.exe fails when USER_DIR in config.h is defined #191

JSB2500 opened this issue Jun 9, 2020 · 10 comments

Comments

@JSB2500
Copy link

JSB2500 commented Jun 9, 2020

Version: v1.3.1

When USER_DIR in config.h is defined, embedded.exe reports this error: "EMBED C:...\libwdi\libwdi\libusb0.dll embedder : error: Could not open file 'C:...\libwdi\libwdi\libusb0.dll'."

Suggested fix: Change line 298 of embedder.c from:
embeddable[i].reuse_last = 0;
to:
embeddable[i].reuse_last = embeddable_fixed[i].reuse_last;

@mcuee
Copy link
Contributor

mcuee commented Jul 7, 2021

Yes I can reproduce this issue with latest git.

Build started...
1>------ Build started: Project: embedder, Configuration: Release Win32 ------
1>embedder.c
1>Generating code
1>4 of 18 functions (22.2%) were compiled, the rest were copied from previous compilation.
1>  2 functions were new in current compilation
1>  1 functions had inline decision re-evaluated but remain unchanged
1>Finished generating code
1>embedder.vcxproj -> C:\work\libusb\libwdi\libwdi\embedder.exe
2>------ Build started: Project: libwdi (static), Configuration: Release Win32 ------
3>------ Skipped Build: Project: libwdi (dll), Configuration: Release Win32 ------
3>Project not selected to build for this solution configuration 
2>Embedding binary resources
2>unable to stat 'C:\work\libusb\libwdi\libwdi\libusb0.dll' - assuming rebuild needed
2>  EMBED  C:\Program Files (x86)\Windows Kits\10\redist\wdf\x86\WdfCoInstaller01011.dll (2021.01.14)
2>  EMBED  C:\Program Files (x86)\Windows Kits\10\redist\wdf\x86\winusbcoinstaller2.dll (2021.01.14)
2>  EMBED  C:\Program Files (x86)\Windows Kits\10\redist\wdf\x64\WdfCoInstaller01011.dll (2021.01.14)
2>  EMBED  C:\Program Files (x86)\Windows Kits\10\redist\wdf\x64\winusbcoinstaller2.dll (2021.01.14)
2>  EMBED  C:\libusb-win32-1.2.6.0-bin\bin\x86\libusb0_x86.dll (2021.07.07)
2>  EMBED  C:\libusb-win32-1.2.6.0-bin\bin\x86\install-filter.exe (2021.07.07)
2>embedder : error : Could not open file 'C:\work\libusb\libwdi\libwdi\libusb0.dll'.
2>  EMBED  C:\work\libusb\libwdi\libwdi\libusb0.dll
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(145,5): error MSB3073: The command "cd C:\work\libusb\libwdi\libwdi\.msvc\\..
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(145,5): error MSB3073: embedder embedded.h
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(145,5): error MSB3073: :VCEnd" exited with code 1.
2>Done building project "libwdi_static.vcxproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 7 up-to-date, 1 skipped ==========

@mcuee
Copy link
Contributor

mcuee commented Jul 7, 2021

And I can confirm the fix works.

Build started...
1>------ Build started: Project: embedder, Configuration: Release Win32 ------
1>embedder.c
1>Generating code
1>2 of 18 functions (11.1%) were compiled, the rest were copied from previous compilation.
1>  0 functions were new in current compilation
1>  0 functions had inline decision re-evaluated but remain unchanged
1>Finished generating code
1>embedder.vcxproj -> C:\work\libusb\libwdi\libwdi\embedder.exe
2>------ Build started: Project: libwdi (static), Configuration: Release Win32 ------
3>------ Skipped Build: Project: libwdi (dll), Configuration: Release Win32 ------
3>Project not selected to build for this solution configuration 
2>Embedding binary resources
2>  EMBED  C:\Program Files (x86)\Windows Kits\10\redist\wdf\x86\WdfCoInstaller01011.dll (2021.01.14)
2>  EMBED  C:\Program Files (x86)\Windows Kits\10\redist\wdf\x86\winusbcoinstaller2.dll (2021.01.14)
2>  EMBED  C:\Program Files (x86)\Windows Kits\10\redist\wdf\x64\WdfCoInstaller01011.dll (2021.01.14)
2>  EMBED  C:\Program Files (x86)\Windows Kits\10\redist\wdf\x64\winusbcoinstaller2.dll (2021.01.14)
2>  EMBED  C:\libusb-win32-1.2.6.0-bin\bin\x86\libusb0_x86.dll (2021.07.07)
2>  EMBED  C:\libusb-win32-1.2.6.0-bin\bin\x86\install-filter.exe (2021.07.07)
2>  EMBED  C:\libusb-win32-1.2.6.0-bin\bin\x86\libusb0.sys (2021.07.07)
2>  EMBED  C:\libusb-win32-1.2.6.0-bin\bin\amd64\libusb0.dll (2021.07.07)
2>  EMBED  C:\libusb-win32-1.2.6.0-bin\bin\amd64\libusb0.sys (2021.07.07)
2>  EMBED  C:\libusb-win32-1.2.6.0-bin\bin\amd64\install-filter.exe (2021.07.07)
2>  EMBED  C:\libusb-win32-1.2.6.0-bin\installer_license.txt (2021.07.07)
2>  EMBED  C:\libusbK-3.0.8.0-bin\bin\sys\x86\libusbK.sys (2021.07.07)
2>  EMBED  C:\libusbK-3.0.8.0-bin\bin\dll\x86\libusbK.dll (2021.07.07)
2>  EMBED  C:\libusbK-3.0.8.0-bin\bin\sys\amd64\libusbK.sys (2021.07.07)
2>  EMBED  C:\libusbK-3.0.8.0-bin\bin\dll\amd64\libusbK.dll (2021.07.07)
2>  EMBED  C:\work\libusb\libwdi\Win32\Release\helper\installer_x86.exe (2021.07.07)
2>  EMBED  C:\work\libusb\libwdi\x64\Release\helper\installer_x64.exe (2021.07.07)
2>  EMBED  C:\work\libusb\libwdi\libwdi\winusb.inf.in (2021.06.09)
2>  EMBED  C:\work\libusb\libwdi\libwdi\libusb0.inf.in (2021.06.09)
2>  EMBED  C:\work\libusb\libwdi\libwdi\libusbk.inf.in (2021.06.09)
2>  EMBED  C:\work\libusb\libwdi\libwdi\usbser.inf.in (2021.06.09)
2>  EMBED  C:\work\libusb\libwdi\libwdi\winusb.cat.in (2021.06.09)
2>  EMBED  C:\work\libusb\libwdi\libwdi\libusb0.cat.in (2021.06.09)
2>  EMBED  C:\work\libusb\libwdi\libwdi\libusbk.cat.in (2021.06.09)
2>  EMBED  C:\work\libusb\libwdi\libwdi\usbser.cat.in (2021.06.09)
2>  EMBED  C:\work\cyusb\driver\bin\Win10\x64\cyusb3.cat (2021.07.07)
2>  EMBED  C:\work\cyusb\driver\bin\Win10\x64\cyusb3.inf (2021.07.07)
2>  EMBED  C:\work\cyusb\driver\bin\Win10\x64\cyusb3.pdb (2021.07.07)
2>  EMBED  C:\work\cyusb\driver\bin\Win10\x64\cyusb3.sys (2021.07.07)
2>  EMBED  C:\work\cyusb\driver\bin\Win10\x86\cyusb3.cat (2021.07.07)
2>  EMBED  C:\work\cyusb\driver\bin\Win10\x86\cyusb3.inf (2021.07.07)
2>  EMBED  C:\work\cyusb\driver\bin\Win10\x86\cyusb3.pdb (2021.07.07)
2>  EMBED  C:\work\cyusb\driver\bin\Win10\x86\cyusb3.sys (2021.07.07)
2>libwdi.c
2>libwdi_dlg.c
2>logging.c
2>pki.c
2>tokenizer.c
2>libwdi_static.vcxproj -> C:\work\libusb\libwdi\Win32\Release\lib\libwdi.lib
4>------ Build started: Project: wdi-simple, Configuration: Release Win32 ------
5>------ Build started: Project: zadic, Configuration: Release Win32 ------
6>------ Build started: Project: zadig, Configuration: Release Win32 ------
4>Generating code
5>Generating code
6>Generating code
4>37 of 93 functions (39.8%) were compiled, the rest were copied from previous compilation.
4>  0 functions were new in current compilation
4>  1 functions had inline decision re-evaluated but remain unchanged
4>Finished generating code
5>12 of 90 functions (13.3%) were compiled, the rest were copied from previous compilation.
5>  0 functions were new in current compilation
5>  2 functions had inline decision re-evaluated but remain unchanged
5>Finished generating code
6>13 of 253 functions ( 5.1%) were compiled, the rest were copied from previous compilation.
6>  0 functions were new in current compilation
6>  4 functions had inline decision re-evaluated but remain unchanged
4>wdi-simple.vcxproj -> C:\work\libusb\libwdi\Win32\Release\examples\wdi-simple.exe
6>Finished generating code
5>zadic.vcxproj -> C:\work\libusb\libwdi\Win32\Release\examples\zadic.exe
6>zadig.vcxproj -> C:\work\libusb\libwdi\Win32\Release\examples\zadig.exe
========== Build: 5 succeeded, 0 failed, 4 up-to-date, 1 skipped ==========

@mcuee
Copy link
Contributor

mcuee commented Jul 7, 2021

However, Zadig will often crash with the above configuration, probably due to the embedded Cypress USB driver.

@mcuee
Copy link
Contributor

mcuee commented Jul 7, 2021

I just tried with one build which remove WinUSB/libusbk/libusb-win32 but only with Cypress, with or without the changes, Zadig will crash. So I guess I do not know how to use the option of user defined driver yet. IMHO this is not well documented.

Rebuild started...
1>------ Rebuild All started: Project: detect_64build, Configuration: Release Win32 ------
2>------ Rebuild All started: Project: installer_x86, Configuration: Release Win32 ------
3>------ Rebuild All started: Project: installer_x64, Configuration: Release x64 ------
4>------ Rebuild All started: Project: getopt, Configuration: Release Win32 ------
1>detected 32 bit build
5>------ Rebuild All started: Project: embedder, Configuration: Release Win32 ------
2>installer.c
4>getopt.c
3>installer.c
4>getopt1.c
5>embedder.c
4>getopt.vcxproj -> C:\work\libusb\libwdi\Win32\Release\lib\getopt.lib
5>Generating code
5>Previous IPDB not found, fall back to full compilation.
2>Generating code
3>Generating code
5>All 18 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
2>Previous IPDB not found, fall back to full compilation.
3>Previous IPDB not found, fall back to full compilation.
5>Finished generating code
2>All 31 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
2>Finished generating code
3>All 31 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
3>Finished generating code
5>embedder.vcxproj -> C:\work\libusb\libwdi\libwdi\embedder.exe
2>installer_x86.vcxproj -> C:\work\libusb\libwdi\Win32\Release\helper\installer_x86.exe
3>installer_x64.vcxproj -> C:\work\libusb\libwdi\x64\Release\helper\installer_x64.exe
6>------ Rebuild All started: Project: libwdi (static), Configuration: Release Win32 ------
7>------ Skipped Rebuild All: Project: libwdi (dll), Configuration: Release Win32 ------
7>Project not selected to build for this solution configuration 
6>Embedding binary resources
6>detected change for 'C:\work\libusb\libwdi\Win32\Release\helper\installer_x86.exe'
6>  EMBED  C:\work\libusb\libwdi\Win32\Release\helper\installer_x86.exe (2021.07.07)
6>  EMBED  C:\work\libusb\libwdi\x64\Release\helper\installer_x64.exe (2021.07.07)
6>  EMBED  C:\work\libusb\libwdi\libwdi\winusb.inf.in (2021.06.09)
6>  EMBED  C:\work\libusb\libwdi\libwdi\libusb0.inf.in (2021.06.09)
6>  EMBED  C:\work\libusb\libwdi\libwdi\libusbk.inf.in (2021.06.09)
6>  EMBED  C:\work\libusb\libwdi\libwdi\usbser.inf.in (2021.06.09)
6>  EMBED  C:\work\libusb\libwdi\libwdi\winusb.cat.in (2021.06.09)
6>  EMBED  C:\work\libusb\libwdi\libwdi\libusb0.cat.in (2021.06.09)
6>  EMBED  C:\work\libusb\libwdi\libwdi\libusbk.cat.in (2021.06.09)
6>  EMBED  C:\work\libusb\libwdi\libwdi\usbser.cat.in (2021.06.09)
6>  EMBED  C:\work\cyusb\driver\bin\Win10\x64\cyusb3.cat (2021.07.07)
6>  EMBED  C:\work\cyusb\driver\bin\Win10\x64\cyusb3.inf (2021.07.07)
6>  EMBED  C:\work\cyusb\driver\bin\Win10\x64\cyusb3.pdb (2021.07.07)
6>  EMBED  C:\work\cyusb\driver\bin\Win10\x64\cyusb3.sys (2021.07.07)
6>  EMBED  C:\work\cyusb\driver\bin\Win10\x86\cyusb3.cat (2021.07.07)
6>  EMBED  C:\work\cyusb\driver\bin\Win10\x86\cyusb3.inf (2021.07.07)
6>  EMBED  C:\work\cyusb\driver\bin\Win10\x86\cyusb3.pdb (2021.07.07)
6>  EMBED  C:\work\cyusb\driver\bin\Win10\x86\cyusb3.sys (2021.07.07)
6>libwdi.c
6>libwdi_dlg.c
6>logging.c
6>pki.c
6>tokenizer.c
6>vid_data.c
6>libwdi_static.vcxproj -> C:\work\libusb\libwdi\Win32\Release\lib\libwdi.lib
8>------ Rebuild All started: Project: wdi-simple, Configuration: Release Win32 ------
9>------ Rebuild All started: Project: zadic, Configuration: Release Win32 ------
10>------ Rebuild All started: Project: zadig, Configuration: Release Win32 ------
8>wdi-simple.c
9>zadic.c
10>zadig_net.c
8>Generating code
9>Generating code
10>profile.c
8>Previous IPDB not found, fall back to full compilation.
9>Previous IPDB not found, fall back to full compilation.
10>zadig.c
8>All 93 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
8>Finished generating code
9>All 90 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
9>Finished generating code
8>wdi-simple.vcxproj -> C:\work\libusb\libwdi\Win32\Release\examples\wdi-simple.exe
9>zadic.vcxproj -> C:\work\libusb\libwdi\Win32\Release\examples\zadic.exe
10>zadig_parser.c
10>zadig_stdlg.c
10>Generating code
10>Previous IPDB not found, fall back to full compilation.
10>All 253 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
10>Finished generating code
10>zadig.vcxproj -> C:\work\libusb\libwdi\Win32\Release\examples\zadig.exe
========== Rebuild All: 9 succeeded, 0 failed, 1 skipped ==========


@mcuee
Copy link
Contributor

mcuee commented Jul 7, 2021

It seems to me I need to do something to create a template inf and cat file but it is a bit more complicated than that.
https://github.com/pbatard/libwdi/wiki/Install#using-a-custom-driver-file-with-libwdi

@mcuee
Copy link
Contributor

mcuee commented Jul 20, 2021

It seems to me this is not a real issue but rather lack of documentation to use the custom driver file. I was trying to embed cyusb3 but failed.

@mcuee
Copy link
Contributor

mcuee commented Jul 20, 2021

One simple solution is to use dpscat.exe from libusbk to sign a custom driver package, then you can use Windows Device Manager to install the file. Windows 10 will pop up a warning message but the installation will be successful.

dpscat is part of libusbk and it uses part of the libwdi codes.
https://github.com/mcuee/libusbk/releases

Example run log:

C:\work\libusb\libusbK-3.1.0.0-bin\bin\exe\amd64\cyusb3\Win10\x64> .\dpscat.exe
Copyright(c) 2012 Travis Lee Robinson. (DUAL BSD/GPL)
Portions Copyright(c) Pete Batard. (LGPL)
C:\work\libusb\libusbK-3.1.0.0-bin\bin\exe\amd64\cyusb3\Win10\x64>
Actual section to install: Device.NTamd64
Found Hwid: USB\VID_04B4&PID_00FC
Found Hwid: USB\VID_04B4&PID_00FE
Found Hwid: USB\VID_04B4&PID_00FD
Found Hwid: USB\VID_04B4&PID_00FB
Hash calculated for: .\cyusb3.inf
Using INF guid..
Hash added..
Catalog file 'CYUSB3.cat' created..
Deleted existing certificate: CN="Cypress (cyusb3.inf) [Self]" (Root store)
Deleted existing certificate: CN="Cypress (cyusb3.inf) [Self]" (TrustedPublisher store)
Set Enhanced Key Usage, URL and CPS..
Created new key container..
Generated new keypair.
Created new self-signed certificate: CN="Cypress (cyusb3.inf) [Self]"
Added CN="Cypress (cyusb3.inf) [Self]" certificate to 'Root' and 'TrustedPublisher' stores..
Signed file: C:\work\libusb\libusbK-3.1.0.0-bin\bin\exe\amd64\cyusb3\Win10\x64\CYUSB3.cat
Deleted private key..
Success!

Better method: Use dpinst32.exe/dpinst64.exe from a libusbK driver package and copy dpinst.xml into your driver folder as well. Then you can run dpinst32/dpinst64 to install the driver package for 32bit/64bit respectively.

C:\work\libusb\libusbK-3.1.0.0-bin\bin\exe\amd64\cyusb3\Win10\x64> ls

    Directory: C:\work\libusb\libusbK-3.1.0.0-bin\bin\exe\amd64\cyusb3\Win10\x64

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           7/20/2021 10:32 PM           2034 cyusb3.cat
-a---           7/20/2021 10:29 PM           3864 cyusb3.inf
-a---            5/8/2018 11:05 AM         937984 cyusb3.pdb
-a---            5/8/2018 11:05 AM          74624 cyusb3.sys
-a---           7/20/2021 10:12 PM            661 dpinst.xml
-a---           7/20/2021 10:12 PM        1050104 dpinst64.exe

C:\work\libusb\libusbK-3.1.0.0-bin\bin\exe\amd64\cyusb3\Win10\x64> .\dpinst64.exe

@mcuee
Copy link
Contributor

mcuee commented Jul 20, 2021

From Travis -- but I have not tried it yet.

You can also use some of the files from a libusbK driver package to create a self-contained "InstallDriver.exe"

  1. Use the 7za.exe included in the lbusbK driver package to zip all of your driver files to _DriverFiles.7z (You must use the 7za.exe from the libusbK package)
  2. Copy the 7zDP_LZMA.* files, dpinst* files, and dpscat.exe into your driver folder
  3. Execute: "COPY /B "7zDP_LZMA.sfx"+"7zDP_LZMA.cfg"+"_DriverFiles.7z" "InstallDriver.exe"

@mcuee
Copy link
Contributor

mcuee commented Jul 20, 2021

In reality, once you use the dpscat to build the driver package, you can use different method to create the driver installer, not necessary to follow the above libusbk method or the method in libwdi Zadig or libwdi wid-simple example.

@pbatard pbatard closed this as completed in e1257a8 Sep 4, 2021
NikhilNarayana pushed a commit to project-slippi/libwdi that referenced this issue Oct 2, 2021
* With thanks to JSB2500 for the fix suggestion
* Closes pbatard#191
* Also fix a CodeQL reported issue
@mcuee
Copy link
Contributor

mcuee commented Jul 20, 2023

Example Installation using Zadig.

Zadig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants