Skip to content
This repository was archived by the owner on Oct 5, 2019. It is now read-only.

Commit 0b57103

Browse files
author
Zaczero
committed
Added char encryption
1 parent 6e54618 commit 0b57103

File tree

1 file changed

+124
-1
lines changed

1 file changed

+124
-1
lines changed

SharpLoader/Core/SourceRandomizer.cs

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ private void Trash(ref string str)
586586

587587
private bool _stringDecryptorInjected;
588588
private string _stringDecryptorFunction;
589+
private bool _charDecryptorInjected;
590+
private string _charDecryptorFunction;
589591
private bool _valueDecryptorInjected;
590592
private string _valueDecryptorFunction;
591593
private void Encrypt(ref string str)
@@ -610,7 +612,7 @@ private void Encrypt(ref string str)
610612
var arg = str.Substring(tagIndex + 5, tagLength - 5);
611613

612614
// String
613-
if (arg.Contains('"'))
615+
if (arg.EndsWith("\""))
614616
{
615617
// Inject decryptor
616618
if (!_stringDecryptorInjected)
@@ -730,6 +732,127 @@ private void Encrypt(ref string str)
730732
str = str.Remove(tagIndex, tagLength + 1).Insert(tagIndex, output);
731733
}
732734
}
735+
// Char
736+
else if (arg.EndsWith("'"))
737+
{
738+
// Inject decryptor
739+
if (!_charDecryptorInjected)
740+
{
741+
var namespaceName = GetVariableName(str);
742+
var className = GetVariableName(str);
743+
var funcName = GetVariableName(str);
744+
745+
var baseEncrypted = GetVariableName(str);
746+
var baseDecryptor = GetVariableName(str);
747+
748+
var tmp1 = GetVariableName(str);
749+
var tmp2 = GetVariableName(str);
750+
751+
var decryptorOne = GetVariableName(str);
752+
var decryptorTwo = GetVariableName(str);
753+
754+
var result = GetVariableName(str);
755+
var i = GetVariableName(str);
756+
757+
var a = GetVariableName(str);
758+
var b = GetVariableName(str);
759+
var c = GetVariableName(str);
760+
var d = GetVariableName(str);
761+
762+
Inject.Add($"using System;" +
763+
$"using System.Text;" +
764+
$"namespace {namespaceName}" +
765+
$"{{" +
766+
$"public static class {className}" +
767+
$"{{" +
768+
$"private static byte[] {tmp1};" +
769+
$"private static byte[] {tmp2};" +
770+
$"private static byte[] {result};" +
771+
$"private static byte {decryptorOne};" +
772+
$"private static byte {decryptorTwo};" +
773+
$"private static int {a};" +
774+
$"private static int {b};" +
775+
$"private static int {c};" +
776+
$"private static int {d};" +
777+
$"public static char {funcName}(string {baseEncrypted}, string {baseDecryptor})" +
778+
$"{{" +
779+
$"<flow>" +
780+
$"<swap>" +
781+
$"{tmp1} = Convert.FromBase64String({baseEncrypted});" +
782+
$"{tmp2} = Convert.FromBase64String({baseDecryptor});" +
783+
$"<trash>" +
784+
$"<swap/>" +
785+
$"<swap>" +
786+
$"{result} = new byte[{tmp1}.Length];" +
787+
$"{decryptorOne} = {tmp2}[0];" +
788+
$"{decryptorTwo} = {tmp2}[1];" +
789+
$"<trash>" +
790+
$"<swap/>" +
791+
$"<flow/>" +
792+
$"for(int {i} = 0; {i} < {tmp1}.Length; {i}++)" +
793+
$"{{" +
794+
$"<flow>" +
795+
$"{a} = {decryptorOne} % {decryptorTwo};" +
796+
$"{b} = {i} + {decryptorTwo};" +
797+
$"{c} = {a} * {b};" +
798+
$"{d} = {c} ^ {tmp1}[{i}];" +
799+
$"{result}[{i}] = (byte){d};" +
800+
$"<trash>" +
801+
$"<flow/>" +
802+
$"}}" +
803+
$"<flow>" +
804+
$"<trash>" +
805+
$"return BitConverter.ToChar({result}, 0);" +
806+
$"<flow/>" +
807+
$"return \'\\0\';" +
808+
$"}}" +
809+
$"}}" +
810+
$"}}");
811+
812+
InjectAssemblies.Add("System.dll");
813+
814+
_charDecryptorInjected = true;
815+
_charDecryptorFunction = $"{namespaceName}.{className}.{funcName}";
816+
}
817+
818+
char rawChar;
819+
820+
// Are arguments given?
821+
if (tagLength > 6)
822+
{
823+
// Substring arguments
824+
rawChar = str.Substring(tagIndex + 5, tagLength - 5).Trim('\'')[0];
825+
}
826+
// No arguments
827+
else
828+
{
829+
throw new Exception($"invalid argument value: null");
830+
}
831+
832+
{
833+
var decryptorOne = (byte)_rnd.Next(byte.MinValue, byte.MaxValue);
834+
var decryptorTwo = (byte)_rnd.Next(1, byte.MaxValue);
835+
836+
var stringBytes = BitConverter.GetBytes(rawChar);
837+
838+
var tmp1 = new byte[stringBytes.Length];
839+
840+
for (var i = 0; i < stringBytes.Length; i++)
841+
{
842+
tmp1[i] = (byte)(decryptorOne % decryptorTwo * (i + decryptorTwo) ^ stringBytes[i]);
843+
}
844+
845+
var tmp2 = new[] { decryptorOne, decryptorTwo };
846+
847+
var baseEncrypted = Convert.ToBase64String(tmp1);
848+
var baseDecryptor = Convert.ToBase64String(tmp2);
849+
850+
var output = $"{_charDecryptorFunction}(\"{baseEncrypted}\",\"{baseDecryptor}\")";
851+
852+
// Replace
853+
str = str.Remove(tagIndex, tagLength + 1).Insert(tagIndex, output);
854+
}
855+
}
733856
// Value
734857
else
735858
{

0 commit comments

Comments
 (0)