Skip to content

Commit

Permalink
* Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ko4life-psko committed May 18, 2020
0 parents commit 70d45b2
Show file tree
Hide file tree
Showing 43 changed files with 3,773 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
packages/
.vs/
source/KO-TBLCryptoEditor/obj/
source/KO-TBLCryptoEditor/bin/
UpgradeLog.htm
source/KO-TBLCryptoEditor/FodyWeavers.xml
source/KO-TBLCryptoEditor/FodyWeavers.xsd
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "thirdparty/PatternFinder"]
path = thirdparty/PatternFinder
url = https://github.com/ko4life-net/PatternFinder.git
[submodule "thirdparty/pe"]
path = thirdparty/pe
url = https://github.com/ko4life-net/pe.git
50 changes: 50 additions & 0 deletions KO-TBLCryptoEditor.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30104.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KO-TBLCryptoEditor", "source\KO-TBLCryptoEditor\KO-TBLCryptoEditor.csproj", "{29854838-9FCA-4090-BA6E-85CD54280847}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "thirdparty", "thirdparty", "{1790BEB3-7281-48E1-B189-4EADB596D905}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatternFinder", "thirdparty\PatternFinder\PatternFinder\PatternFinder.csproj", "{5FFB2393-5455-49C1-8D45-3EA5C0F22386}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Workshell.PE", "thirdparty\pe\src\Workshell.PE\Workshell.PE.csproj", "{A08F8A40-9EEA-4A5D-B434-C4FBFD5EFFD8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CI|Any CPU = CI|Any CPU
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{29854838-9FCA-4090-BA6E-85CD54280847}.CI|Any CPU.ActiveCfg = Release|Any CPU
{29854838-9FCA-4090-BA6E-85CD54280847}.CI|Any CPU.Build.0 = Release|Any CPU
{29854838-9FCA-4090-BA6E-85CD54280847}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{29854838-9FCA-4090-BA6E-85CD54280847}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29854838-9FCA-4090-BA6E-85CD54280847}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29854838-9FCA-4090-BA6E-85CD54280847}.Release|Any CPU.Build.0 = Release|Any CPU
{5FFB2393-5455-49C1-8D45-3EA5C0F22386}.CI|Any CPU.ActiveCfg = Release|Any CPU
{5FFB2393-5455-49C1-8D45-3EA5C0F22386}.CI|Any CPU.Build.0 = Release|Any CPU
{5FFB2393-5455-49C1-8D45-3EA5C0F22386}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5FFB2393-5455-49C1-8D45-3EA5C0F22386}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5FFB2393-5455-49C1-8D45-3EA5C0F22386}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5FFB2393-5455-49C1-8D45-3EA5C0F22386}.Release|Any CPU.Build.0 = Release|Any CPU
{A08F8A40-9EEA-4A5D-B434-C4FBFD5EFFD8}.CI|Any CPU.ActiveCfg = CI|Any CPU
{A08F8A40-9EEA-4A5D-B434-C4FBFD5EFFD8}.CI|Any CPU.Build.0 = CI|Any CPU
{A08F8A40-9EEA-4A5D-B434-C4FBFD5EFFD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A08F8A40-9EEA-4A5D-B434-C4FBFD5EFFD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A08F8A40-9EEA-4A5D-B434-C4FBFD5EFFD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A08F8A40-9EEA-4A5D-B434-C4FBFD5EFFD8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5FFB2393-5455-49C1-8D45-3EA5C0F22386} = {1790BEB3-7281-48E1-B189-4EADB596D905}
{A08F8A40-9EEA-4A5D-B434-C4FBFD5EFFD8} = {1790BEB3-7281-48E1-B189-4EADB596D905}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {58EDDF0E-2C5B-4255-B74B-E468E971CD4F}
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 ko4life.net

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Knight Online Table Crypto Editor

This tool will allow targeting any version KnightOnLine.exe and change/update continuously their encryption keys. If you are looking into cheats, you're probably in the wrong place, as this tool is meant to be used for people that are into KO development.

Loading the target executable into the tool will parse all the bytes in the binary that have similar pattern for the encryption algorithm, so when it comes to patching, it knows exactly the right offsets to be patched.

For more information, please visit [ko4life.net](https://www.ko4life.net/).

### Getting Started

You can decide whether you want to build this project from source or download the binary from the Releases [here](https://github.com/ko4life-net/KO-TBLCryptoEditor/releases).

It is recommended that the target exe you load into this tool, will be in the root directory where the client is, so it would automatically detect the Data folder where the tbls are and update their encryption to match with the new keys as well.

Note that if you cannot update Key2, it is because the parser detected that the compiler inlined some of the functions, which made the compiler generate multiple instructions to create the second key dynamically. Therefore, it would only be enabled for executables that do not have inlined functions.

After generating new random keys and clicking the `Update Client Encryption`, make sure the next step you do, is update your TBLs as well by clicking `Update Data Encryption`.

### Preview

![](/media/main_window.png)

You can also view detailed report of the found offsets and target executeable:

![](/media/view_offsets_window.png)

Also note that it detects the encryption algorithm used for the tbls:

![](/media/view_offsets_window2.png)

## Contributing

Pull-Requests are greatly appreciated should you like to contribute to the project.

Same goes for opening issues; if you have any suggestions, feedback or you found any bugs, please do not hesitate to open an [issue](https://github.com/ko4life-net/KO-TBLCryptoEditor/issues) or reach out at [ko4life.net](https://www.ko4life.net/).

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
21 changes: 21 additions & 0 deletions docs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 ko4life.net

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file added media/main_window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/view_offsets_window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/view_offsets_window2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions source/KO-TBLCryptoEditor/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<packageRestore>
<!-- The 'enabled' key is True when the "Allow NuGet to download missing packages" checkbox is set.
Clearing the box sets this to False, disabling command-line, automatic, and MSBuild-integrated restore. -->
<add key="enabled" value="True" />
</packageRestore>
</configuration>
57 changes: 57 additions & 0 deletions source/KO-TBLCryptoEditor/Controls/CryptoKeyInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;

namespace KO.TBLCryptoEditor.Controls
{
public class CryptoKeyInput : TextBox
{
public short Key => Convert.ToInt16(Text, 16);

public CryptoKeyInput()
{
TextChanged += delegate { Validate(); };
}

private void Validate()
{
Action cartToEnd = () =>
{
SelectionStart = Text.Length;
SelectionLength = 0;
};

if (!Text.StartsWith("0x"))
{
Text = "0x";
cartToEnd();
return;
}

if (Text.Length > 6)
{
Text = Text.Substring(0, 6);
cartToEnd();
return;
}

if (Text.Length > 2)
{
if (!Int32.TryParse(Text.Substring(2, Text.Length - 2), NumberStyles.HexNumber,
CultureInfo.CurrentCulture, out int _))
{
Text = "0x";
BackColor = Color.Crimson;
cartToEnd();
return;
}
}


Text = "0x" + Text.Substring(2, Text.Length - 2).ToUpper();
BackColor = Text.Length != 6 ? Color.Crimson : SystemColors.Control;
cartToEnd();
}
}
}
39 changes: 39 additions & 0 deletions source/KO-TBLCryptoEditor/Core/CryptoKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

namespace KO.TBLCryptoEditor.Core
{
public class CryptoKey
{
public long Offset { get; }
public ushort Key { get; }
public long VirtualAddress { get; }

public CryptoKey(long offset, ushort key, long virtualAdderss)
{
Offset = offset;
Key = key;
VirtualAddress = virtualAdderss;
}

public override bool Equals(object obj)
{
CryptoKey key = (CryptoKey)obj;
return key.Offset == Offset
&& key.Key == Key
&& key.VirtualAddress == VirtualAddress;
}

public override int GetHashCode()
{
unchecked
{
return (Offset.GetHashCode() * 397) ^ Key.GetHashCode();
}
}

public override string ToString()
{
return $"[0x{(int)Offset:X8}||0x{(int)VirtualAddress:X8}]: 0x{Key:X4}";
}
}
}
70 changes: 70 additions & 0 deletions source/KO-TBLCryptoEditor/Core/CryptoPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace KO.TBLCryptoEditor.Core
{
public class CryptoPatch : IEnumerable<CryptoKey>
{
public const int KEYS_COUNT = 3;

public long RegionOffset { get; }
public long RegionVA { get; }
public CryptoKey[] Keys { get; set; }
public bool Inlined { get; set; }


public CryptoPatch(long regionOffset, long regionVA, CryptoKey[] keys = null, bool inlined = false)
{
if (keys != null && keys.Length != KEYS_COUNT)
throw new ArgumentException("Mismatched keys length.");

RegionOffset = regionOffset;
RegionVA = regionVA;
Keys = keys ?? new CryptoKey[KEYS_COUNT];
Inlined = inlined;
}

public CryptoKey this[int index]
{
get
{
if (index > KEYS_COUNT - 1)
throw new IndexOutOfRangeException();

return Keys[index];
}
set
{
if (index > KEYS_COUNT - 1)
throw new IndexOutOfRangeException();

Keys[index] = value ?? throw new ArgumentNullException();
}
}

public IEnumerator<CryptoKey> GetEnumerator()
{
foreach (var key in Keys)
yield return key;
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

public override string ToString()
{
return base.ToString();
}

public override int GetHashCode()
{
unchecked
{
return (RegionOffset.GetHashCode() * 397) ^ RegionVA.GetHashCode();
}
}
}
}
Loading

0 comments on commit 70d45b2

Please sign in to comment.