├── .gitattributes ├── README.md ├── SWebScan.sln ├── SWebVulnsScan.v12.suo └── SWebVulnsScan ├── Hashtable.cs ├── Main.Designer.cs ├── Main.cs ├── Main.resx ├── Program.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── SWebScan.csproj ├── model ├── Config.cs └── ServerInfo.cs ├── obj ├── Debug │ ├── DesignTimeResolveAssemblyReferences.cache │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── SWebScan.Properties.Resources.resources │ ├── SWebScan.csproj.FileListAbsolute.txt │ ├── SWebScan.csproj.GenerateResource.Cache │ ├── SWebScan.csprojResolveAssemblyReference.cache │ ├── SWebScan.exe │ ├── SWebScan.pdb │ ├── SWebVulnsScan.FrmMain.resources │ ├── SWebVulnsScan.csproj.FileListAbsolute.txt │ ├── SWebVulnsScan.csproj.GenerateResource.Cache │ ├── SWebVulnsScan.csprojResolveAssemblyReference.cache │ └── TempPE │ │ └── Properties.Resources.Designer.cs.dll └── x86 │ ├── Debug │ ├── DesignTimeResolveAssemblyReferences.cache │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── SWebScan.Properties.Resources.resources │ ├── SWebScan.csproj.FileListAbsolute.txt │ ├── SWebScan.csproj.GenerateResource.Cache │ ├── SWebScan.csprojResolveAssemblyReference.cache │ ├── SWebScan.exe │ ├── SWebScan.pdb │ ├── SWebVulnsScan.FrmMain.resources │ └── TempPE │ │ └── Properties.Resources.Designer.cs.dll │ └── Release │ ├── DesignTimeResolveAssemblyReferences.cache │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── SWebScan.Properties.Resources.resources │ ├── SWebScan.csproj.FileListAbsolute.txt │ ├── SWebScan.csproj.GenerateResource.Cache │ ├── SWebScan.exe │ ├── SWebScan.pdb │ ├── SWebVulnsScan.FrmMain.resources │ └── TempPE │ └── Properties.Resources.Designer.cs.dll └── tools ├── ListViewColumnSorter.cs ├── Tools.cs ├── XML.cs ├── encode ├── URLEncode.cs └── URLTools.cs ├── file └── FileTool.cs ├── http └── HTTPRequest.cs └── thread ├── CallerThreadContext.cs ├── CanceledWorkItemsGroup.cs ├── EventWaitHandle.cs ├── EventWaitHandleFactory.cs ├── Exceptions.cs ├── Interfaces.cs ├── InternalInterfaces.cs ├── PriorityQueue.cs ├── SLExt.cs ├── STPEventWaitHandle.cs ├── STPPerformanceCounter.cs ├── STPStartInfo.cs ├── SmartThreadPool.ThreadEntry.cs ├── SmartThreadPool.cs ├── Stopwatch.cs ├── SynchronizedDictionary.cs ├── WIGStartInfo.cs ├── WorkItem.WorkItemResult.cs ├── WorkItem.cs ├── WorkItemFactory.cs ├── WorkItemInfo.cs ├── WorkItemResultTWrapper.cs ├── WorkItemsGroup.cs ├── WorkItemsGroupBase.cs └── WorkItemsQueue.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 程序使用需要安装.NET Framework 4.0 2 | 3 | SWebScan简介: 4 | 5 | 6 | SWebScan是一款基于C#的Web目录扫描器。 7 | 8 | 目前采用字典扫描模式,在a5站长和pudn将Web类代码目录爬下来,以及其他地方收集到一些字典,人工整理了一下。扫目录不错,不过有点多,稍微慢点。支持批量域名扫描,支持延时扫描对付防火墙。 9 | 10 | 快速扫描: 11 | 12 | 直接读取整个响应头的全部数据,速度比较快,缺点是无法对付404错误页面状态码也是200的情况。 13 | 14 | 关键字扫描: 15 | 16 | 直接读取整个响应头和响应主体的全部数据,因为404页面可能很长,所以读文档内容会浪费时间, 17 | 18 | 相对来说速度较慢,优点是可以对付404错误页面状态码是200的情况,但需要设置合理的404页面的标志关键词或者200页面的标志关键词。 19 | 20 | 建议设置一段英文字符的关键词,不要设置中文,因为编码如果未正确解析就会导致设置的关键字无效。 21 | 22 | 排除响应长度大于小于或者等于某个长度的情况,默认值是-2,就是排除响应长度小于-2的情况,如果某个404页面时固定长度,就可以设置排除这个长度。 23 | 24 | 文档类型限制,如果只需要提示某种文档类型,可以设置类型为指定的开头的字符,例如扫描压缩包,同都是application/xxx,所以可以设置文档类型为application,不是application开头的响内容都不会提示。 25 | 26 | 程序下面dic目录为默认的字典文件,默认字典较多,特别是dir、php、asp都是几十万的字典,min目录为小字典目录,字典相对较少,便于快速扫描。 27 | -------------------------------------------------------------------------------- /SWebScan.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SWebScan", "SWebVulnsScan\SWebScan.csproj", "{59E8BE8F-D97B-4616-BAB4-ECFEB4340A40}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|x86 = Debug|x86 12 | Release|Any CPU = Release|Any CPU 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {59E8BE8F-D97B-4616-BAB4-ECFEB4340A40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {59E8BE8F-D97B-4616-BAB4-ECFEB4340A40}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {59E8BE8F-D97B-4616-BAB4-ECFEB4340A40}.Debug|x86.ActiveCfg = Debug|x86 19 | {59E8BE8F-D97B-4616-BAB4-ECFEB4340A40}.Debug|x86.Build.0 = Debug|x86 20 | {59E8BE8F-D97B-4616-BAB4-ECFEB4340A40}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {59E8BE8F-D97B-4616-BAB4-ECFEB4340A40}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {59E8BE8F-D97B-4616-BAB4-ECFEB4340A40}.Release|x86.ActiveCfg = Release|x86 23 | {59E8BE8F-D97B-4616-BAB4-ECFEB4340A40}.Release|x86.Build.0 = Release|x86 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /SWebVulnsScan.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan.v12.suo -------------------------------------------------------------------------------- /SWebVulnsScan/Hashtable.cs: -------------------------------------------------------------------------------- 1 | namespace SWebVulnsScan 2 | { 3 | internal class Hashtable 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /SWebVulnsScan/Main.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 132, 20 125 | 126 | 127 | 257, 23 128 | 129 | 130 | 108 131 | 132 | -------------------------------------------------------------------------------- /SWebVulnsScan/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace SWebVulnsScan 7 | { 8 | static class Program 9 | { 10 | /// 11 | /// 应用程序的主入口点。 12 | /// 13 | [STAThread] 14 | static void Main() 15 | { 16 | Application.EnableVisualStyles(); 17 | Application.SetCompatibleTextRenderingDefault(false); 18 | Application.Run(new FrmMain()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SWebVulnsScan/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("SWebScan V5.0")] 9 | [assembly: AssemblyDescription("by shack2")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SWebScan")] 13 | [assembly: AssemblyCopyright("Copyright © 2012-2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("9a41454b-a657-4911-9866-a5f157f21fe6")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("5.0.0.0")] 36 | [assembly: AssemblyFileVersion("5.0.0.0")] 37 | -------------------------------------------------------------------------------- /SWebVulnsScan/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SWebScan.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SWebScan.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 使用此强类型资源类,为所有资源查找 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /SWebVulnsScan/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /SWebVulnsScan/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SWebScan.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SWebVulnsScan/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SWebVulnsScan/SWebScan.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {59E8BE8F-D97B-4616-BAB4-ECFEB4340A40} 8 | WinExe 9 | Properties 10 | SWebScan 11 | SWebScan 12 | v4.0 13 | 512 14 | 15 | 16 | x86 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 | true 36 | bin\x86\Debug\ 37 | DEBUG;TRACE 38 | full 39 | x86 40 | prompt 41 | MinimumRecommendedRules.ruleset 42 | 43 | 44 | bin\x86\Release\ 45 | TRACE 46 | true 47 | pdbonly 48 | x86 49 | prompt 50 | MinimumRecommendedRules.ruleset 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | Form 69 | 70 | 71 | Main.cs 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 | 107 | 108 | 109 | 110 | Main.cs 111 | 112 | 113 | ResXFileCodeGenerator 114 | Resources.Designer.cs 115 | Designer 116 | 117 | 118 | True 119 | Resources.resx 120 | True 121 | 122 | 123 | SettingsSingleFileGenerator 124 | Settings.Designer.cs 125 | 126 | 127 | True 128 | Settings.settings 129 | True 130 | 131 | 132 | 133 | 140 | -------------------------------------------------------------------------------- /SWebVulnsScan/model/Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Collections; 5 | 6 | namespace shack2.tools.model 7 | { 8 | [Serializable] 9 | public class Config 10 | { 11 | public Config() { 12 | 13 | } 14 | public String domain = ""; 15 | public int threadSize = 20; 16 | public int scanMode = 1; 17 | public String method = "HEAD"; 18 | public String url = ""; 19 | public int timeOut = 10;//秒 20 | public Boolean scanWAF = false; 21 | public Boolean getBanner = false; 22 | 23 | public String ext = ""; 24 | public int sleepTime = 0;//毫秒 25 | public String request = ""; 26 | public String key = ""; 27 | public String showCodes = "404"; 28 | public int show = 0; 29 | public int isExists = 0; 30 | // 31 | public Boolean getHeaderFirstLine = true; 32 | 33 | public int dicType = 0; 34 | public int contentSelect = 0; 35 | 36 | public int contentLength = -2; 37 | 38 | public String contentType=""; 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /SWebVulnsScan/model/ServerInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Text; 5 | 6 | namespace shack2.tools.model 7 | { 8 | public class ServerInfo 9 | { 10 | public String target = "";//扫描目标 11 | public String host = "";//host主机头 12 | public String url = "";//pathAndQuery 13 | public String path = "";//host主机头 14 | public int port = 80; 15 | public String request = ""; 16 | public String server = ""; 17 | public String header = ""; 18 | public String body = ""; 19 | public String reuqestHeader = ""; 20 | public Dictionary headers = new Dictionary(); 21 | public String response = ""; 22 | public String gzip = ""; 23 | public String encoding = ""; 24 | public String contentType = ""; 25 | public long id = 0; 26 | public long length = 0; 27 | public String ip = ""; 28 | public String type = ""; 29 | public int code = 0; 30 | public int mode = 0; 31 | public String location = ""; 32 | public long runTime = 0;//获取网页消耗时间,毫秒 33 | public int sleepTime = 0;//休息时间 34 | public String powerBy = ""; 35 | public Boolean timeout = false; 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/Debug/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/SWebScan.Properties.Resources.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/Debug/SWebScan.Properties.Resources.resources -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/SWebScan.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\Debug\SWebScan.csprojResolveAssemblyReference.cache 2 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\Debug\SWebVulnsScan.FrmMain.resources 3 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\Debug\SWebScan.csproj.GenerateResource.Cache 4 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\bin\Debug\SWebScan.exe 5 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\bin\Debug\SWebScan.pdb 6 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\Debug\SWebScan.Properties.Resources.resources 7 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\Debug\SWebScan.exe 8 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\Debug\SWebScan.pdb 9 | G:\MyCoding\c#\GitHub\SWebScanV5\SWebScan\SWebVulnsScan\obj\Debug\SWebScan.exe 10 | G:\MyCoding\c#\GitHub\SWebScanV5\SWebScan\SWebVulnsScan\obj\Debug\SWebScan.pdb 11 | -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/SWebScan.csproj.GenerateResource.Cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/Debug/SWebScan.csproj.GenerateResource.Cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/SWebScan.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/Debug/SWebScan.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/SWebScan.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/Debug/SWebScan.exe -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/SWebScan.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/Debug/SWebScan.pdb -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/SWebVulnsScan.FrmMain.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/Debug/SWebVulnsScan.FrmMain.resources -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/SWebVulnsScan.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | F:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\bin\Debug\SWebVulnsScan.exe 2 | F:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\bin\Debug\SWebVulnsScan.pdb 3 | F:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.Properties.Resources.resources 4 | F:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.csproj.GenerateResource.Cache 5 | F:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.exe 6 | F:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.pdb 7 | F:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.FrmMain.resources 8 | F:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.csprojResolveAssemblyReference.cache 9 | E:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.exe 10 | E:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.pdb 11 | E:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\bin\Debug\SWebVulnsScan.exe 12 | E:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\bin\Debug\SWebVulnsScan.pdb 13 | E:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.FrmMain.resources 14 | E:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.Properties.Resources.resources 15 | E:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.csproj.GenerateResource.Cache 16 | E:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.csprojResolveAssemblyReference.cache 17 | H:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.exe 18 | H:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.pdb 19 | H:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\bin\Debug\SWebVulnsScan.exe 20 | H:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\bin\Debug\SWebVulnsScan.pdb 21 | H:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.csprojResolveAssemblyReference.cache 22 | H:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.FrmMain.resources 23 | H:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.Properties.Resources.resources 24 | H:\MyCoding\c#\2015\SWebVulnsScan\SWebVulnsScan\obj\Debug\SWebVulnsScan.csproj.GenerateResource.Cache 25 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\Debug\SWebVulnsScan.exe 26 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\Debug\SWebVulnsScan.pdb 27 | -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/SWebVulnsScan.csproj.GenerateResource.Cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/Debug/SWebVulnsScan.csproj.GenerateResource.Cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/SWebVulnsScan.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/Debug/SWebVulnsScan.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Debug/SWebScan.Properties.Resources.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Debug/SWebScan.Properties.Resources.resources -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Debug/SWebScan.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\bin\x86\Debug\SWebScan.exe 2 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\bin\x86\Debug\SWebScan.pdb 3 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Debug\SWebVulnsScan.FrmMain.resources 4 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Debug\SWebScan.Properties.Resources.resources 5 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Debug\SWebScan.csproj.GenerateResource.Cache 6 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Debug\SWebScan.exe 7 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Debug\SWebScan.pdb 8 | H:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Debug\SWebScan.csprojResolveAssemblyReference.cache 9 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Debug\SWebScan.exe 10 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Debug\SWebScan.pdb 11 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\bin\x86\Debug\SWebScan.exe 12 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\bin\x86\Debug\SWebScan.pdb 13 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Debug\SWebVulnsScan.FrmMain.resources 14 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Debug\SWebScan.Properties.Resources.resources 15 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Debug\SWebScan.csproj.GenerateResource.Cache 16 | G:\MyCoding\c#\2017\SWebScanV5\SWebVulnsScan\obj\x86\Debug\SWebScan.exe 17 | G:\MyCoding\c#\2017\SWebScanV5\SWebVulnsScan\obj\x86\Debug\SWebScan.pdb 18 | G:\MyCoding\c#\2017\SWebScanV5\SWebVulnsScan\obj\x86\Debug\SWebVulnsScan.FrmMain.resources 19 | G:\MyCoding\c#\2017\SWebScanV5\SWebVulnsScan\obj\x86\Debug\SWebScan.Properties.Resources.resources 20 | G:\MyCoding\c#\2017\SWebScanV5\SWebVulnsScan\obj\x86\Debug\SWebScan.csproj.GenerateResource.Cache 21 | G:\MyCoding\c#\2017\SWebScanV5\SWebVulnsScan\bin\x86\Debug\SWebScan.exe 22 | G:\MyCoding\c#\2017\SWebScanV5\SWebVulnsScan\bin\x86\Debug\SWebScan.pdb 23 | G:\MyCoding\c#\2017\SWebScanV5\SWebVulnsScan\obj\x86\Debug\SWebScan.csprojResolveAssemblyReference.cache 24 | -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Debug/SWebScan.csproj.GenerateResource.Cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Debug/SWebScan.csproj.GenerateResource.Cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Debug/SWebScan.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Debug/SWebScan.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Debug/SWebScan.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Debug/SWebScan.exe -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Debug/SWebScan.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Debug/SWebScan.pdb -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Debug/SWebVulnsScan.FrmMain.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Debug/SWebVulnsScan.FrmMain.resources -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Debug/TempPE/Properties.Resources.Designer.cs.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Debug/TempPE/Properties.Resources.Designer.cs.dll -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Release/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Release/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Release/SWebScan.Properties.Resources.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Release/SWebScan.Properties.Resources.resources -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Release/SWebScan.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\bin\x86\Release\SWebScan.exe 2 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\bin\x86\Release\SWebScan.pdb 3 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Release\SWebVulnsScan.FrmMain.resources 4 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Release\SWebScan.Properties.Resources.resources 5 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Release\SWebScan.csproj.GenerateResource.Cache 6 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Release\SWebScan.exe 7 | G:\MyCoding\c#\2017\SWebScanV4\SWebVulnsScan\obj\x86\Release\SWebScan.pdb 8 | G:\MyCoding\c#\2017\SWebScanV5\SWebVulnsScan\obj\x86\Release\SWebScan.exe 9 | G:\MyCoding\c#\2017\SWebScanV5\SWebVulnsScan\obj\x86\Release\SWebScan.pdb 10 | -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Release/SWebScan.csproj.GenerateResource.Cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Release/SWebScan.csproj.GenerateResource.Cache -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Release/SWebScan.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Release/SWebScan.exe -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Release/SWebScan.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Release/SWebScan.pdb -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Release/SWebVulnsScan.FrmMain.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Release/SWebVulnsScan.FrmMain.resources -------------------------------------------------------------------------------- /SWebVulnsScan/obj/x86/Release/TempPE/Properties.Resources.Designer.cs.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/obj/x86/Release/TempPE/Properties.Resources.Designer.cs.dll -------------------------------------------------------------------------------- /SWebVulnsScan/tools/ListViewColumnSorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Windows.Forms; 6 | 7 | namespace shack2.tools 8 | { 9 | class ListViewColumnSorter:IComparer 10 | { 11 | /**/ 12 | /// 13 | /// 指定按照哪个列排序 14 | /// 15 | private int ColumnToSort; 16 | /**/ 17 | /// 18 | /// 指定排序的方式 19 | /// 20 | private SortOrder OrderOfSort; 21 | /**/ 22 | /// 23 | /// 声明CaseInsensitiveComparer类对象, 24 | /// 参见ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemCollectionsCaseInsensitiveComparerClassTopic.htm 25 | /// 26 | private CaseInsensitiveComparer ObjectCompare; 27 | 28 | /**/ 29 | /// 30 | /// 构造函数 31 | /// 32 | public ListViewColumnSorter() 33 | { 34 | // 默认按第一列排序 35 | ColumnToSort = 0; 36 | 37 | // 排序方式为不排序 38 | OrderOfSort = SortOrder.None; 39 | 40 | // 初始化CaseInsensitiveComparer类对象 41 | ObjectCompare = new CaseInsensitiveComparer(); 42 | } 43 | 44 | /**/ 45 | /// 46 | /// 重写IComparer接口. 47 | /// 48 | /// 要比较的第一个对象 49 | /// 要比较的第二个对象 50 | /// 比较的结果.如果相等返回0,如果x大于y返回1,如果x小于y返回-1 51 | public int Compare(object x, object y) 52 | { 53 | int compareResult; 54 | ListViewItem listviewX, listviewY; 55 | 56 | // 将比较对象转换为ListViewItem对象 57 | listviewX = (ListViewItem)x; 58 | listviewY = (ListViewItem)y; 59 | 60 | // 比较 61 | compareResult = ObjectCompare.Compare(listviewX.SubItems[ColumnToSort].Text, listviewY.SubItems[ColumnToSort].Text); 62 | 63 | // 根据上面的比较结果返回正确的比较结果 64 | if (OrderOfSort == SortOrder.Ascending) 65 | { 66 | // 因为是正序排序,所以直接返回结果 67 | return compareResult; 68 | } 69 | else if (OrderOfSort == SortOrder.Descending) 70 | { 71 | // 如果是反序排序,所以要取负值再返回 72 | return (-compareResult); 73 | } 74 | else 75 | { 76 | // 如果相等返回0 77 | return 0; 78 | } 79 | } 80 | 81 | /**/ 82 | /// 83 | /// 获取或设置按照哪一列排序. 84 | /// 85 | public int SortColumn 86 | { 87 | set 88 | { 89 | ColumnToSort = value; 90 | } 91 | get 92 | { 93 | return ColumnToSort; 94 | } 95 | } 96 | 97 | /**/ 98 | /// 99 | /// 获取或设置排序方式. 100 | /// 101 | public SortOrder Order 102 | { 103 | set 104 | { 105 | OrderOfSort = value; 106 | } 107 | get 108 | { 109 | return OrderOfSort; 110 | } 111 | } 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/Tools.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.IO; 4 | using System.Net; 5 | using System.Text.RegularExpressions; 6 | using System.Threading; 7 | using shack2.tools.file; 8 | using shack2.tools.model; 9 | 10 | namespace shack2.tools 11 | { 12 | class Tools 13 | { 14 | public const String httpLogPath = "logs/http/"; 15 | 16 | public static long currentMillis() 17 | { 18 | return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; 19 | } 20 | public static String encodeURIPath(String path) 21 | { 22 | return Uri.EscapeUriString(path).Replace("#","%23"); 23 | } 24 | public static bool ThreadPoolIsEnd() 25 | { 26 | int workerThreads = 0; 27 | int maxWordThreads = 0; 28 | //int 29 | int compleThreads = 0; 30 | ThreadPool.GetAvailableThreads(out workerThreads, out compleThreads); 31 | ThreadPool.GetMaxThreads(out maxWordThreads, out compleThreads); 32 | 33 | if (maxWordThreads == workerThreads) 34 | { 35 | return true; 36 | } 37 | else { 38 | return false; 39 | } 40 | } 41 | 42 | public static void SysLog(String log) 43 | { 44 | FileTool.AppendLogToFile("logs/" + DateTime.Now.ToLongDateString() + ".log.txt", log + "----" + DateTime.Now); 45 | } 46 | 47 | public static String fomartTime(String time) 48 | { 49 | try 50 | { 51 | DateTime dt = Convert.ToDateTime(time); 52 | String newtime = dt.ToLocalTime().ToString(); 53 | return newtime; 54 | } 55 | catch (Exception e) 56 | { 57 | SysLog(e.Message); 58 | } 59 | return time; 60 | 61 | } 62 | 63 | 64 | 65 | public static void sysHTTPLog(String index ,ServerInfo server) 66 | { 67 | FileTool.AppendLogToFile(httpLogPath + index + "-request.txt", server.request); 68 | FileTool.AppendLogToFile(httpLogPath + index + "-response.txt", server.header + "\r\n\r\n" + server.body); 69 | } 70 | 71 | public static void delHTTPLog() 72 | { 73 | try 74 | { 75 | DirectoryInfo din = new DirectoryInfo(httpLogPath); 76 | FileInfo[] files = din.GetFiles(); 77 | foreach (FileInfo f in files) 78 | { 79 | f.Delete(); 80 | } 81 | } 82 | catch (Exception re) 83 | { 84 | Tools.SysLog("删除HTTP日志发生错误!" + re.Message); 85 | } 86 | } 87 | 88 | 89 | public static String convertToString(String[] strs){ 90 | 91 | StringBuilder sb = new StringBuilder(); 92 | foreach(String s in strs){ 93 | sb.Append(s); 94 | } 95 | return sb.ToString(); 96 | 97 | } 98 | 99 | /// 100 | /// 将字符串转换成数字,错误返回0 101 | /// 102 | /// 字符串 103 | /// 104 | public static int convertToInt(String str) 105 | { 106 | 107 | try 108 | { 109 | return int.Parse(str); 110 | } 111 | catch (Exception e) { 112 | Tools.SysLog("info:-" + e.Message + "----将字符串[" + str + "]转换成数字发生错误----!"); 113 | } 114 | return 0; 115 | 116 | } 117 | /// 118 | /// 将16进制转换成10进制 119 | /// 120 | /// 16进制字符串 121 | /// 122 | public static int convertToIntBy16(String str) 123 | { 124 | try 125 | { 126 | return Convert.ToInt32(str,16); 127 | } 128 | catch (Exception e) 129 | { 130 | 131 | } 132 | return 0; 133 | 134 | } 135 | 136 | public static Boolean checkEmpty(String str) { 137 | 138 | if (str != null && str.Length > 0) 139 | { 140 | return false; 141 | } 142 | else { 143 | return true; 144 | } 145 | } 146 | 147 | public static String randIP() 148 | { 149 | Random rd = new Random(); 150 | 151 | String ip = rd.Next(1, 255) + "." + rd.Next(1, 255) + "." + rd.Next(1, 255) + "." + rd.Next(1, 255); 152 | 153 | return ip; 154 | } 155 | 156 | 157 | public static String getCurrentPath(String url) 158 | { 159 | int index =url.LastIndexOf("/"); 160 | 161 | if (index != -1) 162 | { 163 | return url.Substring(0,index)+"/"; 164 | } 165 | else { 166 | return ""; 167 | } 168 | } 169 | 170 | public static String getRootDomain(String domain) 171 | { 172 | int index = domain.LastIndexOf("."); 173 | 174 | if (index>0) 175 | { 176 | int index2 = domain.LastIndexOf(".", index - 1); 177 | if (index2 != -1) 178 | { 179 | return domain.Substring(index2+1); 180 | } 181 | 182 | } 183 | return domain; 184 | } 185 | public const String CONTENTLENGTH = "Content-Length: "; 186 | public static int getLength(String header) 187 | { 188 | 189 | return Tools.convertToInt(getHeaderInfo(CONTENTLENGTH, header)); 190 | 191 | 192 | } 193 | 194 | public static String getHeaderInfo(String key, String header) 195 | { 196 | 197 | int s_index = -1; 198 | int s_endIndex = -1; 199 | String server = ""; 200 | try 201 | { 202 | if ((s_index = header.IndexOf(key)) != -1) 203 | { 204 | if ((s_endIndex = header.IndexOf("\r", s_index + key.Length)) != -1) 205 | { 206 | server = header.Substring(s_index + key.Length, s_endIndex - s_index - key.Length).Trim(); 207 | } 208 | } 209 | } 210 | catch (Exception e) 211 | { 212 | 213 | } 214 | return server; 215 | } 216 | public const String SERVER = "Server: "; 217 | public static String getServerInfo(String header) 218 | { 219 | 220 | return getHeaderInfo(SERVER, header); 221 | } 222 | public const String ContentType = "Content-Type: "; 223 | public static String getContentType(String header) 224 | { 225 | String contentType = getHeaderInfo(ContentType, header); 226 | if(!String.IsNullOrEmpty(contentType)){ 227 | int cindex = contentType.IndexOf(";"); 228 | if (cindex != -1) { 229 | contentType = contentType.Substring(0, cindex); 230 | } 231 | } 232 | 233 | return contentType; 234 | } 235 | public const String PowerBy = "X-Powered-By: "; 236 | public static String getPowerBy(String header) 237 | { 238 | 239 | return getHeaderInfo(PowerBy, header); 240 | } 241 | 242 | public const String Location = "Location: "; 243 | public static String getLocation(String header) 244 | { 245 | 246 | return getHeaderInfo(Location, header); 247 | } 248 | 249 | 250 | //验证并修改域名格式 251 | public static String updateTheDomain(String weburl,bool delEND) 252 | { 253 | if ("".Equals(weburl.Trim())) 254 | { 255 | return ""; 256 | } 257 | if (!weburl.StartsWith("http://")&&!weburl.StartsWith("https://")) 258 | { 259 | weburl = "http://" + weburl; 260 | } 261 | if (delEND) 262 | { 263 | if (weburl.EndsWith("/")) 264 | { 265 | weburl = weburl.Substring(0, weburl.Length - 1); 266 | } 267 | } 268 | 269 | return weburl; 270 | } 271 | 272 | //获取HTTP状态码 273 | public static int getHttpCode(String headFirstLine) 274 | { 275 | int code = 0; 276 | try 277 | { 278 | //查找状态码 279 | if (!String.IsNullOrEmpty(headFirstLine)) 280 | { 281 | code = int.Parse(headFirstLine.Split(' ')[1]); 282 | } 283 | } 284 | catch (Exception e) 285 | { 286 | Tools.SysLog("waring:截取HTTP状态码,发生异常!----" + headFirstLine); 287 | } 288 | return code; 289 | } 290 | 291 | public static String getHost(String domain) 292 | { 293 | 294 | try 295 | { 296 | Uri u = new Uri(domain); 297 | return u.Host; 298 | 299 | } 300 | catch (Exception e) 301 | { 302 | } 303 | return domain; 304 | } 305 | 306 | public static String getHostCenter(String host) 307 | { 308 | String center = ""; 309 | try 310 | { 311 | 312 | int s = host.IndexOf("."); 313 | int e = host.IndexOf(".", s + 1); 314 | if (e <= s) 315 | { 316 | center = host.Substring(0, s); 317 | } 318 | else 319 | { 320 | center = host.Substring(s + 1, e - s - 1); 321 | } 322 | 323 | } 324 | catch (Exception e) 325 | { 326 | } 327 | return center.ToLower().Replace("http://", ""); 328 | } 329 | 330 | public static String getIP(String url) 331 | { 332 | try 333 | { 334 | 335 | Uri uri = new Uri(url); 336 | String host = uri.Host; 337 | bool isIP = Regex.IsMatch(url, @"[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}"); 338 | if (isIP) { 339 | return host; 340 | } 341 | IPHostEntry hostinfo = Dns.GetHostEntry(host); 342 | IPAddress[] aryIP = hostinfo.AddressList; 343 | 344 | return aryIP[0].ToString(); 345 | 346 | } 347 | catch (Exception e) 348 | { 349 | } 350 | return ""; 351 | } 352 | 353 | public static String UrlEncode(String str) 354 | { 355 | 356 | 357 | if (string.IsNullOrEmpty(str)) 358 | { 359 | return str; 360 | } 361 | StringBuilder stringBuilder = new StringBuilder(); 362 | for (int i = 0; i < str.Length; i++) 363 | { 364 | char c = str[i]; 365 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '.' || c == ':' || c == '(' || c == ')' || c == '*' || c == '_' || c == '!' || c == '/') 366 | { 367 | stringBuilder.Append(c); 368 | } 369 | else 370 | { 371 | byte[] bytes = Encoding.UTF8.GetBytes(new char[] { c }); 372 | byte[] array = bytes; 373 | for (int j = 0; j < array.Length; j++) 374 | { 375 | byte b = array[j]; 376 | stringBuilder.Append("%"); 377 | stringBuilder.Append(b.ToString("x2")); 378 | } 379 | } 380 | } 381 | return stringBuilder.ToString(); 382 | 383 | 384 | } 385 | 386 | } 387 | } 388 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/XML.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Xml; 5 | using System.IO; 6 | using System.Xml.Serialization; 7 | using System.Windows.Forms; 8 | using shack2.tools.model; 9 | 10 | namespace shack2.tools 11 | { 12 | class XML 13 | { 14 | 15 | 16 | public static void saveConfig(String fileName,Config config) 17 | { 18 | Stream fStream = null; 19 | try 20 | { 21 | fStream = new FileStream(fileName, FileMode.Create, FileAccess.Write); 22 | //创建XML序列化器,需要指定对象的类型 23 | XmlSerializer xmlFormat = new XmlSerializer(typeof(Config)); 24 | xmlFormat.Serialize(fStream, config); 25 | fStream.Close(); 26 | 27 | } 28 | catch (Exception e) 29 | { 30 | 31 | throw e; 32 | } 33 | finally { 34 | if(fStream!=null){ 35 | fStream.Close(); 36 | } 37 | 38 | } 39 | } 40 | 41 | public static Config readConfig(String configPath) 42 | { 43 | Stream fStream = null; 44 | try 45 | { 46 | XmlSerializer xml = new XmlSerializer(typeof(Config)); 47 | //创建XML序列化器,需要指定对象的类型 48 | fStream = new FileStream(configPath, FileMode.Open, FileAccess.Read); 49 | XmlTextReader reader = new XmlTextReader(fStream); 50 | reader.Normalization = false; 51 | Config config = (Config)xml.Deserialize(reader); 52 | return config; 53 | } 54 | catch (Exception e) 55 | { 56 | 57 | throw e; 58 | } 59 | finally { 60 | if (fStream != null) { 61 | 62 | fStream.Close(); 63 | } 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/encode/URLEncode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace shack2.tools.encode 6 | { 7 | class URLEncode 8 | { 9 | 10 | public static string UrlEncode(string sInput) 11 | { 12 | return UrlEncodeChars(sInput, Encoding.UTF8); 13 | } 14 | public static string UrlEncode(string sInput, Encoding oEnc) 15 | { 16 | return UrlEncodeChars(sInput, oEnc); 17 | } 18 | private static string UrlEncodeChars(string str, Encoding oEnc) 19 | { 20 | if (string.IsNullOrEmpty(str)) 21 | { 22 | return str; 23 | } 24 | StringBuilder stringBuilder = new StringBuilder(); 25 | for (int i = 0; i < str.Length; i++) 26 | { 27 | char c = str[i]; 28 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '.' || c == '(' || c == ')' || c == '*' || c == '\'' || c == '_' || c == '!') 29 | { 30 | stringBuilder.Append(c); 31 | } 32 | else 33 | { 34 | byte[] bytes = oEnc.GetBytes(new char[]{c}); 35 | byte[] array = bytes; 36 | for (int j = 0; j < array.Length; j++) 37 | { 38 | byte b = array[j]; 39 | stringBuilder.Append("%"); 40 | stringBuilder.Append(b.ToString("x2")); 41 | } 42 | } 43 | } 44 | return stringBuilder.ToString(); 45 | } 46 | // Fiddler.Utilities 47 | public static string UrlPathEncode(string str) 48 | { 49 | if (string.IsNullOrEmpty(str)) 50 | { 51 | return str; 52 | } 53 | int num = str.IndexOf('?'); 54 | if (num >= 0) 55 | { 56 | return UrlPathEncode(str.Substring(0, num)) + str.Substring(num); 57 | } 58 | return UrlPathEncodeChars(str); 59 | } 60 | 61 | private static string UrlPathEncodeChars(string str) 62 | { 63 | if (string.IsNullOrEmpty(str)) 64 | { 65 | return str; 66 | } 67 | StringBuilder stringBuilder = new StringBuilder(); 68 | for (int i = 0; i < str.Length; i++) 69 | { 70 | char c = str[i]; 71 | if (c > ' ' && c < '\u007f') 72 | { 73 | stringBuilder.Append(c); 74 | } 75 | else 76 | { 77 | if (c < '!') 78 | { 79 | stringBuilder.Append("%"); 80 | stringBuilder.Append(((byte)c).ToString("X2")); 81 | } 82 | else 83 | { 84 | byte[] bytes = Encoding.UTF8.GetBytes(new char[] 85 | { 86 | c 87 | }); 88 | byte[] array = bytes; 89 | for (int j = 0; j < array.Length; j++) 90 | { 91 | byte b = array[j]; 92 | stringBuilder.Append("%"); 93 | stringBuilder.Append(b.ToString("X2")); 94 | } 95 | } 96 | } 97 | } 98 | return stringBuilder.ToString(); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/encode/URLTools.cs: -------------------------------------------------------------------------------- 1 | using shack2.tools.model; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace shack2.tools.encode 7 | { 8 | class URLTools 9 | { 10 | public static ServerInfo getHostAndPathQueryByURL(String url){ 11 | 12 | try 13 | { 14 | ServerInfo server = new ServerInfo(); 15 | Uri uri = new Uri(url); 16 | server.host = uri.Host; 17 | server.url = uri.PathAndQuery; 18 | server.port = uri.Port; 19 | return server; 20 | } 21 | catch (Exception e) { 22 | 23 | throw e; 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/file/FileTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.IO; 5 | 6 | namespace shack2.tools.file 7 | { 8 | class FileTool 9 | { 10 | public static List readAllDic(String dic) 11 | { 12 | List fs = new List(); 13 | try 14 | { 15 | DirectoryInfo din = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory+"/"+dic); 16 | FileInfo[] files = din.GetFiles(); 17 | foreach (FileInfo f in files) 18 | { 19 | fs.Add(f.Name); 20 | } 21 | } 22 | catch (Exception re) 23 | { 24 | Tools.SysLog(dic + "读取错误!" + re.Message); 25 | } 26 | return fs; 27 | } 28 | public static List readFileToList(String path) 29 | { 30 | 31 | List list = new List(); 32 | FileStream fs_dir = null; 33 | StreamReader reader = null; 34 | try 35 | { 36 | fs_dir = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "/" + path, FileMode.Open, FileAccess.Read); 37 | 38 | reader = new StreamReader(fs_dir); 39 | 40 | String lineStr; 41 | 42 | while ((lineStr = reader.ReadLine()) != null) 43 | { 44 | if (!lineStr.Equals("")) 45 | { 46 | list.Add(lineStr); 47 | } 48 | } 49 | } catch (Exception e) 50 | { 51 | Tools.SysLog(e.Message); 52 | } 53 | finally { 54 | if (reader != null) 55 | { 56 | reader.Close(); 57 | } 58 | if (fs_dir != null) 59 | { 60 | fs_dir.Close(); 61 | } 62 | } 63 | return list; 64 | } 65 | 66 | public static List readFileToListByEncoding(String path,String encode) 67 | { 68 | 69 | List list = new List(); 70 | FileStream fs_dir = null; 71 | StreamReader reader = null; 72 | try 73 | { 74 | fs_dir = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "/" + path, FileMode.Open, FileAccess.Read); 75 | 76 | reader = new StreamReader(fs_dir,Encoding.GetEncoding(encode)); 77 | 78 | String lineStr; 79 | 80 | while ((lineStr = reader.ReadLine()) != null) 81 | { 82 | if (!lineStr.Equals("")) 83 | { 84 | int index = 0; 85 | if ((index = lineStr.IndexOf("?")) != -1) 86 | { 87 | String cpath = lineStr.Substring(0, index); 88 | String data = lineStr.Substring(index+1, lineStr.Length - index-1); 89 | list.Add(Tools.encodeURIPath(Tools.UrlEncode(cpath) + "?" + data)); 90 | } 91 | else { 92 | list.Add(Tools.UrlEncode(lineStr)); 93 | } 94 | 95 | } 96 | 97 | } 98 | } 99 | catch (Exception e) 100 | { 101 | Tools.SysLog(e.Message); 102 | } 103 | finally 104 | { 105 | if (reader != null) 106 | { 107 | reader.Close(); 108 | } 109 | if (fs_dir != null) 110 | { 111 | fs_dir.Close(); 112 | } 113 | } 114 | return list; 115 | } 116 | public static int getReadFileLine(String path) 117 | { 118 | 119 | 120 | FileStream fs_dir = null; 121 | StreamReader reader = null; 122 | int line = 0; 123 | try 124 | { 125 | fs_dir = new FileStream(path, FileMode.Open, FileAccess.Read); 126 | 127 | reader = new StreamReader(fs_dir); 128 | 129 | String lineStr; 130 | 131 | while ((lineStr = reader.ReadLine()) != null) 132 | { 133 | line++; 134 | } 135 | 136 | } 137 | catch (Exception e) 138 | { 139 | Tools.SysLog(e.Message); 140 | } 141 | finally 142 | { 143 | if (reader != null) 144 | { 145 | reader.Close(); 146 | } 147 | if (fs_dir != null) 148 | { 149 | fs_dir.Close(); 150 | } 151 | } 152 | return line; 153 | } 154 | public static List readDomainToList(String path) 155 | { 156 | 157 | List list = new List(); 158 | FileStream fs_dir = null; 159 | StreamReader reader = null; 160 | try 161 | { 162 | fs_dir = new FileStream(path, FileMode.Open, FileAccess.Read); 163 | 164 | reader = new StreamReader(fs_dir); 165 | 166 | String lineStr; 167 | 168 | while ((lineStr = reader.ReadLine()) != null) 169 | { 170 | if (!lineStr.Equals("")&&!lineStr.StartsWith("http")) { 171 | lineStr = "http://" + lineStr; 172 | } 173 | list.Add(lineStr); 174 | } 175 | } 176 | catch (Exception e) 177 | { 178 | Tools.SysLog(e.Message); 179 | } 180 | finally 181 | { 182 | if (reader != null) 183 | { 184 | reader.Close(); 185 | } 186 | if (fs_dir != null) 187 | { 188 | fs_dir.Close(); 189 | } 190 | } 191 | return list; 192 | } 193 | 194 | //读取文件 195 | public static String readFileToString(String path) 196 | { 197 | String str = ""; 198 | FileStream fs_dir=null; 199 | StreamReader reader = null; 200 | try 201 | { 202 | fs_dir = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "/" + path, FileMode.Open, FileAccess.Read); 203 | reader = new StreamReader(fs_dir); 204 | str = reader.ReadToEnd(); 205 | } 206 | catch (Exception e) 207 | { 208 | Tools.SysLog("readFileToString发生异常!"+e.Message); 209 | }finally 210 | { 211 | if (reader != null) 212 | { 213 | reader.Close(); 214 | } 215 | if (fs_dir != null) 216 | { 217 | fs_dir.Close(); 218 | } 219 | } 220 | return str; 221 | 222 | } 223 | //读取文件 224 | public static Byte[] readFileToByte(String path,int a) 225 | { 226 | Byte[] buffer = null; 227 | FileStream fs_dir=null; 228 | StreamReader reader = null; 229 | try 230 | { 231 | fs_dir = new FileStream(path, FileMode.Open, FileAccess.Read); 232 | BinaryReader br = new BinaryReader(fs_dir); 233 | int len = (int)fs_dir.Length; 234 | 235 | buffer = new byte[len]; 236 | 237 | int size = br.Read(buffer, 0, len); 238 | 239 | reader.Read(); 240 | 241 | } 242 | catch (Exception e) 243 | { 244 | Tools.SysLog("readFileToByte-error:读取文件内容发生错误!"+e.Message); 245 | }finally 246 | { 247 | if (reader != null) 248 | { 249 | reader.Close(); 250 | } 251 | if (fs_dir != null) 252 | { 253 | fs_dir.Close(); 254 | } 255 | } 256 | return buffer; 257 | 258 | } 259 | public static object c = ""; 260 | public static void AppendLogToFile(String path,String log) 261 | { 262 | //锁住,防止多线程引发错误 263 | lock (c) 264 | { 265 | List list = new List(); 266 | FileStream fs_dir = null; 267 | StreamWriter sw = null; 268 | try 269 | { 270 | fs_dir = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "/" + path, FileMode.Append, FileAccess.Write); 271 | 272 | sw = new StreamWriter(fs_dir); 273 | 274 | sw.WriteLine(log); 275 | 276 | sw.Close(); 277 | 278 | fs_dir.Close(); 279 | 280 | } 281 | catch (Exception e) 282 | { 283 | Tools.SysLog("FileTools-AppendLogToFile-error:读取文件内容发生错误!"+e.Message); 284 | } 285 | finally 286 | { 287 | if (sw != null) 288 | { 289 | sw.Close(); 290 | } 291 | if (fs_dir != null) 292 | { 293 | fs_dir.Close(); 294 | } 295 | } 296 | } 297 | 298 | } 299 | } 300 | } 301 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/http/HTTPRequest.cs: -------------------------------------------------------------------------------- 1 |  2 | using shack2.tools.model; 3 | using System; 4 | using System.Diagnostics; 5 | using System.IO; 6 | using System.Net; 7 | using System.Net.Security; 8 | using System.Security.Cryptography.X509Certificates; 9 | using System.Text; 10 | using System.Text.RegularExpressions; 11 | 12 | namespace shack2.tools.http 13 | { 14 | class HTTPRequest 15 | { 16 | 17 | public static String getHTMLEncoding(String contenType, String body) 18 | { 19 | if (String.IsNullOrEmpty(contenType) && String.IsNullOrEmpty(body)) 20 | { 21 | return ""; 22 | } 23 | body = body.ToUpper(); 24 | 25 | String encode = ""; 26 | Match m = Regex.Match(contenType, @"charset=(?[\w\-]+)", RegexOptions.IgnoreCase); 27 | if (m.Success) 28 | { 29 | encode = m.Groups["charset"].Value.ToUpper(); 30 | } 31 | else 32 | { 33 | if (String.IsNullOrEmpty(body)) 34 | { 35 | return ""; 36 | } 37 | m = Regex.Match(body, @"charset=['""]{0,1}(?[\w\-]+)['""]{0,1}", RegexOptions.IgnoreCase); 38 | if (m.Success) 39 | { 40 | encode = m.Groups["charset"].Value.ToUpper(); 41 | } 42 | } 43 | if ("UTF8".Equals(encode)) 44 | { 45 | encode = "UTF-8"; 46 | } 47 | return encode; 48 | 49 | 50 | } 51 | 52 | private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) 53 | { 54 | return true; //总是接受 55 | } 56 | 57 | public static ServerInfo SendRequestGetHeader(String method,String url,int timeout,bool keepAlive) 58 | { 59 | Stopwatch st = new Stopwatch(); 60 | st.Start(); 61 | HttpWebRequest request = null; 62 | HttpWebResponse response = null; 63 | ServerInfo res = new ServerInfo(); 64 | Stream rs = null; 65 | StreamReader sr = null; 66 | try 67 | { 68 | //设置模拟http访问参数 69 | Uri uri = new Uri(url); 70 | request = (HttpWebRequest)WebRequest.Create(uri); 71 | request.Accept = "*/*"; 72 | request.UserAgent = "Mozilla/5.0 (compatible; Baiduspider-render/2.0; +http://www.baidu.com/search/spider.html)"; 73 | request.Method = method; 74 | request.KeepAlive = keepAlive; 75 | request.Timeout = timeout*1000; 76 | request.Headers.Add("X-Forwarded-For", Tools.randIP()); 77 | request.Referer = "http://www.baidu.com/"; 78 | request.AllowAutoRedirect = false; 79 | request.ServicePoint.Expect100Continue = false; 80 | request.ServicePoint.UseNagleAlgorithm = false; 81 | request.ServicePoint.ConnectionLimit = 1024; 82 | request.AllowWriteStreamBuffering = false; 83 | request.Proxy = null; 84 | 85 | if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase)) 86 | { 87 | ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); 88 | 89 | } 90 | try 91 | { 92 | response = (HttpWebResponse)request.GetResponse(); 93 | 94 | } 95 | catch (WebException e) 96 | { 97 | response = (HttpWebResponse)e.Response; 98 | } 99 | 100 | res.contentType= response.ContentType; 101 | res.powerBy = response.Headers["X-Powered-By"]; 102 | res.location= response.Headers["Location"]; 103 | res.length = response.ContentLength; 104 | res.code = (int)(response.StatusCode); 105 | res.server = response.Server; 106 | } 107 | catch (WebException e) 108 | { 109 | Tools.SysLog("发生异常:" + e.Message); 110 | } 111 | finally 112 | { 113 | if (sr != null) 114 | { 115 | sr.Close(); 116 | } 117 | if (rs != null) 118 | { 119 | rs.Close(); 120 | } 121 | if (response != null) 122 | { 123 | response.Close(); 124 | } 125 | if (request != null) 126 | { 127 | request.Abort(); 128 | } 129 | } 130 | st.Stop(); 131 | res.runTime = st.ElapsedMilliseconds; 132 | return res; 133 | } 134 | 135 | public static ServerInfo SendRequestGetBody(String method, String url, int timeout,bool keeAlive) 136 | { 137 | HttpWebRequest request = null; 138 | HttpWebResponse response = null; 139 | ServerInfo res = new ServerInfo(); 140 | Stream rs = null; 141 | StreamReader sr = null; 142 | try 143 | { 144 | //设置模拟http访问参数 145 | Uri uri = new Uri(url); 146 | request = (HttpWebRequest)WebRequest.Create(uri); 147 | request.Accept = "*/*"; 148 | request.UserAgent = "Mozilla/5.0 (compatible; Baiduspider-render/2.0; +http://www.baidu.com/search/spider.html)"; 149 | request.KeepAlive = keeAlive; 150 | request.Timeout = timeout * 1000; 151 | request.Headers.Add("X-Forwarded-For", Tools.randIP()); 152 | request.Referer = "http://www.baidu.com/"; 153 | request.AllowAutoRedirect = false; 154 | request.ServicePoint.Expect100Continue = false; 155 | request.ServicePoint.UseNagleAlgorithm = false; 156 | request.ServicePoint.ConnectionLimit = 1024; 157 | request.AllowWriteStreamBuffering = false; 158 | request.Proxy = null; 159 | 160 | if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase)) 161 | { 162 | ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); 163 | 164 | } 165 | try 166 | { 167 | response = (HttpWebResponse)request.GetResponse(); 168 | 169 | } 170 | catch (WebException e) 171 | { 172 | response = (HttpWebResponse)e.Response; 173 | } 174 | res.contentType = response.ContentType; 175 | res.powerBy = response.Headers["powerby"]; 176 | res.location = response.Headers["location"]; 177 | res.length = response.ContentLength; 178 | res.code = (int)(response.StatusCode); 179 | res.server = response.Server; 180 | rs = response.GetResponseStream(); 181 | sr = new StreamReader(rs, Encoding.GetEncoding("UTF-8")); 182 | res.body = sr.ReadToEnd(); 183 | String encoding = getHTMLEncoding(response.ContentType, res.body); 184 | 185 | if (!"".Equals(encoding) && !"UTF-8".Equals(encoding, StringComparison.OrdinalIgnoreCase)) { 186 | rs = response.GetResponseStream(); 187 | sr = new StreamReader(rs, Encoding.GetEncoding(encoding)); 188 | res.body = sr.ReadToEnd(); 189 | } ; 190 | 191 | } 192 | catch (Exception e) 193 | { 194 | Tools.SysLog("发生异常:" + e.Message); 195 | } 196 | finally 197 | { 198 | if (sr != null) 199 | { 200 | sr.Close(); 201 | } 202 | if (rs != null) 203 | { 204 | rs.Close(); 205 | } 206 | if (response != null) 207 | { 208 | response.Close(); 209 | } 210 | if (request != null) 211 | { 212 | request.Abort(); 213 | } 214 | } 215 | return res; 216 | } 217 | 218 | public static String getHTML(String url,int timeout){ 219 | String html = ""; 220 | HttpWebResponse response = null; 221 | StreamReader sr = null; 222 | HttpWebRequest request = null; 223 | try 224 | { 225 | 226 | //设置模拟http访问参数 227 | Uri uri = new Uri(url); 228 | request = (HttpWebRequest)WebRequest.Create(uri); 229 | request.Accept = "*/*"; 230 | request.Method = "GET"; 231 | request.Timeout = timeout*1000; 232 | request.AllowAutoRedirect = false; 233 | response = (HttpWebResponse)request.GetResponse(); 234 | 235 | Stream s=response.GetResponseStream(); 236 | 237 | 238 | //读取服务器端返回的消息 239 | String encode = getHTMLEncoding(response.Headers["Content-Type"],""); 240 | if (!String.IsNullOrEmpty(encode)) 241 | { 242 | sr = new StreamReader(s, Encoding.GetEncoding(encode)); 243 | html = sr.ReadToEnd(); 244 | } 245 | else { 246 | sr = new StreamReader(s, Encoding.UTF8); 247 | html = sr.ReadToEnd(); 248 | } 249 | s.Close(); 250 | sr.Close(); 251 | } 252 | catch (Exception e) 253 | { 254 | Tools.SysLog(e.Message); 255 | } 256 | finally 257 | { 258 | if (response != null) 259 | { 260 | response.Close(); 261 | } 262 | if (request != null) 263 | { 264 | request.Abort(); 265 | } 266 | } 267 | return html; 268 | } 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/CallerThreadContext.cs: -------------------------------------------------------------------------------- 1 | 2 | #if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) 3 | 4 | using System; 5 | using System.Diagnostics; 6 | using System.Threading; 7 | using System.Reflection; 8 | using System.Web; 9 | using System.Runtime.Remoting.Messaging; 10 | 11 | 12 | namespace Amib.Threading.Internal 13 | { 14 | #region CallerThreadContext class 15 | 16 | /// 17 | /// This class stores the caller call context in order to restore 18 | /// it when the work item is executed in the thread pool environment. 19 | /// 20 | internal class CallerThreadContext 21 | { 22 | #region Prepare reflection information 23 | 24 | // Cached type information. 25 | private static readonly MethodInfo getLogicalCallContextMethodInfo = 26 | typeof(Thread).GetMethod("GetLogicalCallContext", BindingFlags.Instance | BindingFlags.NonPublic); 27 | 28 | private static readonly MethodInfo setLogicalCallContextMethodInfo = 29 | typeof(Thread).GetMethod("SetLogicalCallContext", BindingFlags.Instance | BindingFlags.NonPublic); 30 | 31 | private static string HttpContextSlotName = GetHttpContextSlotName(); 32 | 33 | private static string GetHttpContextSlotName() 34 | { 35 | FieldInfo fi = typeof(HttpContext).GetField("CallContextSlotName", BindingFlags.Static | BindingFlags.NonPublic); 36 | 37 | if (fi != null) 38 | { 39 | return (string) fi.GetValue(null); 40 | } 41 | 42 | return "HttpContext"; 43 | } 44 | 45 | #endregion 46 | 47 | #region Private fields 48 | 49 | private HttpContext _httpContext; 50 | private LogicalCallContext _callContext; 51 | 52 | #endregion 53 | 54 | /// 55 | /// Constructor 56 | /// 57 | private CallerThreadContext() 58 | { 59 | } 60 | 61 | public bool CapturedCallContext 62 | { 63 | get 64 | { 65 | return (null != _callContext); 66 | } 67 | } 68 | 69 | public bool CapturedHttpContext 70 | { 71 | get 72 | { 73 | return (null != _httpContext); 74 | } 75 | } 76 | 77 | /// 78 | /// Captures the current thread context 79 | /// 80 | /// 81 | public static CallerThreadContext Capture( 82 | bool captureCallContext, 83 | bool captureHttpContext) 84 | { 85 | Debug.Assert(captureCallContext || captureHttpContext); 86 | 87 | CallerThreadContext callerThreadContext = new CallerThreadContext(); 88 | 89 | // TODO: In NET 2.0, redo using the new feature of ExecutionContext class - Capture() 90 | // Capture Call Context 91 | if(captureCallContext && (getLogicalCallContextMethodInfo != null)) 92 | { 93 | callerThreadContext._callContext = (LogicalCallContext)getLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, null); 94 | if (callerThreadContext._callContext != null) 95 | { 96 | callerThreadContext._callContext = (LogicalCallContext)callerThreadContext._callContext.Clone(); 97 | } 98 | } 99 | 100 | // Capture httpContext 101 | if (captureHttpContext && (null != HttpContext.Current)) 102 | { 103 | callerThreadContext._httpContext = HttpContext.Current; 104 | } 105 | 106 | return callerThreadContext; 107 | } 108 | 109 | /// 110 | /// Applies the thread context stored earlier 111 | /// 112 | /// 113 | public static void Apply(CallerThreadContext callerThreadContext) 114 | { 115 | if (null == callerThreadContext) 116 | { 117 | throw new ArgumentNullException("callerThreadContext"); 118 | } 119 | 120 | // Todo: In NET 2.0, redo using the new feature of ExecutionContext class - Run() 121 | // Restore call context 122 | if ((callerThreadContext._callContext != null) && (setLogicalCallContextMethodInfo != null)) 123 | { 124 | setLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, new object[] { callerThreadContext._callContext }); 125 | } 126 | 127 | // Restore HttpContext 128 | if (callerThreadContext._httpContext != null) 129 | { 130 | HttpContext.Current = callerThreadContext._httpContext; 131 | //CallContext.SetData(HttpContextSlotName, callerThreadContext._httpContext); 132 | } 133 | } 134 | } 135 | 136 | #endregion 137 | } 138 | #endif 139 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/CanceledWorkItemsGroup.cs: -------------------------------------------------------------------------------- 1 | namespace Amib.Threading.Internal 2 | { 3 | internal class CanceledWorkItemsGroup 4 | { 5 | public readonly static CanceledWorkItemsGroup NotCanceledWorkItemsGroup = new CanceledWorkItemsGroup(); 6 | 7 | public CanceledWorkItemsGroup() 8 | { 9 | IsCanceled = false; 10 | } 11 | 12 | public bool IsCanceled { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/EventWaitHandle.cs: -------------------------------------------------------------------------------- 1 | #if (_WINDOWS_CE) 2 | 3 | using System; 4 | using System.Runtime.InteropServices; 5 | using System.Threading; 6 | 7 | namespace Amib.Threading.Internal 8 | { 9 | /// 10 | /// EventWaitHandle class 11 | /// In WindowsCE this class doesn't exist and I needed the WaitAll and WaitAny implementation. 12 | /// So I wrote this class to implement these two methods with some of their overloads. 13 | /// It uses the WaitForMultipleObjects API to do the WaitAll and WaitAny. 14 | /// Note that this class doesn't even inherit from WaitHandle! 15 | /// 16 | public class STPEventWaitHandle 17 | { 18 | #region Public Constants 19 | 20 | public const int WaitTimeout = Timeout.Infinite; 21 | 22 | #endregion 23 | 24 | #region Private External Constants 25 | 26 | private const Int32 WAIT_FAILED = -1; 27 | private const Int32 WAIT_TIMEOUT = 0x102; 28 | private const UInt32 INFINITE = 0xFFFFFFFF; 29 | 30 | #endregion 31 | 32 | #region WaitAll and WaitAny 33 | 34 | internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext) 35 | { 36 | return waitHandle.WaitOne(millisecondsTimeout, exitContext); 37 | } 38 | 39 | private static IntPtr[] PrepareNativeHandles(WaitHandle[] waitHandles) 40 | { 41 | IntPtr[] nativeHandles = new IntPtr[waitHandles.Length]; 42 | for (int i = 0; i < waitHandles.Length; i++) 43 | { 44 | nativeHandles[i] = waitHandles[i].Handle; 45 | } 46 | return nativeHandles; 47 | } 48 | 49 | public static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) 50 | { 51 | uint timeout = millisecondsTimeout < 0 ? INFINITE : (uint)millisecondsTimeout; 52 | 53 | IntPtr[] nativeHandles = PrepareNativeHandles(waitHandles); 54 | 55 | int result = WaitForMultipleObjects((uint)waitHandles.Length, nativeHandles, true, timeout); 56 | 57 | if (result == WAIT_TIMEOUT || result == WAIT_FAILED) 58 | { 59 | return false; 60 | } 61 | 62 | return true; 63 | } 64 | 65 | 66 | public static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) 67 | { 68 | uint timeout = millisecondsTimeout < 0 ? INFINITE : (uint)millisecondsTimeout; 69 | 70 | IntPtr[] nativeHandles = PrepareNativeHandles(waitHandles); 71 | 72 | int result = WaitForMultipleObjects((uint)waitHandles.Length, nativeHandles, false, timeout); 73 | 74 | if (result >= 0 && result < waitHandles.Length) 75 | { 76 | return result; 77 | } 78 | 79 | return -1; 80 | } 81 | 82 | public static int WaitAny(WaitHandle[] waitHandles) 83 | { 84 | return WaitAny(waitHandles, Timeout.Infinite, false); 85 | } 86 | 87 | public static int WaitAny(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext) 88 | { 89 | int millisecondsTimeout = (int)timeout.TotalMilliseconds; 90 | 91 | return WaitAny(waitHandles, millisecondsTimeout, false); 92 | } 93 | 94 | #endregion 95 | 96 | #region External methods 97 | 98 | [DllImport("coredll.dll", SetLastError = true)] 99 | public static extern int WaitForMultipleObjects(uint nCount, IntPtr[] lpHandles, bool fWaitAll, uint dwMilliseconds); 100 | 101 | #endregion 102 | } 103 | } 104 | #endif -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/EventWaitHandleFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | 3 | #if (_WINDOWS_CE) 4 | using System; 5 | using System.Runtime.InteropServices; 6 | #endif 7 | 8 | namespace Amib.Threading.Internal 9 | { 10 | /// 11 | /// EventWaitHandleFactory class. 12 | /// This is a static class that creates AutoResetEvent and ManualResetEvent objects. 13 | /// In WindowCE the WaitForMultipleObjects API fails to use the Handle property 14 | /// of XxxResetEvent. It can use only handles that were created by the CreateEvent API. 15 | /// Consequently this class creates the needed XxxResetEvent and replaces the handle if 16 | /// it's a WindowsCE OS. 17 | /// 18 | public static class EventWaitHandleFactory 19 | { 20 | /// 21 | /// Create a new AutoResetEvent object 22 | /// 23 | /// Return a new AutoResetEvent object 24 | public static AutoResetEvent CreateAutoResetEvent() 25 | { 26 | AutoResetEvent waitHandle = new AutoResetEvent(false); 27 | 28 | #if (_WINDOWS_CE) 29 | ReplaceEventHandle(waitHandle, false, false); 30 | #endif 31 | 32 | return waitHandle; 33 | } 34 | 35 | /// 36 | /// Create a new ManualResetEvent object 37 | /// 38 | /// Return a new ManualResetEvent object 39 | public static ManualResetEvent CreateManualResetEvent(bool initialState) 40 | { 41 | ManualResetEvent waitHandle = new ManualResetEvent(initialState); 42 | 43 | #if (_WINDOWS_CE) 44 | ReplaceEventHandle(waitHandle, true, initialState); 45 | #endif 46 | 47 | return waitHandle; 48 | } 49 | 50 | #if (_WINDOWS_CE) 51 | 52 | /// 53 | /// Replace the event handle 54 | /// 55 | /// The WaitHandle object which its handle needs to be replaced. 56 | /// Indicates if the event is a ManualResetEvent (true) or an AutoResetEvent (false) 57 | /// The initial state of the event 58 | private static void ReplaceEventHandle(WaitHandle waitHandle, bool manualReset, bool initialState) 59 | { 60 | // Store the old handle 61 | IntPtr oldHandle = waitHandle.Handle; 62 | 63 | // Create a new event 64 | IntPtr newHandle = CreateEvent(IntPtr.Zero, manualReset, initialState, null); 65 | 66 | // Replace the old event with the new event 67 | waitHandle.Handle = newHandle; 68 | 69 | // Close the old event 70 | CloseHandle (oldHandle); 71 | } 72 | 73 | [DllImport("coredll.dll", SetLastError = true)] 74 | public static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName); 75 | 76 | //Handle 77 | [DllImport("coredll.dll", SetLastError = true)] 78 | public static extern bool CloseHandle(IntPtr hObject); 79 | #endif 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/Exceptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | #if !(_WINDOWS_CE) 3 | using System.Runtime.Serialization; 4 | #endif 5 | 6 | namespace Amib.Threading 7 | { 8 | #region Exceptions 9 | 10 | /// 11 | /// Represents an exception in case IWorkItemResult.GetResult has been canceled 12 | /// 13 | public sealed partial class WorkItemCancelException : Exception 14 | { 15 | public WorkItemCancelException() 16 | { 17 | } 18 | 19 | public WorkItemCancelException(string message) 20 | : base(message) 21 | { 22 | } 23 | 24 | public WorkItemCancelException(string message, Exception e) 25 | : base(message, e) 26 | { 27 | } 28 | } 29 | 30 | /// 31 | /// Represents an exception in case IWorkItemResult.GetResult has been timed out 32 | /// 33 | public sealed partial class WorkItemTimeoutException : Exception 34 | { 35 | public WorkItemTimeoutException() 36 | { 37 | } 38 | 39 | public WorkItemTimeoutException(string message) 40 | : base(message) 41 | { 42 | } 43 | 44 | public WorkItemTimeoutException(string message, Exception e) 45 | : base(message, e) 46 | { 47 | } 48 | } 49 | 50 | /// 51 | /// Represents an exception in case IWorkItemResult.GetResult has been timed out 52 | /// 53 | public sealed partial class WorkItemResultException : Exception 54 | { 55 | public WorkItemResultException() 56 | { 57 | } 58 | 59 | public WorkItemResultException(string message) 60 | : base(message) 61 | { 62 | } 63 | 64 | public WorkItemResultException(string message, Exception e) 65 | : base(message, e) 66 | { 67 | } 68 | } 69 | 70 | 71 | /// 72 | /// Represents an exception in case the STP queue is full and work item cannot be queued. 73 | /// Relevant when the STP has a queue size limit 74 | /// 75 | public sealed partial class QueueRejectedException : Exception 76 | { 77 | public QueueRejectedException() 78 | { 79 | } 80 | 81 | public QueueRejectedException(string message) 82 | : base(message) 83 | { 84 | } 85 | 86 | public QueueRejectedException(string message, Exception e) 87 | : base(message, e) 88 | { 89 | } 90 | } 91 | 92 | #if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) 93 | /// 94 | /// Represents an exception in case IWorkItemResult.GetResult has been canceled 95 | /// 96 | [Serializable] 97 | public sealed partial class WorkItemCancelException 98 | { 99 | public WorkItemCancelException(SerializationInfo si, StreamingContext sc) 100 | : base(si, sc) 101 | { 102 | } 103 | } 104 | 105 | /// 106 | /// Represents an exception in case IWorkItemResult.GetResult has been timed out 107 | /// 108 | [Serializable] 109 | public sealed partial class WorkItemTimeoutException 110 | { 111 | public WorkItemTimeoutException(SerializationInfo si, StreamingContext sc) 112 | : base(si, sc) 113 | { 114 | } 115 | } 116 | 117 | /// 118 | /// Represents an exception in case IWorkItemResult.GetResult has been timed out 119 | /// 120 | [Serializable] 121 | public sealed partial class WorkItemResultException 122 | { 123 | public WorkItemResultException(SerializationInfo si, StreamingContext sc) 124 | : base(si, sc) 125 | { 126 | } 127 | } 128 | 129 | /// 130 | /// Represents an exception in case IWorkItemResult.GetResult has been timed out 131 | /// 132 | [Serializable] 133 | public sealed partial class QueueRejectedException 134 | { 135 | public QueueRejectedException(SerializationInfo si, StreamingContext sc) 136 | : base(si, sc) 137 | { 138 | } 139 | } 140 | 141 | #endif 142 | 143 | #endregion 144 | } 145 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/InternalInterfaces.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Amib.Threading.Internal 3 | { 4 | /// 5 | /// An internal delegate to call when the WorkItem starts or completes 6 | /// 7 | internal delegate void WorkItemStateCallback(WorkItem workItem); 8 | 9 | internal interface IInternalWorkItemResult 10 | { 11 | event WorkItemStateCallback OnWorkItemStarted; 12 | event WorkItemStateCallback OnWorkItemCompleted; 13 | } 14 | 15 | internal interface IInternalWaitableResult 16 | { 17 | /// 18 | /// This method is intent for internal use. 19 | /// 20 | IWorkItemResult GetWorkItemResult(); 21 | } 22 | 23 | public interface IHasWorkItemPriority 24 | { 25 | WorkItemPriority WorkItemPriority { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/PriorityQueue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | 6 | namespace Amib.Threading.Internal 7 | { 8 | #region PriorityQueue class 9 | 10 | /// 11 | /// PriorityQueue class 12 | /// This class is not thread safe because we use external lock 13 | /// 14 | public sealed class PriorityQueue : IEnumerable 15 | { 16 | #region Private members 17 | 18 | /// 19 | /// The number of queues, there is one for each type of priority 20 | /// 21 | private const int _queuesCount = WorkItemPriority.Highest-WorkItemPriority.Lowest+1; 22 | 23 | /// 24 | /// Work items queues. There is one for each type of priority 25 | /// 26 | private readonly LinkedList[] _queues = new LinkedList[_queuesCount]; 27 | 28 | /// 29 | /// The total number of work items within the queues 30 | /// 31 | private int _workItemsCount; 32 | 33 | /// 34 | /// Use with IEnumerable interface 35 | /// 36 | private int _version; 37 | 38 | #endregion 39 | 40 | #region Contructor 41 | 42 | public PriorityQueue() 43 | { 44 | for(int i = 0; i < _queues.Length; ++i) 45 | { 46 | _queues[i] = new LinkedList(); 47 | } 48 | } 49 | 50 | #endregion 51 | 52 | #region Methods 53 | 54 | /// 55 | /// Enqueue a work item. 56 | /// 57 | /// A work item 58 | public void Enqueue(IHasWorkItemPriority workItem) 59 | { 60 | Debug.Assert(null != workItem); 61 | 62 | int queueIndex = _queuesCount-(int)workItem.WorkItemPriority-1; 63 | Debug.Assert(queueIndex >= 0); 64 | Debug.Assert(queueIndex < _queuesCount); 65 | 66 | _queues[queueIndex].AddLast(workItem); 67 | ++_workItemsCount; 68 | ++_version; 69 | } 70 | 71 | /// 72 | /// Dequeque a work item. 73 | /// 74 | /// Returns the next work item 75 | public IHasWorkItemPriority Dequeue() 76 | { 77 | IHasWorkItemPriority workItem = null; 78 | 79 | if(_workItemsCount > 0) 80 | { 81 | int queueIndex = GetNextNonEmptyQueue(-1); 82 | Debug.Assert(queueIndex >= 0); 83 | workItem = _queues[queueIndex].First.Value; 84 | _queues[queueIndex].RemoveFirst(); 85 | Debug.Assert(null != workItem); 86 | --_workItemsCount; 87 | ++_version; 88 | } 89 | 90 | return workItem; 91 | } 92 | 93 | /// 94 | /// Find the next non empty queue starting at queue queueIndex+1 95 | /// 96 | /// The index-1 to start from 97 | /// 98 | /// The index of the next non empty queue or -1 if all the queues are empty 99 | /// 100 | private int GetNextNonEmptyQueue(int queueIndex) 101 | { 102 | for(int i = queueIndex+1; i < _queuesCount; ++i) 103 | { 104 | if(_queues[i].Count > 0) 105 | { 106 | return i; 107 | } 108 | } 109 | return -1; 110 | } 111 | 112 | /// 113 | /// The number of work items 114 | /// 115 | public int Count 116 | { 117 | get 118 | { 119 | return _workItemsCount; 120 | } 121 | } 122 | 123 | /// 124 | /// Clear all the work items 125 | /// 126 | public void Clear() 127 | { 128 | if (_workItemsCount > 0) 129 | { 130 | foreach(LinkedList queue in _queues) 131 | { 132 | queue.Clear(); 133 | } 134 | _workItemsCount = 0; 135 | ++_version; 136 | } 137 | } 138 | 139 | #endregion 140 | 141 | #region IEnumerable Members 142 | 143 | /// 144 | /// Returns an enumerator to iterate over the work items 145 | /// 146 | /// Returns an enumerator 147 | public IEnumerator GetEnumerator() 148 | { 149 | return new PriorityQueueEnumerator(this); 150 | } 151 | 152 | #endregion 153 | 154 | #region PriorityQueueEnumerator 155 | 156 | /// 157 | /// The class the implements the enumerator 158 | /// 159 | private class PriorityQueueEnumerator : IEnumerator 160 | { 161 | private readonly PriorityQueue _priorityQueue; 162 | private int _version; 163 | private int _queueIndex; 164 | private IEnumerator _enumerator; 165 | 166 | public PriorityQueueEnumerator(PriorityQueue priorityQueue) 167 | { 168 | _priorityQueue = priorityQueue; 169 | _version = _priorityQueue._version; 170 | _queueIndex = _priorityQueue.GetNextNonEmptyQueue(-1); 171 | if (_queueIndex >= 0) 172 | { 173 | _enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator(); 174 | } 175 | else 176 | { 177 | _enumerator = null; 178 | } 179 | } 180 | 181 | #region IEnumerator Members 182 | 183 | public void Reset() 184 | { 185 | _version = _priorityQueue._version; 186 | _queueIndex = _priorityQueue.GetNextNonEmptyQueue(-1); 187 | if (_queueIndex >= 0) 188 | { 189 | _enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator(); 190 | } 191 | else 192 | { 193 | _enumerator = null; 194 | } 195 | } 196 | 197 | public object Current 198 | { 199 | get 200 | { 201 | Debug.Assert(null != _enumerator); 202 | return _enumerator.Current; 203 | } 204 | } 205 | 206 | public bool MoveNext() 207 | { 208 | if (null == _enumerator) 209 | { 210 | return false; 211 | } 212 | 213 | if(_version != _priorityQueue._version) 214 | { 215 | throw new InvalidOperationException("The collection has been modified"); 216 | 217 | } 218 | if (!_enumerator.MoveNext()) 219 | { 220 | _queueIndex = _priorityQueue.GetNextNonEmptyQueue(_queueIndex); 221 | if(-1 == _queueIndex) 222 | { 223 | return false; 224 | } 225 | _enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator(); 226 | _enumerator.MoveNext(); 227 | return true; 228 | } 229 | return true; 230 | } 231 | 232 | #endregion 233 | } 234 | 235 | #endregion 236 | } 237 | 238 | #endregion 239 | } 240 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/SLExt.cs: -------------------------------------------------------------------------------- 1 | #if _SILVERLIGHT 2 | 3 | using System.Threading; 4 | 5 | namespace Amib.Threading 6 | { 7 | public enum ThreadPriority 8 | { 9 | Lowest, 10 | BelowNormal, 11 | Normal, 12 | AboveNormal, 13 | Highest, 14 | } 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/STPEventWaitHandle.cs: -------------------------------------------------------------------------------- 1 | #if !(_WINDOWS_CE) 2 | 3 | using System; 4 | using System.Threading; 5 | 6 | namespace Amib.Threading.Internal 7 | { 8 | #if _SILVERLIGHT || WINDOWS_PHONE 9 | internal static class STPEventWaitHandle 10 | { 11 | public const int WaitTimeout = Timeout.Infinite; 12 | 13 | internal static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) 14 | { 15 | return WaitHandle.WaitAll(waitHandles, millisecondsTimeout); 16 | } 17 | 18 | internal static int WaitAny(WaitHandle[] waitHandles) 19 | { 20 | return WaitHandle.WaitAny(waitHandles); 21 | } 22 | 23 | internal static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) 24 | { 25 | return WaitHandle.WaitAny(waitHandles, millisecondsTimeout); 26 | } 27 | 28 | internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext) 29 | { 30 | return waitHandle.WaitOne(millisecondsTimeout); 31 | } 32 | } 33 | #else 34 | internal static class STPEventWaitHandle 35 | { 36 | public const int WaitTimeout = Timeout.Infinite; 37 | 38 | internal static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) 39 | { 40 | return WaitHandle.WaitAll(waitHandles, millisecondsTimeout, exitContext); 41 | } 42 | 43 | internal static int WaitAny(WaitHandle[] waitHandles) 44 | { 45 | return WaitHandle.WaitAny(waitHandles); 46 | } 47 | 48 | internal static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) 49 | { 50 | return WaitHandle.WaitAny(waitHandles, millisecondsTimeout, exitContext); 51 | } 52 | 53 | internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext) 54 | { 55 | return waitHandle.WaitOne(millisecondsTimeout, exitContext); 56 | } 57 | } 58 | #endif 59 | 60 | } 61 | 62 | #endif -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/STPPerformanceCounter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading; 4 | 5 | namespace Amib.Threading 6 | { 7 | public interface ISTPPerformanceCountersReader 8 | { 9 | long InUseThreads { get; } 10 | long ActiveThreads { get; } 11 | long WorkItemsQueued { get; } 12 | long WorkItemsProcessed { get; } 13 | } 14 | } 15 | 16 | namespace Amib.Threading.Internal 17 | { 18 | internal interface ISTPInstancePerformanceCounters : IDisposable 19 | { 20 | void Close(); 21 | void SampleThreads(long activeThreads, long inUseThreads); 22 | void SampleWorkItems(long workItemsQueued, long workItemsProcessed); 23 | void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime); 24 | void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime); 25 | } 26 | #if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) 27 | 28 | internal enum STPPerformanceCounterType 29 | { 30 | // Fields 31 | ActiveThreads = 0, 32 | InUseThreads = 1, 33 | OverheadThreads = 2, 34 | OverheadThreadsPercent = 3, 35 | OverheadThreadsPercentBase = 4, 36 | 37 | WorkItems = 5, 38 | WorkItemsInQueue = 6, 39 | WorkItemsProcessed = 7, 40 | 41 | WorkItemsQueuedPerSecond = 8, 42 | WorkItemsProcessedPerSecond = 9, 43 | 44 | AvgWorkItemWaitTime = 10, 45 | AvgWorkItemWaitTimeBase = 11, 46 | 47 | AvgWorkItemProcessTime = 12, 48 | AvgWorkItemProcessTimeBase = 13, 49 | 50 | WorkItemsGroups = 14, 51 | 52 | LastCounter = 14, 53 | } 54 | 55 | 56 | /// 57 | /// Summary description for STPPerformanceCounter. 58 | /// 59 | internal class STPPerformanceCounter 60 | { 61 | // Fields 62 | private readonly PerformanceCounterType _pcType; 63 | protected string _counterHelp; 64 | protected string _counterName; 65 | 66 | // Methods 67 | public STPPerformanceCounter( 68 | string counterName, 69 | string counterHelp, 70 | PerformanceCounterType pcType) 71 | { 72 | _counterName = counterName; 73 | _counterHelp = counterHelp; 74 | _pcType = pcType; 75 | } 76 | 77 | public void AddCounterToCollection(CounterCreationDataCollection counterData) 78 | { 79 | CounterCreationData counterCreationData = new CounterCreationData( 80 | _counterName, 81 | _counterHelp, 82 | _pcType); 83 | 84 | counterData.Add(counterCreationData); 85 | } 86 | 87 | // Properties 88 | public string Name 89 | { 90 | get 91 | { 92 | return _counterName; 93 | } 94 | } 95 | } 96 | 97 | internal class STPPerformanceCounters 98 | { 99 | // Fields 100 | internal STPPerformanceCounter[] _stpPerformanceCounters; 101 | private static readonly STPPerformanceCounters _instance; 102 | internal const string _stpCategoryHelp = "SmartThreadPool performance counters"; 103 | internal const string _stpCategoryName = "SmartThreadPool"; 104 | 105 | // Methods 106 | static STPPerformanceCounters() 107 | { 108 | _instance = new STPPerformanceCounters(); 109 | } 110 | 111 | private STPPerformanceCounters() 112 | { 113 | STPPerformanceCounter[] stpPerformanceCounters = new STPPerformanceCounter[] 114 | { 115 | new STPPerformanceCounter("Active threads", "The current number of available in the thread pool.", PerformanceCounterType.NumberOfItems32), 116 | new STPPerformanceCounter("In use threads", "The current number of threads that execute a work item.", PerformanceCounterType.NumberOfItems32), 117 | new STPPerformanceCounter("Overhead threads", "The current number of threads that are active, but are not in use.", PerformanceCounterType.NumberOfItems32), 118 | new STPPerformanceCounter("% overhead threads", "The current number of threads that are active, but are not in use in percents.", PerformanceCounterType.RawFraction), 119 | new STPPerformanceCounter("% overhead threads base", "The current number of threads that are active, but are not in use in percents.", PerformanceCounterType.RawBase), 120 | 121 | new STPPerformanceCounter("Work Items", "The number of work items in the Smart Thread Pool. Both queued and processed.", PerformanceCounterType.NumberOfItems32), 122 | new STPPerformanceCounter("Work Items in queue", "The current number of work items in the queue", PerformanceCounterType.NumberOfItems32), 123 | new STPPerformanceCounter("Work Items processed", "The number of work items already processed", PerformanceCounterType.NumberOfItems32), 124 | 125 | new STPPerformanceCounter("Work Items queued/sec", "The number of work items queued per second", PerformanceCounterType.RateOfCountsPerSecond32), 126 | new STPPerformanceCounter("Work Items processed/sec", "The number of work items processed per second", PerformanceCounterType.RateOfCountsPerSecond32), 127 | 128 | new STPPerformanceCounter("Avg. Work Item wait time/sec", "The average time a work item supends in the queue waiting for its turn to execute.", PerformanceCounterType.AverageCount64), 129 | new STPPerformanceCounter("Avg. Work Item wait time base", "The average time a work item supends in the queue waiting for its turn to execute.", PerformanceCounterType.AverageBase), 130 | 131 | new STPPerformanceCounter("Avg. Work Item process time/sec", "The average time it takes to process a work item.", PerformanceCounterType.AverageCount64), 132 | new STPPerformanceCounter("Avg. Work Item process time base", "The average time it takes to process a work item.", PerformanceCounterType.AverageBase), 133 | 134 | new STPPerformanceCounter("Work Items Groups", "The current number of work item groups associated with the Smart Thread Pool.", PerformanceCounterType.NumberOfItems32), 135 | }; 136 | 137 | _stpPerformanceCounters = stpPerformanceCounters; 138 | SetupCategory(); 139 | } 140 | 141 | private void SetupCategory() 142 | { 143 | if (!PerformanceCounterCategory.Exists(_stpCategoryName)) 144 | { 145 | CounterCreationDataCollection counters = new CounterCreationDataCollection(); 146 | 147 | for (int i = 0; i < _stpPerformanceCounters.Length; i++) 148 | { 149 | _stpPerformanceCounters[i].AddCounterToCollection(counters); 150 | } 151 | 152 | PerformanceCounterCategory.Create( 153 | _stpCategoryName, 154 | _stpCategoryHelp, 155 | PerformanceCounterCategoryType.MultiInstance, 156 | counters); 157 | 158 | } 159 | } 160 | 161 | // Properties 162 | public static STPPerformanceCounters Instance 163 | { 164 | get 165 | { 166 | return _instance; 167 | } 168 | } 169 | } 170 | 171 | internal class STPInstancePerformanceCounter : IDisposable 172 | { 173 | // Fields 174 | private bool _isDisposed; 175 | private PerformanceCounter _pcs; 176 | 177 | // Methods 178 | protected STPInstancePerformanceCounter() 179 | { 180 | _isDisposed = false; 181 | } 182 | 183 | public STPInstancePerformanceCounter( 184 | string instance, 185 | STPPerformanceCounterType spcType) : this() 186 | { 187 | STPPerformanceCounters counters = STPPerformanceCounters.Instance; 188 | _pcs = new PerformanceCounter( 189 | STPPerformanceCounters._stpCategoryName, 190 | counters._stpPerformanceCounters[(int) spcType].Name, 191 | instance, 192 | false); 193 | _pcs.RawValue = _pcs.RawValue; 194 | } 195 | 196 | 197 | public void Close() 198 | { 199 | if (_pcs != null) 200 | { 201 | _pcs.RemoveInstance(); 202 | _pcs.Close(); 203 | _pcs = null; 204 | } 205 | } 206 | 207 | public void Dispose() 208 | { 209 | Dispose(true); 210 | } 211 | 212 | public virtual void Dispose(bool disposing) 213 | { 214 | if (!_isDisposed) 215 | { 216 | if (disposing) 217 | { 218 | Close(); 219 | } 220 | } 221 | _isDisposed = true; 222 | } 223 | 224 | public virtual void Increment() 225 | { 226 | _pcs.Increment(); 227 | } 228 | 229 | public virtual void IncrementBy(long val) 230 | { 231 | _pcs.IncrementBy(val); 232 | } 233 | 234 | public virtual void Set(long val) 235 | { 236 | _pcs.RawValue = val; 237 | } 238 | } 239 | 240 | internal class STPInstanceNullPerformanceCounter : STPInstancePerformanceCounter 241 | { 242 | // Methods 243 | public override void Increment() {} 244 | public override void IncrementBy(long value) {} 245 | public override void Set(long val) {} 246 | } 247 | 248 | 249 | 250 | internal class STPInstancePerformanceCounters : ISTPInstancePerformanceCounters 251 | { 252 | private bool _isDisposed; 253 | // Fields 254 | private STPInstancePerformanceCounter[] _pcs; 255 | private static readonly STPInstancePerformanceCounter _stpInstanceNullPerformanceCounter; 256 | 257 | // Methods 258 | static STPInstancePerformanceCounters() 259 | { 260 | _stpInstanceNullPerformanceCounter = new STPInstanceNullPerformanceCounter(); 261 | } 262 | 263 | public STPInstancePerformanceCounters(string instance) 264 | { 265 | _isDisposed = false; 266 | _pcs = new STPInstancePerformanceCounter[(int)STPPerformanceCounterType.LastCounter]; 267 | 268 | // Call the STPPerformanceCounters.Instance so the static constructor will 269 | // intialize the STPPerformanceCounters singleton. 270 | STPPerformanceCounters.Instance.GetHashCode(); 271 | 272 | for (int i = 0; i < _pcs.Length; i++) 273 | { 274 | if (instance != null) 275 | { 276 | _pcs[i] = new STPInstancePerformanceCounter( 277 | instance, 278 | (STPPerformanceCounterType) i); 279 | } 280 | else 281 | { 282 | _pcs[i] = _stpInstanceNullPerformanceCounter; 283 | } 284 | } 285 | } 286 | 287 | 288 | public void Close() 289 | { 290 | if (null != _pcs) 291 | { 292 | for (int i = 0; i < _pcs.Length; i++) 293 | { 294 | if (null != _pcs[i]) 295 | { 296 | _pcs[i].Dispose(); 297 | } 298 | } 299 | _pcs = null; 300 | } 301 | } 302 | 303 | public void Dispose() 304 | { 305 | Dispose(true); 306 | } 307 | 308 | public virtual void Dispose(bool disposing) 309 | { 310 | if (!_isDisposed) 311 | { 312 | if (disposing) 313 | { 314 | Close(); 315 | } 316 | } 317 | _isDisposed = true; 318 | } 319 | 320 | private STPInstancePerformanceCounter GetCounter(STPPerformanceCounterType spcType) 321 | { 322 | return _pcs[(int) spcType]; 323 | } 324 | 325 | public void SampleThreads(long activeThreads, long inUseThreads) 326 | { 327 | GetCounter(STPPerformanceCounterType.ActiveThreads).Set(activeThreads); 328 | GetCounter(STPPerformanceCounterType.InUseThreads).Set(inUseThreads); 329 | GetCounter(STPPerformanceCounterType.OverheadThreads).Set(activeThreads-inUseThreads); 330 | 331 | GetCounter(STPPerformanceCounterType.OverheadThreadsPercentBase).Set(activeThreads-inUseThreads); 332 | GetCounter(STPPerformanceCounterType.OverheadThreadsPercent).Set(inUseThreads); 333 | } 334 | 335 | public void SampleWorkItems(long workItemsQueued, long workItemsProcessed) 336 | { 337 | GetCounter(STPPerformanceCounterType.WorkItems).Set(workItemsQueued+workItemsProcessed); 338 | GetCounter(STPPerformanceCounterType.WorkItemsInQueue).Set(workItemsQueued); 339 | GetCounter(STPPerformanceCounterType.WorkItemsProcessed).Set(workItemsProcessed); 340 | 341 | GetCounter(STPPerformanceCounterType.WorkItemsQueuedPerSecond).Set(workItemsQueued); 342 | GetCounter(STPPerformanceCounterType.WorkItemsProcessedPerSecond).Set(workItemsProcessed); 343 | } 344 | 345 | public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime) 346 | { 347 | GetCounter(STPPerformanceCounterType.AvgWorkItemWaitTime).IncrementBy((long)workItemWaitTime.TotalMilliseconds); 348 | GetCounter(STPPerformanceCounterType.AvgWorkItemWaitTimeBase).Increment(); 349 | } 350 | 351 | public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime) 352 | { 353 | GetCounter(STPPerformanceCounterType.AvgWorkItemProcessTime).IncrementBy((long)workItemProcessTime.TotalMilliseconds); 354 | GetCounter(STPPerformanceCounterType.AvgWorkItemProcessTimeBase).Increment(); 355 | } 356 | } 357 | #endif 358 | 359 | internal class NullSTPInstancePerformanceCounters : ISTPInstancePerformanceCounters, ISTPPerformanceCountersReader 360 | { 361 | private static readonly NullSTPInstancePerformanceCounters _instance = new NullSTPInstancePerformanceCounters(); 362 | 363 | public static NullSTPInstancePerformanceCounters Instance 364 | { 365 | get { return _instance; } 366 | } 367 | 368 | public void Close() {} 369 | public void Dispose() {} 370 | 371 | public void SampleThreads(long activeThreads, long inUseThreads) {} 372 | public void SampleWorkItems(long workItemsQueued, long workItemsProcessed) {} 373 | public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime) {} 374 | public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime) {} 375 | public long InUseThreads 376 | { 377 | get { return 0; } 378 | } 379 | 380 | public long ActiveThreads 381 | { 382 | get { return 0; } 383 | } 384 | 385 | public long WorkItemsQueued 386 | { 387 | get { return 0; } 388 | } 389 | 390 | public long WorkItemsProcessed 391 | { 392 | get { return 0; } 393 | } 394 | } 395 | 396 | internal class LocalSTPInstancePerformanceCounters : ISTPInstancePerformanceCounters, ISTPPerformanceCountersReader 397 | { 398 | public void Close() { } 399 | public void Dispose() { } 400 | 401 | private long _activeThreads; 402 | private long _inUseThreads; 403 | private long _workItemsQueued; 404 | private long _workItemsProcessed; 405 | 406 | public long InUseThreads 407 | { 408 | get { return _inUseThreads; } 409 | } 410 | 411 | public long ActiveThreads 412 | { 413 | get { return _activeThreads; } 414 | } 415 | 416 | public long WorkItemsQueued 417 | { 418 | get { return _workItemsQueued; } 419 | } 420 | 421 | public long WorkItemsProcessed 422 | { 423 | get { return _workItemsProcessed; } 424 | } 425 | 426 | public void SampleThreads(long activeThreads, long inUseThreads) 427 | { 428 | _activeThreads = activeThreads; 429 | _inUseThreads = inUseThreads; 430 | } 431 | 432 | public void SampleWorkItems(long workItemsQueued, long workItemsProcessed) 433 | { 434 | _workItemsQueued = workItemsQueued; 435 | _workItemsProcessed = workItemsProcessed; 436 | } 437 | 438 | public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime) 439 | { 440 | // Not supported 441 | } 442 | 443 | public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime) 444 | { 445 | // Not supported 446 | } 447 | } 448 | } 449 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/STPStartInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | 4 | namespace Amib.Threading 5 | { 6 | /// 7 | /// Summary description for STPStartInfo. 8 | /// 9 | public class STPStartInfo : WIGStartInfo 10 | { 11 | private int _idleTimeout = SmartThreadPool.DefaultIdleTimeout; 12 | private int _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads; 13 | private int _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads; 14 | #if !(WINDOWS_PHONE) 15 | private ThreadPriority _threadPriority = SmartThreadPool.DefaultThreadPriority; 16 | #endif 17 | private string _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName; 18 | private bool _areThreadsBackground = SmartThreadPool.DefaultAreThreadsBackground; 19 | private bool _enableLocalPerformanceCounters; 20 | private string _threadPoolName = SmartThreadPool.DefaultThreadPoolName; 21 | private int? _maxStackSize = SmartThreadPool.DefaultMaxStackSize; 22 | private int? _maxQueueLength = SmartThreadPool.DefaultMaxQueueLength; 23 | 24 | public STPStartInfo() 25 | { 26 | _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName; 27 | #if !(WINDOWS_PHONE) 28 | _threadPriority = SmartThreadPool.DefaultThreadPriority; 29 | #endif 30 | _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads; 31 | _idleTimeout = SmartThreadPool.DefaultIdleTimeout; 32 | _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads; 33 | } 34 | 35 | public STPStartInfo(STPStartInfo stpStartInfo) 36 | : base(stpStartInfo) 37 | { 38 | _idleTimeout = stpStartInfo.IdleTimeout; 39 | _minWorkerThreads = stpStartInfo.MinWorkerThreads; 40 | _maxWorkerThreads = stpStartInfo.MaxWorkerThreads; 41 | #if !(WINDOWS_PHONE) 42 | _threadPriority = stpStartInfo.ThreadPriority; 43 | #endif 44 | _performanceCounterInstanceName = stpStartInfo.PerformanceCounterInstanceName; 45 | _enableLocalPerformanceCounters = stpStartInfo._enableLocalPerformanceCounters; 46 | _threadPoolName = stpStartInfo._threadPoolName; 47 | _areThreadsBackground = stpStartInfo.AreThreadsBackground; 48 | _maxQueueLength = stpStartInfo.MaxQueueLength; 49 | #if !(_SILVERLIGHT) && !(WINDOWS_PHONE) 50 | _apartmentState = stpStartInfo._apartmentState; 51 | #endif 52 | _maxStackSize = stpStartInfo._maxStackSize; 53 | } 54 | 55 | /// 56 | /// Get/Set the idle timeout in milliseconds. 57 | /// If a thread is idle (starved) longer than IdleTimeout then it may quit. 58 | /// 59 | public virtual int IdleTimeout 60 | { 61 | get { return _idleTimeout; } 62 | set 63 | { 64 | ThrowIfReadOnly(); 65 | _idleTimeout = value; 66 | } 67 | } 68 | 69 | 70 | /// 71 | /// Get/Set the lower limit of threads in the pool. 72 | /// 73 | public virtual int MinWorkerThreads 74 | { 75 | get { return _minWorkerThreads; } 76 | set 77 | { 78 | ThrowIfReadOnly(); 79 | _minWorkerThreads = value; 80 | } 81 | } 82 | 83 | 84 | /// 85 | /// Get/Set the upper limit of threads in the pool. 86 | /// 87 | public virtual int MaxWorkerThreads 88 | { 89 | get { return _maxWorkerThreads; } 90 | set 91 | { 92 | ThrowIfReadOnly(); 93 | _maxWorkerThreads = value; 94 | } 95 | } 96 | 97 | #if !(WINDOWS_PHONE) 98 | /// 99 | /// Get/Set the scheduling priority of the threads in the pool. 100 | /// The Os handles the scheduling. 101 | /// 102 | public virtual ThreadPriority ThreadPriority 103 | { 104 | get { return _threadPriority; } 105 | set 106 | { 107 | ThrowIfReadOnly(); 108 | _threadPriority = value; 109 | } 110 | } 111 | #endif 112 | /// 113 | /// Get/Set the thread pool name. Threads will get names depending on this. 114 | /// 115 | public virtual string ThreadPoolName { 116 | get { return _threadPoolName; } 117 | set 118 | { 119 | ThrowIfReadOnly (); 120 | _threadPoolName = value; 121 | } 122 | } 123 | 124 | /// 125 | /// Get/Set the performance counter instance name of this SmartThreadPool 126 | /// The default is null which indicate not to use performance counters at all. 127 | /// 128 | public virtual string PerformanceCounterInstanceName 129 | { 130 | get { return _performanceCounterInstanceName; } 131 | set 132 | { 133 | ThrowIfReadOnly(); 134 | _performanceCounterInstanceName = value; 135 | } 136 | } 137 | 138 | /// 139 | /// Enable/Disable the local performance counter. 140 | /// This enables the user to get some performance information about the SmartThreadPool 141 | /// without using Windows performance counters. (Useful on WindowsCE, Silverlight, etc.) 142 | /// The default is false. 143 | /// 144 | public virtual bool EnableLocalPerformanceCounters 145 | { 146 | get { return _enableLocalPerformanceCounters; } 147 | set 148 | { 149 | ThrowIfReadOnly(); 150 | _enableLocalPerformanceCounters = value; 151 | } 152 | } 153 | 154 | /// 155 | /// Get/Set backgroundness of thread in thread pool. 156 | /// 157 | public virtual bool AreThreadsBackground 158 | { 159 | get { return _areThreadsBackground; } 160 | set 161 | { 162 | ThrowIfReadOnly (); 163 | _areThreadsBackground = value; 164 | } 165 | } 166 | 167 | /// 168 | /// The maximum number of items allowed in the queue. Items attempting to be queued 169 | /// when the queue is at its maximum will throw a QueueRejectedException. 170 | /// 171 | /// Value must be > 0. A null value will leave the queue unbounded (i.e. 172 | /// bounded only by available resources). 173 | /// 174 | /// Ignored when Enqueue()ing on a Thread Pool from within a 175 | /// WorkItemsGroup. 176 | /// 177 | public virtual int? MaxQueueLength 178 | { 179 | get { return _maxQueueLength; } 180 | set 181 | { 182 | ThrowIfReadOnly(); 183 | _maxQueueLength = value; 184 | } 185 | } 186 | 187 | /// 188 | /// Get a readonly version of this STPStartInfo. 189 | /// 190 | /// Returns a readonly reference to this STPStartInfo 191 | public new STPStartInfo AsReadOnly() 192 | { 193 | return new STPStartInfo(this) { _readOnly = true }; 194 | } 195 | 196 | #if !(_SILVERLIGHT) && !(WINDOWS_PHONE) 197 | 198 | private ApartmentState _apartmentState = SmartThreadPool.DefaultApartmentState; 199 | 200 | /// 201 | /// Get/Set the apartment state of threads in the thread pool 202 | /// 203 | public ApartmentState ApartmentState 204 | { 205 | get { return _apartmentState; } 206 | set 207 | { 208 | ThrowIfReadOnly(); 209 | _apartmentState = value; 210 | } 211 | } 212 | 213 | #if !(_SILVERLIGHT) && !(WINDOWS_PHONE) 214 | 215 | /// 216 | /// Get/Set the max stack size of threads in the thread pool 217 | /// 218 | public int? MaxStackSize 219 | { 220 | get { return _maxStackSize; } 221 | set 222 | { 223 | ThrowIfReadOnly(); 224 | if (value.HasValue && value.Value < 0) 225 | { 226 | throw new ArgumentOutOfRangeException("value", "Value must be greater than 0."); 227 | } 228 | _maxStackSize = value; 229 | } 230 | } 231 | #endif 232 | 233 | #endif 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/SmartThreadPool.ThreadEntry.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | using Amib.Threading.Internal; 4 | 5 | namespace Amib.Threading 6 | { 7 | public partial class SmartThreadPool 8 | { 9 | #region ThreadEntry class 10 | 11 | internal class ThreadEntry 12 | { 13 | /// 14 | /// The thread creation time 15 | /// The value is stored as UTC value. 16 | /// 17 | private readonly DateTime _creationTime; 18 | 19 | /// 20 | /// The last time this thread has been running 21 | /// It is updated by IAmAlive() method 22 | /// The value is stored as UTC value. 23 | /// 24 | private DateTime _lastAliveTime; 25 | 26 | /// 27 | /// A reference from each thread in the thread pool to its SmartThreadPool 28 | /// object container. 29 | /// With this variable a thread can know whatever it belongs to a 30 | /// SmartThreadPool. 31 | /// 32 | private readonly SmartThreadPool _associatedSmartThreadPool; 33 | 34 | /// 35 | /// A reference to the current work item a thread from the thread pool 36 | /// is executing. 37 | /// 38 | public WorkItem CurrentWorkItem { get; set; } 39 | 40 | public ThreadEntry(SmartThreadPool stp) 41 | { 42 | _associatedSmartThreadPool = stp; 43 | _creationTime = DateTime.UtcNow; 44 | _lastAliveTime = DateTime.MinValue; 45 | } 46 | 47 | public SmartThreadPool AssociatedSmartThreadPool 48 | { 49 | get { return _associatedSmartThreadPool; } 50 | } 51 | 52 | public void IAmAlive() 53 | { 54 | _lastAliveTime = DateTime.UtcNow; 55 | } 56 | } 57 | 58 | #endregion 59 | } 60 | } -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/Stopwatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Amib.Threading.Internal 4 | { 5 | /// 6 | /// Stopwatch class 7 | /// Used with WindowsCE and Silverlight which don't have Stopwatch 8 | /// 9 | internal class Stopwatch 10 | { 11 | private long _elapsed; 12 | private bool _isRunning; 13 | private long _startTimeStamp; 14 | 15 | public Stopwatch() 16 | { 17 | Reset(); 18 | } 19 | 20 | private long GetElapsedDateTimeTicks() 21 | { 22 | long rawElapsedTicks = GetRawElapsedTicks(); 23 | return rawElapsedTicks; 24 | } 25 | 26 | private long GetRawElapsedTicks() 27 | { 28 | long elapsed = _elapsed; 29 | if (_isRunning) 30 | { 31 | long ticks = GetTimestamp() - _startTimeStamp; 32 | elapsed += ticks; 33 | } 34 | return elapsed; 35 | } 36 | 37 | public static long GetTimestamp() 38 | { 39 | return DateTime.UtcNow.Ticks; 40 | } 41 | 42 | public void Reset() 43 | { 44 | _elapsed = 0L; 45 | _isRunning = false; 46 | _startTimeStamp = 0L; 47 | } 48 | 49 | public void Start() 50 | { 51 | if (!_isRunning) 52 | { 53 | _startTimeStamp = GetTimestamp(); 54 | _isRunning = true; 55 | } 56 | } 57 | 58 | public static Stopwatch StartNew() 59 | { 60 | Stopwatch stopwatch = new Stopwatch(); 61 | stopwatch.Start(); 62 | return stopwatch; 63 | } 64 | 65 | public void Stop() 66 | { 67 | if (_isRunning) 68 | { 69 | long ticks = GetTimestamp() - _startTimeStamp; 70 | _elapsed += ticks; 71 | _isRunning = false; 72 | } 73 | } 74 | 75 | // Properties 76 | public TimeSpan Elapsed 77 | { 78 | get 79 | { 80 | return new TimeSpan(GetElapsedDateTimeTicks()); 81 | } 82 | } 83 | 84 | public long ElapsedMilliseconds 85 | { 86 | get 87 | { 88 | return (GetElapsedDateTimeTicks() / 0x2710L); 89 | } 90 | } 91 | 92 | public long ElapsedTicks 93 | { 94 | get 95 | { 96 | return GetRawElapsedTicks(); 97 | } 98 | } 99 | 100 | public bool IsRunning 101 | { 102 | get 103 | { 104 | return _isRunning; 105 | } 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/SynchronizedDictionary.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Amib.Threading.Internal 4 | { 5 | internal class SynchronizedDictionary 6 | { 7 | private readonly Dictionary _dictionary; 8 | private readonly object _lock; 9 | 10 | public SynchronizedDictionary() 11 | { 12 | _lock = new object(); 13 | _dictionary = new Dictionary(); 14 | } 15 | 16 | public int Count 17 | { 18 | get { return _dictionary.Count; } 19 | } 20 | 21 | public bool Contains(TKey key) 22 | { 23 | lock (_lock) 24 | { 25 | return _dictionary.ContainsKey(key); 26 | } 27 | } 28 | 29 | public void Remove(TKey key) 30 | { 31 | lock (_lock) 32 | { 33 | _dictionary.Remove(key); 34 | } 35 | } 36 | 37 | public object SyncRoot 38 | { 39 | get { return _lock; } 40 | } 41 | 42 | public TValue this[TKey key] 43 | { 44 | get 45 | { 46 | lock (_lock) 47 | { 48 | return _dictionary[key]; 49 | } 50 | } 51 | set 52 | { 53 | lock (_lock) 54 | { 55 | _dictionary[key] = value; 56 | } 57 | } 58 | } 59 | 60 | public Dictionary.KeyCollection Keys 61 | { 62 | get 63 | { 64 | lock (_lock) 65 | { 66 | return _dictionary.Keys; 67 | } 68 | } 69 | } 70 | 71 | public Dictionary.ValueCollection Values 72 | { 73 | get 74 | { 75 | lock (_lock) 76 | { 77 | return _dictionary.Values; 78 | } 79 | } 80 | } 81 | public void Clear() 82 | { 83 | lock (_lock) 84 | { 85 | _dictionary.Clear(); 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/WIGStartInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Amib.Threading 4 | { 5 | /// 6 | /// Summary description for WIGStartInfo. 7 | /// 8 | public class WIGStartInfo 9 | { 10 | private bool _useCallerCallContext; 11 | private bool _useCallerHttpContext; 12 | private bool _disposeOfStateObjects; 13 | private CallToPostExecute _callToPostExecute; 14 | private PostExecuteWorkItemCallback _postExecuteWorkItemCallback; 15 | private bool _startSuspended; 16 | private WorkItemPriority _workItemPriority; 17 | private bool _fillStateWithArgs; 18 | 19 | protected bool _readOnly; 20 | 21 | public WIGStartInfo() 22 | { 23 | _fillStateWithArgs = SmartThreadPool.DefaultFillStateWithArgs; 24 | _workItemPriority = SmartThreadPool.DefaultWorkItemPriority; 25 | _startSuspended = SmartThreadPool.DefaultStartSuspended; 26 | _postExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback; 27 | _callToPostExecute = SmartThreadPool.DefaultCallToPostExecute; 28 | _disposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects; 29 | _useCallerHttpContext = SmartThreadPool.DefaultUseCallerHttpContext; 30 | _useCallerCallContext = SmartThreadPool.DefaultUseCallerCallContext; 31 | } 32 | 33 | public WIGStartInfo(WIGStartInfo wigStartInfo) 34 | { 35 | _useCallerCallContext = wigStartInfo.UseCallerCallContext; 36 | _useCallerHttpContext = wigStartInfo.UseCallerHttpContext; 37 | _disposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; 38 | _callToPostExecute = wigStartInfo.CallToPostExecute; 39 | _postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback; 40 | _workItemPriority = wigStartInfo.WorkItemPriority; 41 | _startSuspended = wigStartInfo.StartSuspended; 42 | _fillStateWithArgs = wigStartInfo.FillStateWithArgs; 43 | } 44 | 45 | protected void ThrowIfReadOnly() 46 | { 47 | if (_readOnly) 48 | { 49 | throw new NotSupportedException("This is a readonly instance and set is not supported"); 50 | } 51 | } 52 | 53 | /// 54 | /// Get/Set if to use the caller's security context 55 | /// 56 | public virtual bool UseCallerCallContext 57 | { 58 | get { return _useCallerCallContext; } 59 | set 60 | { 61 | ThrowIfReadOnly(); 62 | _useCallerCallContext = value; 63 | } 64 | } 65 | 66 | 67 | /// 68 | /// Get/Set if to use the caller's HTTP context 69 | /// 70 | public virtual bool UseCallerHttpContext 71 | { 72 | get { return _useCallerHttpContext; } 73 | set 74 | { 75 | ThrowIfReadOnly(); 76 | _useCallerHttpContext = value; 77 | } 78 | } 79 | 80 | 81 | /// 82 | /// Get/Set if to dispose of the state object of a work item 83 | /// 84 | public virtual bool DisposeOfStateObjects 85 | { 86 | get { return _disposeOfStateObjects; } 87 | set 88 | { 89 | ThrowIfReadOnly(); 90 | _disposeOfStateObjects = value; 91 | } 92 | } 93 | 94 | 95 | /// 96 | /// Get/Set the run the post execute options 97 | /// 98 | public virtual CallToPostExecute CallToPostExecute 99 | { 100 | get { return _callToPostExecute; } 101 | set 102 | { 103 | ThrowIfReadOnly(); 104 | _callToPostExecute = value; 105 | } 106 | } 107 | 108 | 109 | /// 110 | /// Get/Set the default post execute callback 111 | /// 112 | public virtual PostExecuteWorkItemCallback PostExecuteWorkItemCallback 113 | { 114 | get { return _postExecuteWorkItemCallback; } 115 | set 116 | { 117 | ThrowIfReadOnly(); 118 | _postExecuteWorkItemCallback = value; 119 | } 120 | } 121 | 122 | 123 | /// 124 | /// Get/Set if the work items execution should be suspended until the Start() 125 | /// method is called. 126 | /// 127 | public virtual bool StartSuspended 128 | { 129 | get { return _startSuspended; } 130 | set 131 | { 132 | ThrowIfReadOnly(); 133 | _startSuspended = value; 134 | } 135 | } 136 | 137 | 138 | /// 139 | /// Get/Set the default priority that a work item gets when it is enqueued 140 | /// 141 | public virtual WorkItemPriority WorkItemPriority 142 | { 143 | get { return _workItemPriority; } 144 | set { _workItemPriority = value; } 145 | } 146 | 147 | /// 148 | /// Get/Set the if QueueWorkItem of Action<...>/Func<...> fill the 149 | /// arguments as an object array into the state of the work item. 150 | /// The arguments can be access later by IWorkItemResult.State. 151 | /// 152 | public virtual bool FillStateWithArgs 153 | { 154 | get { return _fillStateWithArgs; } 155 | set 156 | { 157 | ThrowIfReadOnly(); 158 | _fillStateWithArgs = value; 159 | } 160 | } 161 | 162 | /// 163 | /// Get a readonly version of this WIGStartInfo 164 | /// 165 | /// Returns a readonly reference to this WIGStartInfoRO 166 | public WIGStartInfo AsReadOnly() 167 | { 168 | return new WIGStartInfo(this) { _readOnly = true }; 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/WorkItem.WorkItemResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading; 5 | 6 | namespace Amib.Threading.Internal 7 | { 8 | public partial class WorkItem 9 | { 10 | #region WorkItemResult class 11 | 12 | private class WorkItemResult : IWorkItemResult, IInternalWorkItemResult, IInternalWaitableResult 13 | { 14 | /// 15 | /// A back reference to the work item 16 | /// 17 | private readonly WorkItem _workItem; 18 | 19 | public WorkItemResult(WorkItem workItem) 20 | { 21 | _workItem = workItem; 22 | } 23 | 24 | internal WorkItem GetWorkItem() 25 | { 26 | return _workItem; 27 | } 28 | 29 | #region IWorkItemResult Members 30 | 31 | public bool IsCompleted 32 | { 33 | get 34 | { 35 | return _workItem.IsCompleted; 36 | } 37 | } 38 | 39 | public bool IsCanceled 40 | { 41 | get 42 | { 43 | return _workItem.IsCanceled; 44 | } 45 | } 46 | 47 | public object GetResult() 48 | { 49 | return _workItem.GetResult(Timeout.Infinite, true, null); 50 | } 51 | 52 | public object GetResult(int millisecondsTimeout, bool exitContext) 53 | { 54 | return _workItem.GetResult(millisecondsTimeout, exitContext, null); 55 | } 56 | 57 | public object GetResult(TimeSpan timeout, bool exitContext) 58 | { 59 | return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, null); 60 | } 61 | 62 | public object GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle) 63 | { 64 | return _workItem.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle); 65 | } 66 | 67 | public object GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle) 68 | { 69 | return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, cancelWaitHandle); 70 | } 71 | 72 | public object GetResult(out Exception e) 73 | { 74 | return _workItem.GetResult(Timeout.Infinite, true, null, out e); 75 | } 76 | 77 | public object GetResult(int millisecondsTimeout, bool exitContext, out Exception e) 78 | { 79 | return _workItem.GetResult(millisecondsTimeout, exitContext, null, out e); 80 | } 81 | 82 | public object GetResult(TimeSpan timeout, bool exitContext, out Exception e) 83 | { 84 | return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, null, out e); 85 | } 86 | 87 | public object GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e) 88 | { 89 | return _workItem.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle, out e); 90 | } 91 | 92 | public object GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e) 93 | { 94 | return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, cancelWaitHandle, out e); 95 | } 96 | 97 | public bool Cancel() 98 | { 99 | return Cancel(false); 100 | } 101 | 102 | public bool Cancel(bool abortExecution) 103 | { 104 | return _workItem.Cancel(abortExecution); 105 | } 106 | 107 | public object State 108 | { 109 | get 110 | { 111 | return _workItem._state; 112 | } 113 | } 114 | 115 | public WorkItemPriority WorkItemPriority 116 | { 117 | get 118 | { 119 | return _workItem._workItemInfo.WorkItemPriority; 120 | } 121 | } 122 | 123 | /// 124 | /// Return the result, same as GetResult() 125 | /// 126 | public object Result 127 | { 128 | get { return GetResult(); } 129 | } 130 | 131 | /// 132 | /// Returns the exception if occured otherwise returns null. 133 | /// This value is valid only after the work item completed, 134 | /// before that it is always null. 135 | /// 136 | public object Exception 137 | { 138 | get { return _workItem._exception; } 139 | } 140 | 141 | #endregion 142 | 143 | #region IInternalWorkItemResult Members 144 | 145 | public event WorkItemStateCallback OnWorkItemStarted 146 | { 147 | add 148 | { 149 | _workItem.OnWorkItemStarted += value; 150 | } 151 | remove 152 | { 153 | _workItem.OnWorkItemStarted -= value; 154 | } 155 | } 156 | 157 | 158 | public event WorkItemStateCallback OnWorkItemCompleted 159 | { 160 | add 161 | { 162 | _workItem.OnWorkItemCompleted += value; 163 | } 164 | remove 165 | { 166 | _workItem.OnWorkItemCompleted -= value; 167 | } 168 | } 169 | 170 | #endregion 171 | 172 | #region IInternalWorkItemResult Members 173 | 174 | public IWorkItemResult GetWorkItemResult() 175 | { 176 | return this; 177 | } 178 | 179 | public IWorkItemResult GetWorkItemResultT() 180 | { 181 | return new WorkItemResultTWrapper(this); 182 | } 183 | 184 | #endregion 185 | } 186 | 187 | #endregion 188 | 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/WorkItemFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Amib.Threading.Internal 4 | { 5 | #region WorkItemFactory class 6 | 7 | public class WorkItemFactory 8 | { 9 | /// 10 | /// Create a new work item 11 | /// 12 | /// The WorkItemsGroup of this workitem 13 | /// Work item group start information 14 | /// A callback to execute 15 | /// Returns a work item 16 | public static WorkItem CreateWorkItem( 17 | IWorkItemsGroup workItemsGroup, 18 | WIGStartInfo wigStartInfo, 19 | WorkItemCallback callback) 20 | { 21 | return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null); 22 | } 23 | 24 | /// 25 | /// Create a new work item 26 | /// 27 | /// The WorkItemsGroup of this workitem 28 | /// Work item group start information 29 | /// A callback to execute 30 | /// The priority of the work item 31 | /// Returns a work item 32 | public static WorkItem CreateWorkItem( 33 | IWorkItemsGroup workItemsGroup, 34 | WIGStartInfo wigStartInfo, 35 | WorkItemCallback callback, 36 | WorkItemPriority workItemPriority) 37 | { 38 | return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null, workItemPriority); 39 | } 40 | 41 | /// 42 | /// Create a new work item 43 | /// 44 | /// The WorkItemsGroup of this workitem 45 | /// Work item group start information 46 | /// Work item info 47 | /// A callback to execute 48 | /// Returns a work item 49 | public static WorkItem CreateWorkItem( 50 | IWorkItemsGroup workItemsGroup, 51 | WIGStartInfo wigStartInfo, 52 | WorkItemInfo workItemInfo, 53 | WorkItemCallback callback) 54 | { 55 | return CreateWorkItem( 56 | workItemsGroup, 57 | wigStartInfo, 58 | workItemInfo, 59 | callback, 60 | null); 61 | } 62 | 63 | /// 64 | /// Create a new work item 65 | /// 66 | /// The WorkItemsGroup of this workitem 67 | /// Work item group start information 68 | /// A callback to execute 69 | /// 70 | /// The context object of the work item. Used for passing arguments to the work item. 71 | /// 72 | /// Returns a work item 73 | public static WorkItem CreateWorkItem( 74 | IWorkItemsGroup workItemsGroup, 75 | WIGStartInfo wigStartInfo, 76 | WorkItemCallback callback, 77 | object state) 78 | { 79 | ValidateCallback(callback); 80 | 81 | WorkItemInfo workItemInfo = new WorkItemInfo(); 82 | workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; 83 | workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; 84 | workItemInfo.PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback; 85 | workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute; 86 | workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; 87 | workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority; 88 | 89 | WorkItem workItem = new WorkItem( 90 | workItemsGroup, 91 | workItemInfo, 92 | callback, 93 | state); 94 | return workItem; 95 | } 96 | 97 | /// 98 | /// Create a new work item 99 | /// 100 | /// The work items group 101 | /// Work item group start information 102 | /// A callback to execute 103 | /// 104 | /// The context object of the work item. Used for passing arguments to the work item. 105 | /// 106 | /// The work item priority 107 | /// Returns a work item 108 | public static WorkItem CreateWorkItem( 109 | IWorkItemsGroup workItemsGroup, 110 | WIGStartInfo wigStartInfo, 111 | WorkItemCallback callback, 112 | object state, 113 | WorkItemPriority workItemPriority) 114 | { 115 | ValidateCallback(callback); 116 | 117 | WorkItemInfo workItemInfo = new WorkItemInfo(); 118 | workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; 119 | workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; 120 | workItemInfo.PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback; 121 | workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute; 122 | workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; 123 | workItemInfo.WorkItemPriority = workItemPriority; 124 | 125 | WorkItem workItem = new WorkItem( 126 | workItemsGroup, 127 | workItemInfo, 128 | callback, 129 | state); 130 | 131 | return workItem; 132 | } 133 | 134 | /// 135 | /// Create a new work item 136 | /// 137 | /// The work items group 138 | /// Work item group start information 139 | /// Work item information 140 | /// A callback to execute 141 | /// 142 | /// The context object of the work item. Used for passing arguments to the work item. 143 | /// 144 | /// Returns a work item 145 | public static WorkItem CreateWorkItem( 146 | IWorkItemsGroup workItemsGroup, 147 | WIGStartInfo wigStartInfo, 148 | WorkItemInfo workItemInfo, 149 | WorkItemCallback callback, 150 | object state) 151 | { 152 | ValidateCallback(callback); 153 | ValidateCallback(workItemInfo.PostExecuteWorkItemCallback); 154 | 155 | WorkItem workItem = new WorkItem( 156 | workItemsGroup, 157 | new WorkItemInfo(workItemInfo), 158 | callback, 159 | state); 160 | 161 | return workItem; 162 | } 163 | 164 | /// 165 | /// Create a new work item 166 | /// 167 | /// The work items group 168 | /// Work item group start information 169 | /// A callback to execute 170 | /// 171 | /// The context object of the work item. Used for passing arguments to the work item. 172 | /// 173 | /// 174 | /// A delegate to call after the callback completion 175 | /// 176 | /// Returns a work item 177 | public static WorkItem CreateWorkItem( 178 | IWorkItemsGroup workItemsGroup, 179 | WIGStartInfo wigStartInfo, 180 | WorkItemCallback callback, 181 | object state, 182 | PostExecuteWorkItemCallback postExecuteWorkItemCallback) 183 | { 184 | ValidateCallback(callback); 185 | ValidateCallback(postExecuteWorkItemCallback); 186 | 187 | WorkItemInfo workItemInfo = new WorkItemInfo(); 188 | workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; 189 | workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; 190 | workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback; 191 | workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute; 192 | workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; 193 | workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority; 194 | 195 | WorkItem workItem = new WorkItem( 196 | workItemsGroup, 197 | workItemInfo, 198 | callback, 199 | state); 200 | 201 | return workItem; 202 | } 203 | 204 | /// 205 | /// Create a new work item 206 | /// 207 | /// The work items group 208 | /// Work item group start information 209 | /// A callback to execute 210 | /// 211 | /// The context object of the work item. Used for passing arguments to the work item. 212 | /// 213 | /// 214 | /// A delegate to call after the callback completion 215 | /// 216 | /// The work item priority 217 | /// Returns a work item 218 | public static WorkItem CreateWorkItem( 219 | IWorkItemsGroup workItemsGroup, 220 | WIGStartInfo wigStartInfo, 221 | WorkItemCallback callback, 222 | object state, 223 | PostExecuteWorkItemCallback postExecuteWorkItemCallback, 224 | WorkItemPriority workItemPriority) 225 | { 226 | ValidateCallback(callback); 227 | ValidateCallback(postExecuteWorkItemCallback); 228 | 229 | WorkItemInfo workItemInfo = new WorkItemInfo(); 230 | workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; 231 | workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; 232 | workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback; 233 | workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute; 234 | workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; 235 | workItemInfo.WorkItemPriority = workItemPriority; 236 | 237 | WorkItem workItem = new WorkItem( 238 | workItemsGroup, 239 | workItemInfo, 240 | callback, 241 | state); 242 | 243 | return workItem; 244 | } 245 | 246 | /// 247 | /// Create a new work item 248 | /// 249 | /// The work items group 250 | /// Work item group start information 251 | /// A callback to execute 252 | /// 253 | /// The context object of the work item. Used for passing arguments to the work item. 254 | /// 255 | /// 256 | /// A delegate to call after the callback completion 257 | /// 258 | /// Indicates on which cases to call to the post execute callback 259 | /// Returns a work item 260 | public static WorkItem CreateWorkItem( 261 | IWorkItemsGroup workItemsGroup, 262 | WIGStartInfo wigStartInfo, 263 | WorkItemCallback callback, 264 | object state, 265 | PostExecuteWorkItemCallback postExecuteWorkItemCallback, 266 | CallToPostExecute callToPostExecute) 267 | { 268 | ValidateCallback(callback); 269 | ValidateCallback(postExecuteWorkItemCallback); 270 | 271 | WorkItemInfo workItemInfo = new WorkItemInfo(); 272 | workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; 273 | workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; 274 | workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback; 275 | workItemInfo.CallToPostExecute = callToPostExecute; 276 | workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; 277 | workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority; 278 | 279 | WorkItem workItem = new WorkItem( 280 | workItemsGroup, 281 | workItemInfo, 282 | callback, 283 | state); 284 | 285 | return workItem; 286 | } 287 | 288 | /// 289 | /// Create a new work item 290 | /// 291 | /// The work items group 292 | /// Work item group start information 293 | /// A callback to execute 294 | /// 295 | /// The context object of the work item. Used for passing arguments to the work item. 296 | /// 297 | /// 298 | /// A delegate to call after the callback completion 299 | /// 300 | /// Indicates on which cases to call to the post execute callback 301 | /// The work item priority 302 | /// Returns a work item 303 | public static WorkItem CreateWorkItem( 304 | IWorkItemsGroup workItemsGroup, 305 | WIGStartInfo wigStartInfo, 306 | WorkItemCallback callback, 307 | object state, 308 | PostExecuteWorkItemCallback postExecuteWorkItemCallback, 309 | CallToPostExecute callToPostExecute, 310 | WorkItemPriority workItemPriority) 311 | { 312 | 313 | ValidateCallback(callback); 314 | ValidateCallback(postExecuteWorkItemCallback); 315 | 316 | WorkItemInfo workItemInfo = new WorkItemInfo(); 317 | workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; 318 | workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; 319 | workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback; 320 | workItemInfo.CallToPostExecute = callToPostExecute; 321 | workItemInfo.WorkItemPriority = workItemPriority; 322 | workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; 323 | 324 | WorkItem workItem = new WorkItem( 325 | workItemsGroup, 326 | workItemInfo, 327 | callback, 328 | state); 329 | 330 | return workItem; 331 | } 332 | 333 | private static void ValidateCallback(Delegate callback) 334 | { 335 | if (callback != null && callback.GetInvocationList().Length > 1) 336 | { 337 | throw new NotSupportedException("SmartThreadPool doesn't support delegates chains"); 338 | } 339 | } 340 | } 341 | 342 | #endregion 343 | } 344 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/WorkItemInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Amib.Threading 2 | { 3 | #region WorkItemInfo class 4 | 5 | /// 6 | /// Summary description for WorkItemInfo. 7 | /// 8 | public class WorkItemInfo 9 | { 10 | public WorkItemInfo() 11 | { 12 | UseCallerCallContext = SmartThreadPool.DefaultUseCallerCallContext; 13 | UseCallerHttpContext = SmartThreadPool.DefaultUseCallerHttpContext; 14 | DisposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects; 15 | CallToPostExecute = SmartThreadPool.DefaultCallToPostExecute; 16 | PostExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback; 17 | WorkItemPriority = SmartThreadPool.DefaultWorkItemPriority; 18 | } 19 | 20 | public WorkItemInfo(WorkItemInfo workItemInfo) 21 | { 22 | UseCallerCallContext = workItemInfo.UseCallerCallContext; 23 | UseCallerHttpContext = workItemInfo.UseCallerHttpContext; 24 | DisposeOfStateObjects = workItemInfo.DisposeOfStateObjects; 25 | CallToPostExecute = workItemInfo.CallToPostExecute; 26 | PostExecuteWorkItemCallback = workItemInfo.PostExecuteWorkItemCallback; 27 | WorkItemPriority = workItemInfo.WorkItemPriority; 28 | Timeout = workItemInfo.Timeout; 29 | } 30 | 31 | /// 32 | /// Get/Set if to use the caller's security context 33 | /// 34 | public bool UseCallerCallContext { get; set; } 35 | 36 | /// 37 | /// Get/Set if to use the caller's HTTP context 38 | /// 39 | public bool UseCallerHttpContext { get; set; } 40 | 41 | /// 42 | /// Get/Set if to dispose of the state object of a work item 43 | /// 44 | public bool DisposeOfStateObjects { get; set; } 45 | 46 | /// 47 | /// Get/Set the run the post execute options 48 | /// 49 | public CallToPostExecute CallToPostExecute { get; set; } 50 | 51 | /// 52 | /// Get/Set the post execute callback 53 | /// 54 | public PostExecuteWorkItemCallback PostExecuteWorkItemCallback { get; set; } 55 | 56 | /// 57 | /// Get/Set the work item's priority 58 | /// 59 | public WorkItemPriority WorkItemPriority { get; set; } 60 | 61 | /// 62 | /// Get/Set the work item's timout in milliseconds. 63 | /// This is a passive timout. When the timout expires the work item won't be actively aborted! 64 | /// 65 | public long Timeout { get; set; } 66 | } 67 | 68 | #endregion 69 | } 70 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/WorkItemResultTWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | 4 | namespace Amib.Threading.Internal 5 | { 6 | #region WorkItemResultTWrapper class 7 | 8 | internal class WorkItemResultTWrapper : IWorkItemResult, IInternalWaitableResult 9 | { 10 | private readonly IWorkItemResult _workItemResult; 11 | 12 | public WorkItemResultTWrapper(IWorkItemResult workItemResult) 13 | { 14 | _workItemResult = workItemResult; 15 | } 16 | 17 | #region IWorkItemResult Members 18 | 19 | public TResult GetResult() 20 | { 21 | return (TResult)_workItemResult.GetResult(); 22 | } 23 | 24 | public TResult GetResult(int millisecondsTimeout, bool exitContext) 25 | { 26 | return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext); 27 | } 28 | 29 | public TResult GetResult(TimeSpan timeout, bool exitContext) 30 | { 31 | return (TResult)_workItemResult.GetResult(timeout, exitContext); 32 | } 33 | 34 | public TResult GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle) 35 | { 36 | return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle); 37 | } 38 | 39 | public TResult GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle) 40 | { 41 | return (TResult)_workItemResult.GetResult(timeout, exitContext, cancelWaitHandle); 42 | } 43 | 44 | public TResult GetResult(out Exception e) 45 | { 46 | return (TResult)_workItemResult.GetResult(out e); 47 | } 48 | 49 | public TResult GetResult(int millisecondsTimeout, bool exitContext, out Exception e) 50 | { 51 | return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext, out e); 52 | } 53 | 54 | public TResult GetResult(TimeSpan timeout, bool exitContext, out Exception e) 55 | { 56 | return (TResult)_workItemResult.GetResult(timeout, exitContext, out e); 57 | } 58 | 59 | public TResult GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e) 60 | { 61 | return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle, out e); 62 | } 63 | 64 | public TResult GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e) 65 | { 66 | return (TResult)_workItemResult.GetResult(timeout, exitContext, cancelWaitHandle, out e); 67 | } 68 | 69 | public bool IsCompleted 70 | { 71 | get { return _workItemResult.IsCompleted; } 72 | } 73 | 74 | public bool IsCanceled 75 | { 76 | get { return _workItemResult.IsCanceled; } 77 | } 78 | 79 | public object State 80 | { 81 | get { return _workItemResult.State; } 82 | } 83 | 84 | public bool Cancel() 85 | { 86 | return _workItemResult.Cancel(); 87 | } 88 | 89 | public bool Cancel(bool abortExecution) 90 | { 91 | return _workItemResult.Cancel(abortExecution); 92 | } 93 | 94 | public WorkItemPriority WorkItemPriority 95 | { 96 | get { return _workItemResult.WorkItemPriority; } 97 | } 98 | 99 | public TResult Result 100 | { 101 | get { return (TResult)_workItemResult.Result; } 102 | } 103 | 104 | public object Exception 105 | { 106 | get { return _workItemResult.Exception; } 107 | } 108 | 109 | #region IInternalWorkItemResult Members 110 | 111 | public IWorkItemResult GetWorkItemResult() 112 | { 113 | return _workItemResult.GetWorkItemResult(); 114 | } 115 | 116 | public IWorkItemResult GetWorkItemResultT() 117 | { 118 | return (IWorkItemResult)this; 119 | } 120 | 121 | #endregion 122 | 123 | #endregion 124 | } 125 | 126 | #endregion 127 | 128 | } 129 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/WorkItemsGroup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Runtime.CompilerServices; 4 | using System.Diagnostics; 5 | 6 | namespace Amib.Threading.Internal 7 | { 8 | 9 | #region WorkItemsGroup class 10 | 11 | /// 12 | /// Summary description for WorkItemsGroup. 13 | /// 14 | public class WorkItemsGroup : WorkItemsGroupBase 15 | { 16 | #region Private members 17 | 18 | private readonly object _lock = new object(); 19 | 20 | /// 21 | /// A reference to the SmartThreadPool instance that created this 22 | /// WorkItemsGroup. 23 | /// 24 | private readonly SmartThreadPool _stp; 25 | 26 | /// 27 | /// The OnIdle event 28 | /// 29 | private event WorkItemsGroupIdleHandler _onIdle; 30 | 31 | /// 32 | /// A flag to indicate if the Work Items Group is now suspended. 33 | /// 34 | private bool _isSuspended; 35 | 36 | /// 37 | /// Defines how many work items of this WorkItemsGroup can run at once. 38 | /// 39 | private int _concurrency; 40 | 41 | /// 42 | /// Priority queue to hold work items before they are passed 43 | /// to the SmartThreadPool. 44 | /// 45 | private readonly PriorityQueue _workItemsQueue; 46 | 47 | /// 48 | /// Indicate how many work items are waiting in the SmartThreadPool 49 | /// queue. 50 | /// This value is used to apply the concurrency. 51 | /// 52 | private int _workItemsInStpQueue; 53 | 54 | /// 55 | /// Indicate how many work items are currently running in the SmartThreadPool. 56 | /// This value is used with the Cancel, to calculate if we can send new 57 | /// work items to the STP. 58 | /// 59 | private int _workItemsExecutingInStp = 0; 60 | 61 | /// 62 | /// WorkItemsGroup start information 63 | /// 64 | private readonly WIGStartInfo _workItemsGroupStartInfo; 65 | 66 | /// 67 | /// Signaled when all of the WorkItemsGroup's work item completed. 68 | /// 69 | //private readonly ManualResetEvent _isIdleWaitHandle = new ManualResetEvent(true); 70 | private readonly ManualResetEvent _isIdleWaitHandle = EventWaitHandleFactory.CreateManualResetEvent(true); 71 | 72 | /// 73 | /// A common object for all the work items that this work items group 74 | /// generate so we can mark them to cancel in O(1) 75 | /// 76 | private CanceledWorkItemsGroup _canceledWorkItemsGroup = new CanceledWorkItemsGroup(); 77 | 78 | #endregion 79 | 80 | #region Construction 81 | 82 | public WorkItemsGroup( 83 | SmartThreadPool stp, 84 | int concurrency, 85 | WIGStartInfo wigStartInfo) 86 | { 87 | if (concurrency <= 0) 88 | { 89 | throw new ArgumentOutOfRangeException( 90 | "concurrency", 91 | #if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) 92 | concurrency, 93 | #endif 94 | "concurrency must be greater than zero"); 95 | } 96 | _stp = stp; 97 | _concurrency = concurrency; 98 | _workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo).AsReadOnly(); 99 | _workItemsQueue = new PriorityQueue(); 100 | Name = "WorkItemsGroup"; 101 | 102 | // The _workItemsInStpQueue gets the number of currently executing work items, 103 | // because once a work item is executing, it cannot be cancelled. 104 | _workItemsInStpQueue = _workItemsExecutingInStp; 105 | 106 | _isSuspended = _workItemsGroupStartInfo.StartSuspended; 107 | } 108 | 109 | #endregion 110 | 111 | #region WorkItemsGroupBase Overrides 112 | 113 | public override int Concurrency 114 | { 115 | get { return _concurrency; } 116 | set 117 | { 118 | Debug.Assert(value > 0); 119 | 120 | int diff = value - _concurrency; 121 | _concurrency = value; 122 | if (diff > 0) 123 | { 124 | EnqueueToSTPNextNWorkItem(diff); 125 | } 126 | } 127 | } 128 | 129 | public override int InUseThreads 130 | { 131 | get 132 | { 133 | return _workItemsExecutingInStp; 134 | } 135 | } 136 | 137 | public override int WaitingCallbacks 138 | { 139 | get { return _workItemsQueue.Count; } 140 | } 141 | 142 | public override object[] GetStates() 143 | { 144 | lock (_lock) 145 | { 146 | object[] states = new object[_workItemsQueue.Count]; 147 | int i = 0; 148 | foreach (WorkItem workItem in _workItemsQueue) 149 | { 150 | states[i] = workItem.GetWorkItemResult().State; 151 | ++i; 152 | } 153 | return states; 154 | } 155 | } 156 | 157 | /// 158 | /// WorkItemsGroup start information 159 | /// 160 | public override WIGStartInfo WIGStartInfo 161 | { 162 | get { return _workItemsGroupStartInfo; } 163 | } 164 | 165 | /// 166 | /// Start the Work Items Group if it was started suspended 167 | /// 168 | public override void Start() 169 | { 170 | // If the Work Items Group already started then quit 171 | if (!_isSuspended) 172 | { 173 | return; 174 | } 175 | _isSuspended = false; 176 | 177 | EnqueueToSTPNextNWorkItem(Math.Min(_workItemsQueue.Count, _concurrency)); 178 | } 179 | 180 | public override void Cancel(bool abortExecution) 181 | { 182 | lock (_lock) 183 | { 184 | _canceledWorkItemsGroup.IsCanceled = true; 185 | _workItemsQueue.Clear(); 186 | _workItemsInStpQueue = 0; 187 | _canceledWorkItemsGroup = new CanceledWorkItemsGroup(); 188 | } 189 | 190 | if (abortExecution) 191 | { 192 | _stp.CancelAbortWorkItemsGroup(this); 193 | } 194 | } 195 | 196 | /// 197 | /// Wait for the thread pool to be idle 198 | /// 199 | public override bool WaitForIdle(int millisecondsTimeout) 200 | { 201 | SmartThreadPool.ValidateWorkItemsGroupWaitForIdle(this); 202 | return STPEventWaitHandle.WaitOne(_isIdleWaitHandle, millisecondsTimeout, false); 203 | } 204 | 205 | public override event WorkItemsGroupIdleHandler OnIdle 206 | { 207 | add { _onIdle += value; } 208 | remove { _onIdle -= value; } 209 | } 210 | 211 | #endregion 212 | 213 | #region Private methods 214 | 215 | private void RegisterToWorkItemCompletion(IWorkItemResult wir) 216 | { 217 | IInternalWorkItemResult iwir = (IInternalWorkItemResult)wir; 218 | iwir.OnWorkItemStarted += OnWorkItemStartedCallback; 219 | iwir.OnWorkItemCompleted += OnWorkItemCompletedCallback; 220 | } 221 | 222 | public void OnSTPIsStarting() 223 | { 224 | if (_isSuspended) 225 | { 226 | return; 227 | } 228 | 229 | EnqueueToSTPNextNWorkItem(_concurrency); 230 | } 231 | 232 | public void EnqueueToSTPNextNWorkItem(int count) 233 | { 234 | for (int i = 0; i < count; ++i) 235 | { 236 | EnqueueToSTPNextWorkItem(null, false); 237 | } 238 | } 239 | 240 | private object FireOnIdle(object state) 241 | { 242 | FireOnIdleImpl(_onIdle); 243 | return null; 244 | } 245 | 246 | [MethodImpl(MethodImplOptions.NoInlining)] 247 | private void FireOnIdleImpl(WorkItemsGroupIdleHandler onIdle) 248 | { 249 | if(null == onIdle) 250 | { 251 | return; 252 | } 253 | 254 | Delegate[] delegates = onIdle.GetInvocationList(); 255 | foreach(WorkItemsGroupIdleHandler eh in delegates) 256 | { 257 | try 258 | { 259 | eh(this); 260 | } 261 | catch { } // Suppress exceptions 262 | } 263 | } 264 | 265 | private void OnWorkItemStartedCallback(WorkItem workItem) 266 | { 267 | lock(_lock) 268 | { 269 | ++_workItemsExecutingInStp; 270 | } 271 | } 272 | 273 | private void OnWorkItemCompletedCallback(WorkItem workItem) 274 | { 275 | EnqueueToSTPNextWorkItem(null, true); 276 | } 277 | 278 | internal override void Enqueue(WorkItem workItem) 279 | { 280 | EnqueueToSTPNextWorkItem(workItem); 281 | } 282 | 283 | private void EnqueueToSTPNextWorkItem(WorkItem workItem) 284 | { 285 | EnqueueToSTPNextWorkItem(workItem, false); 286 | } 287 | 288 | private void EnqueueToSTPNextWorkItem(WorkItem workItem, bool decrementWorkItemsInStpQueue) 289 | { 290 | lock(_lock) 291 | { 292 | // Got here from OnWorkItemCompletedCallback() 293 | if (decrementWorkItemsInStpQueue) 294 | { 295 | --_workItemsInStpQueue; 296 | 297 | if(_workItemsInStpQueue < 0) 298 | { 299 | _workItemsInStpQueue = 0; 300 | } 301 | 302 | --_workItemsExecutingInStp; 303 | 304 | if(_workItemsExecutingInStp < 0) 305 | { 306 | _workItemsExecutingInStp = 0; 307 | } 308 | } 309 | 310 | // If the work item is not null then enqueue it 311 | if (null != workItem) 312 | { 313 | workItem.CanceledWorkItemsGroup = _canceledWorkItemsGroup; 314 | 315 | RegisterToWorkItemCompletion(workItem.GetWorkItemResult()); 316 | _workItemsQueue.Enqueue(workItem); 317 | //_stp.IncrementWorkItemsCount(); 318 | 319 | if ((1 == _workItemsQueue.Count) && 320 | (0 == _workItemsInStpQueue)) 321 | { 322 | _stp.RegisterWorkItemsGroup(this); 323 | IsIdle = false; 324 | _isIdleWaitHandle.Reset(); 325 | } 326 | } 327 | 328 | // If the work items queue of the group is empty than quit 329 | if (0 == _workItemsQueue.Count) 330 | { 331 | if (0 == _workItemsInStpQueue) 332 | { 333 | _stp.UnregisterWorkItemsGroup(this); 334 | IsIdle = true; 335 | _isIdleWaitHandle.Set(); 336 | if (decrementWorkItemsInStpQueue && _onIdle != null && _onIdle.GetInvocationList().Length > 0) 337 | { 338 | _stp.QueueWorkItem(new WorkItemCallback(FireOnIdle)); 339 | } 340 | } 341 | return; 342 | } 343 | 344 | if (!_isSuspended) 345 | { 346 | if (_workItemsInStpQueue < _concurrency) 347 | { 348 | WorkItem nextWorkItem = _workItemsQueue.Dequeue() as WorkItem; 349 | try 350 | { 351 | _stp.Enqueue(nextWorkItem); 352 | } 353 | catch (ObjectDisposedException e) 354 | { 355 | e.GetHashCode(); 356 | // The STP has been shutdown 357 | } 358 | 359 | ++_workItemsInStpQueue; 360 | } 361 | } 362 | } 363 | } 364 | 365 | #endregion 366 | } 367 | 368 | #endregion 369 | } 370 | -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/WorkItemsGroupBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | 4 | namespace Amib.Threading.Internal 5 | { 6 | public abstract class WorkItemsGroupBase : IWorkItemsGroup 7 | { 8 | #region Private Fields 9 | 10 | /// 11 | /// Contains the name of this instance of SmartThreadPool. 12 | /// Can be changed by the user. 13 | /// 14 | private string _name = "WorkItemsGroupBase"; 15 | 16 | public WorkItemsGroupBase() 17 | { 18 | IsIdle = true; 19 | } 20 | 21 | #endregion 22 | 23 | #region IWorkItemsGroup Members 24 | 25 | #region Public Methods 26 | 27 | /// 28 | /// Get/Set the name of the SmartThreadPool/WorkItemsGroup instance 29 | /// 30 | public string Name 31 | { 32 | get { return _name; } 33 | set { _name = value; } 34 | } 35 | 36 | #endregion 37 | 38 | #region Abstract Methods 39 | 40 | public abstract int Concurrency { get; set; } 41 | public abstract int WaitingCallbacks { get; } 42 | public abstract int InUseThreads { get; } 43 | 44 | public abstract object[] GetStates(); 45 | public abstract WIGStartInfo WIGStartInfo { get; } 46 | public abstract void Start(); 47 | public abstract void Cancel(bool abortExecution); 48 | public abstract bool WaitForIdle(int millisecondsTimeout); 49 | public abstract event WorkItemsGroupIdleHandler OnIdle; 50 | 51 | internal abstract void Enqueue(WorkItem workItem); 52 | internal virtual void PreQueueWorkItem() { } 53 | 54 | #endregion 55 | 56 | #region Common Base Methods 57 | 58 | /// 59 | /// Cancel all the work items. 60 | /// Same as Cancel(false) 61 | /// 62 | public virtual void Cancel() 63 | { 64 | Cancel(false); 65 | } 66 | 67 | /// 68 | /// Wait for the SmartThreadPool/WorkItemsGroup to be idle 69 | /// 70 | public void WaitForIdle() 71 | { 72 | WaitForIdle(Timeout.Infinite); 73 | } 74 | 75 | /// 76 | /// Wait for the SmartThreadPool/WorkItemsGroup to be idle 77 | /// 78 | public bool WaitForIdle(TimeSpan timeout) 79 | { 80 | return WaitForIdle((int)timeout.TotalMilliseconds); 81 | } 82 | 83 | /// 84 | /// IsIdle is true when there are no work items running or queued. 85 | /// 86 | public bool IsIdle { get; protected set; } 87 | 88 | #endregion 89 | 90 | #region QueueWorkItem 91 | 92 | /// 93 | /// Queue a work item 94 | /// 95 | /// A callback to execute 96 | /// Returns a work item result 97 | public IWorkItemResult QueueWorkItem(WorkItemCallback callback) 98 | { 99 | WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback); 100 | Enqueue(workItem); 101 | return workItem.GetWorkItemResult(); 102 | } 103 | 104 | /// 105 | /// Queue a work item 106 | /// 107 | /// A callback to execute 108 | /// The priority of the work item 109 | /// Returns a work item result 110 | public IWorkItemResult QueueWorkItem(WorkItemCallback callback, WorkItemPriority workItemPriority) 111 | { 112 | PreQueueWorkItem(); 113 | WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, workItemPriority); 114 | Enqueue(workItem); 115 | return workItem.GetWorkItemResult(); 116 | } 117 | 118 | /// 119 | /// Queue a work item 120 | /// 121 | /// Work item info 122 | /// A callback to execute 123 | /// Returns a work item result 124 | public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback) 125 | { 126 | PreQueueWorkItem(); 127 | WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback); 128 | Enqueue(workItem); 129 | return workItem.GetWorkItemResult(); 130 | } 131 | 132 | /// 133 | /// Queue a work item 134 | /// 135 | /// A callback to execute 136 | /// 137 | /// The context object of the work item. Used for passing arguments to the work item. 138 | /// 139 | /// Returns a work item result 140 | public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state) 141 | { 142 | WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state); 143 | Enqueue(workItem); 144 | return workItem.GetWorkItemResult(); 145 | } 146 | 147 | /// 148 | /// Queue a work item 149 | /// 150 | /// A callback to execute 151 | /// 152 | /// The context object of the work item. Used for passing arguments to the work item. 153 | /// 154 | /// The work item priority 155 | /// Returns a work item result 156 | public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, WorkItemPriority workItemPriority) 157 | { 158 | PreQueueWorkItem(); 159 | WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, workItemPriority); 160 | Enqueue(workItem); 161 | return workItem.GetWorkItemResult(); 162 | } 163 | 164 | /// 165 | /// Queue a work item 166 | /// 167 | /// Work item information 168 | /// A callback to execute 169 | /// 170 | /// The context object of the work item. Used for passing arguments to the work item. 171 | /// 172 | /// Returns a work item result 173 | public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state) 174 | { 175 | PreQueueWorkItem(); 176 | WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback, state); 177 | Enqueue(workItem); 178 | return workItem.GetWorkItemResult(); 179 | } 180 | 181 | /// 182 | /// Queue a work item 183 | /// 184 | /// A callback to execute 185 | /// 186 | /// The context object of the work item. Used for passing arguments to the work item. 187 | /// 188 | /// 189 | /// A delegate to call after the callback completion 190 | /// 191 | /// Returns a work item result 192 | public IWorkItemResult QueueWorkItem( 193 | WorkItemCallback callback, 194 | object state, 195 | PostExecuteWorkItemCallback postExecuteWorkItemCallback) 196 | { 197 | PreQueueWorkItem(); 198 | WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback); 199 | Enqueue(workItem); 200 | return workItem.GetWorkItemResult(); 201 | } 202 | 203 | /// 204 | /// Queue a work item 205 | /// 206 | /// A callback to execute 207 | /// 208 | /// The context object of the work item. Used for passing arguments to the work item. 209 | /// 210 | /// 211 | /// A delegate to call after the callback completion 212 | /// 213 | /// The work item priority 214 | /// Returns a work item result 215 | public IWorkItemResult QueueWorkItem( 216 | WorkItemCallback callback, 217 | object state, 218 | PostExecuteWorkItemCallback postExecuteWorkItemCallback, 219 | WorkItemPriority workItemPriority) 220 | { 221 | PreQueueWorkItem(); 222 | WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, workItemPriority); 223 | Enqueue(workItem); 224 | return workItem.GetWorkItemResult(); 225 | } 226 | 227 | /// 228 | /// Queue a work item 229 | /// 230 | /// A callback to execute 231 | /// 232 | /// The context object of the work item. Used for passing arguments to the work item. 233 | /// 234 | /// 235 | /// A delegate to call after the callback completion 236 | /// 237 | /// Indicates on which cases to call to the post execute callback 238 | /// Returns a work item result 239 | public IWorkItemResult QueueWorkItem( 240 | WorkItemCallback callback, 241 | object state, 242 | PostExecuteWorkItemCallback postExecuteWorkItemCallback, 243 | CallToPostExecute callToPostExecute) 244 | { 245 | PreQueueWorkItem(); 246 | WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute); 247 | Enqueue(workItem); 248 | return workItem.GetWorkItemResult(); 249 | } 250 | 251 | /// 252 | /// Queue a work item 253 | /// 254 | /// A callback to execute 255 | /// 256 | /// The context object of the work item. Used for passing arguments to the work item. 257 | /// 258 | /// 259 | /// A delegate to call after the callback completion 260 | /// 261 | /// Indicates on which cases to call to the post execute callback 262 | /// The work item priority 263 | /// Returns a work item result 264 | public IWorkItemResult QueueWorkItem( 265 | WorkItemCallback callback, 266 | object state, 267 | PostExecuteWorkItemCallback postExecuteWorkItemCallback, 268 | CallToPostExecute callToPostExecute, 269 | WorkItemPriority workItemPriority) 270 | { 271 | PreQueueWorkItem(); 272 | WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); 273 | Enqueue(workItem); 274 | return workItem.GetWorkItemResult(); 275 | } 276 | 277 | #endregion 278 | 279 | #region QueueWorkItem(Action<...>) 280 | 281 | public IWorkItemResult QueueWorkItem(Action action, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority) 282 | { 283 | PreQueueWorkItem (); 284 | WorkItem workItem = WorkItemFactory.CreateWorkItem ( 285 | this, 286 | WIGStartInfo, 287 | delegate 288 | { 289 | action.Invoke (); 290 | return null; 291 | }, priority); 292 | Enqueue (workItem); 293 | return workItem.GetWorkItemResult (); 294 | } 295 | 296 | public IWorkItemResult QueueWorkItem(Action action, T arg, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority) 297 | { 298 | PreQueueWorkItem (); 299 | WorkItem workItem = WorkItemFactory.CreateWorkItem ( 300 | this, 301 | WIGStartInfo, 302 | state => 303 | { 304 | action.Invoke (arg); 305 | return null; 306 | }, 307 | WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null, priority); 308 | Enqueue (workItem); 309 | return workItem.GetWorkItemResult (); 310 | } 311 | 312 | public IWorkItemResult QueueWorkItem(Action action, T1 arg1, T2 arg2, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority) 313 | { 314 | PreQueueWorkItem (); 315 | WorkItem workItem = WorkItemFactory.CreateWorkItem ( 316 | this, 317 | WIGStartInfo, 318 | state => 319 | { 320 | action.Invoke (arg1, arg2); 321 | return null; 322 | }, 323 | WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null, priority); 324 | Enqueue (workItem); 325 | return workItem.GetWorkItemResult (); 326 | } 327 | 328 | public IWorkItemResult QueueWorkItem(Action action, T1 arg1, T2 arg2, T3 arg3, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority) 329 | { 330 | PreQueueWorkItem (); 331 | WorkItem workItem = WorkItemFactory.CreateWorkItem ( 332 | this, 333 | WIGStartInfo, 334 | state => 335 | { 336 | action.Invoke (arg1, arg2, arg3); 337 | return null; 338 | }, 339 | WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null, priority); 340 | Enqueue (workItem); 341 | return workItem.GetWorkItemResult (); 342 | } 343 | 344 | public IWorkItemResult QueueWorkItem ( 345 | Action action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority) 346 | { 347 | PreQueueWorkItem (); 348 | WorkItem workItem = WorkItemFactory.CreateWorkItem ( 349 | this, 350 | WIGStartInfo, 351 | state => 352 | { 353 | action.Invoke (arg1, arg2, arg3, arg4); 354 | return null; 355 | }, 356 | WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null, priority); 357 | Enqueue (workItem); 358 | return workItem.GetWorkItemResult (); 359 | } 360 | 361 | #endregion 362 | 363 | #region QueueWorkItem(Func<...>) 364 | 365 | public IWorkItemResult QueueWorkItem(Func func, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority) 366 | { 367 | PreQueueWorkItem(); 368 | WorkItem workItem = WorkItemFactory.CreateWorkItem( 369 | this, 370 | WIGStartInfo, 371 | state => 372 | { 373 | return func.Invoke(); 374 | }, priority); 375 | Enqueue(workItem); 376 | return new WorkItemResultTWrapper(workItem.GetWorkItemResult()); 377 | } 378 | 379 | public IWorkItemResult QueueWorkItem(Func func, T arg, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority) 380 | { 381 | PreQueueWorkItem(); 382 | WorkItem workItem = WorkItemFactory.CreateWorkItem( 383 | this, 384 | WIGStartInfo, 385 | state => 386 | { 387 | return func.Invoke(arg); 388 | }, 389 | WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null, 390 | priority); 391 | Enqueue(workItem); 392 | return new WorkItemResultTWrapper(workItem.GetWorkItemResult()); 393 | } 394 | 395 | public IWorkItemResult QueueWorkItem(Func func, T1 arg1, T2 arg2, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority) 396 | { 397 | PreQueueWorkItem(); 398 | WorkItem workItem = WorkItemFactory.CreateWorkItem( 399 | this, 400 | WIGStartInfo, 401 | state => 402 | { 403 | return func.Invoke(arg1, arg2); 404 | }, 405 | WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null, 406 | priority); 407 | Enqueue(workItem); 408 | return new WorkItemResultTWrapper(workItem.GetWorkItemResult()); 409 | } 410 | 411 | public IWorkItemResult QueueWorkItem( 412 | Func func, T1 arg1, T2 arg2, T3 arg3, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority) 413 | { 414 | PreQueueWorkItem(); 415 | WorkItem workItem = WorkItemFactory.CreateWorkItem( 416 | this, 417 | WIGStartInfo, 418 | state => 419 | { 420 | return func.Invoke(arg1, arg2, arg3); 421 | }, 422 | WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null, 423 | priority); 424 | Enqueue(workItem); 425 | return new WorkItemResultTWrapper(workItem.GetWorkItemResult()); 426 | } 427 | 428 | public IWorkItemResult QueueWorkItem( 429 | Func func, T1 arg1, T2 arg2, T3 arg3, T4 arg4, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority) 430 | { 431 | PreQueueWorkItem(); 432 | WorkItem workItem = WorkItemFactory.CreateWorkItem( 433 | this, 434 | WIGStartInfo, 435 | state => 436 | { 437 | return func.Invoke(arg1, arg2, arg3, arg4); 438 | }, 439 | WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null, 440 | priority); 441 | Enqueue(workItem); 442 | return new WorkItemResultTWrapper(workItem.GetWorkItemResult()); 443 | } 444 | 445 | #endregion 446 | 447 | #endregion 448 | } 449 | } -------------------------------------------------------------------------------- /SWebVulnsScan/tools/thread/WorkItemsQueue.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shack2/SWebScan/7a8394b196b4dcd9fbca7fc9a368b4a430614b7c/SWebVulnsScan/tools/thread/WorkItemsQueue.cs --------------------------------------------------------------------------------