0

i'm trying to replace a string to call a function but send the string as param (the function will return something)

Result.Append(b.ToString("AnyString"));

i'm trying to replace to something like this:

Result.Append(b.ToString(Class1.Function1("AnyString")));

using dnlib

what i have :

...
...
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();
    }
jazb
  • 5,498
  • 6
  • 37
  • 44
Gil13
  • 1
  • 1
  • Try this: `Result.Append(Class1.Function1("AnyString").ToString()));`. Does that give you what you want? Note in the first example `"AnyString"` is a formatprovider, not the the sting itself. if the function returns a string, you can use: `Result.Append(Class1.Function1("AnyString"));`. – Poul Bak Jan 03 '22 at 01:30
  • thanks for your answer, I'm trying to do it through dnlib (3rd example), the first example is how it looks like and the second example is how i'm trying to make it look like (with dnlib). so basically i want to add a call to Class1.Function1 and adding the string as a param (with dnlib) – Gil13 Jan 03 '22 at 01:40

0 Answers0