ckmdf

'HookedDeviceControl': undeclared identifier


I get a 'HookedDeviceControl': undeclared identifier error when i compile this code. (InterlockedExchange((PLONG)&pDrv_tcpip->MajorFunction[IRP_MJ_DEVICE_CONTROL],(LONG)HookedDeviceControl);) Does the "HookedDeviceControl" function need to have specific code in it? Do i need any specific libraries or imports? Im not entirely sure why its saying its unidentified when there is a HookedDeviceControl function

#include <wdm.h>

VOID Unload_Driver() {
    DbgPrint("Driver Successfully Unloaded");
}

NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) // this is main
{
    UNREFERENCED_PARAMETER(RegistryPath);
    UNREFERENCED_PARAMETER(DriverObject);
    //HookedMjCreate();
    DriverObject->DriverUnload = Unload_Driver;
}

PFILE_OBJECT pFile_tcp;
PDEVICE_OBJECT pDev_tcp;
PDRIVER_OBJECT pDrv_tcpip;
typedef NTSTATUS(*OLDIRPMJDEVICECONTROL)(IN PDEVICE_OBJECT, IN PIRP);
OLDIRPMJDEVICECONTROL OldIrpMjDeviceControl;

NTSTATUS InstallTCPDriverHook(IN ACCESS_MASK DesiredAccess)
{
    NTSTATUS ntStatus;
    UNICODE_STRING deviceTCPUnicodeString;
    WCHAR deviceTCPNameBuffer[] = L"\\Device\\Tcp";
    pFile_tcp = NULL;
    pDev_tcp = NULL;
    ntStatus = IoGetDeviceObjectPointer(L"\\Device\\Tcp", FILE_READ_DATA, &pFile_tcp, &pDev_tcp);
    RtlInitUnicodeString(&deviceTCPUnicodeString,
        deviceTCPNameBuffer);
    ntStatus = IoGetDeviceObjectPointer(&deviceTCPUnicodeString,
        FILE_READ_DATA, &pFile_tcp,
        &pDev_tcp);
    if (!NT_SUCCESS(ntStatus))
        return ntStatus;
    pDrv_tcpip = pDev_tcp->DriverObject;
    OldIrpMjDeviceControl = pDrv_tcpip->
        MajorFunction[IRP_MJ_DEVICE_CONTROL];
    if (OldIrpMjDeviceControl)
        InterlockedExchange((PLONG)&pDrv_tcpip->MajorFunction[IRP_MJ_DEVICE_CONTROL],(LONG)HookedDeviceControl);
    return STATUS_SUCCESS;
}



NTSTATUS HookedDeviceControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
{

}```

Solution

  • You need to declare/define the function HookedDeviceControl before calling it or passing it as an argument. So one of the options is to define HookedDeviceControl before InstallTCPDriverHook:

    NTSTATUS HookedDeviceControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
    {
       ...
    }
    NTSTATUS InstallTCPDriverHook(IN ACCESS_MASK DesiredAccess)
    {
      ...
    }