Re: Dynamically loading binaries in Kernel mode.
- From: "jerry lee" <lihwf@xxxxxxxxxx>
- Date: 31 Mar 2006 01:39:07 -0800
Hi Luis,
You do not need allocate memory and read file in,maybe the following
code can help you. The functio protype is come from Gary Nebbett's book
Windows NT/2000 Native API, but Gary made a mistake there for the
SYSTEM_LOAD_IMAGE struct. Also, when run on Windows XP, the size of
the struct is different depend on the service pack.
As to the PE parsing, It is a little tedious so you can find them
otherwhere.
Note: The code is tested only on Windows xp, with and without SP1/SP2.
typedef struct _SYSTEM_LOAD_IMAGE { // Information Class 26
UNICODE_STRING ModuleName;
PVOID ModuleBase;
PVOID ModuleSection; //Lihw. ModuleSection is used to free the
image
PVOID EntryPoint;
PVOID ExportDirectory;
PVOID DummyForSP; //Lihw. XP sp2 use extra field
} SYSTEM_LOAD_IMAGE, *PSYSTEM_LOAD_IMAGE;
HANDLE LoadModule(IN PCWSTR pModName,OUT PVOID* pImageBase)
/*
Load specified module into kernel address space
Para:
pModName: Unicode string point to absolute path
return:
NULL if failed
ModuleSection if success, which can be used later as input para to
FreeModule.
*/
{
SYSTEM_LOAD_IMAGE sli;
NTSTATUS ret;
ULONG ulStructSize = sizeof(SYSTEM_LOAD_IMAGE);
RtlZeroMemory(&sli,sizeof(SYSTEM_LOAD_IMAGE));
RtlInitUnicodeString(&sli.ModuleName,pModName);
//Get windows version to determine the size of SYSTEM_LOAD_IMAGE
struct.
RTL_OSVERSIONINFOEXW ver;
ver.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
RtlGetVersion((PRTL_OSVERSIONINFOW)&ver);
if (ver.wServicePackMajor == 0)
ulStructSize = offsetof(SYSTEM_LOAD_IMAGE,DummyForSP);
if ((ret = ZwSetSystemInformation(SystemLoadImage,&sli,ulStructSize))
!=STATUS_SUCCESS )
{
TRACE("LoadModule failed\n Ret=%x\n",ret);
return NULL;
}
*pImageBase = sli.ModuleBase;
return sli.ModuleSection;
}
Jerry Lee
.
- Follow-Ups:
- Re: Dynamically loading binaries in Kernel mode.
- From: Ivan Brugiolo [MSFT]
- Re: Dynamically loading binaries in Kernel mode.
- Prev by Date: Re: How to make the work going on after usb device re-plug in?
- Next by Date: Re: Dynamically loading binaries in Kernel mode.
- Previous by thread: Re: Dynamically loading binaries in Kernel mode.
- Next by thread: Re: Dynamically loading binaries in Kernel mode.
- Index(es):
Relevant Pages
|
Loading