WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Process UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

GetExeData UDF

 Keywords: Enumerate List Extender Extenders OtherFiles WIL DLL DLLS WBD include Compile Compiled WB WBC Winbatch EXE Check Valid 

TechHome     Edit/Archive

GetExeData UDF
 Keywords: Enumerate List Extender Extenders OtherFiles WIL DLL DLLS WBD Include Compile Compiled WB WBC Winbatch EXE CHECK Valid
--------------------------------------------------------------------------------


;***************************************************************************
;**           List Files included in Compiled WinBatch EXE
;**
;**
;** Purpose: List DLLs included in Winbatch EXE
;** Inputs:
;**  (s) Full path and filename of a compiled WinBatch EXE
;** Outputs:
;**  (s) Tab delimited list of DLLs included in EXE, or null if NON Winbatch Exe
;**
;**
;** This script gives you information about a compiled Winbatch EXE.
;**
;** It can:
;**     Check if Valid Winbatch EXE
;**     Determine EXE Type: Small or Large
;**     List DLLs included in Winbatch EXE
;**     List Extenders included in Winbatch EXE
;**     List OtherFiles included in Winbatch EXE
;**
;** Revisions:
;**   1.0.0.0  Initial Release [Deana Falk]
;***************************************************************************


;***************************************************************************
;                           SPECIAL DETAILS
;                   !!!!!!!!!!DO NOT MODIFY!!!!!!!!!!
;***************************************************************************
; Top entry of compiler.
tableentrysize = 276
WBSIGSTRING = "From Wilson WindowWare!"
WBSIGDWORD = 537923872
;converts to hex
; 20 11 10 20
;converts to decimal
; 32 17 16 32
WBSIGWORDSTR = Num2Char(32) : Num2Char(17) : Num2Char(16) : Num2Char(32)
WBSIGSEARCH = WBSIGWORDSTR : WBSIGSTRING :   WBSIGWORDSTR

;***************************************************************************
;              FID Values
;***************************************************************************
;
; 111 - WBBOOT
; 222 - WBBUILD
; 333 - WIL DLL
; 444 - OLE DLL ( no longer in use )
; 5__ - Extender DLLS
; 555 - Source
;
;***************************************************************************

;***************************************************************************
;              FDATA Values
;***************************************************************************
;
; 1    - WBCMP44I.EXE
; 2    - WIL DLL and Extender DLLS
; 2222 - Other Files
;
;***************************************************************************

;***************************************************************************
; Table Array Format
;***************************************************************************

; SMALL EXE
; --------------------------
; | fname            | fdata | fid | fcode     | fsize
; | WBDHE44I.DLL     | 2     | 333 | 950944136 | 0         <-----------NOTICE fname = WBDHE44I.DLL && fsize= 0 for SMALL EXE

; LARGE EXE w/ Extenders
; --------------------------
; | fname            | fdata | fid | fcode     | fsize
; | WBDHE44I.DLL     | 2     | 333 | 950944136 | 1097728
; | ADSSECURITY.DLL  | 2     | 501 | 697172815 | 57344   <-----------NOTICE fdata = 2 for Extender Dlls
; | WWADS44i.dll     | 2     | 502 | 909641232 | 229445
; | WWCPU44I.DLL     | 2     | 503 | 829820335 | 61509

; LARGE EXE w/ Extenders & Other Files
; --------------------------
; | fname            | fdata | fid | fcode     | fsize
; | WBDHE44I.DLL     | 2     | 333 | 950944136 | 1097728
; | ADSSECURITY.DLL  | 2     | 501 | 697172815 | 57344
; | WWADS44i.DLL     | 2     | 502 | 909641232 | 229445
; | WWCPU44I.DLL     | 2     | 503 | 829820335 | 61509
; | TABLE.TXT        | 2222  | 505 | 958691728 | 7579     <-----------NOTICE fdata = 2222 for Other Files


OurExeName = 'D:\temp\ExtenderList\Large.exe'
;OurExeName = 'D:\temp\ExtenderList\Small.exe'
;OurExeName = 'D:\temp\ExtenderList\OtherFiles.exe'
;OurExeName = 'D:\temp\ExtenderList\Encrypted.wbe'  ;  Expect Error - Invalid EXE specified
;OurExeName = 'c:\Windows\Notepad.exe'                 ;  Expect - Invalid EXE specified

GoSub DefinedFuncts

;Check if Valid EXE
ret = IsValidEXE (OurExeName, WBSIGSEARCH)
If ret == @FALSE
   Message("Error", "Invalid EXE specified")
   Exit
EndIf


ArrResult = GetEXEData( OurExeName )


;***************************************************************************
;Get Type of EXE.
;***************************************************************************
FSIZE = StrUpper(ArrResult[ 0, 4])
If FSIZE == 0
   Pause('Type of EXE', 'SMALL EXE')
Else
   Pause('Type of EXE', 'LARGE EXE')
EndIf

;***************************************************************************
; Get Name of WIL DLL
;***************************************************************************
WILDLL = StrUpper(ArrResult[ 0, 0])
Pause("WIL DLL", WILDLL)


;***************************************************************************
; List All Filenames
;***************************************************************************
filelist = ''
count = ArrInfo(ArrResult, 1 )
For part = 0 To count -1
   filelist = filelist :  StrUpper(ArrResult[ part, 0]) : @TAB
Next
filelist = StrTrim (filelist) ; remove leading tab
AskItemlist('List of Total files included in EXE', filelist, @TAB, @UNSORTED, @SINGLE )


;***************************************************************************
; List Extender Filenames Only
;***************************************************************************
filelist = ''
count = ArrInfo(ArrResult, 1 )
For part = 0 To count -1
   fdata = ArrResult[ part, 1]
   fid = StrSub( ArrResult[ part, 2], 1 , 1) ;Grab first number for FID
   If fdata == 2 && fid == 5 ;NOTICE fdata = 2 && fid == 5 for Extender Dlls
      filelist = filelist :  StrUpper(ArrResult[ part, 0]) : @TAB
   EndIf
Next
filelist = StrTrim (filelist) ; remove leading tab
AskItemlist('List of Extenders ONLY included in EXE', filelist, @TAB, @UNSORTED, @SINGLE )

;***************************************************************************
; List 'Other Files' Filenames Only
;***************************************************************************
filelist = ''
count = ArrInfo(ArrResult, 1 )
For part = 0 To count -1
   fdata = ArrResult[ part, 1]
   fid = StrSub( ArrResult[ part, 2], 1 , 1) ;Grab first number for FID
   If fdata == 2222 && fid == 5 ;NOTICE fdata = 2 && fid == 5 for Extender Dlls
      filelist = filelist :  StrUpper(ArrResult[ part, 0]) : @TAB
   EndIf
Next
filelist = StrTrim (filelist) ; remove leading tab
AskItemlist('List of `Other Files` ONLY included in EXE', filelist, @TAB, @UNSORTED, @SINGLE )

Exit


;***************************************************************************
:DefinedFuncts
;***************************************************************************

#DefineFunction GetEXEData( OurExeName  )
   ;***************************************************************************
   ;**   Returns an array of the table 'parts' in an EXE file
   ;**
   ;**   Parameters:
   ;**     (s) OurExeName: Full path and file name of the EXE
   ;**
   ;**   Returns:
   ;**      (a) Array of data based on DataFlag request.
   ;**
   ;**
   ;***************************************************************************;
   ; Top entry of compiler.
   tableentrysize = 276
   WBSIGSTRING = "From Wilson WindowWare!"
   WBSIGDWORD = 537923872
   ;converts to hex
   ; 20 11 10 20
   ;converts to decimal
   ; 32 17 16 32
   WBSIGWORDSTR = Num2Char(32) : Num2Char(17) : Num2Char(16) : Num2Char(32)
   WBSIGSEARCH = WBSIGWORDSTR : WBSIGSTRING :   WBSIGWORDSTR

   MainSize=FileSize(OurExeName)
   If MainSize==0
      Message("System Configuration Error","Cannot continue due to inability to access " : OurExeName)
      Exit
   EndIf
   MainBin=BinaryAlloc(MainSize)
   a=BinaryRead(MainBin,OurExeName) ;Compiled exe now in Binary Buffer
   ;----------------------------------------
   ; Locate build table
   ; WBSIGSEARCH is a preset search varible just before table
   ItemBeginOffset=BinaryIndexEx(MainBin, MainSize - 1, WBSIGSEARCH , @BACKSCAN, @TRUE)
   If ItemBeginOffset== -1
      Message("Internal Error", "Builder table not found")
      Exit
   EndIf
   ItemOffset=ItemBeginOffset ;beginning of table in memory
   ;Get total part count
   PartCount = BinaryPeek(MainBin, ItemBeginOffset + 31) ;get the numbers of total parts
   TableOffset=ItemOffset
   DataOffset=0
   ;Define array for return data
   arrDataTable = ArrDimension( PartCount-2, 5 ) ;Ignore first two parts: WBSIGSEARCH & WBCMP44I.EXE
   startpart = 3
   For part = startpart To PartCount  ;Ignore first two parts: WBSIGSEARCH & WBCMP44I.EXE
      ItemOffset=TableOffset+((part-1)*tableentrysize) ;move to next table entry
      ;Skip first 'part'
      ;if part == 1 then continue
      fname=BinaryPeekStr(MainBin,ItemOffset,256)
      DT1=BinaryPeek(MainBin,ItemOffset+256)
      DT2=BinaryPeek(MainBin,ItemOffset+257)
      DT3=BinaryPeek(MainBin,ItemOffset+258)
      DT4=BinaryPeek(MainBin,ItemOffset+259)
      fcode=(DT1<<24)+(DT2<<16)+(DT3<<8)+DT4
      DT1=BinaryPeek(MainBin,ItemOffset+260)
      DT2=BinaryPeek(MainBin,ItemOffset+261)
      DT3=BinaryPeek(MainBin,ItemOffset+262)
      DT4=BinaryPeek(MainBin,ItemOffset+263)
      fsize=(DT1<<24)+(DT2<<16)+(DT3<<8)+DT4
      DT1=BinaryPeek(MainBin,ItemOffset+264)
      DT2=BinaryPeek(MainBin,ItemOffset+265)
      DT3=BinaryPeek(MainBin,ItemOffset+266)
      DT4=BinaryPeek(MainBin,ItemOffset+267)
      fsize=(DT1<<24)+(DT2<<16)+(DT3<<8)+DT4
      DT1=BinaryPeek(MainBin,ItemOffset+268)
      DT2=BinaryPeek(MainBin,ItemOffset+269)
      DT3=BinaryPeek(MainBin,ItemOffset+270)
      DT4=BinaryPeek(MainBin,ItemOffset+271)
      fdata=(DT1<<24)+(DT2<<16)+(DT3<<8)+DT4
      DT1=BinaryPeek(MainBin,ItemOffset+272)
      DT2=BinaryPeek(MainBin,ItemOffset+273)
      DT3=BinaryPeek(MainBin,ItemOffset+274)
      DT4=BinaryPeek(MainBin,ItemOffset+275)
      fid=(DT1<<24)+(DT2<<16)+(DT3<<8)+DT4
      arrDataTable[ part-startpart, 4 ] = fsize
      arrDataTable[ part-startpart, 3 ] = fcode
      arrDataTable[ part-startpart, 2 ] = fid
      arrDataTable[ part-startpart, 1 ] = fdata
      arrDataTable[ part-startpart, 0 ] = fname
      DataOffset=DataOffset+fsize
   Next
   ;Clean up
   BinaryFree( MainBin )
   Return arrDataTable
#EndFunction

#DefineFunction IsValidEXE ( EXEname, WBSIGSEARCH)
   MainSize = FileSize( EXEname )
   If MainSize == 0
        Message("Error","Cannot continue due to inability to access " : EXEname)
        Exit
   EndIf
   MainBin = BinaryAlloc( MainSize )
   a = BinaryRead( MainBin, EXEname )
   ItemBeginOffset = BinaryIndexEx(MainBin, MainSize - 1, WBSIGSEARCH , @BACKSCAN, @TRUE)
   BinaryFree( MainBin )
   If ItemBeginOffset== -1 Then Return @FALSE
   Return @TRUE
#EndFunction

Return
File Created: 2010:02:17:11:00:10
Last Updated: 2009:06:24:09:52:50

Article ID:   W18382
Filename:   GetExeData UDF.txt
File Created: 2012:02:16:11:02:16
Last Updated: 2012:02:16:11:02:16