├── BinaryExpressionGenerateToken ├── BinaryExpressionGenerateToken.sln ├── BinaryExpressionGenerateToken.v12.suo ├── BinaryExpressionGenerateToken │ ├── BinaryExpressionGenerateToken.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── bin │ │ └── Debug │ │ │ ├── BinaryExpressionGenerateToken.exe │ │ │ ├── BinaryExpressionGenerateToken.pdb │ │ │ ├── BinaryExpressionGenerateToken.vshost.exe │ │ │ ├── BinaryExpressionGenerateToken.vshost.exe.manifest │ │ │ ├── Core.dll │ │ │ └── Core.pdb │ └── obj │ │ └── Debug │ │ ├── BinaryExpressionGenerateToken.csproj.FileListAbsolute.txt │ │ ├── BinaryExpressionGenerateToken.csprojResolveAssemblyReference.cache │ │ ├── BinaryExpressionGenerateToken.exe │ │ ├── BinaryExpressionGenerateToken.pdb │ │ └── DesignTimeResolveAssemblyReferencesInput.cache ├── BinaryExpressionGenerateTokenTest │ ├── BinaryExpressionGenerateTokenTest.csproj │ ├── BrowserAPITest │ │ ├── FactorySelectBrowserAPITest.cs │ │ ├── FileReaderAPITest.cs │ │ ├── GeolocationAPITest.cs │ │ ├── HistoryAPITest.cs │ │ ├── MediaDeviceAPITest.cs │ │ ├── MessageChannelAPITest.cs │ │ └── ScreenAPITest.cs │ ├── BrowserTest │ │ ├── ChromeTest.cs │ │ ├── FirefoxTest.cs │ │ ├── IE10Test.cs │ │ ├── IE11Test.cs │ │ ├── IE6Test.cs │ │ ├── IE7Test.cs │ │ ├── IE8Test.cs │ │ ├── IE9Test.cs │ │ ├── OperaTest.cs │ │ └── SafariTest.cs │ ├── JSPackerCryptoTest │ │ └── JSPackerCryptoTest.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── PuzzleFunctionTest │ │ └── BinaryExpressionRandomTest.cs │ ├── bin │ │ └── Debug │ │ │ ├── BinaryExpressionGenerateTokenTest.dll │ │ │ ├── BinaryExpressionGenerateTokenTest.pdb │ │ │ ├── Core.dll │ │ │ ├── Core.pdb │ │ │ ├── JavaScriptEngineSwitcher.Core.dll │ │ │ ├── JavaScriptEngineSwitcher.Jurassic.dll │ │ │ ├── Jurassic.dll │ │ │ ├── Moq.dll │ │ │ ├── Moq.xml │ │ │ └── ru-ru │ │ │ └── JavaScriptEngineSwitcher.Core.resources.dll │ └── obj │ │ └── Debug │ │ ├── BinaryExpressionGenerateTokenTest.csproj.FileListAbsolute.txt │ │ ├── BinaryExpressionGenerateTokenTest.csprojResolveAssemblyReference.cache │ │ ├── BinaryExpressionGenerateTokenTest.dll │ │ ├── BinaryExpressionGenerateTokenTest.pdb │ │ └── DesignTimeResolveAssemblyReferencesInput.cache └── Core │ ├── BinaryExpressionGenerateTokenCore.csproj │ ├── Browser │ ├── Chrome.cs │ ├── Firefox.cs │ ├── IBrowser.cs │ ├── IE10.cs │ ├── IE11.cs │ ├── IE6.cs │ ├── IE7.cs │ ├── IE8.cs │ ├── IE9.cs │ ├── Opera.cs │ └── Safari.cs │ ├── BrowserAPI │ ├── FactorySelectBrowserAPI.cs │ ├── FileReaderAPI.cs │ ├── GeolocationAPI.cs │ ├── HistoryAPI.cs │ ├── IBrowserAPI.cs │ ├── MediaDeviceAPI.cs │ ├── MessageChannelAPI.cs │ └── ScreenAPI.cs │ ├── JSPackerCrypto │ ├── DeanEdward │ │ ├── DeanEdwardPackerCrypto.cs │ │ ├── ECMAScriptPacker.cs │ │ └── ParseMaster.cs │ ├── FactoryJSPackerCrypto.cs │ ├── IJSPackerCrypto.cs │ ├── StandardJSStyle.cs │ └── TypeConversion │ │ ├── Alpha_a.cs │ │ ├── Alpha_b.cs │ │ ├── Alpha_c.cs │ │ ├── Alpha_d.cs │ │ ├── Alpha_e.cs │ │ ├── Alpha_f.cs │ │ ├── Alpha_i.cs │ │ ├── Alpha_j.cs │ │ ├── Alpha_l.cs │ │ ├── Alpha_n.cs │ │ ├── Alpha_o.cs │ │ ├── Alpha_r.cs │ │ ├── Alpha_s.cs │ │ ├── Alpha_t.cs │ │ ├── Alpha_u.cs │ │ ├── ElementCryptoFactory.cs │ │ ├── GetCryptoElement.cs │ │ ├── IAlpha.cs │ │ ├── Number.cs │ │ ├── RawMetadata.cs │ │ └── Space.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── PuzzleFunction │ ├── FunctionRandom │ │ ├── BinaryExpressionRandom.cs │ │ ├── ExpressionPart │ │ │ ├── Addition.cs │ │ │ ├── And.cs │ │ │ ├── ExclusiveOr.cs │ │ │ ├── IExpressionPart.cs │ │ │ ├── Multiply.cs │ │ │ ├── Or.cs │ │ │ └── Subtraction.cs │ │ └── IFunctionRandom.cs │ ├── Puzzle │ │ ├── BinaryPuzzle.cs │ │ ├── FactoryPuzzle.cs │ │ └── IPuzzle.cs │ └── Transfer │ │ ├── BinaryExpressionToJSTransfer.cs │ │ └── ITransfer.cs │ ├── bin │ └── Debug │ │ ├── Core.dll │ │ └── Core.pdb │ └── obj │ └── Debug │ ├── BinaryExpressionGenerateTokenCore.csproj.FileListAbsolute.txt │ ├── Core.csproj.FileListAbsolute.txt │ ├── Core.dll │ ├── Core.pdb │ └── DesignTimeResolveAssemblyReferencesInput.cache └── LICENSE /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinaryExpressionGenerateToken", "BinaryExpressionGenerateToken\BinaryExpressionGenerateToken.csproj", "{F7FBF34D-DA6C-47AC-817F-21DCB295A0EF}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinaryExpressionGenerateTokenCore", "Core\BinaryExpressionGenerateTokenCore.csproj", "{1BE9FA10-6967-4386-8257-70B786B41FD1}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinaryExpressionGenerateTokenTest", "BinaryExpressionGenerateTokenTest\BinaryExpressionGenerateTokenTest.csproj", "{E28E8630-F33C-43F6-8ECF-83482D9C7F29}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {F7FBF34D-DA6C-47AC-817F-21DCB295A0EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {F7FBF34D-DA6C-47AC-817F-21DCB295A0EF}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {F7FBF34D-DA6C-47AC-817F-21DCB295A0EF}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {F7FBF34D-DA6C-47AC-817F-21DCB295A0EF}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {1BE9FA10-6967-4386-8257-70B786B41FD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {1BE9FA10-6967-4386-8257-70B786B41FD1}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {1BE9FA10-6967-4386-8257-70B786B41FD1}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {1BE9FA10-6967-4386-8257-70B786B41FD1}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {E28E8630-F33C-43F6-8ECF-83482D9C7F29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {E28E8630-F33C-43F6-8ECF-83482D9C7F29}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {E28E8630-F33C-43F6-8ECF-83482D9C7F29}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {E28E8630-F33C-43F6-8ECF-83482D9C7F29}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateToken.v12.suo -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/BinaryExpressionGenerateToken.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F7FBF34D-DA6C-47AC-817F-21DCB295A0EF} 8 | Exe 9 | Properties 10 | BinaryExpressionGenerateToken 11 | BinaryExpressionGenerateToken 12 | v4.0 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | {1be9fa10-6967-4386-8257-70b786b41fd1} 50 | BinaryExpressionGenerateTokenCore 51 | 52 | 53 | 54 | 61 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Core; 3 | 4 | namespace BinaryExpressionGenerateToken 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | var puzzle = FactoryPuzzle.CreatePuzzle("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"); 11 | Console.WriteLine(puzzle.StringSendToFrantEnd); 12 | Console.WriteLine(puzzle.GetResult()); 13 | 14 | Console.ReadLine(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BinaryExpressionGenerateToken")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("BinaryExpressionGenerateToken")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("661e3bff-5ba7-41c0-9b0f-2fcff529b5eb")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/bin/Debug/BinaryExpressionGenerateToken.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/bin/Debug/BinaryExpressionGenerateToken.exe -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/bin/Debug/BinaryExpressionGenerateToken.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/bin/Debug/BinaryExpressionGenerateToken.pdb -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/bin/Debug/BinaryExpressionGenerateToken.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/bin/Debug/BinaryExpressionGenerateToken.vshost.exe -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/bin/Debug/BinaryExpressionGenerateToken.vshost.exe.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/bin/Debug/Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/bin/Debug/Core.dll -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/bin/Debug/Core.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/bin/Debug/Core.pdb -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/obj/Debug/BinaryExpressionGenerateToken.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\bin\Debug\BinaryExpressionGenerateToken.exe 2 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\bin\Debug\BinaryExpressionGenerateToken.pdb 3 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\obj\Debug\BinaryExpressionGenerateToken.csprojResolveAssemblyReference.cache 4 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\obj\Debug\BinaryExpressionGenerateToken.exe 5 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\obj\Debug\BinaryExpressionGenerateToken.pdb 6 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\bin\Debug\Core.dll 7 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\bin\Debug\Core.pdb 8 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/obj/Debug/BinaryExpressionGenerateToken.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/obj/Debug/BinaryExpressionGenerateToken.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/obj/Debug/BinaryExpressionGenerateToken.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/obj/Debug/BinaryExpressionGenerateToken.exe -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/obj/Debug/BinaryExpressionGenerateToken.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/obj/Debug/BinaryExpressionGenerateToken.pdb -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateToken/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BinaryExpressionGenerateTokenTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 7 | 8 | 2.0 9 | {E28E8630-F33C-43F6-8ECF-83482D9C7F29} 10 | Library 11 | Properties 12 | BinaryExpressionGenerateTokenTest 13 | BinaryExpressionGenerateTokenTest 14 | v4.0 15 | 512 16 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 17 | 10.0 18 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 19 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 20 | True 21 | CodedUITest 22 | 23 | 24 | true 25 | full 26 | false 27 | bin\Debug\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | 32 | 33 | pdbonly 34 | true 35 | bin\Release\ 36 | TRACE 37 | prompt 38 | 4 39 | 40 | 41 | 42 | ..\..\..\..\..\..\..\工作2010\Domesticsearch\DomesticSearch\Hotel.Booking.AntiSpider.Logic.Tests\bin\Debug\JavaScriptEngineSwitcher.Core.dll 43 | 44 | 45 | ..\..\..\..\..\..\..\工作2010\Domesticsearch\DomesticSearch\Hotel.Booking.AntiSpider.Logic.Tests\bin\Debug\JavaScriptEngineSwitcher.Jurassic.dll 46 | 47 | 48 | ..\..\..\..\..\..\..\工作2010\Domesticsearch\DomesticSearch\Hotel.Booking.AntiSpider.Logic.Tests\bin\Debug\Jurassic.dll 49 | 50 | 51 | 52 | ..\..\..\..\..\..\..\工作2010\Domesticsearch\DomesticSearch\Hotel.Booking.DomesticSearch.Logic.Tests\bin\Debug\Moq.dll 53 | 54 | 55 | 56 | 3.5 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | False 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | {1be9fa10-6967-4386-8257-70b786b41fd1} 93 | BinaryExpressionGenerateTokenCore 94 | 95 | 96 | 97 | 98 | 99 | 100 | False 101 | 102 | 103 | False 104 | 105 | 106 | False 107 | 108 | 109 | False 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 130 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserAPITest/FactorySelectBrowserAPITest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace Core.Tests.BrowserAPITest 4 | { 5 | /// 6 | /// FactorySelectBrowserAPI 测试类 7 | /// 8 | [TestClass] 9 | public class FactorySelectBrowserAPITest 10 | { 11 | FactorySelectBrowserAPI testedClass = null; 12 | 13 | /// 14 | /// 初始化 15 | /// 16 | [TestInitialize] 17 | public void Init() 18 | { 19 | testedClass = new FactorySelectBrowserAPI(); 20 | } 21 | 22 | /// 23 | /// 预期:被测类中的浏览器实体和浏览器api实体必须存在 24 | /// 25 | [TestMethod] 26 | public void FactorySelectBrowserAPI_BrowserAndBrowserAPIIsNotNull() 27 | { 28 | Assert.IsTrue(FactorySelectBrowserAPI.apis != null && FactorySelectBrowserAPI.apis.Count > 0); 29 | Assert.IsTrue(FactorySelectBrowserAPI.browsers != null && FactorySelectBrowserAPI.browsers.Count > 0); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserAPITest/FileReaderAPITest.cs: -------------------------------------------------------------------------------- 1 | using Jurassic; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserAPITest 5 | { 6 | /// 7 | /// FileReader api测试类 8 | /// 9 | [TestClass] 10 | public class FileReaderAPITest 11 | { 12 | /// 13 | /// 场景:FileReader api在js引擎中使用 14 | /// 预期:不可使用 15 | /// 16 | [TestMethod] 17 | public void CannotUseInJSEnginee() 18 | { 19 | string jsFormat = "var f = function() {var i = 30; #replace# var j = 10; return i + j;}; f();"; 20 | var engine = new ScriptEngine(); 21 | IBrowserAPI api = new FileReaderAPI(); 22 | var result = engine.Evaluate(jsFormat.Replace("#replace#", api.GetAPIJSCode())); 23 | 24 | Assert.AreNotEqual(result, 40); 25 | } 26 | 27 | /// 28 | /// 场景:测试浏览器可用性 29 | /// 预期:见被测试类注释 30 | /// 31 | [TestMethod] 32 | public void BrowserEnable() 33 | { 34 | IBrowserAPI api = new FileReaderAPI(); 35 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE6())); 36 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE7())); 37 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE8())); 38 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE9())); 39 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE10())); 40 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE11())); 41 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Chrome())); 42 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Firefox())); 43 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new Opera())); 44 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new Safari())); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserAPITest/GeolocationAPITest.cs: -------------------------------------------------------------------------------- 1 | using Jurassic; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserAPITest 5 | { 6 | /// 7 | /// 地理位置api测试类 8 | /// 9 | [TestClass] 10 | public class GeolocationAPITest 11 | { 12 | /// 13 | /// 场景:地理位置api在js引擎中使用 14 | /// 预期:不可使用 15 | /// 16 | [TestMethod] 17 | public void CannotUseInJSEnginee() 18 | { 19 | string jsFormat = "var f = function() {var i = 30; #replace# var j = 10; return i + j;}; f();"; 20 | var engine = new ScriptEngine(); 21 | IBrowserAPI api = new GeolocationAPI(); 22 | var result = engine.Evaluate(jsFormat.Replace("#replace#", api.GetAPIJSCode())); 23 | 24 | Assert.AreNotEqual(result, 40); 25 | } 26 | 27 | /// 28 | /// 场景:测试浏览器可用性 29 | /// 预期:见被测试类注释 30 | /// 31 | [TestMethod] 32 | public void BrowserEnable() 33 | { 34 | IBrowserAPI api = new GeolocationAPI(); 35 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE6())); 36 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE7())); 37 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE8())); 38 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE9())); 39 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE10())); 40 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE11())); 41 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Chrome())); 42 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Firefox())); 43 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Opera())); 44 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Safari())); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserAPITest/HistoryAPITest.cs: -------------------------------------------------------------------------------- 1 | using Jurassic; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserAPITest 5 | { 6 | /// 7 | /// 浏览器历史记录api 测试 8 | /// 9 | [TestClass] 10 | public class HistoryAPITest 11 | { 12 | /// 13 | /// 场景:浏览器历史记录api在js引擎中使用 14 | /// 预期:不可使用,和js中设置值不同 15 | /// 16 | [TestMethod] 17 | public void CannotUseInJSEnginee() 18 | { 19 | string jsFormat = "var f = function() {var i = 30; #replace# var j = 10; return i + j;}; f();"; 20 | var engine = new ScriptEngine(); 21 | IBrowserAPI api = new HistoryAPI(); 22 | var result = engine.Evaluate(jsFormat.Replace("#replace#", api.GetAPIJSCode())); 23 | 24 | Assert.AreNotEqual(result, 40); 25 | } 26 | 27 | /// 28 | /// 场景:测试浏览器可用性 29 | /// 预期:所有浏览器都可用 30 | /// 31 | [TestMethod] 32 | public void BrowserEnable() 33 | { 34 | IBrowserAPI api = new HistoryAPI(); 35 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE6())); 36 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE7())); 37 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE8())); 38 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE9())); 39 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE10())); 40 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE11())); 41 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Chrome())); 42 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Firefox())); 43 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Opera())); 44 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Safari())); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserAPITest/MediaDeviceAPITest.cs: -------------------------------------------------------------------------------- 1 | using Jurassic; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserAPITest 5 | { 6 | /// 7 | /// MediaDeviceAPI测试类 8 | /// 9 | [TestClass] 10 | public class MediaDeviceAPITest 11 | { 12 | /// 13 | /// 场景:MediaDeviceAPI在js引擎中使用 14 | /// 预期:不可使用 15 | /// 16 | [TestMethod] 17 | public void CannotUseInJSEnginee() 18 | { 19 | string jsFormat = "var f = function() {var i = 30; #replace# var j = 10; return i + j;}; f();"; 20 | var engine = new ScriptEngine(); 21 | IBrowserAPI api = new MediaDeviceAPI(); 22 | var result = engine.Evaluate(jsFormat.Replace("#replace#", api.GetAPIJSCode())); 23 | 24 | Assert.AreNotEqual(result, 40); 25 | } 26 | 27 | /// 28 | /// 场景:测试浏览器可用性 29 | /// 预期:见被测试类注释 30 | /// 31 | [TestMethod] 32 | public void BrowserEnable() 33 | { 34 | IBrowserAPI api = new MediaDeviceAPI(); 35 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE6())); 36 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE7())); 37 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE8())); 38 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE9())); 39 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE10())); 40 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE11())); 41 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new Chrome())); 42 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Firefox())); 43 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new Opera())); 44 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new Safari())); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserAPITest/MessageChannelAPITest.cs: -------------------------------------------------------------------------------- 1 | using Jurassic; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserAPITest 5 | { 6 | /// 7 | /// MessageChannelAPI测试类 8 | /// 9 | [TestClass] 10 | public class MessageChannelAPITest 11 | { 12 | /// 13 | /// 场景:MessageChannelAPI在js引擎中使用 14 | /// 预期:不可使用 15 | /// 16 | [TestMethod] 17 | public void CannotUseInJSEnginee() 18 | { 19 | string jsFormat = "var f = function() {var i = 30; #replace# var j = 10; return i + j;}; f();"; 20 | var engine = new ScriptEngine(); 21 | IBrowserAPI api = new MessageChannelAPI(); 22 | var result = engine.Evaluate(jsFormat.Replace("#replace#", api.GetAPIJSCode())); 23 | 24 | Assert.AreNotEqual(result, 40); 25 | } 26 | 27 | /// 28 | /// 场景:测试浏览器可用性 29 | /// 预期:见被测试类注释 30 | /// 31 | [TestMethod] 32 | public void BrowserEnable() 33 | { 34 | IBrowserAPI api = new MessageChannelAPI(); 35 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE6())); 36 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE7())); 37 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE8())); 38 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new IE9())); 39 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE10())); 40 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE11())); 41 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Chrome())); 42 | Assert.IsFalse(api.IsThisBrowserEnableThisBrowserAPI(new Firefox())); 43 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Opera())); 44 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Safari())); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserAPITest/ScreenAPITest.cs: -------------------------------------------------------------------------------- 1 | using Jurassic; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserAPITest 5 | { 6 | /// 7 | /// ScreenAPI 测试类 8 | /// 9 | [TestClass] 10 | public class ScreenAPITest 11 | { 12 | /// 13 | /// 场景:MessageChannelAPI在js引擎中使用 14 | /// 预期:不可使用 15 | /// 16 | [TestMethod] 17 | public void CannotUseInJSEnginee() 18 | { 19 | string jsFormat = "var f = function() {var i = 30; #replace# var j = 10; return i + j;}; f();"; 20 | var engine = new ScriptEngine(); 21 | IBrowserAPI api = new ScreenAPI(); 22 | var result = engine.Evaluate(jsFormat.Replace("#replace#", api.GetAPIJSCode())); 23 | 24 | Assert.AreNotEqual(result, 40); 25 | } 26 | 27 | /// 28 | /// 场景:测试浏览器可用性 29 | /// 预期:见被测试类注释 30 | /// 31 | [TestMethod] 32 | public void BrowserEnable() 33 | { 34 | IBrowserAPI api = new ScreenAPI(); 35 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE6())); 36 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE7())); 37 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE8())); 38 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE9())); 39 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE10())); 40 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new IE11())); 41 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Chrome())); 42 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Firefox())); 43 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Opera())); 44 | Assert.IsTrue(api.IsThisBrowserEnableThisBrowserAPI(new Safari())); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserTest/ChromeTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserTest 5 | { 6 | [TestClass] 7 | public class ChromeTest 8 | { 9 | [TestMethod] 10 | public void Test() 11 | { 12 | Chrome Chrome = new Chrome(); 13 | string ua = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36"; 14 | Assert.IsTrue(Chrome.UserAgentRegex.IsMatch(ua)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserTest/FirefoxTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserTest 5 | { 6 | [TestClass] 7 | public class FirefoxTest 8 | { 9 | [TestMethod] 10 | public void Test() 11 | { 12 | Firefox Firefox = new Firefox(); 13 | string ua = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0"; 14 | Assert.IsTrue(Firefox.UserAgentRegex.IsMatch(ua)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserTest/IE10Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserTest 5 | { 6 | [TestClass] 7 | public class IE10Test 8 | { 9 | [TestMethod] 10 | public void Test() 11 | { 12 | IE10 ie10 = new IE10(); 13 | string ua = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"; 14 | Assert.IsTrue(ie10.UserAgentRegex.IsMatch(ua)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserTest/IE11Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserTest 5 | { 6 | [TestClass] 7 | public class IE11Test 8 | { 9 | [TestMethod] 10 | public void Test() 11 | { 12 | IE11 ie11 = new IE11(); 13 | string ua = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko"; 14 | Assert.IsTrue(ie11.UserAgentRegex.IsMatch(ua)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserTest/IE6Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserTest 5 | { 6 | [TestClass] 7 | public class IE6Test 8 | { 9 | [TestMethod] 10 | public void Test() 11 | { 12 | IE6 ie6 = new IE6(); 13 | string ua = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"; 14 | Assert.IsTrue(ie6.UserAgentRegex.IsMatch(ua)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserTest/IE7Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserTest 5 | { 6 | [TestClass] 7 | public class IE7Test 8 | { 9 | [TestMethod] 10 | public void Test() 11 | { 12 | IE7 ie7 = new IE7(); 13 | string ua = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"; 14 | Assert.IsTrue(ie7.UserAgentRegex.IsMatch(ua)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserTest/IE8Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserTest 5 | { 6 | [TestClass] 7 | public class IE8Test 8 | { 9 | [TestMethod] 10 | public void Test() 11 | { 12 | IE8 ie8 = new IE8(); 13 | string ua1 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB7.0)"; 14 | string ua2 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3)"; 15 | Assert.IsTrue(ie8.UserAgentRegex.IsMatch(ua1)); 16 | Assert.IsTrue(ie8.UserAgentRegex.IsMatch(ua2)); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserTest/IE9Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserTest 5 | { 6 | [TestClass] 7 | public class IE9Test 8 | { 9 | [TestMethod] 10 | public void Test() 11 | { 12 | IE9 ie9 = new IE9(); 13 | string ua = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; Tablet PC 2.0; .NET4.0E)"; 14 | Assert.IsTrue(ie9.UserAgentRegex.IsMatch(ua)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserTest/OperaTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserTest 5 | { 6 | [TestClass] 7 | public class OperaTest 8 | { 9 | [TestMethod] 10 | public void Test() 11 | { 12 | Opera Opera = new Opera(); 13 | string ua = "Opera/9.80 (Windows NT 6.1; U; zh-cn) Presto/2.9.168 Version/11.50"; 14 | Assert.IsTrue(Opera.UserAgentRegex.IsMatch(ua)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/BrowserTest/SafariTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Core.Tests.BrowserTest 5 | { 6 | [TestClass] 7 | public class SafariTest 8 | { 9 | [TestMethod] 10 | public void Test() 11 | { 12 | Safari Safari = new Safari(); 13 | string ua1 = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50"; 14 | Assert.IsTrue(Safari.UserAgentRegex.IsMatch(ua1)); 15 | string ua2 = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36"; 16 | Assert.IsFalse(Safari.UserAgentRegex.IsMatch(ua2)); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/JSPackerCryptoTest/JSPackerCryptoTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Jurassic; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | namespace Core.Tests.JSPackerCrypto 6 | { 7 | /// 8 | /// js加密混淆的综合测试 9 | /// 测试方法: 10 | /// 在循环内不停构造token生成函数,转成js,加密混淆,用js引擎运行,将结果和c#委托结果进行比较 11 | /// 12 | [TestClass] 13 | public class JSPackerCryptoTest 14 | { 15 | /// 16 | /// 场景:二元运算js,进行混淆加密 17 | /// 预期:js运算结果应该和c#运算结果相同 18 | /// 19 | [TestMethod] 20 | public void JSPackerCrypto_PackerCrypto_JSResultEqualCSharpResult() 21 | { 22 | var engine = new ScriptEngine(); 23 | IPuzzle puzzle = null; 24 | BinaryExpressionRandom token = null; 25 | 26 | for (int i = 0; i < 100; i++) 27 | { 28 | try 29 | { 30 | token = new BinaryExpressionRandom(); 31 | var expression = token.Create(); 32 | puzzle = new BinaryPuzzle( 33 | DateTime.Now, 34 | expression.Item1, 35 | expression.Item2, 36 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36", 37 | false); 38 | if (puzzle.GetResult() == "0") 39 | { 40 | i--; 41 | continue; 42 | } 43 | } 44 | catch 45 | { 46 | i--; 47 | continue; 48 | } 49 | var csharpResult = puzzle.GetResult(); 50 | var jsResult = engine.Evaluate(puzzle.StringSendToFrantEnd.Replace("", "") + "getuseridentityresult();").ToString(); 51 | Assert.AreEqual(csharpResult, jsResult); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BinaryExpressionGenerateTokenTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("BinaryExpressionGenerateTokenTest")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4e6f712f-561e-42fa-ae37-6a3edbc2a8a1")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/PuzzleFunctionTest/BinaryExpressionRandomTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | namespace Core.Tests 6 | { 7 | /// 8 | /// 随机创建二元运算符的表达式树 测试类 9 | /// 10 | [TestClass] 11 | public class BinaryExpressionRandomTest 12 | { 13 | /// 14 | /// 测试类,override和随机性相关的部分,以便测试 15 | /// 16 | class BinaryExpressionRandomForTest : BinaryExpressionRandom 17 | { 18 | internal override int GetTreeLayerCount(Random random) 19 | { 20 | return 5; 21 | } 22 | internal override int GetExpressionPartNumber(Random random) 23 | { 24 | return 1; 25 | } 26 | } 27 | 28 | /// 29 | /// 验证以程序生成的表达式树,是否和手工创建的相同 30 | /// 31 | [TestMethod] 32 | public void Test_ProgramCreateEqualsHandCreate() 33 | { 34 | BinaryExpressionRandomForTest testedClass = new BinaryExpressionRandomForTest(); 35 | var programResult = testedClass.Create().Item1; 36 | 37 | //===========以手工方式创建表达式树,5层二元运算========================= 38 | //-------left----------------------------------------------------- 39 | Expression parametera1 = Expression.Parameter(typeof(int), "a1"); 40 | Expression parametera2 = Expression.Parameter(typeof(int), "a2"); 41 | Expression add1 = Expression.Add(parametera1, parametera2); 42 | 43 | Expression parameterb1 = Expression.Parameter(typeof(int), "b1"); 44 | Expression parameterb2 = Expression.Parameter(typeof(int), "b2"); 45 | Expression add2 = Expression.Add(parameterb1, parameterb2); 46 | 47 | Expression parameterc1 = Expression.Parameter(typeof(int), "c1"); 48 | Expression parameterc2 = Expression.Parameter(typeof(int), "c2"); 49 | Expression add3 = Expression.Add(parameterc1, parameterc2); 50 | 51 | Expression parameterd1 = Expression.Parameter(typeof(int), "d1"); 52 | Expression parameterd2 = Expression.Parameter(typeof(int), "d2"); 53 | Expression add4 = Expression.Add(parameterd1, parameterd2); 54 | 55 | Expression parametere1 = Expression.Parameter(typeof(int), "e1"); 56 | Expression parametere2 = Expression.Parameter(typeof(int), "e2"); 57 | Expression add5 = Expression.Add(parametere1, parametere2); 58 | 59 | Expression parameterf1 = Expression.Parameter(typeof(int), "f1"); 60 | Expression parameterf2 = Expression.Parameter(typeof(int), "f2"); 61 | Expression add6 = Expression.Add(parameterf1, parameterf2); 62 | 63 | Expression parameterg1 = Expression.Parameter(typeof(int), "g1"); 64 | Expression parameterg2 = Expression.Parameter(typeof(int), "g2"); 65 | Expression add7 = Expression.Add(parameterg1, parameterg2); 66 | 67 | Expression parameterh1 = Expression.Parameter(typeof(int), "h1"); 68 | Expression parameterh2 = Expression.Parameter(typeof(int), "h2"); 69 | Expression add8 = Expression.Add(parameterh1, parameterh2); 70 | 71 | Expression add9 = Expression.Add(add1, add2); 72 | Expression add10 = Expression.Add(add3, add4); 73 | Expression add11 = Expression.Add(add5, add6); 74 | Expression add12 = Expression.Add(add7, add8); 75 | 76 | Expression add13 = Expression.Add(add9, add10); 77 | Expression add14 = Expression.Add(add11, add12); 78 | 79 | Expression add15 = Expression.Add(add13, add14); 80 | //------------right------------------------------------------------ 81 | Expression parameteri1 = Expression.Parameter(typeof(int), "i1"); 82 | Expression parameteri2 = Expression.Parameter(typeof(int), "i2"); 83 | Expression add16 = Expression.Add(parameteri1, parameteri2); 84 | 85 | Expression parameterj1 = Expression.Parameter(typeof(int), "j1"); 86 | Expression parameterj2 = Expression.Parameter(typeof(int), "j2"); 87 | Expression add17 = Expression.Add(parameterj1, parameterj2); 88 | 89 | Expression parameterk1 = Expression.Parameter(typeof(int), "k1"); 90 | Expression parameterk2 = Expression.Parameter(typeof(int), "k2"); 91 | Expression add18 = Expression.Add(parameterk1, parameterk2); 92 | 93 | Expression parameterl1 = Expression.Parameter(typeof(int), "l1"); 94 | Expression parameterl2 = Expression.Parameter(typeof(int), "l2"); 95 | Expression add19 = Expression.Add(parameterl1, parameterl2); 96 | 97 | Expression parameterm1 = Expression.Parameter(typeof(int), "m1"); 98 | Expression parameterm2 = Expression.Parameter(typeof(int), "m2"); 99 | Expression add20 = Expression.Add(parameterm1, parameterm2); 100 | 101 | Expression parametern1 = Expression.Parameter(typeof(int), "n1"); 102 | Expression parametern2 = Expression.Parameter(typeof(int), "n2"); 103 | Expression add21 = Expression.Add(parametern1, parametern2); 104 | 105 | Expression parametero1 = Expression.Parameter(typeof(int), "o1"); 106 | Expression parametero2 = Expression.Parameter(typeof(int), "o2"); 107 | Expression add22 = Expression.Add(parametero1, parametero2); 108 | 109 | Expression parameterp1 = Expression.Parameter(typeof(int), "p1"); 110 | Expression parameterp2 = Expression.Parameter(typeof(int), "p2"); 111 | Expression add23 = Expression.Add(parameterp1, parameterp2); 112 | 113 | Expression add24 = Expression.Add(add16, add17); 114 | Expression add25 = Expression.Add(add18, add19); 115 | Expression add26 = Expression.Add(add20, add21); 116 | Expression add27 = Expression.Add(add22, add23); 117 | 118 | Expression add28 = Expression.Add(add24, add25); 119 | Expression add29 = Expression.Add(add26, add27); 120 | 121 | Expression add30 = Expression.Add(add28, add29); 122 | 123 | var handResult = Expression.Add(add15, add30); 124 | //==================================================================== 125 | 126 | Assert.AreEqual(programResult.ToString(), handResult.ToString()); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/BinaryExpressionGenerateTokenTest.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/BinaryExpressionGenerateTokenTest.dll -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/BinaryExpressionGenerateTokenTest.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/BinaryExpressionGenerateTokenTest.pdb -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/Core.dll -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/Core.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/Core.pdb -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/JavaScriptEngineSwitcher.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/JavaScriptEngineSwitcher.Core.dll -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/JavaScriptEngineSwitcher.Jurassic.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/JavaScriptEngineSwitcher.Jurassic.dll -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/Jurassic.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/Jurassic.dll -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/Moq.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/Moq.dll -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/ru-ru/JavaScriptEngineSwitcher.Core.resources.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/bin/Debug/ru-ru/JavaScriptEngineSwitcher.Core.resources.dll -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/obj/Debug/BinaryExpressionGenerateTokenTest.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\obj\Debug\BinaryExpressionGenerateTokenTest.csprojResolveAssemblyReference.cache 2 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\bin\Debug\BinaryExpressionGenerateTokenTest.dll 3 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\bin\Debug\BinaryExpressionGenerateTokenTest.pdb 4 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\bin\Debug\Core.dll 5 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\bin\Debug\JavaScriptEngineSwitcher.Core.dll 6 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\bin\Debug\JavaScriptEngineSwitcher.Jurassic.dll 7 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\bin\Debug\Jurassic.dll 8 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\bin\Debug\Moq.dll 9 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\bin\Debug\Core.pdb 10 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\bin\Debug\Moq.xml 11 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\bin\Debug\ru-ru\JavaScriptEngineSwitcher.Core.resources.dll 12 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\obj\Debug\BinaryExpressionGenerateTokenTest.dll 13 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\BinaryExpressionGenerateTokenTest\obj\Debug\BinaryExpressionGenerateTokenTest.pdb 14 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/obj/Debug/BinaryExpressionGenerateTokenTest.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/obj/Debug/BinaryExpressionGenerateTokenTest.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/obj/Debug/BinaryExpressionGenerateTokenTest.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/obj/Debug/BinaryExpressionGenerateTokenTest.dll -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/obj/Debug/BinaryExpressionGenerateTokenTest.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/obj/Debug/BinaryExpressionGenerateTokenTest.pdb -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/BinaryExpressionGenerateTokenTest/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/BinaryExpressionGenerateTokenCore.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1BE9FA10-6967-4386-8257-70B786B41FD1} 8 | Library 9 | Properties 10 | Core 11 | Core 12 | v4.0 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 113 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Browser/Chrome.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Core 4 | { 5 | class Chrome : IBrowser 6 | { 7 | //Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36 8 | private static Regex regex = new Regex(@"chrome\/([\d.]+)", RegexOptions.IgnoreCase); 9 | 10 | public Regex UserAgentRegex 11 | { 12 | get { return regex; } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Browser/Firefox.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Core 4 | { 5 | class Firefox : IBrowser 6 | { 7 | // Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0 8 | private static Regex regex = new Regex(@"firefox\/([\d.]+)", RegexOptions.IgnoreCase); 9 | 10 | public Regex UserAgentRegex 11 | { 12 | get { return regex; } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Browser/IBrowser.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Core 4 | { 5 | /// 6 | /// 浏览器属性 接口 7 | /// 8 | public interface IBrowser 9 | { 10 | /// 11 | /// UserAgent正则 12 | /// 13 | Regex UserAgentRegex { get; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Browser/IE10.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Core 4 | { 5 | class IE10 : IBrowser 6 | { 7 | //Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0) 8 | private static Regex regex = new Regex("msie ([10.]+)", RegexOptions.IgnoreCase); 9 | 10 | public Regex UserAgentRegex 11 | { 12 | get { return regex; } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Browser/IE11.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Core 4 | { 5 | class IE11 : IBrowser 6 | { 7 | private static Regex regex = new Regex("rv:([11.]+).*like Gecko", RegexOptions.IgnoreCase); 8 | 9 | public Regex UserAgentRegex 10 | { 11 | get { return regex; } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Browser/IE6.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Core 4 | { 5 | class IE6 : IBrowser 6 | { 7 | //Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) 8 | private static Regex regex = new Regex("msie ([6.]+)", RegexOptions.IgnoreCase); 9 | 10 | public Regex UserAgentRegex 11 | { 12 | get { return regex; } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Browser/IE7.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Core 4 | { 5 | class IE7 : IBrowser 6 | { 7 | //Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1) 8 | private static Regex regex = new Regex("msie ([7.]+)", RegexOptions.IgnoreCase); 9 | 10 | public Regex UserAgentRegex 11 | { 12 | get { return regex; } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Browser/IE8.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Core 4 | { 5 | class IE8 : IBrowser 6 | { 7 | //Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB7.0) 8 | //Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3) 9 | private static Regex regex = new Regex("msie ([8.]+)", RegexOptions.IgnoreCase); 10 | 11 | public Regex UserAgentRegex 12 | { 13 | get { return regex; } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Browser/IE9.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Core 4 | { 5 | class IE9 : IBrowser 6 | { 7 | //Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; Tablet PC 2.0; .NET4.0E) 8 | private static Regex regex = new Regex("msie ([9.]+)", RegexOptions.IgnoreCase); 9 | 10 | public Regex UserAgentRegex 11 | { 12 | get { return regex; } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Browser/Opera.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Core 4 | { 5 | class Opera : IBrowser 6 | { 7 | //Opera/9.80 (Windows NT 6.1; U; zh-cn) Presto/2.9.168 Version/11.50 8 | private static Regex regex = new Regex(@"opera.([\d.]+)", RegexOptions.IgnoreCase); 9 | 10 | public Regex UserAgentRegex 11 | { 12 | get { return regex; } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Browser/Safari.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Core 4 | { 5 | class Safari : IBrowser 6 | { 7 | //Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50 8 | private static Regex regex = new Regex(@"^(?!.*?chrome).*safari\/([\d.]+)", RegexOptions.IgnoreCase); 9 | 10 | public Regex UserAgentRegex 11 | { 12 | get { return regex; } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/BrowserAPI/FactorySelectBrowserAPI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace Core 7 | { 8 | /// 9 | /// 选择一个可用的浏览器api 10 | /// 11 | class FactorySelectBrowserAPI 12 | { 13 | internal static List browsers; 14 | internal static List apis; 15 | 16 | /// 17 | /// 在静态构造函数中,通过反射,获取目前所有继承了IBrowser和IBrowserAPI接口的类型 18 | /// 19 | static FactorySelectBrowserAPI() 20 | { 21 | Assembly assembly = Assembly.GetExecutingAssembly(); 22 | 23 | browsers = new List(); 24 | List types = new List(); 25 | types.AddRange(assembly.GetTypes().Where(t => typeof(IBrowser).IsAssignableFrom(t) && t.IsClass)); 26 | browsers.AddRange(types.Select(pt => Activator.CreateInstance(pt) as IBrowser)); 27 | 28 | apis = new List(); 29 | types = new List(); 30 | types.AddRange(assembly.GetTypes().Where(t => typeof(IBrowserAPI).IsAssignableFrom(t) && t.IsClass)); 31 | apis.AddRange(types.Select(pt => Activator.CreateInstance(pt) as IBrowserAPI)); 32 | } 33 | 34 | public Tuple> SelectBrowserAPI(string rawUserAgent) 35 | { 36 | if (string.IsNullOrEmpty(rawUserAgent)) return null; 37 | 38 | //根据传过来的UA,确定用户是哪个浏览器 39 | IBrowser userBrowser = browsers.Find(b => b.UserAgentRegex.IsMatch(rawUserAgent)); 40 | 41 | if (userBrowser == null) 42 | { 43 | return null; 44 | } 45 | 46 | List enableApis = 47 | apis.FindAll(a => a.IsThisBrowserEnableThisBrowserAPI(userBrowser)); 48 | if (enableApis == null || enableApis.Count == 0) return null; 49 | 50 | return Tuple.Create(userBrowser, enableApis); 51 | } 52 | 53 | /// 54 | /// 从客户端回传的错误代码,得到api名字,以便记录log 55 | /// 56 | public string GetApiNameFromErrorCode(string errorCode) 57 | { 58 | var api = apis.Find(a => a.errorCode == errorCode); 59 | if (api == null) return ""; 60 | return api.GetType().Name; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/BrowserAPI/FileReaderAPI.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Core 3 | { 4 | /// 5 | /// FileReader API 6 | /// 可用性: 7 | /// Firefox (Gecko) Chrome Internet Explorer* Opera* Safari 8 | /// 3.6 (1.9.2) 7 10 未实现 未实现 9 | /// js引擎可用性:no 10 | /// 11 | class FileReaderAPI : IBrowserAPI 12 | { 13 | public string GetAPIJSCode() 14 | { 15 | return "try { new FileReader(); } catch (e) { var err = function() { return " + errorCode + "; }; return err; }"; 16 | } 17 | 18 | 19 | public bool IsThisBrowserEnableThisBrowserAPI(IBrowser browser) 20 | { 21 | if (browser == null) return false; 22 | 23 | if (browser is IE6) return false; 24 | if (browser is IE7) return false; 25 | if (browser is IE8) return false; 26 | if (browser is IE9) return false; 27 | if (browser is IE10) return true; 28 | if (browser is IE11) return true; 29 | if (browser is Chrome) return true; 30 | if (browser is Firefox) return true; 31 | if (browser is Opera) return false; 32 | if (browser is Safari) return false; 33 | 34 | return false; 35 | } 36 | 37 | public string errorCode 38 | { 39 | get { return "60000000000"; } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/BrowserAPI/GeolocationAPI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Core 4 | { 5 | /// 6 | /// 地理位置api 7 | /// 可用性: 8 | /// Chrome Firefox (Gecko) Internet Explorer Opera Safari 9 | /// 5 3.5 (1.9.1) 9 10.60 5 10 | /// js引擎可用性:no 11 | /// 12 | class GeolocationAPI : IBrowserAPI 13 | { 14 | public string GetAPIJSCode() 15 | { 16 | string s1 = "try { if(typeof navigator.geolocation.watchPosition != 'function') throw { message:'fk' } } catch(e) { var err = function() { return " + errorCode + "; }; return err; } "; 17 | string s2 = "try { if(typeof navigator.geolocation.getCurrentPosition != 'function') throw { message:'fk' } } catch(e) { var err = function() { return " + errorCode + "; }; return err; } "; 18 | return DateTime.Now.Second % 2 == 0 ? s1 : s2; 19 | } 20 | 21 | public bool IsThisBrowserEnableThisBrowserAPI(IBrowser browser) 22 | { 23 | if (browser == null) return false; 24 | 25 | if (browser is IE6) return false; 26 | if (browser is IE7) return false; 27 | if (browser is IE8) return false; 28 | if (browser is IE9) return true; 29 | if (browser is IE10) return true; 30 | if (browser is IE11) return true; 31 | if (browser is Chrome) return true; 32 | if (browser is Firefox) return true; 33 | if (browser is Opera) return true; 34 | if (browser is Safari) return true; 35 | 36 | return false; 37 | } 38 | 39 | public string errorCode 40 | { 41 | get { return "50000000000"; } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/BrowserAPI/HistoryAPI.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Core 3 | { 4 | /// 5 | /// 历史浏览记录api 6 | /// 可用性:所有浏览器 7 | /// JS引擎可用性:no 8 | /// 9 | class HistoryAPI : IBrowserAPI 10 | { 11 | public string GetAPIJSCode() 12 | { 13 | return "try { if( typeof window.history != 'object') throw { message:'err' };} catch(e) { var err = function() { return " + errorCode + "; }; return err; } "; 14 | } 15 | 16 | public bool IsThisBrowserEnableThisBrowserAPI(IBrowser browser) 17 | { 18 | if (browser == null) return false; 19 | 20 | if (browser is IE6) return true; 21 | if (browser is IE7) return true; 22 | if (browser is IE8) return true; 23 | if (browser is IE9) return true; 24 | if (browser is IE10) return true; 25 | if (browser is IE11) return true; 26 | if (browser is Chrome) return true; 27 | if (browser is Firefox) return true; 28 | if (browser is Opera) return true; 29 | if (browser is Safari) return true; 30 | 31 | return false; 32 | } 33 | 34 | public string errorCode 35 | { 36 | get { return "40000000000"; } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/BrowserAPI/IBrowserAPI.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Core 3 | { 4 | /// 5 | /// 浏览器api接口 6 | /// 7 | public interface IBrowserAPI 8 | { 9 | /// 10 | /// JS代码 11 | /// 12 | /// 13 | string GetAPIJSCode(); 14 | 15 | /// 16 | /// 浏览器是否可用 17 | /// 18 | /// 19 | /// 20 | bool IsThisBrowserEnableThisBrowserAPI(IBrowser browser); 21 | 22 | /// 23 | /// 错误代码 24 | /// 25 | string errorCode { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/BrowserAPI/MediaDeviceAPI.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Core 3 | { 4 | /// 5 | /// MediaDeviceAPI 6 | /// 可用性:firefox可用,ie和chrome都不行 7 | /// js引擎可用性:no 8 | /// 9 | class MediaDeviceAPI : IBrowserAPI 10 | { 11 | public string GetAPIJSCode() 12 | { 13 | return "try { if (typeof navigator.mediaDevices != 'object') throw { message : 'what?'}; } catch (e) { var err = function() { return " + errorCode + "; }; return err; }"; 14 | } 15 | 16 | public bool IsThisBrowserEnableThisBrowserAPI(IBrowser browser) 17 | { 18 | if (browser == null) return false; 19 | 20 | if (browser is IE6) return false; 21 | if (browser is IE7) return false; 22 | if (browser is IE8) return false; 23 | if (browser is IE9) return false; 24 | if (browser is IE10) return false; 25 | if (browser is IE11) return false; 26 | if (browser is Chrome) return false; 27 | if (browser is Firefox) return true; 28 | if (browser is Opera) return false; 29 | if (browser is Safari) return false; 30 | 31 | return false; 32 | } 33 | 34 | public string errorCode 35 | { 36 | get { return "30000000000"; } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/BrowserAPI/MessageChannelAPI.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Core 3 | { 4 | /// 5 | /// MessageChannelAPI 6 | /// 可用性: 7 | /// Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit) 8 | /// 4 Not supported 10.0 10.6 5 9 | /// js引擎可用性:no 10 | /// 11 | class MessageChannelAPI : IBrowserAPI 12 | { 13 | public string GetAPIJSCode() 14 | { 15 | return "try { if ( typeof new MessageChannel() != 'object') throw { message : 'no...'}; } catch (e) { var err = function() { return " + errorCode + "; }; return err; }"; 16 | } 17 | 18 | 19 | public bool IsThisBrowserEnableThisBrowserAPI(IBrowser browser) 20 | { 21 | if (browser == null) return false; 22 | 23 | if (browser is IE6) return false; 24 | if (browser is IE7) return false; 25 | if (browser is IE8) return false; 26 | if (browser is IE9) return false; 27 | if (browser is IE10) return true; 28 | if (browser is IE11) return true; 29 | if (browser is Chrome) return true; 30 | if (browser is Firefox) return false; 31 | if (browser is Opera) return true; 32 | if (browser is Safari) return true; 33 | 34 | return false; 35 | } 36 | 37 | public string errorCode 38 | { 39 | get { return "20000000000"; } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/BrowserAPI/ScreenAPI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Core 4 | { 5 | /// 6 | /// 屏幕api 7 | /// 可用性:所有浏览器 8 | /// js引擎可用性:no 9 | /// 10 | class ScreenAPI : IBrowserAPI 11 | { 12 | public string GetAPIJSCode() 13 | { 14 | string[] s = new string[3] 15 | { 16 | "try {if (typeof window.screen.colorDepth == 'undefined') throw { message : 'error'}; } catch (e) { var err = function() { return "+errorCode+"; }; return err; }", 17 | "try {if (typeof window.screen.height == 'undefined') throw { message : 'error'}; } catch (e) { var err = function() { return "+errorCode+"; }; return err; }", 18 | "try {if (typeof window.screen.width == 'undefined') throw { message : 'error'}; } catch (e) { var err = function() { return "+errorCode+"; }; return err; }" 19 | }; 20 | Random ran = new Random(); 21 | int i = ran.Next(0, s.Length); 22 | return s[i]; 23 | } 24 | 25 | public bool IsThisBrowserEnableThisBrowserAPI(IBrowser browser) 26 | { 27 | if (browser == null) return false; 28 | 29 | if (browser is IE6) return true; 30 | if (browser is IE7) return true; 31 | if (browser is IE8) return true; 32 | if (browser is IE9) return true; 33 | if (browser is IE10) return true; 34 | if (browser is IE11) return true; 35 | if (browser is Chrome) return true; 36 | if (browser is Firefox) return true; 37 | if (browser is Opera) return true; 38 | if (browser is Safari) return true; 39 | 40 | return false; 41 | } 42 | 43 | 44 | public string errorCode 45 | { 46 | get { return "10000000000"; } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/DeanEdward/DeanEdwardPackerCrypto.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | namespace Core 5 | { 6 | class DeanEdwardPackerCrypto : IJSPackerCrypto 7 | { 8 | public DeanEdwardPackerCrypto(IJSPackerCrypto next) 9 | { 10 | this.next = next; 11 | } 12 | 13 | public string JSPackerCrypto(string js) 14 | { 15 | string after = new ECMAScriptPacker().Pack(js); 16 | if (next != null) return next.JSPackerCrypto(after); 17 | return after; 18 | } 19 | 20 | public IJSPackerCrypto next 21 | { 22 | get; 23 | set; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/DeanEdward/ECMAScriptPacker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Text.RegularExpressions; 4 | using System.Collections; 5 | using System.Collections.Specialized; 6 | using System.Web; 7 | using System.IO; 8 | using Core; 9 | using System.Collections.Generic; 10 | 11 | /* 12 | packer, version 2.0 (beta) (2005/02/01) 13 | Copyright 2004-2005, Dean Edwards 14 | Web: http://dean.edwards.name/ 15 | 16 | This software is licensed under the CC-GNU LGPL 17 | Web: http://creativecommons.org/licenses/LGPL/2.1/ 18 | 19 | Ported to C# by Jesse Hansen, twindagger2k@msn.com 20 | */ 21 | 22 | // http://dean.edwards.name/packer/ 23 | 24 | namespace Core 25 | { 26 | /// 27 | /// Packs a javascript file into a smaller area, removing unnecessary characters from the output. 28 | /// 29 | public class ECMAScriptPacker 30 | { 31 | private enum PackerEncoding { Normal = 62 }; 32 | private PackerEncoding encoding = PackerEncoding.Normal; 33 | 34 | private string IGNORE = "$1"; 35 | 36 | /// 37 | /// Packs the script 38 | /// 39 | /// the script to pack 40 | /// the packed script 41 | public string Pack(string script) 42 | { 43 | script += "\n"; 44 | script = basicCompression(script); 45 | script = encodeSpecialChars(script); 46 | script = encodeKeywords(script); 47 | return script; 48 | } 49 | 50 | //zero encoding - just removal of whitespace and comments 51 | private string basicCompression(string script) 52 | { 53 | ParseMaster parser = new ParseMaster(); 54 | // make safe 55 | parser.EscapeChar = '\\'; 56 | // protect strings 57 | parser.Add("'[^'\\n\\r]*'", IGNORE); 58 | parser.Add("\"[^\"\\n\\r]*\"", IGNORE); 59 | // remove comments 60 | parser.Add("\\/\\/[^\\n\\r]*[\\n\\r]"); 61 | parser.Add("\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\/"); 62 | // protect regular expressions 63 | parser.Add("\\s+(\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?)", "$2"); 64 | parser.Add("[^\\w\\$\\/'\"*)\\?:]\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?", IGNORE); 65 | // remove: ;;; doSomething(); 66 | parser.Add(";;[^\\n\\r]+[\\n\\r]"); 67 | // remove redundant semi-colons 68 | parser.Add(";+\\s*([};])", "$2"); 69 | // remove white-space 70 | parser.Add("(\\b|\\$)\\s+(\\b|\\$)", "$2 $3"); 71 | parser.Add("([+\\-])\\s+([+\\-])", "$2 $3"); 72 | parser.Add("\\s+"); 73 | // done 74 | return parser.Exec(script); 75 | } 76 | 77 | WordList encodingLookup; 78 | private string encodeSpecialChars(string script) 79 | { 80 | ParseMaster parser = new ParseMaster(); 81 | // replace: $name -> n, $$name -> na 82 | parser.Add("((\\$+)([a-zA-Z\\$_]+))(\\d*)", 83 | new ParseMaster.MatchGroupEvaluator(encodeLocalVars)); 84 | 85 | // replace: _name -> _0, double-underscore (__name) is ignored 86 | Regex regex = new Regex("\\b_[A-Za-z\\d]\\w*"); 87 | 88 | // build the word list 89 | encodingLookup = analyze(script, regex, new EncodeMethod(encodePrivate)); 90 | 91 | parser.Add("\\b_[A-Za-z\\d]\\w*", new ParseMaster.MatchGroupEvaluator(encodeWithLookup)); 92 | 93 | script = parser.Exec(script); 94 | return script; 95 | } 96 | 97 | private string encodeKeywords(string script) 98 | { 99 | // escape high-ascii values already in the script (i.e. in strings) 100 | // create the parser 101 | ParseMaster parser = new ParseMaster(); 102 | EncodeMethod encode = new EncodeMethod(encode62); 103 | 104 | // for high-ascii, don't encode single character low-ascii 105 | Regex regex = new Regex("\\w+"); 106 | // build the word list 107 | encodingLookup = analyze(script, regex, encode); 108 | 109 | // encode 110 | parser.Add("\\w+", new ParseMaster.MatchGroupEvaluator(encodeWithLookup)); 111 | 112 | // if encoded, wrap the script in a decoding function 113 | return (script == string.Empty) ? "" : bootStrap(parser.Exec(script), encodingLookup); 114 | } 115 | 116 | private string bootStrap(string packed, WordList keywords) 117 | { 118 | // packed: the packed script 119 | packed = "'" + escape(packed) + "'"; 120 | 121 | // ascii: base for encoding 122 | int ascii = Math.Min(keywords.Sorted.Count, (int)encoding); 123 | if (ascii == 0) 124 | ascii = 1; 125 | 126 | // count: number of words contained in the script 127 | int count = keywords.Sorted.Count; 128 | 129 | // keywords: list of words contained in the script 130 | foreach (object key in keywords.Protected.Keys) 131 | { 132 | keywords.Sorted[(int)key] = ""; 133 | } 134 | // convert from a string to an array 135 | List l = new List(); 136 | //StringBuilder sbKeywords = new StringBuilder("'"); 137 | foreach (string word in keywords.Sorted) 138 | { 139 | string after = ""; 140 | if (string.IsNullOrEmpty(word)) after="''"; 141 | else after = ElementCryptoFactory.Crypto(word); 142 | l.Add(after); 143 | //sbKeywords.Append(word + "|"); 144 | } 145 | //sbKeywords.Remove(sbKeywords.Length - 1, 1); 146 | //string keywordsout = sbKeywords.ToString() + "'.split('|')"; 147 | string keywordsout = "(" + string.Join("+'|'+", l) + ")" + ".split('|')"; 148 | 149 | 150 | string encode; 151 | string inline = "c"; 152 | 153 | encode = "function(c){return(c35?String.fromCharCode(c+29):c.toString(36))}"; 155 | inline += ".toString(a)"; 156 | 157 | // decode: code snippet to speed up decoding 158 | string decode = ""; 159 | 160 | decode = "if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\\\w+'};c=1;}"; 161 | if (count == 0) 162 | decode = decode.Replace("c=1", "c=0"); 163 | 164 | // boot function 165 | string unpack = "function(p,a,c,k,e,d){while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p;}"; 166 | Regex r; 167 | 168 | //insert the decoder 169 | r = new Regex("\\{"); 170 | unpack = r.Replace(unpack, "{" + decode + ";", 1); 171 | 172 | // insert the encode function 173 | r = new Regex("\\{"); 174 | unpack = r.Replace(unpack, "{e=" + encode + ";", 1); 175 | 176 | // no need to pack the boot function since i've already done it 177 | string _params = "" + packed + "," + ascii + "," + count + "," + keywordsout; 178 | //insert placeholders for the decoder 179 | _params += ",0,{}"; 180 | 181 | // the whole thing 182 | return "eval(" + unpack + "(" + _params + "))\n"; 183 | } 184 | 185 | private string escape(string input) 186 | { 187 | Regex r = new Regex("([\\\\'])"); 188 | return r.Replace(input, "\\$1"); 189 | } 190 | 191 | //lookups seemed like the easiest way to do this since 192 | // I don't know of an equivalent to .toString(36) 193 | private static string lookup36 = "0123456789abcdefghijklmnopqrstuvwxyz"; 194 | private static string lookup62 = lookup36 + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 195 | 196 | private string encode62(int code) 197 | { 198 | string encoded = ""; 199 | int i = 0; 200 | do 201 | { 202 | int digit = (code / (int) Math.Pow(62, i)) % 62; 203 | encoded = lookup62[digit] + encoded; 204 | code -= digit * (int) Math.Pow(62, i++); 205 | } while (code > 0); 206 | return encoded; 207 | } 208 | 209 | private string encodeLocalVars(Match match, int offset) 210 | { 211 | int length = match.Groups[offset + 2].Length; 212 | int start = length - Math.Max(length - match.Groups[offset + 3].Length, 0); 213 | return match.Groups[offset + 1].Value.Substring(start, length) + 214 | match.Groups[offset + 4].Value; 215 | } 216 | 217 | private string encodeWithLookup(Match match, int offset) 218 | { 219 | return (string) encodingLookup.Encoded[match.Groups[offset].Value]; 220 | } 221 | 222 | private delegate string EncodeMethod(int code); 223 | 224 | private string encodePrivate(int code) 225 | { 226 | return "_" + code; 227 | } 228 | 229 | private WordList analyze(string input, Regex regex, EncodeMethod encodeMethod) 230 | { 231 | // analyse 232 | // retreive all words in the script 233 | MatchCollection all = regex.Matches(input); 234 | WordList rtrn; 235 | rtrn.Sorted = new StringCollection(); // list of words sorted by frequency 236 | rtrn.Protected = new HybridDictionary(); // dictionary of word->encoding 237 | rtrn.Encoded = new HybridDictionary(); // instances of "protected" words 238 | if (all.Count > 0) 239 | { 240 | StringCollection unsorted = new StringCollection(); // same list, not sorted 241 | HybridDictionary Protected = new HybridDictionary(); // "protected" words (dictionary of word->"word") 242 | HybridDictionary values = new HybridDictionary(); // dictionary of charCode->encoding (eg. 256->ff) 243 | HybridDictionary count = new HybridDictionary(); // word->count 244 | int i = all.Count, j = 0; 245 | string word; 246 | // count the occurrences - used for sorting later 247 | do 248 | { 249 | word = "$" + all[--i].Value; 250 | if (count[word] == null) 251 | { 252 | count[word] = 0; 253 | unsorted.Add(word); 254 | // make a dictionary of all of the protected words in this script 255 | // these are words that might be mistaken for encoding 256 | Protected["$" + (values[j] = encodeMethod(j))] = j++; 257 | } 258 | // increment the word counter 259 | count[word] = (int) count[word] + 1; 260 | } while (i > 0); 261 | /* prepare to sort the word list, first we must protect 262 | words that are also used as codes. we assign them a code 263 | equivalent to the word itself. 264 | e.g. if "do" falls within our encoding range 265 | then we store keywords["do"] = "do"; 266 | this avoids problems when decoding */ 267 | i = unsorted.Count; 268 | string[] sortedarr = new string[unsorted.Count]; 269 | do 270 | { 271 | word = unsorted[--i]; 272 | if (Protected[word] != null) 273 | { 274 | sortedarr[(int) Protected[word]] = word.Substring(1); 275 | rtrn.Protected[(int) Protected[word]] = true; 276 | count[word] = 0; 277 | } 278 | } while (i > 0); 279 | string[] unsortedarr = new string[unsorted.Count]; 280 | unsorted.CopyTo(unsortedarr, 0); 281 | // sort the words by frequency 282 | Array.Sort(unsortedarr, (IComparer) new CountComparer(count)); 283 | j = 0; 284 | /*because there are "protected" words in the list 285 | we must add the sorted words around them */ 286 | do 287 | { 288 | if (sortedarr[i] == null) 289 | sortedarr[i] = unsortedarr[j++].Substring(1); 290 | rtrn.Encoded[sortedarr[i]] = values[i]; 291 | } while (++i < unsortedarr.Length); 292 | rtrn.Sorted.AddRange(sortedarr); 293 | } 294 | return rtrn; 295 | } 296 | 297 | private struct WordList 298 | { 299 | public StringCollection Sorted; 300 | public HybridDictionary Encoded; 301 | public HybridDictionary Protected; 302 | } 303 | 304 | private class CountComparer : IComparer 305 | { 306 | HybridDictionary count; 307 | 308 | public CountComparer(HybridDictionary count) 309 | { 310 | this.count = count; 311 | } 312 | 313 | #region IComparer Members 314 | 315 | public int Compare(object x, object y) 316 | { 317 | return (int) count[y] - (int) count[x]; 318 | } 319 | 320 | #endregion 321 | } 322 | } 323 | } 324 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/DeanEdward/ParseMaster.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Specialized; 3 | using System.Text; 4 | using System.Text.RegularExpressions; 5 | 6 | /* 7 | ParseMaster, version 1.0 (pre-release) (2005/02/01) x4 8 | Copyright 2005, Dean Edwards 9 | Web: http://dean.edwards.name/ 10 | 11 | This software is licensed under the CC-GNU LGPL 12 | Web: http://creativecommons.org/licenses/LGPL/2.1/ 13 | 14 | Ported to C# by Jesse Hansen, twindagger2k@msn.com 15 | */ 16 | 17 | namespace Core 18 | { 19 | /// 20 | /// a multi-pattern parser 21 | /// 22 | public class ParseMaster 23 | { 24 | // used to determine nesting levels 25 | Regex GROUPS = new Regex("\\("), 26 | SUB_REPLACE = new Regex("\\$"), 27 | INDEXED = new Regex("^\\$\\d+$"), 28 | ESCAPE = new Regex("\\\\."), 29 | DELETED = new Regex("\\x01[^\\x01]*\\x01"); 30 | 31 | /// 32 | /// Delegate to call when a regular expression is found. 33 | /// Use match.Groups[offset + <group number>].Value to get 34 | /// the correct subexpression 35 | /// 36 | public delegate string MatchGroupEvaluator(Match match, int offset); 37 | 38 | private string DELETE(Match match, int offset) 39 | { 40 | return "\x01" + match.Groups[offset].Value + "\x01"; 41 | } 42 | 43 | private char escapeChar = '\0'; 44 | 45 | /// 46 | /// Escape Character to use 47 | /// 48 | public char EscapeChar 49 | { 50 | get { return escapeChar; } 51 | set { escapeChar = value; } 52 | } 53 | 54 | /// 55 | /// Add an expression to be deleted 56 | /// 57 | /// Regular Expression String 58 | public void Add(string expression) 59 | { 60 | Add(expression, string.Empty); 61 | } 62 | 63 | /// 64 | /// Add an expression to be replaced with the replacement string 65 | /// 66 | /// Regular Expression String 67 | /// Replacement String. Use $1, $2, etc. for groups 68 | public void Add(string expression, string replacement) 69 | { 70 | if (replacement == string.Empty) 71 | add(expression, new MatchGroupEvaluator(DELETE)); 72 | 73 | add(expression, replacement); 74 | } 75 | 76 | /// 77 | /// Add an expression to be replaced using a callback function 78 | /// 79 | /// Regular expression string 80 | /// Callback function 81 | public void Add(string expression, MatchGroupEvaluator replacement) 82 | { 83 | add(expression, replacement); 84 | } 85 | 86 | /// 87 | /// Executes the parser 88 | /// 89 | /// input string 90 | /// parsed string 91 | public string Exec(string input) 92 | { 93 | return DELETED.Replace(unescape(getPatterns().Replace(escape(input), new MatchEvaluator(replacement))), string.Empty); 94 | //long way for debugging 95 | /*input = escape(input); 96 | Regex patterns = getPatterns(); 97 | input = patterns.Replace(input, new MatchEvaluator(replacement)); 98 | input = DELETED.Replace(input, string.Empty); 99 | return input;*/ 100 | } 101 | 102 | ArrayList patterns = new ArrayList(); 103 | private void add(string expression, object replacement) 104 | { 105 | Pattern pattern = new Pattern(); 106 | pattern.expression = expression; 107 | pattern.replacement = replacement; 108 | //count the number of sub-expressions 109 | // - add 1 because each group is itself a sub-expression 110 | pattern.length = GROUPS.Matches(internalEscape(expression)).Count + 1; 111 | 112 | //does the pattern deal with sup-expressions? 113 | if (replacement is string && SUB_REPLACE.IsMatch((string)replacement)) 114 | { 115 | string sreplacement = (string)replacement; 116 | // a simple lookup (e.g. $2) 117 | if (INDEXED.IsMatch(sreplacement)) 118 | { 119 | pattern.replacement = int.Parse(sreplacement.Substring(1)) - 1; 120 | } 121 | } 122 | 123 | patterns.Add(pattern); 124 | } 125 | 126 | /// 127 | /// builds the patterns into a single regular expression 128 | /// 129 | /// 130 | private Regex getPatterns() 131 | { 132 | StringBuilder rtrn = new StringBuilder(string.Empty); 133 | foreach (object pattern in patterns) 134 | { 135 | rtrn.Append(((Pattern)pattern).ToString() + "|"); 136 | } 137 | rtrn.Remove(rtrn.Length - 1, 1); 138 | return new Regex(rtrn.ToString(), RegexOptions.None); 139 | } 140 | 141 | /// 142 | /// Global replacement function. Called once for each match found 143 | /// 144 | /// Match found 145 | private string replacement(Match match) 146 | { 147 | int i = 1, j = 0; 148 | Pattern pattern; 149 | //loop through the patterns 150 | while (!((pattern = (Pattern)patterns[j++]) == null)) 151 | { 152 | //do we have a result? 153 | if (match.Groups[i].Value != string.Empty) 154 | { 155 | object replacement = pattern.replacement; 156 | if (replacement is MatchGroupEvaluator) 157 | { 158 | return ((MatchGroupEvaluator)replacement)(match, i); 159 | } 160 | else if (replacement is int) 161 | { 162 | return match.Groups[(int)replacement + i].Value; 163 | } 164 | else 165 | { 166 | //string, send to interpreter 167 | return replacementString(match, i, (string)replacement, pattern.length); 168 | } 169 | } 170 | else //skip over references to sub-expressions 171 | i += pattern.length; 172 | } 173 | return match.Value; //should never be hit, but you never know 174 | } 175 | 176 | /// 177 | /// Replacement function for complicated lookups (e.g. Hello $3 $2) 178 | /// 179 | private string replacementString(Match match, int offset, string replacement, int length) 180 | { 181 | while (length > 0) 182 | { 183 | replacement = replacement.Replace("$" + length--, match.Groups[offset + length].Value); 184 | } 185 | return replacement; 186 | } 187 | 188 | private StringCollection escaped = new StringCollection(); 189 | 190 | //encode escaped characters 191 | private string escape(string str) 192 | { 193 | if (escapeChar == '\0') 194 | return str; 195 | Regex escaping = new Regex("\\\\(.)"); 196 | return escaping.Replace(str, new MatchEvaluator(escapeMatch)); 197 | } 198 | 199 | private string escapeMatch(Match match) 200 | { 201 | escaped.Add(match.Groups[1].Value); 202 | return "\\"; 203 | } 204 | 205 | //decode escaped characters 206 | private int unescapeIndex = 0; 207 | private string unescape(string str) 208 | { 209 | if (escapeChar == '\0') 210 | return str; 211 | Regex unescaping = new Regex("\\" + escapeChar); 212 | return unescaping.Replace(str, new MatchEvaluator(unescapeMatch)); 213 | } 214 | 215 | private string unescapeMatch(Match match) 216 | { 217 | return "\\" + escaped[unescapeIndex++]; 218 | } 219 | 220 | private string internalEscape(string str) 221 | { 222 | return ESCAPE.Replace(str, ""); 223 | } 224 | 225 | //subclass for each pattern 226 | private class Pattern 227 | { 228 | public string expression; 229 | public object replacement; 230 | public int length; 231 | 232 | public override string ToString() 233 | { 234 | return "(" + expression + ")"; 235 | } 236 | } 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/FactoryJSPackerCrypto.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Core 3 | { 4 | /// 5 | /// js混淆加密工厂 6 | /// 7 | class FactoryJSPackerCrypto 8 | { 9 | public static string Process(string rawJS) 10 | { 11 | if (string.IsNullOrEmpty(rawJS)) return rawJS; 12 | 13 | IJSPackerCrypto end = new StandardJSStyle(); 14 | IJSPackerCrypto first = new DeanEdwardPackerCrypto(end); 15 | return first.JSPackerCrypto(rawJS); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/IJSPackerCrypto.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Core 3 | { 4 | /// 5 | /// JS的混淆加密接口 6 | /// 7 | interface IJSPackerCrypto 8 | { 9 | string JSPackerCrypto(string js); 10 | 11 | IJSPackerCrypto next { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/StandardJSStyle.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Core 3 | { 4 | /// 5 | /// 标准化js格式 6 | /// 7 | class StandardJSStyle : IJSPackerCrypto 8 | { 9 | public string JSPackerCrypto(string js) 10 | { 11 | return ""; 12 | } 13 | 14 | public IJSPackerCrypto next 15 | { 16 | get; 17 | set; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_a.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | namespace Core 4 | { 5 | /// 6 | /// 字符a 7 | /// 8 | class Alpha_a : IAlpha 9 | { 10 | public string Get(Random ran) 11 | { 12 | return GetCryptoElement.Get( 13 | RawMetadata.metadataAlpha.GetValues("false"), 14 | RawMetadata.metadataNumber.GetValues("1"), ran); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_b.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 字符b 8 | /// 9 | class Alpha_b : IAlpha 10 | { 11 | public string Get(Random ran) 12 | { 13 | return GetCryptoElement.Get( 14 | RawMetadata.metadataAlpha.GetValues("[object Object]"), 15 | RawMetadata.metadataNumber.GetValues("2").Union(RawMetadata.metadataNumber.GetValues("9")), ran); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_c.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | namespace Core 4 | { 5 | /// 6 | /// 字符c 7 | /// 8 | class Alpha_c : IAlpha 9 | { 10 | public string Get(Random ran) 11 | { 12 | return GetCryptoElement.Get( 13 | RawMetadata.metadataAlpha.GetValues("[object Object]"), 14 | RawMetadata.metadataNumber.GetValues("5"), ran); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_d.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 字符d 8 | /// 9 | class Alpha_d : IAlpha 10 | { 11 | public string Get(Random ran) 12 | { 13 | return GetCryptoElement.Get( 14 | RawMetadata.metadataAlpha.GetValues("undefined"), 15 | RawMetadata.metadataNumber.GetValues("2").Union(RawMetadata.metadataNumber.GetValues("8")), ran); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_e.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Core 4 | { 5 | /// 6 | /// 字符e 7 | /// 8 | class Alpha_e : IAlpha 9 | { 10 | public string Get(Random ran) 11 | { 12 | return GetCryptoElement.Get( 13 | RawMetadata.metadataAlpha.GetValues("true"), 14 | RawMetadata.metadataNumber.GetValues("3"), ran); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_f.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Core 4 | { 5 | /// 6 | /// 字符f 7 | /// 8 | class Alpha_f : IAlpha 9 | { 10 | public string Get(Random ran) 11 | { 12 | return GetCryptoElement.Get( 13 | RawMetadata.metadataAlpha.GetValues("false"), 14 | RawMetadata.metadataNumber.GetValues("0"), ran); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_i.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 字符i 8 | /// 9 | class Alpha_i : IAlpha 10 | { 11 | public string Get(Random ran) 12 | { 13 | return GetCryptoElement.Get( 14 | RawMetadata.metadataAlpha.GetValues("undefined"), 15 | RawMetadata.metadataNumber.GetValues("5"), ran); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_j.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | namespace Core 4 | { 5 | /// 6 | /// 字符j 7 | /// 8 | class Alpha_j : IAlpha 9 | { 10 | public string Get(Random ran) 11 | { 12 | return GetCryptoElement.Get( 13 | RawMetadata.metadataAlpha.GetValues("[object Object]"), 14 | RawMetadata.metadataNumber.GetValues("3"), ran); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_l.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 字符l 8 | /// 9 | class Alpha_l : IAlpha 10 | { 11 | public string Get(Random ran) 12 | { 13 | return GetCryptoElement.Get( 14 | RawMetadata.metadataAlpha.GetValues("false"), 15 | RawMetadata.metadataNumber.GetValues("2"), ran); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_n.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 字符n 8 | /// 9 | class Alpha_n : IAlpha 10 | { 11 | public string Get(Random ran) 12 | { 13 | return GetCryptoElement.Get( 14 | RawMetadata.metadataAlpha.GetValues("undefined"), 15 | RawMetadata.metadataNumber.GetValues("1").Union(RawMetadata.metadataNumber.GetValues("6")), ran); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_o.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Core 3 | { 4 | /// 5 | /// 字符o 6 | /// 7 | class Alpha_o : IAlpha 8 | { 9 | public string Get(Random ran) 10 | { 11 | return GetCryptoElement.Get( 12 | RawMetadata.metadataAlpha.GetValues("[object Object]"), 13 | RawMetadata.metadataNumber.GetValues("1"), ran); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_r.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | namespace Core 4 | { 5 | /// 6 | /// 字符r 7 | /// 8 | class Alpha_r : IAlpha 9 | { 10 | public string Get(Random ran) 11 | { 12 | return GetCryptoElement.Get( 13 | RawMetadata.metadataAlpha.GetValues("true"), 14 | RawMetadata.metadataNumber.GetValues("1"), ran); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_s.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Core 4 | { 5 | /// 6 | /// 字符s 7 | /// 8 | class Alpha_s : IAlpha 9 | { 10 | public string Get(Random ran) 11 | { 12 | return GetCryptoElement.Get( 13 | RawMetadata.metadataAlpha.GetValues("false"), 14 | RawMetadata.metadataNumber.GetValues("3"), ran); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_t.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 字符t 8 | /// 9 | class Alpha_t : IAlpha 10 | { 11 | public string Get(Random ran) 12 | { 13 | return GetCryptoElement.Get( 14 | RawMetadata.metadataAlpha.GetValues("true"), 15 | RawMetadata.metadataNumber.GetValues("0"), ran); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Alpha_u.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Core 4 | { 5 | /// 6 | /// 字符u 7 | /// 8 | class Alpha_u : IAlpha 9 | { 10 | public string Get(Random ran) 11 | { 12 | return GetCryptoElement.Get( 13 | RawMetadata.metadataAlpha.GetValues("true"), 14 | RawMetadata.metadataNumber.GetValues("2"), ran); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/ElementCryptoFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 将js代码加密 8 | /// 9 | class ElementCryptoFactory 10 | { 11 | public static string Crypto(string rawJS) 12 | { 13 | if (string.IsNullOrEmpty(rawJS)) return ""; 14 | 15 | Random ran = new Random(); 16 | StringBuilder sb = new StringBuilder(); 17 | foreach (var c in rawJS) 18 | { 19 | switch (c.ToString()) 20 | { 21 | case "a": sb.Append(new Alpha_a().Get(ran)); break; 22 | case "b": sb.Append(new Alpha_b().Get(ran)); break; 23 | case "c": sb.Append(new Alpha_c().Get(ran)); break; 24 | case "d": sb.Append(new Alpha_d().Get(ran)); break; 25 | case "e": sb.Append(new Alpha_e().Get(ran)); break; 26 | case "f": sb.Append(new Alpha_f().Get(ran)); break; 27 | case "i": sb.Append(new Alpha_i().Get(ran)); break; 28 | case "j": sb.Append(new Alpha_j().Get(ran)); break; 29 | case "l": sb.Append(new Alpha_l().Get(ran)); break; 30 | case "n": sb.Append(new Alpha_n().Get(ran)); break; 31 | case "o": sb.Append(new Alpha_o().Get(ran)); break; 32 | case "r": sb.Append(new Alpha_r().Get(ran)); break; 33 | case "s": sb.Append(new Alpha_s().Get(ran)); break; 34 | case "t": sb.Append(new Alpha_t().Get(ran)); break; 35 | case "u": sb.Append(new Alpha_u().Get(ran)); break; 36 | case " ": sb.Append(new Space().Get(ran)); break; 37 | case "0": sb.Append(new Number().Get(0, ran)); break; 38 | case "1": sb.Append(new Number().Get(1, ran)); break; 39 | case "2": sb.Append(new Number().Get(2, ran)); break; 40 | case "3": sb.Append(new Number().Get(3, ran)); break; 41 | case "4": sb.Append(new Number().Get(4, ran)); break; 42 | case "5": sb.Append(new Number().Get(5, ran)); break; 43 | case "6": sb.Append(new Number().Get(6, ran)); break; 44 | case "7": sb.Append(new Number().Get(7, ran)); break; 45 | case "8": sb.Append(new Number().Get(8, ran)); break; 46 | case "9": sb.Append(new Number().Get(9, ran)); break; 47 | default: sb.Append("'").Append(c.ToString()).Append("'"); break; 48 | } 49 | sb.Append("+"); 50 | } 51 | 52 | return sb.ToString().TrimEnd('+'); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/GetCryptoElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Core 7 | { 8 | /// 9 | /// 获取加密后的字母、空格和数字 10 | /// 11 | class GetCryptoElement 12 | { 13 | public static string Get(IEnumerable raws, IEnumerable positions, Random ran) 14 | { 15 | if (raws == null || raws.Count() == 0) throw new Exception("获取加密后的字母、空格和数字异常"); 16 | if (positions == null || positions.Count() == 0) throw new Exception("获取加密后的字母、空格和数字异常"); 17 | 18 | //提取字母——>加括号——>加''——>加括号——>选取下标——>将下标扩进中括号——>和字母连接 19 | StringBuilder sb = new StringBuilder(); 20 | sb.Append("(").Append("("). 21 | Append(raws.ElementAt(ran.Next(0, raws.Count()))). 22 | Append("+''").Append(")"); 23 | sb.Append("[").Append(positions.ElementAt(ran.Next(0, positions.Count()))).Append("]").Append(")"); 24 | 25 | return sb.ToString(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/IAlpha.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | namespace Core 4 | { 5 | /// 6 | /// 字符混淆接口 7 | /// 8 | interface IAlpha 9 | { 10 | string Get(Random ran); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Number.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 获取数字混淆 8 | /// 9 | class Number 10 | { 11 | public string Get(int number, Random ran) 12 | { 13 | if (number < 0 || number > 9) throw new Exception("请使用0-9的基本字符"); 14 | 15 | var numbers = RawMetadata.metadataNumber.GetValues(number.ToString()); 16 | var s = numbers[ran.Next(0, numbers.Length)]; 17 | 18 | return new StringBuilder().Append("(").Append(s).Append("+'')").ToString(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/RawMetadata.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Specialized; 2 | 3 | namespace Core 4 | { 5 | /// 6 | /// 原始的元数据(还未分割) 7 | /// 8 | class RawMetadata 9 | { 10 | /// 11 | /// 字母元数据 12 | /// 13 | public static NameValueCollection metadataAlpha { get; private set; } 14 | /// 15 | /// 数字元数据 16 | /// 17 | public static NameValueCollection metadataNumber { get; private set; } 18 | 19 | static RawMetadata() 20 | { 21 | //从metadataAlpha中,可以提取a b c d e f i j l n o r s t u 15个字符以及空格 22 | //其余字符保留原字符 23 | metadataAlpha = new NameValueCollection() 24 | { 25 | {"false","!~+[]"}, 26 | {"false","!!+[]"}, 27 | {"true","!+[]"}, 28 | //{"true","!~~+[]"}, 29 | {"[object Object]","({}+[])"}, 30 | {"[object Object]","([]+{})"}, 31 | {"undefined","[][--[~+''][+[]]*[~+[]]+~~!+[]]"}, 32 | //{"undefined","[{}][--[~+''][+[]]*[~+[]]+~~!+[]+(~+[]*~+[])]"} 33 | }; 34 | //从metadataNumber可以提取数字 35 | metadataNumber = new NameValueCollection() 36 | { 37 | {"0","+[]"}, 38 | //{"0","~~+[]"}, 39 | {"1","~~!+[]"}, 40 | //{"1","~+[]*~+[]"}, 41 | {"2","+[]-~!+[]"}, 42 | //{"2","~!+[]*~+[]"}, 43 | {"3","~~!+[]+ +[]-~!+[]"}, 44 | //{"3","~+[]*~+[] +~!+[]*~+[]"}, 45 | //{"4","~~!+[]+~~!+[]+ +[]-~!+[]"}, 46 | {"4","+[]-~!+[]+ +[]-~!+[]"}, 47 | {"5","+[]-~!+[]+~~!+[]+ +[]-~!+[]"}, 48 | //{"5","~~!+[]+~+[]*~+[]+~~!+[]+~+[]*~+[]+~+[]*~+[]"}, 49 | {"6","~~!+[]+ +[]-~!+[]+~~!+[]+ +[]-~!+[]"}, 50 | //{"6","(+[]-(~!+[]))+(~+[]*~+[])+(+[]-(~!+[])+~~!+[])"}, 51 | {"7","~~!+[]+ +[]-~!+[]+ +[]-~!+[]+ +[]-~!+[]"}, 52 | //{"7","~~!+[]+~+[]*~+[]+~~!+[]+~~!+[]+~+[]*~+[]+~~!+[]+~+[]*~+[]"}, 53 | {"8","+[]-~!+[]+ +[]-~!+[]+ +[]-~!+[]+ +[]-~!+[]"}, 54 | //{"8","~~!+[]+~+[]*~+[]+~~!+[]+~+[]*~+[]+(+[]-(~!+[])+(~!+[])*(~+[]))"}, 55 | //{"9","(+[]-(~!+[]))+(+[]-(~!+[])+(~!+[])*(~+[]))+(~~!+[]+~+[]*~+[]+~~!+[])"}, 56 | {"9","+[]-~!+[]+ +[]-~!+[]+ +[]-~!+[]+~~!+[]+ +[]-~!+[]"} 57 | }; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/JSPackerCrypto/TypeConversion/Space.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | namespace Core 4 | { 5 | /// 6 | /// 空格 7 | /// 8 | class Space : IAlpha 9 | { 10 | public string Get(Random ran) 11 | { 12 | return GetCryptoElement.Get( 13 | RawMetadata.metadataAlpha.GetValues("[object Object]"), 14 | RawMetadata.metadataNumber.GetValues("7"), ran); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Core")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("Core")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("84dd2a43-a737-4be5-86ad-3199679e218f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: InternalsVisibleTo("BinaryExpressionGenerateTokenTest")] 38 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/FunctionRandom/BinaryExpressionRandom.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Reflection; 6 | 7 | namespace Core 8 | { 9 | /// 10 | /// 随机创建二元运算符的表达式树,一定是一颗满二叉树 11 | /// 12 | public class BinaryExpressionRandom : IFunctionRandom>> 13 | { 14 | /// 15 | /// 树的最大层数 16 | /// 17 | private int maxLayer = 5; 18 | 19 | private static List parts; 20 | /// 21 | /// 在静态构造函数中,通过反射,获取目前所有继承了IExpressionPart接口的类型 22 | /// 23 | static BinaryExpressionRandom() 24 | { 25 | parts = new List(); 26 | List partsType = new List(); 27 | Assembly assembly = Assembly.GetExecutingAssembly(); 28 | partsType.AddRange(assembly.GetTypes().Where(t => typeof(IExpressionPart).IsAssignableFrom(t) && t.IsClass)); 29 | parts.AddRange(partsType.Select(pt => Activator.CreateInstance(pt) as IExpressionPart)); 30 | } 31 | 32 | /// 33 | /// 确定树的层数 34 | /// 满二叉树的节点数:公式:(2的layer次方)-1; 35 | /// 为单元测试而作,常规代码请勿override 36 | /// 37 | /// 38 | internal virtual int GetTreeLayerCount(Random random) 39 | { 40 | return random.Next(2, maxLayer + 1);//先确定层数,在2-5范围内 41 | } 42 | 43 | /// 44 | /// 确定部件编号 45 | /// 为单元测试而作,常规代码请勿override 46 | /// 47 | internal virtual int GetExpressionPartNumber(Random random) 48 | { 49 | return random.Next(1, parts.Count + 1); 50 | } 51 | 52 | /// 53 | /// 随机创建表达式树 54 | /// 55 | public Tuple> Create() 56 | { 57 | //参数名 58 | Queue parameterName = 59 | new Queue(new string[] 60 | { "a1","a2", 61 | "b1","b2", 62 | "c1","c2", 63 | "d1","d2", 64 | "e1", "e2", 65 | "f1","f2", 66 | "g1", "g2", 67 | "h1","h2", 68 | "i1", "i2", 69 | "j1", "j2", 70 | "k1", "k2", 71 | "l1", "l2", 72 | "m1","m2", 73 | "n1", "n2", 74 | "o1", "o2", 75 | "p1","p2" 76 | }); 77 | 78 | Random random = new Random(); 79 | int layer = GetTreeLayerCount(random); 80 | 81 | //每层使用的队列 82 | Queue[] queue = new Queue[layer]; 83 | for (int i = 0; i < layer; i++) queue[i] = new Queue(); 84 | 85 | List parameterList = new List(); 86 | 87 | for (int l = layer; l >= 1; l--)//自低向上每一层 88 | { 89 | int layerCount = (int)Math.Pow(2, l - 1);//本层的节点数 90 | for (int i = 0; i < layerCount; i++)//每个节点 91 | { 92 | int number = GetExpressionPartNumber(random); 93 | IExpressionPart part = parts.Where(t => t.Number == number).FirstOrDefault();//随机生成一个部件 94 | 95 | Expression[] parameter; 96 | Expression expression; 97 | if (layer == l)//最底下一层,直接操作常量的二元运算符 98 | { 99 | string s = parameterName.Dequeue(); 100 | var p1 = Expression.Parameter(typeof(int), s); 101 | parameterList.Add(p1); 102 | s = parameterName.Dequeue(); 103 | var p2 = Expression.Parameter(typeof(int), s); 104 | parameterList.Add(p2); 105 | 106 | parameter = new Expression[] { p1, p2 }; 107 | expression = (Activator.CreateInstance(part.GetType()) as IExpressionPart).Process(parameter); 108 | } 109 | else//操作下面一层的二元运算符的结果的表达式 110 | { 111 | parameter = new Expression[] { queue[layer - l - 1].Dequeue(), queue[layer - l - 1].Dequeue() };//从下一层取出两个表达式 112 | expression = (Activator.CreateInstance(part.GetType()) as IExpressionPart).Process(parameter); 113 | } 114 | queue[layer - l].Enqueue(expression); 115 | } 116 | } 117 | 118 | return Tuple.Create(queue[layer - 1].Dequeue(), parameterList); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/FunctionRandom/ExpressionPart/Addition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 加法 8 | /// 9 | class Addition : IExpressionPart 10 | { 11 | public Expression Process(params Expression[] parameter) 12 | { 13 | if (parameter == null || parameter.Length < 2) throw new ArgumentException("加法部件参数异常!"); 14 | return Expression.AddChecked(parameter[0], parameter[1]); 15 | } 16 | 17 | public int Number 18 | { 19 | get { return 1; } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/FunctionRandom/ExpressionPart/And.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 按位与 8 | /// 9 | class And : IExpressionPart 10 | { 11 | public Expression Process(params Expression[] parameter) 12 | { 13 | if (parameter == null || parameter.Length < 2) throw new ArgumentException("按位与部件参数异常!"); 14 | return Expression.And(parameter[0], parameter[1]); 15 | } 16 | public int Number 17 | { 18 | get { return 4; } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/FunctionRandom/ExpressionPart/ExclusiveOr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 按位异或 8 | /// 9 | class ExclusiveOr : IExpressionPart 10 | { 11 | public Expression Process(params Expression[] parameter) 12 | { 13 | if (parameter == null || parameter.Length < 2) throw new ArgumentException("按位异或部件参数异常!"); 14 | return Expression.ExclusiveOr(parameter[0], parameter[1]); 15 | } 16 | public int Number 17 | { 18 | get { return 6; } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/FunctionRandom/ExpressionPart/IExpressionPart.cs: -------------------------------------------------------------------------------- 1 | using System.Linq.Expressions; 2 | 3 | namespace Core 4 | { 5 | /// 6 | /// 运算部件接口 7 | /// 8 | interface IExpressionPart 9 | { 10 | /// 11 | /// 部件编号 12 | /// 13 | int Number { get; } 14 | /// 15 | /// 运算 16 | /// 17 | /// 参数表达式 18 | /// 表达式树 19 | Expression Process(params Expression[] parameter); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/FunctionRandom/ExpressionPart/Multiply.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 乘法 8 | /// 9 | class Multiply : IExpressionPart 10 | { 11 | public Expression Process(params Expression[] parameter) 12 | { 13 | if (parameter == null || parameter.Length < 2) throw new ArgumentException("乘法部件参数异常!"); 14 | return Expression.MultiplyChecked(parameter[0], parameter[1]); 15 | } 16 | public int Number 17 | { 18 | get { return 3; } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/FunctionRandom/ExpressionPart/Or.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 按位或 8 | /// 9 | class Or : IExpressionPart 10 | { 11 | public Expression Process(params Expression[] parameter) 12 | { 13 | if (parameter == null || parameter.Length < 2) throw new ArgumentException("按位或部件参数异常!"); 14 | return Expression.Or(parameter[0], parameter[1]); 15 | } 16 | public int Number 17 | { 18 | get { return 5; } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/FunctionRandom/ExpressionPart/Subtraction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace Core 5 | { 6 | /// 7 | /// 减法 8 | /// 9 | class Subtraction : IExpressionPart 10 | { 11 | public Expression Process(params Expression[] parameter) 12 | { 13 | if (parameter == null || parameter.Length < 2) throw new ArgumentException("减法部件参数异常!"); 14 | 15 | return Expression.SubtractChecked(parameter[0], parameter[1]); 16 | } 17 | 18 | public int Number 19 | { 20 | get { return 2; } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/FunctionRandom/IFunctionRandom.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Core 3 | { 4 | /// 5 | /// 创建迷惑函数 6 | /// 7 | public interface IFunctionRandom 8 | { 9 | /// 10 | /// 创建 11 | /// 12 | T Create(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/Puzzle/BinaryPuzzle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | 5 | namespace Core 6 | { 7 | /// 8 | /// 二元运算迷惑函数实体 9 | /// 10 | public class BinaryPuzzle : IPuzzle 11 | { 12 | #region 浏览器api相关 13 | /// 14 | /// user agent 15 | /// 16 | public string RawUserAgent { get; private set; } 17 | public IBrowser browser { get; private set; } 18 | #endregion 19 | 20 | /// 21 | /// C#表达式树 22 | /// 23 | private Expression expression; 24 | /// 25 | /// 表达式树编译出的委托 26 | /// 27 | private Delegate lambda; 28 | /// 29 | /// 运算参数 30 | /// 31 | private object[] parameterValue; 32 | 33 | /// 34 | /// 获取随机数 35 | /// 为单元测试而作,常规代码请勿override 36 | /// 37 | internal virtual int GetRandomNumber(Random random) 38 | { 39 | return random.Next(1, 30); 40 | } 41 | 42 | public override string GetResult() 43 | { 44 | lastUseTime = DateTime.Now; 45 | return Convert.ToString(this.lambda.DynamicInvoke(parameterValue)); 46 | } 47 | 48 | public BinaryPuzzle(DateTime createTime, Expression expression, List parameterName, string useragent, bool enableBrowserApi = true) 49 | : base(createTime) 50 | { 51 | int count = parameterName.Count; 52 | Random ran = new Random(); 53 | parameterValue = new object[count]; 54 | for (int i = 0; i < count; i++)//随机创建表达式执行参数 55 | parameterValue[i] = GetRandomNumber(ran); 56 | 57 | this.expression = expression; 58 | this.lambda = Expression.Lambda(expression, parameterName).Compile(); 59 | 60 | this.RawUserAgent = useragent; 61 | var tuple = new FactorySelectBrowserAPI().SelectBrowserAPI(RawUserAgent); 62 | this.browser = tuple.Item1; 63 | var apis = tuple.Item2; 64 | this.StringSendToFrantEnd = new BinaryExpressionToJSTransfer(apis, enableBrowserApi). 65 | Translate(expression, parameterValue); 66 | 67 | //进行混淆加密 68 | this.StringSendToFrantEnd = FactoryJSPackerCrypto.Process(StringSendToFrantEnd); 69 | } 70 | 71 | /// 72 | /// 为单元测试而做,常规代码请勿调用 73 | /// 74 | public BinaryPuzzle() : base() { } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/Puzzle/FactoryPuzzle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Core 4 | { 5 | /// 6 | /// 迷惑函数工厂 7 | /// 8 | public class FactoryPuzzle 9 | { 10 | /// 11 | /// 构造一次迷惑函数 12 | /// 13 | public static IPuzzle CreatePuzzle(string useragent) 14 | { 15 | while (true) 16 | { 17 | try 18 | { 19 | DateTime now = DateTime.Now; 20 | 21 | BinaryExpressionRandom token1 = new BinaryExpressionRandom(); 22 | var expression = token1.Create(); 23 | IPuzzle puzzle = new BinaryPuzzle(now, expression.Item1, expression.Item2, useragent); 24 | if (puzzle.GetResult() == "0") continue; 25 | 26 | return puzzle; 27 | } 28 | catch 29 | { 30 | continue; 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/Puzzle/IPuzzle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Core 4 | { 5 | /// 6 | /// 迷惑函数抽象类 7 | /// 8 | public abstract class IPuzzle 9 | { 10 | /// 11 | /// 被使用次数 12 | /// 13 | protected int useCount; 14 | /// 15 | /// 创建时间 16 | /// 17 | protected DateTime createTime; 18 | /// 19 | /// 最后被使用时间 20 | /// 21 | public DateTime lastUseTime { get; protected set; } 22 | 23 | /// 24 | /// 将发送至前端的代码 25 | /// 26 | public string StringSendToFrantEnd { get; protected set; } 27 | 28 | /// 29 | /// 是否还在可用次数之内 30 | /// 为单元测试而作,常规代码请勿override 31 | /// 32 | public virtual bool IsInUseCount() 33 | { 34 | return useCount <= 50; 35 | } 36 | 37 | /// 38 | /// 自增使用次数 39 | /// 40 | public void IncUseCount() 41 | { 42 | useCount++; 43 | } 44 | 45 | public IPuzzle(DateTime now) 46 | { 47 | this.lastUseTime = now; 48 | this.createTime = now; 49 | } 50 | 51 | /// 52 | /// 为单元测试而做,常规代码请勿调用 53 | /// 54 | internal IPuzzle() { } 55 | 56 | /// 57 | /// 获取运算结果,将和前端发回来进行比对验证 58 | /// 59 | public abstract string GetResult(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/Transfer/BinaryExpressionToJSTransfer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | 7 | namespace Core 8 | { 9 | /// 10 | /// C#表达式树转译成javascript代码 11 | /// 12 | class BinaryExpressionToJSTransfer : ExpressionVisitor, ITransfer 13 | { 14 | #region 浏览器api相关 15 | /// 16 | /// 是否在二元运算符之间插入浏览器api。 17 | /// 为单元测试而做,因为单元测试使用的js引擎要模拟浏览器api需要做一番工作, 18 | /// 所以在单元测试中关闭‘插入浏览器api’ 19 | /// 20 | private bool enableInsertBrowserAPI = true; 21 | internal bool EnableInsertBrowserAPI 22 | { 23 | get 24 | { 25 | return enableInsertBrowserAPI; 26 | } 27 | set 28 | { 29 | enableInsertBrowserAPI = value; 30 | } 31 | } 32 | private Random ran = null; 33 | private IEnumerable apis = null; 34 | #endregion 35 | 36 | /// 37 | /// 方法编号,以防重名 38 | /// 39 | private int current = 0; 40 | /// 41 | /// 表达式树的二元运算符节点的个数 42 | /// 43 | private int layerCount = 0; 44 | 45 | /// 46 | /// 方法名栈 47 | /// 48 | private Stack functionNames = new Stack(); 49 | /// 50 | /// javascript结果字符串 51 | /// 52 | private StringBuilder sb = new StringBuilder(); 53 | 54 | /// 55 | /// 字符串模板 56 | /// 57 | private string format = "var {0}=function()[return _p({1});];"; 58 | private string format2 = "var {0}=function()[return _p({1}(){2}{3}());];"; 59 | private string format3 = "{0}{1}"; 60 | private string format4 = "var _p=parseInt;var g=function({0})[{1}];var getuseridentityresult=g({2});"; 61 | 62 | /// 63 | /// 参数名队列 64 | /// 65 | private Queue parameterNames = new Queue(); 66 | 67 | public BinaryExpressionToJSTransfer(IEnumerable apis, bool enableBrowserApi) 68 | { 69 | this.apis = apis; 70 | this.enableInsertBrowserAPI = enableBrowserApi; 71 | } 72 | 73 | /// 74 | /// C#表达式树转译成javascript 75 | /// 76 | public string Translate(Expression expression, object[] parameterValue) 77 | { 78 | ran = new Random(); 79 | 80 | GetExpressionLayerCount(expression); 81 | 82 | this.Visit(expression); 83 | string result = sb.ToString(); 84 | return string.Format(format4, string.Join(",", parameterNames), result, string.Join(",", parameterValue)).Replace("[", "{").Replace("]", "}"); 85 | } 86 | 87 | /// 88 | /// 获取表达式树的二元运算符的个数 89 | /// 90 | private void GetExpressionLayerCount(Expression expression) 91 | { 92 | BinaryExpression b = expression as BinaryExpression; 93 | if (b != null) 94 | { 95 | GetExpressionLayerCount(b.Left); 96 | GetExpressionLayerCount(b.Right); 97 | layerCount++; 98 | } 99 | } 100 | 101 | /// 102 | /// 获取二元操作符的javascript形式 103 | /// 104 | private string GetBinaryOperation(ExpressionType nodeType) 105 | { 106 | string opr = ""; 107 | switch (nodeType) 108 | { 109 | case ExpressionType.AddChecked: opr = "+"; break; 110 | case ExpressionType.And: opr = "&"; break; 111 | case ExpressionType.ExclusiveOr: opr = "^"; break; 112 | case ExpressionType.MultiplyChecked: opr = "*"; break; 113 | case ExpressionType.Or: opr = "|"; break; 114 | case ExpressionType.SubtractChecked: opr = "-"; break; 115 | default: throw new Exception("未定义的操作符!"); 116 | } 117 | return opr; 118 | } 119 | /// 120 | /// 获取二元操作符操作名 121 | /// 122 | private string GetBinaryFunctionName(ExpressionType nodeType) 123 | { 124 | string fun = ""; 125 | switch (nodeType) 126 | { 127 | case ExpressionType.AddChecked: fun = "AC"; break; 128 | case ExpressionType.And: fun = "A"; break; 129 | case ExpressionType.ExclusiveOr: fun = "E"; break; 130 | case ExpressionType.MultiplyChecked: fun = "M"; break; 131 | case ExpressionType.Or: fun = "O"; break; 132 | case ExpressionType.SubtractChecked: fun = "S"; break; 133 | default: throw new Exception("未定义的操作符!"); 134 | } 135 | return fun; 136 | } 137 | 138 | /// 139 | /// 处理二元运算符 140 | /// 141 | protected override Expression VisitBinary(BinaryExpression node) 142 | { 143 | if (node == null) return node; 144 | 145 | this.Visit(node.Left); 146 | this.Visit(node.Right); 147 | 148 | current++; 149 | 150 | string functionName; 151 | string result; 152 | if (typeof(ParameterExpression).IsAssignableFrom(node.Left.GetType()) && 153 | typeof(ParameterExpression).IsAssignableFrom(node.Right.GetType()))//是叶子二元运算符了 154 | { 155 | functionName = string.Format(format3, GetBinaryFunctionName(node.NodeType), current); 156 | result = string.Format(format, functionName, node.ToString()); 157 | } 158 | else//非叶子二元运算符 159 | { 160 | functionName = string.Format(format3, GetBinaryFunctionName(node.NodeType), current); 161 | string rightFunction = functionNames.Pop(); 162 | string leftFunction = functionNames.Pop(); 163 | string opr = GetBinaryOperation(node.NodeType); 164 | result = string.Format(format2, functionName, leftFunction, opr, rightFunction); 165 | } 166 | 167 | if(EnableInsertBrowserAPI) 168 | { 169 | bool canInsert = ran.Next(0, 2) == 0; 170 | if (canInsert) 171 | { 172 | string browserApiJSCode = 173 | apis.ElementAt(ran.Next(0, apis.Count())).GetAPIJSCode(); 174 | result += browserApiJSCode; 175 | } 176 | } 177 | 178 | if (current == layerCount) //最后一个方法 179 | result += string.Format("return {0};", functionName); 180 | 181 | sb.Append(result); 182 | functionNames.Push(functionName); 183 | 184 | return node; 185 | } 186 | 187 | /// 188 | /// 处理参数 189 | /// 190 | protected override Expression VisitParameter(ParameterExpression node) 191 | { 192 | if (node == null) return node; 193 | parameterNames.Enqueue(node.Name); 194 | return node; 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/PuzzleFunction/Transfer/ITransfer.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Core 3 | { 4 | /// 5 | /// 迷惑函数转换为将发送到客户端的形式 接口 6 | /// 7 | public interface ITransfer 8 | { 9 | /// 10 | /// 迷惑函数转换为将发送到客户端的形式 11 | /// 12 | string Translate(T t, object[] parameterValue); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/bin/Debug/Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/Core/bin/Debug/Core.dll -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/bin/Debug/Core.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/Core/bin/Debug/Core.pdb -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/obj/Debug/BinaryExpressionGenerateTokenCore.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\Core\bin\Debug\Core.dll 2 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\Core\bin\Debug\Core.pdb 3 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\Core\obj\Debug\Core.dll 4 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\Core\obj\Debug\Core.pdb 5 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/obj/Debug/Core.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\Core\bin\Debug\Core.dll 2 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\Core\bin\Debug\Core.pdb 3 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\Core\obj\Debug\Core.dll 4 | D:\Users\wbxia\Documents\GitHub\BinaryExpressionGenerateToken\BinaryExpressionGenerateToken\Core\obj\Debug\Core.pdb 5 | -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/obj/Debug/Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/Core/obj/Debug/Core.dll -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/obj/Debug/Core.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/Core/obj/Debug/Core.pdb -------------------------------------------------------------------------------- /BinaryExpressionGenerateToken/Core/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiawenbinEnvy/BinaryExpressionGenerateToken/b1b435d71a54c3bf14e3197351e70b769e2d1277/BinaryExpressionGenerateToken/Core/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | --------------------------------------------------------------------------------