Etichetă: asm

Snippet StrLen Asm

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

Avem in windows functia lstrlen , dar lstrlen nu reda marimea in format numeric , asa ca trebuie transformat in ascii de prefeinta , putem face asta cu functia dwtoa care se afla in masm32.lib dar decat sa folosim 2 functii ca sa facem una putem folosi functia de mai jos :

StrLen proc pStr:DWORD
	mov eax,[esp+1*4]                  ; get pointer to string
	mov edx,eax
	xor ecx,ecx
@@:                                    
	test al,3                        
	jz @F                            
	mov cl,[eax]                     
	inc eax                          
	test cl,cl                       
	jnz @B                           
	sub cl,1
	jmp @1
@@:                                    
	mov edx,[eax]                      ; read first 4 bytes
	add eax,4                          ; increment pointer
	lea ecx,[edx-01010101h]            ; subtract 1 from each byte
	xor edx,-1                         ; invert all bytes
	and ecx,edx                        ; and these two
	and ecx,80808080h                  ; test all sign bits
	jz @B                              ; no zero bytes, continue loop
	mov edx,[esp+1*4]                  ; get pointer to string
	add edx,3                          ; pointer+3
	test ecx,00008080h                 ; test first two bytes
	jnz @F                           
	shr ecx,16                         ; not in the first 2 bytes
	add eax,2                        
@@:
	shl cl,1                           ; use carry 

Embedded File in Exe Asm

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

Un mic exemplu pentru a extrage o resursa inglobata intr-un exe , exemplul este simbolic nu poate fi compliat caci este o bucata dintr-un cod-sursa al unui executabil , dar poate va desluseste ce functii ati putea folosi pentru a face acest lucru exemplu mai jos :

Invoke  FindResource, NULL, ZIPDLL, RT_FILEDATA
Mov hMIDIres, Eax ;
Invoke GetWindowItem, [hWnd], IDC_WMAIN_LSTE
Invoke SetText, Eax, Addr lste
Invoke GetWindowItem, [hWnd], IDC_WMAIN_PGB
Invoke SetValue, Eax, 70
Invoke Sleep, 2500
Invoke SizeofResource, NULL, hMIDIres ;
Mov hMIDISize, Eax ;
Invoke LoadResource, NULL, hMIDIres ;
Invoke LockResource, Eax
Mov hMIDIres, Eax
Invoke GetWindowItem, [hWnd], IDC_WMAIN_LSTF
Invoke SetText, Eax, Addr lstf
Invoke GetWindowItem, [hWnd], IDC_WMAIN_PGB
Invoke SetValue, Eax, 85
Invoke Sleep, 2500
Invoke CreateFile, Addr szdllfpath, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, 0
Mov Ebx, Eax
Invoke WriteFile, Ebx, hMIDIres, hMIDISize, Addr numchar, 0 ;
Invoke CloseHandle, Ebx
Invoke GetWindowItem, [hWnd], IDC_WMAIN_LSTG
Invoke SetText, Eax, Addr lstg
Invoke GetWindowItem, [hWnd], IDC_WMAIN_PGB
Invoke SetValue, Eax, 100

De functile SetValue , Getwindowitem , SetText , si Sleep …

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,