{"id":69,"date":"2023-12-21T09:28:33","date_gmt":"2023-12-21T01:28:33","guid":{"rendered":"http:\/\/www.zrxf.xyz\/?p=69"},"modified":"2023-12-21T16:06:43","modified_gmt":"2023-12-21T08:06:43","slug":"cwpf%e5%86%85%e5%ad%98%e5%9b%9e%e6%94%b6%e4%b8%8e%e9%87%8a%e6%94%belierdacracker","status":"publish","type":"post","link":"http:\/\/www.zrxf.xyz\/?p=69","title":{"rendered":"C#WPF\u5185\u5b58\u56de\u6536\u4e0e\u91ca\u653eLierdaCracker"},"content":{"rendered":"\n<p>\u4f7f\u7528wpf\u7a0b\u5e8f\u5e38\u5e38\u4f1a\u51fa\u73b0\u4e00\u4e2a\u95ee\u9898,\u90a3\u5c31\u662f\u5185\u5b58\u5360\u7528\u8fc7\u9ad8\uff0c\u4f7f\u7528wpf\u7684\u7a0b\u5e8f\u529f\u80fd\u8d8a\u590d\u6742\u5f80\u5f80\u7528\u7740\u7528\u7740\u5185\u5b58\u5c31\u672c\u774090\u5f80\u4e0a\u53bb\u4e86\u3002<\/p>\n\n\n\n<p>\u4e00\u65b9\u9762wpf\u672c\u8eab\u662f\u4e00\u4e2aui\u6846\u67b6\uff0c\u5bf9\u56fe\u50cf\u4ee5\u53ca\u754c\u9762\u7684\u6e32\u67d3\u867d\u7136\u63d0\u9ad8\u4e86\u8f6f\u4ef6\u7684\u7f8e\u89c2\u6027,\u4f46\u5b9e\u9645\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u8c03\u7528\u548c\u6d88\u8017\u4e86\u5927\u91cf\u7684\u5185\u5b58\u6765\u8fdb\u884c\u534f\u540c\u5904\u7406;\u53e6\u4e00\u65b9\u9762\u8fd9\u4e9b\u8c03\u7528\u7684\u5185\u5b58\u7684\u786e\u5728\u4f7f\u7528\u5b8c\u6210\u4e4b\u540e\u5e76\u6ca1\u6709\u8fdb\u884c\u4e3b\u52a8\u7684\u91ca\u653e\u6216\u8005\u662f\u53ea\u662f\u81ea\u52a8\u91ca\u653e\u4e86\u4e00\u90e8\u5206\uff0c\u5373\u5bf9\u4e8e\u6258\u7ba1\u8d44\u6e90\u901a\u8fc7GC\u81ea\u52a8\u6e05\u7406\u56de\u6536\u3002\u5bf9\u4e8e\u975e\u6258\u7ba1\u8d44\u6e90\uff0c\u901a\u8fc7\u4ee3\u7801\u8c03\u7528\u624b\u52a8\u8fdb\u884c\u6e05\u9664\uff0c\u518d\u7531GC\u56de\u6536\u3002\u4f8b\u5982\u6d41\uff0c\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u7f51\u7edc\u8fde\u63a5\u7b49,\u6240\u4ee5\u5c31\u9700\u8981\u6211\u4eec\u4e3b\u52a8\u5b9a\u65f6\u7684\u5bf9\u5185\u5b58\u8fdb\u884c\u56de\u6536\u91ca\u653e\u7684\u5904\u7406\u3002\u5728\u8fd9\u91cc\u975e\u5e38\u63a8\u8350\u4f7f\u7528LierdaCracker\u4e00.\u53ef\u4ee5\u4f7f\u7528nuget\u7ba1\u7406\u5b89\u88c5Lierda.WPFHelper\u5305\uff0c\u5728\u9879\u76ee\u7684App.xaml.cs\u4e2d\u7684Application_Startup\u65b9\u6cd5\u91cc\u5b9e\u4f8b\u5316\u5e76\u8c03\u7528cracker\u65b9\u6cd5\u76f4\u63a5\u4f7f\u7528&nbsp;&nbsp;&nbsp;LierdaCracker&nbsp;cracker&nbsp;=&nbsp;new&nbsp;LierdaCracker();&nbsp;&nbsp;&nbsp;cracker.Cracker();<\/p>\n\n\n\n<p>\u4e8c.\u81ea\u5df1\u5b9e\u73b0LierdaCracker\u7c7b\u63d0\u5230C#\u8d44\u6e90\u548c\u5185\u5b58\u56de\u6536\u80af\u5b9a\u5c11\u4e0d\u4e86GC\u5783\u573e\u56de\u6536\u673a\u5236\uff0c\u6258\u7ba1\u5806\u4e0a\u7684\u5185\u5b58\u7531GC\u5168\u6743\u8d1f\u8d23\uff0c&nbsp;\u503c\u5f15\u7528\u7684\u5728\u6808\u4e0a\u7684\u5185\u5b58\u4f1a\u968f\u7740\u6808\u7a7a\u95f4\u7684\u6d88\u4ea1\u800c\u81ea\u52a8\u6d88\u5931\u3002GC.Collect()\uff1b&nbsp;GC.WaitForPendingFinalizers();12\u6b64\u65b9\u6cd5\u5f3a\u5236\u5bf9\u6240\u6709\u4ee3\u8fdb\u884c\u5373\u65f6\u5783\u573e\u56de\u6536\uff01\u5f53\u5e94\u7528\u7a0b\u5e8f\u4ee3\u7801\u4e2d\u67d0\u4e2a\u786e\u5b9a\u7684\u70b9\u4e0a\u4f7f\u7528\u7684\u5185\u5b58\u91cf\u5927\u91cf\u51cf\u5c11\u65f6\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4f7f\u7528&nbsp;GC.Collect&nbsp;\u65b9\u6cd5\u53ef\u80fd\u6bd4\u8f83\u5408\u9002\u3002\u800cGC.WaitForPendingFinalizers\u5219\u662f\u63d0\u4f9b\u6536\u96c6\u5b8c\u6210\u524d\u7684\u7b49\u5f85\u3002\u53e6\u5916\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u7cfb\u7edfapi\u5728\u91ca\u653e\u5185\u5b58\u7684\u65f6\u5019\u4e5f\u662f\u975e\u5e38\u91cd\u8981\u7684SetProcessWorkingSetSize\uff0c\u4f7f\u7528\u8fd9\u4e2a\u51fd\u6570\u6765\u8bbe\u7f6e\u5e94\u7528\u7a0b\u5e8f\u6700\u5c0f\u548c\u6700\u5927\u7684\u8fd0\u884c\u7a7a\u95f4\uff0c\u53ea\u4f1a\u4fdd\u7559\u9700\u8981\u7684\u5185\u5b58\u3002\u5f53\u5e94\u7528\u7a0b\u5e8f\u88ab\u95f2\u7f6e\u6216\u7cfb\u7edf\u5185\u5b58\u592a\u4f4e\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u8c03\u7528\u8fd9\u4e2a\u673a\u5236\u6765\u8bbe\u7f6e\u5e94\u7528\u7a0b\u5e8f\u7684\u5185\u5b58\u3002\u5e94\u7528\u7a0b\u5e8f\u4e5f\u53ef\u4ee5\u4f7f\u7528&nbsp;VirtualLock&nbsp;\u6765\u9501\u4f4f\u4e00\u5b9a\u8303\u56f4\u7684\u5185\u5b58\u4e0d\u88ab\u7cfb\u7edf\u91ca\u653e\u3002\u4e8b\u5b9e\u4e0a\uff0c\u4f7f\u7528\u8be5\u51fd\u6570\u5e76\u4e0d\u80fd\u63d0\u9ad8\u4ec0\u4e48\u6027\u80fd\uff0c\u4e5f\u4e0d\u4f1a\u771f\u7684\u8282\u7701\u5185\u5b58\u3002\u56e0\u4e3a\u4ed6\u53ea\u662f\u6682\u65f6\u7684\u5c06\u5e94\u7528\u7a0b\u5e8f\u5360\u7528\u7684\u5185\u5b58\u79fb\u81f3\u865a\u62df\u5185\u5b58\uff0c\u4e00\u65e6\uff0c\u5e94\u7528\u7a0b\u5e8f\u88ab\u6fc0\u6d3b\u6216\u8005\u6709\u64cd\u4f5c\u8bf7\u6c42\u65f6\uff0c\u8fd9\u4e9b\u5185\u5b58\u53c8\u4f1a\u88ab\u91cd\u65b0\u5360\u7528\u3002\u5982\u679c\u4f60\u5f3a\u5236\u4f7f\u7528\u8be5\u65b9\u6cd5\u6765&nbsp;\u8bbe\u7f6e\u7a0b\u5e8f\u5360\u7528\u7684\u5185\u5b58\uff0c\u90a3\u4e48\u53ef\u80fd\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u53cd\u800c\u4f1a\u964d\u4f4e\u7cfb\u7edf\u6027\u80fd\uff0c\u56e0\u4e3a\u7cfb\u7edf\u9700\u8981\u9891\u7e41\u7684\u8fdb\u884c\u5185\u5b58\u548c\u786c\u76d8\u95f4\u7684\u9875\u9762\u4ea4\u6362\u3002BOOL&nbsp;SetProcessWorkingSetSize(HANDLE&nbsp;hProcess,SIZE_T&nbsp;dwMinimumWorkingSetSize,SIZE_T&nbsp;dwMaximumWorkingSetSize);\u5c06&nbsp;2\u4e2a&nbsp;SIZE_T&nbsp;\u53c2\u6570\u8bbe\u7f6e\u4e3a&nbsp;\uff0d1&nbsp;\uff0c\u5373\u53ef\u4ee5\u4f7f\u8fdb\u7a0b\u4f7f\u7528\u7684\u5185\u5b58\u4ea4\u6362\u5230\u865a\u62df\u5185\u5b58\uff0c\u53ea\u4fdd\u7559\u4e00\u5c0f\u90e8\u5206\u4ee3\u7801\uff0c\u5b83\u662fwindowsNT\u7684api&nbsp;\u6240\u4ee5\u4f7f\u7528\u7684\u4f7f\u7528\u9700\u8981\u52a0\u4e0a\u5e73\u53f0\u6761\u4ef6\u3002&nbsp;<\/p>\n\n\n<p>public class LierdaCracker<br \/>\n {<br \/>\n\t [DllImport(&#8220;kernel32.dll&#8221;)]<br \/>\n     private static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);<\/p>\n<p>\t private void FlushMemory()<br \/>\n     {<br \/>\n          GC.Collect();<br \/>\n          GC.WaitForPendingFinalizers();<br \/>\n          if (Environment.OSVersion.Platform == PlatformID.Win32NT)<br \/>\n              SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);<br \/>\n      }<\/p>\n<p>\t  public void Cracker(int sleepSpan = 50)<br \/>\n      {<br \/>\n           _ = Task.Factory.StartNew(delegate<br \/>\n           {<br \/>\n               while (true)<br \/>\n               {<br \/>\n                   try<br \/>\n                   {<br \/>\n                       \/\/SetDate();<br \/>\n                       FlushMemory();<br \/>\n                       Thread.Sleep(TimeSpan.FromSeconds((double)sleepSpan));<br \/>\n                   }<br \/>\n                   catch { }<br \/>\n               }<br \/>\n           });<br \/>\n       }<\/p>\n<p> }<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528wpf\u7a0b\u5e8f\u5e38\u5e38\u4f1a\u51fa\u73b0\u4e00\u4e2a\u95ee\u9898,\u90a3\u5c31\u662f\u5185\u5b58\u5360\u7528\u8fc7\u9ad8\uff0c\u4f7f\u7528wpf\u7684\u7a0b\u5e8f\u529f\u80fd\u8d8a\u590d\u6742\u5f80\u5f80\u7528\u7740\u7528\u7740\u5185\u5b58\u5c31\u672c\u774090\u5f80\u4e0a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.zrxf.xyz\/?p=69\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cC#WPF\u5185\u5b58\u56de\u6536\u4e0e\u91ca\u653eLierdaCracker\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zrxf.xyz\/index.php?rest_route=\/wp\/v2\/posts\/69"}],"collection":[{"href":"http:\/\/www.zrxf.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zrxf.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zrxf.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zrxf.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=69"}],"version-history":[{"count":6,"href":"http:\/\/www.zrxf.xyz\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":106,"href":"http:\/\/www.zrxf.xyz\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions\/106"}],"wp:attachment":[{"href":"http:\/\/www.zrxf.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zrxf.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zrxf.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}