Add --mangle switch for mangling password before hashing
[hashcat.git] / src / ext_nvapi.c
1 /**
2 * Authors.....: Jens Steube <jens.steube@gmail.com>
3 * Gabriele Gristina <matrix@hashcat.net>
4 *
5 * License.....: MIT
6 */
7
8 #include <ext_nvapi.h>
9
10 int nvapi_init (NVAPI_PTR *nvapi)
11 {
12 if (!nvapi) return -1;
13
14 memset (nvapi, 0, sizeof (NVAPI_PTR));
15
16 #ifdef _WIN
17 #if __x86_64__
18 nvapi->lib = hc_dlopen ("nvapi64.dll");
19 #elif __x86__
20 nvapi->lib = hc_dlopen ("nvapi.dll");
21 #endif
22 #else
23 nvapi->lib = hc_dlopen ("nvapi.so", RTLD_NOW); // uhm yes, but .. yeah
24 #endif
25
26 if (!nvapi->lib)
27 {
28 //if (data.quiet == 0)
29 // log_info ("WARNING: load NVAPI library failed, proceed without NVAPI HWMon enabled.");
30
31 return -1;
32 }
33
34 HC_LOAD_FUNC(nvapi, nvapi_QueryInterface, NVAPI_QUERYINTERFACE, NVAPI, 0)
35 HC_LOAD_ADDR(nvapi, NvAPI_Initialize, NVAPI_INITIALIZE, nvapi_QueryInterface, 0x0150E828, NVAPI, 0)
36 HC_LOAD_ADDR(nvapi, NvAPI_Unload, NVAPI_UNLOAD, nvapi_QueryInterface, 0xD22BDD7E, NVAPI, 0)
37 HC_LOAD_ADDR(nvapi, NvAPI_GetErrorMessage, NVAPI_GETERRORMESSAGE, nvapi_QueryInterface, 0x6C2D048C, NVAPI, 0)
38 HC_LOAD_ADDR(nvapi, NvAPI_EnumPhysicalGPUs, NVAPI_ENUMPHYSICALGPUS, nvapi_QueryInterface, 0xE5AC921F, NVAPI, 0)
39 HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesInfo, NVAPI_GPU_GETPERFPOLICIESINFO, nvapi_QueryInterface, 0x409D9841, NVAPI, 0)
40 HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesStatus, NVAPI_GPU_GETPERFPOLICIESSTATUS, nvapi_QueryInterface, 0x3D358A0C, NVAPI, 0)
41 HC_LOAD_ADDR(nvapi, NvAPI_GPU_SetCoolerLevels, NVAPI_GPU_SETCOOLERLEVELS, nvapi_QueryInterface, 0x891FA0AE, NVAPI, 0)
42 HC_LOAD_ADDR(nvapi, NvAPI_GPU_RestoreCoolerSettings, NVAPI_GPU_RESTORECOOLERSETTINGS, nvapi_QueryInterface, 0x8F6ED0FB, NVAPI, 0)
43
44 return 0;
45 }
46
47 void nvapi_close (NVAPI_PTR *nvapi)
48 {
49 if (nvapi)
50 {
51 if (nvapi->lib)
52 hc_dlclose (nvapi->lib);
53
54 myfree (nvapi);
55 }
56 }
57
58 int hm_NvAPI_Initialize (NVAPI_PTR *nvapi)
59 {
60 if (!nvapi) return -1;
61
62 NvAPI_Status NvAPI_rc = nvapi->NvAPI_Initialize ();
63
64 if (NvAPI_rc == NVAPI_LIBRARY_NOT_FOUND) NvAPI_rc = NVAPI_OK; // not a bug
65
66 if (NvAPI_rc != NVAPI_OK)
67 {
68 NvAPI_ShortString string = { 0 };
69
70 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
71
72 log_info ("WARN: %s %d %s\n", "NvAPI_Initialize()", NvAPI_rc, string);
73 }
74
75 return NvAPI_rc;
76 }
77
78 int hm_NvAPI_Unload (NVAPI_PTR *nvapi)
79 {
80 if (!nvapi) return -1;
81
82 NvAPI_Status NvAPI_rc = nvapi->NvAPI_Unload ();
83
84 if (NvAPI_rc != NVAPI_OK)
85 {
86 NvAPI_ShortString string = { 0 };
87
88 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
89
90 log_info ("WARN: %s %d %s\n", "NvAPI_Unload()", NvAPI_rc, string);
91 }
92
93 return NvAPI_rc;
94 }
95
96 int hm_NvAPI_GetErrorMessage (NVAPI_PTR *nvapi, NvAPI_Status NvAPI_rc, NvAPI_ShortString string)
97 {
98 if (!nvapi) return -1;
99
100 return nvapi->NvAPI_GetErrorMessage (NvAPI_rc, string);
101 }
102
103 int hm_NvAPI_EnumPhysicalGPUs (NVAPI_PTR *nvapi, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount)
104 {
105 if (!nvapi) return -1;
106
107 NvAPI_Status NvAPI_rc = nvapi->NvAPI_EnumPhysicalGPUs (nvGPUHandle, pGpuCount);
108
109 if (NvAPI_rc != NVAPI_OK)
110 {
111 NvAPI_ShortString string = { 0 };
112
113 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
114
115 log_info ("WARN: %s %d %s\n", "NvAPI_EnumPhysicalGPUs()", NvAPI_rc, string);
116 }
117
118 return NvAPI_rc;
119 }
120
121 int hm_NvAPI_GPU_GetPerfPoliciesInfo (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info)
122 {
123 if (!nvapi) return -1;
124
125 NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetPerfPoliciesInfo (hPhysicalGpu, perfPolicies_info);
126
127 if (NvAPI_rc != NVAPI_OK)
128 {
129 NvAPI_ShortString string = { 0 };
130
131 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
132
133 log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetPerfPoliciesInfo()", NvAPI_rc, string);
134 }
135
136 return NvAPI_rc;
137 }
138
139 int hm_NvAPI_GPU_GetPerfPoliciesStatus (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status)
140 {
141 if (!nvapi) return -1;
142
143 NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetPerfPoliciesStatus (hPhysicalGpu, perfPolicies_status);
144
145 if (NvAPI_rc != NVAPI_OK)
146 {
147 NvAPI_ShortString string = { 0 };
148
149 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
150
151 log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetPerfPoliciesStatus()", NvAPI_rc, string);
152 }
153
154 return NvAPI_rc;
155 }
156
157 int hm_NvAPI_GPU_SetCoolerLevels (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex, NV_GPU_COOLER_LEVELS *pCoolerLevels)
158 {
159 if (!nvapi) return -1;
160
161 NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_SetCoolerLevels (hPhysicalGpu, coolerIndex, pCoolerLevels);
162
163 if (NvAPI_rc != NVAPI_OK)
164 {
165 NvAPI_ShortString string = { 0 };
166
167 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
168
169 log_info ("WARN: %s %d %s\n", "NvAPI_GPU_SetCoolerLevels()", NvAPI_rc, string);
170 }
171
172 return NvAPI_rc;
173 }
174
175 int hm_NvAPI_GPU_RestoreCoolerSettings (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex)
176 {
177 if (!nvapi) return -1;
178
179 NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_RestoreCoolerSettings (hPhysicalGpu, coolerIndex);
180
181 if (NvAPI_rc != NVAPI_OK)
182 {
183 NvAPI_ShortString string = { 0 };
184
185 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
186
187 log_info ("WARN: %s %d %s\n", "NvAPI_GPU_RestoreCoolerSettings()", NvAPI_rc, string);
188 }
189
190 return NvAPI_rc;
191 }
192
193 #ifdef __MINGW64__
194
195 void __security_check_cookie (uintptr_t _StackCookie)
196 {
197 (void) _StackCookie;
198 }
199
200 void __GSHandlerCheck ()
201 {
202 }
203
204 #endif