
/**
 * @file: object_initializer_w7.h
 *
 * Tento soubor je soucasti frameworku na prochazeni internich datovych struktur spravce
 * objektu jadra Windos. Obsahuje prototypy funkci a definici struktury OBJECT_TYPE_INITIALIZER
 * pro Windows 7.
 */

#ifndef __OBJECT_INITIALIZER_W7_H_
#define __OBJECT_INITIALIZER_W7_H_

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

// Definice (virtualnich) metod
typedef VOID (*DUMP_METHOD_W7)(PVOID Object, PDUMP_CONTROL Control);
typedef NTSTATUS (*OPEN_METHOD_W7)(OPEN_REASON OpenReason, KPROCESSOR_MODE AccessMode, PEPROCESS Process, PVOID Object, ACCESS_MASK *GrantedAccess, ULONG32 HandleCount);
typedef BOOLEAN (*OKAYTOCLOSE_METHOD_W7)(PEPROCESS Process,PVOID Object, HANDLE Handle, KPROCESSOR_MODE PreviousMode);
typedef VOID (*CLOSE_METHOD_W7)(PEPROCESS Process, PVOID Object, ULONG_PTR ProcessHandleCount, ULONG_PTR SystemHandleCount);
typedef VOID (*DELETE_METHOD_W7)(PVOID Object);
typedef NTSTATUS (*PARSE_METHOD_W7)(PVOID ParseObject, PVOID ObjectType, PACCESS_STATE AccessState, KPROCESSOR_MODE AccessMode, ULONG32 Attributes, PUNICODE_STRING CompleteName, PUNICODE_STRING RemainingName, PVOID Context, PSECURITY_QUALITY_OF_SERVICE SecurityQos, PVOID *Object);
typedef NTSTATUS (*SECURITY_METHOD_W7)(PVOID Object, SECURITY_OPERATION_CODE OperationCode, PSECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR SecurityDescriptor, PULONG32 CapturedLength, PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor, POOL_TYPE PoolType, PGENERIC_MAPPING GenericMapping, KPROCESSOR_MODE AccessMode);
typedef NTSTATUS (*QUERYNAME_METHOD_W7)(PVOID Object, BOOLEAN HasObjectName, POBJECT_NAME_INFORMATION ObjectNameInfo, ULONG32 Length, PULONG32 ReturnLength, KPROCESSOR_MODE AccessMode);


// Definice struktury OBJECT_TYPE_INITIALIZER. Vyznam jednotlivych clenu najdete
// u implementace funkci v souboru object_initializer.c a v souboru object_initializer.h
typedef struct {
  USHORT Length;                                                                                                                                                                                
  union {                                                                                                                                                                                                   
    UINT8 ObjectTypeFlags;                                                                                                                                                                   
    struct {                                                                                                                                                                                               
      UINT8 CaseInsensitive : 1;                                                                                                                       // 0 BitPosition                    
      UINT8 UnnamedObjectsOnly : 1;                                                                                                                    // 1 BitPosition                    
      UINT8 UseDefaultObject : 1;                                                                                                                      // 2 BitPosition                    
      UINT8 SecurityRequired : 1;                                                                                                                      // 3 BitPosition                    
      UINT8 MaintainHandleCount : 1;                                                                                                                   // 4 BitPosition                    
      UINT8 MaintainTypeList : 1;                                                                                                                      // 5 BitPosition                    
      UINT8 SupportsObjectCallbacks : 1;                                                                                                               // 6 BitPosition                    
    } ObjectFlags;                                                                                                                                                                                              
  };    

  ULONG32 ObjectTypeCode;                                                                                                                                                                        
  ULONG32 InvalidAttributes;                                                                                                                                                                     
  ULONG32 GenericMapping [4];                                                                                                                         // 4 elements, 0x10 bytes (sizeof)  
  ULONG32 ValidAccessMask;                                                                                                                                                                       
  ULONG32 RetainAccess;                                                                                                                                                                          
  POOL_TYPE PoolType;                                                                                                                                                                           
  ULONG32      DefaultPagedPoolCharge;                                                                                                                                                                
  ULONG32      DefaultNonPagedPoolCharge;                                                                                                                                                             
  DUMP_METHOD_W7 DumpProcedure;                                                                                                                                                       
  OPEN_METHOD_W7 OpenProcedure;                                                                                                                                                       
  CLOSE_METHOD_W7 CloseProcedure;                                                                                                                                                     
  DELETE_METHOD_W7 DeleteProcedure;                                     
  PARSE_METHOD_W7 ParseProcedure;                                                                                                                                                     
  SECURITY_METHOD_W7 SecurityProcedure;                                                                                                                                               
  QUERYNAME_METHOD_W7 QueryNameProcedure;                                                                                                                                             
  OKAYTOCLOSE_METHOD_W7 OkayToCloseProcedure; 
} OBJECT_TYPE_INITIALIZER_W7, *POBJECT_TYPE_INITIALIZER_W7;

// Makra slouzici k "vytahnuti" dulezitych clenu struktury OBJECTy_TYPE_INITIALIZER

#define OTIW7CaseInsensitive(a)                                ((POBJECT_TYPE_INITIALIZER_W7)a)->ObjectFlags.CaseInsensitive
#define OTIW7UnnamedObjectsOnly(a)                             ((POBJECT_TYPE_INITIALIZER_W7)a)->ObjectFlags.UnnamedObjectsOnly
#define OTIW7UseDefaultObject(a)                               ((POBJECT_TYPE_INITIALIZER_W7)a)->ObjectFlags.UseDefaultObject
#define OTIW7SecurityRequired(a)                               ((POBJECT_TYPE_INITIALIZER_W7)a)->ObjectFlags.SecurityRequired
#define OTIW7MaintainHandleCount(a)                            ((POBJECT_TYPE_INITIALIZER_W7)a)->ObjectFlags.MaintainHandleCount
#define OTIW7MaintainTypeList(a)                               ((POBJECT_TYPE_INITIALIZER_W7)a)->ObjectFlags.MaintainTypeList
#define OTIW7SupportsObjectCallbacks(a)                        ((POBJECT_TYPE_INITIALIZER_W7)a)->ObjectFlags.SupportsObjectCallbacks

#define OTIW7ObjectTypeCode(a)                                 ((POBJECT_TYPE_INITIALIZER_W7)a)->ObjectTypeCode
#define OTIW7InvalidAttributes(a)                              ((POBJECT_TYPE_INITIALIZER_W7)a)->InvalidAttributes
#define OTIW7ValidAccessMask(a)                                ((POBJECT_TYPE_INITIALIZER_W7)a)->ValidAccessMask
#define OTIW7RetainAccess(a)                                   ((POBJECT_TYPE_INITIALIZER_W7)a)->RetainAccess
#define OTIW7PoolType(a)                                       ((POBJECT_TYPE_INITIALIZER_W7)a)->PoolType
#define OTIW7DefaultPagedPoolCharge(a)                         ((POBJECT_TYPE_INITIALIZER_W7)a)->DefaultPagedPoolCharge
#define OTIW7DefaultNonPagedPoolCharge(a)                      ((POBJECT_TYPE_INITIALIZER_W7)a)->DefaultNonPagedPoolCharge
#define OTIW7DumpProcedure(a)                                  (DUMP_METHOD_W7)((POBJECT_TYPE_INITIALIZER_W7)a)->DumpProcedure
#define OTIW7OpenProcedure(a)                                  (OPEN_METHOD_W7)((POBJECT_TYPE_INITIALIZER_W7)a)->OpenProcedure
#define OTIW7CloseProcedure(a)                                 (CLOSE_METHOD_W7)((POBJECT_TYPE_INITIALIZER_W7)a)->CloseProcedure
#define OTIW7OkayToCloseProcedure(a)                           (OKAYTOCLOSE_METHOD_W7)((POBJECT_TYPE_INITIALIZER_W7)a)->OkayToCloseProcedure
#define OTIW7DeleteProcedure(a)                                (DELETE_METHOD_W7)((POBJECT_TYPE_INITIALIZER_W7)a)->DeleteProcedure
#define OTIW7ParseProcedure(a)                                 (PARSE_METHOD_W7)((POBJECT_TYPE_INITIALIZER_W7)a)->ParseProcedure
#define OTIW7SecurityProcedure(a)                              (SECURITY_METHOD_W7)((POBJECT_TYPE_INITIALIZER_W7)a)->SecurityProcedure
#define OTIW7QueryNameProcedure(a)                             (QUERYNAME_METHOD_W7)((POBJECT_TYPE_INITIALIZER_W7)a)->QueryNameProcedure

#endif
