したらばTOP ■掲示板に戻る■ 全部 1-100 最新50 | メール | |

管理人の独り言(プログラミング関連)

1116774さん:2008/12/17(水) 23:42:02 ID:CENbthlg0
void Unko(void *src, void *des, DWORD srcSize, DWORD desSize){
IMAGE_DOS_HEADER *pSrcDosHeader = (IMAGE_DOS_HEADER *)src;
IMAGE_DOS_HEADER *pDesDosHeader = (IMAGE_DOS_HEADER *)des;

if(pSrcDosHeader->e_magic == IMAGE_DOS_SIGNATURE && pDesDosHeader->e_magic == IMAGE_DOS_SIGNATURE){
IMAGE_NT_HEADERS32 *pSrcNtHeader = (IMAGE_NT_HEADERS32 *)RVA(src, pSrcDosHeader->e_lfanew);
IMAGE_NT_HEADERS32 *pDesNtHeader = (IMAGE_NT_HEADERS32 *)RVA(des, pDesDosHeader->e_lfanew);

if(pSrcNtHeader->Signature == IMAGE_NT_SIGNATURE && pDesNtHeader->Signature == IMAGE_NT_SIGNATURE){
WORD srcNumberOfSections = pSrcNtHeader->FileHeader.NumberOfSections;
WORD desNumberOfSections = pDesNtHeader->FileHeader.NumberOfSections;

IMAGE_SECTION_HEADER *pSrcSections = IMAGE_FIRST_SECTION(pSrcNtHeader);
IMAGE_SECTION_HEADER *pDesSections = IMAGE_FIRST_SECTION(pDesNtHeader);

IMAGE_SECTION_HEADER *pSrcTextSection = GetTextSection(pSrcSections, srcNumberOfSections);
IMAGE_SECTION_HEADER *pDesTextSection = GetTextSection(pDesSections, desNumberOfSections);

if(pSrcTextSection && pDesTextSection){
//ソースの.textセクションの大きさ
DWORD srcTextSectionSize = pSrcTextSection->SizeOfRawData;

//挿入先の.textセクションのファイル上の大きさ
DWORD desTextSectionSize = pDesTextSection->SizeOfRawData;
//挿入先の.textセクションのメモリ上の大きさ
DWORD desTextSectionVirtualSize = pDesTextSection->Misc.VirtualSize;

//挿入先のセクションのアラインメントの大きさ
DWORD desSectionAlignment = pDesNtHeader->OptionalHeader.SectionAlignment;
//挿入先のセクションのファイル上のアラインメントの大きさ
DWORD desFileAlignment = pDesNtHeader->OptionalHeader.FileAlignment;

//挿入後の.textセクションのファイル上の大きさ(もっと良い求め方があったが、忘れた。)幾らか足しているのはアセンブリ用(下の方のcode分)
DWORD desAfterTextSectionSize = ((srcTextSectionSize + desTextSectionSize) + desFileAlignment - 1 + 10 /*アセンブリ分*/) / desFileAlignment * desFileAlignment;
//.textセクションのファイル上の増加量
DWORD desTextSectionAddition = desAfterTextSectionSize - desTextSectionSize;
//挿入後の.textセクションのメモリ上の大きさ?良く分からん。
//DWORD desAfterTextSectionVirtualSize = (desAfterTextSectionSize + desSectionAlignment - 1) / desSectionAlignment * desSectionAlignment;
DWORD desAfterTextSectionVirtualSize = desTextSectionVirtualSize + desTextSectionAddition;

//挿入後のexeの大きさ
SIZE_T fileSize
= desSize //元のファイルの大きさ
+ desTextSectionAddition //増えた.textセクションの大きさ
;

void *p = VirtualAlloc(NULL, fileSize, MEM_COMMIT, PAGE_READWRITE);


新着レスの表示


名前: E-mail(省略可)

※書き込む際の注意事項はこちら

※画像アップローダーはこちら

(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)

掲示板管理者へ連絡 無料レンタル掲示板