Modding guide
What is the mod for the kernel?
The mod is the kernel extension file that loads on boot and adds extensions to the kernel, the shell, and everything. It can also respond to events.
This is useful if you want to add your own extensions to the kernel, like event handlers for the kernel.
[!TIP] To get started to our Kernel Simulator API, visit this page.
Mod format
The mods have the file extension of .dll
, and can support more than one code file for each mod. This will allow you to make bigger mods that can't fit on one source file, or if you want to separate some parts of the big source code to multiple fragments.
How to start your own mod on Visual Studio?
[!NOTE] We recommend following the template repository for making your own mod here.
If you're going to make your mod, follow these steps:
On the Start Page, click on
New Project
Click on
Class Library (.NET Framework)
orClass Library
, select VB or C#, and name your mod or modpack. Select Framework as.NET Framework 4.8
or.NET 6.0
. When you're finished, clickCreate
.Right-click on References in the Solution Explorer, and press
Manage NuGet packages...
Go to
Browse
, and findKernel Simulator
and install it.You will see that your KS executable files are added to the references. In your project file, this will be added:
The code will be ready in your ModName codefile:
Now, follow these steps to create your first mod:
Between the Public Class... and the End Class lines, let Visual Studio know that you're going to create your KS mod by writing:
Implements IScript
Define properties for mod information by putting below the Implements IScript:
Make your start mod sub named StartMod() that implements the IScript.StartMod, by writing:
Replace every
'Your code below
comment with your code. Repeat this step on all the interface subsMake your mod stop sub named StopMod() that implements the IScript.StopMod, by writing: (You can leave it blank)
Make a command handler, which can be one of the following forms: i) If you're making your commands in your mod, make a class that implements both CommandExecutor and ICommand for each command and include your statements for each:
ii) If you're making your commands which handle text arguments, write the response code below:
iii) If you're making your commands which handle subsequent arguments, write the response code below:
Make an event handler code for your mod, which can be one of the following: i) If you're making your event handler which handles what happened in the kernel, write the handle code below:
ii) If you're handling multiple events, write the handle code below:
iii) IMPORTANT NOTICE! Never try to use infinite loops in handlers unless you're making infinite loops that exits if the specified condition is met, or in the test environment. That will lock the kernel up.
Make the same event handler code, but this time, with arguments provided:
Right-click on the solution and press Build.
Copy the output
.dll
file to KSMods directory in your profile folder (/home/<user>/
in Linux, andUsers\<user>\
in Windows)Run your Kernel Simulator you've just referenced to in your project.
Optional Stuff
You can make your subs anywhere on the class, but if:
they're on the different class, make a separate code file for it:
they're trying to re-initialize the mod by re-calling StartMod(), Try so on your test environment first, then the production environment if that worked properly.
The new subs or functions should meet the following conditions:
They shouldn't make an infinite loop unless you're making them that exits if specified conditions are met
They shouldn't try to cause errors with the kernel.
If you're an exploiter and are making the exploit code for the kernel, do so on your test environment first then the production environment, then make your CVE report so we get attention and fix that quickly.
If your mod is going to extend the kernel, place your extension codes on separate subs
Put your sub call on one of the four subs that implements the IScript interface. Ex. If you're going to make a sub that's going to be called on mod start, place your sub call on the StartMod() sub, and then your code on your sub.
If you're going to add imports, these rules must be met:
Don't import "KS" by itself. KS does that automatically
When importing modules/classes like TextWriterColor, it's written like this:
Imports KS.Misc.Writers.TextWriterColor
You can add dependencies for your mods.
You can also add manual page files to your mods. Consult the Mod Manual Page for more info.
Example
Here is the simplest example of how to make a mod:
Hello World on Mod Start, and Goodbye World on Mod Stop
Hello World is the popular starting example for all of the programmers. These examples usually start with printing the "Hello World" string to the console output or command prompt. To make your first Hello World mod, follow the project creation steps, then follow these steps:
Write below the (assuming that your mod name is HelloGuys) Public Class HelloGuys:
Implements IScript
Write above the Public Class HelloGuys:
Make your start mod event handler by writing:
Make your stop event handler by writing:
Since we're not implementing commands nor event handlers, we're going to leave these blank:
The code should look like this in VB:
...Or in C#:
Right-click on the solution and press Build.
Run the target KS once you copied the generated
.dll
file.
More Examples
If you want to check out more examples, feel free to check them out in the KSModExamples respository in GitHub.
Last updated