
/**
 * @file: object_initializer.h
 *
 * Tento soubor je soucasti frameworku pro praci s internimi strukturami spravce objektu.
 * Obsahuje definice struktur a hlavicky funkci pro praci se strukturami OBJECT_TYPE_INITIALIZER,
 * ktere jsou nedilnou soucasti kazde struktury OBJECT_TYPE popisujici telo objektu typu.
 */
 
#ifndef __OBJECT_INITIALIZER_H_
#define __OBJECT_INITIALIZER_H_

#include <ntddk.h>

// Definice struktury parametru pro metodu DumpProcedure. Ta slouzila pouze k ladicim
// ucelum a dnes se uz nepouziva.
typedef struct {
  PVOID Stream;
  ULONG Detail;
} DUMP_CONTROL, *PDUMP_CONTROL;

// Tento enum obsahuje duvody zavolani metody Openprocedure
typedef enum {
  ObCreateHandle,              // Vytvoreno prvni handle noveho objektu
  ObOpenHandle,                // Vytvoreno nove handle existujiciho objektu
  ObDuplicateHandle,           // Duplikace handle
  ObInheritHandle,             // Dedeni handle
  ObMaxOpenReason
} OPEN_REASON;

// Vlozime deklarace struktur OBJECT_TYPE_INITIALIZER a jednotliych metod pro ruzne verze
// Windows.
#include "object_initializer_w2k.h"
#include "object_initializer_w2k3.h"
#include "object_initializer_wxp.h"
#include "object_initializer_w7.h"
#include "object_initializer_vista.h"

// Struktura pro uchovani priznaku struktury OBJECT_TYPE_INITIALIZER.
// Pro jejich blizsi popis viz rutina OTIGetFlags.
typedef struct _OBJECT_INITIALIZER_FLAGS {
  ULONG CaseInsensitive;
  ULONG UseDefaultObject;
  ULONG MaintainHandleCount;
  ULONG MaintainTypeList;
  ULONG UnnamedObjectsOnly;
  ULONG SupportsObjectCallbacks;
  ULONG SecurityRequired;
} OBJECT_INITIALIZER_FLAGS, *POBJECT_INITIALIZER_FLAGS;

// Tuto strukturu pouziva funkce OTIGetMethods pro zaznamenani adres jednotlivych metod
// struktury OBJECT_TYPE_INITIALIZER
typedef struct _OBJECT_INITIALIZER_METHODS {
  PVOID Open;                  // Volana pri vytvoreni noveho handle
  PVOID Close;                 // Volana behem ruseni handle
  PVOID OkayToClose;           // Dovoluje zabranit zruseni zadaneho handle
  PVOID Delete;                // Provadi uklid objektu (dealokace struktur napojenych na jeho telo atd.)
  PVOID Parse;                 // Je volana pri prochazeni adresaroveho stromu a prekladani cest.
  PVOID QueryName;             // Vraci jmeno objektu.
  PVOID Security;              // Nastavuje bezpecnostni udaje objektu (popisovac zabezpeceni).
  PVOID Dump;                  // Nepouziva se, puvodne urcena pro ladeni.
} OBJECT_INITIALIZER_METHODS, *POBJECT_INITIALIZER_METHODS;

// Tuto strukturu pouziva funkce OTIGetOtherInfo pro ulozeni ruznych udaju o strukture
// OBJECT_TYPE_INITIALIZER. Popis jejich clenu najdete u implementace teto rutiny.
typedef struct _OBJECT_INITIALIZER_OTHER_INFO {
  ULONG DefaultPagedPoolCharge;
  ULONG DefaultNonPagedPoolCharge;
  ULONG ObjectTypeCode;
  ULONG VaildAccessMask;
  ULONG InvalidAttributes;
  ULONG RetainAccess;
  GENERIC_MAPPING GenericMapping;
  POOL_TYPE PoolType;
} OBJECT_INITIALIZER_OTHER_INFO, *POBJECT_INITIALIZER_OTHER_INFO;

// Popis semantiky jednotlivych funkci naleznete v souboru object_initializer.c u jejich
// implementace
NTSTATUS OTIGetFlags(PVOID Initializer, POBJECT_INITIALIZER_FLAGS Flags);
NTSTATUS OTIGetMethods(PVOID Initializer, POBJECT_INITIALIZER_METHODS Methods);
NTSTATUS OTIGetOtherInfo(PVOID Initializer, POBJECT_INITIALIZER_OTHER_INFO OtherInfo);

NTSTATUS OTIInit(PDRIVER_OBJECT DriverObject);
VOID OTIFinit(VOID);

#endif
