![]() |
|
[C#] how to replace a string to call a function using dnlib? - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] how to replace a string to call a function using dnlib? (/showthread.php?tid=6187365) |
how to replace a string to call a function using dnlib? - truco - Jan 2, 2022 hello, 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 ...I just don't know how to replace the string with a function calling that specific string RE: how to replace a string to call a function using dnlib? - 0xDEAD10CC - Jan 2, 2022 The method would have to return a string to be suitable for the parameter replacement. You'd effectively be replacing the ldstr instruction with a new set of instructions to load the argument onto the stack, load the string (i.e. the existing ldstr), then an additional call instruction for the method return to be used as the new argument in the original method (presumably). This: Code ldstr "testing"Becomes: Code ldarg.0Or this depending: Code ldarg.0What method are you trying to replace the string argument with? One pre-existing within the assembly? One within the .NET BCL? Or are you trying to dynamically generate one? What is this ToString method in your example? That does not look like the correct use of the default string extension method. RE: how to replace a string to call a function using dnlib? - truco - Jan 3, 2022 (Jan 2, 2022 10:30 PM)0xDEAD10CC Wrote: The method would have to return a string to be suitable for the parameter replacement. You'd effectively be replacing the ldstr instruction with a new set of instructions to load the argument onto the stack, load the string (i.e. the existing ldstr), then an additional call instruction for the method return to be used as the new argument in the original method (presumably). thank you for your answer! so basically calling the function Code Class1.Aes256Decrypt("EncryptedString");the aes decryption function already exists within the program, i don't know how to connect it with dnlib. so for example, it will look something like this Code MessageBox.Show("hello"); <- original linereplaced with : Code MessageBox.Show(Class1.Aes256Decrypt("Rtei3gTSQakRdqQpN05jCA==")); <- "hello" aes256 encrypted, the function will return the decrypted stringthe sample code is taken here : https://github.com/srn-g/EncryptStrings but he encrypts the strings using base64 (plus it's not calling a pre-existing function), i'm trying to encrypt using aes256 |