首页
社区
课程
招聘
[求助]大家帮我看看这段代码为什么出错。
发表于: 2008-9-15 17:06 3697

[求助]大家帮我看看这段代码为什么出错。

2008-9-15 17:06
3697
在_ErrorExit这段子程序中我是想让他显示一下SETWINDOWSHOOKEX的错识的原因
但调用子程序时总是出错,不知道为什么。请指点。
.const
szFormat    db    '%s failed with error %d: %s',0
.code
_ErrorExit    proc
        local    @szbuf[80]:BYTE
        local    @lpMsgBuf
        local    @dw
        local    @szBuffer[256]:BYTE
        invoke    GetLastError
        mov    @dw,eax
        ;invoke   
        invoke    FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS ,NULL,@dw ,0,addr @lpMsgBuf,0,NULL
        invoke    wsprintf,addr @szBuffer,addr szFormat,@dw ,addr @lpMsgBuf
        invoke    MessageBox,NULL,addr @szBuffer,NULL,MB_OK
        invoke    LocalFree,@lpMsgBuf
        
        ;invoke    ExitProcess,@dw
        ret
_ErrorExit    endp

以下是MSDN的例子如下。请看
#include <windows.h>

void ErrorExit(LPTSTR lpszFunction)
{
    TCHAR szBuf[80];
    LPVOID lpMsgBuf;
    DWORD dw = GetLastError();

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER |
        FORMAT_MESSAGE_FROM_SYSTEM,
        NULL,
        dw,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );

    wsprintf(szBuf,
        "%s failed with error %d: %s",
        lpszFunction, dw, lpMsgBuf);

    MessageBox(NULL, szBuf, "Error", MB_OK);

    LocalFree(lpMsgBuf);
    ExitProcess(dw);
}

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 293
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
invoke    wsprintf,addr @szBuffer,addr szFormat,@dw ,addr @lpMsgBuf

去掉 addr 即可
2008-9-15 17:58
0
雪    币: 454
活跃值: (1673)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
3
.const
szFormat    db    '%s failed with error %d: %s',0
invoke    wsprintf,addr @szBuffer,addr szFormat,@dw ,addr @lpMsgBuf

wsprintf少一个参数,另外FormatMessage的参数似乎也有点问题
2008-9-15 18:13
0
雪    币: 796
活跃值: (370)
能力值: ( LV9,RANK:380 )
在线值:
发帖
回帖
粉丝
4
.386
                .model flat,stdcall
                option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include                windows.inc
include                user32.inc
includelib        user32.lib
include                kernel32.inc
includelib        kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
szText                db        'test',0
szFormat    db    '%s failed with error %d: %s',0
.data?
@szBuffer db 256 dup(?)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
_ErrorExit    proc lpszFunction:DWORD
        pushad
        invoke    GetLastError
        mov    esi,eax  
        ;invoke    FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM,NULL,@dw ,0,addr @lpMsgBuf,0,NULL
        push    0                ; Arguments
        push    0                ; nSize
        push    offset @szBuffer ; lpBuffer
        push    400h             ; dwLanguageId
        push    esi              ; dwMessageId
        push    0                ; lpSource
        push    1100h            ; dwFlags
        call    FormatMessage
        mov     ecx, dword ptr @szBuffer
        invoke    wsprintf,addr @szBuffer,addr szFormat,lpszFunction,esi,ecx
        invoke    MessageBox,NULL,addr @szBuffer,NULL,MB_OK
        mov     ecx, dword ptr @szBuffer
        invoke    LocalFree,ecx
        popad
        ret
_ErrorExit    endp
start:
                invoke        _ErrorExit,offset szText
                invoke        ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                end        start
2008-9-15 22:29
0
雪    币: 227
活跃值: (10)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
5
哇哦果然有高手,谢谢了。我对的崇拜有如滔滔江水,一发不可收拾。
2008-9-17 09:32
0
游客
登录 | 注册 方可回帖
返回
//