Hey coders,
merry christmas! I'm sorry guys but even on this day I have a problem. I don't think it's a bug but something in this way. But let me describe it: I'm using bin2db.exe to convert a little exe into masm's db-format (ascii). As you can see this are a few lines. Later I will modify the data and finally write it to the disk. But there's the problem. I don't know how big the MyData is so I thought of using the sizeof operand. But this gets only the length of the first line and not of all :( because if I say directly how big it is (in this case 57 bytes) it works. But I have to deal with larger files so getting this value wouldn't be easy :confused:.
I really hope you find a work-around or something easy... ;)

thx,
DaEagle99

And here's the code:


.data
MyData db 72,101,121,44,13,10,121,111,117,13,10,115,117,99,107,33
db 13,10,84,104,105,115,13,10,105,115,13,10,97,13,10,116
db 101,115,116,33,13,10,77,97,115,109,13,10,105,115,13,10
db 103,114,101,97,116,32,58,68,33

.data?
hFile dd ?
bRead dd ?

.code
start:

invoke CreateFile, addr MyFile, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_SYSTEM, 0
mov hFile, eax
;___________________________________________________
invoke WriteFile, hFile, addr MyData, sizeof MyData, addr bRead, 0
;___________________________________________________
invoke MessageBox, 0,offset MyData,offset Msg,MB_OK

invoke CloseHandle, hFile
invoke ExitProcess,NULL

end start
Posted on 2001-12-24 02:15:47 by DaEagle99
If you use bin2db, it writes the size in the generated file:


; D:\masm32\CBLOCKC.DLL [COLOR=red]8704[/COLOR] bytes

db 77,90,10,0,2,0,0,0,4,0,15,0,255,255,0,0
db 192,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
[...]


Another way for compiling a binary file into your exe is, to include it in the resource file (would be better, if the file size is over 100kb):



MYEXE RCDATA blah.exe
Posted on 2001-12-24 04:07:09 by bazik
Here is a tip if you want to compute offset of large data :


LargeData db 77,90,10,0,2,0,0,0,4,0,15,0,255,255,0,0
db 192,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
[...]
LargeDataSize equ offset $ - offset LargeData
Posted on 2001-12-24 06:28:22 by Axial
Hey guys,
thanks for your fast answers although it's christmas :alright:

bAZiK) The file i wanna include is about 3kb. There are two versions of this file, each 3kb. But there is only one line that differs so I want to include the part of the files wich is in both equal and the two different lines. So I'm able to generate both files. The whole file is split up and I don't know the size of each part.
The code in my program looks like this (but with asciis) and other content:


Part1 db "Begin Function",0

Encrypt db "Encrypt",0
Decrypt db "Decrypt",0

Part2 db "End Function",0

WriteFile, Part1
.if blabla == encrypt
WriteFile, Encrypt
.else
WriteFile, Decrypt
.endif
WriteFile, Part2


So I can save a few kbs :grin:

Axial) I'm gonna try your code and post again... thanks

cya,
DaEagle99
Posted on 2001-12-24 07:05:06 by DaEagle99
Hey Axial,
thank you very much, your code works perfectly :alright:

Merry christmas,
DaEagle99
Posted on 2001-12-24 10:51:28 by DaEagle99
This is a limitation of MASM. SIZEOF only counts data defined on one line, and MASM has a line limit - so your not going to be able to use SIZEOF.
Posted on 2001-12-24 12:25:41 by bitRAKE
This is a limitation of MASM. SIZEOF only counts data defined on one line, and MASM has a line limit - so your not going to be able to use SIZEOF.


It doesn't really matter since the equates are not written in the data section and therefore does not take extra space...

Merry Christmas all !!!

Axial
Posted on 2001-12-24 12:44:02 by Axial