2024-06-22 12:12:18 -04:00
using CliFx ;
using CliFx.Attributes ;
using CliFx.Infrastructure ;
2024-12-31 13:46:44 -05:00
using ReCodeItLib.Utils ;
using ReCodeItLib.ReMapper ;
2024-06-22 12:12:18 -04:00
2024-12-22 07:04:20 -05:00
namespace ReCodeItCLI.Commands ;
2024-06-22 12:12:18 -04:00
[Command("ReMap", Description = "Generates a re-mapped dll provided a mapping file and de-obfuscated dll")]
2024-06-22 12:39:10 -04:00
public class ReMap : ICommand
2024-06-22 12:12:18 -04:00
{
private ReCodeItRemapper _remapper { get ; set ; } = new ( ) ;
[CommandParameter(0, IsRequired = true, Description = "The absolute path to your mapping.json file, supports .json and .jsonc")]
2024-12-30 23:50:31 -05:00
public required string MappingJsonPath { get ; init ; }
2024-06-22 12:12:18 -04:00
[CommandParameter(1, IsRequired = true, Description = "The absolute path to your de-obfuscated dll, containing all references that it needs to resolve.")]
2024-12-30 23:50:31 -05:00
public required string AssemblyPath { get ; init ; }
2024-06-22 12:12:18 -04:00
[CommandParameter(2, IsRequired = true, Description = "If true, the re-mapper will publicize all types, methods, and properties")]
public bool Publicize { get ; init ; }
[CommandParameter(3, IsRequired = false, Description = "If true, the re-mapper will rename all changed types associated variable names to be the same as the declaring type")]
public bool? ReName { get ; init ; }
public ValueTask ExecuteAsync ( IConsole console )
{
2024-11-05 16:19:38 -05:00
DataProvider . IsCli = true ;
2024-06-22 14:40:04 -04:00
DataProvider . LoadAppSettings ( ) ;
2024-07-03 07:03:14 -04:00
DataProvider . Settings . Remapper . MappingPath = MappingJsonPath ;
2024-06-22 12:12:18 -04:00
var remapperSettings = DataProvider . Settings . Remapper . MappingSettings ;
remapperSettings . RenameFields = ReName ? ? false ;
remapperSettings . RenameProperties = ReName ? ? false ;
remapperSettings . Publicize = Publicize ;
var remaps = DataProvider . LoadMappingFile ( MappingJsonPath ) ;
2024-12-30 23:50:31 -05:00
var outPath = Path . GetDirectoryName ( AssemblyPath ) ;
if ( outPath is null )
{
throw new DirectoryNotFoundException ( "OutPath could not be resolved." ) ;
}
2024-06-28 17:13:47 -04:00
2024-12-30 23:50:31 -05:00
_remapper . InitializeRemap ( remaps , AssemblyPath , outPath ) ;
2024-06-22 12:12:18 -04:00
2024-06-26 14:45:54 -04:00
// Wait for log termination
Logger . Terminate ( ) ;
while ( Logger . IsRunning ( ) ) { }
2024-06-22 12:12:18 -04:00
return default ;
}
}