
#ifndef __COMMON_H_
#define __COMMON_H_

/**
 * @file: common.c
 *
 * Tento soubor obsahuje ruzne definice konstant, typu a funkci, ktere
 * plni podpurnou ulohu. Napriklad dovoluji povolit urcita opravneni atd.
 * Nektere z nich jsou implementovany v souboru common.c.
 */


#include <windows.h>


// Nazev privilegia nutneho k nacitani ovladacu do jadra
#define LOAD_DRIVER_PRIVILEGE  L"SeLoadDriverPrivilege"

// Definice nekterych konstant NTSTATUS uzitecnych pri volani NtXXX funkci.
#define STATUS_SUCCESS                 0x00000000L
#define STATUS_UNSUCCESSFUL            0xC0000001L
#define STATUS_INFO_LENGTH_MISMATCH    0xC0000004L

// Definice polozky SystemInformationClass z funkce NtQuery(set)SystemInformation
typedef enum _SYSTEM_INFORMATION_CLASS {
  SystemBasicInformation,
  SystemProcessorInformation,     
  SystemPerformanceInformation,
  SystemTimeOfDayInformation,
  SystemPathInformation,
  SystemProcessInformation,
  SystemCallCountInformation,
  SystemDeviceInformation,
  SystemProcessorPerformanceInformation,
  SystemFlagsInformation,
  SystemCallTimeInformation,
  SystemModuleInformation,
  SystemLocksInformation,
  SystemStackTraceInformation,
  SystemPagedPoolInformation,
  SystemNonPagedPoolInformation,
  SystemHandleInformation,
  SystemObjectInformation,
  SystemPageFileInformation,
  SystemVdmInstemulInformation,
  SystemVdmBopInformation,
  SystemFileCacheInformation,
  SystemPoolTagInformation,
  SystemInterruptInformation,
  SystemDpcBehaviorInformation,
  SystemFullMemoryInformation,
  SystemLoadGdiDriverInformation,
  SystemUnloadGdiDriverInformation,
  SystemTimeAdjustmentInformation,
  SystemSummaryMemoryInformation,
  SystemMirrorMemoryInformation,
  SystemPerformanceTraceInformation,
  SystemObsolete0,
  SystemExceptionInformation,
  SystemCrashDumpStateInformation,
  SystemKernelDebuggerInformation,
  SystemContextSwitchInformation,
  SystemRegistryQuotaInformation,
  SystemExtendServiceTableInformation,
  SystemPrioritySeperation,
  SystemVerifierAddDriverInformation,
  SystemVerifierRemoveDriverInformation,
  SystemProcessorIdleInformation,
  SystemLegacyDriverInformation,
  SystemCurrentTimeZoneInformation,
  SystemLookasideInformation,
  SystemTimeSlipNotification,
  SystemSessionCreate,
  SystemSessionDetach,
  SystemSessionInformation,
  SystemRangeStartInformation,
  SystemVerifierInformation,
  SystemVerifierThunkExtend,
  SystemSessionProcessInformation,
  SystemLoadGdiDriverInSystemSpace,
  SystemNumaProcessorMap,
  SystemPrefetcherInformation,
  SystemExtendedProcessInformation,
  SystemRecommendedSharedDataAlignment,
  SystemComPlusPackage,
  SystemNumaAvailableMemory,
  SystemProcessorPowerInformation,
  SystemEmulationBasicInformation,
  SystemEmulationProcessorInformation,
  SystemExtendedHandleInformation,
  SystemLostDelayedWriteInformation,
  SystemBigPoolInformation,
  SystemSessionPoolTagInformation,
  SystemSessionMappedViewInformation,
  SystemHotpatchInformation,
  SystemObjectSecurityMode,
  SystemWatchdogTimerHandler,
  SystemWatchdogTimerInformation,
  SystemLogicalProcessorInformation,
  SystemWow64SharedInformation,
  SystemRegisterFirmwareTableInformationHandler,
  SystemFirmwareTableInformation,
  SystemModuleInformationEx,
  SystemVerifierTriageInformation,
  SystemSuperfetchInformation,
  SystemMemoryListInformation,
  SystemFileCacheInformationEx,
  MaxSystemInfoClass
} SYSTEM_INFORMATION_CLASS;

// Devinice struktury UNICODE_STRING
typedef struct _UNICODE_STRING {
  USHORT Length;
  USHORT MaximumLength;
  PWSTR  Buffer;
} UNICODE_STRING, *PUNICODE_STRING;

// Hlavicka rutiny NtSetSystemInformation
typedef NTSTATUS (NTAPI *NTSETSYSTEMINFORMATION) (IN SYSTEM_INFORMATION_CLASS SystemInformationClass, IN PVOID Buffer, IN ULONG Length);

// Hlavicka rutiny NtLoadDriver
typedef NTSTATUS (NTAPI *NTLOADDRIVER)(IN PUNICODE_STRING DriverName);

// Hlavicka rutiny NtUnloadDriver
typedef NTSTATUS (NTAPI *NTUNLOADDRIVER)(IN PUNICODE_STRING DriverName);

// Hlavicka rutiny RtlInitUnicodeString
typedef VOID (NTAPI *RTLINITUNICODESTRING)(OUT PUNICODE_STRING UnicodeString, IN PWCHAR WideString);



#define ALIGN_DOWN(Length, Type)       ((ULONG)(Length) & ~(sizeof(Type) - 1))
#define ALIGN_UP(Length, Type)         (ALIGN_DOWN(((ULONG)(Length) + sizeof(Type) - 1), Type))



// Popis jednotlivych funkci najdete v komentarich u jejich implementace
// v souboru common.c

BOOL _PrepareFullName(IN PWCHAR DriverName, IN PWCHAR Prefix, OUT PUNICODE_STRING uFullName);
VOID _FreeFullName(IN PUNICODE_STRING uFullName);
BOOL EnablePrivilege(PWCHAR PrivilegeName);
BOOL DeleteRegistryKey(HKEY hKey, PWCHAR aSubkey);

PVOID AllocMem(SIZE_T Size);
VOID FreeMem(PVOID Buffer);
PWCHAR ConvertAnsiStringToUnicode(PCHAR AnsiString);
VOID FreeUnicodeString(PWCHAR UnicodeString);

// #define DBG
#ifdef DBG
#define DebugMsg(a)            printf a
#else
#define DebugMsg(a)
#endif

BOOL CommonInit(VOID);
VOID CommonFinit(VOID);


#endif
