[原创]用MASM32编程获取windows类型

时间:2022-12-07 14:00:45


;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;Function: Display the Windows type
; Author:purple endurer
; Develop: MASM32 V8
;Log
;------------------------------------
; 2005-04-29 Create
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.386
.model  flat,  stdcall
option  casemap: none
include /masm32/ include/windows.inc
include /masm32/ include/kernel32.inc
include /masm32/ include/user32.inc
includelib /masm32/lib/user32.lib
includelib /masm32/lib/kernel32.lib

GetWinType  PROTO


.data
g_szWin95        db  "Windows 95", 0
g_szWin98        db  "Windows 98", 0
g_szWinMe        db  "Windows Mellinnium", 0
g_szWinNT351     db  "Windows NT 3.51", 0
g_szWinNT40      db  "Windows NT 4.0", 0
g_szWin2000      db  "Windows 2000", 0
g_szWinXP        db  "Windows XP", 0
g_szWin2003      db  "Windows Server 2003", 0
g_szUnknow       db  "Unknow", 0

.data?
g_OsVerInfo OSVERSIONINFO <>

.code
start:
     mov g_OsVerInfo.dwOSVersionInfoSize,  SIZEOF OSVERSIONINFO
     invoke  GetVersionEx,  ADDR g_OsVerInfo
     .if  eax != 0
         invoke GetWinType
         invoke  MessageBox, NULL,  eax,  eax, MB_OK
     .endif
     invoke  ExitProcess, NULL

;//
;Function: Get the Windows type
; Input: g_OsVerInfo
; Output: Pointer to the string of windows type
;//
GetWinType  proc
     push  ebx     ;用ebx作为临时变量
     mov  eax,  OFFSET g_szUnknow ;假设返回值为Unknow
     mov  ebx, g_OsVerInfo.dwPlatformId
     .if   ebx==1
         mov  ebx, g_OsVerInfo.dwMinorVersion
         .IF  ebx==0
             mov  eax,  OFFSET g_szWin95
         .ELSEIF  ebx==10
             mov  eax,  OFFSET g_szWin98
         .ELSEIF  ebx==90
             mov  eax,  OFFSET g_szWinMe
         .ENDIF
     .elseif  ebx==2
         mov  ebx, g_OsVerInfo.dwMajorVersion
         .IF  ebx==3
             mov  eax,  OFFSET g_szWinNT351
         .ELSEIF  ebx==4
             mov  eax,  OFFSET g_szWinNT40
         .ELSEIF  ebx==5
             mov  ebx, g_OsVerInfo.dwMinorVersion
             .if  ebx==0
                 mov  eax,  OFFSET g_szWin2000
             .elseif  ebx==1
                 mov  eax,  OFFSET g_szWinXP
             .elseif  ebx==2
                 mov  eax,  OFFSET g_szWin2003
             .endif
         .ENDIF
     .endif

     pop  ebx

     ret
GetWinType  endp

end start