Created
October 5, 2017 16:47
-
-
Save alencar/094c58ad9fdfdba293a6cdc3d2e1a55e to your computer and use it in GitHub Desktop.
Extract build date and time of a PE image for [x]Harbour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FUNCTION MAIN ( cPEImage ) | |
IF Empty(cPEImage) | |
QOut("Showing info for this PE Image") | |
ELSE | |
QOut("Showing info for ", cPEImage ) | |
ENDIF | |
QOut("Build Date", BuildTimeStamp(cPEImage, .T., .F.)) | |
QOut("Build Time", BuildTimeStamp(cPEImage, .F., .T.)) | |
QOut("Build Date/Time", BuildTimeStamp(cPEImage, .T., .T.)) | |
#pragma begindump | |
#include <hbapi.h> | |
#include <hbapiitm.h> | |
#include <time.h> | |
#include <windows.h> | |
#include <Imagehlp.h> | |
typedef BOOL (__stdcall *MAPANDLOADPROC)(PSTR, PSTR, PLOADED_IMAGE, BOOL, BOOL); | |
typedef BOOL (__stdcall *UNMAPANDLOADPROC)(PLOADED_IMAGE); | |
HB_FUNC ( BUILDTIMESTAMP ) { | |
LOADED_IMAGE li; | |
char *szImage = (char *) hb_parc( 1 ); | |
char *szBuffer = (char *) hb_xgrab( 64 ); | |
time_t ts; | |
struct tm *ti; | |
int nLength = 0; | |
HINSTANCE hiImagehlpDll; | |
MAPANDLOADPROC ProcMapAndLoadAdd; | |
UNMAPANDLOADPROC ProcUnMapAndLoadAdd; | |
memset(szBuffer, 0, 64); | |
hiImagehlpDll = LoadLibrary("Imagehlp.dll"); | |
if(hiImagehlpDll == NULL) | |
{ | |
hb_xfree(szBuffer); | |
hb_retc_null(); | |
} | |
ProcMapAndLoadAdd = (MAPANDLOADPROC) GetProcAddress(hiImagehlpDll, "MapAndLoad"); | |
ProcUnMapAndLoadAdd = (UNMAPANDLOADPROC) GetProcAddress(hiImagehlpDll, "UnMapAndLoad"); | |
if (NULL != ProcMapAndLoadAdd && NULL != ProcUnMapAndLoadAdd) | |
{ | |
if (szImage == NULL) | |
{ | |
szImage = (char *) hb_xgrab(MAX_PATH * sizeof(char)); | |
GetModuleFileName(NULL, szImage, MAX_PATH); | |
} | |
if(ProcMapAndLoadAdd(szImage, NULL, (PLOADED_IMAGE)&li, FALSE, TRUE)) | |
{ | |
ts = (time_t)li.FileHeader->FileHeader.TimeDateStamp; | |
ti = localtime(&ts); | |
if(hb_parnl( 2 ) == TRUE && hb_parnl( 3 ) == FALSE) | |
nLength = strftime(szBuffer, 64, "%d/%m/%Y", ti); | |
else if (hb_parl( 2 ) == FALSE && hb_parl( 3 ) == TRUE) | |
nLength = strftime(szBuffer, 64, "%H:%M:%S", ti); | |
else | |
nLength = strftime(szBuffer, 64, "%d/%m/%Y %H:%M:%S", ti); | |
ProcUnMapAndLoadAdd((PLOADED_IMAGE)&li); | |
} | |
} | |
if ( nLength > 0 && nLength < 64 ) | |
szBuffer = (char *) hb_xrealloc(szBuffer, nLength + 1); | |
if ( hiImagehlpDll != NULL ) | |
FreeLibrary(hiImagehlpDll); | |
hb_retc(szBuffer); | |
hb_xfree(szBuffer); | |
} | |
#pragma enddump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment