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

Problem with System.Object in .net core 3.1 #167

Closed
TheSkorpiox opened this issue Jul 21, 2020 · 4 comments
Closed

Problem with System.Object in .net core 3.1 #167

TheSkorpiox opened this issue Jul 21, 2020 · 4 comments

Comments

@TheSkorpiox
Copy link

Hello,
So i'm trying to use DllExport for a .Net Core 3.1 project, but i can't make it work.

DllExport -version: v1.7.3.58831+9a4bc51
Logs from DllExport tool: cfg.log

Here is the code for the dll

using System;
using System.Runtime.InteropServices;

namespace ManagedLibrary
{
    public class EntryClass
    {
        [DllExport]
        public static void EntryPoint()
        {
            Console.WriteLine("Injected ...");
        }
    }
}

The IL code DllExport generated


//  Microsoft (R) .NET Framework IL Disassembler.  Version 4.5.30319.0



// Metadata version: v4.0.30319
.assembly extern 'mscorlib'
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) 
  .ver 4:0:0:0
}
.assembly extern 'System.Runtime'
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 4:2:2:0
}
.assembly extern 'System.Console'
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 4:1:2:0
}
.assembly 'ManagedLibrary'
{
  .custom instance void ['System.Runtime']'System.Runtime.CompilerServices'.'CompilationRelaxationsAttribute'::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
  .custom instance void ['System.Runtime']'System.Runtime.CompilerServices'.'RuntimeCompatibilityAttribute'::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                                         63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.

  // --- The following custom attribute is added automatically, do not uncomment -------
  //  .custom instance void ['System.Runtime']'System.Diagnostics'.'DebuggableAttribute'::.ctor(valuetype ['System.Runtime']'System.Diagnostics'.'DebuggableAttribute'/'DebuggingModes') = ( 01 00 02 00 00 00 00 00 ) 

  .custom instance void ['System.Runtime']'System.Runtime.Versioning'.'TargetFrameworkAttribute'::.ctor(string) = ( 01 00 18 2E 4E 45 54 43 6F 72 65 41 70 70 2C 56   // ....NETCoreApp,V
                                                                                                                    65 72 73 69 6F 6E 3D 76 33 2E 31 01 00 54 0E 14   // ersion=v3.1..T..
                                                                                                                    46 72 61 6D 65 77 6F 72 6B 44 69 73 70 6C 61 79   // FrameworkDisplay
                                                                                                                    4E 61 6D 65 00 )                                  // Name.
  .custom instance void ['System.Runtime']'System.Reflection'.'AssemblyCompanyAttribute'::.ctor(string) = ( 01 00 0E 4D 61 6E 61 67 65 64 4C 69 62 72 61 72   // ...ManagedLibrar
                                                                                                            79 00 00 )                                        // y..
  .custom instance void ['System.Runtime']'System.Reflection'.'AssemblyConfigurationAttribute'::.ctor(string) = ( 01 00 07 52 65 6C 65 61 73 65 00 00 )             // ...Release..
  .custom instance void ['System.Runtime']'System.Reflection'.'AssemblyFileVersionAttribute'::.ctor(string) = ( 01 00 07 31 2E 30 2E 30 2E 30 00 00 )             // ...1.0.0.0..
  .custom instance void ['System.Runtime']'System.Reflection'.'AssemblyInformationalVersionAttribute'::.ctor(string) = ( 01 00 05 31 2E 30 2E 30 00 00 )                   // ...1.0.0..
  .custom instance void ['System.Runtime']'System.Reflection'.'AssemblyProductAttribute'::.ctor(string) = ( 01 00 0E 4D 61 6E 61 67 65 64 4C 69 62 72 61 72   // ...ManagedLibrar
                                                                                                            79 00 00 )                                        // y..
  .custom instance void ['System.Runtime']'System.Reflection'.'AssemblyTitleAttribute'::.ctor(string) = ( 01 00 0E 4D 61 6E 61 67 65 64 4C 69 62 72 61 72   // ...ManagedLibrar
                                                                                                          79 00 00 )                                        // y..
  .hash algorithm 0x00008004
  .ver 1:0:0:0
}
.module 'ManagedLibrary.dll'
// MVID: {1FEC2A2A-E2B0-4751-9A3C-7E8E660D3A06}
.imagebase 0x0000000180000000
.file alignment 0x00000200
.stackreserve 0x0000000000400000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000000
// Image base: 0x031F0000


// =============== CLASS MEMBERS DECLARATION ===================

.class public auto ansi beforefieldinit 'ManagedLibrary'.'EntryClass'
       extends ['System.Runtime']'System'.'Object'
{
.method public hidebysig static void modopt(['mscorlib']'System.Runtime.CompilerServices.CallConvCdecl')  'EntryPoint'()
  {
    .export [1] as 'EntryPoint'
    .maxstack  8
    IL_0000:  ldstr      "Injected ..."
    IL_0005:  call       void ['System.Console']'System'.'Console'::'WriteLine'(string)
    IL_000a:  ret
  } // end of method 'EntryClass'::'EntryPoint'

.method public hidebysig specialname rtspecialname instance void  .ctor() cil managed
  {
    // Code size       7 (0x7)
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  call       instance void ['System.Runtime']'System'.'Object'::.ctor()
    IL_0006:  ret
  } // end of method 'EntryClass'::.ctor

} // end of class 'ManagedLibrary'.'EntryClass'


// =============================================================

// *********** DISASSEMBLY COMPLETE ***********************
// WARNING: Created Win32 resource file C:\Users\fanad\AppData\Local\Temp\dxp-7d3d5aea-7e24-4c43-9ac7-5eb48cf1e236\ManagedLibrary.res

And the console app

using System;
using System.Threading.Tasks;

namespace ConsoleAppToInject
{
    class Program
    {
        static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult();

        public async Task MainAsync()
        {
            Console.WriteLine("Hello world!");

            await Task.Delay(-1);
        }
    }
}

I'm actually facing 2 problems:

  • 1: It doesn't ship any dll with it, so i had to manually copy System.Console.dll, System.Private.CoreLib.dll and System.Runtime.dll on the output directory
  • 2: When that is done, i'm left with that error
    image
    which translate by "Unable to load type 'System.Object' from 'System.Private.CoreLib' because the parent doesn't exists."

It indeed look like #132 but i did that rebase thing.

I don't really know what to do now.

Best regards

@3F
Copy link
Owner

3F commented Jul 22, 2020

Thanks for the report,

1: It doesn't ship any dll with it,

It depends on the specific structure of your projects in solution. So it would be good to attach sample of the empty projects with the same structure to illustrate the problem.

2: When that is done, i'm left with that error

Can you clarify your "console app" part? For how does this relate to the final use of the export because I don't see any part of the call of the "EntryPoint()" from .module 'ManagedLibrary.dll' thus I'm not sure what are you actually trying here.

Regarding to #132, as I already voiced yesterday in twitter, Can you share the result for netstandard 2.0 and/or netcoreapp 2.1 ?

@TheSkorpiox
Copy link
Author

Here is the complete project:
ScourgeModder.zip

It contains:

  • AppToInject (.net core 3.1 executable) (simulate a .net 3.1 process that i would like to inject)
  • Injector (.net core 3.1 executable)
  • ScourgeMod (.net core 3.1 library)

My objective is to inject a recent game running in .net core 3.1, AppToInject act as a dummy process for my tests.

I tried with .netcoreapp 2.1 as asked, but it crashes the process

@3F
Copy link
Owner

3F commented Jul 23, 2020

Thanks for the complete sample!
I've checked the problem. This is duplicate of #132.

AppToInject and Injector still can be configured for .NET Core 3.1. But for ScourgeMod please temporarily use netstandard2.0 targeting.

Regarding your "It doesn't ship any dll",

This is duplicate of #144.
For 1.7.3 you can simply configure it through PostProc https://github.com/3F/DllExport/wiki/PostProc#post-processing

@TheSkorpiox
Copy link
Author

Thank you very much, i applied your suggestions and it now works !

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

No branches or pull requests

2 participants