Hello Coders
My question is is it possible to copy text that is in a buffer Directly to a file without using edit boxes. I tried to do this for the past couple of days by changing stuff in the CreateFile to make things point to my buffer. I had no success at all. But once I did get some scribble scrabble in the saved file but that was about it. If it is possible could someone explain or give an example of how it is done.
Straight from Buffer to File...

Thanks
Posted on 2001-11-24 23:26:08 by cmax
Try somthing like this:



.....

;write code
call WriteFile,hFile,offset[pMemory],offset[MEMSIZE],offset[fsize],0

;Did it work?
.if (eax == 1)
push 'T'
.else
push 'F'
.endif
pop DWORD ptr[Saved]
call MessageBoxA, 0,offset[Saved], offset[Saved],0

....
Posted on 2001-11-25 00:11:26 by -T-
invoke _lwrite, hFile, ADDR Buffer, sizeof Buffer
Posted on 2001-11-25 03:38:29 by clip
Thank Guys
I tried it and have not got it to work yet but i know it should. It's got to be a problem in my code. I sure i will get it soon...

T..i wondering when you use those [ ] around your codes does it help secure operation or information hiding or does it show up easy on a debugger or something. Very interesting.
Posted on 2001-11-26 07:56:38 by cmax
Afternoon, Cmax.



; in .data
.data
lpszDiskFile db "ErrorLog.log",0
hFile DWORD 0
lpFileBuffer db "My message",13,10,"Blah, blah.",0
lpNumberOfBytesWritten DWORD 0

; in .code
.code
invoke CreateFile,addr lpszDiskFile,GENERIC_WRITE,FILE_SHARE_WRITE,
NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
mov hFile, eax

invoke WriteFile, hFile, addr lpFileBuffer, sizeof lpFileBuffer, addr lpNumberOfBytesWritten, 0

invoke CloseHandle,hFile

The buffer can be any buffer you're needing to save.

Cheers,
Scronty
Posted on 2001-11-26 08:28:33 by Scronty
>T..i wondering when you use those [ ] around your codes does it help secure operation or information hiding or does it show up easy on a debugger or something. Very interesting.

I just use the square brackets to make it easier to read. Offset works like addr in MASM(...right?). Most people omit the brackets... same thing as far as I know.

If I don't do that I somtimes find myself forgetting to use offset at all, ie. just leaving the []. Call me crazy, its just what I do:)
Posted on 2001-11-26 20:01:48 by -T-
Btw, use WriteFile and not _lwrite ...

Note This function is provided only for compatibility with 16-bit versions of Windows. New applications should use the WriteFile function.

I wouldn't be surprised if they map to the same thing on proper
systems, but... WriteFile is the correct api to use, mmm'kay?
Posted on 2001-11-26 20:39:17 by f0dder
"Offset works like addr in MASM(...right?)."

I saw a post a few months back about that. Hutch, f0dder and others had a deep discussion about this. I founded for a fact that depending on the strangenest of the code or where you put your data in the .asm file I had to use ADDR and other times I had to uses OFFSET even when i start switching data position i think. I learned a lot in thoses 2 days. I mostly use LOCAL.
Posted on 2001-11-26 23:53:07 by cmax
Afternoon, CMax.

As far as I know, "addr" is only used in an INVOKE.

Otherwise, you've got to use OFFSET.

Cheers,
Scronty
Posted on 2001-11-27 02:35:39 by Scronty
AFAIK, in masm you use:

- "ADDR" within invoke for both global and local variable
- "OFFSET" to point to global variables (i.e. those defined in .data etc)
- "LEA" to get the address of local variables (i.e. those defined after LOCAL within a PROC) ... you can also use LEA for global variable by the way

Random
Posted on 2001-11-27 05:06:25 by random
Hello Everyone

I just got to the point of knowing there is a real difference in a DD and DB.
DB sometime require sizing. DD may have much less or much more byte in memory. I thought they both were buffer types.

Whatever it is my text is stuck in the DD.

After days of trying to write text from a DD buffer Directly to disk I realize that it may not be that easy.

Buffer1 db 25 dup(?).............. I know this will work and had learned how to use it fairly well.

Buffer1 dd ? .............. But how do you make this work with the text in this type of Buffer

I can read the text in a message box from the DD value but I can't write it Directly to disk.

I been using Scronty and clip formats and both work perfectly when dealing with ( db ). I could not figure out how to use your format -T- .

Could someone please tell me what to do this and send me on my merry way...

Happy Holidays
Posted on 2001-12-22 04:20:59 by cmax
DB means "define byte" data.
DD means "define dword" data.

If you generate only numbers (instead of characters) then

DB 1,2,3,4 ; this will generate four bytes
DD 1,2,3,4 ; this will generate four dwords (16 bytes)

When working with text buffers, DD or DWORD would normally be used to hold pointers (addresses) to buffers.

ActualString DB 'This is the string storage.',0
StringPointer DD ActualString ; Value of StringPointer is address of ActualString
Posted on 2001-12-24 13:56:05 by tank