How do I embed a .res file into a PE file? #105271
-
I'm using the new .NET 9 I believe the equivalent for .NET 9 is the internal class VersionInfoBuilder : ResourceSectionBuilder
{
public VersionInfoBuilder(string resFilePath)
{
if (resFilePath == null)
return;
rawBytes = File.ReadAllBytes(resFilePath);
}
private readonly byte[] rawBytes = null;
protected override void Serialize(BlobBuilder builder, SectionLocation location)
{
if (rawBytes == null)
return;
builder.WriteBytes(rawBytes);
}
} I'm using it like this: public static ManagedPEBuilder CreatePEBuilder(MethodInfo entryPoint, string resFilePath = null)
{
MetadataBuilder mb = Context.Assembly.GenerateMetadata(out BlobBuilder ilStream, out BlobBuilder mappedFieldData);
PEHeaderBuilder headerBuilder = new(
imageBase: 0x00400000,
imageCharacteristics: Characteristics.ExecutableImage);
ManagedPEBuilder peBuilder = new(
headerBuilder,
new(mb),
ilStream,
mappedFieldData,
entryPoint: MetadataTokens.MethodDefinitionHandle(entryPoint.MetadataToken),
nativeResources: new VersionInfoBuilder(resFilePath));
return peBuilder;
} It does not work. Can anyone tell me how to correctly do it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Maybe @buyaa-n or @jkotas or one of the other guys responsible for the .NET 9 implementation of |
Beta Was this translation helpful? Give feedback.
-
RES file format and contents of the .rsrc section are similar, but subtly different. https://github.com/dotnet/corert/blob/master/src/ILCompiler.Build.Tasks/src/DumpNativeResources.cs is a sample converter from When doing the conversion, you'll see that the data structures within the rsrc section refer to offsets from the beginning of the file (not from the beginning of the section). The |
Beta Was this translation helpful? Give feedback.
RES file format and contents of the .rsrc section are similar, but subtly different. https://github.com/dotnet/corert/blob/master/src/ILCompiler.Build.Tasks/src/DumpNativeResources.cs is a sample converter from
.rsrc
section to a res file. You'll need to do this in the opposite direction.When doing the conversion, you'll see that the data structures within the rsrc section refer to offsets from the beginning of the file (not from the beginning of the section). The
SectionLocation
argument that gets passed to yourSerialize
override should come handy for that since it tells where in the file rsrc section is getting placed.