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

Commit ce73d2d

Browse files
author
Zaczero
committed
Improved injected methods speed
1 parent c3f28d6 commit ce73d2d

File tree

1 file changed

+57
-88
lines changed

1 file changed

+57
-88
lines changed

SharpLoader/Core/SourceRandomizer.cs

Lines changed: 57 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,6 @@ private void Encrypt(ref string str)
624624
var baseEncrypted = GetVariableName(str);
625625
var baseDecryptor = GetVariableName(str);
626626

627-
var tmp1 = GetVariableName(str);
628-
var tmp2 = GetVariableName(str);
629-
630-
var decryptorOne = GetVariableName(str);
631-
var decryptorTwo = GetVariableName(str);
632-
633627
var result = GetVariableName(str);
634628
var i = GetVariableName(str);
635629

@@ -644,39 +638,32 @@ private void Encrypt(ref string str)
644638
$"{{" +
645639
$"public static class {className}" +
646640
$"{{" +
647-
$"private static byte[] {tmp1};" +
648-
$"private static byte[] {tmp2};" +
649641
$"private static byte[] {result};" +
650-
$"private static byte {decryptorOne};" +
651-
$"private static byte {decryptorTwo};" +
652642
$"private static int {a};" +
653643
$"private static int {b};" +
654644
$"private static int {c};" +
655645
$"private static int {d};" +
656-
$"public static string {funcName}(string {baseEncrypted}, short {baseDecryptor})" +
646+
$"public static string {funcName}(byte[] {baseEncrypted}, byte[] {baseDecryptor})" +
657647
$"{{" +
658648
$"<flow>" +
659649
$"<swap>" +
660-
$"{tmp1} = Convert.FromBase64String({baseEncrypted});" +
661-
$"{tmp2} = BitConverter.GetBytes({baseDecryptor});" +
662-
$"<trash>" +
663-
$"<swap/>" +
664-
$"<swap>" +
665-
$"{result} = new byte[{tmp1}.Length];" +
666-
$"{decryptorOne} = {tmp2}[0];" +
667-
$"{decryptorTwo} = {tmp2}[1];" +
650+
$"{result} = new byte[{baseEncrypted}.Length];" +
668651
$"<trash>" +
669652
$"<swap/>" +
670653
$"<flow/>" +
671-
$"for(int {i} = 0; {i} < {tmp1}.Length; {i}++)" +
654+
$"for(int {i} = 0; {i} < {baseEncrypted}.Length; {i}++)" +
672655
$"{{" +
673656
$"<flow>" +
674-
$"{a} = {decryptorOne} % {decryptorTwo};" +
675-
$"{b} = {i} + {decryptorTwo};" +
657+
$"{a} = {baseDecryptor}[0] % {baseDecryptor}[1];" +
658+
$"<trash 4>" +
659+
$"{b} = {i} + {baseDecryptor}[1];" +
660+
$"<trash 4>" +
676661
$"{c} = {a} * {b};" +
677-
$"{d} = {c} ^ {tmp1}[{i}];" +
662+
$"<trash 4>" +
663+
$"{d} = {c} ^ {baseEncrypted}[{i}];" +
664+
$"<trash 4>" +
678665
$"{result}[{i}] = (byte){d};" +
679-
$"<trash>" +
666+
$"<trash 4>" +
680667
$"<flow/>" +
681668
$"}}" +
682669
$"<flow>" +
@@ -723,10 +710,10 @@ private void Encrypt(ref string str)
723710

724711
var tmp2 = new[] { decryptorOne, decryptorTwo };
725712

726-
var baseEncrypted = Convert.ToBase64String(tmp1);
727-
var baseDecryptor = BitConverter.ToInt16(tmp2, 0);
713+
var baseEncrypted = ByteArrayToString(tmp1);
714+
var baseDecryptor = ByteArrayToString(tmp2);
728715

729-
var output = $"{_stringDecryptorFunction}(\"{baseEncrypted}\",{baseDecryptor})";
716+
var output = $"{_stringDecryptorFunction}({baseEncrypted},{baseDecryptor})";
730717

731718
// Replace
732719
str = str.Remove(tagIndex, tagLength + 1).Insert(tagIndex, output);
@@ -745,12 +732,6 @@ private void Encrypt(ref string str)
745732
var baseEncrypted = GetVariableName(str);
746733
var baseDecryptor = GetVariableName(str);
747734

748-
var tmp1 = GetVariableName(str);
749-
var tmp2 = GetVariableName(str);
750-
751-
var decryptorOne = GetVariableName(str);
752-
var decryptorTwo = GetVariableName(str);
753-
754735
var result = GetVariableName(str);
755736
var i = GetVariableName(str);
756737

@@ -765,39 +746,32 @@ private void Encrypt(ref string str)
765746
$"{{" +
766747
$"public static class {className}" +
767748
$"{{" +
768-
$"private static byte[] {tmp1};" +
769-
$"private static byte[] {tmp2};" +
770749
$"private static byte[] {result};" +
771-
$"private static byte {decryptorOne};" +
772-
$"private static byte {decryptorTwo};" +
773750
$"private static int {a};" +
774751
$"private static int {b};" +
775752
$"private static int {c};" +
776753
$"private static int {d};" +
777-
$"public static char {funcName}(string {baseEncrypted}, short {baseDecryptor})" +
754+
$"public static char {funcName}(byte[] {baseEncrypted}, byte[] {baseDecryptor})" +
778755
$"{{" +
779756
$"<flow>" +
780757
$"<swap>" +
781-
$"{tmp1} = Convert.FromBase64String({baseEncrypted});" +
782-
$"{tmp2} = BitConverter.GetBytes({baseDecryptor});" +
783-
$"<trash>" +
784-
$"<swap/>" +
785-
$"<swap>" +
786-
$"{result} = new byte[{tmp1}.Length];" +
787-
$"{decryptorOne} = {tmp2}[0];" +
788-
$"{decryptorTwo} = {tmp2}[1];" +
758+
$"{result} = new byte[{baseEncrypted}.Length];" +
789759
$"<trash>" +
790760
$"<swap/>" +
791761
$"<flow/>" +
792-
$"for(int {i} = 0; {i} < {tmp1}.Length; {i}++)" +
762+
$"for(int {i} = 0; {i} < {baseEncrypted}.Length; {i}++)" +
793763
$"{{" +
794764
$"<flow>" +
795-
$"{a} = {decryptorOne} % {decryptorTwo};" +
796-
$"{b} = {i} + {decryptorTwo};" +
765+
$"{a} = {baseDecryptor}[0] % {baseDecryptor}[1];" +
766+
$"<trash 4>" +
767+
$"{b} = {i} + {baseDecryptor}[1];" +
768+
$"<trash 4>" +
797769
$"{c} = {a} * {b};" +
798-
$"{d} = {c} ^ {tmp1}[{i}];" +
770+
$"<trash 4>" +
771+
$"{d} = {c} ^ {baseEncrypted}[{i}];" +
772+
$"<trash 4>" +
799773
$"{result}[{i}] = (byte){d};" +
800-
$"<trash>" +
774+
$"<trash 4>" +
801775
$"<flow/>" +
802776
$"}}" +
803777
$"<flow>" +
@@ -844,10 +818,10 @@ private void Encrypt(ref string str)
844818

845819
var tmp2 = new[] { decryptorOne, decryptorTwo };
846820

847-
var baseEncrypted = Convert.ToBase64String(tmp1);
848-
var baseDecryptor = BitConverter.ToInt16(tmp2, 0);
821+
var baseEncrypted = ByteArrayToString(tmp1);
822+
var baseDecryptor = ByteArrayToString(tmp2);
849823

850-
var output = $"{_charDecryptorFunction}(\"{baseEncrypted}\",{baseDecryptor})";
824+
var output = $"{_charDecryptorFunction}({baseEncrypted},{baseDecryptor})";
851825

852826
// Replace
853827
str = str.Remove(tagIndex, tagLength + 1).Insert(tagIndex, output);
@@ -867,11 +841,6 @@ private void Encrypt(ref string str)
867841
var baseDecryptor = GetVariableName(str);
868842

869843
var encrypted = GetVariableName(str);
870-
var decryptorOne = GetVariableName(str);
871-
var decryptorTwo = GetVariableName(str);
872-
873-
var tmp1 = GetVariableName(str);
874-
var tmp2 = GetVariableName(str);
875844

876845
var a = GetVariableName(str);
877846
var b = GetVariableName(str);
@@ -882,32 +851,23 @@ private void Encrypt(ref string str)
882851
$"{{" +
883852
$"public static class {className}" +
884853
$"{{" +
885-
$"private static byte[] {tmp1};" +
886-
$"private static byte[] {tmp2};" +
887854
$"private static int {encrypted};" +
888-
$"private static byte {decryptorOne};" +
889-
$"private static byte {decryptorTwo};" +
890855
$"private static int {a};" +
891856
$"private static int {b};" +
892857
$"private static int {c};" +
893-
$"public static int {funcName}(string {baseEncrypted}, short {baseDecryptor})" +
858+
$"public static int {funcName}(byte[] {baseEncrypted}, byte[] {baseDecryptor})" +
894859
$"{{" +
895860
$"<flow>" +
896861
$"<swap>" +
897-
$"{tmp1} = Convert.FromBase64String({baseEncrypted});" +
898-
$"{tmp2} = BitConverter.GetBytes({baseDecryptor});" +
899-
$"<trash>" +
900-
$"<swap/>" +
901-
$"<swap>" +
902-
$"{encrypted} = BitConverter.ToInt32({tmp1}, 0);" +
903-
$"{decryptorOne} = {tmp2}[0];" +
904-
$"{decryptorTwo} = {tmp2}[1];" +
862+
$"{encrypted} = BitConverter.ToInt32({baseEncrypted}, 0);" +
905863
$"<trash>" +
906864
$"<swap/>" +
907-
$"{a} = {decryptorOne} % {decryptorTwo};" +
908-
$"{b} = {a} * {decryptorTwo};" +
865+
$"{a} = {baseDecryptor}[0] % {baseDecryptor}[1];" +
866+
$"<trash 4>" +
867+
$"{b} = {a} * {baseDecryptor}[1];" +
868+
$"<trash 4>" +
909869
$"{c} = {b} ^ {encrypted};" +
910-
$"<trash>" +
870+
$"<trash 4>" +
911871
$"return {c};" +
912872
$"<flow/>" +
913873
$"return 0;" +
@@ -959,10 +919,10 @@ private void Encrypt(ref string str)
959919
var tmp1 = BitConverter.GetBytes(encrypted);
960920
var tmp2 = new[] {decryptorOne, decryptorTwo};
961921

962-
var baseEncrypted = Convert.ToBase64String(tmp1);
963-
var baseDecryptor = BitConverter.ToInt16(tmp2, 0);
922+
var baseEncrypted = ByteArrayToString(tmp1);
923+
var baseDecryptor = ByteArrayToString(tmp2);
964924

965-
var output = $"{_valueDecryptorFunction}(\"{baseEncrypted}\", {baseDecryptor})";
925+
var output = $"{_valueDecryptorFunction}({baseEncrypted}, {baseDecryptor})";
966926

967927
// Replace
968928
str = str.Remove(tagIndex, tagLength + 1).Insert(tagIndex, output);
@@ -1084,7 +1044,6 @@ private void Flow(ref string str)
10841044

10851045
var tmp1 = GetVariableName(str);
10861046
var tmp2 = GetVariableName(str);
1087-
var tmp3 = GetVariableName(str);
10881047

10891048
var decryptorOne = GetVariableName(str);
10901049
var decryptorTwo = GetVariableName(str);
@@ -1096,23 +1055,21 @@ private void Flow(ref string str)
10961055
$"{{" +
10971056
$"public static class {className}" +
10981057
$"{{" +
1099-
$"private static byte[] {tmp1};" +
1058+
$"private static byte[] {tmp1} = new byte[4];" +
11001059
$"private static byte[] {tmp2} = new byte[4];" +
1101-
$"private static byte[] {tmp3} = new byte[4];" +
11021060
$"private static int {decryptorOne};" +
11031061
$"private static int {decryptorTwo};" +
11041062
$"private static int {result};" +
1105-
$"public static int {funcName}(long {baseDecryptor})" +
1063+
$"public static int {funcName}(byte[] {baseDecryptor})" +
11061064
$"{{" +
1107-
$"{tmp1} = BitConverter.GetBytes({baseDecryptor});" +
11081065
$"<swap>" +
1109-
$"Array.Copy({tmp1}, 0, {tmp2}, 0, 4);" +
1110-
$"Array.Copy({tmp1}, 4, {tmp3}, 0, 4);" +
1066+
$"Array.Copy({baseDecryptor}, 0, {tmp1}, 0, 4);" +
1067+
$"Array.Copy({baseDecryptor}, 4, {tmp2}, 0, 4);" +
11111068
$"<trash>" +
11121069
$"<swap/>" +
11131070
$"<swap>" +
1114-
$"{decryptorOne} = BitConverter.ToInt32({tmp2}, 0);" +
1115-
$"{decryptorTwo} = BitConverter.ToInt32({tmp3}, 0);" +
1071+
$"{decryptorOne} = BitConverter.ToInt32({tmp1}, 0);" +
1072+
$"{decryptorTwo} = BitConverter.ToInt32({tmp2}, 0);" +
11161073
$"<trash>" +
11171074
$"<swap/>" +
11181075
$"<swap>" +
@@ -1193,7 +1150,7 @@ private void Flow(ref string str)
11931150
var tmp1 = new byte[8];
11941151
Array.Copy(tmp2, 0, tmp1, 0, 4);
11951152
Array.Copy(tmp3, 0, tmp1, 4, 4);
1196-
var baseDecryptor = BitConverter.ToInt64(tmp1, 0);
1153+
var baseDecryptor = ByteArrayToString(tmp1);
11971154

11981155
cases[i] = $"case {switchValues[i]}:{{{finalBlocks[i]}{switchName}={_xorDecryptorFunction}({baseDecryptor});break;}}<block>";
11991156
}
@@ -1350,5 +1307,17 @@ private string[] GetCodeBlocks(string str)
13501307

13511308
return blocks;
13521309
}
1310+
1311+
private string ByteArrayToString(byte[] byteArray)
1312+
{
1313+
var returnSb = new StringBuilder("new byte[] {");
1314+
foreach (var b in byteArray)
1315+
{
1316+
returnSb.Append(' ' + b.ToString() + ',');
1317+
}
1318+
returnSb.Remove(returnSb.Length - 1, 1);
1319+
returnSb.Append("}");
1320+
return returnSb.ToString();
1321+
}
13531322
}
13541323
}

0 commit comments

Comments
 (0)