C # Assembly generation 07, tampered with Assembly

Source: Internet
Author: User
Tags mscorlib

The following aspects are used to differentiate different assemblies:
○ Assembly name: Name
○ Assembly version: Version
○ Assembly Public Key: Public token
○ Assembly culture: Culture

 

If you do not strictly follow these steps to create an assembly, the Assembly is easily tampered. This article describes how to tamper with the Assembly.

 

→ Clear all files in the as folder of drive F
→ Create the dog. CS class in the as folder, open it in notepad, write as follows, and save

using System;
public class Dog
{
    public static void MakeSound()
    {
Console. writeline ("Wang ");
    }
}

→ Compile dog. cs into an assembly

→ Decompile the dog. dll assembly and view the Il code

 

// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly Dog
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                             63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.
  .hash algorithm 0x00008004
  .ver 0:0:0:0
}
.module Dog.dll
// MVID: {A8BAEEAB-2DF4-425C-B851-87260378D735}
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x00400000
// =============== CLASS MEMBERS DECLARATION ===================
.class public auto ansi beforefieldinit Dog
       extends [mscorlib]System.Object
{
  .method public hidebysig static void  MakeSound() cil managed
  {
// Code size 13 (0xd)
    .maxstack  8
    IL_0000:  nop
    IL_0001:  ldstr      bytearray (6A 6C 6A 6C 6A 6C )                               // jljljl
    IL_0006:  call       void [mscorlib]System.Console::WriteLine(string)
    IL_000b:  nop
    IL_000c:  ret
  } // end of method Dog::MakeSound
  .method public hidebysig specialname rtspecialname 
          instance void  .ctor() cil managed
  {
// Code size 7 (0x7)
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
    IL_0006:  ret
  } // end of method Dog::.ctor
} // end of class Dog

○. Assembly dog indicates that the Assembly name is dog.
○. Ver 0: 0: 0: 0: 0 in the Assembly dog statement block indicates that the Assembly version has not been specially set.
○ The Assembly dog statement block does not contain public token or culture information.

→ Create the mainclass. CS class in the as folder, open it in notepad, write as follows, and save

using System;
class MainClass
{
    static void Main()
    {
        Dog.MakeSound();
    }
}

Compile and translate mainclass.cs, and use dog.dllto generate mainclass.exe.

→Mainclass.exe

→ If you want to tamper with dog. dll, delete dog. dll first.

→ Create the anotherdog. CS class in the as folder, open it in notepad, write as follows, and save

using System;
public class Dog
{
    public static void MakeSound()
    {
Console. writeline ("How is a puppy called ~ ");
    }
}

→ Compile the anotherdog. CS class and generate a dog. dll assembly.

Then run mainclass.exe.

The Assembly has been tampered.

 

Summary: When an assembly is generated, it is easy to tamper with the Assembly if no special settings are made for the assembly version, public key, and culture.

 

"C # Assembly series" includes:

C # Assembly series 01, use NotePad to write C # And il code, use the DOS command to compile the assembly, and run the C # Assembly series 02 program, use NotePad to view the Il code C # Assembly series 03 of the executable assembly, reference multiple Module C # Assembly series 04, when an Assembly contains multiple modules, you can understand the keyword internal C # Assembly generation 05, so that the Assembly contains multiple modules C # Assembly generation 06, assembly list, differences between EXE and dll c # Assembly series 07: tampered with Assembly

 

References:

Http://www.computersciencevideos.org/created by Jamie King

C # Assembly generation 07, tampered with Assembly

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.