⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reg_demo.asm

📁 一个非常简单的注册表操作示例 程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
               dec     eax
            INVOKE     SendMessage, hREdit, EM_SETSEL, 0, eax
               mov     charF.crTextColor, 000000ffh
            INVOKE     SendMessage,  hREdit, EM_SETCHARFORMAT, SCF_SELECTION, addr charF
            INVOKE     SendMessage, hREdit, EM_LINEINDEX, Line, 0
               dec     eax
            INVOKE     SendMessage, hREdit, EM_SETSEL, eax, -1
               mov     charF.crTextColor, 0000ff00h
            INVOKE     SendMessage,  hREdit, EM_SETCHARFORMAT, SCF_SELECTION, addr charF
            INVOKE     SendMessage, hREdit, EM_SETSEL, 0, 0
            INVOKE     SendMessage, hREdit, EM_HIDESELECTION, 0, 0

            .if Step == 1
                  jmp     CreateKey
            .elseif Step == 2
                  jmp     OpenKey
            .elseif Step == 3
                  jmp     SetDword
            .elseif Step == 4
                  jmp     GetDword
            .elseif Step == 5
                  jmp     SetString
            .elseif Step == 6
                  jmp     GetString
            .elseif Step == 7
                  jmp     SetBinary
            .elseif Step == 8
                  jmp     GetBinary
            .elseif Step == 9
                  jmp     GetNumber
            .elseif Step == 10
                  jmp     GetLength
            .elseif Step == 11
                  jmp     CreateSubKey
            .elseif Step == 12
                  jmp     SetStrings
            .elseif Step == 13
                  jmp     Enumerate
            .elseif Step == 14
                  jmp     DeleteSubkey
            .elseif Step == 15
                  jmp     CloseSubkey
            .elseif Step == 16
                  jmp     Deletekey
            .elseif Step == 17
                  jmp     Closekey
            .elseif Step == 18
               INVOKE     SendMessage, hButt1, WM_SETTEXT, 0, addr szButt1
               INVOKE     ShowWindow, hButt2, SW_HIDE
               INVOKE     GetPrivateProfileString, addr szInfo, addr szInfoT, addr szNULL, addr szBuff, 255, addr CurDir
               INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, addr szBuff
               INVOKE     MessageBox, NULL, addr szAgain, addr AppName, MB_YESNO
               .if eax == IDNO
                  INVOKE     SendMessage, hWnd, WM_COMMAND, IDM_EXIT, 0
               .endif
                  and     Step, 0
                  jmp     Ret0
            .endif
         .elseif eax == IDM_EXIT
            INVOKE     DestroyWindow, hwnd
         .endif

      .else

DefWin:
         INVOKE     DefWindowProc, hwnd, wMsg, wParam, lParam
            ret
      .endif
         jmp     Ret0

CreateKey:
;---------- [Open or create a registry key] ---------- 
      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szTestKey, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hKey, addr lpdwDisp
      .if eax == ERROR_SUCCESS
            jmp     Closekey
      .else
      .endif
         jmp     Ret0

OpenKey:
;---------- [Open an existing registry key] ---------- 
      INVOKE     RegOpenKeyEx, HKEY_CURRENT_USER, addr szTestKey, 0,\
                 KEY_WRITE or KEY_READ, addr hKey
      .if eax == ERROR_SUCCESS
      .else
      .endif
         jmp     Ret0

SetDword:
;---------- [Set a dword value to the registry key] ---------- 
         mov     lpcbData, 4
      INVOKE     RegSetValueEx, hKey, addr szHandle, 0, REG_DWORD, addr hwnd, lpcbData
      .if eax == ERROR_SUCCESS
      .else
      .endif
         jmp     Ret0

GetDword:
;---------- [Get a dword value from the registry key] ---------- 
         mov     lpcbData, 4
      INVOKE     RegQueryValueEx, hKey, addr szHandle, 0, addr lpType, addr DecVal, addr lpcbData
      .if eax == ERROR_SUCCESS
         INVOKE     wsprintf, addr szBuff1, addr fmat2, DecVal
         INVOKE     SendMessage, hREdit, EM_GETLINECOUNT, 0, 0
            mov     Line, eax
         INVOKE     SendMessage, hREdit, EM_LINEINDEX, Line, 0
            dec     eax
         INVOKE     SendMessage, hREdit, EM_SETSEL, eax, -1
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff1
      .else
      .endif
         jmp     Ret0

SetString:
;---------- [Set a string value to the registry key] ---------- 
      INVOKE     lstrlen, addr szDay
         mov     lpcbData, eax
      INVOKE     RegSetValueEx, hKey, addr szDayName, 0, REG_SZ, addr szDay, lpcbData
      .if eax == ERROR_SUCCESS
      .else
      .endif
         jmp     Ret0

GetString:
;---------- [Get a string value from the registry key] ---------- 
         mov     lpcbData, 250
      INVOKE     RegQueryValueEx, hKey, addr szDayName, 0, addr szREGSZ, addr szBuff, addr lpcbData
      .if eax == ERROR_SUCCESS
         INVOKE     SendMessage, hREdit, EM_GETLINECOUNT, 0, 0
            mov     Line, eax
         INVOKE     SendMessage, hREdit, EM_LINEINDEX, Line, 0
            dec     eax
         INVOKE     SendMessage, hREdit, EM_SETSEL, eax, -1
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff
      .else
      .endif
         jmp     Ret0

SetBinary:
;---------- [Set a binary value to the registry key] ----------
         mov     eax, hwnd
         mov     dword ptr BinVal, eax
         add     eax, 44
         mov     dword ptr BinVal+3, eax
         add     eax, 999
         mov     word ptr BinVal+7, ax

         mov     lpcbData, 10
      INVOKE     RegSetValueEx, hKey, addr szBinary, 0, REG_BINARY, addr BinVal, lpcbData  ;hwnd
      .if eax == ERROR_SUCCESS

      .else
      .endif
         jmp     Ret0

GetBinary:
;---------- [Get a binary value from the registry key] ---------- 
         mov     lpcbData, 10
      INVOKE     RegQueryValueEx, hKey, addr szBinary, 0, addr lpType, addr szBuff, addr lpcbData
      .if eax == ERROR_SUCCESS
            mov     byte ptr szBuff2, 0
            and     Cnt, 0
         .while (Cnt < 10)
               xor     edx, edx
               mov     eax, Cnt
               mov     dl, byte ptr szBuff[eax]
            INVOKE     wsprintf, addr szBuff1, addr fmatH2, edx
            INVOKE     lstrcat, addr szBuff2, addr szBuff1
            .if Cnt < 9
               INVOKE     lstrcat, addr szBuff2, addr szSpace
            .endif
               inc     Cnt
         .endw
         INVOKE     SendMessage, hREdit, EM_GETLINECOUNT, 0, 0
            mov     Line, eax
         INVOKE     SendMessage, hREdit, EM_LINEINDEX, Line, 0
            dec     eax
         INVOKE     SendMessage, hREdit, EM_SETSEL, eax, -1
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff2

      .else
      .endif
         jmp     Ret0

GetNumber:
;---------- [Get the number of value entries in the registry key] ---------- 
      INVOKE     RegQueryInfoKey, hKey, 0, 0, 0, 0, 0, 0, addr lpcValues, 0, 0, 0, 0
      .if eax == ERROR_SUCCESS
         INVOKE     wsprintf, addr szBuff1, addr fmat2, lpcValues
         INVOKE     SendMessage, hREdit, EM_GETLINECOUNT, 0, 0
            mov     Line, eax
         INVOKE     SendMessage, hREdit, EM_LINEINDEX, Line, 0
            dec     eax
         INVOKE     SendMessage, hREdit, EM_SETSEL, eax, -1
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff1
      .else
      .endif
         jmp     Ret0

GetLength:
;---------- [Get  the longest value data length in the registry key] ---------- 
      INVOKE     RegQueryInfoKey, hKey, 0, 0, 0, 0, 0, 0, 0, 0, addr lpcbMaxValueLen, 0,0
      .if eax == ERROR_SUCCESS
         INVOKE     wsprintf, addr szBuff1, addr fmat2, lpcbMaxValueLen
         INVOKE     SendMessage, hREdit, EM_GETLINECOUNT, 0, 0
            mov     Line, eax
         INVOKE     SendMessage, hREdit, EM_LINEINDEX, Line, 0
            dec     eax
         INVOKE     SendMessage, hREdit, EM_SETSEL, eax, -1
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff1
      .else
      .endif
         jmp     Ret0

CreateSubKey:
;---------- [Open or create a registry Subkey] ---------- 
      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szSubKey, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hKeyS, addr lpdwDisp
      .if eax == ERROR_SUCCESS
      .else
      .endif
         jmp     Ret0

SetStrings:
;---------- [Set four string values to the registry Subkey] ----------
         mov     Cnt, 0
      .while (Cnt < 4)
            inc     Cnt
         INVOKE     wsprintf, addr szBuff1, addr fmat2, Cnt
            mov     ax, word ptr szBuff1
            mov     word ptr szItem+6, ax
            mov     word ptr szItemT+5, ax
         INVOKE     lstrlen, addr szItemT
            mov     lpcbData, eax
         INVOKE     RegSetValueEx, hKeyS, addr szItem, 0, REG_SZ, addr szItemT, lpcbData
         .if eax == ERROR_SUCCESS
         .else
         .endif
      .endw
         jmp     Ret0

Enumerate:
;---------- [Enumerate the registry Subkey] ----------
         mov     byte ptr szBuff, 0
         mov     lpcValues, 4
         mov     Cnt, 0
      .while lpcValues   
            dec     lpcValues
            mov     lpcbValueName, 8
            mov     lpcbData, 25
         INVOKE     RegEnumValue, hKeyS, Cnt, addr szBuff1, addr lpcbValueName, 0, addr szREGSZ, addr szBuff2, addr lpcbData
         .if eax == ERROR_NO_MORE_ITEMS
               jmp     NoMore
         .endif
            inc     Cnt
         INVOKE     lstrcat, addr szBuff, addr szBuff2
         INVOKE     lstrcat, addr szBuff, addr szCRLF+2
      .endw

NoMore:
         INVOKE     SendMessage, hREdit, EM_GETLINECOUNT, 0, 0
            mov     Line, eax
         INVOKE     SendMessage, hREdit, EM_LINEINDEX, Line, 0
            dec     eax
         INVOKE     SendMessage, hREdit, EM_SETSEL, eax, -1
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff
         jmp     Ret0

DeleteSubkey:
;---------- [Delete the registry Subkey] ---------- 
      INVOKE     RegDeleteKey, HKEY_CURRENT_USER, addr szSubKey
      .if eax == ERROR_SUCCESS
      .else
      .endif

CloseSubkey:
;---------- [Close the registry Subkey] ----------
      INVOKE     RegCloseKey, hKeyS
      .if eax == ERROR_SUCCESS
      .else
      .endif
         jmp     Ret0

Deletekey:
;---------- [Delete the registry key] ---------- 
      INVOKE     RegDeleteKey, HKEY_CURRENT_USER, addr szTestKey
         jmp     Ret0

Closekey:
;---------- [Close the registry key] ---------- 
      INVOKE     RegCloseKey, hKey
         jmp     Ret0

Ret0:
         xor    eax, eax
         ret
WndProc ENDP

;________________________________________________________________________________
GetCode PROC

         INVOKE     GetPrivateProfileString, addr szBuff1, addr szBuff2, addr szNULL, addr szBuff, 255, addr CurDir
         INVOKE     lstrlen, addr szBuff
         .while (eax)
            .if byte ptr szBuff[eax] == '>'
                  mov     byte ptr szBuff[eax], 0ah
            .elseif byte ptr szBuff[eax] == '<'
                  mov     byte ptr szBuff[eax], 0dh
            .endif
               dec     eax
         .endw

Ret0:
         xor    eax, eax
         ret
GetCode ENDP

;________________________________________________________________________________
BuildEM PROC
      INVOKE     lstrcat, pMem, edx
         ret
BuildEM ENDP

end start
;INVOKE     MessageBox, NULL, addr szBuff, addr AppName, MB_OK

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -