News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Retrieving the version of EXEs and DLLs

Started by Vortex, January 19, 2025, 05:26:52 AM

Previous topic - Next topic

zedd151

#15
Quote from: jj2007 on January 27, 2025, 08:24:20 PM
Quote from: TimoVJL on January 27, 2025, 07:41:45 PMCode Design

This looks like written by Hutch :cool:

Or at the very least, in the style of hutch--, as used in the early days of Masm32 SDK development- in the documentation. It does look very familiar.


A short time later... I had to dig deeper...  :tongue:
Looking further up the tree in the url that TimoVJL posted, there is a complete partial Masm32 SDK package there (but the SDK install .exe is also along the url path). It uses qeditor version 3.0n in that version of the Masm32 SDK. A very old version... Seems it was used in a university course at one time.

https://www.cs.emory.edu/~cheung/Courses/255/Syllabus/9-Intel/masm32/
If my assumptions are correct, the file linked by Timo was in fact written by hutch--. :)  Good catch, Jochen. It was part of the html help files for that version of the Masm32 SDK.

Still later...
That is all from The Masm32 SDK, version 9.0 release.  :smiley:
Hutch did mention a few times that he did license some version(s) of the Masm32 SDK to universities/colleges at one point.


P.S. sorry for the detour, but I had to get to the bottom of this...  :azn:
¯\_(ツ)_/¯

greenozon


NoCforMe

Quote from: jj2007 on January 27, 2025, 07:14:48 PM
Quote from: NoCforMe on January 27, 2025, 08:14:11 AM2. Don't like to use macros like rv(xxx) for my own code.

You shouldn't use invoke, really :cool:
That's the exception to my rule.
invoke is so much better than the alternative, push-push-call.
Assembly language programming should be fun. That's why I do it.

TimoVJL

Invoke is directive in masm32 / ml.exe
So not a macro.
May the source be with you

NoCforMe

Quote from: TimoVJL on January 28, 2025, 07:42:02 PMInvoke is directive in masm32 / ml.exe
So not a macro.

Correct. According to my MASM 6.1 manual,

QuoteMASM provides the INVOKE directive to handle many of the details important to procedure calls,

So there.
Makes me feel better about my no-macros rule.
Assembly language programming should be fun. That's why I do it.

HSE

Quote from: Vortex on January 19, 2025, 05:26:52 AMHere is a command line tool to get the version of the an exe\dll.

Nice  :thumbsup:

Build and run in Win10 perfectly.
Equations in Assembly: SmplMath

daydreamer

This thread made me curious about how to put in my own exe and dll version number instead of being limited to renaming file name my program V2.0 and comment in beginning of main source file ; my program V2.0?

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

zedd151

Quote from: daydreamer on January 30, 2025, 02:56:15 AMThis thread made me curious about how to put in my own exe and dll version number instead of being limited to renaming file name my program V2.0 and comment in beginning of main source file ; my program V2.0?

VERSIONINFO Resource   :smiley:
¯\_(ツ)_/¯


Vortex

#24
Hi daydreamer,

Here is an example from Hutch. Downloading the attachment from this thread :

https://masm32.com/board/index.php?topic=88.0

The resource script :

#include "Resource.h"

1 24 "barewin.xml"

5 ICON "barewin.ico"

// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1, 0, 0, 0
PRODUCTVERSION 1, 0, 0, 0
FILEOS VOS_WINDOWS32
FILETYPE VFT_APP
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "040904B0"
    BEGIN
      VALUE "CompanyName",      "PowerBASIC Inc\000"
      VALUE "FileDescription",  "Bare API Window\000"
      VALUE "FileVersion",      "1.0\000"
      VALUE "InternalName",    "barewin\000"
      VALUE "OriginalFilename", "barewin.exe\000"
      VALUE "LegalCopyright",  "\251 2011 PowerBASIC Inc\000"
      VALUE "ProductName",      "barewin\000"
      VALUE "ProductVersion",  "1.0\000"
    END
  END
  BLOCK "VarFileInfo"
  BEGIN
    VALUE "Translation", 0x409, 0x4B0
  END
END

ognil

It is from DeepSeek, :biggrin:

; Retrieve Version Information for Windows Executables in x64 Assembly
; Assemble with NASM and link with version.lib and kernel32.lib

section .data
    filename    db "C:\\path\\to\\file.exe",0  ; Replace with your file path
    subBlock    db "\",0                       ; Root block for version info
    errorMsg    db "Error retrieving version information.",0

section .bss
    versionSize resd 1          ; Size of version info buffer
    versionInfo resq 1          ; Pointer to version info buffer
    fixedInfo   resq 1          ; Pointer to fixed file info structure
    fixedLen    resd 1          ; Length of fixed file info

section .text
    global Start
    extern GetFileVersionInfoSizeA
    extern GetFileVersionInfoA
    extern VerQueryValueA
    extern VirtualAlloc
    extern VirtualFree
    extern ExitProcess

Start:
    ; Get version information size
    sub rsp, 32                 ; Shadow space + alignment
    lea rcx, [filename]
    xor edx, edx
    call GetFileVersionInfoSizeA
    add rsp, 32
    test eax, eax
    jz error
    mov [versionSize], eax

    ; Allocate memory for version info
    sub rsp, 32
    xor rcx, rcx                ; lpAddress
    mov edx, [versionSize]      ; dwSize
    mov r8, 0x1000              ; MEM_COMMIT
    mov r9, 4                   ; PAGE_READWRITE
    call VirtualAlloc
    add rsp, 32
    test rax, rax
    jz error
    mov [versionInfo], rax

    ; Retrieve version information
    sub rsp, 32
    lea rcx, [filename]
    xor edx, edx                ; dwHandle
    mov r8d, [versionSize]
    mov r9, [versionInfo]
    call GetFileVersionInfoA
    add rsp, 32
    test eax, eax
    jz error

    ; Query fixed file information
    sub rsp, 32
    mov rcx, [versionInfo]
    lea rdx, [subBlock]
    lea r8, [fixedInfo]
    lea r9, [fixedLen]
    call VerQueryValueA
    add rsp, 32
    test eax, eax
    jz error

    ; Extract version numbers
    mov rsi, [fixedInfo]
    mov eax, [rsi + 8]          ; dwFileVersionMS
    mov edx, [rsi + 12]         ; dwFileVersionLS

    ; Major = HIWORD(dwFileVersionMS)
    ; Minor = LOWORD(dwFileVersionMS)
    ; Build = HIWORD(dwFileVersionLS)
    ; Revision = LOWORD(dwFileVersionLS)
    mov ecx, eax
    shr ecx, 16                 ; Major version
    mov ebx, eax
    and ebx, 0xFFFF             ; Minor version
    mov esi, edx
    shr esi, 16                 ; Build number
    mov edi, edx
    and edi, 0xFFFF             ; Revision number

    ; Clean up allocated memory
    sub rsp, 32
    mov rcx, [versionInfo]
    xor edx, edx
    mov r8, 0x8000              ; MEM_RELEASE
    call VirtualFree
    add rsp, 32

    ; Exit with success
    xor ecx, ecx
    call ExitProcess

error:
    ; Handle error (exit with code 1)
    mov ecx, 1
    call ExitProcess

"Not keeping emotions under control is another type of mental distortion."

TimoVJL

From DeepSeek
; MASM 64-bit example to get file version information using GetFileVersionInfo

extrn GetFileVersionInfoSizeExW : proc
extrn GetFileVersionInfoExW : proc
extrn VerQueryValueW : proc
extrn GetLastError : proc
extrn ExitProcess : proc
extrn MessageBoxW : proc
extrn wsprintfW : proc
extrn LocalFree : proc

.data
wszFileName        dw 'C', ':', '\', 'P', 'a', 't', 'h', '\', 'T', 'o', '\', 'Y', 'o', 'u', 'r', 'F', 'i', 'l', 'e', '.', 'e', 'x', 'e', 0
wszSubBlock        dw '\', 0
wszFormat          dw 'File Version: %d.%d.%d.%d', 0
wszCaption         dw 'File Version Info', 0
wszError           dw 'Error getting file version info', 0
dwVersionInfoSize  dd 0
pVersionInfo       dq 0
pVersionBuffer     dq 0
dwLangCodepage     dd 0
dwFileVersionMS    dd 0
dwFileVersionLS    dd 0
wszBuffer          dw 256 dup(0)

.code
main proc
    ; Get the size of the version information
    mov rcx, 0
    lea rdx, wszFileName
    mov r8, 0
    lea r9, dwVersionInfoSize
    call GetFileVersionInfoSizeExW
    test rax, rax
    jz error_exit

    ; Allocate memory for the version information
    mov ecx, dwVersionInfoSize
    call LocalAlloc
    mov pVersionInfo, rax
    test rax, rax
    jz error_exit

    ; Get the version information
    mov rcx, 0
    lea rdx, wszFileName
    mov r8, 0
    mov r9, dwVersionInfoSize
    mov rax, pVersionInfo
    push rax
    sub rsp, 20h
    call GetFileVersionInfoExW
    add rsp, 20h
    test rax, rax
    jz error_exit

    ; Query the file version
    lea rcx, wszSubBlock
    lea rdx, pVersionBuffer
    lea r8, dwVersionInfoSize
    mov r9, pVersionInfo
    call VerQueryValueW
    test rax, rax
    jz error_exit
®
    ; Extract the file version
    mov rax, pVersionBuffer
    mov eax, [rax+8]  ; FileVersionMS
    mov dwFileVersionMS, eax
    mov eax, [rax+12] ; FileVersionLS
    mov dwFileVersionLS, eax

    ; Format the version string
    lea rcx, wszBuffer
    lea rdx, wszFormat
    mov r8d, dwFileVersionMS
    shr r8d, 16
    mov r9d, dwFileVersionMS
    and r9d, 0FFFFh
    mov eax, dwFileVersionLS
    shr eax, 16
    push rax
    mov eax, dwFileVersionLS
    and eax, 0FFFFh
    push rax
    call wsprintfW
    add rsp, 10h

    ; Display the version information
    mov rcx, 0
    lea rdx, wszBuffer
    lea r8, wszCaption
    mov r9, 0
    call MessageBoxW

    ; Clean up
    mov rcx, pVersionInfo
    call LocalFree

    ; Exit
    xor rcx, rcx
    call ExitProcess

error_exit:
    ; Display error message
    mov rcx, 0
    lea rdx, wszError
    lea r8, wszCaption
    mov r9, 0
    call MessageBoxW

    ; Exit with error
    mov rcx, 1
    call ExitProcess
main endp

end
May the source be with you