flat assembler
Message board for the users of flat assembler.
Index
> Windows > Is it possible to alloc memory without apis? |
Author |
|
snify 06 Jan 2005, 12:42
Can someone give me an example if it is possible cause I've seen something like this only in 16bit mode or on linux
|
|||
06 Jan 2005, 12:42 |
|
snify 07 Jan 2005, 21:50
JohnFound, and if I want to do it with one section?
|
|||
07 Jan 2005, 21:50 |
|
JohnFound 08 Jan 2005, 00:49
snify wrote: JohnFound, and if I want to do it with one section? The same approach. Only keep your uninitialized data at the end of the section. |
|||
08 Jan 2005, 00:49 |
|
snify 08 Jan 2005, 18:12
but I want also to realloc if needed... heh?
|
|||
08 Jan 2005, 18:12 |
|
f0dder 08 Jan 2005, 18:19
That would be pretty hard to do, snify. On UNIX you have "brk" and "sbrk", but... you really should use whatever API the OS offers, or libc if the API sucks
|
|||
08 Jan 2005, 18:19 |
|
Nikolay Petrov 09 Jan 2005, 13:49
John is right!
Code: format PE GUI 4.0 include "%fasminc%\win32a.inc" include "%fasminc%\macro\if.inc" entry start MAX_MEM = 0xFFFFFF struc GLOBAL_MEM { .count = 0 .mem rb MAX_MEM } macro $import_libs [libs] ;dlls import section with dll's libs and import functions { forward local _label if ~ libs#.redundant dd RVA libs#.lookup,0,0,RVA _label,RVA libs#.address end if common dd 0,0,0,0,0 forward if ~ libs#.redundant _label db `libs#'.dll',0 end if forward include '%fasminc%\apia\'#`libs#'.inc' } macro allocMem var,page,nbytes; if nbytes is constant { page#.count = page#.count + nbytes if page#.count <= MAX_MEM virtual at page#.mem + page#.count var rb nbytes end virtual else page#.count = page#.count - nbytes display "Error: ",`page," memory is too low for ",`var,",",13,10,\ " and variable not defined!" end if } ;page1.count=0 ;for one section page1 GLOBAL_MEM ;added section .flat for uninitialized data page2 GLOBAL_MEM section '.alldata' import data readable writeable executable $import_libs kernel32,user32 start: allocMem buffer1,page1,256 ccall multicat,9,buffer1,ss1,ss2,ss3,ss1,ss2,ss3,ss1,ss2,ss3 invoke MessageBox,HWND_DESKTOP,buffer1,_title,MB_OK allocMem buffer2,page2,256 ccall multicat,3,buffer2,ss2,ss1,ss3 invoke MessageBox,HWND_DESKTOP,buffer2,_title,MB_OK invoke MessageBox,HWND_DESKTOP,buffer1,_title,MB_OK invoke ExitProcess,0 cproc multicat,numsting,strBuffer push esi edi xor ecx,ecx xor edx,edx mov edi,[strBuffer] .repeat mov esi,dword[ebp+4*(edx+4)] @@: lodsb test al,al jz @f stosb inc ecx jmp @r @@: inc edx .until edx,e,[numsting] mov byte[edi],0 pop edi esi return endp _title db "Win32 Assembly",0 ss1 db "sting1 ",0 ss2 db "string2 ",0 ss3 db "string3 ",0 ;page1.mem rb MAX_MEM ;for one section May be you will try to think a little, how realloc or free memory - it's not unpossible. |
|||
09 Jan 2005, 13:49 |
|
snify 11 Jan 2005, 17:33
Yes, this code is good I like the multicat and the $import thing but.. Is there something like malloc written in fasm/masm? I know that it doesn't need any imports..
|
|||
11 Jan 2005, 17:33 |
|
beppe85 11 Jan 2005, 19:46
snify wrote: Yes, this code is good I like the multicat and the $import thing but.. Is there something like malloc written in fasm/masm? I know that it doesn't need any imports.. You can write a sub-allocator, you still need to request memory from OS, via VirtualAlloc, via a unitializated section, etc... |
|||
11 Jan 2005, 19:46 |
|
drocon 19 Jan 2005, 18:00
uhhhhhhh... guys, just use the stack
Code: push 256 pop ebx sub esp,ebx mov edi,esp ;do something add esp,ebx but dont go over it, normal buffers are usually no problem |
|||
19 Jan 2005, 18:00 |
|
Nikolay Petrov 19 Jan 2005, 22:19
|
|||||||||||
19 Jan 2005, 22:19 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.