starzboy Posted December 6, 2006 Posted December 6, 2006 helloi am making a stupid log file ... but i am facing problems....datafilename db "log.log",0.data?hdir dd ?htemp dd ?buffer db 512 dup(?)buffer1 db 512 dup(?)i was making a log file .. kindofinvoke GetCurrentDirectory,sizeof hdir ,addr hdirinvoke lstrcat,addr hdir,offset filenameinvoke CreateFile,addr hdir,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0push eaxinvoke WriteFile,eax,addr buffer,sizeof buffer,addr htemp,0pop eaxinvoke WriteFile,eax,addr buffer,sizeof buffer1,addr htemp,0pop eaxinvoke CloseHandle,eaxi want buffer1 to write on next line ... but i am not able to do so ...hope to get some helpty
cektop Posted December 6, 2006 Posted December 6, 2006 You need to write newline character after first line then. In windows thats 0x0A,0x0Dso make a variablenl db 0Ah,0Dhand write those 2 bytes whenever you need new line.
starzboy Posted December 6, 2006 Author Posted December 6, 2006 you mean .... push eax invoke WriteFile,eax,addr buffer,sizeof buffer,addr htemp,0 pop eax invoke WriteFile,eax,addr nl,sizeof nl,addr htemp,0 pop eax invoke WriteFile,eax,addr buffer1,sizeof buffer1,addr htemp,0 pop eaxif so ... not work
cektop Posted December 6, 2006 Posted December 6, 2006 First of all, don't use sizeof for buffers. Use it ONLY for primitive data types. Those are byte, word, dword etc (depends on programming language).I'm don't write stuff in asm so I don't know what sizeof will return in this case, but I'm guessing 1. In this case just hardcode length for newline. Put 2 there. If you read strings into buffer, don't write sizeof buffer, but get length of a string and write length bytes to file. If it's binary buffer this is ok, but since you're setting new lines I guess these are string variables.
Ox87k Posted December 8, 2006 Posted December 8, 2006 u could do something like this: add in .data szNextLine db 0Dh,0Ah,00h the code should be this: invoke CreateFile, addr hdir, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0push eaxinvoke WriteFile, eax, addr buffer, sizeof buffer, addr htemp, 0pop eaxinvoke WriteFile, eax, addr szNextLine, 2, addr htemp, 0pop eaxinvoke WriteFile, eax, addr buffer, sizeof buffer1, addr htemp, 0pop eaxinvoke CloseHandle, eax
Ehtyar Posted December 8, 2006 Posted December 8, 2006 (edited) I can't imagine how much you've corrupted the stack by popping eax three times after pushing it only once, TBH i'm astounded you didn't get any kind of fatal error. However, excluding that mistake, Ox87k is correct. Though, if you did a bit of searching, you would also find that there are several write-line type functions for masm, or you could use the crt.As an afterthought, you can alleviate the need for calling GetCurrentDirectory by specifying only the filename in CreateFile, it will assume you want the file created in the cwd, see here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/creating_and_opening_files.aspEhtyar. Edited December 8, 2006 by Ehtyar
Ox87k Posted December 8, 2006 Posted December 8, 2006 (edited) .datafilename db "log.log",0szNextLine db 0Dh,0Ah,00h.data?buffer db 512 dup(?)buffer1 db 512 dup(?)hFileWr DWORD ?invoke CreateFile, ADDR filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0mov [hFileWr], eaxinvoke lstrlen, ADDR bufferinvoke WriteFile, [hFileWr], ADDR buffer, eax, ADDR htemp, 0invoke WriteFile, [hFileWr], ADDR szNextLine, 2, ADDR htemp, 0invoke lstrlen, ADDR buffer1invoke WriteFile, [hFileWr], ADDR buffer1, eax, ADDR htemp, 0invoke CloseHandle, [hFileWr] maybe now is more clean Edited December 8, 2006 by Ox87k
PuNkDuDe Posted December 9, 2006 Posted December 9, 2006 just add the new line bytes to the buffer CODE.datafilename db "log.log",0szNextLine db 0Dh,0Ah,00h.data?buffer db 512 dup(?)buffer1 db 512 dup(?)bWrite db 1024 dup(?)hFileWr DWORD ?hFileSize DWORD ?invoke lstrcpy,addr bWrite,addr bufferinvoke lstrcat,addr bWrite,addr szNextLineinvoke lstrcat,addr bWrite,addr buffer1invoke lstrlen,addr bWritemov hFileSize,eaxinvoke CreateFile,ADDR buffer,GENERIC_READ or GENERIC_WRITE ,\FILE_SHARE_READ or FILE_SHARE_WRITE,\NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL mov hFileWr,eaxmov eax,hFileSizeinvoke WriteFile,hFileWr,bWrite,eax,ADDR htemp,NULLinvoke CloseHandle,hFileWr
starzboy Posted December 9, 2006 Author Posted December 9, 2006 @Ehtyar ...nah bro ... it was a mistype in that post ...btw Napalm/iCu finall helped me out with it ...mov eax, offset buffer0 mov word ptr [eax], 0A0Dh add eax, 2 invoke GetDlgItemText, hwnd, 10036, eax, 509 ; copy to buffer mov eax, offset buffer1 mov word ptr [eax], 0A0Dh add eax, 2 invoke GetDlgItemText, hwnd, 10040, eax, 509 ; copy to buffer invoke GetCurrentDirectory, sizeof hdir, addr hdir ; current dir invoke lstrcat, addr hdir, offset filename ; cat filename on invoke CreateFile, addr hdir, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0 push eax push eax push eax mov ebx, eax invoke lstrlen, addr buffer0 invoke WriteFile, ebx, addr registrationdata,sizeof registrationdata, addr ddTemp, 0; Write to file pop ebx invoke lstrlen, addr buffer0 invoke WriteFile, ebx, addr buffer0, eax, addr ddTemp, 0; Write to file pop ebx invoke lstrlen, addr buffer1 invoke WriteFile, ebx, addr buffer1, eax, addr ddTemp, 0; Write to file pop ebx invoke CloseHandle, ebx; close handle
Guest shot Posted March 15, 2007 Posted March 15, 2007 .datafilename db "log.log",0szNextLine db 0Dh,0Ah,00h.data?buffer db 512 dup(?)buffer1 db 512 dup(?)hFileWr DWORD ?invoke CreateFile, ADDR filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0mov [hFileWr], eaxinvoke lstrlen, ADDR bufferinvoke WriteFile, [hFileWr], ADDR buffer, eax, ADDR htemp, 0invoke WriteFile, [hFileWr], ADDR szNextLine, 2, ADDR htemp, 0invoke lstrlen, ADDR buffer1invoke WriteFile, [hFileWr], ADDR buffer1, eax, ADDR htemp, 0invoke CloseHandle, [hFileWr] maybe now is more clean I try to compile this code and i get errors :S error A2133: register value overwritten by INVOKE error A2133: register value overwritten by INVOKE im not sure why and do not understand this I added all the buffers and data and narrowed it down to 2 unsolvable errors
yamraaj Posted March 17, 2007 Posted March 17, 2007 It may happen..So it's always better to use registers which are not usually changed with calls like ebx or esi,ediSo save the return value from "invoke lstrlen, ADDR buffer" to ebx and then use it and similar for others where you get errors
Guest shot Posted March 17, 2007 Posted March 17, 2007 (edited) ok I think i may have it now htemp was not defined anywhere in the example so I assumed it was a LOCAL when I add it to .data? it works you need to add this to the .data? to compile correctly htemp DWORD ? now i will try to finish the code and dump information from a dialog item to the log EDIT: I got it working now it read information from my dialog item and dumps it to a log file like i wanted but im having problems with my dialog items I want it to read each line from the dialog Item and insert it to another dialog in the same format once it is in the second dialog i save it to a file but i cant get it to move down a line instead of; Line1 Line2 Line3 I get; Line1Line2Line3 I know i will have to use 0Ah,0Dh to define a new line but im not sure how I would do that dynamically I mean i need to read dialog item 1 then add the number of lines found to buffer copy data to buffer2 and from there add to dialog item 2 but i cant figure out how to read line by line and set dialog text line by line I also cant seem to clear buffers correctly I tryinvoke SetDlgItemText,hWnd,buffer,NULLbut it doesnt workI think its because the buffer is not a dialog itemis there any way to null the buffer after im done with it? nvm the clear buffer thing I solved it I use this code to clear out the buffer push eax push ecx push edi xor eax, eax mov ecx, 512/4 mov edi, offset buffer rep stosd pop edi pop ecx pop eax works great for me just a little lengthy any help would be much appreciated Edited March 18, 2007 by shot
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now