Hi

I make this MP3 editor (for TAG v1) and updating of tag works fine only for files that already have this TAG info. First problem is that i dont know how to resize this file so i can add new 128 bytes at the end of file and update this TAG info. Second is that i want to completely remove this TAG and then the file will be 128 bytes smaller (shorter). I try with this:
invoke CreateFile,lpFilename,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,
ebx,OPEN_EXISTING or CREATE_ALWAYS,FILE_FLAG_SEQUENTIAL_SCAN OR FILE_FLAG_NO_BUFFERING,ebx
.if eax==INVALID_HANDLE_VALUE
jmp End1
.endif
mov hFileUpdate,eax
invoke GetFileSize,hFileUpdate,0
mov edx,eax
add edx,128d
push edx ; save new file size for writing
invoke CreateFileMapping, hFileUpdate, ebx, PAGE_READWRITE, eax,ebx,ebx ; eax is dwMaximumSizeHigh
.if eax==NULL ; error
jmp End1
.endif

But here CreateFileMapping fail. I use olly's debugger and there i can see ERROR_INVALID_PARAMETER. What i doing wrong? Can you help me with this?

Thank in advance

stanks

Here is the file: MP3 Editor.zip
Posted on 2002-12-02 12:24:24 by stanks
probably you just have to allocate 128 bytes more (even if tag already present)
or just check if tag if present before openning the mp3

then 3 case:
add tag: -if tag already present Do Nothing or Update tag
-if not go to then end of mp3 file (GetFileSize) and add you 128 bytes struct(TAG) and save the file with (GetFileSize)+128 as size

Update tag:-if tag not present do nothing or just add tag
-if tag just update it and save file with it original file size

Del Tag:-if tag not there do nothing
-if tag just save file with it filesize reduced by 128

ok hope it will be but sometimes a better point of view can fix some bugs or prevent you to fail doing what you want.

of course you can use FileMapping if you want.
Posted on 2002-12-02 12:57:18 by Thor0Asgard
You invoke CreateFileMapping with wrong parameters.

instead of:
invoke CreateFileMapping, hFileUpdate, ebx, PAGE_READWRITE, eax,ebx,ebx

you should use

invoke CreateFileMapping, hFileUpdate, 0, PAGE_READWRITE, 0, eax, 0

because pair 0, eax makes the new 64-bit file size and 0 is high word.
and obviously you should xor ebx,ebx

(sorry Stanks for sending thrash to your private mailbox, but i had problems with cookies and couldn't log to the forum and tried to reply to this post via private message box but now everything works fine)
PS: Bomb Raider rules!!!
Posted on 2002-12-03 03:41:50 by stolarz
you can change the size of memory mapped files very easily...



.DATA
MAPSIZE DD 1000

.DATA?

FILENAME1 DB "test.dat",0

FILEHANDLE DD ?
FILESIZE DD ?
H_BUFFER DD ?
M_BUFFER DD ?

.CODE
INVOKE CreateFile,addr FILENAME1,GENERIC_READ+GENERIC_WRITE,0,NULL,\
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
CMP EAX, INVALID_HANDLE_VALUE
JZ _ERR

MOV FILEHANDLE,EAX

INVOKE GetFileSize,EAX,NULL
INC EAX
JZ _ERR
DEC EAX

MOV FILESIZE,EAX
ADD MAPSIZE,EAX

INVOKE CreateFileMapping,FILEHANDLE,NULL,PAGE_READWRITE,NULL,MAPSIZE,0
MOV H_BUFFER, EAX

INVOKE MapViewOfFile,H_BUFFER,FILE_MAP_WRITE,0,0,MAPSIZE
MOV M_BUFFER,EAX
MOV EDI, EAX

;[I]EDI points now to the allocated memory (filesize + 1000 bytes extra buffer)[/I]
;[I]you can do now what you want to do with that data... read it, change it...[/I]
;[I]whatever...[/I]

INVOKE UnmapViewOfFile,M_BUFFER
INVOKE CloseHandle,H_BUFFER

;[I]the next part is very important... please look up the next two api functions [/I]
;[I]in your api-ref. SetFilePointer is able to change the position of the "filpointer"[/I]
;[I]and SetEndOfFile marks the end-of-file at the filepointers current position.[/I]
;[I]so with these two instructions you can enlarge or cut the file with no problems.[/I]

INVOKE SetFilePointer,FILEHANDLE,ESI,0,FILE_BEGIN
INVOKE SetEndOfFile,FILEHANDLE

INVOKE CloseHandle,FILEHANDLE
Posted on 2002-12-03 03:46:58 by mob
Thank you guys very much. Now i will finish my program. Thanks again.

stanks
Posted on 2002-12-03 10:41:04 by stanks