AssemblyLoader
Various implementations for C# in memory execution. Assembly.Load() Assembly.LoadFile() AppDomain.ExecuteAssembly()
Install / Use
/learn @KINGSABRI/AssemblyLoaderREADME
AssemblyLoader
Here, I'm listing various implementations of loading C# in memory in simple code for reference.
Implementations/Techniques
Assembly.Load()
This has been used in two different ways
- The
ExecuteAssemblyLoad1is a very simple and vanilla use ofAssembly.Load() - The
ExecuteAssemblyLoad2it- enumerates namespaces,
- enumerates the classes of each namespece,
- enumerates the methods of each class,
- enumerates the parameters of each method
- then finally call the method to be executed.
Assembly.LoadFile()
The ExecuteAssemblyLoadFile is a vanilla use of Assembly.LoadFile()
AppDomain.ExecuteAssembly()
The ExecuteAssemblyLoadFileAppDomain is using AppDomain to load the assembly, execute it then unload the AppDomain.
Usage
Executing an assembly without arguments
C:\AssemblyLoader\AssemblyLoaderX\bin\Release\AssemblyLoaderX.exe C:\Tools\JustACommand.exe
result
[*] Using Assembly.Load 1:
I've been executed successfully!
[*] Using Assembly.Load 2:
[*] Loaded Type 'JustACommand.Program'
[*] Loading Method 'CallMeIfYouCan'
[*] Enumerating Method Parameters:
- parameter type: 'System.String[] names'
[*] Loading Method 'CallMeIfYouCan2'
[*] Enumerating Method Parameters:
- parameter type: 'System.String name'
[!] Ops, wrong method name 'CallMeIfYouCan2'
[*] Loading Method 'Equals'
[*] Enumerating Method Parameters:
- parameter type: 'System.Object obj'
[*] Loading Method 'GetHashCode'
[*] Enumerating Method Parameters:
[!] Ops, wrong method name 'GetHashCode'
[*] Loading Method 'GetType'
[*] Enumerating Method Parameters:
[!] Ops, wrong method name 'GetType'
[*] Loading Method 'ToString'
[*] Enumerating Method Parameters:
[!] Ops, wrong method name 'ToString'
[*] Using Assembly.LoadFile:
I've been executed successfully!
[*] Using ExecuteAssemblyLoadFileAppDomain1:
[+] Executing 'JustACommand.exe' in 'King AppDomain' AppDomain.
I've been executed successfully!
Executing an assembly with arguments
C:\AssemblyLoader\AssemblyLoaderX\bin\Release\AssemblyLoaderX.exe C:\Tools\JustACommandWithArgs.exe "111 222 333"
result
[*] Using Assembly.Load 1:
Hi 111!
Hi 222!
Hi 333!
[*] Using Assembly.Load 2:
[*] Loaded Type 'JustACommandWithArgs.Program'
[*] Loading Method 'Equals'
[*] Enumerating Method Parameters:
- parameter type: 'System.Object obj'
[*] Loading Method 'GetHashCode'
[*] Enumerating Method Parameters:
[!] Ops, wrong method name 'GetHashCode'
[*] Loading Method 'GetType'
[*] Enumerating Method Parameters:
[!] Ops, wrong method name 'GetType'
[*] Loading Method 'ToString'
[*] Enumerating Method Parameters:
[!] Ops, wrong method name 'ToString'
[*] Using Assembly.LoadFile:
Hi 111!
Hi 222!
Hi 333!
[*] Using ExecuteAssemblyLoadFileAppDomain1:
[+] Executing 'JustACommandWithArgs.exe' in 'King AppDomain' AppDomain.
Hi 111!
Hi 222!
Hi 333!
Executing an assembly without arguments and enumerate all class methods (not the "Main" method) to be executed.
See Assembly.Load 2 enumerating all the namesspace classes then enumerate all methods in that class and try to execute it.
It's going to find CallMeIfYouCan method, enumerate its parameters then call it for execution.
C:\AssemblyLoader\AssemblyLoaderX\bin\Release\AssemblyLoaderX.exe C:\Tools\JustACommand.exe "111 222 333"
result
[*] Using Assembly.Load 1:
I've been executed successfully!
[*] Using Assembly.Load 2: <-----
[*] Loaded Type 'JustACommand.Program'
[*] Loading Method 'CallMeIfYouCan'
[*] Enumerating Method Parameters:
- parameter type: 'System.String[] names'
CallMeIfYouCan says: Hello, 111!.
CallMeIfYouCan says: Hello, 222!.
CallMeIfYouCan says: Hello, 333!.
[*] Loading Method 'CallMeIfYouCan2'
[*] Enumerating Method Parameters:
- parameter type: 'System.String name'
[!] Ops, wrong method name 'CallMeIfYouCan2'
[*] Loading Method 'Equals'
[*] Enumerating Method Parameters:
- parameter type: 'System.Object obj'
[*] Loading Method 'GetHashCode'
[*] Enumerating Method Parameters:
[!] Ops, wrong method name 'GetHashCode'
[*] Loading Method 'GetType'
[*] Enumerating Method Parameters:
[!] Ops, wrong method name 'GetType'
[*] Loading Method 'ToString'
[*] Enumerating Method Parameters:
[!] Ops, wrong method name 'ToString'
[*] Using Assembly.LoadFile:
I've been executed successfully!
[*] Using ExecuteAssemblyLoadFileAppDomain1:
[+] Executing 'JustACommand.exe' in 'King AppDomain' AppDomain.
I've been executed successfully!
Resources
- https://www.csharpcodi.com/csharp-examples/System.Reflection.Assembly.Load(byte[])/
- https://exord66.github.io/csharp-in-memory-assemblies
- https://blog.netspi.com/net-reflection-without-system-reflection-assembly/
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
