Registry Functions M-Asm (snippet)

This article has been written before more than 24months, information might old.

M am gandit sa imi public unele din sinppeturile mele poate va ajuta , acest snippet contine cateva protos ( proceduri (functii pentru cei care „vin” din c si altceva bazat pe c ) ) legate de registry ( windows de la 98 pana la windows 7 ar trebui sa functioneze )

Snippet :


.486                      ; force 32 bit code
.model flat, stdcall      ; memory model & calling convention
option casemap :none      ; case sensitive

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc
include \masm32\include\advapi32.inc
include \masm32\include\gdi32.inc
include \masm32\include\comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\masm32.inc
include \masm32\include\ole32.inc
include \masm32\macros\macros.asm

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\advapi32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\masm32.lib


SetRegString    	PROTO :dword, :dword, :dword, :dword
GetRegString    	PROTO :dword, :dword, :dword, :dword
SetRegDword     	PROTO :dword, :dword, :dword, :dword
GetRegDword     	PROTO :dword, :dword, :dword, :dword
Reg_Delete_Value 	PROTO :dword, :dword, :dword

.code
align 4
SetRegString  proc reg_HKEY:dword, lpszKeyName:dword, lpszValueName:dword, lpszString:dword
    local Disp: dword
    local pKey: dword
    local dwSize: dword
    invoke RegCreateKeyEx, reg_HKEY,
        lpszKeyName, NULL, NULL, 
        REG_OPTION_NON_VOLATILE, 
        KEY_ALL_ACCESS, NULL,
        addr pKey, addr Disp
    .if eax == ERROR_SUCCESS
        invoke lstrlen, lpszString
        mov dwSize, eax
        invoke RegSetValueEx, pKey, lpszValueName, 
            NULL, REG_SZ, 
            lpszString, dwSize 
        push eax
        invoke RegCloseKey, pKey
        pop eax
    .endif
    ret
SetRegString endp

align 4
Reg_Delete_Value  proc reg_HKEY:dword, lpszKeyName:dword, lpszValueName:dword
    local Disp: dword
    local pKey: dword
    invoke RegCreateKeyEx, reg_HKEY,
        lpszKeyName, NULL, NULL, 
        REG_OPTION_NON_VOLATILE, 
        KEY_ALL_ACCESS, NULL,
        addr pKey, addr Disp
    .if eax == ERROR_SUCCESS
        invoke RegDeleteValue,pKey,lpszValueName
        push eax
        invoke RegCloseKey, pKey
        pop eax
    .endif
    ret
Reg_Delete_Value endp

align 4
GetRegString proc lpszBuffer:dword, reg_HKEY:dword, lpszKeyName:dword, lpszValueName:dword
    local TType: dword
    local pKey: dword
    local dwSize: dword
    mov TType, REG_SZ
    invoke RegOpenKey, reg_HKEY, lpszKeyName, addr pKey
    invoke RegQueryValueEx, pKey, lpszValueName, NULL, NULL, NULL, addr dwSize
    invoke RegCreateKeyEx, reg_HKEY, lpszKeyName, NULL, NULL, REG_OPTION_NON_VOLATILE, 
        KEY_ALL_ACCESS, NULL, addr pKey, addr TType
    .if eax == ERROR_SUCCESS
        mov eax, REG_DWORD
        mov TType, eax
        inc dwSize
        invoke RegQueryValueEx, pKey, lpszValueName, 
            NULL, addr TType, 
            lpszBuffer, addr dwSize
        push eax
        invoke RegCloseKey, pKey
        pop eax
    .endif
    ret
GetRegString endp

align 4
SetRegDword proc reg_HKEY:dword, lpszKeyName:dword, lpszValueName:dword, lpdwValue:dword
    local Disp: dword
    local pKey: dword
    local dwValue: dword
    push lpdwValue
    pop dwValue
    DW_SIZE equ 4
    invoke RegCreateKeyEx, reg_HKEY,
        lpszKeyName, NULL, NULL, 
        REG_OPTION_NON_VOLATILE, 
        KEY_ALL_ACCESS, NULL,
        addr pKey, addr Disp
    .if eax == ERROR_SUCCESS
        invoke RegSetValueEx, pKey, lpszValueName, 
        NULL, REG_DWORD_LITTLE_ENDIAN, 
        addr dwValue, DW_SIZE
        push eax
        invoke RegCloseKey, pKey
        pop eax
    .endif
    ret
SetRegDword endp

align 4
GetRegDword proc reg_HKEY:dword, lpszKeyName:dword, lpszValueName:dword, lpdwValue:dword
    local Temp: dword
    local pKey: dword
    local DWordSize: dword
    DW_SIZE EQU 4
    mov DWordSize, DW_SIZE
    invoke RegCreateKeyEx, reg_HKEY, 
        lpszKeyName, NULL, NULL, 
        REG_OPTION_NON_VOLATILE, 
        KEY_ALL_ACCESS, NULL,
        addr pKey, addr Temp
    .if eax == ERROR_SUCCESS
        mov eax, REG_DWORD
        mov Temp, eax
        invoke RegQueryValueEx, pKey, lpszValueName, 
            NULL, addr Temp, 
            lpdwValue, addr DWordSize 
        push eax
        invoke RegCloseKey, pKey
        pop eax
    .endif
    ret
GetRegDword endp

end
Share the joy

Leave a Reply