Запись и удаление значений реестра - C#
Формулировка задачи:
если на этот вопрос найдётся ответ то все предыдущие темы стоит удалить...
ругается на
if (BitnostSistem == bit32)
{
RegistryKey regFirst = Registry.LocalMachine;
RegistryKey regsw = regFirst.OpenSubKey("SOFTWARE", true);
RegistryKey regmc = regsw.OpenSubKey("Microsoft", true);
RegistryKey regwin = regmc.OpenSubKey("Windows NT", true);
RegistryKey regcv = regwin.OpenSubKey("CurrentVersion", true);
RegistryKey regrun = regcv.OpenSubKey("Windows", true);
regrun.SetValue("AppInit_DLLs", NameDLL);
regrun.SetValue("LoadAppInit_DLLs", 1, RegistryValueKind.DWord);
timer1.Stop();
timer2.Start();
notifyIcon1.ShowBalloonTip(600, "**", "DLL внедрена в процесс.", ToolTipIcon.Warning);regrun.SetValue("AppInit_DLLs", NameDLL); regrun.SetValue("LoadAppInit_DLLs", 1, RegistryValueKind.DWord);
этой командой DLl добавляется в реестр? каким образом выгрузить её с реестра?
string NameDLL = "" если оставить так? будет ли работать, у меня просто vs не запускается, нужно сделать откат системы
додумался до такого
private void Form1_Closing(object sender, EventArgs e)
{
reg.SetValue("AppInit_DLLs", string.Empty);
}reg
Решение задачи: «Запись и удаление значений реестра»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Net;
using System.Management;
using Microsoft.Win32;
namespace Инжектор_DLL
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
//#region Global оказалось не нужным
//string globalstringtextbox = "";
//const bool debugState = false;
//#endregion
timer1.Start();
notifyIcon1.Text = "****блоло";
notifyIcon1.MouseClick += new MouseEventHandler(_notifyIcon_MouseClick);
this.components = null;
}
public static int BitnostSistem = IntPtr.Size;//Переменная равная 4 - 32x(битности). А в 64x - 8.
int bit32 = 4;//Windows ... 32(86)x
int bit64 = 8;//Windows ... 64x
/// <summary>
/// здесь хранится состояние окна до сворачивания (максимизированное или нормальное)
/// </summary>
private FormWindowState _OldFormState;
private static bool debugState;
/// <summary>
/// обрабатываем событие клика мышью по значку в трее
/// </summary>
void _notifyIcon_MouseClick(object sender, MouseEventArgs e)
{
//проверяем, какой кнопкой было произведено нажатие
if (e.Button == MouseButtons.Left)//если левой кнопкой мыши
{
//проверяем текущее состояние окна
if (WindowState == FormWindowState.Normal || WindowState == FormWindowState.Maximized)//если оно развернуто
{
//сохраняем текущее состояние
_OldFormState = WindowState;
//сворачиваем окно
WindowState = FormWindowState.Minimized;
//скрываться в трей оно будет по событию Resize (изменение размера), которое сгенерировалось после минимизации строчкой выше
}
else//в противном случае
{
//и показываем на нанели задач
Show();
//разворачиваем (возвращаем старое состояние "до сворачивания")
WindowState = _OldFormState;
}
}
}
/// <summary>
/// обрабатываем событие изменения размера
/// </summary>
private void Form1_Load(object sender, EventArgs e)
{
notifyIcon1.ShowBalloonTip(600, "Инжектор", "Программа запущена", ToolTipIcon.Warning);
// MessageBox.Show("Pleas Wait (2-3min.");
// WebClient Client = new WebClient();
//Создаем клиент
//string DownloadFileName = System.IO.Path.GetFileName(txtAddr2.Text);
//Объявляем адрес файла для скачки
//Client.DownloadFile(txtAddr2.Text, txtPath2.Text + DownloadFileName);
//С помощью клиента начинаем загрузку файла
}
private void timer1_Tick(object sender, EventArgs e)
{
Process[] process = Process.GetProcesses();
bool ProcessFound = false;
foreach (Process proc in process)
{
if (proc.ProcessName == "GTA*.*")
{
string NameDLL = @"C:\Disco.dll";
if (BitnostSistem == bit32)
{
RegistryKey regFirst = Registry.LocalMachine;
RegistryKey regsw = regFirst.OpenSubKey("SOFTWARE", true);
RegistryKey regmc = regsw.OpenSubKey("Microsoft", true);
RegistryKey regwin = regmc.OpenSubKey("Windows NT", true);
RegistryKey regcv = regwin.OpenSubKey("CurrentVersion", true);
RegistryKey regrun = regcv.OpenSubKey("Windows", true);
regrun.SetValue("AppInit_DLLs", NameDLL);
regrun.SetValue("LoadAppInit_DLLs", 1, RegistryValueKind.DWord);
timer1.Stop();
timer2.Start();
notifyIcon1.ShowBalloonTip(600, "Инжектор", "DLL внедрена в процесс.", ToolTipIcon.Warning);
//System.IO.File.Delete(@"C:\WINDOWS\Temp\Disco.dll");
}
if (BitnostSistem == bit64)
{
RegistryKey regFirst = Registry.LocalMachine;
RegistryKey regsw = regFirst.OpenSubKey("SOFTWARE", true);
RegistryKey regmc = regsw.OpenSubKey("Wow6432Node", true);
RegistryKey regwin = regmc.OpenSubKey("Microsoft", true);
RegistryKey regcv = regwin.OpenSubKey("Windows NT", true);
RegistryKey regrun = regcv.OpenSubKey("CurrentVersion", true);
RegistryKey rego = regcv.OpenSubKey("Windows", true);
rego.SetValue("AppInit_DLLs", NameDLL);
rego.SetValue("LoadAppInit_DLLs", 1, RegistryValueKind.DWord);
timer1.Stop();
timer2.Start();
notifyIcon1.ShowBalloonTip(600, "Инжектор", "DLL внедрена в процесс.", ToolTipIcon.Warning);
ProcessFound = true;
//System.IO.File.Delete(@"C:\WINDOWS\Temp\Disco.dll");
}
}
if (ProcessFound != true)
label1.Text = "Go Go Go WarFace Hacking...";
label2.Text = "[ожидание запуска игры]...";
}
}
private void timer2_Tick(object sender, EventArgs e)
{
Process[] process = Process.GetProcesses();
bool ProcessFound = false;
foreach (Process proc in process)
{
if (proc.ProcessName == "Game")
{
string NameDLL = @"C:\WINDOWS\Temp\Disco.dll";
if (BitnostSistem == bit32)
{
RegistryKey regFirst = Registry.LocalMachine;
RegistryKey regsw = regFirst.OpenSubKey("SOFTWARE", true);
RegistryKey regmc = regsw.OpenSubKey("Microsoft", true);
RegistryKey regwin = regmc.OpenSubKey("Windows NT", true);
RegistryKey regcv = regwin.OpenSubKey("CurrentVersion", true);
RegistryKey regrun = regcv.OpenSubKey("Windows", true);
regrun.SetValue("AppInit_DLLs", NameDLL);
regrun.SetValue("LoadAppInit_DLLs", 1, RegistryValueKind.DWord);
timer2.Stop();
notifyIcon1.ShowBalloonTip(600, "Инжектор", "DLL успешно заинжектена!", ToolTipIcon.Warning);
this.Opacity = 100;
//rego.SetValue("AppInit_DLLs", string.Empty);
FileInfo fi = new FileInfo(@"C:\WINDOWS\Temp\Disco.dll");
fi.Delete();
//Process.Start(@"C:\Windows\System32\cmd.exe", @" /C del C:\WINDOWS\Temp\Disco.dll");
// System.IO.File.Delete(@"C:\WINDOWS\Temp\Disco.dll");
Application.Exit();
}
if (BitnostSistem == bit64)
{
RegistryKey regFirst = Registry.LocalMachine;
RegistryKey regsw = regFirst.OpenSubKey("SOFTWARE", true);
RegistryKey regmc = regsw.OpenSubKey("Wow6432Node", true);
RegistryKey regwin = regmc.OpenSubKey("Microsoft", true);
RegistryKey regcv = regwin.OpenSubKey("Windows NT", true);
RegistryKey regrun = regcv.OpenSubKey("CurrentVersion", true);
RegistryKey rego = regcv.OpenSubKey("Windows", true);
rego.SetValue("AppInit_DLLs", NameDLL);
rego.SetValue("LoadAppInit_DLLs", 1, RegistryValueKind.DWord);
timer2.Stop();
notifyIcon1.ShowBalloonTip(600, "Инжектор", "DLL успешно заинжектена!", ToolTipIcon.Warning);
this.Opacity = 100;
ProcessFound = true;
// Process.Start(@"C:\Windows\System32\cmd.exe", @" /C del C:\WINDOWS\Temp\Disco.dll");
// System.IO.File.Delete(@"C:\WINDOWS\Temp\Disco.dll");
// FileInfo fi = new FileInfo(@"C:\WINDOWS\Temp\Disco.dll");
Application.Exit();
}
}
if (ProcessFound != true)
label1.Text = "Ожидание запуска игры...";
}
}
public static void ErrorMessage(string message)//Служит для определения в каком месте - произошла ошибка. Конечно можно просто использовать MessBox, но мне так удобней
{
if (debugState == true)
MessageBox.Show("Ошибка : " + message);
}
private void Form1_Closing(object sender, EventArgs e)
{
Registry.CurrentUser.DeleteSubKey(@"что удалить");
}
}
}