Ignore a previous symbol mapping when names are randomised
Reusing the previous build's mapping returns every pre-existing symbol to its old name, which silently undoes the randomisation while every build-side check still passes. Deleting the mapping file before each build worked but left the guarantee resting on the caller.pull/36/head
parent
dcf38b3f0f
commit
72397812cd
|
|
@ -45,12 +45,12 @@ namespace Obfuz.ObfusPasses.SymbolObfus.NameMakers
|
|||
_wordSet = wordSet;
|
||||
_nextIndex = 0;
|
||||
_random = seed != 0 ? new System.Random(seed) : null;
|
||||
int space = 1;
|
||||
long space = 1;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
space *= wordSet.Count;
|
||||
}
|
||||
_nameSpace = space;
|
||||
_nameSpace = (int)System.Math.Min(space, int.MaxValue);
|
||||
}
|
||||
|
||||
protected override void BuildNewName(StringBuilder nameBuilder, string originalName, string lastName)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
@ -120,16 +120,29 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
|||
private readonly Dictionary<VirtualMethodGroup, RenameRecord> _virtualMethodGroups = new Dictionary<VirtualMethodGroup, RenameRecord>();
|
||||
|
||||
|
||||
private readonly bool _reusePreviousNames;
|
||||
|
||||
public RenameRecordMap(string mappingFile, bool debug, bool keepUnknownSymbolInSymbolMappingFile)
|
||||
: this(mappingFile, debug, keepUnknownSymbolInSymbolMappingFile, true)
|
||||
{
|
||||
}
|
||||
|
||||
public RenameRecordMap(string mappingFile, bool debug, bool keepUnknownSymbolInSymbolMappingFile, bool reusePreviousNames)
|
||||
{
|
||||
_mappingFile = mappingFile;
|
||||
_debug = debug;
|
||||
_keepUnknownSymbolInSymbolMappingFile = keepUnknownSymbolInSymbolMappingFile;
|
||||
_reusePreviousNames = reusePreviousNames;
|
||||
}
|
||||
|
||||
public void Init(List<ModuleDef> assemblies, INameMaker nameMaker)
|
||||
{
|
||||
LoadXmlMappingFile(_mappingFile);
|
||||
// With a randomised name seed, reusing the previous build's mapping would hand every
|
||||
// pre-existing symbol its old name back and silently undo the randomisation.
|
||||
if (_reusePreviousNames)
|
||||
{
|
||||
LoadXmlMappingFile(_mappingFile);
|
||||
}
|
||||
foreach (ModuleDef mod in assemblies)
|
||||
{
|
||||
string name = mod.Assembly.Name;
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
|||
_useConsistentNamespaceObfuscation = settings.useConsistentNamespaceObfuscation;
|
||||
_mappingXmlPath = settings.symbolMappingFile;
|
||||
_obfuscationRuleFiles = settings.ruleFiles.ToList();
|
||||
_renameRecordMap = new RenameRecordMap(settings.symbolMappingFile, settings.debug, settings.keepUnknownSymbolInSymbolMappingFile);
|
||||
_renameRecordMap = new RenameRecordMap(settings.symbolMappingFile, settings.debug, settings.keepUnknownSymbolInSymbolMappingFile, settings.nameRandomSeed == 0);
|
||||
_virtualMethodGroupCalculator = new VirtualMethodGroupCalculator();
|
||||
_nameMaker = settings.debug ? NameMakerFactory.CreateDebugNameMaker() : NameMakerFactory.CreateNameMakerBaseASCIICharSet(settings.obfuscatedNamePrefix, settings.nameRandomSeed);
|
||||
_customPolicyTypes = settings.customRenamePolicyTypes;
|
||||
|
|
|
|||
Loading…
Reference in New Issue