flat assembler
Message board for the users of flat assembler.

Index > Main > What are some fast ways to load a file into memory

Author
Thread Post new topic Reply to topic
shism2



Joined: 14 Sep 2005
Posts: 248
shism2 23 Dec 2005, 04:01
Can anyone tell me the fastest ways to load files into memory and be able to manipulate and then write it back into it's original file???
Post 23 Dec 2005, 04:01
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 23 Dec 2005, 06:04
memory maps

CreateFileMapping, MapViewOfFile, etc
Post 23 Dec 2005, 06:04
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2 23 Dec 2005, 06:13
another question

Code:
invoke  CreateFile,database,GENERIC_ALL, \ 
                NULL, NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE, NULL
               mov [datahandle],eax                                                                                                                                                                                  
              mov ebx,255
               cinvoke wsprintf,buffer,shi,ebx
               
                invoke WriteFile,[datahandle],buffer,eax,databytes,0
                invoke ReadFile,[datahandle],bufin,3h,byteread,0
                
                cinvoke wsprintf,bufin2,shi,bufin
                invoke MessageBox,0,bufin2,bufin2,0 <---why this wont show correct data?
                invoke CloseHandle,[datahandle]

database db "collection",0
datahandle dd 0
buffer rb 20h
bufin dd 4096 dup (?)
bufin2 dd 4096 dup (?)
databytes rb 20h
shi db "%d",0
shi1 db "%s",0
byteread dd ?    
Post 23 Dec 2005, 06:13
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 23 Dec 2005, 14:44
What is it supposed to show? "255"?

Maybe you want to reset the file pointer after WriteFile
Code:
invoke WriteFile,[datahandle],buffer,eax,databytes,0
invoke SetFilePointer,[datahandle],0,0,FILE_BEGIN
invoke ReadFile,[datahandle],bufin,3h,byteread,0
    
Post 23 Dec 2005, 14:44
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 23 Dec 2005, 16:37
You had:
Code:
                cinvoke wsprintf,bufin2,shi,bufin
                invoke MessageBox,0,bufin2,bufin2,0

bufin dd 4096 dup (?)
bufin2 dd 4096 dup (?)
shi db "%d",0
    
Wsprintf: you pass format %d and as an argument you pass an address to bufin (not it's content if it's what you want)

As I understand the code. You write something into file, then read 3 bytes after it. The three bytes are some binary values which you want to convert into ascii and show in a messagebox. So do this:
Code:
        and     dword [bufin], 0 ; when zeroing and is smaller than mov
        invoke  ReadFile, [datahandle], bufin, 3, byteread, 0
        cinvoke wsprintf, bufin2, shi, dword [bufin]
        invoke  MessageBox, 0, bufin2, bufin2, 0    
But if the data you read (those 3 bytes) are not binary but string so do this:
Code:
        and     dword [bufin], 0 ; when zeroing and is smaller than mov
        invoke  ReadFile, [datahandle], bufin, 3, byteread, 0
        invoke  lstrcpy, bufin2, bufin ; it's better to use lstrcpy than to use %s format 
        invoke  MessageBox, 0, bufin2, bufin2, 0    


Some suggestions: give more precise labels' names - bufin, bufin2, etc. will surely mean nothing to you if you let this project away for a week. Next, always presume how much memory will you need. I doubt you need 32 kB for only bufin and bufin2. Try to imagine how much at most will you need and if it's impossible reserve memory dynamically, e.g. buffer of file size.
Post 23 Dec 2005, 16:37
View user's profile Send private message Visit poster's website Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2 23 Dec 2005, 16:48
Code:
invoke  CreateFile,[dname],GENERIC_ALL, \ 
                NULL, NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE, NULL
               mov [datahandle],eax                                                                                                                                                                                  
              mov ebx,255
               cinvoke wsprintf,buffer,shi,ebx
                invoke WriteFile,[datahandle],buffer,eax,databytes,0
                invoke SetFilePointer,[datahandle],0,0,FILE_BEGIN 
                invoke ReadFile,[datahandle],bufin,3h,byteread,0
                cinvoke wsprintf,bufin2,shi1,bufin
                invoke MessageBox,0,bufin2,bufin2,0
                invoke CloseHandle,[datahandle]
               ret

 datahandle dd 0
buffer rb 20h
bufin dd 40 dup (?)
bufin2 dd 40 dup (?)
databytes rb 20h
byteread dd ?     
hWnd2 dd 0
database db "hello",0

    


This is comrades way...
Post 23 Dec 2005, 16:48
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.