.Net 静态水印
所谓的软件水印就是把程序的版权信息和用户身份信息嵌入到程序中。根据不同阶段将信息嵌入到程序中可以分为静态水印和动态水印,静态水印是将信息写在代码中,而动态水印则是将信息保存在程序的执行状态中,而不是程序源代码本身。
[coolcode]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Plz input the string that you want to calculate :”);
string in_string=Console.ReadLine();
Console.WriteLine(Length(in_string));
}
static int Length(string str)
{
return str.Length;
}
}
}
[/coolcode]
选择工具 IL反汇编程序
导入编译后生成后的.exe文件,并转储
则得到下面的代码
[coolcode]
// Microsoft (R) .NET Framework IL Disassembler. Version 3.5.30729.1
// Metadata version: v2.0.50727
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 2:0:0:0
}
.assembly HelloWorld
{
.custom instance void [mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 0A 48 65 6C 6C 6F 57 6F 72 6C 64 00 00 ) // …HelloWorld..
.custom instance void [mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 09 4D 69 63 72 6F 73 6F 66 74 00 00 ) // …Microsoft..
.custom instance void [mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00 0A 48 65 6C 6C 6F 57 6F 72 6C 64 00 00 ) // …HelloWorld..
.custom instance void [mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) = ( 01 00 1B 43 6F 70 79 72 69 67 68 74 20 C2 A9 20 // …Copyright ..
4D 69 63 72 6F 73 6F 66 74 20 32 30 31 30 00 00 ) // Microsoft 2010..
.custom instance void [mscorlib]System.Reflection.AssemblyTrademarkAttribute::.ctor(string) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 33 33 38 63 38 39 30 63 2D 38 37 32 66 // ..$338c890c-872f
2D 34 38 35 32 2D 39 66 37 36 2D 64 32 31 64 66 // -4852-9f76-d21df
35 31 38 35 66 37 30 00 00 ) // 5185f70..
.custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 31 2E 30 2E 30 2E 30 00 00 ) // …1.0.0.0..
// — 下列自定义属性会自动添加,不要取消注释 ——-
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 )
.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 1:0:0:0
}
.module HelloWorld.exe
// MVID: {A9CAEE52-9DC8-47CB-BB6F-CF5E9CD08A25}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x03330000
// =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi beforefieldinit HelloWorld.Program
extends [mscorlib]System.Object
{
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// 代码大小 31 (0x1f)
.maxstack 1
.locals init ([0] string in_string)
IL_0000: nop
IL_0001: ldstr “Plz input the string that you want to calculate :”
IL_0006: call void [mscorlib]System.Console::WriteLine(string)
IL_000b: nop
IL_000c: call string [mscorlib]System.Console::ReadLine()
IL_0011: stloc.0
IL_0012: ldloc.0
IL_0013: call int32 HelloWorld.Program::Length(string)
IL_0018: call void [mscorlib]System.Console::WriteLine(int32)
IL_001d: nop
IL_001e: ret
} // end of method Program::Main
.method private hidebysig static int32
Length(string str) cil managed
{
// 代码大小 12 (0xc)
.maxstack 1
.locals init ([0] int32 CS$1$0000)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: callvirt instance int32 [mscorlib]System.String::get_Length()
IL_0007: stloc.0
IL_0008: br.s IL_000a
IL_000a: ldloc.0
IL_000b: ret
} // end of method Program::Length
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// 代码大小 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method Program::.ctor
} // end of class HelloWorld.Program
// =============================================================
// *********** 反汇编完成 ***********************
// 警告: 创建了 Win32 资源文件 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\HelloWorld\HelloWorld\bin\Debug\121.res
[/coolcode]
在这两行
IL_000a: ldloc.0
IL_000b: ret
这件插入水印信息
[coolcode]
/* //水印代码 开始端
IL_000b: .locals init(int32 returnvalue)
IL_000c: stloc returnvalue
IL_000d: ldstr “DEBUG -current value is ‘{0}'”
IL_000f: ldstr “Copyright BUPTISC”
IL_0010: call void [mscorlib]System.Console::WriteLine(string,object)
IL_0011: ldloc returnvalue
//水印代码 结束端*/
[/coolcode]