[
板情報
|
カテゴリランキング
]
したらばTOP
■掲示板に戻る■
全部
1-100
最新50
|
メール
|
1-
101-
201-
301-
401-
501-
601-
701-
801-
901-
1001-
1101-
1201-
1301-
1401-
1501-
1601-
1701-
1801-
1901-
2001-
2101-
2201-
2301-
2401-
2501-
2601-
2701-
2801-
2901-
3001-
3101-
3201-
3301-
3401-
3501-
3601-
3701-
3801-
3901-
4001-
4101-
4201-
4301-
4401-
4501-
4601-
4701-
4801-
4901-
5001-
5101-
5201-
5301-
5401-
この機能を使うにはJavaScriptを有効にしてください
|
管理人の独り言(プログラミング関連)
1117
:
774さん
:2008/12/17(水) 23:42:25 ID:CENbthlg0
if(p){
#define DESTOP(po) (void *)((long)(po) - (long)(des) + (long)(p))
memcpy(p, des, desSize);
//TODO
//.textセクションの挿入&エントリポイントの変更&アセンブリ(バイナリ)の挿入&情報の修正
IMAGE_NT_HEADERS32 *pImageNtHeader = (IMAGE_NT_HEADERS32 *)DESTOP(pDesNtHeader);
IMAGE_SECTION_HEADER *pImageSections = (IMAGE_SECTION_HEADER *)DESTOP(pDesSections);
IMAGE_SECTION_HEADER *pTextSection = (IMAGE_SECTION_HEADER *)DESTOP(pDesTextSection);
//.textセクションより後ろにあるものを移動&値変更
{
//.textセクションの開始位置(RVA)
DWORD pTextSectionPointerToRawData = pTextSection->PointerToRawData;
std::priority_queue<std::pair<DWORD, IMAGE_SECTION_HEADER *>, std::vector<std::pair<DWORD, IMAGE_SECTION_HEADER *> >, std::greater<std::vector<std::pair<DWORD, IMAGE_SECTION_HEADER *> >::value_type > > q;
for(int i = 0; i < desNumberOfSections; ++i){
if(pImageSections[i].PointerToRawData > pTextSectionPointerToRawData){
q.push(std::pair<DWORD, IMAGE_SECTION_HEADER *>(pImageSections[i].PointerToRawData, &pImageSections[i]));
pImageSections[i].PointerToRawData += desTextSectionAddition;
}
}
while(!q.empty()){
std::pair<DWORD, IMAGE_SECTION_HEADER *> &top = q.top();
void *sp = RVA(p, top.first);
memmove(RVA(sp, desTextSectionAddition), sp, top.second->SizeOfRawData);
q.pop();
}
}
//.textセクションを弄くる
{
void *sp = RVA(p, pTextSection->PointerToRawData);
memmove(RVA(sp, desTextSectionAddition), sp, pTextSection->SizeOfRawData);
static const BYTE code[] = {
0xE8, 0x00, 0x00, 0x00, 0x00, //CALL rel32
0xE9, 0x00, 0x00, 0x00, 0x00, //JMP rel32
};
memcpy(sp, code, sizeof(code));
memcpy(RVA(sp, sizeof(code)), RVA(src, pSrcTextSection->PointerToRawData), pSrcTextSection->SizeOfRawData);
//挿入元のEXEのエントリポイントの.textでの相対位置
DWORD srcEntryPoint = pSrcNtHeader->OptionalHeader.AddressOfEntryPoint - pSrcNtHeader->OptionalHeader.BaseOfCode;
//挿入先のEXEのエントリポイントの.textでの相対位置
DWORD desEntryPoint = pDesNtHeader->OptionalHeader.AddressOfEntryPoint - pDesNtHeader->OptionalHeader.BaseOfCode;
pImageNtHeader->OptionalHeader.AddressOfEntryPoint = pImageNtHeader->OptionalHeader.BaseOfCode;
*((DWORD *)RVA(sp, 1)) = sizeof(code) - 5 + srcEntryPoint;
*((DWORD *)RVA(sp, 6)) = desTextSectionAddition + desEntryPoint - 10;
}
//.textセクションの大きさの修正
{
pTextSection->SizeOfRawData = desAfterTextSectionSize;
pTextSection->Misc.VirtualSize = desAfterTextSectionVirtualSize;
}
FILE *filew = fopen("out.exe", "wb");
fwrite(p, fileSize, 1, filew);
VirtualFree(p, fileSize, MEM_DECOMMIT);
}
}
}
}
}
新着レスの表示
名前:
E-mail
(省略可)
:
※書き込む際の注意事項は
こちら
※画像アップローダーは
こちら
(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)
スマートフォン版
掲示板管理者へ連絡
無料レンタル掲示板