Added CreateWellKnownSid and IsWellKnownSid imports.
authorIain Patterson <me@iain.cx>
Tue, 28 Jan 2014 22:56:02 +0000 (22:56 +0000)
committerIain Patterson <me@iain.cx>
Wed, 29 Jan 2014 20:37:34 +0000 (20:37 +0000)
Visual Studio 2008 doesn't recognise the functions so we need to load
them to the imports table.

imports.cpp
imports.h

index d0970bd..18c8bb0 100644 (file)
@@ -69,10 +69,24 @@ int get_imports() {
   }
   else if (error != ERROR_MOD_NOT_FOUND) return 1;
 
+  imports.advapi32 = get_dll(_T("advapi32.dll"), &error);
+  if (imports.advapi32) {
+    imports.CreateWellKnownSid = (CreateWellKnownSid_ptr) get_import(imports.advapi32, "CreateWellKnownSid", &error);
+    if (! imports.CreateWellKnownSid) {
+      if (error != ERROR_PROC_NOT_FOUND) return 6;
+    }
+    imports.IsWellKnownSid = (IsWellKnownSid_ptr) get_import(imports.advapi32, "IsWellKnownSid", &error);
+    if (! imports.IsWellKnownSid) {
+      if (error != ERROR_PROC_NOT_FOUND) return 7;
+    }
+  }
+  else if (error != ERROR_MOD_NOT_FOUND) return 5;
+
   return 0;
 }
 
 void free_imports() {
   if (imports.kernel32) FreeLibrary(imports.kernel32);
+  if (imports.advapi32) FreeLibrary(imports.advapi32);
   ZeroMemory(&imports, sizeof(imports));
 }
index 8b36778..03e2df1 100644 (file)
--- a/imports.h
+++ b/imports.h
@@ -4,12 +4,17 @@
 typedef BOOL (WINAPI *AttachConsole_ptr)(DWORD);
 typedef BOOL (WINAPI *SleepConditionVariableCS_ptr)(PCONDITION_VARIABLE, PCRITICAL_SECTION, DWORD);
 typedef void (WINAPI *WakeConditionVariable_ptr)(PCONDITION_VARIABLE);
+typedef BOOL (WINAPI *CreateWellKnownSid_ptr)(WELL_KNOWN_SID_TYPE, SID *, SID *, unsigned long *);
+typedef BOOL (WINAPI *IsWellKnownSid_ptr)(SID *, WELL_KNOWN_SID_TYPE);
 
 typedef struct {
   HMODULE kernel32;
+  HMODULE advapi32;
   AttachConsole_ptr AttachConsole;
   SleepConditionVariableCS_ptr SleepConditionVariableCS;
   WakeConditionVariable_ptr WakeConditionVariable;
+  CreateWellKnownSid_ptr CreateWellKnownSid;
+  IsWellKnownSid_ptr IsWellKnownSid;
 } imports_t;
 
 HMODULE get_dll(const TCHAR *, unsigned long *);