SHARE
TWEET

Untitled




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- #include <stdlib.h>
- DWORD align(DWORD number, DWORD alignment)
- {
- if(number % alignment == 0)
- return number;
- else
- return (number / alignment) * alignment + alignment;
- }
- char code[] = "\xE8\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x5A\x81\xEA\x0A\x10\x40"\
- "\x00\x89\xD1\x81\xC1\x31\x10\x40\x00\xB8\x7B\x1D\x80\x7C\x51\xFF\xD0\x6A\x00\x6A"\
- "\x00\x6A\x00\x6A\x00\xB8\xEA\x07\x3D\x7E\xFF\xD0\xC3\x75\x73\x65\x72\x33\x32\x2E"\
- "\x64\x6C\x6C\x00";
- int main()
- {
- IMAGE_DOS_HEADER dh;
- IMAGE_NT_HEADERS nth;
- IMAGE_SECTION_HEADER * seccion;
- IMAGE_SECTION_HEADER nSeccion;
- // char * stub_dos -> Datos del STUB_DOS
- //dSecciones-> Datos de las secciones
- long TamanoSecciones = 0;
- //int i;
- FILE * archivo = fopen("c:\\IsDgb.exe","r+b");
- if (archivo == NULL)
- {
- printf("Error al leer el archivo\n");
- system("PAUSE");
- return 1;
- }
- fread(&dh,sizeof(dh),1,archivo); // Rellenamos IMAGE_DOS_HEADER
- char * stub_dos = (char*)malloc(dh.e_lfanew-0x40);
- fread(stub_dos,1,dh.e_lfanew-0x40,archivo); // Leemos el Stub DOS
- fread(&nth,sizeof(nth),1,archivo); // leemos nt headers
- seccion = (IMAGE_SECTION_HEADER*)malloc(sizeof(IMAGE_SECTION_HEADER)*nth.FileHeader.NumberOfSections);
- fread(seccion,sizeof(IMAGE_SECTION_HEADER),nth.FileHeader.NumberOfSections,archivo);// leemos lascabeceras
- fseek(archivo,sizeof(dh)+(dh.e_lfanew-0x40)+sizeof(nth)+(sizeof(IMAGE_SECTION_HEADER)*nth.FileHeader.NumberOfSections)+0x28,SEEK_SET);
- // nos saltamos el espacio de 0's donde va a estar nuestra cabecera.
- TamanoSecciones = (seccion[nth.FileHeader.NumberOfSections-1].PointerToRawData + seccion[nth.FileHeader.NumberOfSections-1].SizeOfRawData) - seccion[0].PointerToRawData;
- char * dSecciones = (char*)malloc(TamanoSecciones);
- fread(dSecciones,TamanoSecciones,1,archivo); // leemos el cuerpo de las secciones.
- fclose(archivo); // terminamos de leer
- strcpy((char*)nSeccion.Name,".fary"); // nombre de la nueva sección: .fary
- nSeccion.VirtualAddress = align(seccion[nth.FileHeader.NumberOfSections-1].VirtualAddress + seccion[nth.FileHeader.NumberOfSections-1].Misc.VirtualSize, nth.OptionalHeader.SectionAlignment);
- nSeccion.SizeOfRawData = align(sizeof(code), nth.OptionalHeader.FileAlignment);
- nSeccion.PointerToRawData = align(sizeof(code),nth.OptionalHeader.FileAlignment);
- nSeccion.Characteristics = 0xE0000060;
- nSeccion.Misc.VirtualSize = sizeof(code);
- nth.FileHeader.NumberOfSections +=1; // sumamos la nueva sección
- nth.OptionalHeader.SizeOfImage = align(sizeof(code)+nSeccion.VirtualAddress,nth.OptionalHeader.SectionAlignment);
- nth.OptionalHeader.SizeOfHeaders += 0x28;
- nth.OptionalHeader.AddressOfEntryPoint = nSeccion.VirtualAddress;
- FILE * nuevo = fopen("Nuevo1.exe","wb+"); // Generamos el nuevo archivo :P
- fwrite(&dh,sizeof(dh),1,nuevo);
- fwrite(stub_dos,dh.e_lfanew-0x40,1,nuevo);
- fwrite(&nth,sizeof(nth),1,nuevo);
- nth.FileHeader.NumberOfSections -= 1;
- fwrite(seccion,sizeof(IMAGE_SECTION_HEADER)*nth.FileHeader.NumberOfSections,1,nuevo);
- fwrite(&nSeccion,sizeof(IMAGE_SECTION_HEADER),1,nuevo);
- fwrite(dSecciones,TamanoSecciones,1,nuevo);
- fwrite(code,sizeof(code),1,nuevo);
- fclose(nuevo);
- system("PAUSE");
- return 0;
- }
RAW Paste Data