Thursday, July 21, 2011

Doing Memory mapped I/O from windows driver

Here is the example of how to perform Memory Mapped I/O using windows driver.



#include <wdm.h>

VOID DriverUnload(PDRIVER_OBJECT pDriverObject)
{
    DbgPrint("Driver unloading\n");
    {
        PVOID p;
        PHYSICAL_ADDRESS physAddr;
        physAddr.QuadPart = 0xFED01000;
        p = MmMapIoSpace(physAddr, 4, 1);
        *(unsigned int*)p = 0xF9;
    }
}

NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
    DbgPrint("Hello, World\n");
    DriverObject->DriverUnload = DriverUnload;

    return STATUS_SUCCESS;
}

Tuesday, July 19, 2011

Linking error with MSVCRT ??

One of the reason could be that the 'Library' and 'EXE' are using different run time library.
For example, if LIB will use 'Debug Multithreaded' and EXE will use 'Multithreaded' OR a different combination, then you will get Linking error while linking LIB with EXE.

In visual studio 6, you can get this option @  Project -> Setting -> c/c++ tab -> Code Generation -> use run time library combo box.

Monday, July 18, 2011

How to check PING command on a group of IPs

Here is a small DOS script that can ping a group of IPs...
In this example, we are trying to ping from 10.125.56.125 to 10.125.56.150 range.

Things which is important and must be remember is 'ENABLEDELAYEDEXPANSION' which is used for 'delayed expansion' for '!' mark (%var% ==> !var!)



@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set ip=10.125.56.1
for /L %%i in (25,1,50) do (
set add= %ip%%%i
ping !add! -n 1 > nul
set ret=!ERRORLEVEL!
if !ret!==1 (
echo Host not reachable : !add!
)
)