Jan 2, 2022 02:05 PM
(This post was last modified: Jan 2, 2022 02:05 PM by truco.)
hello,
i'm trying to replace all available strings inside a program to call a function but send the string as param.
for example:
i'm trying to replace to something like this (using dnlib):
so basically what i'm trying to do is encrypt every string inside the program using aes256 and decrypt them when it's running
Here is what i have so far:
I just don't know how to replace the string with a function calling that specific string
i'm trying to replace all available strings inside a program to call a function but send the string as param.
for example:
Code
Result.Append(b.ToString("String"));i'm trying to replace to something like this (using dnlib):
Code
Result.Append(b.ToString(Class1.Aes256Decrypt("EncryptedString")));so basically what i'm trying to do is encrypt every string inside the program using aes256 and decrypt them when it's running
Here is what i have so far:
Code
...
...
foreach (var method in type.Methods)
{
if (!method.HasBody)
continue;
if (method == decryptMethod)
continue;
method.Body.KeepOldMaxStack = true;
for (var i = 0; i < method.Body.Instructions.Count; i++)
{
if (method.Body.Instructions[i].OpCode != OpCodes.Ldstr) continue;
var oldString = method.Body.Instructions[i].Operand.ToString(); //Original String
method.Body.Instructions[i].Operand = Algorithm.Aes256.EncryptString(oldString); //i encrypt the string here
method.Body.Instructions.Insert(i + 1, new Instruction(OpCodes.Call, decryptMethod)); //what do i use for decryptMethod?
}
method.Body.SimplifyBranches();
method.Body.OptimizeBranches();
}I just don't know how to replace the string with a function calling that specific string


