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

Maybye an error with costura fody? #102

Closed
Mrgaton opened this issue Feb 26, 2023 · 48 comments
Closed

Maybye an error with costura fody? #102

Mrgaton opened this issue Feb 26, 2023 · 48 comments
Labels
enhancement New feature or request invalid This doesn't seem right

Comments

@Mrgaton
Copy link

Mrgaton commented Feb 26, 2023

BitMono Version

0.11 alpha

.NET Version

.Net 7

Description

Unhandled exception. System.BadImageFormatException: Bad IL format. The format of the file 'C:\Users\Mrgaton\Proyectee\bin\x64\Debug\net7.0-windows\Proyectee_Launcher.dll' is invalid.

Reproduction URL

No response

Reproduction steps

1 install costura fody 
2 try to obfuscate it using cli 
3 Output dll does nothing

Screenshots

![image](https://user-images.githubusercontent.com/68958481/221433219-cea51766-a520-4090-bf44-e2b447f4d43a.png)

Logs

[2023-02-26 20:37:01 INF][BitMono.CLI.Program] Everything is seems to be ok, starting obfuscation..
[2023-02-26 20:37:01 INF][BitMono.CLI.Program]
       ___  _ __  __  ___
      / _ )(_) /_/  |/  /__  ___  ___
     / _  / / __/ /|_/ / _ \/ _ \/ _ \
    /____/_/\__/_/  /_/\___/_//_/\___/
    https://github.com/sunnamed434/BitMono
    BitMono v0.11.0.0
[2023-02-26 20:37:01 INF][BitMono.Obfuscation.BitMonoEngine] Loaded Module Proyectee_Launcher.dll
[2023-02-26 20:37:01 INF][BitMono.Obfuscation.Notifiers.ProtectionsNotifier] Enabled protections: , BitTimeDateStamp, BitDotNet, BitMono
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.Notifiers.ProtectionsRuntimeMonikerNotifier] [!!!] BitDotNet - Intended for Mono runtime
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.Notifiers.ProtectionsRuntimeMonikerNotifier] [!!!] BitMono - Intended for Mono runtime
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.Notifiers.ProtectionsNotifier] Disabled protections: AntiDe4dot, AntiDebugBreakpoints, AntiDecompiler, AntiILdasm, BitMethodDotnet, CallToCalli, DotNetHook, FullRenamer, NoNamespaces, ObjectReturnType, StringsEncryption
[2023-02-26 20:37:01 INF][BitMono.Obfuscation.BitMonoObfuscator] Running on Microsoft Windows NT 6.2.9200.0, .NETFramework v4.0.30319.42000, x64 bits
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Runtime, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Drawing.Common, Version=7.0.0.0, PublicKeyToken=cc7b13ffcd2ddd51
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Windows.Forms, Version=7.0.0.0, PublicKeyToken=b77a5c561934e089
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: DiscordRPC, Version=1.1.3.18, PublicKeyToken=null
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: NAudio, Version=2.1.0.0, PublicKeyToken=e279aa5131008a41
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: NAudio.WinForms, Version=2.1.0.0, PublicKeyToken=e279aa5131008a41
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Drawing.Primitives, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.ComponentModel.Primitives, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Collections, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Linq.Expressions, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Security.Cryptography, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Diagnostics.Process, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Net.Http, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Text.Json, Version=7.0.0.0, PublicKeyToken=cc7b13ffcd2ddd51
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: Microsoft.VisualBasic.Forms, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Runtime.InteropServices.JavaScript, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Net.WebClient, Version=7.0.0.0, PublicKeyToken=cc7b13ffcd2ddd51
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.IO.Compression, Version=7.0.0.0, PublicKeyToken=b77a5c561934e089
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Text.RegularExpressions, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Net.Requests, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Runtime.InteropServices, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Console, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: Microsoft.CSharp, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.ComponentModel, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Windows.Forms.Primitives, Version=7.0.0.0, PublicKeyToken=b77a5c561934e089
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Linq, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: Microsoft.Win32.Registry, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Threading.Thread, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Net.Primitives, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.IO.Packaging, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Web.HttpUtility, Version=7.0.0.0, PublicKeyToken=cc7b13ffcd2ddd51
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: NAudio.Core, Version=2.1.0.0, PublicKeyToken=e279aa5131008a41
[2023-02-26 20:37:01 WRN][BitMono.Obfuscation.BitMonoObfuscator] Failed to resolve dependency: System.Threading, Version=7.0.0.0, PublicKeyToken=b03f5f7f11d50a3a
[2023-02-26 20:37:02 INF][BitMono.Obfuscation.BitMonoObfuscator] No one error were registered while building the PE
[2023-02-26 20:37:02 INF][BitMono.Obfuscation.BitMonoObfuscator] Protected module`s saved in C:\Users\Mrgaton\Proyectee\bin\x64\Debug\net7.0-windows\output
[2023-02-26 20:37:02 INF][BitMono.Obfuscation.BitMonoObfuscator] BitTimeDateStamp -> OK
[2023-02-26 20:37:02 INF][BitMono.Obfuscation.BitMonoObfuscator] BitDotNet -> OK
[2023-02-26 20:37:02 INF][BitMono.Obfuscation.BitMonoObfuscator] BitMono -> OK
[2023-02-26 20:37:02 INF][BitMono.Obfuscation.BitMonoObfuscator] Since obfuscation elapsed: 00:00:00.8033801
Enter anything to exit!

Applications

No response

OS

No response

@Mrgaton
Copy link
Author

Mrgaton commented Feb 27, 2023

Umm i tested without costura and same error

@Mrgaton
Copy link
Author

Mrgaton commented Feb 27, 2023

net framework 4.8 errors aswell so i am thinktink its my problem :c

@sunnamed434
Copy link
Owner

sunnamed434 commented Feb 27, 2023

As I see you've used BitDotNet, and BitMono protections, they make invalid metadata of PE in your file, so in this case, you can use such protections only in Mono or Unity, that means you can't just protect the dotnet executable, and then run it again (you need specific Runtime, Mono, Unity or even your own which support such files with invalid metadata), so, you can use only BitTimeDateStamp, and other.

About the costura fody, atm there's no support for it, but, there's a workaround in the ConfuserEx project, I'll add support for costura fody definitely

@sunnamed434 sunnamed434 added enhancement New feature or request invalid This doesn't seem right labels Feb 27, 2023
@sunnamed434 sunnamed434 added this to the 0.12.0-alpha.21 milestone Feb 27, 2023
@sunnamed434 sunnamed434 pinned this issue Feb 27, 2023
@Mrgaton
Copy link
Author

Mrgaton commented Feb 27, 2023

But I cant select the protections on cli just ask me the file and the lib path

@sunnamed434
Copy link
Owner

But I cant select the protections on cli just ask me the file and the lib path

You can edit protections.json in the root folder of the BitMono

@Mrgaton
Copy link
Author

Mrgaton commented Feb 27, 2023

when you put in the cli from user mode the path of the file if is with quotes doesn't recognize it as a path ("")

@sunnamed434
Copy link
Owner

Ah, yeah, it's kinda bug, will fix

@Mrgaton
Copy link
Author

Mrgaton commented Feb 28, 2023

Ok i tried all protections except those 2 and i got this error when running app

Unhandled Exception: System.TypeLoadException: The signature is not correct.

@Mrgaton
Copy link
Author

Mrgaton commented Feb 28, 2023

Maybie AntiDecompiler ok ill try a bit more

@sunnamed434
Copy link
Owner

Yeah, you're right, AntiDecompiler causes the problem, AntiDecompiler won't work on non-Mono Runtime also (if you see a message that says Intended for Mono runtime then don't use it)

@Mrgaton
Copy link
Author

Mrgaton commented Feb 28, 2023

I turned off anti decompiler and same error

and i dont know what Dependencies (libs): path does or what to put in there

@sunnamed434
Copy link
Owner

sunnamed434 commented Feb 28, 2023

Dependencies simply are references that your files use

(from my file and checked in dnspy)
image

@Mrgaton
Copy link
Author

Mrgaton commented Feb 28, 2023

but i have costura

@sunnamed434
Copy link
Owner

sunnamed434 commented Feb 28, 2023

Ah, yeah, of course, btw, I already added support for the costura, but it will be available only on the new pre-release, I think this week will publish, as a temp solution you can do this, and after that specify the path to the .dlls

@Mrgaton
Copy link
Author

Mrgaton commented Feb 28, 2023

@sunnamed434
Copy link
Owner

How do you specify the path to the references?

@Mrgaton
Copy link
Author

Mrgaton commented Feb 28, 2023

as the same as the file path

@sunnamed434
Copy link
Owner

Weird, it can't resolve references anyway, OK then, wait for the new pre-release

@sunnamed434
Copy link
Owner

sunnamed434 commented Mar 5, 2023

The new version of BitMono pre-released, and support for costura fody has been added, let me know if the issue is solved now

@sunnamed434 sunnamed434 unpinned this issue Mar 5, 2023
@Mrgaton
Copy link
Author

Mrgaton commented Mar 6, 2023

I remark that i am using net 7 not framework

@Mrgaton
Copy link
Author

Mrgaton commented Mar 6, 2023

Now it gets stuck on here https://pastebin.com/w7AKEUyN

@sunnamed434
Copy link
Owner

As far as I know in the compiled folder of your .NET 7 should be .dll which contains all of your code, try to protect it.

@Mrgaton
Copy link
Author

Mrgaton commented Mar 6, 2023

i need to disable auto cleanup of costura fody?

@Mrgaton
Copy link
Author

Mrgaton commented Mar 6, 2023

Ok now it protected but same error https://pastebin.com/8QcecYws

Unhandled exception. System.TypeLoadException: The signature is incorrect.

@sunnamed434
Copy link
Owner

I've created .NET Core app for a test, so, .exe doesn't contain any code, you've to protect the .dll one

image
image

@Mrgaton
Copy link
Author

Mrgaton commented Mar 6, 2023

Yea i know im doing thath

@Mrgaton
Copy link
Author

Mrgaton commented Mar 6, 2023

but the exe tries to load the dll and throw thath exception

Unhandled exception. System.TypeLoadException: The signature is incorrect.

@sunnamed434
Copy link
Owner

but the exe tries to load the dll and throw thath exception

Unhandled exception. System.TypeLoadException: The signature is incorrect.

So weird, yeah, it's a reasonable exception, cuz it's unable to resolve the references

@sunnamed434
Copy link
Owner

I'll check now what else can be done to resolve issue

@sunnamed434
Copy link
Owner

i need to disable auto cleanup of costura fody?

Try to do that

@sunnamed434
Copy link
Owner

I made a simple test and it resolves the reference successfully (EF Core 7.0.0) using the .NET Core 7.0 Console application

image

@sunnamed434
Copy link
Owner

I'll also write xUnit tests on it to be sure 100%

@Mrgaton
Copy link
Author

Mrgaton commented Mar 6, 2023

i need to disable auto cleanup of costura fody?

Try to do that

same error

@Mrgaton
Copy link
Author

Mrgaton commented Mar 6, 2023

INF][BitMono.CLI.Modules.CLIObfuscationNeedsFactory] Dependencies (libs) successfully specified: ***\net7.0-windows! [2023-03-06 11:42:10 INF][BitMono.CLI.Program] File: ***\FileDiffGenerator.dll [2023-03-06 11:42:10 INF][BitMono.CLI.Program] Dependencies (libs): ***\net7.0-windows [2023-03-06 11:42:10 INF][BitMono.CLI.Program] Everything is seems to be ok, starting obfuscation.. [2023-03-06 11:42:10 INF][BitMono.CLI.Program] ___ _ __ __ ___ / _ )(_) /_/ |/ /__ ___ ___ / _ / / __/ /|_/ / _ \/ _ \/ _ \ /____/_/\__/_/ /_/\___/_//_/\___/ https://github.com/sunnamed434/BitMono BitMono v0.12.0.0 Something went wrong! System.BadImageFormatException: El formato del archivo ejecutable (.exe) o de la biblioteca (.dll) no es válido. en AsmResolver.PE.File.SerializedPEFile..ctor(BinaryStreamReader& reader, PEMappingMode mode) en AsmResolver.DotNet.ModuleDefinition.FromBytes(Byte[] buffer, ModuleReaderParameters readerParameters) en BitMono.Obfuscation.Factories.ModuleFactory.Create() en BitMono.Obfuscation.BitMonoEngine.<StartAsync>d__9.MoveNext() --- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción --- en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) en BitMono.Obfuscation.BitMonoEngine.<StartAsync>d__10.MoveNext() --- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción --- en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) en BitMono.CLI.Program.<Main>d__2.MoveNext() --- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción --- en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() en BitMono.CLI.Program.<Main>d__2.MoveNext() Enter anything to exit!

@Mrgaton
Copy link
Author

Mrgaton commented Mar 6, 2023

if you want I can give you the project

@Mrgaton
Copy link
Author

Mrgaton commented Mar 6, 2023

FileDiffGenerator.zip

@sunnamed434
Copy link
Owner

FileDiffGenerator.zip

I see when I try to specify the FileDiffGenerator\bin\Release\net7.0-windows as a libs directory, then I'm getting tons of errors, try to create an external directory called libs: FileDiffGenerator\bin\Release\net7.0-windows\libs

As well I made another pre-release, try it out!

@sunnamed434
Copy link
Owner

sunnamed434 commented Mar 6, 2023

Try to disable the full renamer, cuz it will cause you a lot of problems with custom attributes atm, this will be fixed soon ™️ (#97)

Or simply add [ObfuscationAttribute], but I think this won't help cuz these attributes are seems to be added after compilation :(

@Mrgaton
Copy link
Author

Mrgaton commented Mar 6, 2023

FileDiffGenerator.zip

I see when I try to specify the FileDiffGenerator\bin\Release\net7.0-windows as a libs directory, then I'm getting tons of errors, try to create an external directory called libs: FileDiffGenerator\bin\Release\net7.0-windows\libs

As well I made another pre-release, try it out!

In that i dint use any nuget package

@sunnamed434
Copy link
Owner

Do you have news about the issue?

@Mrgaton
Copy link
Author

Mrgaton commented Mar 7, 2023

but the exe tries to load the dll and throw thath exception
Unhandled exception. System.TypeLoadException: The signature is incorrect.

So weird, yeah, it's a reasonable exception, cuz it's unable to resolve the references

but thath error is on the exe of the net app

@sunnamed434
Copy link
Owner

Try to disable all protections and just then run the "protected" file

@Mrgaton
Copy link
Author

Mrgaton commented Mar 7, 2023

ok wait if you want we can talk on discord if you prefer

@sunnamed434
Copy link
Owner

Try to use one single protection (which could cause minimum issues), and then try to run the app.

Yes sure add me sunnamed#9250, we can book a call tomorrow

@Mrgaton
Copy link
Author

Mrgaton commented Mar 7, 2023

Sended

@sunnamed434
Copy link
Owner

The new version has been pre-released now, try it out, also let me know the results - it fixed the issue or not

@sunnamed434
Copy link
Owner

Does the problem with Costura is solved now?

@Mrgaton
Copy link
Author

Mrgaton commented Mar 17, 2023

Yes

@Mrgaton Mrgaton closed this as completed Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants