Code Monkey home page Code Monkey logo

Comments (12)

 avatar commented on July 25, 2024

C++/.NET assemblies usually have a VTableFixups with references to methods. Executable images also have an EntryPoint.

BTW, the correct way to check for the global type is type.IsGlobalModuleType since it doesn't have to be named <Module>.

from dnlib.

MulleDK19 avatar MulleDK19 commented on July 25, 2024

I've tried setting the VTableFixups property to null. I've also tried to just clear the VTable property on the existing instance. Same exception.

It works if I use Write() instead of NativeWrite(), but I assume all the native stuff is gone then.
Would be helpful if the exception message showed where it was referenced.

from dnlib.

 avatar commented on July 25, 2024

Some MD tokens are preserved when saving C++/.NET assemblies. Make sure nothing is preserved by passing in writer options that don't have those options enabled.

from dnlib.

MulleDK19 avatar MulleDK19 commented on July 25, 2024

Okay, that worked.

However, when I try to reference the written assembly in VS (Regardless of whether I use NativeWrite or Write), it displays this error.

---------------------------
Microsoft Visual Studio
---------------------------
A reference to 'C:\Users\Morten\AppData\Local\Temp\oka2tu2gtxw05fhc\stub.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
---------------------------
OK   
---------------------------

The assembly opens fine in ILSpy.

from dnlib.

 avatar commented on July 25, 2024

Maybe VS can't handle empty assemblies? You removed every single type.

from dnlib.

MulleDK19 avatar MulleDK19 commented on July 25, 2024

I left one. But the example above was just a test.
With the actual assembly, I'm simply converting all methods to stubs.

I was attempting to port my working code from Mono.Cecil to dnlib.

from dnlib.

 avatar commented on July 25, 2024

Cecil doesn't support mixed mode assemblies last time I checked.

If the assembly is never executed, try saving it as a non-mixed mode assembly. I have no idea why VS can't read it but ILSpy can.

from dnlib.

MulleDK19 avatar MulleDK19 commented on July 25, 2024

I tried specifying ILOnly, setting native entry point to 0 and using Write(), but VS still won't reference it. It has no problem referencing the one created by Mono.Cecil.

from dnlib.

 avatar commented on July 25, 2024

What does peverify say?

from dnlib.

MulleDK19 avatar MulleDK19 commented on July 25, 2024
Microsoft (R) .NET Framework PE Verifier.  Version  4.0.30319.33440
Copyright (c) Microsoft Corporation.  All rights reserved.

File not found or has bad headers.
1 Error(s) Verifying C:\Users\Morten\AppData\Local\Temp\ezqtfa5kpunsvnbe\stub.dll

from dnlib.

 avatar commented on July 25, 2024

That error message didn't help. Who knows what it complains about. Try this and if it doesn't help, email me the file if that's possible:

mod.IsILOnly = true;
mod.VTableFixups = null;
mod.IsStrongNameSigned = false;
mod.Assembly.PublicKey = null;
mod.Assembly.HasPublicKey = false;

var opts = new ModuleWriterOptions(mod);
mod.Write("path", opts);

from dnlib.

 avatar commented on July 25, 2024

Closed due to inactivity.

from dnlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.