This source code comes from 9CBS Forum: http://expert.9cbs.net/expert/topic/2854/2854350.xml?temp =.6098749
---------------------------
DOS can call the DOS interrupt service program, you can call the API function getversionEx () under Windows
This is the source code I test in the PE format, which can be run under DOS and Windows, which is reported to report the current OS information.
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@208h; -------------------------------------------------------------------------------------------------------------------- -----------------------------------------------; MS DOS 7.00 001FH 5710H; MS DOS 7.10 18DEH 6EE5H; UCDOS 1AEBH; UCDOS98 1AEBH 6E20H; MSDOS MODE 0000H; PDOS95 0A50H 6E20H ;; Date Summary; --------------------- ----------------------------------; 2002.04.07 Created from Software Paper 95p125; 2002.06.11 show versioniff os is MS-DOS; 2002.08.07 Convert it to DOS EXE format to be stub; program in PE format execute file; 2004.02.09 Added the condition asm var 'UseStack'; Question :; Why can this program run normally with stack segment , Though there is push and pop instruction in bin2dec proc?
USSTACK EQU 0DATA SegmentStrmsdos DB "MS DOS" CMAJORVER DB '' DB '.' CMAJORVER DB "$"
STRUCDOS DB "UCDOS" CuCDOSVER DB "98 Special Edition $"
STRPDOS95 DB "Windows95" in Chinese DOS PDOS95 $ "Data Ends
IF useestacksseg segment stackdb 10 dup (?) SSEG endsendifcode segment; ------------------------------------- -IF USTACKASUME CS: CODE, DS: DATA, SS: SSEGELSEASSUME CS: CODE, DS: DATAENDIFMAIN PROCSTART: MOV AX, DATAMOV DS, AX
IF USESTACKMOV AX, SSEGMOV SS, AXENDIF
MOV AH, 30H; Get Versionint 21HADD Al, '0'mov CMAJORVER, Almov BX, Offset CminorVerCall Bin2Dec
MOV AX, 3508HINT 21H
Mov DX, Offset Strmsdosmov Ah, 09HINT 21H
CMP BX, 1FHJE @END; Here Is DOS 7.00 OnlyCmp BX, 18dehje @END; Here Is DOS 7.10 ONLY
Mov DX, Offset Strucdoscmp BX, 1Aebhje @Report
CMP BX, 1AF3HJNE @ next2mov cucdosver, '$' jmp @Report
@ NEXT2:
MOV DX, OFFSET STRPDOS95CMP BX, 0A50HJNE @ End @ Report:; Mov Ah, 09 Hint 21h @ End: MOV AX, 4C00HINT 21HMAIN ENDP
; ================================================== =======; INPUT: AH = The binary will be translated); bx = first offset; output: bx = first offset of memory stiled the result; ------- ------------------------------------------------- bin2dec ProCPUSH DXMOV DL, 10 @ Loopdiv: MOV Al, Ahxor AH, AHDIV DL; (Al) <- (AX) / (DL) (AH) <- (AX)% (DL) Add Al, '0'mov [BX ], ALINC BXCMP AH, 10JG @LoOpdiv
Add Ah, '0'mov [BX], ahpop DXRetbin2dec Endp; ==================================== ====== Code endsend main
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<;,,,,,,,,,,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BIN / LINK / STUB:
Date Summary; ---------------------------------------------------------------------------------------------- ---------; 2002.04.07 created!; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<
.386.model flat, stdcalloption casemap: noneinclude /masm32/include/windows.incinclude /masm32/include/kernel32.incinclude /masm32/include/user32.incincludelib /masm32/lib/user32.libincludelib /masm32/lib/kernel32.lib
BdetailInfo EQU 0
.dataszmsgboxtitle DB "Current operating system", 0
IF BDETAILINFO; ?????? Bdetailinfoszwin31 DB "Win32S On Windows 3.1", 0SzWin9x DB "Win32 On Windows 95", 0lseszwin31 DB "Windows 3.1", 0SZWIN9X DB "Windows 95", 0ndif; ?????? BdetailInfo
Szwinnt DB "Windows NT", 0
SZFORMAT4SVER DB "% Lu.% lu.% lu", 0Szgetosinfofail DB "Take the operating system information failed!", 0.data?osver osversioninfo <> szosverinfo db 255 dup (?) SzosVerinfotmp DB 255 DUP (?)
.codestart: mov OsVer.dwOSVersionInfoSize, SIZEOF OSVERSIONINFOinvoke GetVersionEx, ADDR OsVer.if eaxmov eax, OsVer.dwPlatformId; Identifies the build number of the operating; system in the low-order word For Win9X
. IF EAX == Ver_Platform_Win32Smov ESI, Offset Szwin31and Osver.dwBuildNumber, 0FFFFH.ELSEIF EAX == Ver_Platform_WIN32_WindowsMov ESI, Offset Szwin9xand Osver.dwbuildNumber, 0FFFFH
.ELSE; EAX == Ver_Platform_Win32_NTMOV ESI, Offset Szwinnt.endif
Invoke Lstrcpy, Addr SzosVerinfo, ESI
Invoke WSPrintf, Addr Szosverinfotmp, / Addr Szformat4osver, Osver.dwmajorversion, / OSVER.DWMINORVERSION, OSVER.DWBUILDNUMBER
invoke lstrcat, ADDR szOsVerInfo, ADDR szOsVerInfoTmpinvoke lstrcat, ADDR szOsVerInfo, ADDR OsVer.szCSDVersionmov edi, OFFSET szOsVerInfomov esi, MB_OK OR MB_ICONINFORMATION .elsemov edi, OFFSET szGetOsInfoFailmov esi, MB_OK OR MB_ICONWARNING.endif
Invoke Messagebox, Null, EDI, Addr Szmsgboxtitle, EsiInvoke EXITPROCESS, NULLEND Start