Files
raton4.0-source/Raton RAT/Raton/RatonForms/BlockWindow.cs
T

173 lines
5.3 KiB
C#
Raw Normal View History

2026-08-27 11:23:13 -06:00
// Decompiled with JetBrains decompiler
// Type: Raton.RatonForms.BlockWindow
// Assembly: Raton, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 36C4E416-7F8D-4D23-930F-B5CCB0D810E7
// Assembly location: C:\Users\user\Desktop\v3.8.0 Deluxe Plugins (v4.0.0) cracked\Raton.exe
using Microsoft.CSharp.RuntimeBinder;
using Microsoft.Win32;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media;
using WpfApp1;
#nullable disable
namespace Raton.RatonForms;
public partial class BlockWindow : Window
{
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
private const int DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19;
private const string PlaceholderText = "Enter the IP or Username here";
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(
IntPtr hwnd,
int dwAttribute,
ref int pvAttribute,
int cbAttribute);
public BlockWindow() => this.InitializeComponent();
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
this.ApplyDarkMode();
}
private void Window_Loaded(object sender, RoutedEventArgs e) => this.LoadJson();
private void Window_Closing(object sender, CancelEventArgs e) => this.SaveJson();
private void ApplyDarkMode()
{
IntPtr handle = new WindowInteropHelper((Window) this).Handle;
if (handle == IntPtr.Zero)
return;
int pvAttribute = this.IsWindowsDarkMode() ? 1 : 0;
BlockWindow.DwmSetWindowAttribute(handle, 20, ref pvAttribute, 4);
BlockWindow.DwmSetWindowAttribute(handle, 19, ref pvAttribute, 4);
}
private bool IsWindowsDarkMode()
{
using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"))
{
if (registryKey != null)
{
if (registryKey.GetValue("AppsUseLightTheme") is int num)
return num == 0;
}
}
return false;
}
private void TextBox1_GotFocus(object sender, RoutedEventArgs e)
{
if (!(this.textBox1.Text == "Enter the IP or Username here"))
return;
this.textBox1.Text = string.Empty;
this.textBox1.Foreground = (Brush) Brushes.White;
}
private void TextBox1_LostFocus(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(this.textBox1.Text))
return;
this.textBox1.Text = "Enter the IP or Username here";
this.textBox1.Foreground = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 85, (byte) 85, (byte) 85));
}
private void TextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key != Key.Return)
return;
this.AddEntry();
}
private void BtnAdd_Click(object sender, RoutedEventArgs e) => this.AddEntry();
private void BtnBlock_Click(object sender, RoutedEventArgs e) => this.AddEntry();
private void BtnUnblock_Click(object sender, RoutedEventArgs e) => this.RemoveSelectedEntry();
private void ClearAll_Click(object sender, RoutedEventArgs e) => this.listBox1.Items.Clear();
private void RemoveSelected_Click(object sender, RoutedEventArgs e) => this.RemoveSelectedEntry();
private void AddEntry()
{
string newItem = this.textBox1.Text.Trim();
if (string.IsNullOrEmpty(newItem) || newItem == "Enter the IP or Username here")
return;
this.listBox1.Items.Add((object) newItem);
this.textBox1.Clear();
this.textBox1.Focus();
if (!(Application.Current.MainWindow is MainWindow mainWindow))
return;
object[] objArray = new object[1]
{
(object) $"USER has blocked a new connection ({newItem})"
};
mainWindow.AddLog(objArray);
}
private void RemoveSelectedEntry()
{
if (this.listBox1.SelectedIndex == -1)
return;
this.listBox1.Items.RemoveAt(this.listBox1.SelectedIndex);
}
private void LoadJson()
{
string filePath = BlockWindow.GetFilePath();
if (!File.Exists(filePath))
return;
try
{
JObject json = JObject.Parse(File.ReadAllText(filePath));
JArray ipArray = json["IP"] as JArray;
if (ipArray != null)
{
foreach (var item in ipArray)
{
this.listBox1.Items.Add(item.ToString());
}
}
}
catch { }
}
private void SaveJson()
{
List<string> stringList = new List<string>();
foreach (object obj in (IEnumerable) this.listBox1.Items)
stringList.Add(obj.ToString());
string contents = JsonConvert.SerializeObject((object) new
{
IP = stringList
}, Formatting.Indented);
string filePath = BlockWindow.GetFilePath();
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
File.WriteAllText(filePath, contents);
}
private static string GetFilePath() => Path.Combine(MainWindow.appData, "blocked.json");
}