《電子技術應用》
您所在的位置:首頁 > 嵌入式技术 > 解决方案 > 汇编源代码之获得操作系统版本

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

2017-07-23
關鍵詞: 汇编语言

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


本站內容除特別聲明的原創文章之外,轉載內容只為傳遞更多信息,并不代表本網站贊同其觀點。轉載的所有的文章、圖片、音/視頻文件等資料的版權歸版權所有權人所有。本站采用的非本站原創文章及圖片等內容無法一一聯系確認版權者。如涉及作品內容、版權和其它問題,請及時通過電子郵件或電話通知我們,以便迅速采取適當措施,避免給雙方造成不必要的經濟損失。聯系電話:010-82306118;郵箱:aet@chinaaet.com。
主站蜘蛛池模板: 国产日韩欧美在线视频观看| 亚洲国产精品日韩| 人妻少妇精品久久| 日韩在线播放一区| 亚洲91精品在线观看| 欧美精品成人在线| 国产精品视频中文字幕91| 国产成人精品免高潮在线观看| 亚洲一区中文字幕| 国产精品福利久久久| 欧美激情国产日韩精品一区18| 91免费看片网站| 国产日韩精品一区观看| 国产精品黄色av| 国精产品99永久一区一区| 91精品视频免费看| 国产精品免费在线免费| 国产午夜大地久久| 亚洲综合av一区| 一区二区三区四区欧美| 99精品视频在线看| 精品欧美日韩在线| 亚洲一区二区三区乱码aⅴ| 国产精品乱码一区二区三区| 国产精品中文字幕在线| 日韩欧美一区二区在线观看| 日韩中文字幕在线| 日本亚洲欧洲色α| 99在线国产| 久久免费视频观看| 91久久精品国产| 久久久精品有限公司| 日韩精品资源| 欧美日韩国产va另类| 国产精品美女久久久久av福利| 久久国产精品一区二区三区| 九九久久国产精品| 国产精品免费久久久| 国产成人免费av| 99国产精品白浆在线观看免费| 91免费看片网站|