flat assembler
Message board for the users of flat assembler.
Index
> Windows > Handling strings of unknown length |
Author |
|
okasvi 02 Aug 2006, 01:09
Code: 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' I hope this is atleast a bit what you are looking for, of course lstrlenA from kernel32 could help too edit: eh, forgot totally about _handling_ of the strings added string-'handling' as commented, parses a-chars sry for my english |
|||
02 Aug 2006, 01:09 |
|
vid 02 Aug 2006, 07:43
check out FASMLIB, next part of tutorial will describe it's string library, which is capable of working with strings with non-fixed length
also same library is used in Fresh project for now, see file /fasmlib/str.inc |
|||
02 Aug 2006, 07:43 |
|
Killswitch 02 Aug 2006, 13:59
Thanks for your help, I just want to make sure I know what's going on:
Code: push [dwBufferSize] push 0x08 ;HEAP_ZERO_MEMORY push [hHeap] call [HeapAlloc] mov [pBuffer], eax - Allocates a buffer of 512 bytes initially Code: mov al, byte [esi] inc esi test al, al jz .zero -Starts copying bytes to pBuffer upto the number of bytes indicated by dwBufferSize, or untill a terminating null byte is encounterded (in which case it jumps to the end) Code: 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 -Increases the size of pBuffer if there's stuff left to copy over, but there wasn't enough space Is that the gist? |
|||
02 Aug 2006, 13:59 |
|
okasvi 03 Aug 2006, 10:23
second part is actually this, but other than that, correct.
Code: .copy: mov al, byte [esi] inc esi test al, al jz .zero stosb loopd .copy |
|||
03 Aug 2006, 10:23 |
|
Killswitch 03 Aug 2006, 15:17
Thank you
Edit: How could I turn that code into a macro, and also have it start adding characters from the end of the Buffer (so I can call the macro once, and make pBuffer = 'hello' then call the macro again so that ' world' gets added to pBuffer)? |
|||
03 Aug 2006, 15:17 |
|
okasvi 04 Aug 2006, 12:24
Killswitch wrote: Thank you You should make it a proc I'll work on example soon. edit: Code: 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 _________________ When We Ride On Our Enemies support reverse smileys |: |
|||
04 Aug 2006, 12:24 |
|
Killswitch 05 Aug 2006, 12:35
You're a genious mate, thank you!
|
|||
05 Aug 2006, 12:35 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.