To assemble the source code for the operating system version

Source: Internet
Author: User
Tags date command line include stub

DOS Interrupt Service program can be invoked

API functions can be invoked under Windows GetVersionEx ()

This is the source code for my test stub in the PE format, which can be run under DOS and Windows, with the ability to report current OS information.

; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; FileName:os_type.asm
; Function:reports Current operation system type
; Author:purple Endurer
; version:0.1
;
; OS Name Offset of int 08h Offset of int 43h
; -------------------------------------------------------
; MS DOS 7.00 001Fh 5710h
; MS DOS 7.10 18DEh 6ee5h
; UCDOS 1af3h
; UCDOS98 1AEBh 6e20h
; MSDOS Mode 0000h
; PDOS95 0a50h 6e20h
;
; Date Summary
; -------------------------------------------------------
; 2002.04.07 Created from software paper 95p125
; 2002.06.11 Show version If OS is MS-DOS
; 2002.08.07 Convert it to DOS EXE format to is 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 are push and pop instruction in Bin2dec proc?
Usestack equ 0
Data segment
Strmsdos db "MS DOS"
Cmajorver DB '
DB '. '
Cminorver db "$"
Strucdos db "UCDOS"
Cucdosver DB "98 Special Edition $"
strPDOS95 db "Windows95 Chinese dos mode pdos95$"
Data ends
If Usestack
SSEG segment Stack
DB ten dup (?)
Sseg ends
endif
Code segment
;--------------------------------------
If Usestack
Assume Cs:code, Ds:data, ss:sseg
Else
Assume Cs:code, Ds:data
endif
Main proc
Start
MOV ax, data
MOV ds, ax
If Usestack
mov ax, sseg
mov ss, ax
endif
mov ah, 30h; Get Version
int 21h
Add al, ' 0 '
mov cmajorver, AL
mov bx, offset cminorver
Call Bin2dec
mov ax, 3508h
int 21h
MOV dx, offset strmsdos
mov ah, 09h
int 21h
CMP BX, 1FH
Je @end; Here's DOS 7.00 only
CMP BX, 18deh
Je @End; Here's DOS 7.10 only
MOV dx, offset strucdos
CMP BX, 1AEBH
Je @Report
CMP BX, 1AF3H
Jne @next2
mov cucdosver, ' $ '
JMP @report
@next2:
MOV dx, offset strPDOS95
CMP BX, 0a50h
Jne @End
@Report:
; mov ah, 09h
int 21h
@End:
mov ax, 4c00h
int 21h
Main ENDP
; ========================================================
; Input:ah = The Binary would be translated)
; BX = Memory us to store
; OUTPUT:BX = "A" of memory stored the result
; --------------------------------------------------------
BIN2DEC proc
Push DX
MOV dl, 10
@LoopDiv:
mov al, ah
XOR Ah, ah
Div DL; (AL) <-(AX)/(DL) (AH) <-(AX)% (DL)
Add al, ' 0 '
mov [BX], AL
Inc BX
CMP Ah, 10
JG @LoopDiv
Add ah, ' 0 '
mov [BX], ah
Pop DX
Ret
Bin2dec ENDP
;=========================================
Code ends
End Main
;<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<
; FileName:StubDemo.asm
; Fuction:demo to use the custome stub of PE exe files.
; Author:purple Endurer
Stub
; The command line refered Cursom STUB program:
;\masm32\bin\link/stub:<filename.exe>/subsystem:windows <objectname.obj>
; Example:
;D: \masm32v6\works\my_stub>\masm32\bin\link/stub:stub.exe/subsystem:windows stubdemo.obj
; Microsoft (R) incremental Linker Version 5.12.8078
; Copyright (C) Microsoft Corp. 1992-1998. All rights reserved.
; stub.exe:warning lnk4060:stub file missing full MS-DOS header; Rebuild stub with/knoweas 16-bit LINK option
; Date Summary
; -------------------------------------------------------
; 2002.04.07 created!
;<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<< <<<
.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
Bdetailinfo equ 0
. Data
Szmsgboxtitle DB "Current operating system", 0
if bdetailinfo;?????? Bdetailinfo
SZWIN31 db "Win32s on Windows 3.1", 0
Szwin9x db "Win32 on Windows 95", 0
Else
SZWIN31 DB "Windows 3.1", 0
Szwin9x db "Windows 95", 0
endif;?????? Bdetailinfo
Szwinnt db "Windows NT", 0
Szformat4osver db "%lu.%lu.%lu", 0
Szgetosinfofail db "Failed to access operating system information!", 0
. Data?
Osver osVersionInfo <>
Szosverinfo DB 255 dup (?)
Szosverinfotmp DB 255 dup (?)
. Code
Start
mov osver.dwosversioninfosize, SIZEOF osversioninfo
Invoke GetVersionEx, ADDR osver

. if eax
mov eax, Osver.dwplatformid

; Identifies the build number of the operating
; system in the Low-order word for Win9x
. if eax = = Ver_platform_win32s
mov esi, OFFSET szWin31
and Osver.dwbuildnumber, 0FFFFh

. elseif EAX = = Ver_platform_win32_windows
mov esi, OFFSET szwin9x
and Osver.dwbuildnumber, 0FFFFh
. else; EAX ==ver_platform_win32_nt
mov 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 szosverinfotmp
Invoke Lstrcat, ADDR szosverinfo, ADDR osver.szcsdversion
mov edi, OFFSET szosverinfo
mov esi, MB_OK OR mb_iconinformation
. else
mov edi, OFFSET szgetosinfofail
mov esi, MB_OK OR mb_iconwarning
. endif
Invoke MessageBox, NULL, EDI, addr szmsgboxtitle, ESI

Invoke Exitprocess,null
End Start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.