• 大小: 0.18M
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2024-04-22
  • 语言: C/C++
  • 标签: linux  LIN  代码  内核  11  

资源简介


资源截图

代码片段和文件信息

#include 
#include 
#include 

DWORD g_dwFileHeader[1024] = {0};    //The PE file‘s header will be read into this buffer.

typedef struct __tagFILE_HEADER{
unsigned char ucNop[4];
DWORD         dwJmpAddr;
}__FILL_HEADER;

__FILL_HEADER g_FillHeader = {0x900x900x900xe90x00000000};    //This structure will be
                                                                  //written to target file.

char* g_lpszTargetPath = “E:\\book\\Temp\\linux011VC\\VC\\Release\\system“;  //Target file’s path and name.

void main(int argcchar argv[])
{
IMAGE_DOS_HEADER*       ImageDosHeader = NULL;
IMAGE_NT_HEADERS*       ImageNtHeader = NULL;
IMAGE_OPTIONAL_HEADER*  ImageOptionalHeader = NULL;
HANDLE                  hFile = INVALID_HANDLE_VALUE;
DWORD                   dwReadBytes = 0L;
BOOL                    bResult = FALSE;
DWORD                   dwActualBytes = 0L;
DWORD                   dwOffset = 0L;
UCHAR*                  lpucSource = NULL;
UCHAR*                  lpucDes    = NULL;
DWORD                   dwLoop     = 0;

hFile = CreateFile(                //Open the target file.
g_lpszTargetPath
GENERIC_READ | GENERIC_WRITE
0L
NULL
OPEN_ALWAYS
0L
NULL);
if(INVALID_HANDLE_VALUE == hFile)
{
printf(“Can not open the target file to read.“);
goto __TERMINAL;
}

dwReadBytes = 4096;               //Read 4k bytes from target file.
bResult = ReadFile(hFileg_dwFileHeaderdwReadBytes&dwActualBytesNULL);
if(!bResult)
goto __TERMINAL;

CloseHandle(hFile);
hFile = INVALID_HANDLE_VALUE;

//
//The following code locates the entry point of the PE fileand modifies it.
//
ImageDosHeader = (IMAGE_DOS_HEADER*)&g_dwFileHeader[0];
dwOffset = ImageDosHeader->e_lfanew;

ImageNtHeader = (IMAGE_NT_HEADERS*)((UCHAR*)&g_dwFileHeader[0] + dwOffset);
ImageOptionalHeader = &(ImageNtHeader->OptionalHeader);

g_FillHeader.dwJmpAddr = ImageOptionalHeader->AddressOfEntryPoint;
printf(“    Entry Point : %d\r\n“ImageOptionalHeader->AddressOfEntryPoint);
g_FillHeader.dwJmpAddr -= sizeof(__FILL_HEADER);    //Calculate the target address will
                                                    //jump to.
                                                    //Because we have added some nop instruc-
                                                    //tions in front of the target fileso
                                                    //we must adjust it.

lpucSource = (UCHAR*)&g_FillHeader.ucNop[0];
lpucDes    = (UCHAR*)&g_dwFileHeader[0];

for(dwLoop = 0;dwLoop < sizeof(__FILL_HEADER);dwLoop ++)  //Modify the target file‘s header.
{
*lpucDes = *lpucSource;
lpucDes ++;
lpucSource ++;
}

hFile = CreateFile(                //Open the target file to write.
g_lpszTargetPath
GENERIC_READ | GENERIC_WRITE
0L
NULL
OPEN_ALWAYS
0L
NULL);
if(INVALID_HANDLE_VALUE == hFile)
{

评论

共有 条评论