Page 1 of 1

Some FASM help...

Posted: Sun Aug 06, 2006 2:55 am
by Killswitch
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:

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'
The second will add two strings together, but won't actually increase the size of the memory buffer.

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
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!

Posted: Thu Aug 10, 2006 11:06 am
by dagcrack
I see you asking for this in the FASM forums.. now I see you asking about that over here...

My tip for you: Learn ASM!. And if you're willing to learn by reading code, theres plenty out there. You just need to understand the basics, once you're there.. you can actually program anything you want.

Second tip: Follow the first tip. :P

Plus, in this case.. you already have the code served, if you couldnt manage to implement your own idea based on this code, its obvious you dont understand the basics, but I'm not blaiming you.. Just follow my advice!.

If you want to know of any good books though, I'll PM you.
Do you want some optimization manuals as well?.

Have fun.

PS: Have you tried the FRESH fasm library already?, It has many string handling routines as far as I remember (although none of them are "very" good, perhaps they might serve your needs - either for learning or implementing your own versions - So why not trying them out?).

I'm sure you'll get the hand of all this pretty soon.

Posted: Thu Aug 10, 2006 3:34 pm
by Psychophanta
Sorry, dagcrack, but as you can see, Killswitch knows ASM perfectly, and he is asking for a concrete problem solution.
Your advises are not the help asked for. okay?
If you understand and have a solution for the explained problem, then reply and you will help.

Posted: Thu Aug 10, 2006 5:01 pm
by dagcrack
Wow, chill.
If you read what he wrote:

Code: Select all

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:
1) he is TRYING
2) he ASKED FOR HELP ON THE FASM FORUMS
3) he needs someone to make him the routine, even though he HAS the routines and its just matter of READING THEM and MAKING YOUR OWN BASED ON WHAT YOU WANT.

For instance: He doesnt know ASM perfectly, so, learn how to read.

So, if you know, you don't try, you do.
End of story.

By the way,
Asking for help doesnt mean that hes an ASM neophyte.
But having the code and not knowing how to implement a routine, does make him quite a neophyte in the subject. Hence the call for help, But thats no big deal, everyone needs help.

What I sense is some sort of personal attack from your side, which is low.

I did offered him a PM with help, you have no point and you made no sense. okay?.

Posted: Thu Aug 10, 2006 5:39 pm
by thefool
Psychophanta wrote:look at me shaking my a**
:shock:

Posted: Thu Aug 10, 2006 6:38 pm
by blueznl
shaking his ace?

i thought this was about programming, not about poker?

<< confused look >>

Posted: Thu Aug 10, 2006 6:40 pm
by thefool
you whiner :lol:

Posted: Thu Aug 10, 2006 6:45 pm
by blueznl
i'm looking for a diamond in the rough, but all i get is being clubbed with bugs, it's a full house even with one kid around, so that's distracting, it's about time my queen of hearts gets home so i can bring her a royal flush on her cheeks...

o darn, that was cheap... i'd better go back to this piss poor piece of coding...

Posted: Thu Aug 10, 2006 6:51 pm
by thefool
:shock:

Posted: Thu Aug 10, 2006 7:11 pm
by Psychophanta
Okay dagcrack, i re-read the killswitch post and i think you are right this time, perhaps for the first time ever. :P

Posted: Thu Aug 10, 2006 9:19 pm
by Killswitch
Wow :oops:

I didn't expect such a huge row over silly old me :). My ASM skills aren't the best, that's a given - but I have been trying and I even tried integrating the two routines, I just couldn't. It just kept crashing.

I'd still really appreciate some help putting these two routines together, or even some pointers on how to do so. What really threw me was the change in the use of registers in the second routine compared to the first.

Posted: Sat Aug 12, 2006 12:21 pm
by Trond
Killswitch wrote:Wow :oops:

I didn't expect such a huge row over silly old me :). My ASM skills aren't the best, that's a given - but I have been trying and I even tried integrating the two routines, I just couldn't. It just kept crashing.
You should've posted the crashing version as well. If it was just a very simple thing wrong it would have been to fix that than to redo it all from the beginning.

Posted: Sun Aug 20, 2006 1:14 am
by MilaJova
nice :D:)