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

Unable to save obfuscated assembly #1

Closed
answering007 opened this issue Apr 16, 2014 · 10 comments
Closed

Unable to save obfuscated assembly #1

answering007 opened this issue Apr 16, 2014 · 10 comments

Comments

@answering007
Copy link

Hi,
I try to save obfuscated assembly (looks like .Net Reactor 4.8) using dnlib, but has an exception. My steps:

  1. Test project with obfuscated assembly referenced
  2. Create an instance of type from obfuscated assembly
  3. Run the code:
    var module = typeof([type_from_ obfuscated_assembly]).Module;
    var modDef = ModuleDefMD.Load(module);
    if (modDef.IsIlOnly)
    modDef.Write(path_to_file);
    This code throws an exception:
    dnlib.DotNet.Writer.ModuleWriterException: Instruction operand is null.
    There were a lot of instructions with call opcode and null in operand.
    Is there any solution for this?
@0xd4d
Copy link
Collaborator

0xd4d commented Apr 16, 2014

It's obfuscated and you should try de4dot first to clean it.

However, if you don't want to clean it, then you can still save it but it might not run afterwards. You can ignore all errors dnlib detects during writing by adding a dummy logger:

var mod = ModuleDefMD.Load(typeof(int).Module);
var writerOptions = new dnlib.DotNet.Writer.ModuleWriterOptions(mod);
writerOptions.Logger = DummyLogger.NoThrowInstance;
mod.Write(@"C:\out.dll", writerOptions);

@answering007
Copy link
Author

The goal is to get clean working assembly.
Unfortunately de4dot 3.1.41592 didn’t reconstruct method bodies and I try to “dump” assembly, using dnlib. Do you plan to update .Net Reactor deobfuscator in de4dot?

@0xd4d
Copy link
Collaborator

0xd4d commented Apr 16, 2014

If de4dot fails to deobfuscate it, email me the file.

@0xd4d 0xd4d closed this as completed Apr 16, 2014
@0xd4d
Copy link
Collaborator

0xd4d commented Apr 16, 2014

My email address is seen when you start de4dot. You just replied to github.com's issue email. This is the wrong place to discuss de4dot.

@RexProg
Copy link

RexProg commented Nov 27, 2016

writerOptions.Logger = DummyLogger.NoThrowInstance;

I Use It
but my app get an exception
"Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified."

what can i do to solve it?

@0xd4d
Copy link
Collaborator

0xd4d commented Nov 27, 2016

You probably don't have an assembly resolver, see the readme file on the front page.

@RexProg
Copy link

RexProg commented Nov 29, 2016

                AssemblyResolver asmResolver = new AssemblyResolver();
                ModuleContext modCtx = new ModuleContext(asmResolver);               
                asmResolver.DefaultModuleContext = modCtx;              
                asmResolver.EnableTypeDefCache = true;
                GlobAssembly.Asm = ModuleDefMD.Load(GlobAssembly.AsmInputPath);
                GlobAssembly.Asm.Context = modCtx;
                GlobAssembly.Asm.Context.AssemblyResolver.AddToCache(GlobAssembly.Asm);

My code for resolve references is this
is it wrong?
Because now i have that problem too

@0xd4d
Copy link
Collaborator

0xd4d commented Nov 29, 2016

Use this method.

@RexProg
Copy link

RexProg commented Nov 30, 2016

excuse me
my problem isn't solved
i made a simple project to show my problem

when i build with NoThrowInstance app have an exception
but without it app run correctly
anyway i need NoThrowInstance

@RexProg
Copy link

RexProg commented Dec 1, 2016

my problem is solved
ModuleWriterOptions();
i use this overloads
i change it to
ModuleWriterOptions(moduleDef);
and my problem solved
excuse me for my spam

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