rendered paste bodyint NewImageSize(unsigned char *Image)
{
DWORD Alignment=0;
DWORD SectionLoop=0;
int Result=0;
TSections **PSections;
PIMAGE_NT_HEADERS ImageNtHeaders;
PIMAGE_DOS_HEADER ImageDosHeader;
ImageDosHeader = (PIMAGE_DOS_HEADER)Image;
ImageNtHeaders = (PIMAGE_NT_HEADERS)((DWORD)(Image) + (DWORD)(ImageDosHeader->e_lfanew));
Alignment = ImageNtHeaders->OptionalHeader.SectionAlignment;
if((ImageNtHeaders->OptionalHeader.SizeOfHeaders % Alignment ==0))
Result = ImageNtHeaders->OptionalHeader.SizeOfHeaders;
else
Result = ((ImageNtHeaders->OptionalHeader.SizeOfHeaders / Alignment)+1)*Alignment;
PSections=(TSections **)((unsigned char *)(&ImageNtHeaders->OptionalHeader)+ImageNtHeaders->FileHeader.SizeOfOptionalHeader);
for(SectionLoop=0; SectionLoop < (DWORD)(ImageNtHeaders->FileHeader.NumberOfSections-1); SectionLoop++){
if((PSections[SectionLoop]->Misc.VirtualSize) < 0 || (PSections[SectionLoop]->Misc.VirtualSize) > 0){
if(PSections[SectionLoop]->Misc.VirtualSize % Alignment ==0)
Result = Result + PSections[SectionLoop]->Misc.VirtualSize ;
else
Result = Result+(((PSections[SectionLoop]->Misc.VirtualSize / Alignment)+1)*Alignment);
}
}
return Result;
}