Feliz cumpleaños BlackZeroX, cuanto lo siento la fecha no tenia conocimiento.
Saludos y que cumplas muchos más!
Saludos y que cumplas muchos más!
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú/*
-----------------------------------------------------------
- Function: RealignPE v2 -
- Programmer: The Swash -
- Web: http://www.h-sec.org -
- Dedicated: Thor, Psymera, Steve10120, [Zero], Karcrack -
-----------------------------------------------------------
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#define ReadWriteBinary "r+b"
int AlingNum(int num, int aling);
char * BytesAling(int number);
int main(void)
{
printf("%i ",RealignPE("C:\\hi.exe"));
getchar();
}
int RealignPE(char * lpFile)
{
IMAGE_DOS_HEADER IDH;
IMAGE_FILE_HEADER IFH;
IMAGE_OPTIONAL_HEADER IOH;
IMAGE_SECTION_HEADER ISH;
DWORD PESignature = 0;
FILE * lFile;
int OriSize = 0;
int ActSize = 0;
int Alingned = 0;
lFile = fopen(lpFile,ReadWriteBinary);
if (lFile == NULL) {return -1;}
else
{
fread(&IDH, 64, 1, lFile);
fseek(lFile, IDH.e_lfanew , SEEK_SET);
fread(&PESignature, 4, 1, lFile);
if (IDH.e_magic != IMAGE_DOS_SIGNATURE) {fclose (lFile); return -2;}
else
{
if(PESignature != IMAGE_NT_SIGNATURE) {fclose (lFile); return -3;}
else
{
fseek(lFile, IDH.e_lfanew + 4, SEEK_SET);
fread(&IFH, sizeof(IFH), 1, lFile);
fseek(lFile, IDH.e_lfanew + 4 + sizeof(IFH), SEEK_SET);
fread(&IOH, IFH.SizeOfOptionalHeader, 1, lFile);
fseek(lFile, IDH.e_lfanew + 4 + sizeof(IFH) + IFH.SizeOfOptionalHeader + (sizeof(ISH)*(IFH.NumberOfSections-1)),SEEK_SET);
fread(&ISH, sizeof(ISH), 1, lFile);
fseek(lFile, 0, SEEK_END);
ActSize = ftell(lFile);
OriSize = ISH.PointerToRawData + ISH.SizeOfRawData;
if (ActSize - OriSize > 0)
{
Alingned = AlingNum(ActSize - OriSize, IOH.FileAlignment);
ISH.SizeOfRawData += Alingned;
ISH.Misc.VirtualSize += Alingned;
IOH.SizeOfImage = ISH.Misc.VirtualSize + ISH.VirtualAddress;
IOH.SizeOfInitializedData += Alingned;
if (ISH.VirtualAddress == IOH.DataDirectory[2].VirtualAddress)
{
IOH.DataDirectory[2].Size += Alingned;
}
fseek(lFile, IDH.e_lfanew + 4 + sizeof(IFH), SEEK_SET);
fwrite(&IOH, 1, IFH.SizeOfOptionalHeader, lFile);
fseek(lFile, IDH.e_lfanew + 4 + sizeof(IFH) + IFH.SizeOfOptionalHeader + (sizeof(ISH)*(IFH.NumberOfSections-1)),SEEK_SET);
fwrite(&ISH, 1, sizeof(ISH), lFile);
if (Alingned - (ActSize - OriSize) > 0)
{
fseek(lFile, ActSize, SEEK_SET);
fwrite(BytesAling(Alingned-(ActSize - OriSize)), 1, Alingned-(ActSize - OriSize), lFile);
}
return 0;
}
else {return 1;}
}
}
}
}
int AlingNum(int num, int aling)
{
if(num % aling == 0)
{ return num; }
else if(num < aling)
{ return aling; }
else { return (num / aling) * aling + aling; }
}
char * BytesAling(int number)
{
char * sTemp = (char *) malloc(number + 1);
int i;
for (i=0; i<number; i++)
{
sTemp[i] = '\0';
}
return sTemp;
}
/*
[Get size of file to base of PE]
- Programmer: The Swash
- Dedicated: Zero, Thor Psymera, Steve10120
*/
#include <windows.h>
#include <stdio.h>
#define RB "rb"
int PEFileSize(char * fPath);
int main(void)
{
printf("File size: %i", PEFileSize("C:\\test.exe"));
getchar();
}
int PEFileSize(char * fPath)
{
IMAGE_DOS_HEADER IDH;
IMAGE_NT_HEADERS INH;
IMAGE_SECTION_HEADER ISH;
FILE * lpFile;
int sTemp = 0, i;
lpFile = fopen(fPath,RB);
if (lpFile != NULL)
{
fseek(lpFile, 0, SEEK_SET); // Seek to begin of file
fread(&IDH, sizeof(IDH), 1, lpFile); // Read 64 bytes to IDH struct
if (IDH.e_magic == IMAGE_DOS_SIGNATURE) // If IDH.e_magic = (MZ)
{
fseek(lpFile, IDH.e_lfanew, SEEK_SET); // Seek in file in begin of NT Headers (PE)
fread(&INH, sizeof(INH), 1, lpFile); // Read in structure 248 bytes
if (INH.Signature == IMAGE_NT_SIGNATURE) // If INH.Signature = (PE)
{
for (i = 0; i < INH.FileHeader.NumberOfSections; i++) // go for all sections
{
fseek(lpFile, IDH.e_lfanew + sizeof(INH) + sizeof(ISH)*i, SEEK_SET); // Seek in actual section
fread(&ISH, sizeof(ISH), 1, lpFile); // Read section
sTemp += ISH.SizeOfRawData; // Save sizeofrawdata of section
}
sTemp += INH.OptionalHeader.SizeOfHeaders;
fclose(lpFile);
return sTemp;
}
}
else
{
return -1;
}
}
else
{
return -1;
}
}
#include <stdio.h>
int main()
{
int D = 0;
if (D == 0)
{
printf("etapa 1");
if (D == 0)
{
printf("etapa 2");
if (D == 0)
{
printf("etapa 3");
while (D <= 6);
{
D++;
}
printf("etapa 5");
}
}
}
}
http://codepad.org/bNsMr5Z7
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* @autor: The Swash
@function: IntToStr - StrToInt
@language: ANSI C
*/
int StrToInt(char * string);
char * IntToStr(int number);
int main()
{
printf("char: %s \n",IntToStr(123));
printf("int: %i",StrToInt("123"));
return 0;
}
int StrToInt(char * string)
{
int i, n, temp = 0;
for (i = 0; i < strlen(string); i++)
{
if ( ( (int)string[i]< 48 ) || ( (int)string[i]>57 ) ) // Si el caracter es distinto a un numero
{
return -1; //Salimos y retornamos -1
}
else
{
for (n = 48; n <= 57; n++) // Hacemos un bucle desde el numero 0 al 9 basandonos en su valor ASCII
{
if (string[i] == n) // Si el valor ASCII del caracter actual correspondi al valor ASCII de un numero
{
temp += (string[i] - 48); // Obtiene y suma el número actual al buffer
temp *= 10; // Aumenta una cifra al resultado
}
}
}
}
return temp / 10; // Retorna el buffer, quitandole la última cifra que sobra
}
char * IntToStr(int number)
{
int num, len = 0, i = 0, altnumber = number;
char * buffer;
if (number == 0)
{
return "0";
}
else
{
while (number > 0)
{
num = number%10;
number = number / 10;
len++;
}
buffer = (char *) malloc (len);
memset(buffer,0,strlen(buffer));
num = 0;
i = len -1;
while (altnumber> 0)
{
num = altnumber%10;
altnumber = altnumber / 10;
buffer[i] = (num + 48);
i--;
}
return buffer;
}
}