flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > Fail VerQueryValue

Author
Thread Post new topic Reply to topic
fasmlover



Joined: 17 May 2017
Posts: 2
Fail VerQueryValue
Hi guys. Pleasure to be here. Can you please help with my code to retrieve file version of ntoskrnl.exe? I want to be able to query my file version and print it in a messagebox. Still learning FASM in Windows32. Thank you for you help. Cannot wait to contribute more.


Code:
format  pe gui 4.0
include 'win32ax.inc'

invoke GetFileVersionInfoAlpszFilePath01024lpVersionInfo
invoke VerQueryValueAbuffer"\\"lplpReturnValdwLength
mov [hfile],VS_FIXEDFILEINFO.dwFileVersionLS
invoke MessageBox0, [hfile], [hfile], MB_OK
invoke ExitProcess0

VS_FIXEDFILEINFO:
 .dwFileVersionLS dd ?

lpszFilePath      db 'C:\Windows\System32\ntoskrnl.exe',0
dwDummy       dd ?
lpVersionInfo    dd ?
buffer               db 256 dup(?)
lplpReturnVal    dd ?
dwLength         dd ?
hfile                dd ? 

section '.idata' import data readable
        library  kernel32,'kernel32.dll',\
                 version'version.dll'
         import  kernel32,\
                 ExitProcess,'ExitProcess',\
         import  version,\
                 GetFileVersionInfoA'GetFileVersionInfoA',\
                 VerQueryValueA'VerQueryValueA'
         import  user32,\
                 MessageBox,'MessageBoxA'

Post 17 May 2017, 03:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15094
Location: The Unicomplex
You are setting the value at hfile to the fixed constant VS_FIXEDFILEINFO.dwFileVersionLS. So MessageBox has nothing to display other than a pointer to an invalid buffer.
Post 18 May 2017, 11:14
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1198
Location: Athens, Greece
Hi fasmlover, it is somewhat more complex.
Here is a working sample (written hurriedly), see if you can make something of it.
Notice that you have to include the version.inc file.


Code:

    format PE gui 4.0
    entry start

    include "..\include\win32ax.inc"

section ".data" data readable writeable

    lptstrFilename db "C:\Windows\System32\ntoskrnl.exe",0
    lpData dd 0
    BufLen dd 0
    dwLen dd 0
    dwHandle dd 0
    pFileInfo dd 0
    lpBuffer rb 256

section ".code" code readable executable
start:

    invoke GetFileVersionInfoSizelptstrFilenamedwHandle
    .if eax = 0
        ; handle error
        jmp .exit
    .endif

    mov [dwLen], eax

    invoke LocalAllocLPTReax  ; use HeapAlloc instead
    .if eax = 0
        ; handle error
        jmp .exit
    .endif

    mov [lpData], eax

    invoke GetFileVersionInfolptstrFilename, [dwHandle], [dwLen], [lpData]
    .if eax = 0
        invoke GetLastError
        ; handle error
        ; free lpData
        jmp .exit
    .endif

    invoke VerQueryValue, [lpData], "\\"pFileInfoBufLen
    .if eax = 0
        ; handle error
        ; free lpData
        jmp .exit
    .endif

    mov esi, [pFileInfo]  ; VS_FIXEDFILEINFO ptr (FAR* FAR*)

    mov eax, [esi+2*4]  ; dwFileVersionMS
    mov ebxeax
    and ebx0xFFFF  ; Minor Version
    shr eax16
    and eax0xFFFF  ; Major Version

    mov ecx, [esi+3*4]  ; dwFileVersionLS
    mov edxecx
    and edx0xFFFF  ; Revision Number
    shr ecx16
    and ecx0xFFFF  ; Build Number

    ; Output: major.minor.build.revision
    cinvoke wsprintflpBuffer, <"File Version: %d.%d.%d.%d">, eaxebxecxedx
    invoke MessageBox0lpBufferlptstrFilenameMB_OK
    invoke LocalFree, [lpData]

    .exitinvoke ExitProcess0


section ".idata" import data readable writeable

    library kernel32,"kernel32.dll"user32,"user32.dll"version,"version.dll"

    include "..\include\api\kernel32.inc"
    include "..\include\api\user32.inc"
    include "..\include\api\version.inc"





XP 32-Bit Output: major.minor.build.revision

Image

Windows 7 64 Bit

Image


Description:
Download
Filename: version.inc
Filesize: 675 Bytes
Downloaded: 39 Time(s)

Post 18 May 2017, 13:22
View user's profile Send private message Reply with quote
fasmlover



Joined: 17 May 2017
Posts: 2
Many thanks, guys. Especially appreciated a detailed response from Picnic and included "version.inc". It is extremely helpful; I did not know at that time what my roadblock was. Thanks again! It works perfectly, Picnic.
Post 21 May 2017, 08:57
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.