VectorNav C++ Library
dllvalidator.h
1 #ifndef _DLLVALIDATOR_H_
2 #define _DLLVALIDATOR_H_
3 
4 #if defined WIN32 && defined DLL_VALIDATOR
5 
6 #include <string>
7 #include <vector>
8 
9 #if defined(_MSC_VER)
10  // Disable a bunch of warnings from 3rd party library.
11  #pragma warning(push)
12  #pragma warning(disable:4091)
13  #pragma warning(disable:4251)
14  #pragma warning(disable:4275)
15 #endif
16 
17 #include "PeLib.h"
18 
19 #if defined (_MSC_VER)
20  #pragma warning(pop)
21 #endif
22 
23 // Class to validate the input DLL exists and that all of it's first level
24 // dependencies exist as well.
25 class DllValidator
26 {
27 public:
28  DllValidator(std::string dllName, std::string currentDirectory);
29 
30  bool initialize();
31 
32  bool hasDllNames();
33 
34  void getDllNames(std::vector<std::string>& dllNamesOut);
35 
36  void getMissingDllNames(std::vector<std::string>& missingDllNamesOut);
37 
38  bool validate();
39 
40 private:
41  struct DllValidatorVisitor : public PeLib::PeFileVisitor
42  {
43  //template<int bits>
44  //void dumpImportDirectory(PeLib::PeFile& pef, std::vector<std::string>& dllNamesOut);
45 
46  virtual void callback(PeLib::PeFile32 &file);
47 
48  virtual void callback(PeLib::PeFile64 &file);
49 
50  std::vector<std::string> mRequiredDlls;
51  };
52 
53  DllValidator();
54 
55  bool mIsInitialized;
56  bool mIsValid;
57  DllValidatorVisitor mVisitor;
58  PeLib::PeFile* mPeFile;
59  std::string mFileName;
60  std::string mWorkingDirectory;
61  std::vector<std::string> mMissingDlls;
62 };
63 
64 #endif
65 
66 #endif