Hi All, I've created a patcher that memory maps a file, replaces a bunch of bytes in it, then writes the image to a new file. The number of bytes being replaced is relatively large and it seems I'm stuck with two options in declaring the array which holds these bytes. If I declare and initialize the array on one line I seem limited to 256 characters, as in myarray db 0a1h, 0a2h, .....to 256 char max Assembling gives me 'statement too complex' and 'line too long' errors if there's more than 256 characters. I can get by the 256 char/line max by spanning more than 1 logical line with a separate declaration on each line, as in myarray db 0a1h, 0a2h .............db 0a3h, 0a4h .............db 0a5h, 0a6h etc. The only problem with this second choice is not being able to use the LENGTHOF and SIZEOF operators for the array. I can just count the LENGTHOF value for the occasion, but this seems so, well crude, compared to using the operator. Are these pretty well my only options here or is there another solution? Wonderful board BTW. This is my first post here but I've been lurking and learning for a while :) Cheers, Kayaker
Posted on 2001-03-04 00:16:00 by Kayaker
A while ago i posted a inquiry with resourced data Here.... I wanted to be able to pack a resouce into a dll. But the major learn for me was using RCDATA within a resource. I posted a working solution on the above link. If you study it (omitting the dll aspect and compiling as one executable) this could help you because there is an API to get the resource size:

The SizeofResource function returns the size, in bytes, of the specified resource. 

DWORD SizeofResource(

    HINSTANCE  hModule,	// resource-module handle  
    HRSRC  hrsrc 	// resource handle 
   );
You can also check another post i made for an example of a standalown exe with RCDATA as an extra file in your project here... My thoughts are, put the array of data in a text file (or binary) and include it as a resource type 'RCDATA' and call that data from you program as needed, as well get the size of the data from the above api. Hope this helps.. NaN
Posted on 2001-03-04 02:44:00 by NaN
Kayaker, One trick is to compute the offsets yourself, kinda semi-automaticly: MyBigThing BYTE {lots of bytes here} MyOtherThing BYTE {more bytes here} DummyEnd BYTE 0 lenMyBigThing EQU OFFSET MyOtherThing - OFFSET MyBigThing lenMyOtherThing EQU OFFSET MyBigThing - OFFSET DummyEnd This lets you play with the arrays without a lot of recounting. And congratulations on leaving lurker land. :-)
Posted on 2001-03-04 02:57:00 by Ernie
Kayaker, I gather the problem is that you need to store BYTE data but the line limit is to short for you with some BYTE sequences. The solution is no big deal but it needs a bit more homework from you. RealItem1 db (first 256 bytes of data) dummy1 db (next 256 bytes of data) dummy2 etc .... RealItem2 db (first 256 bytes of data) dummy1 db (next 256 bytes of data) dummy2 etc .... This approach works fine but you must know the byte length of each section you need to read from it before you read it. When you read RealItem1, it will keep reading until u get the BYTE count you need. In memory, the BYTE data is sequential so it works fine. Regards, hutch@pbq.com.au
Posted on 2001-03-04 04:32:00 by hutch--
I had a similar problem when I tried to port a few of C. Petzold's examples from c... I found a work around in that you could use masm's TEXTEQU function like this...

string1 textequ  ;up to the line length limit
string2 textequ <1,2,3,4,...\>  ;up to the line length limit
                               ;note there is no db directive
string3 textequ   ;not no line continuation

;then to combine them just do
mystring string1 string2 string3; now you can use SIZEof/Lengthof

strlenth equ Lengthof mystring
;this technique does have it's limitations in that eventually 
;you come against the same "line too long" error.
this can be done in an include file...especially if your working with arrays of initiallised structures. hope this helps. GeO
Posted on 2001-03-04 10:38:00 by GeO
Hi, Thanks to everyone for the replies. It's funny you mention that thread on putting a resource in a dll NaN, because I had already printed it out because I thought it would be useful. That's an interesting idea that maybe could be used in making something like a generic patcher, the hex offsets and replacement bytes for each occasion could simply be stored in 2 arrays in a dll 'plugin' that would be called from the main patcher. I ended up placing each sequence of bytes/hex offsets in its own array using a multiple line db/dd directive, and then using Ernie's useful, if slightly suggestive ;) lenMyBigThing suggestion. Worked like a charm. One of the modifications I had made to the original file that I was creating the patcher for, along with several code changes, was adding a couple of new resources. The problem with adding a resource to an existing exe of course is that it pushes the offsets of the rest of the resource section ahead, so that a byte to byte comparison of the 2 files amounts to MAJOR differences (1 new Menu item + Accelerator cost me over 7000 bytes in byte changes!). Luckily I found a utility that I'll pass along that output the byte changes in a form that I could simply copy and paste into my 2 arrays. It's called Cogen II by the Egoiste which compares 2 files and outputs the differences complete with TASM source which can be compiled into a full-on patcher executable. I had no interest in creating the exe, I just wanted the hex offset/byte data. If anyone's interested you can get it at www.suddendischarge.com That said, and without having to code my own, is there any MASM source around that will compare 2 files and spit out the differences in an array form that could be pasted into a project? In any case, thanks again for your help. Regards, Kayaker
Posted on 2001-03-04 15:16:00 by Kayaker
A fairly traditional means of getting sizes and counts is

arrayname DWORD val1, val2, etc
          DWORD ...
          DWORD valy, valz, lastval
asize equ $ - arrayname
acount equ asize / (sizeof structure)
Posted on 2001-03-06 14:49:00 by tank