美文网首页漏洞利用
第6章 定时器和windows时间

第6章 定时器和windows时间

作者: sunnnnnnnnnny | 来源:发表于2020-12-29 10:28 被阅读0次

1 定时器

相关api

//设置定时器
SetTimer
UINT SetTimer(
    HWND hWnd,  // handle of window for timer messages
    UINT nIDEvent,  // timer identifier
    UINT uElapse,   // time-out value
    TIMERPROC lpTimerFunc   // address of timer procedure 当为NULL时会向窗口发送VM_TIMER消息
   );

WM_TIMER 消息的附加参数
wTimerID = wParam;            // timer identifier 
tmprc = (TIMERPROC *) lParam; // address of timer callback 
 

//撤销定时器
KillTimer
BOOL KillTimer(
    HWND hWnd,  // handle of window that installed timer
    UINT uIDEvent   // timer identifier
   );   
 

源代码
Timer.rc

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include        <resource.h>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define DLG_MAIN        1
#define ICO_1           1
#define ICO_2           2
#define IDC_SETICON     100
#define IDC_COUNT       101
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//定义了两个icon
ICO_1   ICON        "1.ico" //对话框的图标,会取第一个ICON
ICO_2   ICON        "2.ico"


//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//定义一个对话框 name DIALOG x,y,w,h
DLG_MAIN DIALOG 50, 50, 113, 40
//对话框的style
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "定时器例子" //对话框标题
FONT 9, "宋体" //对话框字体 
{
 ICON ICO_1, IDC_SETICON, 8, 9, 18, 21
 LTEXT "计数:", -1, 35, 16, 25, 10
 LTEXT "", IDC_COUNT, 62, 16, 40, 10
}

汇编代码
Timer.asm

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Sample code for < Win32ASM Programming 3rd Edition>
; by 罗云彬, http://www.win32asm.com.cn
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Timer.asm
; 定时器的使用例子
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 使用 nmake 或下列命令进行编译和链接:
; ml /c /coff Timer.asm
; rc Timer.rc
; Link /subsystem:windows Timer.obj Timer.res
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        .386
        .model flat,stdcall
        option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include     windows.inc
include     user32.inc
includelib  user32.lib
include     kernel32.inc
includelib  kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ID_TIMER1   equ 1
ID_TIMER2   equ 2
ICO_1       equ 1
ICO_2       equ 2
DLG_MAIN    equ 1
IDC_SETICON equ 100
IDC_COUNT   equ 101
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        .data?
hInstance   dd      ?
hWinMain    dd      ?
dwCount     dd      ?
idTimer     dd      ?
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        .code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 定时器过程
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcTimer  proc    _hWnd,_uMsg,_idEvent,_dwTime
        
        PUSHAD ;将通用寄存器压栈 入栈顺序为EAX,ECX,EDX,EBX,ESP(初始值),EBP,ESI,EDI.
        invoke  GetDlgItemInt,hWinMain,IDC_COUNT,NULL,FALSE
        ; GetDlgItemInt 获取对话框指定控件文本,将其转换为整数
        ;UINT GetDlgItemInt(
        ;    HWND hDlg, // handle to dialog box
        ;    int nIDDlgItem,    // control identifier
        ;    BOOL *lpTranslated,    // points to variable to receive success/failure indicator
        ;    BOOL bSigned   // specifies whether value is signed or unsigned
        ;   );
        inc eax
        invoke  SetDlgItemInt,hWinMain,IDC_COUNT,eax,FALSE
        ;BOOL SetDlgItemInt(
        ;    HWND hDlg, // handle of dialog box
        ;    int nIDDlgItem,    // identifier of control
        ;    UINT uValue,   // value to set
        ;    BOOL bSigned   // signed or unsigned indicator
        ;   );
        POPAD ;将通用寄存器恢复
        ret

_ProcTimer  endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 窗口过程
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain    proc    uses ebx edi esi,hWnd,uMsg,wParam,lParam

        mov eax,uMsg
;********************************************************************
        .if eax ==  WM_TIMER 
            ;处理WM_TIMER
            ;WM_TIMER 消息的附加参数
            ;wTimerID = wParam;            // timer identifier 
            ;tmprc = (TIMERPROC *) lParam; // address of timer callback 
            ;
            mov eax,wParam ;将定时器ID放入eax
            .if eax ==  ID_TIMER1 ;若是第1个定时器
                inc dwCount ;dwCount加1
                ;取dwCount的第1位 0/1
                mov eax,dwCount
                and eax,1 ;eax=0 or 1
                inc EAX ;eax=1 or 2 对应ICO_1 ICO_2
                invoke  LoadIcon,hInstance,EAX ;加载icon
                ;修改ICON控件IDC_SETICON的图标
                invoke  SendDlgItemMessage,hWnd,IDC_SETICON,STM_SETIMAGE,IMAGE_ICON,EAX
                ;LONG SendDlgItemMessage(
                ;    HWND hDlg, // handle of dialog box
                   ; int nIDDlgItem,    // identifier of control
                   ; UINT Msg,  // message to send
                   ; WPARAM wParam, // first message parameter
                   ; LPARAM lParam  // second message parameter
                   ;);
                ;STM_SETIMAGE消息的附带参数
                ;wParam = (WPARAM) fImageType;       // image-type flag IMAGE_ICON/IMAGE_BITMAP/...
                ;lParam = (LPARAM) (HANDLE) hImage;  // handle of the image
            .elseif eax ==  ID_TIMER2 ;若是第2个定时器
                invoke  MessageBeep,-1 ;调用蜂鸣器
            .endif
;********************************************************************
        .elseif eax ==  WM_INITDIALOG ;窗口初始化时
            push    hWnd
            pop hWinMain ;将hWnd赋值给hWinMain
            invoke  SetTimer,hWnd,ID_TIMER1,250,NULL ;创建定时器ID_TIMER1 周期为250ms
            invoke  SetTimer,hWnd,ID_TIMER2,2000,NULL ;创建定时器ID_TIMER2 周期为2s
            invoke  SetTimer,NULL,NULL,1000,addr _ProcTimer ;创建定时器ID_TIMER3 周期为1s 定时器回调函数为_ProcTimer
            mov idTimer,EAX ;将第3个定时器的id保存至idTimer
;********************************************************************
        .elseif eax ==  WM_CLOSE
            ;在窗口退出之前撤销3个定时器
            invoke  KillTimer,hWnd,ID_TIMER1
            invoke  KillTimer,hWnd,ID_TIMER2
            invoke  KillTimer,NULL,idTimer
            ;结束对话框
            invoke  EndDialog,hWnd,NULL
;********************************************************************
        .else
            mov eax,FALSE
            ret
        .endif
        mov eax,TRUE
        ret

_ProcDlgMain    endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
        invoke  GetModuleHandle,NULL
        mov hInstance,eax
        invoke  DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
        invoke  ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        end start

Makefile

NAME = Timer
OBJS = $(NAME).obj
RES  = $(NAME).res

LINK_FLAG = /subsystem:windows
ML_FLAG = /c /coff

$(NAME).exe: $(OBJS) $(RES)
    Link $(LINK_FLAG) $(OBJS) $(RES)

.asm.obj:
    ml $(ML_FLAG) $<
.rc.res:
    rc $<

clean:
    del *.obj
    del *.res

2 windows时间

2.1 windows时间的获取和设置

GetLocalTime SYSTEMTIME
GetSystemTime

2.2 计算时间间隔

GetTickCount

相关文章

  • 第6章 定时器和windows时间

    1 定时器 相关api 源代码Timer.rc 汇编代码Timer.asm Makefile 2 windows时...

  • react-native android模拟器或真机上定时器se

    从Mac系统换到Windows,run android后真机和模拟器的定时器都不运行(Mac下run androi...

  • 运动框架的应用实例

    前两个Json,semaphoreJson和targetJson 定时器和setpJson 在指定时间内关闭定时器...

  • 内核定时器

    定时器的使用 1、定义定时器结构体timer_list。 2、设置超时时间,定义定时器处理函数和传参。 3、激活定...

  • 2018-07-26 定时器

    linux内核分析笔记----定时器和时间管理

  • Flink 定时器

    定时器 基于处理时间或者事件时间处理过一个元素之后, 注册一个定时器, 然后指定的时间执行. Context和On...

  • Pycharm,Anaconda的安装,集成开发环境,包安装

    第01章 Windows下搭建Python集成开发环境 第02章 Pycharm的下载、安装和使用 Windows...

  • 2017.12.21学习总结

    下午学习了定时器,定时器分为高级定时器、通用定时器和基本定时器,我们主要研究通用定时器。 定时器中断实现步骤:...

  • golang-定时器

    定时器 和 断续器 定时器:延时某些操作任务断续器:设置的好间隔时间,周而复始的执行任务

  • 第11章 定时器和时间管理

    系统定时器是一种可编程硬件芯片,能以固定频率产生中断,也就是定时器中断,其对应的中断处理程序负责更新系统时间,也负...

网友评论

    本文标题:第6章 定时器和windows时间

    本文链接:https://www.haomeiwen.com/subject/bytfoktx.html