News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

OS Version code

Started by Cobra, December 06, 2006, 04:39:38 AM

Previous topic - Next topic

Cobra

Would anyone be willing to test this on 95/98/ME/2000 and report what it returns? I don't have access to those and need to know if this is working correctly. Thanks in advance. Link it as a console app.


.586
.mode flat, stdcall
option casemap:none

.code
; GetWindowsVersionInfo
;
; Retrieves the Version, Build and Service Pack of the OS.
;
; Parameters
;
; [in] dwVersion
;      Pointer to a DWORD that will contain the OS version.
; [in] dwBuild
;      Pointer to a DWORD that will contain the build info of the OS
; [in] dwServicePack
;      Pointer to a DWORD that will contail the SP level of the OS
;
; Return Value
;
; If the function is successful, the return value is the OS version and the 3 input
; parameters are set accordingly; otherwise the return value is 0 and the 3 input
; parameters are also set to 0.


GetWindowsVersionInfo PROC USES esi edi, dwVersion:PTR DWORD, dwBuild:PTR DWORD, dwServicePack:PTR DWORD

    LOCAL osvi:OSVERSIONINFOEX
       
    xor    eax, eax
    mov    ecx, SIZEOF OSVERSIONINFOEX / 4
    lea    edi, osvi
    rep    stosd
   
    mov    osvi.dwOSVersionInfoSize, sizeof OSVERSIONINFOEX
    invoke GetVersionEx, ADDR osvi
   
    .if    eax == 0
        mov    osvi.dwOSVersionInfoSize, sizeof OSVERSIONINFO
        invoke GetVersionEx, ADDR osvi
       
        .if    eax == 0
            mov    ecx, dwVersion
            mov    [ecx], eax
            mov    ecx, dwBuild
            mov    [ecx], eax
            mov    ecx, dwServicePack
            mov    [ecx], eax
            ret
        .endif
    .endif

    lea      esi, osvi
    ASSUME   esi:PTR OSVERSIONINFOEX
   
    mov      eax, [esi].dwMajorVersion
    mov      ecx, [esi].dwMinorVersion
    shl      eax, 16
    or       eax, ecx
    mov      ecx, dwVersion
    mov      [ecx], eax
    mov      eax, [esi].dwBuildNumber
    mov      ecx, dwBuild
    mov      [ecx], eax
    xor      eax, eax
   
    .if    [esi].dwMajorVersion >= 5
        movzx    eax, WORD PTR [esi].wServicePackMajor
        movzx    ecx, WORD PTR [esi].wServicePackMinor
        shl      eax, 16
        or       eax, ecx
    .endif
    mov     ecx, dwServicePack
    mov     [ecx], eax
    mov     ecx, dwVersion
    mov     eax, [ecx]
    ASSUME  esi:NOTHING
    ret
   
GetWindowsVersionInfo ENDP

nNumWritten DD ?
hHandle  DD ?
dwVersion DD ?
dwBuild DD ?
dwSP DD ?
buffer    DB  128 dup(?)
szText  DB  "dwVersion = %d.%d, dwBuild = %d, dwSP = %d.%d",13,10,0

.code

main:
          invoke GetStdHandle, STD_OUTPUT_HANDLE
          mov    hHandle, eax
          invoke GetWindowsVersionInfo, addr dwVersion, addr dwBuild, addr dwSP
          movzx  eax, WORD PTR dwSP
          movzx  ecx, WORD PTR dwSP+2
          mov    edx, dwBuild
          movzx  esi, WORD PTR dwVersion
          movzx  edi, WORD PTR dwVersion+2
          invoke wsprintf, addr buffer, addr szText, esi, edi, edx, ecx, eax
          invoke WriteFile, hHandle, addr buffer, eax, addr nNumWritten, 0
          invoke ExitProcess, 0
END main

ToutEnMasm


evlncrn8

next time just attach an exe too, that way more people can test...
like me for example, i couldnt be bothered linking and compiling that in work,
but had you have attached an exe i could have pasted u the results from
my vmware machines for 95, 98, 98se, and me... but u didnt.. so ... i didnt

PBrennick

evlncrn8,
It would never have assembled. I have fixed the source and it is attached here.

Cobra,
Be sure to take a close look at ToutenMasm's excellent example so you can see how it is done. His output is understandable while yours needs work as most people will not understand shorthand. For example, this is the output from my machine:
Quote
dwVersion = 1.5, dwBuild = 2600, dwSP = 2.0
Most people wont understand dwVersion = 1.5

I hope you see this as constructive criticism, you made a good beginning.

Paul


[attachment deleted by admin]
The GeneSys Project is available from:
The Repository or My crappy website

evlncrn8

output from 98 SE machine...

dwVersion = 10.4, dwBuild = 67766446, dwSP = 0.0

output from ME machine...

dwVersion = 90.4, dwBuild = 73010104, dwSp = 0.0

output from 2000 SP4 machine...

dwVersion =0.5 , dwBuild = 2195 , dwSp = 4.0

and i totally agree with PBrennick's comments...

t3dbundy

dwVersion = 1.5, dwBuild = 2600, dwSP = 2.0

xp sp2

PBrennick

Exactly,
ToutenMasm displays that instead of the shorthand. The first field?

Paul
The GeneSys Project is available from:
The Repository or My crappy website

evlncrn8

mov      eax, [esi].dwMajorVersion
    mov      ecx, [esi].dwMinorVersion
    shl      eax, 16
    or       eax, ecx

and that is a really bad idea as the values (currently low) might go high later on and you could end up
with totally screwed results...

if its a dword for each part, keep it so... thats my recommendation

Cobra

Quote from: PBrennick on December 06, 2006, 01:24:58 PM
I hope you see this as constructive criticism, you made a good beginning.

Paul
It's all good. Thanks to evryone for taking the time for it.  :U

zooba

Isn't that 'shorthand' simply the major and minor version numbers around the wrong way?

ie. Windows XP = 5.10    --> 1.5
Windows 2000 = 5.00     --> 0.5
Windows ME    = 4.90     --> 9.4
Windows 98SE = 4.10     --> 1.4

Converting it to text is only useful for the user, and they should really know what 'brand' of Windows they're using already. It's much easier for software to test the DWORDs.

Did Microsoft really build Windows 98 and ME around seventy million times before releasing?

PBrennick

zooba,
Actually, I am surprised by 4.9 for ME.

Quote
Did Microsoft really build Windows 98 and ME around seventy million times before releasing?

They should have!

Paul
The GeneSys Project is available from:
The Repository or My crappy website