forked from yck1509/ConfuserEx
-
-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
651 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Confuser.Renamer { | ||
public class MessageDeobfuscator { | ||
static readonly Regex MapSymbolMatcher = new Regex("_[a-zA-Z0-9]+"); | ||
static readonly Regex PasswordSymbolMatcher = new Regex("[a-zA-Z0-9_$]{23,}"); | ||
|
||
readonly Dictionary<string, string> _symbolMap; | ||
readonly ReversibleRenamer _renamer; | ||
|
||
public static MessageDeobfuscator Load(string symbolMapFileName) { | ||
if (symbolMapFileName is null) | ||
throw new ArgumentNullException(nameof(symbolMapFileName)); | ||
|
||
var symbolMap = new Dictionary<string, string>(); | ||
using (var reader = new StreamReader(File.OpenRead(symbolMapFileName))) { | ||
var line = reader.ReadLine(); | ||
while (line != null) { | ||
int tabIndex = line.IndexOf('\t'); | ||
if (tabIndex == -1) | ||
throw new FileFormatException(); | ||
symbolMap.Add(line.Substring(0, tabIndex), line.Substring(tabIndex + 1)); | ||
line = reader.ReadLine(); | ||
} | ||
} | ||
|
||
return new MessageDeobfuscator(symbolMap); | ||
} | ||
|
||
public MessageDeobfuscator(Dictionary<string, string> map) => _symbolMap = map ?? throw new ArgumentNullException(nameof(map)); | ||
|
||
public MessageDeobfuscator(string password) => _renamer = new ReversibleRenamer(password); | ||
|
||
public string Deobfuscate(string obfuscatedMessage) { | ||
if (_symbolMap != null) { | ||
return MapSymbolMatcher.Replace(obfuscatedMessage, DecodeSymbolMap); | ||
} | ||
|
||
return PasswordSymbolMatcher.Replace(obfuscatedMessage, DecodeSymbolPassword); | ||
} | ||
|
||
string DecodeSymbolMap(Match match) { | ||
var symbol = match.Value; | ||
if (_symbolMap.TryGetValue(symbol, out string result)) | ||
return NameService.ExtractShortName(result, false); | ||
return NameService.ExtractShortName(symbol, false); | ||
} | ||
|
||
string DecodeSymbolPassword(Match match) { | ||
var sym = match.Value; | ||
try { | ||
return NameService.ExtractShortName(_renamer.Decrypt(sym), false); | ||
} | ||
catch { | ||
return sym; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.