VB.NET insert try exception handler & class with method & function & types . using dnlib

-2

Good morning I use dnlib in vb.net We want to inject a class and a function and a try catch exception handler. The place I will insert is an already created exe file, not a new one. I'm looking for an example of it, but I can't find it. The issue on github is also closed so I don't know where to get the example and fix it. Ask Stack Overflow for tips on this. Thanks for reading.

Here is the il code I want to add. Examples that don't relate to my problem are fine. Thank you for reading and please reply Translated by googletranslator

    .method public 
    instance string AES_Decrypt (
        string input,
        string pass
    ) cil managed 
{
    // Header Size: 12 bytes
    // Code Size: 130 (0x82) bytes
    // LocalVarSig Token: 0x11000004 RID: 4
    .maxstack 7
    .locals init (
        [0] string,
        [1] uint8[],
        [2] class [mscorlib]System.Security.Cryptography.ICryptoTransform,
        [3] uint8[],
        [4] class [mscorlib]System.FormatException
    )

    .try
    {
        /* 0x00000640 735300000A   */ IL_0000: newobj    instance void [mscorlib]System.Security.Cryptography.RijndaelManaged::.ctor()
        /* 0x00000645 735400000A   */ IL_0005: newobj    instance void [mscorlib]System.Security.Cryptography.MD5CryptoServiceProvider::.ctor()
        /* 0x0000064A 1F20         */ IL_000A: ldc.i4.s  32
        /* 0x0000064C 8D42000001   */ IL_000C: newarr    [mscorlib]System.Byte
        /* 0x00000651 0B           */ IL_0011: stloc.1
        /* 0x00000652 285500000A   */ IL_0012: call      class [mscorlib]System.Text.Encoding [mscorlib]System.Text.Encoding::get_Unicode()
        /* 0x00000657 04           */ IL_0017: ldarg.2
        /* 0x00000658 6F5600000A   */ IL_0018: callvirt  instance uint8[] [mscorlib]System.Text.Encoding::GetBytes(string)
        /* 0x0000065D 6F5700000A   */ IL_001D: callvirt  instance uint8[] [mscorlib]System.Security.Cryptography.HashAlgorithm::ComputeHash(uint8[])
        /* 0x00000662 25           */ IL_0022: dup
        /* 0x00000663 16           */ IL_0023: ldc.i4.0
        /* 0x00000664 07           */ IL_0024: ldloc.1
        /* 0x00000665 16           */ IL_0025: ldc.i4.0
        /* 0x00000666 1F10         */ IL_0026: ldc.i4.s  16
        /* 0x00000668 285800000A   */ IL_0028: call      void [mscorlib]System.Array::Copy(class [mscorlib]System.Array, int32, class [mscorlib]System.Array, int32, int32)
        /* 0x0000066D 16           */ IL_002D: ldc.i4.0
        /* 0x0000066E 07           */ IL_002E: ldloc.1
        /* 0x0000066F 1F0F         */ IL_002F: ldc.i4.s  15
        /* 0x00000671 1F10         */ IL_0031: ldc.i4.s  16
        /* 0x00000673 285800000A   */ IL_0033: call      void [mscorlib]System.Array::Copy(class [mscorlib]System.Array, int32, class [mscorlib]System.Array, int32, int32)
        /* 0x00000678 25           */ IL_0038: dup
        /* 0x00000679 07           */ IL_0039: ldloc.1
        /* 0x0000067A 6F5900000A   */ IL_003A: callvirt  instance void [mscorlib]System.Security.Cryptography.SymmetricAlgorithm::set_Key(uint8[])
        /* 0x0000067F 25           */ IL_003F: dup
        /* 0x00000680 18           */ IL_0040: ldc.i4.2
        /* 0x00000681 6F5A00000A   */ IL_0041: callvirt  instance void [mscorlib]System.Security.Cryptography.SymmetricAlgorithm::set_Mode(valuetype [mscorlib]System.Security.Cryptography.CipherMode)
        /* 0x00000686 6F5B00000A   */ IL_0046: callvirt  instance class [mscorlib]System.Security.Cryptography.ICryptoTransform [mscorlib]System.Security.Cryptography.SymmetricAlgorithm::CreateDecryptor()
        /* 0x0000068B 0C           */ IL_004B: stloc.2
        /* 0x0000068C 03           */ IL_004C: ldarg.1
        /* 0x0000068D 285C00000A   */ IL_004D: call      uint8[] [mscorlib]System.Convert::FromBase64String(string)
        /* 0x00000692 0D           */ IL_0052: stloc.3
        /* 0x00000693 285500000A   */ IL_0053: call      class [mscorlib]System.Text.Encoding [mscorlib]System.Text.Encoding::get_Unicode()
        /* 0x00000698 08           */ IL_0058: ldloc.2
        /* 0x00000699 09           */ IL_0059: ldloc.3
        /* 0x0000069A 16           */ IL_005A: ldc.i4.0
        /* 0x0000069B 09           */ IL_005B: ldloc.3
        /* 0x0000069C 8E           */ IL_005C: ldlen
        /* 0x0000069D 69           */ IL_005D: conv.i4
        /* 0x0000069E 6F5D00000A   */ IL_005E: callvirt  instance uint8[] [mscorlib]System.Security.Cryptography.ICryptoTransform::TransformFinalBlock(uint8[], int32, int32)
        /* 0x000006A3 6F5E00000A   */ IL_0063: callvirt  instance string [mscorlib]System.Text.Encoding::GetString(uint8[])
        /* 0x000006A8 0A           */ IL_0068: stloc.0
        /* 0x000006A9 DE15         */ IL_0069: leave.s   IL_0080
    } // end .try
    catch [mscorlib]System.FormatException
    {
        /* 0x000006AB 25           */ IL_006B: dup
        /* 0x000006AC 283700000A   */ IL_006C: call      void [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.ProjectData::SetProjectError(class [mscorlib]System.Exception)
        /* 0x000006B1 1304         */ IL_0071: stloc.s   V_4
        /* 0x000006B3 72E9000070   */ IL_0073: ldstr     ""
        /* 0x000006B8 0A           */ IL_0078: stloc.0
        /* 0x000006B9 285F00000A   */ IL_0079: call      void [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.ProjectData::ClearProjectError()
        /* 0x000006BE DE00         */ IL_007E: leave.s   IL_0080
    } // end handler

    /* 0x000006C0 06           */ IL_0080: ldloc.0
    /* 0x000006C1 2A           */ IL_0081: ret
}
c#
.net
vb.net
asked on Stack Overflow Jan 22, 2021 by 1stetcgoldmedal

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0