Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"BadImageFormatException: No string associated with token." occured when Load and Write DirectWriteForwarder.dll #456

Closed
yangzhongke opened this issue Mar 15, 2022 · 1 comment

Comments

@yangzhongke
Copy link

DirectWriteForwarder.dll is an assembly of WPF(.NET Core 6). When I load and write the assembly, the application crashed and "BadImageFormatException: No string associated with token." occured .

  1. Create a WPF application using .NET Core 6.
  2. publish the application with 'self-contained'.
  3. Run the following code to edit the file of DirectWriteForwarder.dll in the published directory:
string filename = @"E:\temp\publish\DirectWriteForwarder.dll";
using MemoryStream ms = new MemoryStream();
using (var mod = ModuleDefMD.Load(filename))
{
    if(mod.IsILOnly)
    {
        mod.Write(ms);
    }
    else
    {
        mod.NativeWrite(ms);
    }
}
ms.Position = 0;
File.WriteAllBytes(filename, ms.ToArray());
  1. Try to launch the WPF executable file, and it cannot starts properly.
  2. Check Windows Event Viewer, the following log can been seen.
    image

Thanks.

@wtfsck
Copy link
Contributor

wtfsck commented Mar 16, 2022

I won't have time to check why it fails, but you could force calling NativeWrite() and you could also enable some of the preserve mdtoken options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants