大佬们,想问一下不拉伸exe怎么往节的空白去添加代码阿,思路不是:msgbox地址-文件中代码开始的地址-文件对齐+内存对齐+imagebase吗,但是没有办法运行啊,求求各位大佬扔个代码,或者思路把。
void write(char
*
ptr,
int
size)
{
FILE
*
fp
=
fopen(
"Dll1.exe"
,
"wb"
);
fwrite(ptr, size,
1
, fp);
fclose(fp);
}
DWORD rtf(char
*
buffer
, DWORD rva)
{
PIMAGE_DOS_HEADER doshd
=
(PIMAGE_DOS_HEADER)
buffer
;
PIMAGE_NT_HEADERS nthd
=
(PIMAGE_NT_HEADERS)(
buffer
+
doshd
-
>e_lfanew);
PIMAGE_FILE_HEADER filehd
=
(PIMAGE_FILE_HEADER)(
buffer
+
doshd
-
>e_lfanew
+
4
);
PIMAGE_OPTIONAL_HEADER32 optionhd
=
(PIMAGE_OPTIONAL_HEADER32)(
buffer
+
doshd
-
>e_lfanew
+
24
);
PIMAGE_SECTION_HEADER sectionhd
=
IMAGE_FIRST_SECTION(nthd);
for
(
int
i
=
0
; i < filehd
-
>NumberOfSections; i
+
+
)
{
if
(rva >
=
sectionhd[i].VirtualAddress && rva <
=
sectionhd[i].VirtualAddress
+
sectionhd[i].SizeOfRawData)
{
return
rva
-
sectionhd[i].VirtualAddress
+
sectionhd[i].PointerToRawData;
}
}
}
void main()
{
DWORD msgbox
=
0x75DF0F40
;
printf(
"%x\n"
, msgbox);
char code[]
=
{
0x6A
,
0x00
,
0x6A
,
0x00
,
0x6A
,
0x00
,
0x6A
,
0x00
,
0xE8
,
0x00
,
0x00
,
0x00
,
0x00
,
0xE9
,
0x00
,
0x00
,
0x00
,
0x00
};
FILE
*
fp
=
fopen(directory,
"rb"
);
fseek(fp,
0
, SEEK_END);
int
size
=
ftell(fp);
rewind(fp);
char
*
ptr
=
(char
*
)malloc(size);
memset(ptr,
0
, size);
fread(ptr, size,
1
, fp);
PIMAGE_DOS_HEADER doshd2
=
(PIMAGE_DOS_HEADER)ptr;
PIMAGE_NT_HEADERS nthd2
=
(PIMAGE_NT_HEADERS)(ptr
+
doshd2
-
>e_lfanew);
PIMAGE_FILE_HEADER filehd2
=
(PIMAGE_FILE_HEADER)(ptr
+
doshd2
-
>e_lfanew
+
4
);
PIMAGE_OPTIONAL_HEADER32 optionhd2
=
(PIMAGE_OPTIONAL_HEADER32)(ptr
+
doshd2
-
>e_lfanew
+
24
);
PIMAGE_SECTION_HEADER sectionhd2
=
IMAGE_FIRST_SECTION(nthd2);
char
*
ptr1
=
ptr
+
(sectionhd2
-
>PointerToRawData
+
sectionhd2
-
>Misc.VirtualSize);
memcpy(ptr1, code, sizeof(code));
DWORD ptr2
=
msgbox
-
(DWORD)(ptr1
+
0xd
-
optionhd2
-
>FileAlignment
+
optionhd2
-
>SectionAlignment
+
optionhd2
-
>ImageBase);
*
(ptr1
+
9
)
=
ptr2;
DWORD ptr3
=
(optionhd2
-
>ImageBase
+
optionhd2
-
>AddressOfEntryPoint)
-
(DWORD)(ptr1
+
0xd
+
0x5
-
optionhd2
-
>FileAlignment
+
optionhd2
-
>SectionAlignment
+
optionhd2
-
>ImageBase);
*
(ptr1
+
0xe
)
=
ptr3;
optionhd2
-
>AddressOfEntryPoint
=
ptr1
-
ptr;
write(ptr, size);
getchar();
}