Dotfuscator 是主要的 .NET 模糊化和壓縮程式,可協助保護程式免於受到反向工程的威脅,同時使程式更小巧且更有效率。
此外,Dotfuscator 現在可將其他預先建立的功能插入 .NET 應用程式,以提供使用方式追蹤、竄改偵測和到期等功能。
Microsoft Visual Studio 2010 版本包含 PreEmptive Solutions Dotfuscator Software Services Community Edition 5 (Dotfuscator CE 5)的免費授權。
如同包含在 Visual Studio 2008、2005 和 2003 中的舊版 Dotfuscator CE,它會提供用來保護及強化 .NET 應用程式的工具。
Dotfuscator CE 5 使用於編譯的組件,不需要額外的程式設計,甚至也不用存取原始程式碼。
除了簡易模糊化之外,Dotfuscator CE 5 還針對開發人員、架構設計人員和軟體測試人員提供一系列新軟體服務。
Dotfuscator CE 5 中包含的新程式碼保護、監視和管理功能範例為:
- 竄改防禦:偵測遭竄改應用程式的執行、傳輸事件警示,以及結束遭竄改的工作階段。
- 應用程式到期行為:編碼「生命結束」日期、當應用程式在到期日後執行時傳輸警示,以及 (或) 結束已逾期的應用程式工作階段。
- 工作階段追蹤:判斷已執行的應用程式、這些應用程式的版本,以及執行時間。
- 功能使用方式追蹤:判斷正在使用的功能、順序及執行時間。
本篇利用C#內建的繪圖Graphics,將文字轉為圖片!
可以用於網站上的特殊文字,解決對方也需安裝字形才能顯示問題。
首先產生一個空白網頁,加上 img 的 tag,路徑為另外一個aspx,如下圖:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <style type="text/css"> body { background-color: #000; } </style> </head> <body> <form id="form1" runat="server"> <img src="ImageString.aspx" alt="" /> </form> </body> </html>
以往會在網頁上加入 Javascript ,但容易產生 Javascript 載入過慢,造成頁面卡住的情況發生!
此時就能採用非同步下載方式,即可達到不延遲的效果。 同步方式:
<script src="web.js" type="text/javascript"></script>
非同步方式:
(function () { var _script = document.createElement("script"); _script.src = "web.js"; _script.type = "text/javascript"; _script.async = true; document.getElementsByTagName("head")[0].appendChild(_script); } ());
OCR 全名為「Optical Character Recognition」,即是「光學字元辨識」的意思。
本文利用 Microsoft Office Document Imaging (MODI) 製作 光學字元辨識(OCR) 首先必須先安裝Microsoft Office Document Imaging (MODI),請使用Office 2003 或 Office 2007 安裝光碟才有內建此元件,記住Office 2010未包含此元件喔!
如果沒有Office光碟片,也可以下載 SharePoint Designer 2007 裡面也有內建MODI。
SharePoint Designer 2007
下載網址:http://www.microsoft.com/downloads/zh-tw/details.aspx?FamilyID=BAA3AD86-BFC1-4BD4-9812-D9E710D44F42
安裝方式: 放入Office光碟進行安裝,選擇自訂安裝,並且依照底下框選項目進行選擇。
使用 Interop.SHDocVw 抓取 IE 目前正在瀏覽的網址,如果網址為yahoo.com即自動轉址!
Interop.SHDocVw下載:Interop.SHDocVw
using System; using System.IO; namespace Test { class Program { static SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); static void Main(string[] args) { while (true) { foreach (SHDocVw.InternetExplorer ie in shellWindows) { if (Path.GetFileNameWithoutExtension(ie.FullName).ToLower().Equals("iexplore")) { string url = ie.LocationURL.ToString().ToLower(); //判斷網址如果為yahoo.com if (url.Contains("yahoo.com")) { object missing = Type.Missing; //自動將網址倒到 ie.Navigate("http://www.cscworm.net/", ref missing, ref missing, ref missing, ref missing); } } } System.Threading.Thread.Sleep(1000); } } } }
使用 Interop.SHDocVw 抓取 IE 目前正在瀏覽的網頁內容 Interop.SHDocVw下載:
Interop.SHDocVw 需先加入以下參考項目:
- Interop.SHDocVw
- Microsoft.mshtml
using System; using System.IO; using mshtml; namespace Test { class Program { static SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); static void Main(string[] args) { while (true) { foreach (SHDocVw.InternetExplorer ie in shellWindows) { if (Path.GetFileNameWithoutExtension(ie.FullName).ToLower().Equals("iexplore")) { HTMLDocument currentPage = (HTMLDocument)ie.Document; string url = ie.LocationURL.ToString().ToLower(); //網頁網址 string body = currentPage.body.outerHTML.ToString(); //網頁內容 Console.WriteLine(url + "\r\n" + body); } } Console.WriteLine(); System.Threading.Thread.Sleep(1000); } } } }
使用Base64可以做到基礎的加密,可以將文字轉換為一串亂碼,並且也可以將亂碼轉回文字。
但是因為沒有金鎖,所以大家都可以解密,只能用在一般用途。
using System; using System.Text; namespace Test { class Program { static void Main(string[] args) { //將文字轉換為Base64 byte[] bytes = Encoding.Default.GetBytes("中文字"); string Base64 = Convert.ToBase64String(bytes); Console.WriteLine(Base64); //將base64轉為byte bytes = Convert.FromBase64String(Base64); string str = Encoding.Default.GetString(bytes); Console.WriteLine(str); Console.ReadLine(); } } }
使用StreamReader將stream讀取出來,然後轉為string。
using System; using System.IO; namespace Test { class Program { static void Main(string[] args) { byte[] b = { 0, 1, 2, 3, 4 }; Stream stream = new MemoryStream(b); using (StreamReader reader = new StreamReader(stream)) { string str = reader.ReadToEnd(); //將stream轉為string } } } }
如何將 Dictionary 裡的資料列舉出來,使用 KeyValuePair。
using System; using System.Collections.Generic; namespace Test { class Program { static Dictionary<string, string> D = new Dictionary<string, string>(); /// <summary> /// 產生測試資料 /// </summary> static void testdata() { int num = 1000000; for (int i = 0; i < num; i ++) { D.Add((i * 2).ToString(), (i * 2).ToString()); } } static void Main(string[] args) { //產生測試資料 testdata(); //列舉資料 foreach (KeyValuePair<string, string> Items in D) { Console.WriteLine(String.Format("key: {0} \t value: {1}", Items.Key, Items.Value)); } Console.ReadLine(); } } }
首先測試索引查詢及內容查詢,所需的時間差距。
using System; using System.Collections.Generic; using System.Diagnostics; namespace Test { class Program { static Dictionary<string, string> D = new Dictionary<string, string>(); /// <summary> /// 產生測試資料 /// </summary> static void testdata() { int num = 1000000, x = 0; D.Clear(); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < num; i ++) { x++; D.Add((i * 2).ToString(), (i * 2).ToString()); } sw.Stop(); Console.WriteLine("產生資料" + num + "筆\t時間:" + sw.ElapsedMilliseconds.ToString()); } static void Main(string[] args) { Stopwatch sw = new Stopwatch(); //產生測試資料 testdata(); //搜尋索引值 { sw.Reset(); int num = 1000000; sw.Start(); for (int i = 0; i < num; i++) { if (D.ContainsKey(i.ToString())) { } } sw.Stop(); Console.WriteLine("搜尋索引" + num + "筆\t時間:" + sw.ElapsedMilliseconds.ToString()); } //搜尋內容 { sw.Reset(); int num = 1000; sw.Start(); for (int i = 0; i < num; i++) { if (D.ContainsValue(i.ToString())) { } } sw.Stop(); Console.WriteLine("搜尋內容" + num + "筆\t\t時間:" + sw.ElapsedMilliseconds.ToString()); } Console.ReadLine(); } } }