Run a C# Program without having .NET Framework [duplicate] - c#

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Can you compile C# without using the .Net framework?
im sure it's a common question. I did read about it but I don't know how to actually do it.
I did see an answer over here that to remove system.dll and another reference, but I can't because I use them, so I read that I can include the Framework in my program or something like that. but how?
Thanks!
Edit: I mean to run after I compiled, sorry, my mistake

I'm afraid that you cannot compile a C# program without the .NET Framework (or equivalent such as Mono) it was written for. There are some ways you can run a program without the framework, but not compile.

I would say, no by my opinion. You need "something" that compiles your code into binary. Will be this .NET Framework, Mono, MyOwnVeryCool framework, you have to have some dependency. If you think about .NET platform you need to compile to IL, so you have a dependecy from CLR, if you don't want compile to IL, so it's not more .NET platform.
Consider the fact also, that on latest Windows OS its already shipped "builtin".
Regards.

Related

Prevent Decompiling [duplicate]

This question already has answers here:
How can I obfuscate my c# code, so it can't be deobfuscated so easily? [closed]
(4 answers)
Closed 5 years ago.
I have made an PC app in visual studio 2017 .net c# and compiled it to an exe. And then I thought my code was safe and nobody could see it because it was compiled, but when I open the exe in a program like .net reflector I can see the source code.
Is there any way I can prevent that? Or protect me against Decompiling??
There's really no point in attempting this.
While you'll be inundated with "obfuscation", this is a poor waste of time.
Deobfuscators are getting better all the time.
If someone wants your code bad enough they'll get it no matter what you do.
Frankly, if you are asking this question then the code you wrote isn't worth the time it would take to protect it.
You cannot prevent decompiling, if you compile into MSIL (intermediate language). In such case you need to use obfuscation
For a deeper discussion on the subject check out this post .NET obfuscation tools/strategy
You can find a similar discussion here How can I obfuscate my c# code, so it can't be deobfuscated so easily?
You can also opt to generate a native image using Ngen.exe for a specific platform - that will bypass the IL and generate compiled processor specific machine code, and that one is pretty much safe from standpoint of reverse - engineering.
Using an IL is a quite common design choice - and it has it's drawbacks and benefits - the main ones being easier support of multiple languages on one platform, and multiple target platforms, i.e cross platform
To get a glimpse of some of the benefits of using IL - check this out - stackoverflow.com/questions/1926386/…
Java also uses an intermediate language - java bytecode - javaworld.com/article/2077233/core-java/bytecode-basics.html

Injecting a .Net process into a Unity process [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'd like to know how to inject a C# DLL into a Unity process. Since Unity hosts a CLR (as it runs mono MSIL), I'd imagine I could play around with reflection.
So how would I inject a .NET DLL into a .Net process, and what can I do in terms of reflection once I'm in there?
For example. Say i have a game that uses unity3d as the engine, with most of the code writtin in C# (that doesn't matter since unity seems to compile unityscript to .net anyway). I want to extend this already written codebase with my own code.
Typically in a normal native process you would start reversing the code, finding pointers and data structures as they appear in memory, gaining an understanding of the code as you go along. Then writing the same structures in your code, obtain rwx access to that processes memory (typically by injecting a dll into that process) and then going to town.
Since unity uses .net however, i was wondering if there was a better way. I'd like to leverage the reflection capabilities of the .net framework. For this I think I'd need to get my code injected into the unity process. From there i don't know how a workflow might be.
Long story short: I'd like to inject a DLL, with a payload written in C# (hopefully using reflection instead of pointers), into a foreign process (i don't have control over it at compile time), and mess around with the processes internal classes and functions.
One option is the .cctor function (module initializer), which does NOT run on assembly load, but rather the first invocation into your dll.
Previously, I thought this was the earliest you could get with .net, but apparently I'm mistaken:
There's a horrible, nasty hack that lets you run a DllMain in .net - C# equivalent of DllMain in C (WinAPI)
This is certainly not something that was intended by the creators of .net. Be careful when using it.
This gets your code running, and once in, you can invoke System.Reflection like normal and do whatever you want.
Drop the DLL into an asset folder
Assets/Libs/MyLib.dll
Open any CS file and in the MonoDevelop solution add the reference.
When you quit MonoDevelop Unity will refetch the solution file and import the dll's reference.
You can now use your library from Unity code that you write in MonoDevelop just as normal.
There will be no difference between your code and any other API like System.IO.
Pay attention to the .NET framework versions, don't mix code.
To be safe, use .NET 2.0. ...wait... I don't remember but it should be 2.0... don't quote me on that.
Once you're there you can do everything as normal.

How to go from published .net project back to original source code project [duplicate]

This question already has answers here:
How do I decompile a .NET EXE into readable C# source code?
(9 answers)
Closed 9 years ago.
I have a deployed .Net project(debug version). It doesn't have any of the code behind files.
What I would like to do is get back the original project including the c# files in the right folders.
You need to use a decompilation toolkit like the free Jetbrains dotPeek.
I see that Chris has recommended Redgate's .Net Reflector - historically this was good but has become slow and bloated as of late not to mention it is no longer free. Would highly recommend dotPeek over it.
You want reflector: http://www.red-gate.com/products/dotnet-development/reflector/
It's purpose is to reverse engineer assemblies. As long as these weren't compiled with an obfuscator you ought to be good. Bear in mind that the last time I had to do this to decompile a website, there was a LOT of work that still needed to occur to get the code back into a usable state.
If this was your fault, use source control next time... If you are picking up from someone else's mess, make sure you charge extra and recommend they use source control. If that someone else had purposely destroyed code, recommend that they be sued.
Note that I've also used the above to dig into LINQ (a few years ago) to locate some interesting bugs. It's a pretty good tool.

Creating a 32 Bit DLL using C# or Java [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Converting .NET App to x86 native code
is there a way to create a standard (not .NET Assembly type) 32Bit DLL for Windows using C# or Java?
And for WinCE ??
Thank you
This was referenced in one of the comments, but I wanted to post it as an answer:
For C#:
https://stackoverflow.com/a/1779505/490561
Basically, the idea is to use Mono and then Ahead Of Time Compilation. I think that'd do the trick.
For Java, the idea is similar:
https://stackoverflow.com/a/2011727/490561

convert c# to pure java? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
is there an effective tool to convert c# to java?
I'm not very experienced with Java and have a lot of C# that I would like to translate into Java syntax so it would become compilable.
Reason: Android and Google Cloud
I know the API/Platforms have different structures, but lets say we dont need a 100% compability, but just to get "core functionalitet" translated. The GUI itself is one story of its own, as I've learned. But instead of rewriting every SWITCH-CASE, rebuild every Class etc. it would be nice to "map" the objects to Java equals and then do a recompile on the Android/Google platform.
I am sure there would be something that cant be translated as its a "C# only thing" - but just like every language is possible to generate .NET/MONO I thought there might be a Java -> .Net available too and therefore also a decompiler kinda thing?
So are there any easy ways to overcome this translation by Frameworks, SDK or other similar methods that will take 80-95% of the task automatically?
Have a look here: JSC.
But beside, there are some c# concepts which don't easyli translate into java.
.NET and Mono are compatible because both are VMs that run C# code. Grasshopper claims to allow you to run .NET classes on the JVM, but I haven't used it. It won't work at all for Android because Android isn't the JVM, but rather Dalvik.
The differences between C# and Java are more than "structural" as you put it, and translating from one language to another is more complicated than I think you understand.
I know Microsoft has a tool that's supposed to help convert Java to C#, but considering that a great many java applications reference libraries outside of the main system (apache being the most prominent example) this type of tool would be a monumental task.
C# also has data types that aren't supported at all in Java, such as unsigned types and stack-allocated objects. Writing translations from CLR to Java bytecode would be difficult indeed. And if you're using lambda functions in your code, kiss this idea goodbye.
Then there's the fact that not all language features in Java are available to the Davlik JVM.
I'm not a microsoft fanboy, but here's a comparison of the two languages that will give you an idea why I doubt this tool exists.
http://en.wikipedia.org/wiki/Comparison_of_C_Sharp_and_Java

Categories