Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Hi guys. I'm trying to code a system where you can import a C# class (.cs) into a C#

Hi guys,

I'm trying to code a system where you can import a C# class (.cs) into an existing C# program and interact with it programmatically.

All the classes that will be imported have the same method names, variable names and every name except the actual content of those methods, variables etc. Does anyone have any pointers as to where I could get started to make this?

Thanks!
If you're referring to run-time JIT compilation for C# then you would need to use the .NET JIT compiler manually to produce byte-code for the C# classes you are trying to compile at run-time and then would need to figure out how to run that byte-code from memory.
CodeDOM would be the traditional approach if you're looking to use something provided within the .NET framework.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Oct 20, 2019 11:19 PM)0xDEAD10CC Wrote:  CodeDOM would be the traditional approach if you're looking to use something provided within the .NET framework.

In addition to that, Reflection would then traditionally be used to load the assembly up into memory without ever writing to the disk (which in reality does not happen since files will still be written and read from disk during and after compilation using 'temporary files'), granted you utilize the correct parameters when using CodeDOM.

OP will have to unload said assemblies from the AppDomain after completion or risk running into several issues which is easier said than done, not to mention security issues. So ideally he would create a new AppDomain.

Noteworthy here is how as time goes on, new ways of doing this are introduced. Take Roslyn for example in combination with the SyntaxTree API. However, this does not solve the AppDomain issue and code integrity/security flaws that may be introduced when loading external modules.

I will not detail process injection because that is simply a malware tactic (or can be used as such) that can be avoided entirely.
[Image: vp6iypF.gif]
Marshalling data between appdomains is relatively easy though. Most people who have never used appdomains or don't know what they are would simply just load the assembly with normal reflection into the current domain though.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by john ronaldsadJul 20, 2022 06:49 PM 4 234 Jul 20, 2022 06:49 PM
Last Post: john ronaldsad
[C] by lockheadApr 22, 2021 07:10 AM 0 146 Apr 22, 2021 07:10 AM
Last Post: lockhead
[Shell] by Emre_May 27, 2020 04:36 AM 0 104 May 27, 2020 04:36 AM
Last Post: Emre_