Etichetă: assembly

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, 
        

Fix Faild to load SDCzip.dll

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

Am scris un fix pentru erroarea ” Faild to load SDCzip.dll ” ce apare uneori la Stardock IconPackager , il putei downloada de aici : http://fix-faild-to-load-sdczip-stardock.googlecode.com/files/FixForStardock.exe , codul sursa il gasiti la adresa http://code.google.com/p/fix-faild-to-load-sdczip-stardock/downloads/list este compatibil cu EasyCoder Ide , nu este pure asm dar poate fi transformat , relativ usor insa codul ar fi mult mai amplu , mai jos este un preview al codului care nu poate fi compilabil , daca veti sa il compilati descarcati sursa ..

Ps : sper ca nu se simte nimeni ofensat de icontia natzi … , trebuie sa recunoasteti ca e un design destul de reusit ….

Code :

.Const

.Data?
;dll
hMIDIres DD ?  ;
hMIDISize DD ?   ;
hMIDIdevID DD ?  ;
numchar DD ?
;dll


;path
szfolder DB ?
szstardf DB ?
szdllfpath DB ?

;path

.Data

lsta DB " Geting the path to 0X0026commun files ... " , 0
lstb DB " Creating necessary directory ... " , 0
lstc DB " Writing registry  ... " 

Video tutoriale assembly

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

Am gasit pe net mai demult cateva tutoriale video assembly , si asa ceva e foarte rar , tutoriale text se gasesc la greu , dar eu intodeauna le am preferat pe cele video in fata celor text si nu cred ca sunt eu singurul , bine sincer sa fiu cine stie ce nu o sa reusiti sa asimilati de aici dar , o buna idee daca vreti sa faceti o aplicatie care sa aiba si UI ( user interface ) ar fi sa luati de pe net EsayCode e un ide pentru masm e mult mai usor sa le scrii intr-un ide decat intr-un text editor nici eu nu pot sa zic ca fac cine stie ce in asm , dar ca idee nu uitati ctrl+space ca sa va arate ide-ul functile din api-ul windowsului , ar trebui sa descarcati de pe net si chm-ul pt api-urile windows ala foarte vechi nu stiu acum nu mai este sub dezvoltare s-a inlocuit cu msdn …

Maine sau poimaine …