Can someone help me find the error in filling in this struture?

Started by ThoughtCriminal, November 18, 2005, 12:55:32 PM

Previous topic - Next topic

ThoughtCriminal


_IMAGE_SECTION_HEADER STRUC
    Name BYTE 8 dup(0)
UNION
PhysicalAddress DWORD ?
VirtualSize DWORD ?
ENDS
VirtualAddress DWORD ?
SizeOfRawData DWORD ?
PointerToRawData DWORD ?
PointerToRelocations DWORD ?
PointerToLinenumbers DWORD ?
NumberOfRelocations WORD  ?
NumberOfLinenumbers WORD  ?
Characteristics DWORD ?
_IMAGE_SECTION_HEADER ENDS

IMAGE_SCN_CNT_CODE                   = 00000020h
IMAGE_SCN_MEM_READ                   = 40000000h
IMAGE_SCN_MEM_WRITE                  = 80000000h


image_section_header _IMAGE_SECTION_HEADER {<'.text'>,0,0,0,0ch,03ch,0,0,0,0,IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ}

Error 1 error A2044: invalid character in file f:\....

Yes I know it is just one big mess.  I'm just trying to test something out before I fix things right.

Thanks.


PBrennick

ThoughtCriminal,
I placed the structure in one of my sources and it compiled with no problems.  I wonder if it is because of the strange characters that are between name and BYTE?  I don't know what they are and I was not able to copy them along with the other characters into my clipboard.  This is what I used...


_IMAGE_SECTION_HEADER STRUC
Name BYTE 8 dup(0)
UNION
PhysicalAddress DWORD ?
VirtualSize DWORD ?
ENDS
VirtualAddress DWORD ?
SizeOfRawData DWORD ?
PointerToRawData DWORD ?
PointerToRelocations DWORD ?
PointerToLinenumbers DWORD ?
NumberOfRelocations WORD ?
NumberOfLinenumbers WORD ?
Characteristics DWORD ?
_IMAGE_SECTION_HEADER ENDS


I am no expert with structures but the above definitely works.
hth,
Paul
The GeneSys Project is available from:
The Repository or My crappy website

ThoughtCriminal

As far as I can see there are no strange characters.  I checked with a hex editor.  The problem on this line according to MASM:

image_section_header _IMAGE_SECTION_HEADER {<'.text'>,0,0,0,0ch,03ch,0,0,0,0,IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ}

I'm guessing it does not work because I want to use a text string.  It should be 8 bytes, but there does not seem to be any NULL key on my keyboard.  Is there a way to put unprintable characters in a string decleraction? It should be something like <.text000> where 0 has the value of zero, not the value of character '0'.

Thanks.


P1

Take out the Braces and put the <> around the whole data initialization data.

Regards,  P1  :8)

ThoughtCriminal

It still thinks there is an invalid character: My changes

image_section_header _IMAGE_SECTION_HEADER <'.text',0,0,0,0ch,03ch,0,0,0,0,IMAGE_SCN_CNT_CODE|IMAGE_SCN_MEM_EXECUTE|IMAGE_SCN_MEM_READ>


Thanks.

PBrennick

Silly me, I thought you said you were having trouble with the structure.  That is what I get for not looking carefully.

Try using .txt instead of .text and you will be fine.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

P1

||            Logical OR

Be sure to a space before and after.

Keep the other format change plus this one.

Regards,  P1  :8)

ThoughtCriminal

PBrennick: Its not a text file extension but a COFF section name so I should use .text

Well, the error changed at least:

image_section_header _IMAGE_SECTION_HEADER <'.text',0,0,0,0ch,3ch,0,0,0,0,IMAGE_SCN_CNT_CODE || IMAGE_SCN_MEM_EXECUTE || IMAGE_SCN_MEM_READ>


Error   1   error A2186: extra characters in literal initialization   f:\....   
Quote
extra characters in literal initialization

A literal structure initializer was not properly delimited.

One of the following may have occurred:

There were missing or mismatched angle brackets (< >) or braces ({ }) around an initializer.

There were extra characters after the end of an initializer.

There was a syntax error in the structure initialization.

Just checked to make sure I had the right number of parameters.  Seems I had 11, not 10. Modified version:

image_section_header _IMAGE_SECTION_HEADER <'.text',0,0,0ch,3ch,0,0,0,0,IMAGE_SCN_CNT_CODE || IMAGE_SCN_MEM_EXECUTE || IMAGE_SCN_MEM_READ>
; 1   2 3  4   5  6 7 8 9   10

Those numbers should match up under the parameters, but they don't on a mesage board.

MASM is weird, I can do this and it works fine:

image_section_header _IMAGE_SECTION_HEADER <'.text';
   
No closing brace and I only get the first part of the structure intilized.
There seems to be a problem trying to intilize a struture with a string as the first parameter.

Thanks.

Jimg

There seems to be basically two problems with your structure.  First, "Name" is a reserved word somewhere, changing it to Namex or something else gets rid of some of masm's confusion.

Second, the extra characters are caused by the || symbol, which is a run-time comparison operator.  Use "OR" in this instance.

But ultimately, there seems to be a bug in masm where unions embedded in a structure are concerned.  It doesn't recoginize anything I could do to try to put a value in in union variable, or anything following the union.  If you can get rid of the union, everything works.

Making the minimum changes to your original post, this seems to work-

_IMAGE_SECTION_HEADER STRUC
    Namex BYTE 8 dup(0)  ; 0
;UNION
PhysicalAddress DWORD ?  ; 1
;VirtualSize DWORD ?
;ENDS
VirtualAddress DWORD ?   ; 2
SizeOfRawData DWORD ?    ; 3
PointerToRawData DWORD ? ; 4
PointerToRelocations DWORD ?  ; 5
PointerToLinenumbers DWORD ?  ; 6
NumberOfRelocations WORD  ?   ; 7
NumberOfLinenumbers WORD  ?   ; 8
Characteristics DWORD ?       ; 9
_IMAGE_SECTION_HEADER ENDS

IMAGE_SCN_CNT_CODE                   = 00000020h
IMAGE_SCN_MEM_READ                   = 40000000h
IMAGE_SCN_MEM_WRITE                  = 80000000h

image_section_header _IMAGE_SECTION_HEADER {'.text',0ch,03ch,3,4,5,6,7,8,IMAGE_SCN_CNT_CODE OR IMAGE_SCN_MEM_EXECUTE OR IMAGE_SCN_MEM_READ}

ThoughtCriminal

Thank you. I was about ready to give up.

Your right, the UNION was the trouble.  Named UNIONs didn't work either.


I used: option nokeyword: <Name>

If I hadn't I don't think I would have gotten as far as I did.