
/**
 * @file object_header_w2k3.h
 *
 * Tento soubor je soucasti frameworku na procjazeni internich datovych struktur
 * spravce objektu. Obsahuje definice nekterych struktur pro Windows Server 2003.
 */
 
#ifndef __OBJECT_HEADER_W2K3_H_
#define __OBJECT_HEADER_W2K3_H_

#include <ntddk.h>
#include "object_type_w2k3.h"


// Definice podhlavicky obsahujici informace, kolik pametove kvoty kazde handle daneho
// objektu ubira procesu.
typedef struct _OBJECT_HEADER_QUOTA_INFO_W2K3
{
  // Strankovana pamet
  ULONG32 PagedPoolCharge;
  // Nestrankovana pamet
  ULONG32 NonPagedPoolCharge;
  // Popisovac zabezpeceni
  ULONG32 SecurityDescriptorCharge;
  // Adresa tela exkluzivniho procesu
  PEPROCESS ExclusiveProcess;
} OBJECT_HEADER_QUOTA_INFO_W2K3, *POBJECT_HEADER_QUOTA_INFO_W2K3;

// Podhlavicka obsahujici informace o procesu, ktery je tvurcem daneho objektu
typedef struct _OBJECT_HEADER_CREATOR_INFO_W2K3
{
  // Propojuje objekt s dalsimi objekty stejneho typu (pouze pokud objekt typu ma priznak MaintainTypeList.
  LIST_ENTRY TypeList;
  // PID tvurce objektu (nemusi byt validni v dobe jeho zkoumani. ten proces uz nemusi existovat)
  HANDLE CreatorUniqueProcess;
  USHORT CreatorBackTraceIndex;
  USHORT Reserved;
} OBJECT_HEADER_CREATOR_INFO_W2K3, *POBJECT_HEADER_CREATOR_INFO_W2K3;

// Definice podhlavicky se jmenem a adresarem objektu
typedef struct _OBJECT_HEADER_NAME_INFO_W2K3
{
  // Adresa tela adresare, ve kterem je objekt obsazen
  PVOID Directory;                                    
  // Jmeno objektu
  UNICODE_STRING Name;
  ULONG32 QueryReferences;
} OBJECT_HEADER_NAME_INFO_W2K3, *POBJECT_HEADER_NAME_INFO_W2K3;


// Struktura "hlavni" hlavicky objektu
typedef struct _OBJECT_HEADER_W2K3 {
  // Pocet referenci na objekt
  LONG_PTR PointerCount;
  // Pocet existujicich handle objektu
  LONG_PTR HandleCount;
  // Adresa tela objektu typu
  POBJECT_TYPE_W2K3 Type;
  // Offset hlavicky OBJECT_HEADER_NAME_INFO
  UCHAR NameInfoOffset;
  // Offset hlavicky OBJECT_HEADER_HANDLE_INFO
  UCHAR HandleInfoOffset;
  // Offset hlavicky OBJECT_HEADER_QUOTA_INFO
  UCHAR QuotaInfoOffset;
  // Priznaky
  UCHAR Flags;
  union {
    // Odkaz na strukturu s parametry pri vytvareni objektu
    PVOID ObjectCreateInfo;
    PVOID QuotaBlockCharged;
  };
  // Popisovac zabezpeceni objektu
  PVOID SecurityDescriptor;
} OBJECT_HEADER_W2K3, *POBJECT_HEADER_W2K3;

// Makra slouzici pro "vytahnuti" dulezitych clenu ze struktur hlavicek a podhlavicek

#define OHW2K3GetPointerCount(a)              ((POBJECT_HEADER_W2K3)a)->PointerCount
#define OHW2K3GetHandleCount(a)               ((POBJECT_HEADER_W2K3)a)->HandleCount
#define OHW2K3GetType(a)                      ((POBJECT_HEADER_W2K3)a)->Type
#define OHW2K3GetNameInfoOffset(a)            ((POBJECT_HEADER_W2K3)a)->NameInfoOffset
#define OHW2K3GetHandleInfoOffset(a)          ((POBJECT_HEADER_W2K3)a)->HandleInfoOffset
#define OHW2K3GetQuotaInfoOffset(a)           ((POBJECT_HEADER_W2K3)a)->QuotaInfoOffset
#define OHW2K3GetFlags(a)                     ((POBJECT_HEADER_W2K3)a)->Flags
#define OHW2K3GetObjectCreateInfo(a)          ((POBJECT_HEADER_W2K3)a)->ObjectCreateInfo
#define OHW2K3GetSecurityDescriptor(a)        (PSECURITY_DESCRIPTOR)(((POBJECT_HEADER_W2K3)a)->SecurityDescriptor)

#define OHW2K3HandleInfoGetHandleCountDatabase(a)       ((POBJECT_HEADER_HANDLE_INFO_W2K3)a)->HandleCountDatabase
#define OHW2K3HandleInfoGetHandleCountSingleEntry(a)    ((POBJECT_HEADER_HANDLE_INFO_W2K3)a)->SingleEntry
#define OHW2K3QuotaInfoGetPagedPoolCharge(a)            ((POBJECT_HEADER_QUOTA_INFO_W2K3)a)->PagedPoolCharge
#define OHW2K3QuotaInfoGetNonPagedPoolCharge(a)         ((POBJECT_HEADER_QUOTA_INFO_W2K3)a)->NonPagedPoolCharge
#define OHW2K3QuotaInfoGetSecurityDescriptorCharge(a)   ((POBJECT_HEADER_QUOTA_INFO_W2K3)a)->SecurityDescriptorCharge
#define OHW2K3QuotaInfoGetExclusiveProcess(a)           ((POBJECT_HEADER_QUOTA_INFO_W2K3)a)->ExclusiveProcess
#define OHW2K3CreatorInfoGetCreatorUniqueProcess(a)     ((POBJECT_HEADER_CREATOR_INFO_W2K3)a)->CreatorUniqueProcess 
#define OHW2K3NameInfoGetDirectory(a)                   ((POBJECT_HEADER_NAME_INFO_W2K3)a)->Directory
#define OHW2K3NameInfoGetReferenceCount(a)              ((POBJECT_HEADER_NAME_INFO_W2K3)a)->QueryReferences



#endif
