0

I disassembled a C# program with ildasm and modified the il code to my needs but now when i try to assemble it back into an exe i get these errors:

Cannot compile native/unmanaged method
Local (embedded native) PInvoke method, the resulting PE file is unusable

I have generated a snk file and tried to use that with ilasm but i still get the same errors.

EDIT: These errors were given by ilasm when i try to reassemble the .il file. I also tried to edit the code in Reflector but after editing and trying to save it says that it cannot save mixed mode assemblies. Maybe i would be able to edit the binary in HEX editor?

1
  • added more information to the question Aug 8 '14 at 12:41
2

Depending how extensive your modifications are, the way I've always done it was to only compile the snippet you want to inject (or manually convert the OpCodes) and patch the existing binary rather than recompile

also, IlSpy may be easier for what you want as you can simply go:

.net binary > c# decompiled > .net binary

http://ilspy.net

2
  • Do you mean i can modify the code directly in ilspy? When i tried decompiling the program to C# in ilspy it generated bunch of useless files that contained meaningles junk. If i could edit the code directly in ilspy and recompile that would be great. EDIT: I now exported IL code from ilspy and edited it but how do i assemble the snippet back into the .exe? Aug 6 '14 at 18:12
  • I think you may be running into this: 'Currently, you cannot use this technique with PE files that contain embedded native code (for example, PE files produced by Visual C++).' msdn.microsoft.com/en-us/library/f7dy01k1%28VS.80%29.aspx Aug 6 '14 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.