[Bug binutils/30376] windres cannot parse rc files which it itself generated

2024-01-06 Thread pali at kernel dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #14 from Pali Rohár  ---
Hello, have you looked at the problem described in comment #6 that res --> rc
--> res --> rc actions are changing attributes?

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-10-05 Thread pali at kernel dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #13 from Pali Rohár  ---
Ok, if it is not possible to fix this particular case then it would be useful
to document this incompatibility with MS RC format. I can understand that
rewriting the whole parser is not something which is going to happen just
because of this issue. Also it could be useful if instead of the generic
message "syntax error" is printed some more describing message like "MS-style
double quotes are not supported" but I can imagine that the whole error message
processing is part of the parser and hence even this is not possible to fix. So
documentation change is the best fix there.

And what about other issues described in comment #6?

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-10-05 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #12 from Nick Clifton  ---
(In reply to Nick Clifton from comment #10)
> (In reply to Pali Rohár from comment #7)

> I think the point that you are trying to make however is that the MS
> resource compiler actually includes the double quote characters as part of
> the resource names, correct ?  

I am sorry, I do not think that there is any way for windres to support MS
style quoted names without completely rewriting the parser.  It is possible to
have double quotes in names, but I suspect that the method is windres specific:

  """this_name_starts_and_ends_with_quotation_marks"""

Ie if you put "" inside a string that is enclosed in "..." marks, then the ""
is converted into a single " character and taken to be part of the name.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-10-04 Thread pali at kernel dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #11 from Pali Rohár  ---
(In reply to Nick Clifton from comment #10)
> I think the point that you are trying to make however is that the MS
> resource compiler actually includes the double quote characters as part of
> the resource names, correct ?  

Yes, above test proves that.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-10-04 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #10 from Nick Clifton  ---
(In reply to Pali Rohár from comment #7)


> "resource_name4" "resource_type4" { "resource_string_data4" }

> i686-w64-mingw32-windres: test-resource.rc:4: syntax error

Right - this is the same issue as described in comment #3.  The parser thinks
that you are concatenating two double-quoted-strings together to make a single
resource name that includes a space in the middle.  Since spaces are not
allowed in resource names it signals a syntax error.



> Binary resource test-resource.ms.res compiled by MS compiler I can put into
> resource-only DLL via MS linker and then list its content via wrestool:

> --type='"RESOURCE_TYPE4"' --name='"RESOURCE_TYPE4"' --language=1033

> And now if I decompile resource.ms.res via GNU windres I get following
> output:
> 
> $ i686-w64-mingw32-windres test-resource.ms.res
> 
> /* Type: """RESOURCE_TYPE4"""
> 
>Name: """RESOURCE_NAME4""".  */
> 
> """RESOURCE_NAME4""" """RESOURCE_TYPE4""" MOVEABLE PURE
> BEGIN
>   0x6f736572L, 0x65637275L, 0x7274735fL, 0x5f676e69L, 0x61746164L,
>   "4"
> END

> It is clear that it is not what was on the input as resource name and types
> have messed quote character.

I think that the triple quotes are an attempt to encode a single quote without
it having any kind of special meaning.  But in practice this does not work.

I think the point that you are trying to make however is that the MS resource
compiler actually includes the double quote characters as part of the resource
names, correct ?  

I will have a look into this now.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-10-02 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #9 from Nick Clifton  ---
(In reply to Pali Rohár from comment #8)
> Hello Nick, have you looked at my above comments? Do you need more tests
> here?

Hi Pali,

  Sorry no, I have dropped the ball on this bug.  I will have a proper look at
it this week.  Thanks for the reminder.

Cheers
  Nick

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-09-30 Thread pali at kernel dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #8 from Pali Rohár  ---
Hello Nick, have you looked at my above comments? Do you need more tests here?

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-05-14 Thread pali at kernel dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #7 from Pali Rohár  ---
I did also another test. I took very simple resource file:

$ cat test-resource.rc
resource_name1 resource_type1 { "resource_string_data1" }
resource_name2 "resource_type2" { "resource_string_data2" }
"resource_name3" resource_type3 { "resource_string_data3" }
"resource_name4" "resource_type4" { "resource_string_data4" }

With MS RC.EXE compiler I can compile it, it does not throw any warning /
error:

$ RC.EXE /fo test-resource.ms.res test-resource.rc

If I try to compile it with GNU windres, it throws syntax error:

$ i686-w64-mingw32-windres test-resource.rc test-resource.gnu.res
i686-w64-mingw32-windres: test-resource.rc:4: syntax error

Binary resource test-resource.ms.res compiled by MS compiler I can put into
resource-only DLL via MS linker and then list its content via wrestool:

$ LINK.EXE /NOLOGO /DLL /NOENTRY /MACHINE:IX86 /OUT:test-resource.ms.dll
test-resource.ms.res
$ $ wrestool -l test-resource.ms.dll
--type='"RESOURCE_TYPE2"' --name='"RESOURCE_TYPE2"' --language=1033
[offset=0x1248 size=21]
--type='"RESOURCE_TYPE4"' --name='"RESOURCE_TYPE4"' --language=1033
[offset=0x1278 size=21]
--type='RESOURCE_TYPE1' --name='RESOURCE_TYPE1' --language=1033 [offset=0x1230
size=21]
--type='RESOURCE_TYPE3' --name='RESOURCE_TYPE3' --language=1033 [offset=0x1260
size=21]


And now if I decompile resource.ms.res via GNU windres I get following output:

$ i686-w64-mingw32-windres test-resource.ms.res

/* Type: """RESOURCE_TYPE2"""

   Name: "RESOURCE_NAME2".  */
LANGUAGE 9, 1

"RESOURCE_NAME2" """RESOURCE_TYPE2""" MOVEABLE PURE
BEGIN
  0x6f736572L, 0x65637275L, 0x7274735fL, 0x5f676e69L, 0x61746164L,
  "2"
END

/* Type: """RESOURCE_TYPE4"""

   Name: """RESOURCE_NAME4""".  */

"""RESOURCE_NAME4""" """RESOURCE_TYPE4""" MOVEABLE PURE
BEGIN
  0x6f736572L, 0x65637275L, 0x7274735fL, 0x5f676e69L, 0x61746164L,
  "4"
END

/* Type: "RESOURCE_TYPE1"

   Name: "RESOURCE_NAME1".  */

"RESOURCE_NAME1" "RESOURCE_TYPE1" MOVEABLE PURE
BEGIN
  0x6f736572L, 0x65637275L, 0x7274735fL, 0x5f676e69L, 0x61746164L,
  "1"
END

/* Type: "RESOURCE_TYPE3"

   Name: """RESOURCE_NAME3""".  */

"""RESOURCE_NAME3""" "RESOURCE_TYPE3" MOVEABLE PURE
BEGIN
  0x6f736572L, 0x65637275L, 0x7274735fL, 0x5f676e69L, 0x61746164L,
  "3"
END


It is clear that it is not what was on the input as resource name and types
have messed quote character. Content seems to be correct, it is just encoded in
less readable DWORDs form instead of ASCII string.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-05-14 Thread pali at kernel dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #6 from Pali Rohár  ---
Hello Nick! Now I tried your patch. Now it is better because windres can
compile its own generated rc file. But there are still issues.

I did more repeated conversions between binary and text file via these steps:

$ i686-w64-mingw32-windres shell32.dll shell32.dll.rc
$ i686-w64-mingw32-windres shell32.dll.rc shell32.dll.rc.res
i686-w64-mingw32-windres: warning: 14: 1001: 1033: duplicate value
i686-w64-mingw32-windres: warning: 14: 1002: 1033: duplicate value
i686-w64-mingw32-windres: warning: 14: 1003: 1033: duplicate value
i686-w64-mingw32-windres: warning: 14: 1004: 1033: duplicate value
i686-w64-mingw32-windres: warning: 14: 1005: 1033: duplicate value
$ i686-w64-mingw32-windres shell32.dll.rc.res shell32.dll.rc.res.rc
$ i686-w64-mingw32-windres shell32.dll.rc.res.rc shell32.dll.rc.res.rc.res
$ i686-w64-mingw32-windres shell32.dll.rc.res.rc.res
shell32.dll.rc.res.rc.res.rc

And I see more issues.

First issue is that every one *.rc file is different individual resources have
different content. So it means that either compiler or decompiler is doing
something wrong if it changes content.

Second issue is that second windres call drops RT_GROUP_CURSOR and
RT_GROUP_ICON during compilation. It throws that duplicate value warning, but
there are no duplicates. Seems that checking for duplicates is improper. See
following output:

$ grep '^1001 ' shell32.dll.rc shell32.dll.rc.res.rc
shell32.dll.rc:1001 3 /* RT_ICON */
shell32.dll.rc:1001 12 /* RT_GROUP_CURSOR */
shell32.dll.rc:1001 14 /* RT_GROUP_ICON */
shell32.dll.rc.res.rc:1001 3 /* RT_ICON */ MOVEABLE PURE DISCARDABLE
shell32.dll.rc.res.rc:1001 14 /* RT_GROUP_ICON */ MOVEABLE PURE DISCARDABLE

It looks like that windres during duplication checks only for name, not for
tuple (name, type).

Third issue is that windres starts adding MOVEABLE PURE DISCARDABLE attributes
even they were not in previous iteration of compilation / decompilation. I'm
not sure if they should be there or not. But I was expecting that res --> rc
--> res --> rc actions would convergate to one stable rc file.

Fourth issue: Resource "2 1" (cursor) has completely different content in
shell32.dll.rc and shell32.dll.rc.res.rc files. diff is:

 /* Name: 2.  */

-2 1 /* RT_CURSOR */
+2 1 /* RT_CURSOR */ MOVEABLE PURE DISCARDABLE
 BEGIN
0x1, 0x3,   /* Hotspot x: 1, y: 3.  */
-  0x28L  , 0x20L  , 0x40L  , 0x10001L   , 0x0L   , 0x100L
, 0x0L   , 0x0L   ,
-  0x0L   , 0x0L   , 0x0L   , 0xffL  , 0x0L   , 0x0L  
, 0x0L   , 0x0L   ,
-  0x0L   , 0x0L   , 0x0L   , 0x0L   , 0x0L   , 0xcL  
, 0x1eL  , 0x1fL  ,
-  0x80ff0700L, 0xc0ff1f00L, 0xe0cf3700L, 0xc0ff6f00L, 0x80cfdf00L, 0xcfbf00L 
, 0xe77f00L  , 0xe37f00L  ,
-  0x33ff00L  , 0x3ef01L   , 0x86df03L  , 0xfcbd07L  , 0xf83b0fL  , 0x70371eL 
, 0xe00e3cL  , 0xc00d38L  ,
-  0x300L , 0x0L   , 0x0L   , 0x0L   , 0xL,
0xL, 0xL, 0xL,
-  0xL, 0xL, 0xL, 0xL, 0xfff7L,
0xffe3L, 0xffc1L, 0xff00f8ffL,
-  0x7f00e0ffL, 0x3f00c0ffL, 0x1f0080ffL, 0x1fffL, 0x3ffeL,
0x7ffeL, 0x7ffeL, 0x7fffL,
-  0x7ffeL, 0x7ffcL, 0xfff8L, 0xff0100f0L, 0xff0300e0L,
0xff0780c0L, 0xff0fc081L, 0xff1fe083L,
-  0xff3ff087L, 0xfcffL, 0xL, 0xL
+  0xed005e70L, 0x55d5L, 0x1L   , 0x0L   , 0x40L  , 0x0L  
, 0x0L   , 0x0L   ,
+  0xed005e90L, 0x55d5L, 0x1L   , 0x0L   , 0x10001L   , 0x0L  
, 0x0L   , 0x0L   ,
+  0xed005eb0L, 0x55d5L, 0x1L   , 0x0L   , 0x0L   , 0x0L  
, 0x0L   , 0x0L   ,
+  0xed005ed0L, 0x55d5L, 0x1L   , 0x0L   , 0x100L , 0x0L  
, 0x0L   , 0x0L   ,
+  0xed005ef0L, 0x55d5L, 0x1L   , 0x0L   , 0x0L   , 0x0L  
, 0x0L   , 0x0L   ,
+  0xed005f10L, 0x55d5L, 0x1L   , 0x0L   , 0x0L   , 0x0L  
, 0x0L   , 0x0L   ,
+  0xed005f30L, 0x55d5L, 0x1L   , 0x0L   , 0x0L   , 0x0L  
, 0x0L   , 0x0L   ,
+  0xed005f50L, 0x55d5L, 0x1L   , 0x0L   , 0x0L   , 0x0L  
, 0x0L   , 0x0L   ,
+  0xed005f70L, 0x55d5L, 0x1L   , 0x0L   , 0x0L   , 0x0L  
, 0x0L   , 0x0L   ,
+  0xed005f90L, 0x55d5L, 0x1L   , 0x0L
 END

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-05-11 Thread pali at kernel dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #5 from Pali Rohár  ---
Finally I found documentation about named resources which caused this issue:
https://learn.microsoft.com/en-us/windows/win32/menurc/user-defined-resource

And here there is no information that name or type should be quoted. Also in
example is both name and type unquoted.

So I did an experiment with simple RC file:

$ cat RESOURCE.RC
resource_name resource_type { "resource_string_data" }

I compiled it with MS resource compiler RC.EXE to RESOURCE.RES file:

$ RC.EXE RESOURCE.RC

It accepted it and did not print any warning / error.

Then I created resource-only DLL with the linker script which you provided:

$ i686-w64-mingw32-windres RESOURCE.RES RESOURCE.OBJ
$ i686-w64-mingw32-ld -dll --subsystem windows -e 0 -s RESOURCE.OBJ -o
RESOURCE.DLL -T resource-only.ld

And then printed resources via wrestool:

$ wrestool -l RESOURCE.DLL
--type='RESOURCE_TYPE' --name='RESOURCE_TYPE' --language=1033 [offset=0x1090
size=20]

(I'm not sure why it prints wrong name, but whatever).

Next I did another experiment with following resource file, when I quoted name
and type:

$ cat RESOURCE.RC
"resource_name" "resource_type" { "resource_string_data" }

And again compiled it with MS RC.EXE compiler and created resource-only DLL
with GNU tools. MS compiler accepted this input file without any warning or
error. And wrestool showed:

$ wrestool -l RESOURCE.DLL
--type='"RESOURCE_TYPE"' --name='"RESOURCE_TYPE"' --language=1033
[offset=0x1098 size=20]

Look at the type, it is quited. So it looks like that name in RC file should be
taken as-is, if it contains quotes then quotes are part of the name. And it
means that GNU windres does not generate correct RC file and also does not
parse  RC file correctly.

I will try your windres patch later and let you know the results.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-05-11 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #4 from Nick Clifton  ---
Created attachment 14876
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14876&action=edit
Proposed patch

OK, here is a possible patch.

With this applied the resource file created from shell32.dll is slightly
different, and when it is converted back into a COFF format file there are no
errors.  There are a few warnings however:

  x86_64-w64-mingw32-windres: warning: 14: 1001: 1033: duplicate value
  x86_64-w64-mingw32-windres: warning: 14: 1002: 1033: duplicate value
  x86_64-w64-mingw32-windres: warning: 14: 1003: 1033: duplicate value
  x86_64-w64-mingw32-windres: warning: 14: 1004: 1033: duplicate value
  x86_64-w64-mingw32-windres: warning: 14: 1005: 1033: duplicate value

I am not sure if these pose a real problem however.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-05-11 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #3 from Nick Clifton  ---
(In reply to Pali Rohár from comment #2)

> 98f2e089891cae87147f74948f694565) for which GNU windres generates shell32.rc
> file with same syntax errors.

Thanks - with that I can reproduce the problem.  (Interestingly some of the
other versions of the shell32.dll file from that site do not exhibit the
problem).


(In reply to Pali Rohár from comment #1)
> i686-w64-mingw32-windres: shell32.rc:6473: syntax error

The problem is this line:

  6472 "REGINST" "REGINST"

The binutils RC parser combines adjacent quoted strings into a single string
with a single space between them, in the same way as the C pre-processor.   So
the parser thinks that a resource called "REGINST REGINST" is being declared
and spaces are not allowed in resource names...

I do not think changing the behaviour of the parser is a good idea, since there
may be projects out there that depend upon the current behaviour.  Instead I am
looking at changing the COFF to RC converter so that it does not emit resource
names enclosed inside quotes.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-05-10 Thread pali at kernel dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

--- Comment #2 from Pali Rohár  ---
I'm not sure if I can upload that generated file here due to possible legal
problems.

But if you agree, you can download some other shell32.dll from the internet.
For example I found different version on
https://www.dll-files.com/shell32.dll.html (6.0.2900.6072 /
98f2e089891cae87147f74948f694565) for which GNU windres generates shell32.rc
file with same syntax errors.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug binutils/30376] windres cannot parse rc files which it itself generated

2023-05-10 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30376

Nick Clifton  changed:

   What|Removed |Added

 CC||nickc at redhat dot com
 Ever confirmed|0   |1
 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2023-05-10
   Assignee|unassigned at sourceware dot org   |nickc at redhat dot com

--- Comment #1 from Nick Clifton  ---
Hi Pali,

  Please could you upload the shell32.rc file created in your first step ?

Cheers
  Nick

-- 
You are receiving this mail because:
You are on the CC list for the bug.