Guidance
指路人
g.yi.org
Software / Reginald / Examples / info.rex

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
/* An example script that FUNCDEFs some Windows OS functions to retrieve
 * information about a file that is a DLL, EXE, driver, font, etc.
 */

/* So that we don't need to use the CALL keyword */
OPTIONS "C_CALL"

/* Allow 32-bit addresses to be stored without exponential notation.
 * Some OS functions may cause Reginald to deal with storing 32-bit
 * addresses, and we don't want those stored in exponential form.
 */
NUMERIC DIGITS 10







/* ============ FUNCDEF the OS functions we need ============ */

/* Make things easy for us with WINFUNC option */
OPTIONS "WINFUNC NOSOURCE"

/* Let's CATCH FAILURE for the following FUNCDEF statements, so we
 * don't have to test if each one succeeded
 */
DO

FUNCDEF("GetModuleHandle", "void *, str", "kernel32", , "O")
FUNCDEF("FreeLibrary", "void, void", "kernel32")
FUNCDEF("LoadLibrary", "void *, str", "kernel32", , "O")
FUNCDEF("GetFileVersionInfoSize", "32u, str, 32u * stor", "version")
FUNCDEF("GetModuleFileName", "32u, void, str[260] stor, 32u", "kernel32")
FUNCDEF("GlobalAlloc", "void *, 32u, 32u", "kernel32", , "O")
FUNCDEF("GlobalFree", "void, void", "kernel32")
FUNCDEF("GetFileVersionInfo", "32u, str, 32u, 32u, void", "version")
FUNCDEF("GetLastError", "32u", "kernel32")
fixedfileinfo = "32u, 32u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 32u, 32u, 32u, 32u, 32u, 16u, 16u, 16u, 16u"
fixedfileptr = "struct FIXEDFILEINFO *"
FUNCDEF("GetFixedFileVersInfo", "32u, void, str, struct FIXEDFILEPTR stor, 32u * stor", "version", "VerQueryValue")
translateinfo = "char[4]"
transinfoptr = "struct TRANSLATEINFO *"
FUNCDEF("VerQueryValue", "32u, void, str, struct TRANSINFOPTR stor, 32u * stor", "version")
infostr = "str *"
FUNCDEF("VerQueryStr", "32u, void, str, struct INFOSTR stor, 32u * stor", "version", "VerQueryValue")

CATCH FAILURE
   CONDITION('M')
   RETURN
END



   

/* Here's the name of the EXE/DLL/driver/font/etc file that we
 * want information upon. Here, we just use notepad.
 */
myexename = SEARCHPATH("%WIN%") || "notepad.exe"

/* Assume that the dll/exe is already loaded into our process, and
 * just get its handle
 */
libloaded = 0
module = getmodulehandle(myexename)

/* Not already loaded? */
IF module == "" THEN DO

   /* Try to load it */
   module = loadlibrary(myexename)

   /* If an error, then we just can't get info */
   IF module == "" THEN DO
infoerr1:
      err = getlasterror() /* NOTE: Hopefully, we call this before the interpreter happens to call some other OS function internally. */
      SAY "Can't retrieve info about" myexename || "." || '0D0A'x || "Error #" || err
      SAY UNIXERROR(err)
      RETURN
   END

   /* Indicate that we must unload the module */
   libloaded = 1

END

/* Retrieve the full path and filename for the executable file containing
 * the specified module.
 */
LENGTH = getmodulefilename(module, filename, 260 /* MAX_PATH */)

/* Error? */
IF LENGTH == 0 THEN DO
infoerr2:
   IF libloaded == 1 THEN freelibrary(module)
   SIGNAL infoerr1
END

/* Determine whether the operating system can obtain version information
 * about the file. If version information is available, GetFileVersionInfoSize
 * returns the size in bytes of that information. NOTE: GetFileVersionInfo works
 * only with Win32 DLL/Exes. It does not work with 16-bit Windows ones.
 */
LENGTH = getfileversioninfosize(filename, junk)
IF LENGTH == 0 THEN SIGNAL infoerr2

/* Allocate memory to hold the version information we'll retrieve */
versioninfo = CONVERTDATA(0,"", "char[" || LENGTH || "]", "A")
IF versioninfo == "" THEN SIGNAL infoerr2

/* Now retrieve the version information */
IF getfileversioninfo(filename, , LENGTH, versioninfo) == 0 THEN SIGNAL infoerr2

IF getfixedfileversinfo(versioninfo, "\", fixedfileinfo, length) == 0 THEN SIGNAL infoerr2

/* Print out the File and Product versions */
SAY "File version =" fixedfileinfo.1.4 || "." fixedfileinfo.1.3 || "." fixedfileinfo.1.6 || "." fixedfileinfo.1.5
SAY "Product version =" fixedfileinfo.1.8 || "." fixedfileinfo.1.7 || "." fixedfileinfo.1.10 || "." fixedfileinfo.1.9

/* Print out what type of file this is */
SELECT
   WHEN fixedfileinfo.1.14 == 1 THEN SAY "Application"
   WHEN fixedfileinfo.1.14 == 2 THEN SAY "Dynamic Link Library"
   WHEN fixedfileinfo.1.14 == 3 THEN DO
      SELECT
         WHEN fixedfileinfo.1.15 == 1 THEN SAY "Printer driver"
         WHEN fixedfileinfo.1.15 == 2 THEN SAY "Keyboard driver"
         WHEN fixedfileinfo.1.15 == 3 THEN SAY "Language driver"
         WHEN fixedfileinfo.1.15 == 4 THEN SAY "Display driver"
         WHEN fixedfileinfo.1.15 == 5 THEN SAY "Mouse driver"
         WHEN fixedfileinfo.1.15 == 6 THEN SAY "Network driver"
         WHEN fixedfileinfo.1.15 == 7 THEN SAY "System driver"
         WHEN fixedfileinfo.1.15 == 8 THEN SAY "Installable driver"
         WHEN fixedfileinfo.1.15 == 9 THEN SAY "Sound driver"
         WHEN fixedfileinfo.1.15 == 10 THEN SAY "Comm driver"
         WHEN fixedfileinfo.1.15 == 11 THEN SAY "Input driver"
         OTHERWISE SAY "Unknown type of driver"
      END
   END
   WHEN fixedfileinfo.1.14 == 4 THEN  DO
      SELECT
         WHEN fixedfileinfo.1.15 == 1 THEN SAY "Raster Font"
         WHEN fixedfileinfo.1.15 == 2 THEN SAY "Vector Font"
         WHEN fixedfileinfo.1.15 == 3 THEN SAY "Truetype Font"
         OTHERWISE SAY "Unknown type of font"
      END
   END
   WHEN fixedfileinfo.1.14 == 5 THEN SAY "16-bit driver"
   WHEN fixedfileinfo.1.14 == 6 THEN NOP
   WHEN fixedfileinfo.1.14 == 7 THEN SAY "Compiler lib"
   OTHERWISE SAY "Unknown type of file"
END

/* Print out what Windows operating system this file is for */
SELECT
   WHEN fixedfileinfo.1.13 == 1 THEN SAY "For 16-bit Windows"
   WHEN fixedfileinfo.1.13 == 2 THEN SAY "For 16-bit OS/2 Presentation Manager"
   WHEN fixedfileinfo.1.13 == 3 THEN SAY "For 32-bit OS/2 Presentation Manager"
   WHEN fixedfileinfo.1.13 == 4 THEN SAY "For 32-bit Windows"
   WHEN fixedfileinfo.1.13 == 65536 THEN SAY "For MS-DOS"
   WHEN fixedfileinfo.1.13 == 131072 THEN SAY "For 16-bit OS/2 (command line)"
   WHEN fixedfileinfo.1.13 == 196608 THEN SAY "For 32-bit OS/2 (command line)"
   WHEN fixedfileinfo.1.13 == 262144 THEN SAY "For 32-bit Windows (command line)"
   WHEN fixedfileinfo.1.13 == 65537 THEN SAY "For MS-DOS or 16-bit Windows"
   WHEN fixedfileinfo.1.13 == 65540 THEN SAY "For MS-DOS or 32-bit Windows"
   WHEN fixedfileinfo.1.13 == 131074 THEN SAY "For 16-bit OS/2"
   WHEN fixedfileinfo.1.13 == 196611 THEN SAY "For 32-bit OS/2"
   WHEN fixedfileinfo.1.13 == 262148 THEN SAY "For Windows NT/2000/XP"
   OTHERWISE SAY "For unknown operating system"
END

/* The Win32 API contains the following predefined version information strings:
 * CompanyName, FileDescription, FileVersion, InternalName, LegalCopyright,
 * OriginalFilename ProductName ProductVersion. So let's query these.
 */

/* Get the translation information. Translation table consists of an array of
 * two WORD items. First item is language Id and second one is character set
 * which we'll use in subsequent queries.
 */
IF verqueryvalue(versioninfo, "\VarFileInfo\Translation", translateinfo, length) == 0 THEN SIGNAL infoerr2

/* Format it so we can use it in subsequent queries */
translateinfo = "\StringFileInfo\" || VALUEIN(translateinfo.1.1, 1, 2, 'HV')  || VALUEIN(translateinfo.1.1, 3, 2, 'HV') || "\"

/* Get company name */
IF verquerystr(versioninfo, translateinfo || "CompanyName", NAME, length) == 0 THEN SIGNAL infoerr2
SAY "company name =" name.1

/* Get product name */
IF verquerystr(versioninfo,  translateinfo || "ProductName", NAME, length) == 0 THEN SIGNAL infoerr2
SAY "product name =" name.1

/* Get product version */
IF verquerystr(versioninfo,  translateinfo || "ProductVersion", NAME, length) == 0 THEN SIGNAL infoerr2
SAY "product version =" name.1

/* Get copyright information */
IF verquerystr(versioninfo, translateinfo || "LegalCopyRight", NAME, length) == 0 THEN SIGNAL infoerr2
SAY "copyright information =" name.1

/* Get original file name */
IF verquerystr(versioninfo, translateinfo || "OriginalFileName", NAME, length) == 0 THEN SIGNAL infoerr2
SAY "original file name =" name.1
	
/* Get file description */
IF verquerystr(versioninfo, translateinfo || "FileDescription", NAME, length) == 0 THEN SIGNAL infoerr2
SAY "file description =" name.1

/* Get file version */
IF verquerystr(versioninfo, translateinfo || "FileVersion", NAME, length) == 0 THEN SIGNAL infoerr2
SAY "file version =" name.1

/* Get internal name */
IF verquerystr(versioninfo, translateinfo || "InternalName", NAME, length) == 0 THEN SIGNAL infoerr2
SAY "internal name =" name.1

/* Free memory for version info. NOTE: Rexx would do this automatically when this script ends,
 * but here's how you explicitly free memory
 */
CALL CONVERTDATA(versioninfo,"",,"=")

/* Free any loaded module */
IF libloaded == 1 THEN freelibrary(module)
掌柜推荐
 
 
¥900.00 ·
 
 
¥880.00 ·
 
 
¥497.00 ·
 
 
¥380.00 ·
 
 
¥980.00 ·
 
 
¥1,080.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-07-16 20:45:50