Some FASM help...
Posted: Sun Aug 06, 2006 2:55 am
I've been looking for some help with FASM, I've asked about on the forums there and some people have been very handy, but I'll feel a bit guilty if I post *again*.
What I'm trying to do is introduce a string handling system (for use with my compiler project) which'll automatically increase the size of the memory buffer allocated for the string if nessacary.
I've been given these two lots of code. The first will automatically resize the buffer to fit the incomming string:
The second will add two strings together, but won't actually increase the size of the memory buffer.
What I really need is something that does both; adds strings together and increases the memory buffer on the fly.
It's quite a lot to as for help with, but it'd be greatly appreciated!
What I'm trying to do is introduce a string handling system (for use with my compiler project) which'll automatically increase the size of the memory buffer allocated for the string if nessacary.
I've been given these two lots of code. The first will automatically resize the buffer to fit the incomming string:
Code: Select all
format PE GUI 4.0
include 'win32a.inc'
entry $
push 0
push 0
push 0
call [HeapCreate]
mov [hHeap], eax
push [dwBufferSize]
push 0x08 ;HEAP_ZERO_MEMORY
push [hHeap]
call [HeapAlloc]
mov [pBuffer], eax
;______________________________________
cld
mov esi, pString
mov edi, [pBuffer]
mov ecx, [dwBufferSize]
xor eax, eax
.copy:
;'lodsb' could be used instead
;of mov / inc, but I've been
;told that it's slower to use
;than mov / inc combination...
mov al, byte [esi]
inc esi
test al, al
jz .zero
;cmp al, 'a'
;jz @f
stosb
;@@:
loopd .copy
imul ecx, [dwBufferSize], 2 ;double the buffersize
push ecx
push [pBuffer]
push 0x08 ;HEAP_ZERO_MEMORY
push [hHeap]
call [HeapReAlloc] ;replace params/function with w/e you use for reallocing
jmp .copy
.zero:
push 0
call [ExitProcess]
;______________________________________
data import
library kernel32,'kernel32'
import kernel32,\
ExitProcess,'ExitProcess',\
HeapAlloc,'HeapAlloc',\
HeapCreate,'HeapCreate',\
HeapReAlloc,'HeapReAlloc'
end data
dwBufferSize dd 512
;pString rd 1
hHeap rd 1
pBuffer rd 1
pString:
; a random file that has 'string'
; longer than 512 bytes.
; db 0x0D,0x0A = CRLF could be used
; instead of 0x00-byte...
; just create .txt file with random
; lines in it to get actual filesize
; over 512bytes
file 'random.txt'
Code: Select all
format PE GUI 4.0
include 'win32a.inc'
entry $
push szString3
push szString2
push szString
call szAppend
push 0
push szCaption
push szString3
push 0
call [MessageBox]
push 0
call [ExitProcess]
;______________________________________
proc szAppend, pString1, pString2, pBufOut
cld
mov esi, [pString1]
mov edi, [pBufOut]
xor eax, eax
mov ecx, 1
.copy:
mov al, byte [esi]
inc esi
test al, al
jz .zero
stosb
jmp .copy
.zero:
test ecx, ecx
jz .ret
mov esi, [pString2]
xor ecx, ecx
jmp .copy
.ret:
ret
endp
;______________________________________
data import
library kernel32,'kernel32',\
user32,'user32'
import kernel32,\
ExitProcess,'ExitProcess'
import user32,\
MessageBox,'MessageBoxA'
end data
szCaption db 'humm',0
szString db 'Hello',0
szString2 db ' World',0
szString3 rb 0x200
It's quite a lot to as for help with, but it'd be greatly appreciated!