mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-12 22:50:45 -05:00
Remove automapper
This commit is contained in:
parent
1505b01bba
commit
0e663099d1
@ -1,4 +1,3 @@
|
|||||||
using ReCodeIt.AutoMapper;
|
|
||||||
using ReCodeIt.Models;
|
using ReCodeIt.Models;
|
||||||
using ReCodeIt.ReMapper;
|
using ReCodeIt.ReMapper;
|
||||||
using ReCodeIt.Utils;
|
using ReCodeIt.Utils;
|
||||||
@ -9,8 +8,6 @@ namespace ReCodeIt.GUI;
|
|||||||
public partial class ReCodeItForm : Form
|
public partial class ReCodeItForm : Form
|
||||||
{
|
{
|
||||||
private static ReCodeItRemapper Remapper { get; set; } = new();
|
private static ReCodeItRemapper Remapper { get; set; } = new();
|
||||||
private static ReCodeItAutoMapper AutoMapper { get; set; } = new();
|
|
||||||
|
|
||||||
private static Settings AppSettings => DataProvider.Settings;
|
private static Settings AppSettings => DataProvider.Settings;
|
||||||
|
|
||||||
private bool _isSearched = false;
|
private bool _isSearched = false;
|
||||||
@ -487,12 +484,7 @@ public partial class ReCodeItForm : Form
|
|||||||
RemapperOutputDirectoryPath.Text = result;
|
RemapperOutputDirectoryPath.Text = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RunAutoMapButton_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
AutoMapper.InitializeAutoMapping();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion MAIN_BUTTONS
|
#endregion MAIN_BUTTONS
|
||||||
|
|
||||||
#region LISTBOX_BUTTONS
|
#region LISTBOX_BUTTONS
|
||||||
@ -717,11 +709,8 @@ public partial class ReCodeItForm : Form
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(DataProvider.Settings.AutoMapper.AssemblyPath))
|
if (string.IsNullOrEmpty(DataProvider.Settings.AutoMapper.AssemblyPath))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Please go to the settings tab and load an assembly and select and output location", "Assembly not loaded");
|
MessageBox.Show("Feature has been removed from this build.", "Feature Removed");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoMapper.InitializeAutoMapping();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion LISTBOX_BUTTONS
|
#endregion LISTBOX_BUTTONS
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
using dnlib.DotNet;
|
|
||||||
|
|
||||||
namespace ReCodeIt.AutoMapper;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a match of a field name to obfuscated class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type"></param>
|
|
||||||
/// <param name="name"></param>
|
|
||||||
/// <param name="isInterface"></param>
|
|
||||||
/// <param name="isStruct"></param>
|
|
||||||
public sealed class MappingPair(
|
|
||||||
TypeDef type,
|
|
||||||
string name,
|
|
||||||
bool isInterface,
|
|
||||||
bool isStruct,
|
|
||||||
bool isPublic)
|
|
||||||
{
|
|
||||||
public TypeDef OriginalTypeDefinition { get; private set; } = type;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The type reference we want to change
|
|
||||||
/// </summary>
|
|
||||||
public TypeDef NewTypeRef { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Is this field an interface?
|
|
||||||
/// </summary>
|
|
||||||
public bool IsInterface { get; set; } = isInterface;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Is this type a struct?
|
|
||||||
/// </summary>
|
|
||||||
public bool IsStruct { get; set; } = isStruct;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Has this type been renamed? Use for checking for failures at the end
|
|
||||||
/// </summary>
|
|
||||||
public bool HasBeenRenamed { get; set; } = false;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Did this match come from a method?
|
|
||||||
/// </summary>
|
|
||||||
public AutoMappingResult AutoMappingResult { get; set; } = AutoMappingResult.None;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is the name we want to change the assembly class to
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; set; } = name;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Original name of the property or field type
|
|
||||||
/// </summary>
|
|
||||||
public string OriginalPropOrFieldName { get; } = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum AutoMappingResult
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Match_From_Field,
|
|
||||||
Match_From_Property,
|
|
||||||
Match_From_Method,
|
|
||||||
Fail_From_Already_Contained_Name,
|
|
||||||
Fail_From_New_Type_Ref_Null,
|
|
||||||
}
|
|
@ -1,532 +0,0 @@
|
|||||||
using dnlib.DotNet;
|
|
||||||
using ReCodeIt.Models;
|
|
||||||
using ReCodeIt.ReMapper;
|
|
||||||
using ReCodeIt.Utils;
|
|
||||||
|
|
||||||
namespace ReCodeIt.AutoMapper;
|
|
||||||
|
|
||||||
public class ReCodeItAutoMapper
|
|
||||||
{
|
|
||||||
private ModuleDefMD Module { get; set; }
|
|
||||||
private List<MappingPair> MappingPairs { get; set; } = [];
|
|
||||||
|
|
||||||
private List<string> CompilerGeneratedClasses = [];
|
|
||||||
|
|
||||||
private List<TypeDef> AllTypes { get; set; } = [];
|
|
||||||
|
|
||||||
private List<string> AlreadyChangedNames { get; set; } = [];
|
|
||||||
|
|
||||||
private static AutoMapperSettings Settings => DataProvider.Settings.AutoMapper;
|
|
||||||
|
|
||||||
private static bool Error { get; set; } = false;
|
|
||||||
private int FailureCount { get; set; } = 0;
|
|
||||||
|
|
||||||
private int TotalFieldRenameCount { get; set; } = 0;
|
|
||||||
private int TotalPropertyRenameCount { get; set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Start the automapping process
|
|
||||||
/// </summary>
|
|
||||||
public void InitializeAutoMapping()
|
|
||||||
{
|
|
||||||
Logger.ClearLog();
|
|
||||||
Logger.Log($"Starting Auto Mapping...");
|
|
||||||
|
|
||||||
// Clear any previous pairs
|
|
||||||
MappingPairs = [];
|
|
||||||
CompilerGeneratedClasses = [];
|
|
||||||
AllTypes = [];
|
|
||||||
AlreadyChangedNames = [];
|
|
||||||
|
|
||||||
Module = DataProvider.LoadModule(Settings.AssemblyPath);
|
|
||||||
|
|
||||||
Error = false;
|
|
||||||
FailureCount = 0;
|
|
||||||
TotalFieldRenameCount = 0;
|
|
||||||
TotalPropertyRenameCount = 0;
|
|
||||||
|
|
||||||
var types = Module.GetTypes();
|
|
||||||
AllTypes.AddRange(types);
|
|
||||||
|
|
||||||
FindCompilerGeneratedObjects(types);
|
|
||||||
|
|
||||||
Logger.Log($"Found {AllTypes.Count - CompilerGeneratedClasses.Count} potential remappable types");
|
|
||||||
Logger.Log($"Found {CompilerGeneratedClasses.Count} compiler generated objects");
|
|
||||||
|
|
||||||
foreach (var type in types)
|
|
||||||
{
|
|
||||||
// We dont want to do anything with compiler generated objects
|
|
||||||
if (CompilerGeneratedClasses.Contains(type.Name))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
MappingPairs.AddRange(FilterFieldNames(type));
|
|
||||||
MappingPairs.AddRange(FilterPropertyNames(type));
|
|
||||||
|
|
||||||
if (Settings.SearchMethods)
|
|
||||||
{
|
|
||||||
MappingPairs.AddRange(GatherFromMethods(type));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PrimaryTypeNameFilter();
|
|
||||||
SanitizeProposedNames();
|
|
||||||
StartRenameProcess();
|
|
||||||
|
|
||||||
WriteChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Finds any compiler generated code so we can ignore it, its mostly LINQ garbage
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="types"></param>
|
|
||||||
private void FindCompilerGeneratedObjects(IEnumerable<TypeDef> types)
|
|
||||||
{
|
|
||||||
foreach (var typeDefinition in types)
|
|
||||||
{
|
|
||||||
if (typeDefinition.IsClass || typeDefinition.IsInterface || typeDefinition.IsValueType) // Check for class or struct
|
|
||||||
{
|
|
||||||
if (typeDefinition.HasCustomAttributes &&
|
|
||||||
typeDefinition.CustomAttributes.Any(attr => attr.AttributeType.FullName == "System.Runtime.CompilerServices.CompilerGeneratedAttribute"))
|
|
||||||
{
|
|
||||||
string typeName = typeDefinition.Name;
|
|
||||||
CompilerGeneratedClasses.Add(typeName);
|
|
||||||
//Logger.Log($"Compiler Generated object found: {typeName}", ConsoleColor.Yellow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeDefinition.NestedTypes.Count > 0)
|
|
||||||
{
|
|
||||||
FindCompilerGeneratedObjects(typeDefinition.NestedTypes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region METHODS
|
|
||||||
|
|
||||||
private List<MappingPair> GatherFromMethods(TypeDef type)
|
|
||||||
{
|
|
||||||
var methodsWithTypes = new List<MappingPair>();
|
|
||||||
|
|
||||||
// Handle nested types recursively
|
|
||||||
foreach (var nestedType in type.NestedTypes)
|
|
||||||
{
|
|
||||||
methodsWithTypes.AddRange(GatherFromMethods(nestedType));
|
|
||||||
}
|
|
||||||
|
|
||||||
var methods = type.Methods
|
|
||||||
// We only want methods with parameters
|
|
||||||
.Where(m => m.HasParams())
|
|
||||||
|
|
||||||
// Only want parameter names of a certain length
|
|
||||||
.Where(m => m.Parameters.Any(p => p.Name.Length > Settings.MinLengthToMatch));
|
|
||||||
|
|
||||||
// Now go over over all filterd methods manually, because fuck this with linq
|
|
||||||
foreach (var method in methods)
|
|
||||||
{
|
|
||||||
// Now over all parameters in the method
|
|
||||||
foreach (var parm in method.Parameters)
|
|
||||||
{
|
|
||||||
// We dont want blacklisted items
|
|
||||||
if (Settings.MethodParamaterBlackList.Contains(parm.Name)
|
|
||||||
|| Settings.TypesToIgnore.Contains(parm.Name))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Logger.Log($"Method Data Found");
|
|
||||||
//Logger.Log($"Parameter count: {method.Parameters.Count}");
|
|
||||||
//Logger.Log($"Paremeter Names: {string.Join(", ", parmNames)}");
|
|
||||||
//Logger.Log($"Paremeter Types: {string.Join(", ", parmTypes)}\n");
|
|
||||||
|
|
||||||
if (parm.Type.TryGetTypeDef() is null) continue;
|
|
||||||
|
|
||||||
var mapPair = new MappingPair(
|
|
||||||
parm.Type.TryGetTypeDef(),
|
|
||||||
parm.Name,
|
|
||||||
parm.Type.TryGetTypeDef().IsInterface,
|
|
||||||
parm.Type.TryGetTypeDef().Name.Contains("Struct"),
|
|
||||||
true);
|
|
||||||
|
|
||||||
mapPair.AutoMappingResult = AutoMappingResult.Match_From_Method;
|
|
||||||
|
|
||||||
methodsWithTypes.Add(mapPair);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return methodsWithTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion METHODS
|
|
||||||
|
|
||||||
#region FIELDS_PROPERTIES
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Pair field declaring types with their names
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private List<MappingPair> FilterFieldNames(TypeDef type)
|
|
||||||
{
|
|
||||||
var fieldsWithTypes = new List<MappingPair>();
|
|
||||||
|
|
||||||
// Handle nested types recursively
|
|
||||||
foreach (var nestedType in type.NestedTypes)
|
|
||||||
{
|
|
||||||
fieldsWithTypes.AddRange(FilterFieldNames(nestedType));
|
|
||||||
}
|
|
||||||
|
|
||||||
var fields = type.Fields
|
|
||||||
// we dont want names shorter than 4
|
|
||||||
.Where(f => f.Name.Length > 3)
|
|
||||||
|
|
||||||
// Skip value types
|
|
||||||
.Where(f => !f.FieldType.IsValueType)
|
|
||||||
|
|
||||||
// TODO: Renaming arrays is strange, come back to this later
|
|
||||||
.Where(p => !p.FieldType.IsArray)
|
|
||||||
|
|
||||||
// We dont want fields in the system type ignore list
|
|
||||||
.Where(f => !Settings.TypesToIgnore.Contains(f.Name.TrimAfterSpecialChar()));
|
|
||||||
|
|
||||||
// Include fields from the current type
|
|
||||||
foreach (var field in fields)
|
|
||||||
{
|
|
||||||
//Logger.Log($"Collecting Field: OriginalTypeRef: {field.FieldType.Name.TrimAfterSpecialChar()} Field Name: {field.Name}");
|
|
||||||
|
|
||||||
var typeDef = field.FieldType.TryGetTypeDef();
|
|
||||||
|
|
||||||
// Dont rename things we cant resolve
|
|
||||||
if (typeDef is null) { continue; }
|
|
||||||
|
|
||||||
var pair = new MappingPair(
|
|
||||||
typeDef,
|
|
||||||
field.Name,
|
|
||||||
typeDef.Name.Contains("Interface"),
|
|
||||||
typeDef.Name.Contains("Struct"),
|
|
||||||
field.IsPublic);
|
|
||||||
|
|
||||||
pair.AutoMappingResult = AutoMappingResult.Match_From_Field;
|
|
||||||
|
|
||||||
fieldsWithTypes.Add(pair);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fieldsWithTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Pair field declaring types with their names
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private IEnumerable<MappingPair> FilterPropertyNames(TypeDef type)
|
|
||||||
{
|
|
||||||
var propertiesWithTypes = new List<MappingPair>();
|
|
||||||
|
|
||||||
// Handle nested types recursively
|
|
||||||
foreach (var nestedType in type.NestedTypes)
|
|
||||||
{
|
|
||||||
propertiesWithTypes.AddRange(FilterPropertyNames(nestedType));
|
|
||||||
}
|
|
||||||
|
|
||||||
var properties = type.Properties
|
|
||||||
// we dont want names shorter than 4
|
|
||||||
.Where(p => p.Name.Length > 3)
|
|
||||||
|
|
||||||
// Skip value types
|
|
||||||
.Where(p => !p.PropertySig.RetType.GetIsValueType())
|
|
||||||
|
|
||||||
// TODO: Renaming arrays is strange, come back to this later
|
|
||||||
.Where(p => !p.PropertySig.RetType.IsArray)
|
|
||||||
|
|
||||||
// We dont want fields in the global ignore list
|
|
||||||
.Where(p => !Settings.TypesToIgnore.Contains(p.Name.TrimAfterSpecialChar()));
|
|
||||||
|
|
||||||
// Include fields from the current type
|
|
||||||
foreach (var property in properties)
|
|
||||||
{
|
|
||||||
//Logger.Log($"Collecting Property: OriginalTypeRef: {property.PropertyType.Name.TrimAfterSpecialChar()} Field Name: {property.Name}");
|
|
||||||
|
|
||||||
var typeDef = property.PropertySig.RetType.TryGetTypeDef();
|
|
||||||
|
|
||||||
// Dont rename things we cant resolve
|
|
||||||
if (typeDef is null) { continue; }
|
|
||||||
|
|
||||||
var mapPair = new MappingPair(
|
|
||||||
typeDef,
|
|
||||||
property.Name,
|
|
||||||
typeDef.Name.Contains("Interface"),
|
|
||||||
typeDef.Name.Contains("Struct"),
|
|
||||||
true);
|
|
||||||
|
|
||||||
mapPair.AutoMappingResult = AutoMappingResult.Match_From_Property;
|
|
||||||
|
|
||||||
propertiesWithTypes.Add(mapPair);
|
|
||||||
}
|
|
||||||
|
|
||||||
return propertiesWithTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion FIELDS_PROPERTIES
|
|
||||||
|
|
||||||
#region FILTER
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This giant linq statement handles all of the filtering once the initial gathering of fields
|
|
||||||
/// and properties is complete
|
|
||||||
/// </summary>
|
|
||||||
private void PrimaryTypeNameFilter()
|
|
||||||
{
|
|
||||||
// Filter types to the ones we're looking for
|
|
||||||
var mappingPairs = MappingPairs
|
|
||||||
// Filter based on length, short lengths dont make good class names
|
|
||||||
.Where(pair => pair.Name.Length >= Settings.MinLengthToMatch)
|
|
||||||
|
|
||||||
// Filter out anything that doesnt start with our specified tokens (Where
|
|
||||||
// pair.OriginalTypeRef.Name is the property OriginalTypeRef name `Class1202` and token
|
|
||||||
// is start identifer we are looking for `GClass`
|
|
||||||
.Where(pair => Settings.TokensToMatch
|
|
||||||
.Any(token => pair.OriginalTypeDefinition.Name.StartsWith(token)))
|
|
||||||
|
|
||||||
// Filter out anything that has the same name as the type, we cant remap those
|
|
||||||
.Where(pair => !Settings.TokensToMatch
|
|
||||||
.Any(token => pair.Name.ToLower().StartsWith(token.ToLower())))
|
|
||||||
|
|
||||||
// Filter based on direct name blacklist (Where pair.Name is the property name and token
|
|
||||||
// is blacklisted item `Columns`
|
|
||||||
.Where(pair => !Settings.PropertyFieldBlackList
|
|
||||||
.Any(token => pair.Name.ToLower().StartsWith(token.ToLower())))
|
|
||||||
|
|
||||||
// Filter out backing fields
|
|
||||||
/// This is slow, but oh well
|
|
||||||
.Where(pair => !pair.Name.ToCharArray().Contains('<')).ToList();
|
|
||||||
|
|
||||||
MappingPairs = mappingPairs;
|
|
||||||
SecondaryTypeNameFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is where we filter down based on more specific parameters
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mappingPairs"></param>
|
|
||||||
private void SecondaryTypeNameFilter()
|
|
||||||
{
|
|
||||||
// Filter property/field names by required number of matches
|
|
||||||
MappingPairs = MappingPairs
|
|
||||||
.GroupBy(pair => pair.OriginalPropOrFieldName.TrimAfterSpecialChar())
|
|
||||||
.Where(group => group.Count() > Settings.RequiredMatches)
|
|
||||||
.SelectMany(group => group)
|
|
||||||
.ToList()
|
|
||||||
// We dont want names that already exist to be considered
|
|
||||||
.Where(pair => AllTypes
|
|
||||||
.Any(token => !pair.OriginalTypeDefinition.FullName.Contains(token.FullName))).ToList();
|
|
||||||
|
|
||||||
FinalGroupAndSelect();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is where we make sure everything is original
|
|
||||||
/// </summary>
|
|
||||||
private void FinalGroupAndSelect()
|
|
||||||
{
|
|
||||||
MappingPairs = MappingPairs
|
|
||||||
// We only want types once, so make it unique
|
|
||||||
.GroupBy(pair => pair.OriginalTypeDefinition.FullName)
|
|
||||||
.Select(group => group.First())
|
|
||||||
.GroupBy(pair => pair.Name)
|
|
||||||
.Select(group => group.First()).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion FILTER
|
|
||||||
|
|
||||||
#region OUTPUT
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sanitizes and prepares mapping pairs for remapping once filtering is complete.
|
|
||||||
/// </summary>
|
|
||||||
private void SanitizeProposedNames()
|
|
||||||
{
|
|
||||||
foreach (var pair in MappingPairs)
|
|
||||||
{
|
|
||||||
char first = pair.Name.ToCharArray().ElementAt(0);
|
|
||||||
|
|
||||||
if (first.Equals('_'))
|
|
||||||
{
|
|
||||||
pair.Name = string.Concat("", pair.Name.AsSpan(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Re-run incase prefix removed
|
|
||||||
first = pair.Name.ToCharArray().ElementAt(0);
|
|
||||||
|
|
||||||
if (char.IsLower(first))
|
|
||||||
{
|
|
||||||
pair.Name = string.Concat(char.ToUpper(first).ToString(), pair.Name.AsSpan(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pair.IsInterface)
|
|
||||||
{
|
|
||||||
pair.Name = string.Concat("I", pair.Name.AsSpan(0));
|
|
||||||
pair.Name = pair.Name.Replace("Class", "");
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
// Try and remove any trailing 's' that exist
|
|
||||||
if (pair.WasCollection)
|
|
||||||
{
|
|
||||||
if (pair.Name.ToLower().EndsWith('s'))
|
|
||||||
{
|
|
||||||
pair.Name = pair.Name.Substring(0, pair.Name.Length - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (pair.IsInterface)
|
|
||||||
{
|
|
||||||
// Replace class if it exists
|
|
||||||
pair.Name = pair.Name.Replace("Class", "");
|
|
||||||
}
|
|
||||||
else if (pair.IsStruct)
|
|
||||||
{
|
|
||||||
pair.Name = string.Concat(pair.Name, "Struct");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pair.Name = string.Concat(pair.Name, "Class");
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Log($"------------------------------------------------------------------------");
|
|
||||||
Logger.Log($"Original Name: {pair.OriginalTypeDefinition.FullName} : Sanitized Name: {pair.Name}");
|
|
||||||
Logger.Log($"Matched From Name: {pair.OriginalPropOrFieldName}");
|
|
||||||
Logger.Log($"IsInterface: {pair.IsInterface}");
|
|
||||||
Logger.Log($"IsStruct: {pair.IsStruct}");
|
|
||||||
Logger.Log($"Is match from: {pair.AutoMappingResult}");
|
|
||||||
Logger.Log($"------------------------------------------------------------------------");
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Log($"Automatically remapped {MappingPairs.Count()} objects");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Start renaming assembly definitions
|
|
||||||
/// </summary>
|
|
||||||
private void StartRenameProcess()
|
|
||||||
{
|
|
||||||
// Gather up any matches we have
|
|
||||||
foreach (var type in Module.GetTypes().ToArray())
|
|
||||||
{
|
|
||||||
foreach (var pair in MappingPairs.ToArray())
|
|
||||||
{
|
|
||||||
GatherMatchedTypeRefs(pair, type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rename Types to matched types
|
|
||||||
foreach (var pair in MappingPairs)
|
|
||||||
{
|
|
||||||
if (pair.NewTypeRef != null && !AlreadyChangedNames.Contains(pair.Name))
|
|
||||||
{
|
|
||||||
Logger.Log($"------------------------------------------------------------------------", ConsoleColor.Green);
|
|
||||||
Logger.Log($"Renaming: {pair.OriginalTypeDefinition.Name} to {pair.Name}", ConsoleColor.Green);
|
|
||||||
Logger.Log($"Is match from method: {pair.AutoMappingResult}", ConsoleColor.Green);
|
|
||||||
|
|
||||||
var fieldCount = RenameHelper.RenameAllFields(
|
|
||||||
pair.OriginalTypeDefinition.Name,
|
|
||||||
pair.Name,
|
|
||||||
Module.GetTypes());
|
|
||||||
|
|
||||||
var propCount = RenameHelper.RenameAllProperties(
|
|
||||||
pair.OriginalTypeDefinition.Name,
|
|
||||||
pair.Name,
|
|
||||||
Module.GetTypes());
|
|
||||||
|
|
||||||
Logger.Log($"Renamed: {fieldCount} fields", ConsoleColor.Green);
|
|
||||||
Logger.Log($"Renamed: {propCount} properties", ConsoleColor.Green);
|
|
||||||
Logger.Log($"------------------------------------------------------------------------", ConsoleColor.Green);
|
|
||||||
|
|
||||||
AlreadyChangedNames.Add(pair.Name);
|
|
||||||
pair.NewTypeRef.Name = pair.Name;
|
|
||||||
pair.HasBeenRenamed = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pair.HasBeenRenamed) { continue; }
|
|
||||||
|
|
||||||
// Set some error codes
|
|
||||||
|
|
||||||
if (AlreadyChangedNames.Contains(pair.Name))
|
|
||||||
{
|
|
||||||
pair.AutoMappingResult = AutoMappingResult.Fail_From_Already_Contained_Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pair.NewTypeRef == null)
|
|
||||||
{
|
|
||||||
pair.AutoMappingResult = AutoMappingResult.Fail_From_New_Type_Ref_Null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do a final error check
|
|
||||||
foreach (var pair in MappingPairs)
|
|
||||||
{
|
|
||||||
if (!pair.HasBeenRenamed)
|
|
||||||
{
|
|
||||||
Logger.Log($"------------------------------------------------------------------------", ConsoleColor.Red);
|
|
||||||
Logger.Log($"Renaming: {pair.OriginalTypeDefinition.Name} to {pair.Name} has failed", ConsoleColor.Red);
|
|
||||||
Logger.Log($"Result Code: {pair.AutoMappingResult}", ConsoleColor.Red);
|
|
||||||
Logger.Log($"IsInterface: {pair.IsInterface}", ConsoleColor.Red);
|
|
||||||
Logger.Log($"IsStruct: {pair.IsStruct}", ConsoleColor.Red);
|
|
||||||
Logger.Log($"------------------------------------------------------------------------", ConsoleColor.Red);
|
|
||||||
|
|
||||||
FailureCount++;
|
|
||||||
Error = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Recursively handle all renaming on nested types on a given type
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pair"></param>
|
|
||||||
/// <param name="type"></param>
|
|
||||||
private void GatherMatchedTypeRefs(MappingPair pair, TypeDef type)
|
|
||||||
{
|
|
||||||
// Handle nested types recursively
|
|
||||||
foreach (var nestedType in type.NestedTypes.ToArray())
|
|
||||||
{
|
|
||||||
GatherMatchedTypeRefs(pair, nestedType);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == pair.OriginalTypeDefinition)
|
|
||||||
{
|
|
||||||
pair.NewTypeRef = type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void WriteChanges()
|
|
||||||
{
|
|
||||||
var path = Path.Combine(Settings.OutputPath, Module.Assembly.Name + "-auto_mapped.dll");
|
|
||||||
|
|
||||||
Module.Write(path);
|
|
||||||
|
|
||||||
var fieldCountMatchResult = MappingPairs
|
|
||||||
.Count(x => x.AutoMappingResult == AutoMappingResult.Match_From_Field);
|
|
||||||
|
|
||||||
var propertyCountMatchResult = MappingPairs
|
|
||||||
.Count(x => x.AutoMappingResult == AutoMappingResult.Match_From_Property);
|
|
||||||
|
|
||||||
var methodCountMatchResult = MappingPairs
|
|
||||||
.Count(x => x.AutoMappingResult == AutoMappingResult.Match_From_Method);
|
|
||||||
|
|
||||||
Logger.Log($"-------------------------------RESULT-----------------------------------", ConsoleColor.Green);
|
|
||||||
Logger.Log($"Complete: Assembly written to `{path}`", ConsoleColor.Green);
|
|
||||||
Logger.Log($"Found {MappingPairs.Count()} automatic remaps", ConsoleColor.Green);
|
|
||||||
Logger.Log($"Found {fieldCountMatchResult} automatic remaps from fields", ConsoleColor.Green);
|
|
||||||
Logger.Log($"Found {propertyCountMatchResult} automatic remaps from properties", ConsoleColor.Green);
|
|
||||||
Logger.Log($"Found {methodCountMatchResult} automatic remaps from methods", ConsoleColor.Green);
|
|
||||||
Logger.Log($"Renamed {TotalFieldRenameCount} fields", ConsoleColor.Green);
|
|
||||||
Logger.Log($"Renamed {TotalPropertyRenameCount} properties", ConsoleColor.Green);
|
|
||||||
Logger.Log($"Failed to rename: {FailureCount} mapping pairs", (FailureCount == 0 ? ConsoleColor.Green : ConsoleColor.Red));
|
|
||||||
Logger.Log($"------------------------------------------------------------------------", ConsoleColor.Green);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion OUTPUT
|
|
||||||
}
|
|
@ -158,14 +158,14 @@ public class DumperClass
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="types">ICollection</param>
|
/// <param name="types">ICollection</param>
|
||||||
/// <param name="name">string</param>
|
/// <param name="name">string</param>
|
||||||
private void CheckNullOrMulti(ICollection types, string name = "")
|
private void CheckNullOrMulti(ICollection? types, string name = "")
|
||||||
{
|
{
|
||||||
if (types == null)
|
if (types == null)
|
||||||
{
|
{
|
||||||
Logger.Log($"{name} was null");
|
Logger.Log($"{name} was null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (types.Count > 1)
|
if (types?.Count > 1)
|
||||||
{
|
{
|
||||||
Logger.Log($"{name} count was more than 1");
|
Logger.Log($"{name} count was more than 1");
|
||||||
}
|
}
|
||||||
@ -186,24 +186,24 @@ public class DumperClass
|
|||||||
|
|
||||||
if (method == null || method.Body.Instructions.Count != 269)
|
if (method == null || method.Body.Instructions.Count != 269)
|
||||||
{
|
{
|
||||||
Logger.Log($"BackRequest Instructions count has changed from 269 to {method.Body.Instructions.Count}", ConsoleColor.Red);
|
Logger.Log($"BackRequest Instructions count has changed from 269 to {method?.Body.Instructions.Count}", ConsoleColor.Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
var startOfInstructions = 252;
|
var startOfInstructions = 252;
|
||||||
var liList = DumpyILHelper.GetBackRequestInstructions(method, _gameImporter);
|
var liList = DumpyILHelper.GetBackRequestInstructions(method!, _gameImporter);
|
||||||
var index = method.Body.Instructions[startOfInstructions];
|
var index = method?.Body.Instructions[startOfInstructions];
|
||||||
|
|
||||||
foreach (var li in liList)
|
foreach (var li in liList)
|
||||||
{
|
{
|
||||||
// something along these lines, this needs to be tested
|
// something along these lines, this needs to be tested
|
||||||
method.Body.Instructions.InsertBefore(index, li);
|
method?.Body.Instructions.InsertBefore(index!, li);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create instruction
|
// create instruction
|
||||||
var ins = Instruction.Create(OpCodes.Brfalse_S, method.Body.Instructions[startOfInstructions]);
|
var ins = Instruction.Create(OpCodes.Brfalse_S, method?.Body.Instructions[startOfInstructions]);
|
||||||
|
|
||||||
// replace instruction at 220 with this
|
// replace instruction at 220 with this
|
||||||
method.Body.Instructions[220] = ins;
|
method!.Body.Instructions[220] = ins;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -93,22 +93,18 @@ public class SearchParams
|
|||||||
|
|
||||||
#region LISTS
|
#region LISTS
|
||||||
|
|
||||||
public List<string> IncludeMethods { get; set; }
|
public List<string> IncludeMethods { get; init; } = [];
|
||||||
public List<string> ExcludeMethods { get; set; }
|
public List<string> ExcludeMethods { get; init; } = [];
|
||||||
public List<string> IncludeFields { get; set; }
|
public List<string> IncludeFields { get; init; } = [];
|
||||||
public List<string> ExcludeFields { get; set; }
|
public List<string> ExcludeFields { get; init; } = [];
|
||||||
public List<string> IncludeProperties { get; set; }
|
public List<string> IncludeProperties { get; init; } = [];
|
||||||
public List<string> ExcludeProperties { get; set; }
|
public List<string> ExcludeProperties { get; init; } = [];
|
||||||
public List<string> IncludeNestedTypes { get; set; }
|
public List<string> IncludeNestedTypes { get; init; } = [];
|
||||||
public List<string> ExcludeNestedTypes { get; set; }
|
public List<string> ExcludeNestedTypes { get; init; } = [];
|
||||||
public List<string> IncludeEvents { get; set; } = [];
|
public List<string> IncludeEvents { get; init; } = [];
|
||||||
public List<string> ExcludeEvents { get; set; } = [];
|
public List<string> ExcludeEvents { get; init; } = [];
|
||||||
|
|
||||||
#endregion LISTS
|
#endregion LISTS
|
||||||
|
|
||||||
public SearchParams()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class AdvancedSearchParams
|
internal class AdvancedSearchParams
|
||||||
|
@ -14,7 +14,7 @@ internal static class RenameHelper
|
|||||||
/// <param name="module"></param>
|
/// <param name="module"></param>
|
||||||
/// <param name="remap"></param>
|
/// <param name="remap"></param>
|
||||||
/// <param name="direct"></param>
|
/// <param name="direct"></param>
|
||||||
public static void RenameAll(IEnumerable<TypeDef> types, RemapModel remap, bool direct = false)
|
public static void RenameAll(IEnumerable<TypeDef> types, RemapModel remap)
|
||||||
{
|
{
|
||||||
// Rename all fields and properties first
|
// Rename all fields and properties first
|
||||||
if (DataProvider.Settings.Remapper.MappingSettings.RenameFields)
|
if (DataProvider.Settings.Remapper.MappingSettings.RenameFields)
|
||||||
@ -39,12 +39,27 @@ internal static class RenameHelper
|
|||||||
types);
|
types);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!direct)
|
RenameType(types, remap);
|
||||||
{
|
|
||||||
RenameType(types, remap);
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Log($"{remap.TypePrimeCandidate.Name.String} Renamed.", ConsoleColor.Green);
|
//Logger.Log($"{remap.TypePrimeCandidate.Name.String} Renamed.", ConsoleColor.Green);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<TypeDef> FixMethods(
|
||||||
|
IEnumerable<TypeDef> typesToCheck,
|
||||||
|
RemapModel remap)
|
||||||
|
{
|
||||||
|
foreach (var type in typesToCheck)
|
||||||
|
{
|
||||||
|
var methods = type.Methods
|
||||||
|
.Where(method => method.Name.StartsWith(remap.TypePrimeCandidate.Name.String));
|
||||||
|
|
||||||
|
if (methods.Any())
|
||||||
|
{
|
||||||
|
Logger.Log($"Found {methods.Count()} methods with mangled names", ConsoleColor.Red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return typesToCheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -58,8 +73,7 @@ internal static class RenameHelper
|
|||||||
|
|
||||||
string oldTypeName,
|
string oldTypeName,
|
||||||
string newTypeName,
|
string newTypeName,
|
||||||
IEnumerable<TypeDef> typesToCheck,
|
IEnumerable<TypeDef> typesToCheck)
|
||||||
int overAllCount = 0)
|
|
||||||
{
|
{
|
||||||
foreach (var type in typesToCheck)
|
foreach (var type in typesToCheck)
|
||||||
{
|
{
|
||||||
@ -86,7 +100,6 @@ internal static class RenameHelper
|
|||||||
UpdateAllTypeFieldMemberRefs(typesToCheck, field, oldName);
|
UpdateAllTypeFieldMemberRefs(typesToCheck, field, oldName);
|
||||||
|
|
||||||
fieldCount++;
|
fieldCount++;
|
||||||
overAllCount++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,12 +139,10 @@ internal static class RenameHelper
|
|||||||
/// <param name="oldTypeName"></param>
|
/// <param name="oldTypeName"></param>
|
||||||
/// <param name="newTypeName"></param>
|
/// <param name="newTypeName"></param>
|
||||||
/// <param name="typesToCheck"></param>
|
/// <param name="typesToCheck"></param>
|
||||||
/// <returns></returns>
|
public static void RenameAllProperties(
|
||||||
public static int RenameAllProperties(
|
|
||||||
string oldTypeName,
|
string oldTypeName,
|
||||||
string newTypeName,
|
string newTypeName,
|
||||||
IEnumerable<TypeDef> typesToCheck,
|
IEnumerable<TypeDef> typesToCheck)
|
||||||
int overAllCount = 0)
|
|
||||||
{
|
{
|
||||||
foreach (var type in typesToCheck)
|
foreach (var type in typesToCheck)
|
||||||
{
|
{
|
||||||
@ -153,22 +164,19 @@ internal static class RenameHelper
|
|||||||
property.Name = new UTF8String(newPropertyName);
|
property.Name = new UTF8String(newPropertyName);
|
||||||
|
|
||||||
propertyCount++;
|
propertyCount++;
|
||||||
overAllCount++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return overAllCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetNewFieldName(string NewName, int fieldCount = 0)
|
private static string GetNewFieldName(string NewName, int fieldCount = 0)
|
||||||
{
|
{
|
||||||
string newFieldCount = fieldCount > 0 ? $"_{fieldCount}" : string.Empty;
|
string newFieldCount = fieldCount > 0 ? $"_{fieldCount}" : string.Empty;
|
||||||
|
|
||||||
return $"{char.ToLower(NewName[0])}{NewName[1..]}{newFieldCount}";
|
return $"{char.ToLower(NewName[0])}{NewName[1..]}{newFieldCount}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetNewPropertyName(string newName, int propertyCount = 0)
|
private static string GetNewPropertyName(string newName, int propertyCount = 0)
|
||||||
{
|
{
|
||||||
return propertyCount > 0 ? $"{newName}_{propertyCount}" : newName;
|
return propertyCount > 0 ? $"{newName}_{propertyCount}" : newName;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
along with de4dot. If not, see <http://www.gnu.org/licenses/>.
|
along with de4dot. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Runtime.Remoting;
|
using System.Runtime.Remoting;
|
||||||
@ -51,13 +50,3 @@ namespace AssemblyServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
namespace AssemblyServer {
|
|
||||||
public static class Start {
|
|
||||||
public static int Main(string[] args) {
|
|
||||||
System.Console.WriteLine("Not supported");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user