wbenny / pdbex

pdbex is a utility for reconstructing structures and unions from the PDB into compilable C headers
MIT License
814 stars 160 forks source link

File not found, invalid file name conversion #7

Closed hfiref0x closed 4 years ago

hfiref0x commented 5 years ago

Actually it doesn't work for me at all. I know about #2 however even giving to pdbex compiled version these dlls (confirmed pdbex loaded that msdia140 dll not system msdia) does not solve this problem here. The root of this problem is a unicode conversion of file path in routine

https://github.com/wbenny/pdbex/blob/3fe750269959d4de71582335a9a28e26b3f5fed1/Source/PDB.cpp#L127-L128

this conversion produce trash on output thus "file not found" error will be printed as result always. Not quite sure what is wrong with this fancy C++ stuff, but I would instead use MultiByteToWideChar (and I fixed that for myself) as loadDataFromPdb expect LPCOLESTR which is WCHAR*.

wbenny commented 5 years ago

That's interesting, I've never run into this issue. What path did you use? Did it have any special characters?

wbenny commented 5 years ago

Check the latest version, please. I've replaced string_converter with MultiByteToWideChar.

hfiref0x commented 5 years ago

What path did you use? Did it have any special characters?

c:\Install>pdbex * c:\install\7601.pdb -o c:\install\extract.h

Check the latest version

The latest release 0.18 produce zero size output file. Double checked - msdia140, symsrv from Library/x64 present in program directory.

Unfortunately I cannot compile anymore because 2017 does not understand new C++ features.

contains': is not a member of 'std::map'

hfiref0x commented 4 years ago

Got VS2019, compiled source and seems this problem resolved. I'm able to produce output from above test pdb. It seems the last release I tried failed because directory where pdbex.exe was located contained x64 version of msdia140, symsrv dlls while application from this github release section is x86.

There is a logical bug in code related to loading of msdia140. If this dll not exist or has wrong architecture (like in my case) the above code will produce incorrect result, later this will crash pdbex as invalid memory (NULL) will be dereferenced.

https://github.com/wbenny/pdbex/blob/000374f6348145c3afa4e17cff9fcd175f39463e/Source/PDB.cpp#L113-L119

LoadDiaViaCoCreateInstance->CoCreateInstance return error 80040154 next SymbolModuleBase::LoadDiaViaLoadLibrary returns FALSE despite return value declared as HRESULT.

Your code treat LoadDiaViaLoadLibrary result as HRESULT, macro FAILED check if it is < 0, and it is not because Result = FALSE. Thus check successfully passed and program continue it execution until first attemt to use m_DataSource (which is NULL).

This must return HRESULT instead of FALSE.

https://github.com/wbenny/pdbex/blob/000374f6348145c3afa4e17cff9fcd175f39463e/Source/PDB.cpp#L74-L78

https://github.com/wbenny/pdbex/blob/000374f6348145c3afa4e17cff9fcd175f39463e/Source/PDB.cpp#L83-L87

https://github.com/wbenny/pdbex/blob/000374f6348145c3afa4e17cff9fcd175f39463e/Source/PDB.cpp#L92-L95

I would additionally add more diagnostic messages in case if required dlls are missing of having diffrent machine type (Result = HRESULT_FROM_WIN32(ERROR_BAD_EXE_FORMAT) : %1 is not a valid Win32 application. ).