xuehaipiaoxiang
驱动牛犊
驱动牛犊
  • 注册日期2006-10-11
  • 最后登录2013-02-01
  • 粉丝0
  • 关注0
  • 积分250分
  • 威望273点
  • 贡献值0点
  • 好评度22点
  • 原创分4分
  • 专家分0分
阅读:2263回复:0

RegMon(1)

楼主#
更多 发布于:2007-04-26 23:10
  先从DriverEntry开始
NTSTATUS                ntStatus;
状态
WCHAR                   deviceNameBuffer[]  = L"\\Device\\Regmon";
设备名称缓冲区
UNICODE_STRING          deviceNameUnicodeString;
设备名称对应得宽字符串结构
WCHAR                   deviceLinkBuffer[]  = L"\\DosDevices\\Regmon";
连接名称缓冲区
UNICODE_STRING          deviceLinkUnicodeString;
连接名称宽字符串结构
WCHAR                   startValueBuffer[] = L"Start";
开始值缓冲区
UNICODE_STRING          startValueUnicodeString;
开始值宽字符串结构
WCHAR                   bootMessage[] =
        L"\nRegmon is logging Registry activity to \\SystemRoot\\Regmon.log\n\n";
启动消息缓冲区
UNICODE_STRING          bootMessageUnicodeString;
启动消息款字符串结构
UNICODE_STRING          registryPath;
注册表项宽字符串结构
HANDLE                  driverKey;
PETHREAD                curthread;
ULONG                   startType, demandStart;
RTL_QUERY_REGISTRY_TABLE paramTable[2];

OBJECT_ATTRIBUTES       objectAttributes;
int                     i;

说明:
RTL_QUERY_REGISTRY_TABLE paramTable[2];是一个RTL_QUERY_REGISTRY_TABLE结构的数组。每个成员都包含一个Name名称项和一些其他值。因为要求这种数组必须以一个“空数组”结束。所以空数组就是说Name为空和QueryRoutine为空。这个结构的具体内容如下:
typedef struct _RTL_QUERY_REGISTRY_TABLE {
    PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
    ULONG Flags;
    PWSTR Name;
    PVOID EntryContext;
    ULONG DefaultType;
    PVOID DefaultData;
    ULONG DefaultLength;
} RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;



// 查询启动时是需要监控
    // Query our start type to see if we are supposed to monitor starting
    // at boot time
//
// 为registryPath分配空间,要求分页空间,长度比RegistryPath多1个UNICODE_NULL
    registryPath.Buffer = ExAllocatePool( PagedPool,
                                          RegistryPath->Length + sizeof(UNICODE_NULL));
 
//  如果分配失败则返回内存不足
    if (!registryPath.Buffer) {
 
        return STATUS_INSUFFICIENT_RESOURCES;
    }
 // 分配了缓冲区还不够,还需要设置Length
registryPath.Length = RegistryPath->Length + sizeof(UNICODE_NULL);
// 设置了Length还不够,还需要设置最大长度MaximumLength
    registryPath.MaximumLength = registryPath.Length;
// 清0缓冲区
    RtlZeroMemory( registryPath.Buffer, registryPath.Length );
 // 把RegistryPath拷贝过来
    RtlMoveMemory( registryPath.Buffer,  RegistryPath->Buffer,
                   RegistryPath->Length  );
// 清空RTL_QUERY_REGISTRY_TABLE的第一个元素
    RtlZeroMemory( &paramTable[0], sizeof(paramTable));
    paramTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
    paramTable[0].Name = L"Start";
    paramTable[0].EntryContext = &startType;
    paramTable[0].DefaultType = REG_DWORD;
    paramTable[0].DefaultData = &startType;
    paramTable[0].DefaultLength = sizeof(ULONG);
// 查询注册值项,,重点是查询Start的值为多少
RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE,
                            registryPath.Buffer, &paramTable[0],
                            NULL, NULL  );

最新喜欢:

精灵dsp精灵dsp
游客

返回顶部