summaryrefslogtreecommitdiff
path: root/src/env.h
blob: 1e913a4045e9944278486175bb267a57c1cd6512 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
namespace env
{

class Module;
class SecurityProduct;
class WindowsInfo;
class Metrics;

struct HandleCloser
{
  using pointer = HANDLE;

  void operator()(HANDLE h)
  {
    if (h != INVALID_HANDLE_VALUE) {
      ::CloseHandle(h);
    }
  }
};

using HandlePtr = std::unique_ptr<HANDLE, HandleCloser>;


struct LibraryFreer
{
  using pointer = HINSTANCE;

  void operator()(HINSTANCE h)
  {
    if (h != 0) {
      ::FreeLibrary(h);
    }
  }
};

struct COMReleaser
{
  void operator()(IUnknown* p)
  {
    if (p) {
      p->Release();
    }
  }
};


template <class T>
using COMPtr = std::unique_ptr<T, COMReleaser>;


class Console
{
public:
  Console();
  ~Console();

private:
  bool m_hasConsole;
  FILE* m_in;
  FILE* m_out;
  FILE* m_err;
};


// represents the process's environment
//
class Environment
{
public:
  Environment();
  ~Environment();

  // list of loaded modules in the current process
  //
  const std::vector<Module>& loadedModules() const;

  // information about the operating system
  //
  const WindowsInfo& windowsInfo() const;

  // information about the installed security products
  //
  const std::vector<SecurityProduct>& securityProducts() const;

  // information about displays
  //
  const Metrics& metrics() const;

  // logs the environment
  //
  void dump() const;

private:
  std::vector<Module> m_modules;
  std::unique_ptr<WindowsInfo> m_windows;
  std::vector<SecurityProduct> m_security;
  std::unique_ptr<Metrics> m_metrics;
};


enum class CoreDumpTypes
{
  Mini = 1,
  Data,
  Full
};

// creates a minidump file for the given process
//
bool coredump(CoreDumpTypes type);

// finds another process with the same name as this one and creates a minidump
// file for it
//
bool coredumpOther(CoreDumpTypes type);

} // namespace env