CProxyDllMaker : a class to make proxy dll's masm source code

来源:互联网 发布:程序员之死 知乎 编辑:程序博客网 时间:2024/05/18 00:05

前言

在做一个小功能, 根据给定DLL名称和API名称列表,生成代理DLL的源码和批处理文件.
封装了一个类CProxyDllMaker, 还挺好用的.
用工具生成可编译的源码工程, 可以做自动化的操作.
有规律可循的源代码实现, 可以考虑写工具生成源代码.

代码片段

调用方代码

void CDlgImportTbl::OnRImportTblMakeProxyDll() {    int iIndex = 0;    int iItemCnt = 0;    DWORD dwRc = 0;    char* pStrEnd = NULL;    CString str;    CString strDllName;    CStringArray strAryApiName;    CProxyDllMaker Maker;    POSITION pos = m_ListDll.GetFirstSelectedItemPosition();    if (NULL == pos) {        AfxMessageBox("请选择DLL");        return;    }    iIndex = m_ListDll.GetNextSelectedItem(pos);    strDllName = m_ListDll.GetItemText(iIndex, 0);    if (strDllName.IsEmpty()) {        AfxMessageBox("DLL名称为空");        return;    }    strAryApiName.RemoveAll();    iItemCnt = m_ListApi.GetItemCount();    for(iIndex = 0; iIndex < iItemCnt; iIndex++) {        str = m_ListApi.GetItemText(iIndex, 0);        if (!str.IsEmpty()) {            if (CStrHelper::IsHexString(str)) {                dwRc = strtoul(str, &pStrEnd, 16);                str.Format("%d", dwRc);            }            strAryApiName.Add(str);        }    }    if (strAryApiName.GetSize() <= 0) {        AfxMessageBox("Api名称列表为空");        return;    }    Maker.MakeProxyDll(strDllName, strAryApiName);    AfxMessageBox(Maker.GetMsg());}

类CProxyDllMaker头文件

// ProxyDllMaker.h: interface for the CProxyDllMaker class.////////////////////////////////////////////////////////////////////////#if !defined(AFX_PROXYDLLMAKER_H__1890B555_CCB9_46D7_9585_FD0584C75D1A__INCLUDED_)#define AFX_PROXYDLLMAKER_H__1890B555_CCB9_46D7_9585_FD0584C75D1A__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000class CProxyDllMaker  {public:    CProxyDllMaker();    virtual ~CProxyDllMaker();    BOOL MakeProxyDll(CString& strDllName, CStringArray& strAryApiName);    CString GetMsg() {return m_strMsg;}private:    void MakeClearBat();    void MakeBuildBat();    void MakeDef(CStringArray& strAryApiName);    void MakeInc(CStringArray& strAryApiName);    void MakeAsm(CStringArray& strAryApiName);private:    CString m_strNameClearBat;    CString m_strNameBuildBat;    CString m_strNameDef;    CString m_strNameInc;    CString m_strNameAsm;    CString m_strDllPrefixName;    CString m_strDirName;    CString m_strMsg;};#endif // !defined(AFX_PROXYDLLMAKER_H__1890B555_CCB9_46D7_9585_FD0584C75D1A__INCLUDED_)

类CProxyDllMaker实现文件

// ProxyDllMaker.cpp: implementation of the CProxyDllMaker class.////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include <atlconv.h>#include "MyPeEdit.h"#include "ProxyDllMaker.h"#include "StrHelper.h"#include "UtilityHelper.h"#include "MyFileOpt.h"#ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE[]=__FILE__;#define new DEBUG_NEW#endif//////////////////////////////////////////////////////////////////////// Construction/Destruction///////////////////////////////////////////////////////////////////////// 用到了kernel32.LoadLibrary, kernel32.GetProcAddress/// 所以不能代理kernel32.dllCProxyDllMaker::CProxyDllMaker(){    m_strMsg.Empty();    m_strDirName.Empty();}CProxyDllMaker::~CProxyDllMaker(){}BOOL CProxyDllMaker::MakeProxyDll(CString& strDllName, CStringArray& strAryApiName) {    CString strDllNamePrefix;    CString strDirName;    if (strDllName.IsEmpty() || (strAryApiName.GetSize() <= 0)) {        m_strMsg = "Dll名称为空或API列表为空";        return FALSE;    }    m_strDirName = CUtilityHelper::GetModuleDir();    m_strDllPrefixName = CStrHelper::GetFileNamePrefix(strDllName);    m_strDirName += m_strDllPrefixName;    ::CreateDirectory(m_strDirName, NULL);    m_strDirName += "\\";    m_strNameClearBat.Format("%s_clear.bat", m_strDllPrefixName);    m_strNameBuildBat.Format("%s_build.bat", m_strDllPrefixName);    m_strNameDef.Format("%s.def", m_strDllPrefixName);    m_strNameInc.Format("proxy_%s.inc", m_strDllPrefixName);    m_strNameAsm.Format("%s.asm", m_strDllPrefixName);    MakeClearBat();    MakeBuildBat();    MakeDef(strAryApiName);    MakeInc(strAryApiName);    MakeAsm(strAryApiName);    m_strMsg.Format(        "制作完成\n"        "输出目录[%s]\n"        "请运行[%s]编译代理DLL工程\n",         m_strDirName,        m_strNameBuildBat);    return TRUE;}void CProxyDllMaker::MakeClearBat() {    USES_CONVERSION;    HANDLE hFile = NULL;    char szBuf[MAXBYTE] = {'\0'};    CString strFilePathName;    int iAryIndex = 0;    CString strRow1;    char* pAry[] = {        "@echo off",        "rem my_clear_dll.bat", // modify pos 1        "echo.",        "echo ========== entry %0 ==========",        "echo.",        "if \"%1\" == \"\" goto NO_PARAM1",        "goto WORK",        ":NO_PARAM1",        "if exist *.exp del *.exp",        "if exist *.obj del *.obj",        "if exist *.lib del *.lib",        "if exist *.dll del *.dll",        "goto END",        ":WORK",        "echo.",        "echo clear trash about %1.dll",        "echo.",        "if exist %1.exp del %1.exp",        "if exist %1.obj del %1.obj",        "if exist %1.lib del %1.lib",        "if exist %1.dll del %1.dll",        ":END",        "echo.",        "echo ========== leave %0 ==========",        "echo.",        NULL    };    strFilePathName = m_strDirName;    strFilePathName += m_strNameClearBat;    // 修正活动的参数    strRow1.Format("rem %s", m_strNameClearBat);    pAry[1] = (char*)(LPCTSTR)strRow1;    // 写文件    hFile = MyOpenFileNew(A2W(strFilePathName));    if (IsValidFileHandle(hFile)) {        iAryIndex = 0;        while (NULL != pAry[iAryIndex]) {            strcpy(szBuf, pAry[iAryIndex++]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));        }        MyCloseFile(hFile);    }}void CProxyDllMaker::MakeBuildBat() {    USES_CONVERSION;    HANDLE hFile = NULL;    char szBuf[MAXBYTE] = {'\0'};    CString strFilePathName;    int iAryIndex = 0;    CString strRow1;    CString strRow3;    CString strRow4;    char* pAry[] = {        "@echo off",        "rem my_build_dll.bat", // change row[1]        "cls",        "set DLLNAME=MyDll", // change row[3]        "if exist my_clear_dll.bat call my_clear_dll.bat %DLLNAME%", // change row[4]        "\\masm32\\bin\\ml /c /coff %DLLNAME%.asm",        "\\masm32\\bin\\Link /SUBSYSTEM:WINDOWS /DLL /DEF:%DLLNAME%.def %DLLNAME%.obj",        "if exist %DLLNAME%.dll goto BUILD_OK",        "goto BUILD_ERROR",        ":BUILD_OK",        "    echo.",        "    echo ========== dll build ok ==========",        "    echo.",        "    goto END",        ":BUILD_ERROR",        "    echo.",        "    echo ========== build error ==========",        "    echo.",        "    goto END",        ":END",        "pause",        NULL    };    strFilePathName = m_strDirName;    strFilePathName += m_strNameBuildBat;    // 修正活动的参数    strRow1.Format("rem %s", m_strNameBuildBat);    pAry[1] = (char*)(LPCTSTR)strRow1;    strRow3.Format("set DLLNAME=%s", m_strDllPrefixName);    pAry[3] = (char*)(LPCTSTR)strRow3;    strRow4.Format("if exist %s call %s %%DLLNAME%%", m_strNameClearBat, m_strNameClearBat);    pAry[4] = (char*)(LPCTSTR)strRow4;    // 写文件    hFile = MyOpenFileNew(A2W(strFilePathName));    if (IsValidFileHandle(hFile)) {        iAryIndex = 0;        while (NULL != pAry[iAryIndex]) {            strcpy(szBuf, pAry[iAryIndex++]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));        }        MyCloseFile(hFile);    }}void CProxyDllMaker::MakeDef(CStringArray& strAryApiName) {    USES_CONVERSION;    HANDLE hFile = NULL;    char szBuf[MAXBYTE] = {'\0'};    CString strFilePathName;    int iAryIndex = 0;    CString strRow0;    char* pAry[] = {        "LIBRARY MyDll", // modify pos 0        "EXPORTS",        // "    fnAdd", // 活动的        NULL    };    strFilePathName = m_strDirName;    strFilePathName += m_strNameDef;    // 修正活动的参数    strRow0.Format("LIBRARY %s", m_strDllPrefixName);    pAry[0] = (char*)(LPCTSTR)strRow0;    // 写文件    hFile = MyOpenFileNew(A2W(strFilePathName));    if (IsValidFileHandle(hFile)) {        iAryIndex = 0;        while (NULL != pAry[iAryIndex]) {            strcpy(szBuf, pAry[iAryIndex++]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));        }        // 写 strAryApiName        for(iAryIndex = 0; iAryIndex < strAryApiName.GetSize(); iAryIndex++) {            sprintf(szBuf, "    %s", strAryApiName.GetAt(iAryIndex));            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));        }        MyCloseFile(hFile);    }}void CProxyDllMaker::MakeInc(CStringArray& strAryApiName) {    USES_CONVERSION;    HANDLE hFile = NULL;    char szBuf[MAXBYTE] = {'\0'};    CString strFilePathName;    int iAryIndex = 0;    CString str;    CString strTmp;    DWORD dwRc = 0;    char* pEnd = NULL;    /// 这里每一行都要改...//     char* pAry[] = {    //     "; file name : MyDll.inc",    //     "IFNDEF MY_DLL_INC",    //     "MY_DLL_INC equ <1>",    //     "    fnAdd PROTO STDCALL",    //     "ENDIF ; IFNDEF MY_DLL_INC",//         NULL//     };    strFilePathName = m_strDirName;    strFilePathName += m_strNameInc;    // 写文件    hFile = MyOpenFileNew(A2W(strFilePathName));    if (IsValidFileHandle(hFile)) {        str.Format("; file name : %s.inc\r\n", m_strDllPrefixName);        MyWriteFile(hFile, str, strlen((LPCTSTR)str));        str.Format("IFNDEF proxy_%s_INC\r\n", m_strDllPrefixName);        str.MakeUpper();        MyWriteFile(hFile, str, strlen((LPCTSTR)str));        str.Format("proxy_%s_INC equ <1>\r\n", m_strDllPrefixName);        str.MakeUpper();        MyWriteFile(hFile, str, strlen((LPCTSTR)str));        // api列表        // 写 strAryApiName        for(iAryIndex = 0; iAryIndex < strAryApiName.GetSize(); iAryIndex++) {            if (CStrHelper::IsHexString(strAryApiName[iAryIndex])) {                dwRc = strtoul(strAryApiName[iAryIndex], &pEnd, 16);                str.Format("    %d PROTO STDCALL\r\n", dwRc);            } else {                str.Format("    %s PROTO STDCALL\r\n", strAryApiName[iAryIndex]);            }            MyWriteFile(hFile, str, strlen((LPCTSTR)str));        }        str.Format("ENDIF ; IFNDEF proxy_%s_INC\r\n", m_strDllPrefixName);        str.MakeUpper();        MyWriteFile(hFile, str, strlen((LPCTSTR)str));        MyCloseFile(hFile);    }}void CProxyDllMaker::MakeAsm(CStringArray& strAryApiName) {    USES_CONVERSION;    HANDLE hFile = NULL;    char szBuf[MAXBYTE] = {'\0'};    CString strFilePathName;    int iAryIndex = 0;    CString strRow0;    char* pAry1[] = {        "; file name : MyDll.asm", // 0        ".386",        ".model flat, stdcall",        "option casemap :none   ; case sensitive",        "",        "include windows.inc",        "",        "include kernel32.inc",        "includelib kernel32.lib",        "",        "fnLoadOriginalDll PROTO STDCALL pszOriginalDllName:DWORD",        "",        ".data",        "    g_hOriginalDll DD 0",        NULL    };    char* pAry2[] = {        ".code",        "LibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD",        "    xor eax, eax",        "    .if reason == DLL_PROCESS_ATTACH",        "        inc eax",        "    .elseif reason == DLL_PROCESS_DETACH",        "        inc eax",        "    .elseif reason == DLL_THREAD_ATTACH",        "        inc eax",        "    .elseif reason == DLL_THREAD_DETACH",        "        inc eax",        "    .endif",        "",        "    ret",        "LibMain Endp",        NULL    };    char* pAry3[] = {        "fnLoadOriginalDll proc STDCALL pszOriginalDllName:DWORD",        "    invoke LoadLibraryA, pszOriginalDllName",        "    mov dword ptr g_hOriginalDll, eax",        "    ret",        "fnLoadOriginalDll endp",        NULL    };    strFilePathName = m_strDirName;    strFilePathName += m_strNameAsm;    // 修正活动的参数    strRow0.Format("; file name : MyDll.asm", m_strDllPrefixName);    pAry1[0] = (char*)(LPCTSTR)strRow0;    // 写文件    hFile = MyOpenFileNew(A2W(strFilePathName));    if (IsValidFileHandle(hFile)) {        iAryIndex = 0;        while (NULL != pAry1[iAryIndex]) {            strcpy(szBuf, pAry1[iAryIndex++]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));        }        //     g_pfn_fnAdd DD 0        // 写 strAryApiName        for(iAryIndex = 0; iAryIndex < strAryApiName.GetSize(); iAryIndex++) {            sprintf(szBuf, "    g_pfn_%s DD 0", strAryApiName.GetAt(iAryIndex));            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));        }        sprintf(szBuf, "%s", "");        strcat(szBuf, "\r\n");        MyWriteFile(hFile, szBuf, strlen(szBuf));    // .const        sprintf(szBuf, "%s", " .const");        strcat(szBuf, "\r\n");        MyWriteFile(hFile, szBuf, strlen(szBuf));    //    g_szDllName_OriginalDll db 'Org_MyDll.dll', 0        sprintf(szBuf, "    g_szDllName_OriginalDll db 'Org_%s.dll', 0", m_strDllPrefixName);        strcat(szBuf, "\r\n");        MyWriteFile(hFile, szBuf, strlen(szBuf));    //    g_szFunName_fnAdd db 'fnAdd', 0        for(iAryIndex = 0; iAryIndex < strAryApiName.GetSize(); iAryIndex++) {            sprintf(szBuf, "    g_szFunName_%s db '%s', 0", strAryApiName.GetAt(iAryIndex), strAryApiName.GetAt(iAryIndex));            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));        }        sprintf(szBuf, "%s", "");        strcat(szBuf, "\r\n");        MyWriteFile(hFile, szBuf, strlen(szBuf));        iAryIndex = 0;        while (NULL != pAry2[iAryIndex]) {            strcpy(szBuf, pAry2[iAryIndex++]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));        }// "    ; 代理DLL的API跳转到原始API地址后,由原始API返回, 栈是平的",        sprintf(szBuf, "%s", "    ; 代理DLL的API跳转到原始API地址后,由原始API返回, 栈是平的");        strcat(szBuf, "\r\n");        MyWriteFile(hFile, szBuf, strlen(szBuf));        // 写每一个代理API实现        for(iAryIndex = 0; iAryIndex < strAryApiName.GetSize(); iAryIndex++) {    // "; ##########################################################################",            sprintf(szBuf, "%s", ";##########################################################################");            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "fnAdd proc",            sprintf(szBuf, "%s proc", strAryApiName[iAryIndex]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "    .if (g_hOriginalDll == NULL)",            sprintf(szBuf, "%s", "    .if (g_hOriginalDll == NULL)");            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll",            sprintf(szBuf, "%s", "        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll");            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "    .endif",            sprintf(szBuf, "%s", "    .endif");            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "",            sprintf(szBuf, "%s", "");            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "    .if (g_pfn_fnAdd == NULL)",            sprintf(szBuf, "    .if (g_pfn_%s == NULL)", strAryApiName[iAryIndex]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_fnAdd",            sprintf(szBuf, "        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_%s", strAryApiName[iAryIndex]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "        mov dword ptr g_pfn_fnAdd, eax",            sprintf(szBuf, "        mov dword ptr g_pfn_%s, eax", strAryApiName[iAryIndex]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "    .endif",            sprintf(szBuf, "%s", "    .endif");            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "",            sprintf(szBuf, "%s", "");            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "    jmp g_pfn_fnAdd",            sprintf(szBuf, "    jmp g_pfn_%s", strAryApiName[iAryIndex]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "    ret",            sprintf(szBuf, "%s", "    ret");            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));    // "fnAdd Endp",            sprintf(szBuf, "%s Endp", strAryApiName[iAryIndex]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));        }    // "",        sprintf(szBuf, "%s", "");        strcat(szBuf, "\r\n");        MyWriteFile(hFile, szBuf, strlen(szBuf));        iAryIndex = 0;        while (NULL != pAry3[iAryIndex]) {            strcpy(szBuf, pAry3[iAryIndex++]);            strcat(szBuf, "\r\n");            MyWriteFile(hFile, szBuf, strlen(szBuf));        }        sprintf(szBuf, "\r\n%s", "End LibMain");        strcat(szBuf, "\r\n");        MyWriteFile(hFile, szBuf, strlen(szBuf));        MyCloseFile(hFile);    }}

用类CProxyDllMaker生成的masm DLL工程源代码全部文件列表

@echo offrem USER32_clear.batecho.echo ========== entry %0 ==========echo.if "%1" == "" goto NO_PARAM1goto WORK:NO_PARAM1if exist *.exp del *.expif exist *.obj del *.objif exist *.lib del *.libif exist *.dll del *.dllgoto END:WORKecho.echo clear trash about %1.dllecho.if exist %1.exp del %1.expif exist %1.obj del %1.objif exist %1.lib del %1.libif exist %1.dll del %1.dll:ENDecho.echo ========== leave %0 ==========echo.
@echo offrem USER32_build.batclsset DLLNAME=USER32if exist USER32_clear.bat call USER32_clear.bat %DLLNAME%\masm32\bin\ml /c /coff %DLLNAME%.asm\masm32\bin\Link /SUBSYSTEM:WINDOWS /DLL /DEF:%DLLNAME%.def %DLLNAME%.objif exist %DLLNAME%.dll goto BUILD_OKgoto BUILD_ERROR:BUILD_OK    echo.    echo ========== dll build ok ==========    echo.    goto END:BUILD_ERROR    echo.    echo ========== build error ==========    echo.    goto END:ENDpause
; file name : USER32.incIFNDEF PROXY_USER32_INCPROXY_USER32_INC EQU <1>    GetMenu PROTO STDCALL    SetDlgItemInt PROTO STDCALL    GetWindowTextW PROTO STDCALL    CheckDlgButton PROTO STDCALL    HideCaret PROTO STDCALL    CallWindowProcW PROTO STDCALL    DrawTextW PROTO STDCALL    WinHelpW PROTO STDCALL    PostQuitMessage PROTO STDCALL    GetDlgCtrlID PROTO STDCALL    ScreenToClient PROTO STDCALL    ChildWindowFromPoint PROTO STDCALL    DefWindowProcW PROTO STDCALL    IsClipboardFormatAvailable PROTO STDCALL    EnableMenuItem PROTO STDCALL    TrackPopupMenuEx PROTO STDCALL    GetDesktopWindow PROTO STDCALL    OpenClipboard PROTO STDCALL    GetClipboardData PROTO STDCALL    CharNextA PROTO STDCALL    CloseClipboard PROTO STDCALL    GetSysColor PROTO STDCALL    DialogBoxParamW PROTO STDCALL    EndDialog PROTO STDCALL    MessageBeep PROTO STDCALL    GetSubMenu PROTO STDCALL    CheckRadioButton PROTO STDCALL    SetWindowTextW PROTO STDCALL    SetFocus PROTO STDCALL    SetCursor PROTO STDCALL    CharNextW PROTO STDCALL    RegisterClassExW PROTO STDCALL    GetSysColorBrush PROTO STDCALL    LoadCursorW PROTO STDCALL    LoadIconW PROTO STDCALL    InvalidateRect PROTO STDCALL    UpdateWindow PROTO STDCALL    ShowWindow PROTO STDCALL    SendMessageW PROTO STDCALL    SetDlgItemTextW PROTO STDCALL    CheckMenuItem PROTO STDCALL    CheckMenuRadioItem PROTO STDCALL    SetWindowPos PROTO STDCALL    OffsetRect PROTO STDCALL    MapWindowPoints PROTO STDCALL    GetClientRect PROTO STDCALL    EnableWindow PROTO STDCALL    LoadMenuW PROTO STDCALL    SetWindowLongW PROTO STDCALL    GetWindowLongW PROTO STDCALL    CreateDialogParamW PROTO STDCALL    GetDlgItem PROTO STDCALL    DestroyMenu PROTO STDCALL    DestroyWindow PROTO STDCALL    SetMenu PROTO STDCALL    GetWindowRect PROTO STDCALL    SystemParametersInfoW PROTO STDCALL    DispatchMessageW PROTO STDCALL    TranslateMessage PROTO STDCALL    TranslateAcceleratorW PROTO STDCALL    IsChild PROTO STDCALL    IsDialogMessageW PROTO STDCALL    GetMessageW PROTO STDCALL    LoadAcceleratorsW PROTO STDCALL    CreateWindowExW PROTO STDCALL    MessageBoxW PROTO STDCALL    LoadStringW PROTO STDCALL    SetProcessDefaultLayout PROTO STDCALL    GetProcessDefaultLayout PROTO STDCALLENDIF ; IFNDEF PROXY_USER32_INC
LIBRARY USER32EXPORTS    GetMenu    SetDlgItemInt    GetWindowTextW    CheckDlgButton    HideCaret    CallWindowProcW    DrawTextW    WinHelpW    PostQuitMessage    GetDlgCtrlID    ScreenToClient    ChildWindowFromPoint    DefWindowProcW    IsClipboardFormatAvailable    EnableMenuItem    TrackPopupMenuEx    GetDesktopWindow    OpenClipboard    GetClipboardData    CharNextA    CloseClipboard    GetSysColor    DialogBoxParamW    EndDialog    MessageBeep    GetSubMenu    CheckRadioButton    SetWindowTextW    SetFocus    SetCursor    CharNextW    RegisterClassExW    GetSysColorBrush    LoadCursorW    LoadIconW    InvalidateRect    UpdateWindow    ShowWindow    SendMessageW    SetDlgItemTextW    CheckMenuItem    CheckMenuRadioItem    SetWindowPos    OffsetRect    MapWindowPoints    GetClientRect    EnableWindow    LoadMenuW    SetWindowLongW    GetWindowLongW    CreateDialogParamW    GetDlgItem    DestroyMenu    DestroyWindow    SetMenu    GetWindowRect    SystemParametersInfoW    DispatchMessageW    TranslateMessage    TranslateAcceleratorW    IsChild    IsDialogMessageW    GetMessageW    LoadAcceleratorsW    CreateWindowExW    MessageBoxW    LoadStringW    SetProcessDefaultLayout    GetProcessDefaultLayout
; file name : MyDll.asm.386.model flat, stdcalloption casemap :none   ; case sensitiveinclude windows.incinclude kernel32.incincludelib kernel32.libfnLoadOriginalDll PROTO STDCALL pszOriginalDllName:DWORD.data    g_hOriginalDll DD 0    g_pfn_GetMenu DD 0    g_pfn_SetDlgItemInt DD 0    g_pfn_GetWindowTextW DD 0    g_pfn_CheckDlgButton DD 0    g_pfn_HideCaret DD 0    g_pfn_CallWindowProcW DD 0    g_pfn_DrawTextW DD 0    g_pfn_WinHelpW DD 0    g_pfn_PostQuitMessage DD 0    g_pfn_GetDlgCtrlID DD 0    g_pfn_ScreenToClient DD 0    g_pfn_ChildWindowFromPoint DD 0    g_pfn_DefWindowProcW DD 0    g_pfn_IsClipboardFormatAvailable DD 0    g_pfn_EnableMenuItem DD 0    g_pfn_TrackPopupMenuEx DD 0    g_pfn_GetDesktopWindow DD 0    g_pfn_OpenClipboard DD 0    g_pfn_GetClipboardData DD 0    g_pfn_CharNextA DD 0    g_pfn_CloseClipboard DD 0    g_pfn_GetSysColor DD 0    g_pfn_DialogBoxParamW DD 0    g_pfn_EndDialog DD 0    g_pfn_MessageBeep DD 0    g_pfn_GetSubMenu DD 0    g_pfn_CheckRadioButton DD 0    g_pfn_SetWindowTextW DD 0    g_pfn_SetFocus DD 0    g_pfn_SetCursor DD 0    g_pfn_CharNextW DD 0    g_pfn_RegisterClassExW DD 0    g_pfn_GetSysColorBrush DD 0    g_pfn_LoadCursorW DD 0    g_pfn_LoadIconW DD 0    g_pfn_InvalidateRect DD 0    g_pfn_UpdateWindow DD 0    g_pfn_ShowWindow DD 0    g_pfn_SendMessageW DD 0    g_pfn_SetDlgItemTextW DD 0    g_pfn_CheckMenuItem DD 0    g_pfn_CheckMenuRadioItem DD 0    g_pfn_SetWindowPos DD 0    g_pfn_OffsetRect DD 0    g_pfn_MapWindowPoints DD 0    g_pfn_GetClientRect DD 0    g_pfn_EnableWindow DD 0    g_pfn_LoadMenuW DD 0    g_pfn_SetWindowLongW DD 0    g_pfn_GetWindowLongW DD 0    g_pfn_CreateDialogParamW DD 0    g_pfn_GetDlgItem DD 0    g_pfn_DestroyMenu DD 0    g_pfn_DestroyWindow DD 0    g_pfn_SetMenu DD 0    g_pfn_GetWindowRect DD 0    g_pfn_SystemParametersInfoW DD 0    g_pfn_DispatchMessageW DD 0    g_pfn_TranslateMessage DD 0    g_pfn_TranslateAcceleratorW DD 0    g_pfn_IsChild DD 0    g_pfn_IsDialogMessageW DD 0    g_pfn_GetMessageW DD 0    g_pfn_LoadAcceleratorsW DD 0    g_pfn_CreateWindowExW DD 0    g_pfn_MessageBoxW DD 0    g_pfn_LoadStringW DD 0    g_pfn_SetProcessDefaultLayout DD 0    g_pfn_GetProcessDefaultLayout DD 0 .const    g_szDllName_OriginalDll db 'Org_USER32.dll', 0    g_szFunName_GetMenu db 'GetMenu', 0    g_szFunName_SetDlgItemInt db 'SetDlgItemInt', 0    g_szFunName_GetWindowTextW db 'GetWindowTextW', 0    g_szFunName_CheckDlgButton db 'CheckDlgButton', 0    g_szFunName_HideCaret db 'HideCaret', 0    g_szFunName_CallWindowProcW db 'CallWindowProcW', 0    g_szFunName_DrawTextW db 'DrawTextW', 0    g_szFunName_WinHelpW db 'WinHelpW', 0    g_szFunName_PostQuitMessage db 'PostQuitMessage', 0    g_szFunName_GetDlgCtrlID db 'GetDlgCtrlID', 0    g_szFunName_ScreenToClient db 'ScreenToClient', 0    g_szFunName_ChildWindowFromPoint db 'ChildWindowFromPoint', 0    g_szFunName_DefWindowProcW db 'DefWindowProcW', 0    g_szFunName_IsClipboardFormatAvailable db 'IsClipboardFormatAvailable', 0    g_szFunName_EnableMenuItem db 'EnableMenuItem', 0    g_szFunName_TrackPopupMenuEx db 'TrackPopupMenuEx', 0    g_szFunName_GetDesktopWindow db 'GetDesktopWindow', 0    g_szFunName_OpenClipboard db 'OpenClipboard', 0    g_szFunName_GetClipboardData db 'GetClipboardData', 0    g_szFunName_CharNextA db 'CharNextA', 0    g_szFunName_CloseClipboard db 'CloseClipboard', 0    g_szFunName_GetSysColor db 'GetSysColor', 0    g_szFunName_DialogBoxParamW db 'DialogBoxParamW', 0    g_szFunName_EndDialog db 'EndDialog', 0    g_szFunName_MessageBeep db 'MessageBeep', 0    g_szFunName_GetSubMenu db 'GetSubMenu', 0    g_szFunName_CheckRadioButton db 'CheckRadioButton', 0    g_szFunName_SetWindowTextW db 'SetWindowTextW', 0    g_szFunName_SetFocus db 'SetFocus', 0    g_szFunName_SetCursor db 'SetCursor', 0    g_szFunName_CharNextW db 'CharNextW', 0    g_szFunName_RegisterClassExW db 'RegisterClassExW', 0    g_szFunName_GetSysColorBrush db 'GetSysColorBrush', 0    g_szFunName_LoadCursorW db 'LoadCursorW', 0    g_szFunName_LoadIconW db 'LoadIconW', 0    g_szFunName_InvalidateRect db 'InvalidateRect', 0    g_szFunName_UpdateWindow db 'UpdateWindow', 0    g_szFunName_ShowWindow db 'ShowWindow', 0    g_szFunName_SendMessageW db 'SendMessageW', 0    g_szFunName_SetDlgItemTextW db 'SetDlgItemTextW', 0    g_szFunName_CheckMenuItem db 'CheckMenuItem', 0    g_szFunName_CheckMenuRadioItem db 'CheckMenuRadioItem', 0    g_szFunName_SetWindowPos db 'SetWindowPos', 0    g_szFunName_OffsetRect db 'OffsetRect', 0    g_szFunName_MapWindowPoints db 'MapWindowPoints', 0    g_szFunName_GetClientRect db 'GetClientRect', 0    g_szFunName_EnableWindow db 'EnableWindow', 0    g_szFunName_LoadMenuW db 'LoadMenuW', 0    g_szFunName_SetWindowLongW db 'SetWindowLongW', 0    g_szFunName_GetWindowLongW db 'GetWindowLongW', 0    g_szFunName_CreateDialogParamW db 'CreateDialogParamW', 0    g_szFunName_GetDlgItem db 'GetDlgItem', 0    g_szFunName_DestroyMenu db 'DestroyMenu', 0    g_szFunName_DestroyWindow db 'DestroyWindow', 0    g_szFunName_SetMenu db 'SetMenu', 0    g_szFunName_GetWindowRect db 'GetWindowRect', 0    g_szFunName_SystemParametersInfoW db 'SystemParametersInfoW', 0    g_szFunName_DispatchMessageW db 'DispatchMessageW', 0    g_szFunName_TranslateMessage db 'TranslateMessage', 0    g_szFunName_TranslateAcceleratorW db 'TranslateAcceleratorW', 0    g_szFunName_IsChild db 'IsChild', 0    g_szFunName_IsDialogMessageW db 'IsDialogMessageW', 0    g_szFunName_GetMessageW db 'GetMessageW', 0    g_szFunName_LoadAcceleratorsW db 'LoadAcceleratorsW', 0    g_szFunName_CreateWindowExW db 'CreateWindowExW', 0    g_szFunName_MessageBoxW db 'MessageBoxW', 0    g_szFunName_LoadStringW db 'LoadStringW', 0    g_szFunName_SetProcessDefaultLayout db 'SetProcessDefaultLayout', 0    g_szFunName_GetProcessDefaultLayout db 'GetProcessDefaultLayout', 0.codeLibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD    xor eax, eax    .if reason == DLL_PROCESS_ATTACH        inc eax    .elseif reason == DLL_PROCESS_DETACH        inc eax    .elseif reason == DLL_THREAD_ATTACH        inc eax    .elseif reason == DLL_THREAD_DETACH        inc eax    .endif    retLibMain Endp    ; 代理DLL的API跳转到原始API地址后,由原始API返回, 栈是平的;##########################################################################GetMenu proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetMenu == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetMenu        mov dword ptr g_pfn_GetMenu, eax    .endif    jmp g_pfn_GetMenu    retGetMenu Endp;##########################################################################SetDlgItemInt proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_SetDlgItemInt == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_SetDlgItemInt        mov dword ptr g_pfn_SetDlgItemInt, eax    .endif    jmp g_pfn_SetDlgItemInt    retSetDlgItemInt Endp;##########################################################################GetWindowTextW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetWindowTextW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetWindowTextW        mov dword ptr g_pfn_GetWindowTextW, eax    .endif    jmp g_pfn_GetWindowTextW    retGetWindowTextW Endp;##########################################################################CheckDlgButton proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_CheckDlgButton == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_CheckDlgButton        mov dword ptr g_pfn_CheckDlgButton, eax    .endif    jmp g_pfn_CheckDlgButton    retCheckDlgButton Endp;##########################################################################HideCaret proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_HideCaret == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_HideCaret        mov dword ptr g_pfn_HideCaret, eax    .endif    jmp g_pfn_HideCaret    retHideCaret Endp;##########################################################################CallWindowProcW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_CallWindowProcW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_CallWindowProcW        mov dword ptr g_pfn_CallWindowProcW, eax    .endif    jmp g_pfn_CallWindowProcW    retCallWindowProcW Endp;##########################################################################DrawTextW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_DrawTextW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_DrawTextW        mov dword ptr g_pfn_DrawTextW, eax    .endif    jmp g_pfn_DrawTextW    retDrawTextW Endp;##########################################################################WinHelpW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_WinHelpW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_WinHelpW        mov dword ptr g_pfn_WinHelpW, eax    .endif    jmp g_pfn_WinHelpW    retWinHelpW Endp;##########################################################################PostQuitMessage proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_PostQuitMessage == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_PostQuitMessage        mov dword ptr g_pfn_PostQuitMessage, eax    .endif    jmp g_pfn_PostQuitMessage    retPostQuitMessage Endp;##########################################################################GetDlgCtrlID proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetDlgCtrlID == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetDlgCtrlID        mov dword ptr g_pfn_GetDlgCtrlID, eax    .endif    jmp g_pfn_GetDlgCtrlID    retGetDlgCtrlID Endp;##########################################################################ScreenToClient proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_ScreenToClient == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_ScreenToClient        mov dword ptr g_pfn_ScreenToClient, eax    .endif    jmp g_pfn_ScreenToClient    retScreenToClient Endp;##########################################################################ChildWindowFromPoint proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_ChildWindowFromPoint == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_ChildWindowFromPoint        mov dword ptr g_pfn_ChildWindowFromPoint, eax    .endif    jmp g_pfn_ChildWindowFromPoint    retChildWindowFromPoint Endp;##########################################################################DefWindowProcW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_DefWindowProcW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_DefWindowProcW        mov dword ptr g_pfn_DefWindowProcW, eax    .endif    jmp g_pfn_DefWindowProcW    retDefWindowProcW Endp;##########################################################################IsClipboardFormatAvailable proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_IsClipboardFormatAvailable == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_IsClipboardFormatAvailable        mov dword ptr g_pfn_IsClipboardFormatAvailable, eax    .endif    jmp g_pfn_IsClipboardFormatAvailable    retIsClipboardFormatAvailable Endp;##########################################################################EnableMenuItem proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_EnableMenuItem == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_EnableMenuItem        mov dword ptr g_pfn_EnableMenuItem, eax    .endif    jmp g_pfn_EnableMenuItem    retEnableMenuItem Endp;##########################################################################TrackPopupMenuEx proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_TrackPopupMenuEx == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_TrackPopupMenuEx        mov dword ptr g_pfn_TrackPopupMenuEx, eax    .endif    jmp g_pfn_TrackPopupMenuEx    retTrackPopupMenuEx Endp;##########################################################################GetDesktopWindow proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetDesktopWindow == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetDesktopWindow        mov dword ptr g_pfn_GetDesktopWindow, eax    .endif    jmp g_pfn_GetDesktopWindow    retGetDesktopWindow Endp;##########################################################################OpenClipboard proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_OpenClipboard == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_OpenClipboard        mov dword ptr g_pfn_OpenClipboard, eax    .endif    jmp g_pfn_OpenClipboard    retOpenClipboard Endp;##########################################################################GetClipboardData proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetClipboardData == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetClipboardData        mov dword ptr g_pfn_GetClipboardData, eax    .endif    jmp g_pfn_GetClipboardData    retGetClipboardData Endp;##########################################################################CharNextA proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_CharNextA == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_CharNextA        mov dword ptr g_pfn_CharNextA, eax    .endif    jmp g_pfn_CharNextA    retCharNextA Endp;##########################################################################CloseClipboard proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_CloseClipboard == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_CloseClipboard        mov dword ptr g_pfn_CloseClipboard, eax    .endif    jmp g_pfn_CloseClipboard    retCloseClipboard Endp;##########################################################################GetSysColor proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetSysColor == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetSysColor        mov dword ptr g_pfn_GetSysColor, eax    .endif    jmp g_pfn_GetSysColor    retGetSysColor Endp;##########################################################################DialogBoxParamW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_DialogBoxParamW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_DialogBoxParamW        mov dword ptr g_pfn_DialogBoxParamW, eax    .endif    jmp g_pfn_DialogBoxParamW    retDialogBoxParamW Endp;##########################################################################EndDialog proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_EndDialog == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_EndDialog        mov dword ptr g_pfn_EndDialog, eax    .endif    jmp g_pfn_EndDialog    retEndDialog Endp;##########################################################################MessageBeep proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_MessageBeep == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_MessageBeep        mov dword ptr g_pfn_MessageBeep, eax    .endif    jmp g_pfn_MessageBeep    retMessageBeep Endp;##########################################################################GetSubMenu proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetSubMenu == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetSubMenu        mov dword ptr g_pfn_GetSubMenu, eax    .endif    jmp g_pfn_GetSubMenu    retGetSubMenu Endp;##########################################################################CheckRadioButton proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_CheckRadioButton == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_CheckRadioButton        mov dword ptr g_pfn_CheckRadioButton, eax    .endif    jmp g_pfn_CheckRadioButton    retCheckRadioButton Endp;##########################################################################SetWindowTextW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_SetWindowTextW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_SetWindowTextW        mov dword ptr g_pfn_SetWindowTextW, eax    .endif    jmp g_pfn_SetWindowTextW    retSetWindowTextW Endp;##########################################################################SetFocus proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_SetFocus == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_SetFocus        mov dword ptr g_pfn_SetFocus, eax    .endif    jmp g_pfn_SetFocus    retSetFocus Endp;##########################################################################SetCursor proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_SetCursor == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_SetCursor        mov dword ptr g_pfn_SetCursor, eax    .endif    jmp g_pfn_SetCursor    retSetCursor Endp;##########################################################################CharNextW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_CharNextW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_CharNextW        mov dword ptr g_pfn_CharNextW, eax    .endif    jmp g_pfn_CharNextW    retCharNextW Endp;##########################################################################RegisterClassExW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_RegisterClassExW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_RegisterClassExW        mov dword ptr g_pfn_RegisterClassExW, eax    .endif    jmp g_pfn_RegisterClassExW    retRegisterClassExW Endp;##########################################################################GetSysColorBrush proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetSysColorBrush == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetSysColorBrush        mov dword ptr g_pfn_GetSysColorBrush, eax    .endif    jmp g_pfn_GetSysColorBrush    retGetSysColorBrush Endp;##########################################################################LoadCursorW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_LoadCursorW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_LoadCursorW        mov dword ptr g_pfn_LoadCursorW, eax    .endif    jmp g_pfn_LoadCursorW    retLoadCursorW Endp;##########################################################################LoadIconW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_LoadIconW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_LoadIconW        mov dword ptr g_pfn_LoadIconW, eax    .endif    jmp g_pfn_LoadIconW    retLoadIconW Endp;##########################################################################InvalidateRect proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_InvalidateRect == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_InvalidateRect        mov dword ptr g_pfn_InvalidateRect, eax    .endif    jmp g_pfn_InvalidateRect    retInvalidateRect Endp;##########################################################################UpdateWindow proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_UpdateWindow == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_UpdateWindow        mov dword ptr g_pfn_UpdateWindow, eax    .endif    jmp g_pfn_UpdateWindow    retUpdateWindow Endp;##########################################################################ShowWindow proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_ShowWindow == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_ShowWindow        mov dword ptr g_pfn_ShowWindow, eax    .endif    jmp g_pfn_ShowWindow    retShowWindow Endp;##########################################################################SendMessageW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_SendMessageW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_SendMessageW        mov dword ptr g_pfn_SendMessageW, eax    .endif    jmp g_pfn_SendMessageW    retSendMessageW Endp;##########################################################################SetDlgItemTextW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_SetDlgItemTextW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_SetDlgItemTextW        mov dword ptr g_pfn_SetDlgItemTextW, eax    .endif    jmp g_pfn_SetDlgItemTextW    retSetDlgItemTextW Endp;##########################################################################CheckMenuItem proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_CheckMenuItem == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_CheckMenuItem        mov dword ptr g_pfn_CheckMenuItem, eax    .endif    jmp g_pfn_CheckMenuItem    retCheckMenuItem Endp;##########################################################################CheckMenuRadioItem proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_CheckMenuRadioItem == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_CheckMenuRadioItem        mov dword ptr g_pfn_CheckMenuRadioItem, eax    .endif    jmp g_pfn_CheckMenuRadioItem    retCheckMenuRadioItem Endp;##########################################################################SetWindowPos proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_SetWindowPos == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_SetWindowPos        mov dword ptr g_pfn_SetWindowPos, eax    .endif    jmp g_pfn_SetWindowPos    retSetWindowPos Endp;##########################################################################OffsetRect proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_OffsetRect == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_OffsetRect        mov dword ptr g_pfn_OffsetRect, eax    .endif    jmp g_pfn_OffsetRect    retOffsetRect Endp;##########################################################################MapWindowPoints proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_MapWindowPoints == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_MapWindowPoints        mov dword ptr g_pfn_MapWindowPoints, eax    .endif    jmp g_pfn_MapWindowPoints    retMapWindowPoints Endp;##########################################################################GetClientRect proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetClientRect == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetClientRect        mov dword ptr g_pfn_GetClientRect, eax    .endif    jmp g_pfn_GetClientRect    retGetClientRect Endp;##########################################################################EnableWindow proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_EnableWindow == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_EnableWindow        mov dword ptr g_pfn_EnableWindow, eax    .endif    jmp g_pfn_EnableWindow    retEnableWindow Endp;##########################################################################LoadMenuW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_LoadMenuW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_LoadMenuW        mov dword ptr g_pfn_LoadMenuW, eax    .endif    jmp g_pfn_LoadMenuW    retLoadMenuW Endp;##########################################################################SetWindowLongW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_SetWindowLongW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_SetWindowLongW        mov dword ptr g_pfn_SetWindowLongW, eax    .endif    jmp g_pfn_SetWindowLongW    retSetWindowLongW Endp;##########################################################################GetWindowLongW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetWindowLongW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetWindowLongW        mov dword ptr g_pfn_GetWindowLongW, eax    .endif    jmp g_pfn_GetWindowLongW    retGetWindowLongW Endp;##########################################################################CreateDialogParamW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_CreateDialogParamW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_CreateDialogParamW        mov dword ptr g_pfn_CreateDialogParamW, eax    .endif    jmp g_pfn_CreateDialogParamW    retCreateDialogParamW Endp;##########################################################################GetDlgItem proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetDlgItem == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetDlgItem        mov dword ptr g_pfn_GetDlgItem, eax    .endif    jmp g_pfn_GetDlgItem    retGetDlgItem Endp;##########################################################################DestroyMenu proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_DestroyMenu == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_DestroyMenu        mov dword ptr g_pfn_DestroyMenu, eax    .endif    jmp g_pfn_DestroyMenu    retDestroyMenu Endp;##########################################################################DestroyWindow proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_DestroyWindow == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_DestroyWindow        mov dword ptr g_pfn_DestroyWindow, eax    .endif    jmp g_pfn_DestroyWindow    retDestroyWindow Endp;##########################################################################SetMenu proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_SetMenu == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_SetMenu        mov dword ptr g_pfn_SetMenu, eax    .endif    jmp g_pfn_SetMenu    retSetMenu Endp;##########################################################################GetWindowRect proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetWindowRect == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetWindowRect        mov dword ptr g_pfn_GetWindowRect, eax    .endif    jmp g_pfn_GetWindowRect    retGetWindowRect Endp;##########################################################################SystemParametersInfoW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_SystemParametersInfoW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_SystemParametersInfoW        mov dword ptr g_pfn_SystemParametersInfoW, eax    .endif    jmp g_pfn_SystemParametersInfoW    retSystemParametersInfoW Endp;##########################################################################DispatchMessageW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_DispatchMessageW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_DispatchMessageW        mov dword ptr g_pfn_DispatchMessageW, eax    .endif    jmp g_pfn_DispatchMessageW    retDispatchMessageW Endp;##########################################################################TranslateMessage proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_TranslateMessage == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_TranslateMessage        mov dword ptr g_pfn_TranslateMessage, eax    .endif    jmp g_pfn_TranslateMessage    retTranslateMessage Endp;##########################################################################TranslateAcceleratorW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_TranslateAcceleratorW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_TranslateAcceleratorW        mov dword ptr g_pfn_TranslateAcceleratorW, eax    .endif    jmp g_pfn_TranslateAcceleratorW    retTranslateAcceleratorW Endp;##########################################################################IsChild proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_IsChild == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_IsChild        mov dword ptr g_pfn_IsChild, eax    .endif    jmp g_pfn_IsChild    retIsChild Endp;##########################################################################IsDialogMessageW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_IsDialogMessageW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_IsDialogMessageW        mov dword ptr g_pfn_IsDialogMessageW, eax    .endif    jmp g_pfn_IsDialogMessageW    retIsDialogMessageW Endp;##########################################################################GetMessageW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetMessageW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetMessageW        mov dword ptr g_pfn_GetMessageW, eax    .endif    jmp g_pfn_GetMessageW    retGetMessageW Endp;##########################################################################LoadAcceleratorsW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_LoadAcceleratorsW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_LoadAcceleratorsW        mov dword ptr g_pfn_LoadAcceleratorsW, eax    .endif    jmp g_pfn_LoadAcceleratorsW    retLoadAcceleratorsW Endp;##########################################################################CreateWindowExW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_CreateWindowExW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_CreateWindowExW        mov dword ptr g_pfn_CreateWindowExW, eax    .endif    jmp g_pfn_CreateWindowExW    retCreateWindowExW Endp;##########################################################################MessageBoxW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_MessageBoxW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_MessageBoxW        mov dword ptr g_pfn_MessageBoxW, eax    .endif    jmp g_pfn_MessageBoxW    retMessageBoxW Endp;##########################################################################LoadStringW proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_LoadStringW == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_LoadStringW        mov dword ptr g_pfn_LoadStringW, eax    .endif    jmp g_pfn_LoadStringW    retLoadStringW Endp;##########################################################################SetProcessDefaultLayout proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_SetProcessDefaultLayout == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_SetProcessDefaultLayout        mov dword ptr g_pfn_SetProcessDefaultLayout, eax    .endif    jmp g_pfn_SetProcessDefaultLayout    retSetProcessDefaultLayout Endp;##########################################################################GetProcessDefaultLayout proc    .if (g_hOriginalDll == NULL)        invoke fnLoadOriginalDll, offset g_szDllName_OriginalDll    .endif    .if (g_pfn_GetProcessDefaultLayout == NULL)        invoke GetProcAddress, g_hOriginalDll, offset g_szFunName_GetProcessDefaultLayout        mov dword ptr g_pfn_GetProcessDefaultLayout, eax    .endif    jmp g_pfn_GetProcessDefaultLayout    retGetProcessDefaultLayout EndpfnLoadOriginalDll proc STDCALL pszOriginalDllName:DWORD    invoke LoadLibraryA, pszOriginalDllName    mov dword ptr g_hOriginalDll, eax    retfnLoadOriginalDll endpEnd LibMain

生成的源代码编译效果

这里写图片描述

0 0
原创粉丝点击