hi,
in the following code i just want to read out the contents of a file into memory, change some stuff and then write in the same file .
But this code is working only if i write a file with a other file name.


code:


invoke CreateFile,ADDR hFile,
GENERIC_READ,0,
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,
NULL
mov fhandle,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMemory,eax
invoke GlobalLock,hMemory
mov pMemory,eax
invoke ReadFile,fhandle,pMemory,MEMSIZE-1,ADDR SizeReadWrite,NULL
mov ecx, pMemory
mov edx,
inc edx
mov , edx
mov pMemory, ecx
;invoke DeleteFile,addr hFile ;Try this but i can't delete
invoke CreateFile,ADDR hFile,\
GENERIC_WRITE ,0,
NULL,CREATE_NEW,FILE_ATTRIBUTE_ARCHIVE,
NULL
mov fhandle,eax
invoke WriteFile,fhandle,pMemory,8,ADDR SizeReadWrite,NULL
invoke GlobalUnlock,pMemory
invoke GlobalFree,hMemory
invoke CloseHandle,hFile
invoke CloseHandle,fhandle


Thanks for any help !

Bye
Posted on 2003-04-07 06:46:05 by Atome X
I you want to read and write to the same file you have to open the file with GENERIC_READ and GENERIC_WRITE file access.

For example

invoke CreateFile,ADDR hFile,
GENERIC_READ or GENERIC_WRITE, 0,
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,
NULL
Posted on 2003-04-07 06:53:20 by Odyssey
Think odyssey for this but i have try and it's not working.
Posted on 2003-04-07 07:09:40 by Atome X
You are doing it the wrong way as far as I can see.



invoke CloseHandle,hfile


I don't see the point in opening the file 2 times and the file is not closed before you open it again.
Posted on 2003-04-07 07:30:25 by roticv
roticv is right. Plus you should pass the size of the file and not of the allocated memory to ReadFile.
Posted on 2003-04-07 07:39:54 by bazik
Hmmm.... you're not trying to write a crack are you?


Think odyssey for this but i have try and it's not working.
What do you mean it's not working? We are not mind readers here, you need to be more specific. Test the returns from your API calls to see if they succeeded. Give us a clue what the problem is ;)
Posted on 2003-04-07 07:43:30 by sluggy
I i have find the probl?me with the odyssey reply, i give you the solutions for over newbies.


invoke CreateFile,ADDR hFile,
GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL
mov fhandle,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMemory,eax
invoke GlobalLock,hMemory
mov pMemory,eax
invoke ReadFile,fhandle,pMemory,MEMSIZE-1,ADDR SizeReadWrite,NULL
mov ecx, pMemory
mov ecx, pMemory
mov edx,
inc edx
mov , edx
invoke CreateFile,ADDR hFile,\
GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,
NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,NULL
mov fhandle,eax
invoke WriteFile,fhandle,pMemory,8,ADDR SizeReadWrite,NULL
invoke ReadFile,fhandle,pMemory,MEMSIZE-1,ADDR SizeReadWrite,NULL
invoke GlobalUnlock,pMemory
invoke GlobalFree,hMemory

Byee

PS: It's not a crack but it's a Keygen/BruteForce for my pleasure only.
Just for Fun
Posted on 2003-04-08 07:48:51 by Atome X

PS: It's not a crack but it's a Keygen/BruteForce for my pleasure only.
Just for Fun


Ya dont need to do File IO for a KeyGen or a BruteForcer. Except you use a word list, but then you wont need to change the file.

Oh and before I forget it,

(I'll leave that thread open for now, but be carefull what you ask for in the future).
Posted on 2003-04-08 07:54:22 by bazik