Add rayman2 source files

This commit is contained in:
2024-09-18 02:33:44 +08:00
parent bcc093f8ed
commit fb036c54fd
14339 changed files with 2596224 additions and 0 deletions

View File

@@ -0,0 +1,260 @@
#include <windows.h>
#include <stdio.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
char szArrayOfNames[][100] =
{
"GetModuleHandleA" , "GetModuleHandleW" ,
"FlushInstructionCache" ,
"GetCurrentProcess" ,
"QueryPerformanceFrequency" ,
"OpenEventA" , "OpenEventW" ,
"CreateEventA" , "CreateEventW" ,
"ResetEvent" ,
"SetEvent" ,
"CreateFileA" , "CreateFileW" ,
"WriteFile" ,
"ReadFile" ,
"CloseHandle" ,
"SetErrorMode",
"GetFileInformationByHandle",
"GetDiskFreeSpaceA",
"SetFileAttributsA",
"GetFileAttributsA",
"GetDiskFreeSpaceW",
"SetFileAttributsW",
"GetFileAttributsW",
"GetFileTime",
"SetFileTime",
"SetFilePointer" ,
"FlushFileBuffer" ,
"QueryPerformanceCounter" ,
"GetDriveTypeA" , "GetDrivrTypeW" ,
"GetVolumeInformationA" , "GetVolumeInformationW" ,
"GetLogicalDriveStringsA" , "GetLogicalDriveStringsW" ,
"GetFileSize" ,
"CreateToolhelp32Snapshot" ,
"Process32First" , "Process32Next" ,
"Module32First" , "Module32Next" ,
"EnumProcesses" , "EnumProcessModules" ,
"LoadLibraryA" , "LoadLibraryW" ,
"FreeLibrary" ,
"Kernel32.dll" ,
"User32.dll" ,
"PSAPI.dll" ,
"ADVAPI32.dll" ,
"GDI32.dll" ,
"VERSION.dll" ,
"WINMM.dll" ,
""
};
//int main(int argc,char *argv[])
//{
// unsigned char cXor = 0x87;
// char c;
// char szText[1024],szCode[255];
// FILE *pFile;
// long l;
// unsigned long ulXor;
// ////////////////////////////////
// pFile = fopen("x:\\cpa\\public\\PTC\\PTC_ABC.h" ,"wt");
// fprintf (pFile, "/* ----------------------------------------------------------------------------------------------------------------- */\n");
// fprintf (pFile, "#ifndef _PTC_ABC_H_ // {\n");
// fprintf (pFile, "#define _PTC_ABC_H_\n");
// fprintf (pFile, "/* ----------------------------------------------------------------------------------------------------------------- */\n");
// fprintf (pFile , "\n");
// /* character code */
// ulXor = (unsigned long)cXor;
// fprintf (pFile, "#define PTC_C_Code_Xor 0x%x\n\n" , ulXor);
// for (c='a' ; c<='z' ; c++)
// {
// ulXor = (unsigned long)c^cXor;
// fprintf (pFile, "#define PTC_C_Code_%c\t\t\"\\x%X\"\n" , c , c^cXor);
// }
// fprintf (pFile , "\n");
// for (c='A' ; c<='Z' ; c++)
// {
// ulXor = (unsigned long)c^cXor;
// fprintf (pFile, "#define PTC_C_Code_%c\t\t\"\\x%X\"\n" , c , c^cXor);
// }
// fprintf (pFile , "\n");
// for (c='0' ; c<='9' ; c++)
// {
// ulXor = (unsigned long)c^cXor;
// fprintf (pFile, "#define PTC_C_Code_%c\t\t\"\\x%X\"\n" , c , c^cXor);
// }
// fprintf (pFile , "\n");
// fprintf (pFile, "#define PTC_C_Code_%s\t\t\"\\x%X\"\n" , "Point" , '.'^cXor);
// fprintf (pFile , "\n");
// fprintf (pFile , "\n");
// fprintf (pFile, "/* ----------------------------------------------------------------------------------------------------------------- */\n");
// fprintf (pFile, "/* Function Names code */\n");
// fprintf (pFile , "\n");
// ////////////////////////////////////////////
// fprintf (pFile , "\n\n");
// for (l=0 ; l<100 ; l++)
// {
// char *szName = szArrayOfNames[l];
// if (*szName)
// {
// char *p_cChar = szName+1;
// char *p_cPoint;
// *szText = 0;
// while (*p_cChar)
// {
// if (*p_cChar == '.')
// {
// strcpy (szCode , " PTC_C_Code_Point");p_cChar++;
// }
// else
// sprintf (szCode , " PTC_C_Code_%c" , *p_cChar++);
// strcat(szText , szCode);
// }
// p_cPoint = strchr(szName , '.');
// if (p_cPoint) *p_cPoint = '_';
// fprintf (pFile , "#define PTC_C_%sName\t\tPTC_C_Code_%c%s\n" , szName , szName[0],szText);
// //fprintf (pFile , "%s\n" , szText);
// }
// else
// {
// break;
// }
// }
// fprintf (pFile , "\n");
// fprintf (pFile, "/* ----------------------------------------------------------------------------------------------------------------- */\n");
// fprintf (pFile , "\n");
// fprintf (pFile , "#endif // _PTC_ABC_H_ }\n");
// fclose (pFile);
// return(0);
//}
/* ---------------- */
/* random functions */
/* ---------------- */
long PTC_g_lCurrentRandom;
long PTC_fn_lGetRandom()
{
long lTmp;
PTC_g_lCurrentRandom ^= 123459876;
lTmp = PTC_g_lCurrentRandom / 127773;
PTC_g_lCurrentRandom = 16807 * (PTC_g_lCurrentRandom - lTmp * 127773) - 2836 * lTmp;
if (PTC_g_lCurrentRandom < 0) PTC_g_lCurrentRandom += 2147483647;
return PTC_g_lCurrentRandom;
}
long PTC_fn_lGetRandomRange(long _lMin , long _lMax)
{
return (_lMin + (PTC_fn_lGetRandom() % (_lMax - _lMin)));
}
int main(int argc,char *argv[])
{
LARGE_INTEGER xCounter;
unsigned char cXor = 0x87;
char c;
char szText[1024],szCode[255];
FILE *pFile;
long l;
unsigned long ulXor;
if (QueryPerformanceCounter (&xCounter))
{
PTC_g_lCurrentRandom = xCounter.LowPart;
}
else
{
PTC_g_lCurrentRandom = 0x12345678;
}
////////////////////////////////
pFile = fopen("x:\\cpa\\public\\PTC\\PTC_ABC.h" ,"wt");
fprintf (pFile, "/* ----------------------------------------------------------------------------------------------------------------- */\n");
fprintf (pFile, "#ifndef _PTC_ABC_H_ // {\n");
fprintf (pFile, "#define _PTC_ABC_H_\n");
fprintf (pFile, "/* ----------------------------------------------------------------------------------------------------------------- */\n");
fprintf (pFile, "/* Function Names code */\n");
fprintf (pFile , "\n");
/* character code */
for (l=0 ; l<100 ; l++)
{
char *szName = szArrayOfNames[l];
if (*szName)
{
long lCryptKey = PTC_fn_lGetRandom();
unsigned char *p_ucCryptKey = (unsigned char*)&lCryptKey;
unsigned char *p_ucChar = (unsigned char*)szName;
char *p_cPoint;
// Crypt Key
sprintf (szText , "\\x%02X\\x%02X\\x%02X\\x%02X" , p_ucCryptKey[0] , p_ucCryptKey[1] , p_ucCryptKey[2] , p_ucCryptKey[3]);
// Size
sprintf (szCode , "\\x%02X" , strlen (szName));
strcat (szText , szCode);
// Name
while(*p_ucChar)
{
unsigned char cCode = (*p_ucChar++ ^ p_ucCryptKey[1]) + p_ucCryptKey[0];
p_ucCryptKey[0] += p_ucCryptKey[2];
p_ucCryptKey[1] += p_ucCryptKey[3];
sprintf (szCode , "\\x%02X" , cCode);
strcat (szText , szCode);
}
p_cPoint = strchr(szName , '.');
if (p_cPoint) *p_cPoint = '_';
fprintf (pFile , "#define PTC_C_%sName\t\t\"%s\"\n" , szName , szText);
}
else
{
break;
}
}
fprintf (pFile , "\n");
fprintf (pFile, "/* ----------------------------------------------------------------------------------------------------------------- */\n");
fprintf (pFile , "\n");
fprintf (pFile , "#endif // _PTC_ABC_H_ }\n");
fclose (pFile);
return(0);
}

View File

@@ -0,0 +1,88 @@
# Microsoft Developer Studio Project File - Name="GenerABC" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 5.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=GenerABC - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "GenerABC.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "GenerABC.mak" CFG="GenerABC - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "GenerABC - Win32 Release" (based on\
"Win32 (x86) Console Application")
!MESSAGE "GenerABC - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "GenerABC - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x40c /d "NDEBUG"
# ADD RSC /l 0x40c /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "GenerABC - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x40c /d "_DEBUG"
# ADD RSC /l 0x40c /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "GenerABC - Win32 Release"
# Name "GenerABC - Win32 Debug"
# Begin Source File
SOURCE=.\GenerABC.cpp
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,6 @@
#if !defined(__DEFLIB_H__)
#define __DEFLIB_H__
#include <stddef.h>
#endif // __DEFLIB_H__

View File

@@ -0,0 +1,46 @@
#if !defined(__MEMLIB_H__)
#define __MEMLIB_H__
#if defined(USE_STDMEMLIB)
#include <stddef.h>
#include <malloc.h>
#include <string.h>
#define MemoryInit()
#define MemoryDone()
#define MemoryAlloc malloc
#define MemoryCalloc calloc
#define MemoryFree(x) { if (*(x)) { free((void*) *(x)); *(x)=NULL; } }
#define MemorySet memset
#define MemoryMove memmove
#define MemoryCopy memcpy
#define MemoryCompare memcmp
#else
#include "deflib.h"
#if defined(__cplusplus)
extern "C" {
#endif
void MemoryInit();
void MemoryDone();
void *MemoryAlloc(size_t size);
void *MemoryCalloc(size_t num,size_t size);
void MemoryFree(void** ptr);
void *MemorySet(void *dest,int c,size_t count);
void *MemoryMove(void *dest,const void *src,size_t count);
void *MemoryCopy(void *dest,const void *src,size_t count);
int MemoryCompare(const void *buf1,const void *buf2, size_t count);
#if defined(__cplusplus)
}
#endif
#endif // USE_STDMEMLIB
#endif // __MEMLIB_H__

View File

@@ -0,0 +1,135 @@
#if !defined(__STRLIB_H__)
#define __STRLIB_H__
#include "acp_base.h"
#if defined(USE_STDSTRLIB)
#include <string.h>
#define StringCopy strcpy
#define StringLength strlen
#define StringCat strcat
#define StringNCopy strncpy
#define StringRChar strrchr
#define StringChar strchr
#define StringCompare strcmp
#define StringICompare stricmp
#define StringNICompare strnicmp
#define StringNCompare strncmp
#define StringString strstr
#define StringUpper strupr
#define StringLower strlwr
#if defined(USE_CRYPTNAME)
#define StringCompareToCryptKey strcmp
#else
#define StringCompareToCryptKey strcmp
#endif
#elif defined(INLINE_STDSTRLIB)
INLINE
const char * __cdecl StringCopy(const char * dst,const char * src)
{
const char *savedst=dst;
while( (*(unsigned char *)dst++=*(unsigned char *)src++) );
return(savedst);
}
INLINE
int __cdecl StringCompare(const char * src,const char * dst)
{
int ret = 0 ;
while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
++src, ++dst;
if ( ret < 0 ) ret = -1 ;
else if ( ret > 0 ) ret = 1 ;
return( ret );
}
INLINE
int __cdecl StringICompare(const char * dst, const char * src)
{
int f,l;
do
{
if ( ((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z') )
f -= ('A' - 'a');
if ( ((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z') )
l -= ('A' - 'a');
}
while ( f && (f == l) );
return(f - l);
}
#if defined(USE_CRYPTNAME)
INLINE
int __cdecl StringCompareToCryptKey(const char * src,const char * dst)
{
int ret = 0 ;
long lKey = *(long*)(dst);
unsigned char *p_ucCryptKey = (unsigned char*) &lKey;
unsigned char ucSize = (unsigned char)dst [4];
unsigned char ucIndex;
unsigned char ucUncoded;
dst += 5;
for (ucIndex = 0 ; ucIndex < ucSize ; ucIndex++)
{
// uncode dst char
ucUncoded = (*(unsigned char *)dst++ - p_ucCryptKey[0]) ^ p_ucCryptKey[1];
p_ucCryptKey[0] += p_ucCryptKey[2];
p_ucCryptKey[1] += p_ucCryptKey[3];
// compare
ret = *(unsigned char *)src++ - ucUncoded;
if(ret) break;
}
if ( ret < 0 ) ret = -1 ;
else if ( ret > 0 ) ret = 1 ;
return( ret );
}
#else
#define StringCompareToCryptKey StringCompare
#endif
#else
#include "deflib.h"
#if defined(__cplusplus)
extern "C" {
#endif
char *StringCopy(char *StrDestination,const char *StrSource);
size_t StringLength(const char *String);
char *StringCat(char *StrDestination,const char *StrSource);
char *StringNCopy(char *StrDestination,const char *StrSource,size_t count);
char *StringRChar(const char *String,int c);
char *StringChar(const char *String,int c);
int StringNICompare(const char *String1,const char *String2,size_t count);
int StringNCompare(const char *String1,const char *String2,size_t count);
int StringICompare(const char *String1,const char *String2);
int StringCompare(const char *String1,const char *String2);
char *StringString(const char *string,const char *strCharSet);
char *StringUpper(char *string);
char *StringLower(char *string);
#if defined(USE_CRYPTNAME)
int StringCompareToCryptKey(const char *String1,const char *String2);
#else
#define StringCompareToCryptKey strcmp
#endif
#if defined(__cplusplus)
}
#endif
#endif // USE_STDSTRLIB
#endif // __STRLIB_H__

View File

@@ -0,0 +1,640 @@
/* this file define all structures used in PE file */
/* found on Microsoft site */
#include "pefile.h"
/* copy dos header information to structure */
BOOL WINAPI GetDosHeader (
LPVOID lpFile,
PIMAGE_DOS_HEADER pHeader)
{
/* dos header rpresents first structure of bytes in file */
if (*(USHORT *)lpFile == IMAGE_DOS_SIGNATURE)
CopyMemory ((LPVOID)pHeader, lpFile, sizeof (IMAGE_DOS_HEADER));
else
return FALSE;
return TRUE;
}
/* return file signature */
DWORD WINAPI ImageFileType (
LPVOID lpFile)
{
/* dos file signature comes first */
if (*(USHORT *)lpFile == IMAGE_DOS_SIGNATURE)
{
/* determine location of PE File header from dos header */
if (LOWORD (*(DWORD *)NTSIGNATURE (lpFile)) == IMAGE_OS2_SIGNATURE ||
LOWORD (*(DWORD *)NTSIGNATURE (lpFile)) == IMAGE_OS2_SIGNATURE_LE)
return (DWORD)LOWORD(*(DWORD *)NTSIGNATURE (lpFile));
else if (*(DWORD *)NTSIGNATURE (lpFile) == IMAGE_NT_SIGNATURE)
return IMAGE_NT_SIGNATURE;
else
return IMAGE_DOS_SIGNATURE;
}
else
/* unknown file type */
return 0;
}
/* copy file header information to structure */
BOOL WINAPI GetPEFileHeader (
LPVOID lpFile,
PIMAGE_FILE_HEADER pHeader)
{
/* file header follows dos header */
if (ImageFileType (lpFile) == IMAGE_NT_SIGNATURE)
CopyMemory ((LPVOID)pHeader, PEFHDROFFSET (lpFile), sizeof (IMAGE_FILE_HEADER));
else
return FALSE;
return TRUE;
}
/* copy optional header info to structure */
BOOL WINAPI GetPEOptionalHeader (
LPVOID lpFile,
PIMAGE_OPTIONAL_HEADER pHeader)
{
/* optional header follows file header and dos header */
if (ImageFileType (lpFile) == IMAGE_NT_SIGNATURE)
CopyMemory ((LPVOID)pHeader, OPTHDROFFSET (lpFile), sizeof (IMAGE_OPTIONAL_HEADER));
else
return FALSE;
return TRUE;
}
/* function returns the entry point for an exe module lpFile must
be a memory mapped file pointer to the beginning of the image file */
LPVOID WINAPI GetModuleEntryPoint (
LPVOID lpFile)
{
PIMAGE_OPTIONAL_HEADER poh = (PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET (lpFile);
if (poh != NULL)
return (LPVOID)(poh->AddressOfEntryPoint);
else
return NULL;
}
/* return the total number of sections in the module */
int WINAPI NumOfSections (
LPVOID lpFile)
{
/* number os sections is indicated in file header */
return ((int)((PIMAGE_FILE_HEADER)PEFHDROFFSET (lpFile))->NumberOfSections);
}
/* retrieve entry point */
LPVOID WINAPI GetImageBase (
LPVOID lpFile)
{
PIMAGE_OPTIONAL_HEADER poh = (PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET (lpFile);
if (poh != NULL)
return (LPVOID)(poh->ImageBase);
else
return NULL;
}
/* return offset to specified IMAGE_DIRECTORY entry */
LPVOID WINAPI ImageDirectoryOffset (
LPVOID lpFile,
DWORD dwIMAGE_DIRECTORY)
{
PIMAGE_OPTIONAL_HEADER poh = (PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET (lpFile);
PIMAGE_SECTION_HEADER psh = (PIMAGE_SECTION_HEADER)SECHDROFFSET (lpFile);
int nSections = NumOfSections (lpFile);
int i = 0;
LPVOID VAImageDir;
/* must be 0 thru (NumberOfRvaAndSizes-1) */
if (dwIMAGE_DIRECTORY >= poh->NumberOfRvaAndSizes)
return NULL;
/* locate specific image directory's relative virtual address */
VAImageDir = (LPVOID)poh->DataDirectory[dwIMAGE_DIRECTORY].VirtualAddress;
/* locate section containing image directory */
while (i++<nSections)
{
if (psh->VirtualAddress <= (DWORD)VAImageDir &&
psh->VirtualAddress + psh->SizeOfRawData > (DWORD)VAImageDir)
break;
psh++;
}
if (i > nSections)
return NULL;
/* return image import directory offset */
return (LPVOID)(((int)lpFile + (int)VAImageDir - psh->VirtualAddress) +
(int)psh->PointerToRawData);
}
/* function retrieve names of all the sections in the file */
int WINAPI GetSectionNames (
LPVOID lpFile,
HANDLE hHeap,
char **pszSections)
{
int nSections = NumOfSections (lpFile);
int i, nCnt = 0;
PIMAGE_SECTION_HEADER psh;
char *ps;
if (ImageFileType (lpFile) != IMAGE_NT_SIGNATURE ||
(psh = (PIMAGE_SECTION_HEADER)SECHDROFFSET (lpFile)) == NULL)
return 0;
/* count the number of chars used in the section names */
for (i=0; i<nSections; i++)
nCnt += strlen ((char*) psh[i].Name) + 1;
/* allocate space for all section names from heap */
ps = *pszSections = (char *)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, nCnt);
for (i=0; i<nSections; i++)
{
strcpy (ps, (char*) psh[i].Name);
ps += strlen ((char*) psh[i].Name) + 1;
}
return nCnt;
}
/* function gets the function header for a section identified by name */
BOOL WINAPI GetSectionHdrByName (
LPVOID lpFile,
IMAGE_SECTION_HEADER *sh,
char *szSection)
{
PIMAGE_SECTION_HEADER psh;
int nSections = NumOfSections (lpFile);
int i;
if ((psh = (PIMAGE_SECTION_HEADER)SECHDROFFSET (lpFile)) != NULL)
{
/* find the section by name */
for (i=0; i<nSections; i++)
{
if (!strcmp ((char*) psh->Name, szSection))
{
/* copy data to header */
CopyMemory ((LPVOID)sh, (LPVOID)psh, sizeof (IMAGE_SECTION_HEADER));
return TRUE;
}
else
psh++;
}
}
return FALSE;
}
/* get import modules names separated by null terminators, return module count */
int WINAPI GetImportModuleNames (
LPVOID lpFile,
HANDLE hHeap,
char **pszModules)
{
PIMAGE_IMPORT_MODULE_DIRECTORY pid = (PIMAGE_IMPORT_MODULE_DIRECTORY)
ImageDirectoryOffset (lpFile, IMAGE_DIRECTORY_ENTRY_IMPORT);
IMAGE_SECTION_HEADER idsh;
BYTE *pData = (BYTE *)pid;
int nCnt = 0, nSize = 0, i;
char *pModule[1024]; /* hardcoded maximum number of modules?? */
char *psz;
/* locate section header for ".idata" section */
if (!GetSectionHdrByName (lpFile, &idsh, ".idata"))
return 0;
/* extract all import modules */
while (pid->dwRVAModuleName)
{
/* allocate temporary buffer for absolute string offsets */
pModule[nCnt] = (char *)(pData + (pid->dwRVAModuleName-idsh.VirtualAddress));
nSize += strlen (pModule[nCnt]) + 1;
/* increment to the next import directory entry */
pid++;
nCnt++;
}
/* copy all strings to one chunk of heap memory */
*pszModules = (char*) HeapAlloc (hHeap, HEAP_ZERO_MEMORY, nSize);
psz = *pszModules;
for (i=0; i<nCnt; i++)
{
strcpy (psz, pModule[i]);
psz += strlen (psz) + 1;
}
return nCnt;
}
/* get import module function names separated by null terminators, return function count */
int WINAPI GetImportFunctionNamesByModule (
LPVOID lpFile,
HANDLE hHeap,
char *pszModule,
char **pszFunctions)
{
PIMAGE_IMPORT_MODULE_DIRECTORY pid = (PIMAGE_IMPORT_MODULE_DIRECTORY)
ImageDirectoryOffset (lpFile, IMAGE_DIRECTORY_ENTRY_IMPORT);
IMAGE_SECTION_HEADER idsh;
DWORD dwBase;
int nCnt = 0, nSize = 0;
DWORD dwFunction;
char *psz;
/* locate section header for ".idata" section */
if (!GetSectionHdrByName (lpFile, &idsh, ".idata"))
return 0;
dwBase = ((DWORD)pid - idsh.VirtualAddress);
/* find module's pid */
while (pid->dwRVAModuleName &&
strcmp (pszModule, (char *)(pid->dwRVAModuleName+dwBase)))
pid++;
/* exit if the module is not found */
if (!pid->dwRVAModuleName)
return 0;
/* count number of function names and length of strings */
dwFunction = pid->dwRVAFunctionNameList;
while (dwFunction &&
*(DWORD *)(dwFunction + dwBase) &&
*(char *)((*(DWORD *)(dwFunction + dwBase)) + dwBase+2))
{
nSize += strlen ((char *)((*(DWORD *)(dwFunction + dwBase)) + dwBase+2)) + 1;
dwFunction += 4;
nCnt++;
}
/* allocate memory off heap for function names */
*pszFunctions = (char*) HeapAlloc (hHeap, HEAP_ZERO_MEMORY, nSize);
psz = *pszFunctions;
/* copy function names to mempry pointer */
dwFunction = pid->dwRVAFunctionNameList;
while (dwFunction &&
*(DWORD *)(dwFunction + dwBase) &&
*((char *)((*(DWORD *)(dwFunction + dwBase)) + dwBase+2)))
{
strcpy (psz, (char *)((*(DWORD *)(dwFunction + dwBase)) + dwBase+2));
psz += strlen ((char *)((*(DWORD *)(dwFunction + dwBase)) + dwBase+2)) + 1;
dwFunction += 4;
}
return nCnt;
}
/* get exported function names separated by null terminators, return count of functions */
int WINAPI GetExportFunctionNames (
LPVOID lpFile,
HANDLE hHeap,
char **pszFunctions)
{
IMAGE_SECTION_HEADER sh;
PIMAGE_EXPORT_DIRECTORY ped;
char *pNames, *pCnt;
int i, nCnt;
/* get section header and pointer to data directory for .edata section */
if ((ped = (PIMAGE_EXPORT_DIRECTORY)ImageDirectoryOffset
(lpFile, IMAGE_DIRECTORY_ENTRY_EXPORT)) == NULL)
return 0;
GetSectionHdrByName (lpFile, &sh, ".edata");
/* determine the offset of the export function names */
pNames = (char *)(*(int *)((int)ped->AddressOfNames -
(int)sh.VirtualAddress +
(int)sh.PointerToRawData +
(int)lpFile) -
(int)sh.VirtualAddress +
(int)sh.PointerToRawData +
(int)lpFile);
/* figure out how much memory to allocate for all strings */
pCnt = pNames;
for (i=0; i<(int)ped->NumberOfNames; i++)
while (*pCnt++);
nCnt = (int)(pCnt - pNames);
/* allocate memory off heap for function names */
*pszFunctions = (char*) HeapAlloc (hHeap, HEAP_ZERO_MEMORY, nCnt);
/* copy all string to buffer */
CopyMemory ((LPVOID)*pszFunctions, (LPVOID)pNames, nCnt);
return nCnt;
}
/* return the number of exported functions in the module */
int WINAPI GetNumberOfExportedFunctions (
LPVOID lpFile)
{
PIMAGE_EXPORT_DIRECTORY ped;
/* get section header and pointer to data directory for .edata section */
if ((ped = (PIMAGE_EXPORT_DIRECTORY)ImageDirectoryOffset
(lpFile, IMAGE_DIRECTORY_ENTRY_EXPORT)) == NULL)
return 0;
else
return (int)ped->NumberOfNames;
}
/* return a pointer to the list of function entry points */
LPVOID WINAPI GetExportFunctionEntryPoints (
LPVOID lpFile)
{
IMAGE_SECTION_HEADER sh;
PIMAGE_EXPORT_DIRECTORY ped;
/* get section header and pointer to data directory for .edata section */
if ((ped = (PIMAGE_EXPORT_DIRECTORY)ImageDirectoryOffset
(lpFile, IMAGE_DIRECTORY_ENTRY_EXPORT)) == NULL)
return NULL;
GetSectionHdrByName (lpFile, &sh, ".edata");
/* determine the offset of the export function entry points */
return (LPVOID) ((int)ped->AddressOfFunctions -
(int)sh.VirtualAddress +
(int)sh.PointerToRawData +
(int)lpFile);
}
/* return a pointer to the list of function ordinals */
LPVOID WINAPI GetExportFunctionOrdinals (
LPVOID lpFile)
{
IMAGE_SECTION_HEADER sh;
PIMAGE_EXPORT_DIRECTORY ped;
/* get section header and pointer to data directory for .edata section */
if ((ped = (PIMAGE_EXPORT_DIRECTORY)ImageDirectoryOffset
(lpFile, IMAGE_DIRECTORY_ENTRY_EXPORT)) == NULL)
return NULL;
GetSectionHdrByName (lpFile, &sh, ".edata");
/* determine the offset of the export function entry points */
return (LPVOID) ((int)ped->AddressOfNameOrdinals -
(int)sh.VirtualAddress +
(int)sh.PointerToRawData +
(int)lpFile);
}
/* determine the total number of resources in the section */
int WINAPI GetNumberOfResources (
LPVOID lpFile)
{
PIMAGE_RESOURCE_DIRECTORY prdRoot, prdType;
PIMAGE_RESOURCE_DIRECTORY_ENTRY prde;
int nCnt=0, i;
/* get root directory of resource tree */
if ((prdRoot = (PIMAGE_RESOURCE_DIRECTORY)ImageDirectoryOffset
(lpFile, IMAGE_DIRECTORY_ENTRY_RESOURCE)) == NULL)
return 0;
/* set pointer to first resource type entry */
prde = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((DWORD)prdRoot + sizeof (IMAGE_RESOURCE_DIRECTORY));
/* loop through all resource directory entry types */
for (i=0; i<prdRoot->NumberOfIdEntries; i++)
{
/* locate directory or each resource type */
prdType = (PIMAGE_RESOURCE_DIRECTORY)((int)prdRoot + (int)prde->OffsetToData);
/* mask off most significant bit of the data offset */
prdType = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)prdType ^ 0x80000000);
/* increment count of name'd and ID'd resources in directory */
nCnt += prdType->NumberOfNamedEntries + prdType->NumberOfIdEntries;
/* increment to next entry */
prde++;
}
return nCnt;
}
/* name each type of resource in the section */
int WINAPI GetListOfResourceTypes (
LPVOID lpFile,
HANDLE hHeap,
char **pszResTypes)
{
PIMAGE_RESOURCE_DIRECTORY prdRoot;
PIMAGE_RESOURCE_DIRECTORY_ENTRY prde;
char *pMem;
int nCnt, i;
/* get root directory of resource tree */
if ((prdRoot = (PIMAGE_RESOURCE_DIRECTORY)ImageDirectoryOffset
(lpFile, IMAGE_DIRECTORY_ENTRY_RESOURCE)) == NULL)
return 0;
/* allocate enuff space from heap to cover all types */
nCnt = prdRoot->NumberOfIdEntries * (MAXRESOURCENAME + 1);
*pszResTypes = (char *)HeapAlloc (hHeap,
HEAP_ZERO_MEMORY,
nCnt);
if ((pMem = *pszResTypes) == NULL)
return 0;
/* set pointer to first resource type entry */
prde = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((DWORD)prdRoot + sizeof (IMAGE_RESOURCE_DIRECTORY));
/* loop through all resource directory entry types */
for (i=0; i<prdRoot->NumberOfIdEntries; i++)
{
prde++;
}
return nCnt;
}
/* function indicates whether debug info has been stripped from file */
BOOL WINAPI IsDebugInfoStripped (
LPVOID lpFile)
{
PIMAGE_FILE_HEADER pfh;
pfh = (PIMAGE_FILE_HEADER)PEFHDROFFSET (lpFile);
return (pfh->Characteristics & IMAGE_FILE_DEBUG_STRIPPED);
}
/* retrieve the module name from the debug misc. structure */
int WINAPI RetrieveModuleName (
LPVOID lpFile,
HANDLE hHeap,
char **pszModule)
{
PIMAGE_DEBUG_DIRECTORY pdd;
PIMAGE_DEBUG_MISC pdm = NULL;
int nCnt;
if (!(pdd = (PIMAGE_DEBUG_DIRECTORY)ImageDirectoryOffset (lpFile, IMAGE_DIRECTORY_ENTRY_DEBUG)))
return 0;
while (pdd->SizeOfData)
{
if (pdd->Type == IMAGE_DEBUG_TYPE_MISC)
{
pdm = (PIMAGE_DEBUG_MISC)((DWORD)pdd->PointerToRawData + (DWORD)lpFile);
*pszModule = (char *)HeapAlloc (hHeap,
HEAP_ZERO_MEMORY,
(nCnt = (lstrlen ((char*) pdm->Data)*(pdm->Unicode?2:1)))+1);
CopyMemory (*pszModule, pdm->Data, nCnt);
break;
}
pdd ++;
}
if (pdm != NULL)
return nCnt;
else
return 0;
}
/* determine if this is a valid debug file */
BOOL WINAPI IsDebugFile (
LPVOID lpFile)
{
PIMAGE_SEPARATE_DEBUG_HEADER psdh;
psdh = (PIMAGE_SEPARATE_DEBUG_HEADER)lpFile;
return (psdh->Signature == IMAGE_SEPARATE_DEBUG_SIGNATURE);
}
/* copy separate debug header structure from debug file */
BOOL WINAPI GetSeparateDebugHeader (
LPVOID lpFile,
PIMAGE_SEPARATE_DEBUG_HEADER psdh)
{
PIMAGE_SEPARATE_DEBUG_HEADER pdh;
pdh = (PIMAGE_SEPARATE_DEBUG_HEADER)lpFile;
if (pdh->Signature == IMAGE_SEPARATE_DEBUG_SIGNATURE)
{
CopyMemory ((LPVOID)psdh, (LPVOID)pdh, sizeof (IMAGE_SEPARATE_DEBUG_HEADER));
return TRUE;
}
return FALSE;
}
DWORD dwGetCodeRVA(DWORD dwImageBase)
{
char *lpBuffer=(char*) dwImageBase;
PIMAGE_OPTIONAL_HEADER pPEOptionalHeader=(PIMAGE_OPTIONAL_HEADER) OPTHDROFFSET(lpBuffer);
PIMAGE_SECTION_HEADER pSectionHeader=(PIMAGE_SECTION_HEADER) SECHDROFFSET (lpBuffer);
DWORD dwEntryPointRVA=pPEOptionalHeader->AddressOfEntryPoint;
while(pSectionHeader->VirtualAddress)
{
if ( (pSectionHeader->VirtualAddress<=dwEntryPointRVA ) && (dwEntryPointRVA<pSectionHeader->VirtualAddress+pSectionHeader->Misc.VirtualSize) )
{
return(pSectionHeader->VirtualAddress);
}
pSectionHeader++;
}
return(0);
}
DWORD dwGetCodeSize(DWORD dwImageBase)
{
char *lpBuffer=(char*) dwImageBase;
PIMAGE_OPTIONAL_HEADER pPEOptionalHeader=(PIMAGE_OPTIONAL_HEADER) OPTHDROFFSET(lpBuffer);
return(pPEOptionalHeader->SizeOfCode);
}

View File

@@ -0,0 +1,108 @@
#if !defined(__PEFILE_H__)
#define __PEFILE_H__
/* this file define all structures used in PE file */
/* found on Microsoft site */
#include <windows.h>
#if defined(__cplusplus)
extern "C" {
#endif
#define IDS_ERRBADFILENAME 1000
#define IDR_CURSOR 1
#define IDR_BITMAP 2
#define IDR_ICON 3
#define IDR_MENU 4
#define IDR_DIALOG 5
#define IDR_STRING 6
#define IDR_FONTDIR 7
#define IDR_FONT 8
#define IDR_ACCELERATOR 9
#define IDR_RCDATA 10
#define IDR_MESSAGETABLE 11
#define SIZE_OF_NT_SIGNATURE sizeof (DWORD)
#define MAXRESOURCENAME 13
/* global macros to define header offsets into file */
/* offset to PE file signature */
#define NTSIGNATURE(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew))
/* DOS header identifies the NT PEFile signature dword
the PEFILE header exists just after that dword */
#define PEFHDROFFSET(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew + \
SIZE_OF_NT_SIGNATURE))
/* PE optional header is immediately after PEFile header */
#define OPTHDROFFSET(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew + \
SIZE_OF_NT_SIGNATURE + \
sizeof (IMAGE_FILE_HEADER)))
/* section headers are immediately after PE optional header */
#define SECHDROFFSET(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew + \
SIZE_OF_NT_SIGNATURE + \
sizeof (IMAGE_FILE_HEADER) + \
sizeof (IMAGE_OPTIONAL_HEADER)))
typedef struct tagImportDirectory
{
DWORD dwRVAFunctionNameList;
DWORD dwUseless1;
DWORD dwUseless2;
DWORD dwRVAModuleName;
DWORD dwRVAFunctionAddressList;
}IMAGE_IMPORT_MODULE_DIRECTORY, * PIMAGE_IMPORT_MODULE_DIRECTORY;
/* global prototypes for functions in pefile.c */
/* PE file header info */
BOOL WINAPI GetDosHeader (LPVOID, PIMAGE_DOS_HEADER);
DWORD WINAPI ImageFileType (LPVOID);
BOOL WINAPI GetPEFileHeader (LPVOID, PIMAGE_FILE_HEADER);
/* PE optional header info */
BOOL WINAPI GetPEOptionalHeader (LPVOID, PIMAGE_OPTIONAL_HEADER);
LPVOID WINAPI GetModuleEntryPoint (LPVOID);
int WINAPI NumOfSections (LPVOID);
LPVOID WINAPI GetImageBase (LPVOID);
LPVOID WINAPI ImageDirectoryOffset (LPVOID, DWORD);
/* PE section header info */
int WINAPI GetSectionNames (LPVOID, HANDLE, char **);
BOOL WINAPI GetSectionHdrByName (LPVOID, PIMAGE_SECTION_HEADER, char *);
/* import section info */
int WINAPI GetImportModuleNames (LPVOID, HANDLE, char **);
int WINAPI GetImportFunctionNamesByModule (LPVOID, HANDLE, char *, char **);
/* export section info */
int WINAPI GetExportFunctionNames (LPVOID, HANDLE, char **);
int WINAPI GetNumberOfExportedFunctions (LPVOID);
LPVOID WINAPI GetExportFunctionEntryPoints (LPVOID);
LPVOID WINAPI GetExportFunctionOrdinals (LPVOID);
/* resource section info */
int WINAPI GetNumberOfResources (LPVOID);
int WINAPI GetListOfResourceTypes (LPVOID, HANDLE, char **);
/* debug section info */
BOOL WINAPI IsDebugInfoStripped (LPVOID);
int WINAPI RetrieveModuleName (LPVOID, HANDLE, char **);
BOOL WINAPI IsDebugFile (LPVOID);
BOOL WINAPI GetSeparateDebugHeader (LPVOID, PIMAGE_SEPARATE_DEBUG_HEADER);
DWORD dwGetCodeRVA(DWORD dwImageBase);
DWORD dwGetCodeSize(DWORD dwImageBase);
#if defined(__cplusplus)
}
#endif
#endif // __PEFILE_H__

View File

@@ -0,0 +1,988 @@
#include "PEOptions.h"
#if !defined(PE_NO_PEFILEEX)
#include <stdio.h>
#include "PEFileEx.h"
#if !defined(PE_NO_MESSAGE)
#include "message.h"
#endif // !PE_NO_MESSAGE
#include "MemLib.h"
#include "StrLib.h"
#if !defined(PE_NO_LOGFILE)
#include "LogFile.h"
#endif // !PE_NO_LOGFILE
#include <time.h>
#include <stdlib.h>
BOOL BlankFill=FALSE;
// Check if EXE is a PE file
BOOL bIsPEFile(unsigned char *lpBuffer)
{
// MZ file
if (*(USHORT *)lpBuffer != IMAGE_DOS_SIGNATURE)
{
#if !defined(PE_NO_MESSAGE)
ErrorMessage("Not an EXE file.\n");
#endif // !PE_NO_MESSAGE
return(FALSE);
}
else
{
// PE file
if (*(DWORD *)NTSIGNATURE (lpBuffer) != IMAGE_NT_SIGNATURE)
{
#if !defined(PE_NO_MESSAGE)
ErrorMessage("Not a PE EXE file.\n");
return(FALSE);
#endif // !PE_NO_MESSAGE
}
}
return(TRUE);
}
// To align size :Vital under NT
unsigned long ulAlignOn(unsigned long ulValue,unsigned ulAlignment)
{
if (ulValue>0) ulValue--;
ulValue/=ulAlignment;ulValue++;ulValue*=ulAlignment;
return(ulValue);
}
unsigned long ulAlignOnSection(LPPEFILE *lpPEFile,unsigned long ulValue)
{
PIMAGE_OPTIONAL_HEADER lpPEOptionalHeader=(*lpPEFile)->PEFileHeader.lpPEOptionalHeader;
return(ulAlignOn(ulValue,lpPEOptionalHeader->SectionAlignment));
}
unsigned long ulAlignOnFile(LPPEFILE *lpPEFile,unsigned long ulValue)
{
PIMAGE_OPTIONAL_HEADER lpPEOptionalHeader=(*lpPEFile)->PEFileHeader.lpPEOptionalHeader;
return(ulAlignOn(ulValue,lpPEOptionalHeader->FileAlignment));
}
BOOL bFillSection(LPPEFILE *lpPEFile,int lSectionIndex,unsigned long ulOffset,char *lpBuffer,unsigned long ulSize)
{
return(FALSE);
}
// find section with index
LPPESECTION lpFindSectionWithIndex(LPPEFILE *lpPEFile,int lSectionIndex)
{
LPPESECTION lpPESection=(*lpPEFile)->lpPESectionList;
int n=0;
while (lpPESection!=NULL)
{
if (n==lSectionIndex)
{
return(lpPESection);
}
n++;
lpPESection=lpPESection->lpNextSection;
}
return(NULL);
}
// find section with name
LPPESECTION lpFindSectionWithName(LPPEFILE *lpPEFile,char *szName)
{
LPPESECTION lpPESection=(*lpPEFile)->lpPESectionList;
while (lpPESection!=NULL)
{
if (!StringNICompare((char*) lpPESection->lpSectionHeader->Name,szName,StringLength(szName)))
{
return(lpPESection);
}
lpPESection=lpPESection->lpNextSection;
}
return(NULL);
}
// find section with rva
LPPESECTION lpFindSectionWithRVA(LPPEFILE *lpPEFile,DWORD RVA)
{
LPPESECTION lpPESection=(*lpPEFile)->lpPESectionList;
while (lpPESection!=NULL)
{
DWORD dwSize=lpPESection->lpSectionHeader->Misc.VirtualSize;
// mouais
if (!dwSize) dwSize=lpPESection->lpSectionHeader->SizeOfRawData;
if (
(lpPESection->lpSectionHeader->VirtualAddress<=RVA) &&
(RVA</*=*/lpPESection->lpSectionHeader->VirtualAddress+dwSize)
)
{
return(lpPESection);
}
lpPESection=lpPESection->lpNextSection;
}
return(NULL);
}
// find section with file offest
LPPESECTION lpFindSectionWithOffset(LPPEFILE *lpPEFile,unsigned long ulOffset)
{
LPPESECTION lpPESection=(*lpPEFile)->lpPESectionList;
while (lpPESection!=NULL)
{
if (
(lpPESection->lpSectionHeader->PointerToRawData<=ulOffset) &&
(ulOffset</*=*/lpPESection->lpSectionHeader->PointerToRawData+lpPESection->lpSectionHeader->SizeOfRawData)
)
{
return(lpPESection);
}
lpPESection=lpPESection->lpNextSection;
}
return(NULL);
}
// find section with pointer in lpPEFile
LPPESECTION lpFindSectionWithPointer(LPPEFILE *lpPEFile,unsigned char *ucPtr)
{
LPPESECTION lpPESection=(*lpPEFile)->lpPESectionList;
while (lpPESection!=NULL)
{
if ( (lpPESection->lpBuffer<=ucPtr) && (ucPtr</*=*/lpPESection->lpBuffer+lpPESection->ulSize))
{
return(lpPESection);
}
lpPESection=lpPESection->lpNextSection;
}
return(NULL);
}
int lGetSectionIndex(LPPEFILE *lpPEFile,LPPESECTION lpPESectionToSearch)
{
LPPESECTION lpPESection=(*lpPEFile)->lpPESectionList;
int n=0;
while (lpPESection!=NULL)
{
if (lpPESection==lpPESectionToSearch)
{
return(n);
}
lpPESection=lpPESection->lpNextSection;
}
return(C_INVALID_SECTION);
}
unsigned char RandomChar()
{
return((unsigned char) rand());
}
void FillWithRandom(unsigned char *lpBuffer,unsigned long ulSize)
{
unsigned long n;
static int init=0;
if (!init)
{
srand( (unsigned)time( NULL ) );
init=1;
}
if (ulSize>0)
{
for (n=0;n<ulSize;n++)
{
*lpBuffer++=RandomChar();
}
}
}
void vInitPEFileHeader(LPPEFILE *lpPEFile,unsigned char *lpBuffer,unsigned long ulSize)
{
(*lpPEFile)->PEFileHeader.ulSize = ulSize;
(*lpPEFile)->PEFileHeader.lpBuffer=lpBuffer;
lpBuffer += SIZE_OF_NT_SIGNATURE;
(*lpPEFile)->PEFileHeader.lpPEHeader=(PIMAGE_FILE_HEADER) lpBuffer;
lpBuffer += sizeof (IMAGE_FILE_HEADER);
(*lpPEFile)->PEFileHeader.lpPEOptionalHeader=(PIMAGE_OPTIONAL_HEADER) lpBuffer;
lpBuffer += sizeof (IMAGE_OPTIONAL_HEADER);
(*lpPEFile)->PEFileHeader.lpSectionHeader=(PIMAGE_SECTION_HEADER) lpBuffer;
}
void vDonePEStructure(LPPEFILE *lpPEFile)
{
if(*lpPEFile!=NULL)
{
unsigned char *lpTempBuffer;
// free debug
lpTempBuffer=(*lpPEFile)->PEDebug.lpBuffer;
if (lpTempBuffer)
{
MemoryFree((void**) &lpTempBuffer);
}
// free PESection
{
int nSections=(*lpPEFile)->PEFileHeader.lpPEHeader->NumberOfSections;
int ok=0;
LPPESECTION lpPESection=(*lpPEFile)->lpPESectionList;
LPPESECTION lpPESectionNext=NULL;
while (lpPESection!=NULL)
{
if (lpPESection->lpBuffer!=NULL)
{
MemoryFree((void**) &lpPESection->lpBuffer);
}
else
{
ok=ok;
}
lpPESectionNext=lpPESection->lpNextSection;
MemoryFree((void**) &lpPESection);
lpPESection=lpPESectionNext;
ok++;
}
if (ok!=nSections)
{
#if defined(_DEBUG)
__asm int 3;
#endif
}
}
// free PEHeader
lpTempBuffer=(*lpPEFile)->PEFileHeader.lpBuffer;
if (lpTempBuffer)
{
MemoryFree((void**) &lpTempBuffer);
}
// free DOSHeader
lpTempBuffer=(*lpPEFile)->PEDosHeader.lpBuffer;
if (lpTempBuffer)
{
MemoryFree((void**) &lpTempBuffer);
}
// free container
MemoryFree((void**) lpPEFile);
lpPEFile=NULL;
}
}
BOOL bInitPEStructure(char *filename,unsigned char *lpBuffer,unsigned long ulSize,LPPEFILE *lpPEFile)
{
BOOL bRet=FALSE;
if (lpPEFile!=NULL)
*lpPEFile=NULL;
if (
(lpPEFile!=NULL) &&
(bIsPEFile(lpBuffer))
)
{
// alloc container
*lpPEFile=(LPPEFILE) MemoryAlloc(sizeof(PEFILE));
if (*lpPEFile!=NULL)
{
PIMAGE_DOS_HEADER pDosHeader=(PIMAGE_DOS_HEADER) lpBuffer;
PIMAGE_FILE_HEADER pPEHeader=(PIMAGE_FILE_HEADER) PEFHDROFFSET (lpBuffer);
PIMAGE_OPTIONAL_HEADER pPEOptionalHeader=(PIMAGE_OPTIONAL_HEADER) OPTHDROFFSET (lpBuffer);
PIMAGE_SECTION_HEADER pSectionHeader=(PIMAGE_SECTION_HEADER) SECHDROFFSET (lpBuffer);
int nSections= NumOfSections(lpBuffer);
unsigned char *lpTempBuffer=NULL;
unsigned long ulTempSize=0;
#if defined(_CONSOLE)
printf("PE informations : %s\n",filename);
printf(" Image base : %08X\n",pPEOptionalHeader->ImageBase);
printf(" Entry point : %08X\n",pPEOptionalHeader->AddressOfEntryPoint);
printf(" Size of code : %08X\n",pPEOptionalHeader->SizeOfCode);
printf(" Size of data : %08X (initialized)\n",pPEOptionalHeader->SizeOfInitializedData);
printf(" : %08X (uninitialized)\n",pPEOptionalHeader->SizeOfUninitializedData);
printf(" File alignment: %08X\n",pPEOptionalHeader->FileAlignment);
printf("\nNumber of object(s) : %d Alignment : %08X \n",nSections,pPEOptionalHeader->SectionAlignment);
#else
#if !defined(PE_NO_LOGFILE)
WriteLogFile("PE informations : %s",filename);
WriteLogFile(" Image base : %08X",pPEOptionalHeader->ImageBase);
WriteLogFile(" Entry point : %08X",pPEOptionalHeader->AddressOfEntryPoint);
WriteLogFile(" Size of code : %08X",pPEOptionalHeader->SizeOfCode);
WriteLogFile(" Size of data : %08X (initialized)",pPEOptionalHeader->SizeOfInitializedData);
WriteLogFile(" : %08X (uninitialized)",pPEOptionalHeader->SizeOfUninitializedData);
WriteLogFile(" File alignment: %08X",pPEOptionalHeader->FileAlignment);
WriteLogFile("\nNumber of object(s) : %d Alignment : %08X",nSections,pPEOptionalHeader->SectionAlignment);
#endif // !PE_NO_LOGFILE
#endif
MemorySet(*lpPEFile,0,sizeof(PEFILE));
// alloc DOSHeader
ulTempSize=pDosHeader->e_lfanew;
lpTempBuffer=(unsigned char *) MemoryAlloc(ulTempSize);
if (lpTempBuffer)
{
(*lpPEFile)->PEDosHeader.ulSize=ulTempSize;
(*lpPEFile)->PEDosHeader.lpBuffer=lpTempBuffer;
MemoryCopy(lpTempBuffer,pDosHeader,ulTempSize);
lpTempBuffer=(*lpPEFile)->PEDosHeader.lpBuffer+(unsigned long) ((unsigned char*) pDosHeader - (unsigned char*) pDosHeader);
(*lpPEFile)->PEDosHeader.lpDosHeader=(PIMAGE_DOS_HEADER) lpTempBuffer;
// alloc all PEHeader
ulTempSize=pPEOptionalHeader->SizeOfHeaders-(*lpPEFile)->PEDosHeader.ulSize;
lpTempBuffer=(unsigned char *) MemoryAlloc(ulTempSize);
if (lpTempBuffer)
{
MemoryCopy(lpTempBuffer,((unsigned char*) pPEHeader) - SIZE_OF_NT_SIGNATURE,ulTempSize);
vInitPEFileHeader(lpPEFile,lpTempBuffer,ulTempSize);
if (BlankFill)
{
int nSections=(*lpPEFile)->PEFileHeader.lpPEHeader->NumberOfSections;
unsigned long ulDeltaSize;
ulDeltaSize =(unsigned long) &((*lpPEFile)->PEFileHeader.lpSectionHeader[nSections]);
ulDeltaSize-=(unsigned long) lpTempBuffer;
ulTempSize-=ulDeltaSize;
if (ulTempSize>0)
{
lpTempBuffer+=ulDeltaSize;
FillWithRandom(lpTempBuffer,ulTempSize);
}
}
// alloc sections
{
int n;
int nSections=(*lpPEFile)->PEFileHeader.lpPEHeader->NumberOfSections;
LPPESECTION lpPESection=NULL;
LPPESECTION lpPEPreviousSection=NULL;
LPPESECTION *lplpPEPreviousSection=&((*lpPEFile)->lpPESectionList);
for(n=0;n<nSections;n++)
{
ulTempSize=pSectionHeader[n].SizeOfRawData;
if (
((lpPESection=(LPPESECTION) MemoryAlloc(sizeof(PESECTION)))!=NULL) &&
(
(pSectionHeader[n].PointerToRawData==0) ||
((lpTempBuffer=(unsigned char*) MemoryAlloc(ulTempSize))!=NULL)
)
)
{
*lplpPEPreviousSection=lpPESection;
if (pSectionHeader[n].PointerToRawData!=0)
{
lpPESection->ulSize=ulTempSize;
lpPESection->lpBuffer=lpTempBuffer;
// for patched exe
if (pSectionHeader[n].PointerToRawData+ulTempSize>ulSize)
{
bRet=FALSE;
}
else
{
lpTempBuffer=lpBuffer+pSectionHeader[n].PointerToRawData;
MemoryCopy(lpPESection->lpBuffer,lpTempBuffer,ulTempSize);
}
}
else
{
// cf .bss section
lpPESection->ulSize=0;
lpPESection->lpBuffer=NULL;
}
lpPESection->lpSectionHeader=&((*lpPEFile)->PEFileHeader.lpSectionHeader[n]);
lpPESection->lpPreviousSection=lpPEPreviousSection;
lpPESection->lpNextSection=NULL;
lpPEPreviousSection=lpPESection;
lplpPEPreviousSection=&(lpPESection->lpNextSection);
#if defined(_CONSOLE)
printf( " Object%02d: %s\n"
" RVA : %08X Virtual Size: %08X Flags : %08X\n"
" Offset: %08X Real Size : %08X Free Size: %08X\n",
n+1,
pSectionHeader[n].Name,
pSectionHeader[n].VirtualAddress ,pSectionHeader[n].SizeOfRawData ,pSectionHeader[n].Characteristics,
pSectionHeader[n].PointerToRawData ,pSectionHeader[n].Misc.VirtualSize ,pSectionHeader[n].SizeOfRawData-pSectionHeader[n].Misc.VirtualSize
);
#else
#if !defined(PE_NO_LOGFILE)
WriteLogFile( " Object%02d: %s\n"
" RVA : %08X Virtual Size: %08X Flags : %08X\n"
" Offset: %08X Real Size : %08X Free Size: %08X",
n+1,
pSectionHeader[n].Name,
pSectionHeader[n].VirtualAddress ,pSectionHeader[n].SizeOfRawData ,pSectionHeader[n].Characteristics,
pSectionHeader[n].PointerToRawData ,pSectionHeader[n].Misc.VirtualSize ,pSectionHeader[n].SizeOfRawData-pSectionHeader[n].Misc.VirtualSize
);
#endif // !PE_NO_LOGFILE
#endif
// Fill blank with random value
if (BlankFill)
{
lpTempBuffer=lpPESection->lpBuffer;
if (lpTempBuffer!=NULL)
{
ulTempSize=pSectionHeader[n].SizeOfRawData-pSectionHeader[n].Misc.VirtualSize;
if (((signed long)ulTempSize)>0)
{
// cf .bss section
if (pSectionHeader[n].Misc.VirtualSize)
{
lpTempBuffer+=pSectionHeader[n].Misc.VirtualSize;
FillWithRandom(lpTempBuffer,ulTempSize);
}
}
// dangerous but .......
//pSectionHeader[n].Misc.VirtualSize=pSectionHeader[n].SizeOfRawData;
}
}
}
else
{
break;
}
}
if (n==nSections)
{
bRet=TRUE;
// no debug info
if (pPEHeader->Characteristics & IMAGE_FILE_DEBUG_STRIPPED)
{
bRet=TRUE;
}
else
{
// remove debug info
(*lpPEFile)->PEFileHeader.lpPEHeader->Characteristics &= ~IMAGE_FILE_DEBUG_STRIPPED;
(*lpPEFile)->PEFileHeader.lpPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress=0;
(*lpPEFile)->PEFileHeader.lpPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size=0;
bRet=TRUE;
/*
(*lpPEFile)->PEFileHeader.lpPEHeader->Characteristics |= IMAGE_FILE_DEBUG_STRIPPED;
(*lpPEFile)->PEFileHeader.lpPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress=0x120000;
(*lpPEFile)->PEFileHeader.lpPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size=0x1FFFFFFF;
*/
/*
{
PIMAGE_DEBUG_DIRECTORY pdd,pdd0;
PIMAGE_DEBUG_MISC pdm = NULL;
ulTempSize=0;
if ((pdd0 = (PIMAGE_DEBUG_DIRECTORY)ImageDirectoryOffset (lpBuffer, IMAGE_DIRECTORY_ENTRY_DEBUG)))
{
pdd=pdd0;
while (pdd->SizeOfData)
{
ulTempSize+=pdd->SizeOfData;
pdd++;
}
}
if (ulTempSize!=0)
{
lpTempBuffer=(unsigned char *) MemoryAlloc(ulTempSize);
if (lpTempBuffer)
{
(*lpPEFile)->PEDebug.ulSize=ulTempSize;
(*lpPEFile)->PEDebug.lpBuffer=lpTempBuffer;
// source
lpTempBuffer=(unsigned char*) pdd0;
MemoCopy((*lpPEFile)->PEDebug.lpBuffer,lpTempBuffer,ulTempSize);
bRet=TRUE;
}
}
}
*/
}
}
}
}
}
}
if (bRet==FALSE)
{
#if !defined(PE_NO_MESSAGE)
ErrorMessage("Cannot init PE structure for %s.\n",filename);
#endif // !PE_NO_MESSAGE
vDonePEStructure(lpPEFile);
}
/*
else
{
LPPESECTION lpPESection=NULL;
if (
((lpPESection=lpFindSectionWithName(lpPEFile,C_TEXT_SECTION))!=NULL)
&&(lpPESection->lpSectionHeader->Characteristics & IMAGE_SCN_MEM_WRITE)
)
{
#if !defined(PE_NO_MESSAGE)
ErrorMessage("%s already crypted.\n",filename);
#endif // !PE_NO_MESSAGE
vDonePEStructure(lpPEFile);
bRet=FALSE;
}
}
*/
}
return(bRet);
}
BOOL bLoadPEFileFromFile(char *filename,unsigned long ulSize,unsigned long ulOffset,LPPEFILE *lpPEFile)
{
BOOL bRet=FALSE;
FILE *fp=NULL;
unsigned char *lpBuffer=NULL;
#define PE_HEADERS 0x400
unsigned char TempBuffer[PE_HEADERS];
// Load PE file
if (
(lpPEFile!=NULL) &&
((fp=fopen(filename,"rb"))!=NULL) &&
(fseek(fp,ulOffset,SEEK_SET)==0)
)
{
// to avoid message and full loading for nothing
if (fread(TempBuffer,1,PE_HEADERS,fp)==PE_HEADERS)
{
// MZ file ?
if (*(USHORT *)TempBuffer == IMAGE_DOS_SIGNATURE)
{
// PE file ?
if (*(DWORD *)NTSIGNATURE (TempBuffer) == IMAGE_NT_SIGNATURE)
{
if ((lpBuffer=(unsigned char*) MemoryAlloc(ulSize))!=NULL)
{
// init internal structures
MemoryCopy(&lpBuffer[0],TempBuffer,PE_HEADERS);
if (fread(&lpBuffer[PE_HEADERS],1,ulSize-PE_HEADERS,fp)==ulSize-PE_HEADERS)
{
bRet=bInitPEStructure(filename,lpBuffer,ulSize,lpPEFile);
}
MemoryFree((void**) &lpBuffer);
}
}
}
}
fclose(fp);
}
return(bRet);
}
BOOL bLoadPEFile(char *filename,LPPEFILE *lpPEFile)
{
BOOL bRet=FALSE;
FILE *fp=NULL;
unsigned char *lpBuffer=NULL;
unsigned long ulSize;
// Load PE file
if (
(lpPEFile!=NULL) &&
((fp=fopen(filename,"rb"))!=NULL) &&
(fseek(fp,0,SEEK_END)==0) &&
((ulSize=ftell(fp))!=-1L) &&
(fseek(fp,0,SEEK_SET)==0)
)
{
if ((lpBuffer=(unsigned char*) MemoryAlloc(ulSize))!=NULL)
{
if (fread(lpBuffer,1,ulSize,fp)==ulSize)
{
// init internal structures
bRet=bInitPEStructure(filename,lpBuffer,ulSize,lpPEFile);
}
else
{
#if !defined(PE_NO_MESSAGE)
ErrorMessage("Unable to read %d bytes in %d.\n",ulSize,filename);
#endif // !PE_NO_MESSAGE
}
MemoryFree((void**) &lpBuffer);
}
else
{
#if !defined(PE_NO_MESSAGE)
ErrorMessage("Unable to allocate %d bytes.\n",ulSize);
#endif // !PE_NO_MESSAGE
}
fclose(fp);
}
else
{
#if !defined(PE_NO_MESSAGE)
ErrorMessage("Unable to open %s for reading.\n",filename);
#endif // !PE_NO_MESSAGE
}
if (!bRet)
{
#if !defined(PE_NO_MESSAGE)
ErrorMessage("PE Loading of %s failed.\n",filename);
#endif // !PE_NO_MESSAGE
}
return(bRet);
}
BOOL bLoadPEFileWithBlankFill(char *filename,LPPEFILE *lpPEFile)
{
BlankFill=TRUE;
return(bLoadPEFile(filename,lpPEFile));
}
BOOL bSavePEFile(char *filename,LPPEFILE *lpPEFile)
{
BOOL bRet=FALSE;
FILE *fp=NULL;
if (
(lpPEFile!=NULL) &&
(*lpPEFile!=NULL) &&
((fp=fopen(filename,"wb"))!=NULL)
)
{
unsigned long ulTempSize;
unsigned char *lpTempBuffer;
PIMAGE_FILE_HEADER lpPEHeader=(*lpPEFile)->PEFileHeader.lpPEHeader;
int nSections=lpPEHeader->NumberOfSections;
// write DOS header
ulTempSize=(*lpPEFile)->PEDosHeader.ulSize;
lpTempBuffer=(*lpPEFile)->PEDosHeader.lpBuffer;
if (fwrite(lpTempBuffer,1,ulTempSize,fp)==(size_t) ulTempSize)
{
// write PE Header
ulTempSize=(*lpPEFile)->PEFileHeader.ulSize;
lpTempBuffer=(*lpPEFile)->PEFileHeader.lpBuffer;
if (fwrite(lpTempBuffer,1,ulTempSize,fp)==(size_t) ulTempSize)
{
// write all sections
int ok=0;
LPPESECTION lpPESection=(*lpPEFile)->lpPESectionList;
while (lpPESection!=NULL)
{
ulTempSize=lpPESection->ulSize;
lpTempBuffer=lpPESection->lpBuffer;
if (lpTempBuffer!=NULL)
{
// Fill with dummy : calc.exe for instance
{
long lPos;
if (
((lPos=ftell(fp))>=0) &&
((unsigned long) lPos<lpPESection->lpSectionHeader->PointerToRawData)
)
{
unsigned long i=0;
unsigned long ulSize=lpPESection->lpSectionHeader->PointerToRawData-lPos;
unsigned char c=0;
for (i=0;i<ulSize;i++)
{
if (BlankFill)
{
c=RandomChar();
}
if (fwrite(&c,1,sizeof(c),fp)!=(size_t) sizeof(c))
{
break;
}
}
}
lPos=ftell(fp)-lpPESection->lpSectionHeader->PointerToRawData;
if (lPos!=0)
{
//_asm int 3;
break;
}
}
if (fwrite(lpTempBuffer,1,ulTempSize,fp)==(size_t) ulTempSize)
{
lpPESection=lpPESection->lpNextSection;
ok++;
}
else
{
break;
}
}
else
{
lpPESection=lpPESection->lpNextSection;
ok++;
}
}
bRet=(ok==nSections);
}
}
fclose(fp);
}
if (!bRet)
{
#if !defined(PE_NO_MESSAGE)
ErrorMessage("PE Saving of %s failed.\n",filename);
#endif // !PE_NO_MESSAGE
}
return(bRet);
}
BOOL bChangeSectionSize(LPPEFILE *lpPEFile,int lSectionIndex, unsigned long ulNewSize)
{
BOOL bRet=FALSE;
if (lSectionIndex!=C_INVALID_SECTION)
{
if ( (lSectionIndex>=0) && (lSectionIndex<(*lpPEFile)->PEFileHeader.lpPEHeader->NumberOfSections) )
{
LPPESECTION lpPESection=NULL;
if ((lpPESection=lpFindSectionWithIndex(lpPEFile,lSectionIndex))!=NULL)
{
unsigned char *lpTempBuffer=NULL;
unsigned long ulTempSize=ulAlignOnFile(lpPEFile,ulNewSize);
unsigned long ulDeltaSize=ulTempSize - lpPESection->ulSize;
if (ulDeltaSize==0)
{
bRet=TRUE;
}
else if
(
(ulDeltaSize>0) &&
// must not change RVA else it's too complicated
(ulAlignOnSection(lpPEFile,lpPESection->lpSectionHeader->Misc.VirtualSize+ulDeltaSize)==ulAlignOnSection(lpPEFile,lpPESection->lpSectionHeader->Misc.VirtualSize) ) &&
((lpTempBuffer=(unsigned char *) MemoryAlloc(ulTempSize))!=NULL)
)
{
MemorySet(lpTempBuffer,0,ulTempSize);
MemoryCopy(lpTempBuffer,lpPESection->lpBuffer,lpPESection->ulSize);
MemoryFree((void**) &lpPESection->lpBuffer);
lpPESection->ulSize=ulTempSize;
lpPESection->lpBuffer=lpTempBuffer;
lpPESection->lpSectionHeader->SizeOfRawData=ulTempSize;
lpPESection->lpSectionHeader->Misc.VirtualSize=ulTempSize;
// update subsequent section
lpPESection=lpPESection->lpNextSection;
while(lpPESection!=NULL)
{
lpPESection->lpSectionHeader->SizeOfRawData += ulDeltaSize;
lpPESection->lpSectionHeader->Misc.VirtualSize += ulDeltaSize;
lpPESection=lpPESection->lpNextSection;
}
bRet=TRUE;
}
}
}
}
return(bRet);
}
BOOL bChangeSizeOfPEHeader(LPPEFILE *lpPEFile,unsigned long ulSizeToAdd)
{
unsigned char *lpTempBuffer;
unsigned long ulTempSize=(*lpPEFile)->PEFileHeader.ulSize;
int nSections=(*lpPEFile)->PEFileHeader.lpPEHeader->NumberOfSections;
unsigned char *lpStart=(*lpPEFile)->PEFileHeader.lpBuffer;
unsigned char *lpEnd=((unsigned char*) &((*lpPEFile)->PEFileHeader.lpSectionHeader[nSections]))+ulSizeToAdd;
// if not enough place in header
if ((unsigned long) (lpEnd-lpStart)>ulTempSize)
{
ulSizeToAdd=ulAlignOnFile(lpPEFile,ulSizeToAdd);
// alloc a new bloc
lpTempBuffer=(unsigned char*) MemoryAlloc(ulTempSize+ulSizeToAdd);
if (!lpTempBuffer)
return(FALSE);
MemorySet(lpTempBuffer,0,ulTempSize+ulSizeToAdd);
MemoryCopy(lpTempBuffer,lpStart,ulTempSize);
MemoryFree((void**) &lpStart);
// update headar
vInitPEFileHeader(lpPEFile,lpTempBuffer,ulTempSize+ulSizeToAdd);
(*lpPEFile)->PEFileHeader.lpPEOptionalHeader->SizeOfHeaders += ulSizeToAdd;
// update section
{
LPPESECTION lpPESection=(*lpPEFile)->lpPESectionList;
int n=0;
while (lpPESection!=NULL)
{
lpPESection->lpSectionHeader=&((*lpPEFile)->PEFileHeader.lpSectionHeader[n++]);
lpPESection->lpSectionHeader->PointerToRawData += ulSizeToAdd;
lpPESection=lpPESection->lpNextSection;
}
}
}
return(TRUE);
}
BOOL bAddSection(LPPEFILE *lpPEFile,char *szSectionName,unsigned long ulSize)
{
BOOL bRet=FALSE;
// check if we can add a section
if (bChangeSizeOfPEHeader(lpPEFile,sizeof(IMAGE_SECTION_HEADER)))
{
PIMAGE_DOS_HEADER lpDosHeader=(*lpPEFile)->PEDosHeader.lpDosHeader;
PIMAGE_FILE_HEADER lpPEHeader=(*lpPEFile)->PEFileHeader.lpPEHeader;
PIMAGE_OPTIONAL_HEADER lpPEOptionalHeader=(*lpPEFile)->PEFileHeader.lpPEOptionalHeader;
PIMAGE_SECTION_HEADER lpSectionHeader=(*lpPEFile)->PEFileHeader.lpSectionHeader;
int nSections=lpPEHeader->NumberOfSections;
unsigned char *lpTempBuffer=NULL;
unsigned long ulTempSize=0;
LPPESECTION lpPESection,lpPENewSection;
PIMAGE_SECTION_HEADER lpNewSection;
// search last section in list
lpPESection=(*lpPEFile)->lpPESectionList;
while (lpPESection->lpNextSection!=NULL)
{
lpPESection=lpPESection->lpNextSection;
}
// alloc a new section
lpPENewSection=NULL;
lpTempBuffer=NULL;
ulTempSize=ulAlignOnFile(lpPEFile,ulSize);
if (
((lpPENewSection=(LPPESECTION) MemoryAlloc(sizeof(PESECTION)))!=NULL) &&
((lpTempBuffer=(unsigned char*) MemoryAlloc(ulTempSize))!=NULL)
)
{
DWORD VirtualAddress;
DWORD VirtualSize;
DWORD PointerToRawData;
DWORD SizeOfRawData;
// init buffer to check it works
if (BlankFill)
{
FillWithRandom(lpTempBuffer,ulTempSize);
}
else
{
MemorySet(lpTempBuffer,0x55,ulTempSize);
MemorySet(lpTempBuffer,0xFF,ulSize);
}
// chain previous
lpPESection->lpNextSection=lpPENewSection;
// init section
lpPENewSection->ulSize=ulTempSize;
lpPENewSection->lpBuffer=lpTempBuffer;
lpPENewSection->lpSectionHeader=&((*lpPEFile)->PEFileHeader.lpSectionHeader[nSections]);
lpPENewSection->lpPreviousSection=lpPESection;
lpPENewSection->lpNextSection=NULL;
lpNewSection=lpPENewSection->lpSectionHeader;
// Section Virtual Address : based on previous section : Important under NT : Need to be aligned
if ( (lpSectionHeader[nSections-1].Misc.VirtualSize==0) && (lpSectionHeader[nSections-1].PointerToRawData!=0) )
{
// .bss section have no rawdata
VirtualAddress=lpSectionHeader[nSections-1].VirtualAddress+lpSectionHeader[nSections-1].SizeOfRawData;
}
else
{
VirtualAddress=lpSectionHeader[nSections-1].VirtualAddress+lpSectionHeader[nSections-1].Misc.VirtualSize;
}
VirtualAddress=ulAlignOnSection(lpPEFile,VirtualAddress);
//Section Virtual Size : Important under NT : Need to be aligned
//SizeOfRawData=ulSize; ?????
SizeOfRawData=ulTempSize;
VirtualSize=ulAlignOnSection(lpPEFile,SizeOfRawData);
// PointerToRawData : based on previous section : Important under NT : Need to be aligned
PointerToRawData=lpSectionHeader[nSections-1].PointerToRawData+lpSectionHeader[nSections-1].SizeOfRawData;
PointerToRawData=ulAlignOnFile(lpPEFile,PointerToRawData);
// Fill section
MemorySet(lpNewSection,0,sizeof(IMAGE_SECTION_HEADER));
StringNCopy((char*) lpNewSection->Name,szSectionName,IMAGE_SIZEOF_SHORT_NAME);
lpNewSection->Name[IMAGE_SIZEOF_SHORT_NAME-1]=0;
lpNewSection->Misc.VirtualSize=VirtualSize;
lpNewSection->VirtualAddress=VirtualAddress;
lpNewSection->SizeOfRawData=SizeOfRawData;
lpNewSection->PointerToRawData=PointerToRawData;
lpNewSection->Characteristics=IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_INITIALIZED_DATA; // 0xC0000040
// update section number
lpPEHeader->NumberOfSections++;
// update image size
lpPEOptionalHeader->SizeOfImage += VirtualSize;
bRet=TRUE;
}
if ((!bRet) && (lpTempBuffer!=NULL))
{
MemoryFree((void**) &lpTempBuffer);
}
}
return(bRet);
}
#endif // !PE_NO_PEFILEEX

View File

@@ -0,0 +1,92 @@
#if !defined(__PEFILEEX_H__)
#define __PEFILEEX_H__
#include "PEFile.h"
#if defined(__cplusplus)
extern "C" {
#endif
#define C_NEW_SECTION ".udata"
#define C_SUPPRESS_SECTION ".sdata"
#define C_DATA_SECTION ".data"
#define C_TEXT_SECTION ".text"
#define C_RELOC_SECTION ".reloc"
#define C_RESSOURCE_SECTION ".rsrc"
#define C_TEXT_SECTION_WATCOM "AUTO"
#define C_DATA_SECTION_WATCOM "DGROUP"
#define C_INVALID_SECTION -1
typedef struct tagPEDOSHEADER
{
unsigned long ulSize;
unsigned char *lpBuffer;
PIMAGE_DOS_HEADER lpDosHeader;
} PEDOSHEADER,*LPPEDOSHEADER;
typedef struct tagPEFILEHEADER
{
unsigned long ulSize;
unsigned char *lpBuffer;
PIMAGE_FILE_HEADER lpPEHeader;
PIMAGE_OPTIONAL_HEADER lpPEOptionalHeader;
PIMAGE_SECTION_HEADER lpSectionHeader;
} PEFILEHEADER,*LPPEFILEHEADER;
typedef struct tagPESECTION
{
unsigned long ulSize;
unsigned char *lpBuffer;
PIMAGE_SECTION_HEADER lpSectionHeader;
struct tagPESECTION *lpPreviousSection;
struct tagPESECTION *lpNextSection;
} PESECTION,*LPPESECTION;
typedef struct tagPEDEBUG
{
unsigned long ulSize;
unsigned char *lpBuffer;
} PEDEBUG,*LPPEDEBUG;
typedef struct tagPEFILE
{
PEDOSHEADER PEDosHeader;
PEFILEHEADER PEFileHeader;
LPPESECTION lpPESectionList;
PEDEBUG PEDebug;
} PEFILE,*LPPEFILE;
// basic function
BOOL bInitPEStructure(char *filename,unsigned char *lpBuffer,unsigned long ulSize,LPPEFILE *lpPEFile);
void vDonePEStructure(LPPEFILE *lpPEFile);
BOOL bLoadPEFile(char *filename,LPPEFILE *lpPEFile);
BOOL bLoadPEFileWithBlankFill(char *filename,LPPEFILE *lpPEFile);
BOOL bSavePEFile(char *filename,LPPEFILE *lpPEFile);
// EXE in another file
BOOL bLoadPEFileFromFile(char *filename,unsigned long ulSize,unsigned long ulOffset,LPPEFILE *lpPEFile);
// other functions
LPPESECTION lpFindSectionWithIndex(LPPEFILE *lpPEFile,int lSectionIndex);
LPPESECTION lpFindSectionWithName(LPPEFILE *lpPEFile,char *szName);
LPPESECTION lpFindSectionWithRVA(LPPEFILE *lpPEFile,DWORD RVA);
LPPESECTION lpFindSectionWithOffset(LPPEFILE *lpPEFile,unsigned long ulOffset);
LPPESECTION lpFindSectionWithPointer(LPPEFILE *lpPEFile,unsigned char *ucPtr);
unsigned long ulAlignOnSection(LPPEFILE *lpPEFile,unsigned long ulValue);
unsigned long ulAlignOnFile(LPPEFILE *lpPEFile,unsigned long ulValue);
BOOL bChangeSectionSize(LPPEFILE *lpPEFile,int lSectionIndex, unsigned long ulNewSize);
BOOL bChangeSizeOfPEHeader(LPPEFILE *lpPEFile,unsigned long ulSizeToAdd);
BOOL bAddSection(LPPEFILE *lpPEFile,char *szSectionName,unsigned long ulSize);
#if defined(__cplusplus)
}
#endif
#endif // __PEFILEEX_H__

View File

@@ -0,0 +1,510 @@
#include "PEOptions.h"
#include "StrLib.h"
#if !defined(PE_NO_PEFILEEX)
#include "PEFileEx.h"
#endif // PE_NO_PEFILEEX
#include "PEImpExp.h"
#if !defined(PE_NO_LOGFILE)
#include "LogFile.h"
#endif // PE_NO_LOGFILE
////////////
// Import //
////////////
DWORD dwInternalGetImportedFunctionEntry(DWORD dwImageBase,PIMAGE_IMPORT_MODULE_DIRECTORY pid,LPCSTR lpProcName)
{
char *lpBuffer=(char*) dwImageBase;
if ( (lpBuffer) && (pid) )
{
// walk through import table name list (DLL)
while(pid->dwRVAFunctionNameList)
{
char *DllNamePtr=(char*) &lpBuffer[pid->dwRVAModuleName];
DWORD dwRVAFunctionNameList=pid->dwRVAFunctionNameList;
DWORD dwRVAFunctionAddressList=pid->dwRVAFunctionAddressList;
DWORD *FunctionNamePtr=(DWORD*) &lpBuffer[dwRVAFunctionNameList];
DWORD *FunctionAdressPtr=(DWORD*) &lpBuffer[dwRVAFunctionAddressList];
// walk through DLL func
while(*FunctionNamePtr)
{
// ordinal or not ?
if (!IMAGE_SNAP_BY_ORDINAL(*FunctionNamePtr))
{
PIMAGE_IMPORT_BY_NAME ImportPtr=(PIMAGE_IMPORT_BY_NAME) &lpBuffer[*FunctionNamePtr];
WORD Hint=ImportPtr->Hint;
char *NamePtr=(char*) &ImportPtr->Name[0];
//if (!StringCompare(NamePtr,lpProcName))
if (!StringCompareToCryptKey(NamePtr,lpProcName))
{
// found what we want
return((DWORD) FunctionAdressPtr);
}
}
FunctionNamePtr++;
FunctionAdressPtr++;
}
pid++;
}
}
return(0);
}
BOOL bInternalGetImportedFunctionName(DWORD dwImageBase,PIMAGE_IMPORT_MODULE_DIRECTORY pid,DWORD dwAddr,char **szDllName,char **szFuncName)
{
char *lpBuffer=(char*) dwImageBase;
*szDllName=NULL;
*szFuncName=NULL;
if ( (lpBuffer) && (pid) )
{
// walk through import table name list (DLL)
while(pid->dwRVAFunctionNameList)
{
char *DllNamePtr=(char*) &lpBuffer[pid->dwRVAModuleName];
DWORD dwRVAFunctionNameList=pid->dwRVAFunctionNameList;
DWORD dwRVAFunctionAddressList=pid->dwRVAFunctionAddressList;
DWORD *FunctionNamePtr=(DWORD*) &lpBuffer[dwRVAFunctionNameList];
DWORD *FunctionAdressPtr=(DWORD*) &lpBuffer[dwRVAFunctionAddressList];
// walk through DLL func
while(*FunctionNamePtr)
{
if (((DWORD) *FunctionAdressPtr)==dwAddr)
{
if (!IMAGE_SNAP_BY_ORDINAL(*FunctionNamePtr))
{
PIMAGE_IMPORT_BY_NAME ImportPtr=(PIMAGE_IMPORT_BY_NAME) &lpBuffer[*FunctionNamePtr];
WORD Hint=ImportPtr->Hint;
char *FuncNamePtr=(char*) &ImportPtr->Name[0];
// found what we want
*szDllName=DllNamePtr;
*szFuncName=FuncNamePtr;
return(TRUE);
}
else
{
*szDllName=DllNamePtr;
*szFuncName=NULL;
// don't handle ordinal
return(TRUE);
}
}
FunctionNamePtr++;
FunctionAdressPtr++;
}
pid++;
}
}
return(FALSE);
}
DWORD dwGetImportedFunctionEntryFromImageBase(DWORD dwImageBase,LPCSTR lpProcName)
{
char *lpBuffer=(char*) dwImageBase;
PIMAGE_OPTIONAL_HEADER pPEOptionalHeader=(PIMAGE_OPTIONAL_HEADER) OPTHDROFFSET(lpBuffer);
DWORD ImportTableRVA=pPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
if (ImportTableRVA)
{
PIMAGE_IMPORT_MODULE_DIRECTORY pid=(PIMAGE_IMPORT_MODULE_DIRECTORY) &lpBuffer[ImportTableRVA];
return(dwInternalGetImportedFunctionEntry(dwImageBase,pid,lpProcName));
}
return(0);
}
BOOL bGetImportedFunctionNameFromImageBase(DWORD dwImageBase,DWORD dwAddr,char **szDllName,char **szFuncName)
{
char *lpBuffer=(char*) dwImageBase;
PIMAGE_OPTIONAL_HEADER pPEOptionalHeader=(PIMAGE_OPTIONAL_HEADER) OPTHDROFFSET(lpBuffer);
DWORD ImportTableRVA=pPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
if (ImportTableRVA)
{
PIMAGE_IMPORT_MODULE_DIRECTORY pid=(PIMAGE_IMPORT_MODULE_DIRECTORY) &lpBuffer[ImportTableRVA];
return(bInternalGetImportedFunctionName(dwImageBase,pid,dwAddr,szDllName,szFuncName));
}
return(FALSE);
}
#if !defined(PE_NO_PEFILEEX)
DWORD dwGetImportedFunctionEntryFromPEFile(LPPEFILE *lpPEFile,LPCSTR lpProcName)
{
DWORD ImportTableRVA=(*lpPEFile)->PEFileHeader.lpPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
if (ImportTableRVA)
{
LPPESECTION lpImportSection=lpFindSectionWithRVA(lpPEFile,ImportTableRVA);
if (lpImportSection)
{
DWORD dwOffset=(DWORD) ImportTableRVA - lpImportSection->lpSectionHeader->VirtualAddress;
PIMAGE_IMPORT_MODULE_DIRECTORY pid=(PIMAGE_IMPORT_MODULE_DIRECTORY) &lpImportSection->lpBuffer[dwOffset];
DWORD dwImageBase=((DWORD) lpImportSection->lpBuffer) - lpImportSection->lpSectionHeader->VirtualAddress;
return(dwInternalGetImportedFunctionEntry(dwImageBase,pid,lpProcName));
}
}
return(0);
}
#endif // !PE_NO_PEFILEEX
#if !defined(PE_NO_PEFILEEX)
BOOL bGetImportedFunctionNameFromPEFile(LPPEFILE *lpPEFile,DWORD dwAddr,char **szDllName,char **szFuncName)
{
DWORD ImportTableRVA=(*lpPEFile)->PEFileHeader.lpPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
if (ImportTableRVA)
{
LPPESECTION lpImportSection=lpFindSectionWithRVA(lpPEFile,ImportTableRVA);
if (lpImportSection)
{
DWORD dwOffset=(DWORD) ImportTableRVA - lpImportSection->lpSectionHeader->VirtualAddress;
PIMAGE_IMPORT_MODULE_DIRECTORY pid=(PIMAGE_IMPORT_MODULE_DIRECTORY) &lpImportSection->lpBuffer[dwOffset];
DWORD dwImageBase=((DWORD) lpImportSection->lpBuffer) - lpImportSection->lpSectionHeader->VirtualAddress;
return(bInternalGetImportedFunctionName(dwImageBase,pid,dwAddr,szDllName,szFuncName));
}
}
return(FALSE);
}
#endif // !PE_NO_PEFILEEX
#if !defined(PE_NO_LOGFILE) && !defined(PE_NO_PEFILEEX)
void LogImportedFunctionFromPEFile(LPPEFILE *lpPEFile)
{
DWORD ImportTableRVA=(*lpPEFile)->PEFileHeader.lpPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
WriteLogFile("\nImport Table : RVA=%08X",ImportTableRVA);
if (ImportTableRVA)
{
LPPESECTION lpImportSection=lpFindSectionWithRVA(lpPEFile,ImportTableRVA);
if (lpImportSection)
{
DWORD dwOffset=(DWORD) ImportTableRVA - lpImportSection->lpSectionHeader->VirtualAddress;
PIMAGE_IMPORT_MODULE_DIRECTORY pid=(PIMAGE_IMPORT_MODULE_DIRECTORY) &lpImportSection->lpBuffer[dwOffset];
DWORD dwImageBase=((DWORD) lpImportSection->lpBuffer) - lpImportSection->lpSectionHeader->VirtualAddress;
DWORD dwRealImageBase=(*lpPEFile)->PEFileHeader.lpPEOptionalHeader->ImageBase;
char *lpBuffer=(char*) dwImageBase;
if ( (lpBuffer) && (pid) )
{
// walk through import table name list (DLL)
while(pid->dwRVAFunctionNameList)
{
char *DllNamePtr=(char*) &lpBuffer[pid->dwRVAModuleName];
DWORD dwRVAFunctionNameList=pid->dwRVAFunctionNameList;
DWORD dwRVAFunctionAddressList=pid->dwRVAFunctionAddressList;
DWORD *FunctionNamePtr=(DWORD*) &lpBuffer[dwRVAFunctionNameList];
DWORD *FunctionAdressPtr=(DWORD*) &lpBuffer[dwRVAFunctionAddressList];
WORD Hint=0;
char DllName[MAX_PATH];
StringCopy(DllName,DllNamePtr);
StringUpper(DllName);
WriteLogFile(" Imported functions from %s",DllName);
*strrchr(DllName,'.')=0;
// walk through DLL func
while(*FunctionNamePtr)
{
// ordinal or not ?
if (!IMAGE_SNAP_BY_ORDINAL(*FunctionNamePtr))
{
PIMAGE_IMPORT_BY_NAME ImportPtr=(PIMAGE_IMPORT_BY_NAME) &lpBuffer[*FunctionNamePtr];
char *FuncNamePtr=(char*) &ImportPtr->Name[0];
Hint=ImportPtr->Hint;
WriteLogFile(" Addr:(%08X) hint(%04X) Name:%s",*FunctionAdressPtr,Hint,FuncNamePtr);
}
else
{
Hint=(WORD) IMAGE_ORDINAL(*FunctionNamePtr);
WriteLogFile(" Addr:(%08X) hint(%04X) Name:???",*FunctionAdressPtr,Hint);
}
FunctionNamePtr++;
FunctionAdressPtr++;
}
pid++;
}
}
}
}
}
#endif // !PE_NO_LOGFILE
////////////
// export //
////////////
/*
DWORD dwGetInternalExportedFunctionEntry(DWORD dwImageBase,PIMAGE_EXPORT_DIRECTORY ped,LPCSTR lpProcName)
{
char *lpBuffer=(char*) dwImageBase;
if ( (lpBuffer) && (ped) )
{
DWORD *FunctionNamePtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfNames];
DWORD *FunctionAdressPtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfFunctions];
DWORD *FunctionOrdinalPtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfNameOrdinals];
int i;
for (i=0; i<(int)ped->NumberOfNames; i++)
{
char *NamePtr=(char*) &lpBuffer[*FunctionNamePtr];
if (!StringCompare(NamePtr,lpProcName))
{
return( (DWORD) FunctionAdressPtr);
}
FunctionNamePtr++;
FunctionAdressPtr++;
FunctionOrdinalPtr++;
}
}
return(0);
}
*/
DWORD dwGetInternalExportedFunctionEntry(DWORD dwImageBase,PIMAGE_EXPORT_DIRECTORY ped,LPCSTR lpProcName)
{
char *lpBuffer=(char*) dwImageBase;
if ( (lpBuffer) && (ped) )
{
DWORD *FunctionNamePtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfNames];
DWORD *FunctionAdressPtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfFunctions];
WORD *FunctionOrdinalPtr=(WORD*) &lpBuffer[(DWORD)ped->AddressOfNameOrdinals];
int i;
for (i=0; i<(int)ped->NumberOfNames; i++)
{
char *NamePtr=(char*) &lpBuffer[*FunctionNamePtr];
DWORD AddrPtr=*(FunctionAdressPtr + *FunctionOrdinalPtr);
//if (!StringCompare(NamePtr,lpProcName))
if (!StringCompareToCryptKey(NamePtr,lpProcName))
{
return(AddrPtr);
}
FunctionNamePtr++;
FunctionOrdinalPtr++;
}
}
return(0);
}
DWORD dwGetExportedFunctionEntryFromImageBase(DWORD dwImageBase,LPCSTR lpProcName)
{
char *lpBuffer=(char*) dwImageBase;
PIMAGE_OPTIONAL_HEADER pPEOptionalHeader=(PIMAGE_OPTIONAL_HEADER) OPTHDROFFSET(lpBuffer);
DWORD ExportTableRVA=pPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
if (ExportTableRVA)
{
PIMAGE_EXPORT_DIRECTORY ped=(PIMAGE_EXPORT_DIRECTORY) &lpBuffer[ExportTableRVA];
return(dwGetInternalExportedFunctionEntry(dwImageBase,ped,lpProcName));
}
return(0);
}
#if !defined(PE_NO_PEFILEEX)
DWORD dwGetExportedFunctionEntryFromPEFile(LPPEFILE *lpPEFile,LPCSTR lpProcName)
{
DWORD ExportTableRVA=(*lpPEFile)->PEFileHeader.lpPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
if (ExportTableRVA)
{
LPPESECTION lpExportSection=lpFindSectionWithRVA(lpPEFile,ExportTableRVA);
if (lpExportSection)
{
DWORD dwOffset=(DWORD) ExportTableRVA - lpExportSection->lpSectionHeader->VirtualAddress;
PIMAGE_EXPORT_DIRECTORY ped=(PIMAGE_EXPORT_DIRECTORY) &lpExportSection->lpBuffer[dwOffset];
DWORD dwImageBase=((DWORD) lpExportSection->lpBuffer) - lpExportSection->lpSectionHeader->VirtualAddress;
return(dwGetInternalExportedFunctionEntry(dwImageBase,ped,lpProcName));
}
}
return(0);
}
#endif // !PE_NO_PEFILEEX
BOOL bFindExportedFunctionNameWithOrdinalFromImageBase(DWORD dwImageBase,WORD uwOrdinal,char *szFuncName)
{
BOOL bRet=FALSE;
char *lpBuffer=(char*) dwImageBase;
PIMAGE_OPTIONAL_HEADER pPEOptionalHeader=(PIMAGE_OPTIONAL_HEADER) OPTHDROFFSET(lpBuffer);
DWORD ExportTableRVA=pPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
if (ExportTableRVA)
{
PIMAGE_EXPORT_DIRECTORY ped=(PIMAGE_EXPORT_DIRECTORY) &lpBuffer[ExportTableRVA];
if (ped)
{
DWORD *FunctionNamePtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfNames];
DWORD *FunctionAdressPtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfFunctions];
WORD *FunctionOrdinalPtr=(WORD*) &lpBuffer[(DWORD)ped->AddressOfNameOrdinals];
int i;
uwOrdinal=(WORD) (uwOrdinal-ped->Base);
for (i=0;i<(int)ped->NumberOfNames; i++)
{
char *NamePtr=(char*) &lpBuffer[*FunctionNamePtr];
DWORD AddrPtr=*(FunctionAdressPtr + *FunctionOrdinalPtr);
WORD Hint=*FunctionOrdinalPtr;
if (Hint==uwOrdinal)
{
StringCopy(szFuncName,NamePtr);
bRet=TRUE;
break;
}
FunctionNamePtr++;
FunctionOrdinalPtr++;
}
}
}
bRet=TRUE;
return(bRet);
}
#if !defined(PE_NO_LOGFILE) && !defined(PE_NO_PEFILEEX)
void LogExportedFunctionFromPEFile(LPPEFILE *lpPEFile)
{
DWORD ExportTableRVA=(*lpPEFile)->PEFileHeader.lpPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
WriteLogFile("\nExport Table : RVA=%08X",ExportTableRVA);
if (ExportTableRVA)
{
LPPESECTION lpExportSection=lpFindSectionWithRVA(lpPEFile,ExportTableRVA);
if (lpExportSection)
{
DWORD dwOffset=(DWORD) ExportTableRVA - lpExportSection->lpSectionHeader->VirtualAddress;
PIMAGE_EXPORT_DIRECTORY ped=(PIMAGE_EXPORT_DIRECTORY) &lpExportSection->lpBuffer[dwOffset];
DWORD dwImageBase=((DWORD) lpExportSection->lpBuffer) - lpExportSection->lpSectionHeader->VirtualAddress;
char *lpBuffer=(char*) dwImageBase;
if ( (lpBuffer) && (ped) )
{
DWORD *FunctionNamePtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfNames];
DWORD *FunctionAdressPtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfFunctions];
WORD *FunctionOrdinalPtr=(WORD*) &lpBuffer[(DWORD)ped->AddressOfNameOrdinals];
int i;
for (i=0; i<(int)ped->NumberOfNames; i++)
{
char *NamePtr=(char*) &lpBuffer[*FunctionNamePtr];
DWORD AddrPtr=*(FunctionAdressPtr + *FunctionOrdinalPtr);
WORD Hint=*FunctionOrdinalPtr;
WriteLogFile(" Addr:(%08X) hint(%04X) ordinal(%04X) Name:%s",AddrPtr,Hint,Hint+ped->Base,NamePtr);
FunctionNamePtr++;
FunctionOrdinalPtr++;
}
}
}
}
}
#endif // !PE_NO_LOGFILE && !PE_NO_PEFILEEX
/*
DWORD ASMdwGetExportedFunctionEntryFromImageBase(DWORD dwImageBase,LPCSTR lpProcName)
{
char *lpBuffer=(char*) dwImageBase;
PIMAGE_OPTIONAL_HEADER pPEOptionalHeader=(PIMAGE_OPTIONAL_HEADER) OPTHDROFFSET(lpBuffer);
DWORD ExportTableRVA=pPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
if (ExportTableRVA)
{
PIMAGE_EXPORT_DIRECTORY ped=(PIMAGE_EXPORT_DIRECTORY) &lpBuffer[ExportTableRVA];
DWORD *FunctionNamePtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfNames];
DWORD *FunctionAdressPtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfFunctions];
DWORD *FunctionOrdinalPtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfNameOrdinals];
int i;
for (i=0; i<(int)ped->NumberOfNames; i++)
{
char *NamePtr=(char*) &lpBuffer[*FunctionNamePtr];
if (!StringCompare(NamePtr,lpProcName))
{
return( (DWORD) FunctionAdressPtr+dwImageBase);
}
FunctionNamePtr++;
FunctionAdressPtr++;
FunctionOrdinalPtr++;
}
}
return(0);
}
/*
DWORD dwGetExportedFunctionAddrFromImageBase(DWORD dwImageBase,LPCSTR lpProcName)
{
DWORD dwAddr=dwGetExportedFunctionEntryFromImageBase(dwImageBase,lpProcName);
if (dwAddr)
{
dwAddr= dwImageBase + (*((DWORD*) dwAddr));
}
return(dwAddr);
}
*/
/*
//
// Export Format
//
typedef struct _IMAGE_EXPORT_DIRECTORY {
DWORD Characteristics;
DWORD TimeDateStamp;
WORD MajorVersion;
WORD MinorVersion;
DWORD Name;
DWORD Base;
DWORD NumberOfFunctions;
DWORD NumberOfNames;
PDWORD *AddressOfFunctions;
PDWORD *AddressOfNames;
PWORD *AddressOfNameOrdinals;
} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
//
// Import Format
//
typedef struct _IMAGE_IMPORT_BY_NAME {
WORD Hint;
BYTE Name[1];
} IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
typedef struct _IMAGE_THUNK_DATA {
union {
PBYTE ForwarderString;
PDWORD Function;
DWORD Ordinal;
PIMAGE_IMPORT_BY_NAME AddressOfData;
} u1;
} IMAGE_THUNK_DATA;
typedef IMAGE_THUNK_DATA * PIMAGE_THUNK_DATA;
#define IMAGE_ORDINAL_FLAG 0x80000000
#define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
#define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
typedef struct _IMAGE_IMPORT_DESCRIPTOR {
union {
DWORD Characteristics; // 0 for terminating null import descriptor
PIMAGE_THUNK_DATA OriginalFirstThunk; // RVA to original unbound IAT
};
DWORD TimeDateStamp; // 0 if not bound,
// -1 if bound, and real date\time stamp
// in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
// O.W. date/time stamp of DLL bound to (Old BIND)
DWORD ForwarderChain; // -1 if no forwarders
DWORD Name;
PIMAGE_THUNK_DATA FirstThunk; // RVA to IAT (if bound this IAT has actual addresses)
} IMAGE_IMPORT_DESCRIPTOR;
typedef IMAGE_IMPORT_DESCRIPTOR UNALIGNED *PIMAGE_IMPORT_DESCRIPTOR;
*/

View File

@@ -0,0 +1,38 @@
#if !defined(__PEIMPEXP_H__)
#define __PEIMPEXP_H__
#include "PEOptions.h"
#if !defined(PE_NO_PEFILEEX)
#include "PEFileEx.h"
#else
#include "PEFile.h"
#endif
#if defined(__cplusplus)
extern "C" {
#endif
DWORD dwGetImportedFunctionEntryFromImageBase(DWORD dwImageBase,LPCSTR lpProcName);
BOOL bGetImportedFunctionNameFromImageBase(DWORD dwImageBase,DWORD dwAddr,char **szDllName,char **szFuncName);
DWORD dwGetExportedFunctionEntryFromImageBase(DWORD dwImageBase,LPCSTR lpProcName);
BOOL bFindExportedFunctionNameWithOrdinalFromImageBase(DWORD dwImageBase,WORD uwOrdinal,char *szFuncName);
#if !defined(PE_NO_PEFILEEX)
DWORD dwGetImportedFunctionEntryFromPEFile(LPPEFILE *lpPEFile,LPCSTR lpProcName);
BOOL bGetImportedFunctionNameFromPEFile(LPPEFILE *lpPEFile,DWORD dwAddr,char **szDllName,char **szFuncName);
DWORD dwGetExportedFunctionEntryFromPEFile(LPPEFILE *lpPEFile,LPCSTR lpProcName);
#if !defined(PE_NO_LOGFILE)
void LogImportedFunctionFromPEFile(LPPEFILE *lpPEFile);
void LogExportedFunctionFromPEFile(LPPEFILE *lpPEFile);
#endif // !defined(PE_NO_LOGFILE)
#endif //!defined(PE_NO_PEFILEEX)
#if defined(__cplusplus)
}
#endif
#endif // __PEIMPEXP_H__

View File

@@ -0,0 +1,195 @@
#if !defined(__PEINLINE_H__) /* { */
#define __PEINLINE_H__
/* -------------------------------------------------------------------------------------------- */
//#include "PEFile.h"
/* -------------------------------------------------------------------------------------------- */
#if defined(__cplusplus)
extern "C" {
#endif
#define IDS_ERRBADFILENAME 1000
#define IDR_CURSOR 1
#define IDR_BITMAP 2
#define IDR_ICON 3
#define IDR_MENU 4
#define IDR_DIALOG 5
#define IDR_STRING 6
#define IDR_FONTDIR 7
#define IDR_FONT 8
#define IDR_ACCELERATOR 9
#define IDR_RCDATA 10
#define IDR_MESSAGETABLE 11
#define SIZE_OF_NT_SIGNATURE sizeof (DWORD)
#define MAXRESOURCENAME 13
/* global macros to define header offsets into file */
/* offset to PE file signature */
#define NTSIGNATURE(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew))
/* DOS header identifies the NT PEFile signature dword
the PEFILE header exists just after that dword */
#define PEFHDROFFSET(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew + \
SIZE_OF_NT_SIGNATURE))
/* PE optional header is immediately after PEFile header */
#define OPTHDROFFSET(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew + \
SIZE_OF_NT_SIGNATURE + \
sizeof (IMAGE_FILE_HEADER)))
/* section headers are immediately after PE optional header */
#define SECHDROFFSET(a) ((LPVOID)((BYTE *)a + \
((PIMAGE_DOS_HEADER)a)->e_lfanew + \
SIZE_OF_NT_SIGNATURE + \
sizeof (IMAGE_FILE_HEADER) + \
sizeof (IMAGE_OPTIONAL_HEADER)))
typedef struct tagImportDirectory
{
DWORD dwRVAFunctionNameList;
DWORD dwUseless1;
DWORD dwUseless2;
DWORD dwRVAModuleName;
DWORD dwRVAFunctionAddressList;
}IMAGE_IMPORT_MODULE_DIRECTORY, * PIMAGE_IMPORT_MODULE_DIRECTORY;
/* -------------------------------------------------------------------------------------------- */
__inline int __cdecl StringCompareToCryptKey(const char * src,const char * dst)/**/
{
int ret = 0 ;
long lKey = *(long*)(dst);
unsigned char *p_ucCryptKey = (unsigned char*) &lKey;
unsigned char ucSize = (unsigned char)dst [4];
unsigned char ucIndex;
unsigned char ucUncoded;
dst += 5;
for (ucIndex = 0 ; ucIndex < ucSize ; ucIndex++)
{
// uncode dst char
ucUncoded = (*(unsigned char *)dst++ - p_ucCryptKey[0]) ^ p_ucCryptKey[1];
p_ucCryptKey[0] += p_ucCryptKey[2];
p_ucCryptKey[1] += p_ucCryptKey[3];
// compare
ret = *(unsigned char *)src++ - ucUncoded;
if(ret) break;
}
if ( ret < 0 ) ret = -1 ;
else if ( ret > 0 ) ret = 1 ;
return( ret );
}
/* -------------------------------------------------------------------------------------------- */
__inline DWORD dwInternalGetImportedFunctionEntry(DWORD dwImageBase,PIMAGE_IMPORT_MODULE_DIRECTORY pid,LPCSTR lpProcName)
{
char *lpBuffer=(char*) dwImageBase;
if ( (lpBuffer) && (pid) )
{
// walk through import table name list (DLL)
while(pid->dwRVAFunctionNameList)
{
char *DllNamePtr=(char*) &lpBuffer[pid->dwRVAModuleName];
DWORD dwRVAFunctionNameList=pid->dwRVAFunctionNameList;
DWORD dwRVAFunctionAddressList=pid->dwRVAFunctionAddressList;
DWORD *FunctionNamePtr=(DWORD*) &lpBuffer[dwRVAFunctionNameList];
DWORD *FunctionAdressPtr=(DWORD*) &lpBuffer[dwRVAFunctionAddressList];
// walk through DLL func
while(*FunctionNamePtr)
{
// ordinal or not ?
if (!IMAGE_SNAP_BY_ORDINAL(*FunctionNamePtr))
{
PIMAGE_IMPORT_BY_NAME ImportPtr=(PIMAGE_IMPORT_BY_NAME) &lpBuffer[*FunctionNamePtr];
WORD Hint=ImportPtr->Hint;
char *NamePtr=(char*) &ImportPtr->Name[0];
//if (!StringCompare(NamePtr,lpProcName))
if (!StringCompareToCryptKey(NamePtr,lpProcName))
{
// found what we want
return((DWORD) FunctionAdressPtr);
}
}
FunctionNamePtr++;
FunctionAdressPtr++;
}
pid++;
}
}
return(0);
}
/* -------------------------------------------------------------------------------------------- */
__inline DWORD dwGetImportedFunctionEntryFromImageBase(DWORD dwImageBase,LPCSTR lpProcName)/**/
{
char *lpBuffer=(char*) dwImageBase;
PIMAGE_OPTIONAL_HEADER pPEOptionalHeader=(PIMAGE_OPTIONAL_HEADER) OPTHDROFFSET(lpBuffer);
DWORD ImportTableRVA=pPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
if (ImportTableRVA)
{
PIMAGE_IMPORT_MODULE_DIRECTORY pid=(PIMAGE_IMPORT_MODULE_DIRECTORY) &lpBuffer[ImportTableRVA];
return(dwInternalGetImportedFunctionEntry(dwImageBase,pid,lpProcName));
}
return(0);
}
/* -------------------------------------------------------------------------------------------- */
__inline
DWORD dwGetInternalExportedFunctionEntry(DWORD dwImageBase,PIMAGE_EXPORT_DIRECTORY ped,LPCSTR lpProcName)/**/
{
char *lpBuffer=(char*) dwImageBase;
if ( (lpBuffer) && (ped) )
{
DWORD *FunctionNamePtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfNames];
DWORD *FunctionAdressPtr=(DWORD*) &lpBuffer[(DWORD)ped->AddressOfFunctions];
WORD *FunctionOrdinalPtr=(WORD*) &lpBuffer[(DWORD)ped->AddressOfNameOrdinals];
int i;
for (i=0; i<(int)ped->NumberOfNames; i++)
{
char *NamePtr=(char*) &lpBuffer[*FunctionNamePtr];
DWORD AddrPtr=*(FunctionAdressPtr + *FunctionOrdinalPtr);
//if (!StringCompare(NamePtr,lpProcName))
if (!StringCompareToCryptKey(NamePtr,lpProcName))
{
return(AddrPtr);
}
FunctionNamePtr++;
FunctionOrdinalPtr++;
}
}
return(0);
}
/* -------------------------------------------------------------------------------------------- */
__inline DWORD dwGetExportedFunctionEntryFromImageBase(DWORD dwImageBase,LPCSTR lpProcName)/**/
{
char *lpBuffer=(char*) dwImageBase;
PIMAGE_OPTIONAL_HEADER pPEOptionalHeader=(PIMAGE_OPTIONAL_HEADER) OPTHDROFFSET(lpBuffer);
DWORD ExportTableRVA=pPEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
if (ExportTableRVA)
{
PIMAGE_EXPORT_DIRECTORY ped=(PIMAGE_EXPORT_DIRECTORY) &lpBuffer[ExportTableRVA];
return(dwGetInternalExportedFunctionEntry(dwImageBase,ped,lpProcName));
}
return(0);
}
/* -------------------------------------------------------------------------------------------- */
#if defined(__cplusplus)
}
#endif
/* -------------------------------------------------------------------------------------------- */
#endif /* __PEINLINE_H__ } */

View File

@@ -0,0 +1,16 @@
#if !defined(__PEOPTIONS_H__)
#define __PEOPTIONS_H__
//#define USE_STDSTRLIB
#define INLINE_STDSTRLIB
#define USE_CRYPTNAME
#define PE_NO_PEFILEEX
#define USE_STDMEMLIB
#define PE_NO_LOGFILE
#define PE_NO_MESSAGE
#define PE_INLINE
#endif // __PEOPTIONS_H__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,331 @@
# Microsoft Developer Studio Generated NMAKE File, Based on Ptc.dsp
!IF "$(CFG)" == ""
CFG=PTC - Win32 Debug
!MESSAGE No configuration specified. Defaulting to PTC - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "PTC - Win32 Release" && "$(CFG)" != "PTC - Win32 Debug" &&\
"$(CFG)" != "PTC - Win32 Retail"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Ptc.mak" CFG="PTC - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "PTC - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "PTC - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE "PTC - Win32 Retail" (based on "Win32 (x86) Static Library")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "PTC - Win32 Release"
OUTDIR=x:\cpa\lib
INTDIR=.\tmp\Release
# Begin Custom Macros
OutDir=x:\cpa\lib
# End Custom Macros
!IF "$(RECURSE)" == "0"
ALL : "$(OUTDIR)\PTCp5_vr.lib"
!ELSE
ALL : "$(OUTDIR)\PTCp5_vr.lib"
!ENDIF
CLEAN :
-@erase "$(INTDIR)\PTC.obj"
-@erase "$(INTDIR)\vc50.idb"
-@erase "$(OUTDIR)\PTCp5_vr.lib"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
"$(INTDIR)" :
if not exist "$(INTDIR)/$(NULL)" mkdir "$(INTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /G5 /ML /W3 /GX /O2 /I "X:\CPA\Public" /I "x:\cpa\public\PTC"\
/I "x:\cpa\tempgrp\PTC" /I "x:\cpa\Tempgrp\PTC\PE" /I "x:\cpa\tempgrp\PTC\Misc"\
/D "NDEBUG" /D "VISUAL" /D "WIN32" /D "USE_PROFILER" /Fo"$(INTDIR)\\"\
/Fd"$(INTDIR)\\" /FD /c
CPP_OBJS=.\tmp\Release/
CPP_SBRS=.
.c{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\Ptc.bsc"
BSC32_SBRS= \
LIB32=link.exe -lib
LIB32_FLAGS=/nologo /out:"$(OUTDIR)\PTCp5_vr.lib"
LIB32_OBJS= \
"$(INTDIR)\PTC.obj"
"$(OUTDIR)\PTCp5_vr.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
$(LIB32) @<<
$(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
<<
!ELSEIF "$(CFG)" == "PTC - Win32 Debug"
OUTDIR=X:\CPA\Lib
INTDIR=.\Tmp\Debug
# Begin Custom Macros
OutDir=X:\CPA\Lib
# End Custom Macros
!IF "$(RECURSE)" == "0"
ALL : "$(OUTDIR)\PTCP5_vd.lib"
!ELSE
ALL : "$(OUTDIR)\PTCP5_vd.lib"
!ENDIF
CLEAN :
-@erase "$(INTDIR)\PTC.obj"
-@erase "$(INTDIR)\vc50.idb"
-@erase "$(OUTDIR)\PTCP5_vd.lib"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
"$(INTDIR)" :
if not exist "$(INTDIR)/$(NULL)" mkdir "$(INTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /G5 /MLd /W3 /GX /Z7 /Od /I "X:\CPA\Public" /I\
"x:\cpa\public\PTC" /I "x:\cpa\tempgrp\PTC" /I "x:\cpa\Tempgrp\PTC\PE" /I\
"x:\cpa\tempgrp\PTC\Misc" /D "_DEBUG" /D "VISUAL" /D "WIN32" /D "USE_PROFILER"\
/D "MTH_CHECK" /D "CPA_WANTS_EXPORT" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
CPP_OBJS=.\Tmp\Debug/
CPP_SBRS=.
.c{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\Ptc.bsc"
BSC32_SBRS= \
LIB32=link.exe -lib
LIB32_FLAGS=/nologo /out:"$(OUTDIR)\PTCP5_vd.lib"
LIB32_OBJS= \
"$(INTDIR)\PTC.obj"
"$(OUTDIR)\PTCP5_vd.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
$(LIB32) @<<
$(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
<<
!ELSEIF "$(CFG)" == "PTC - Win32 Retail"
OUTDIR=x:\cpa\lib
INTDIR=.\tmp\Retail
# Begin Custom Macros
OutDir=x:\cpa\lib
# End Custom Macros
!IF "$(RECURSE)" == "0"
ALL : "$(OUTDIR)\PTCp5_vf.lib"
!ELSE
ALL : "$(OUTDIR)\PTCp5_vf.lib"
!ENDIF
CLEAN :
-@erase "$(INTDIR)\PTC.obj"
-@erase "$(INTDIR)\vc50.idb"
-@erase "$(OUTDIR)\PTCp5_vf.lib"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
"$(INTDIR)" :
if not exist "$(INTDIR)/$(NULL)" mkdir "$(INTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /G5 /ML /W3 /GX /O2 /I "X:\CPA\Public" /I "x:\cpa\public\PTC"\
/I "x:\cpa\tempgrp\PTC" /I "x:\cpa\Tempgrp\PTC\PE" /I "x:\cpa\tempgrp\PTC\Misc"\
/D "NDEBUG" /D "VISUAL" /D "WIN32" /D "RETAIL" /Fo"$(INTDIR)\\"\
/Fd"$(INTDIR)\\" /FD /c
CPP_OBJS=.\tmp\Retail/
CPP_SBRS=.
.c{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\Ptc.bsc"
BSC32_SBRS= \
LIB32=link.exe -lib
LIB32_FLAGS=/nologo /out:"$(OUTDIR)\PTCp5_vf.lib"
LIB32_OBJS= \
"$(INTDIR)\PTC.obj"
"$(OUTDIR)\PTCp5_vf.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
$(LIB32) @<<
$(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
<<
!ENDIF
!IF "$(CFG)" == "PTC - Win32 Release" || "$(CFG)" == "PTC - Win32 Debug" ||\
"$(CFG)" == "PTC - Win32 Retail"
SOURCE=.\PE\PEFile.c
SOURCE=.\PE\PEFileEx.c
SOURCE=.\PE\PEImpExp.c
SOURCE=.\PTC.c
!IF "$(CFG)" == "PTC - Win32 Release"
DEP_CPP_PTC_C=\
"..\..\public\PTC.h"\
"..\..\public\Ptc\PTC_abc.h"\
"..\..\public\PTC\PTC_pub.h"\
"..\..\public\Ptc\PTCDefn.h"\
"..\..\public\Ptc\PTCFcts.h"\
"..\..\public\Ptc\PTCMacro.h"\
".\PE\PEInline.h"\
"$(INTDIR)\PTC.obj" : $(SOURCE) $(DEP_CPP_PTC_C) "$(INTDIR)"
!ELSEIF "$(CFG)" == "PTC - Win32 Debug"
DEP_CPP_PTC_C=\
"..\..\public\PTC.h"\
"..\..\public\Ptc\PTC_abc.h"\
"..\..\public\PTC\PTC_pub.h"\
"..\..\public\Ptc\PTCDefn.h"\
"..\..\public\Ptc\PTCFcts.h"\
".\PE\PEInline.h"\
"$(INTDIR)\PTC.obj" : $(SOURCE) $(DEP_CPP_PTC_C) "$(INTDIR)"
!ELSEIF "$(CFG)" == "PTC - Win32 Retail"
DEP_CPP_PTC_C=\
"..\..\public\PTC.h"\
"..\..\public\Ptc\PTC_abc.h"\
"..\..\public\PTC\PTC_pub.h"\
"..\..\public\Ptc\PTCDefn.h"\
"..\..\public\Ptc\PTCFcts.h"\
"..\..\public\Ptc\PTCMacro.h"\
".\PE\PEInline.h"\
"$(INTDIR)\PTC.obj" : $(SOURCE) $(DEP_CPP_PTC_C) "$(INTDIR)"
!ENDIF
!ENDIF

View File

@@ -0,0 +1,192 @@
# Microsoft Developer Studio Project File - Name="PTC" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 5.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=PTC - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Ptc.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Ptc.mak" CFG="PTC - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "PTC - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "PTC - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE "PTC - Win32 Retail" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP Scc_ProjName ""$/cpa/tempgrp/PTC", CKRAAAAA"
# PROP Scc_LocalPath "."
CPP=cl.exe
!IF "$(CFG)" == "PTC - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "x:\cpa\lib"
# PROP Intermediate_Dir "tmp\Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /G5 /W3 /GX /O2 /I "X:\CPA\Public" /I "x:\cpa\public\PTC" /I "x:\cpa\tempgrp\PTC" /I "x:\cpa\Tempgrp\PTC\PE" /I "x:\cpa\tempgrp\PTC\Misc" /D "NDEBUG" /D "VISUAL" /D "WIN32" /D "USE_PROFILER" /FD /c
# SUBTRACT CPP /YX
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"x:\cpa\lib\PTCp5_vr.lib"
!ELSEIF "$(CFG)" == "PTC - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "X:\CPA\Lib"
# PROP Intermediate_Dir "Tmp\Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /G5 /W3 /GX /Z7 /Od /I "X:\CPA\Public" /I "x:\cpa\public\PTC" /I "x:\cpa\tempgrp\PTC" /I "x:\cpa\Tempgrp\PTC\PE" /I "x:\cpa\tempgrp\PTC\Misc" /D "_DEBUG" /D "VISUAL" /D "WIN32" /D "USE_PROFILER" /D "MTH_CHECK" /D "CPA_WANTS_EXPORT" /FD /c
# SUBTRACT CPP /YX
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"X:\CPA\Lib\PTCP5_vd.lib"
!ELSEIF "$(CFG)" == "PTC - Win32 Retail"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Retail"
# PROP BASE Intermediate_Dir "Retail"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "x:\cpa\lib"
# PROP Intermediate_Dir "tmp\Retail"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /G5 /W3 /GX /O2 /I "x:\cpa\tempgrp\PTC" /D "NDEBUG" /D "VISUAL" /D "WIN32" /D "USE_PROFILER" /FD /c
# SUBTRACT BASE CPP /YX
# ADD CPP /nologo /G5 /W3 /GX /O2 /I "X:\CPA\Public" /I "x:\cpa\public\PTC" /I "x:\cpa\tempgrp\PTC" /I "x:\cpa\Tempgrp\PTC\PE" /I "x:\cpa\tempgrp\PTC\Misc" /D "NDEBUG" /D "VISUAL" /D "WIN32" /D "RETAIL" /FD /c
# SUBTRACT CPP /YX
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo /out:"x:\cpa\lib\PTCp5_vr.lib"
# ADD LIB32 /nologo /out:"x:\cpa\lib\PTCp5_vf.lib"
!ENDIF
# Begin Target
# Name "PTC - Win32 Release"
# Name "PTC - Win32 Debug"
# Name "PTC - Win32 Retail"
# Begin Group "PE"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\PE\PEFile.c
# PROP Exclude_From_Build 1
# End Source File
# Begin Source File
SOURCE=.\PE\PEFile.h
# End Source File
# Begin Source File
SOURCE=.\PE\PEFileEx.c
# PROP Exclude_From_Build 1
# End Source File
# Begin Source File
SOURCE=.\PE\PEFileEx.h
# End Source File
# Begin Source File
SOURCE=.\PE\PEImpExp.c
# PROP Exclude_From_Build 1
# End Source File
# Begin Source File
SOURCE=.\PE\PEImpExp.h
# End Source File
# End Group
# Begin Group "Misc"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Misc\DefLib.h
# End Source File
# Begin Source File
SOURCE=.\Misc\MemLib.h
# End Source File
# Begin Source File
SOURCE=.\Misc\StrLib.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\PE\PEInline.h
# End Source File
# Begin Source File
SOURCE=.\PEOptions.h
# End Source File
# Begin Source File
SOURCE=.\PTC.c
# End Source File
# Begin Source File
SOURCE=..\..\public\PTC.h
# End Source File
# Begin Source File
SOURCE=.\PTC.mak
# End Source File
# Begin Source File
SOURCE=..\..\public\Ptc\PTC_abc.h
# End Source File
# Begin Source File
SOURCE=..\..\public\PTC\PTC_pub.h
# End Source File
# Begin Source File
SOURCE=..\..\public\Ptc\PTCDefn.h
# End Source File
# Begin Source File
SOURCE=..\..\public\Ptc\PTCFcts.h
# End Source File
# Begin Source File
SOURCE=..\..\public\Ptc\PTCMacro.h
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,13 @@
SCC = This is a Source Code Control file
[GenerABC.dsp]
SCC_Aux_Path = "\\srvprojets-ma\Rayman4_DS\Versions\Rayman4DS\Tools"
SCC_Project_Name = "$/CPA/tempgrp/PTC", IHPAAAAA
[Ptc.dsp]
SCC_Aux_Path = "\\srvprojets-ma\Rayman4_DS\Versions\Rayman4DS\Tools"
SCC_Project_Name = "$/CPA/tempgrp/PTC", IHPAAAAA
[PTC.mak]
SCC_Aux_Path = "\\srvprojets-ma\Rayman4_DS\Versions\Rayman4DS\Tools"
SCC_Project_Name = "$/CPA/tempgrp/PTC", IHPAAAAA