庞大资源库的计算机教程网站!
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
首页 操作系统 程序设计 图形图像 媒体动画 机械电子 WEB开发 数 据 库 办公系列 路由技术 网络原理 网络应用
认证考试 安全技术
首页>程序设计>汇编语言>相关源码>正文
资料搜索
Google搜索
Google
返回上级列表

推荐文章

快速保存网页中所有图片的方法
Windows中让光驱巧妙“隐身”技
防范非法用户入侵Win 2000/XP系
两款比较典型的ASP木马防范方法
有关表格边框的css语法整理
Windows XP中可以被禁用的服务
SQL Server导出导入数据方法
Javascript所有对象的属性的获
网页(HTML)中的特殊字符
与篮球共舞,尽显模式本色
QQ病毒的手工清除方法
Photoshop为极品美女打造性感睫
天衣无缝:IIS与PHP水火也相容
SQL Server存储过程编写和优化

获得操作系统版本的汇编源代码

 作者:Purpleendurer    日期:2005-8-1 15:38:41
字号选择〖 〗/ 双击滚屏 单击停止   

---------------------------

dos下可以调用DOS中断服务程序,
WINDOWS下可以调用 API 函数GetVersionEx()

这是我测试PE格式的STUB的源代码, 可以在DOS和WINDOWS下运行,其功能是报告当前OS信息.

; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; 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 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?

UseStack        equ 0
data    segment
        strMSDOS   db "MS DOS "
        cMajorVer  db ' '
                   db '.'
        cMinorVer  db "    $"

        strUCDOS   db "UCDOS"
        cUCDOSVer  db " 98特别版$"

        strPDOS95  db "Windows95中文DOS方式PDOS95$"
data  ends

if UseStack
        sseg segment stack
                db 10 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 is DOS 7.00 only
       cmp  bx, 18deh
       je   @End  ;Here is 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 will be translated)
;          BX = First offset of memory us to store the result
; Output:  BX = First offset 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 how 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 "当前操作系统",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 "取操作系统信息失败!", 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

上一篇:读寄存器内容的源代码    下一篇:汇编语言制作的光带菜单及源程序(1.0)  
[发送给好友]  [关闭窗口]  [返回顶部]   转载请注明来源:www.it00.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
责任编辑: 原点 投稿作者: Purpleendurer
信息来源: 网络 录入时间: 2005-8-1 15:38:41
关于我们 - 广告服务 - 版权申明 - 网站地图 - 联系方式 - 总编信箱 - 会员投稿