From 3167e7ccb6f42c379eb17bcfe7e9075b0499eda2 Mon Sep 17 00:00:00 2001 From: "Taisen.fr (Dev)" Date: Fri, 7 Jun 2024 09:21:38 +0200 Subject: [PATCH] TestCpu++ --- Program.cs | 2 +- TestCpu/TestCpu.cs | 49 ++++++++++++++++++---------------------------- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/Program.cs b/Program.cs index edf1073..3ecc820 100644 --- a/Program.cs +++ b/Program.cs @@ -88,7 +88,7 @@ if(!string.IsNullOrEmpty(test)) { Console.WriteLine("Start CPU Testing"); - TestCpu.TestAffinity(Secret); + TestCpu.TestAffinity(); } if (string.IsNullOrEmpty(url)) diff --git a/TestCpu/TestCpu.cs b/TestCpu/TestCpu.cs index 07b6525..1f7b07d 100644 --- a/TestCpu/TestCpu.cs +++ b/TestCpu/TestCpu.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Linq; using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.Arm; using System.Security.Cryptography; using System.Text; using System.Threading; @@ -10,46 +11,34 @@ namespace VulnerableWebApplication.TestCpu { + /* + Test de perfs sur un seul proc (compatible Windows et Linux uniquement) + */ public class TestCpu { - public static void TestAffinity(string Str) + public static void TestAffinity() { - string BinStr = ConvertToBinary(Str); + byte[] bytes = File.ReadAllBytes("appsettings.json"); + StringBuilder binary = new StringBuilder(); + var sha256 = SHA256.Create(); + foreach (byte b in bytes) binary.Append(Convert.ToString(b, 2).PadLeft(8, '0')); + string BinStr = binary.ToString(); Console.WriteLine("Total proc: {0}", Environment.ProcessorCount); foreach (char bit in BinStr) { - Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)(bit - '0' +1); - CalculateSHA512(Str); - } - Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)5; - } - - public static string ConvertToBinary(string input) - { - byte[] bytes = Encoding.UTF8.GetBytes(input); - StringBuilder binary = new StringBuilder(); - - foreach (byte b in bytes) binary.Append(Convert.ToString(b,2).PadLeft(8,'0')); - - return binary.ToString(); - } - - public static void CalculateSHA512(string input) - { - { - var stopWatch = new Stopwatch(); - stopWatch.Start(); - while (stopWatch.Elapsed.TotalSeconds < 5) + Thread.Sleep(1000); + if (bit == '0') Thread.Sleep(4000); + else { - using (var sha256 = SHA256.Create()) - { - var bytes = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()); - var hash = sha256.ComputeHash(bytes); - } + Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)(bit - '0' + 1); + var stopWatch = new Stopwatch(); + stopWatch.Start(); + while (stopWatch.Elapsed.TotalSeconds < 4) sha256.ComputeHash(bytes); + stopWatch.Stop(); } - stopWatch.Stop(); } + Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)5; } }