Skip to content
This repository was archived by the owner on Jan 27, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Confuser.Core/API/APIStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void AddPredicate(IOpaquePredicateDescriptor predicate) {
public IDataStore GetStore(MethodDef method) {
for (int i = dataStores.Count - 1; i >= 0; i--) {
var list = dataStores[i];
for (int j = list.Count - 1; j >= 0; i--) {
for (int j = list.Count - 1; j >= 0; j--) {
if (list[j].IsUsable(method))
return list[j];
}
Expand Down
1 change: 1 addition & 0 deletions Confuser.Core/ConfuserEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static void RunInternal(ConfuserParameters parameters, CancellationToken token)
bool ok = false;
try {
var asmResolver = new AssemblyResolver();
asmResolver.FindExactMatch = true;
asmResolver.EnableTypeDefCache = true;
asmResolver.DefaultModuleContext = new ModuleContext(asmResolver);
context.Resolver = asmResolver;
Expand Down
64 changes: 62 additions & 2 deletions Confuser.Renamer/AnalyzePhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters
service.SetCanRename(type, false);
}

/*
* Can't rename Classes/Types that will be serialized
*/
if(type != null) {
if (type.IsSerializable) {
service.SetCanRename(type, false);
}

if (type.DeclaringType != null) {
if (type.DeclaringType.IsSerializable) {
service.SetCanRename(type, false);
}
}
}

if (parameters.GetParameter(context, type, "forceRen", false))
return;

Expand Down Expand Up @@ -200,9 +215,30 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters
else if (parameters.GetParameter(context, field, "forceRen", false))
return;

else if (field.DeclaringType.IsSerializable && !field.IsNotSerialized)
/*
* System.Xml.Serialization.XmlSerializer
*
* XmlSerializer by default serializes fields marked with [NonSerialized]
* This is a work-around that causes all fields in a class marked [Serializable]
* to _not_ be renamed, unless marked with [XmlIgnoreAttribute]
*
* If we have a way to detect which serializer method the code is going to use
* for the class, or if Microsoft makes XmlSerializer respond to [NonSerialized]
* we'll have a more accurate way to achieve this.
*/
else if (field.DeclaringType.IsSerializable) // && !field.IsNotSerialized)
service.SetCanRename(field, false);

else if (field.DeclaringType.IsSerializable && (field.CustomAttributes.IsDefined("XmlIgnore")
|| field.CustomAttributes.IsDefined("XmlIgnoreAttribute")
|| field.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnore")
|| field.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnoreAttribute")
|| field.CustomAttributes.IsDefined("T:System.Xml.Serialization.XmlIgnoreAttribute"))) // Can't seem to detect CustomAttribute
service.SetCanRename(field, true);
/*
* End of XmlSerializer work-around
*/

else if (field.IsLiteral && field.DeclaringType.IsEnum &&
!parameters.GetParameter(context, field, "renEnum", false))
service.SetCanRename(field, false);
Expand All @@ -219,7 +255,31 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters
else if (parameters.GetParameter(context, property, "forceRen", false))
return;

else if (property.DeclaringType.Implements("System.ComponentModel.INotifyPropertyChanged"))
/*
* System.Xml.Serialization.XmlSerializer
*
* XmlSerializer by default serializes fields marked with [NonSerialized]
* This is a work-around that causes all fields in a class marked [Serializable]
* to _not_ be renamed, unless marked with [XmlIgnoreAttribute]
*
* If we have a way to detect which serializer method the code is going to use
* for the class, or if Microsoft makes XmlSerializer respond to [NonSerialized]
* we'll have a more accurate way to achieve this.
*/
else if (property.DeclaringType.IsSerializable) // && !field.IsNotSerialized)
service.SetCanRename(property, false);

else if (property.DeclaringType.IsSerializable && (property.CustomAttributes.IsDefined("XmlIgnore")
|| property.CustomAttributes.IsDefined("XmlIgnoreAttribute")
|| property.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnore")
|| property.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnoreAttribute")
|| property.CustomAttributes.IsDefined("T:System.Xml.Serialization.XmlIgnoreAttribute"))) // Can't seem to detect CustomAttribute
service.SetCanRename(property, true);
/*
* End of XmlSerializer work-around
*/

else if (property.DeclaringType.Implements("System.ComponentModel.INotifyPropertyChanged"))
service.SetCanRename(property, false);

else if (property.DeclaringType.Name.String.Contains("AnonymousType"))
Expand Down
6 changes: 3 additions & 3 deletions Confuser.Renamer/Analyzers/CaliburnAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void AnalyzeBAMLElement(BAMLAnalyzer analyzer, BamlElement elem) {
else if (attr.Item1 != null)
attrName = attr.Item1.Name;

if (attrName == "Attach")
if (attrName == "Attach" || (attrName == "Value" && prop.Value.Contains("Action")))
AnalyzeMessageAttach(analyzer, attr, prop.Value);

if (attrName == "Name")
Expand All @@ -60,7 +60,7 @@ void AnalyzeMessageAttach(BAMLAnalyzer analyzer, Tuple<IDnlibDef, AttributeInfoR
if (attr.Item2 == null)
return;
var attrDeclType = analyzer.ResolveType(attr.Item2.OwnerTypeId);
if (attrDeclType.FullName != "Caliburn.Micro.Message")
if (attrDeclType.FullName != "Caliburn.Micro.Message" && attrDeclType.FullName != "System.Windows.Setter")
return;

foreach (var msg in value.Split(';')) {
Expand Down Expand Up @@ -113,4 +113,4 @@ public void PostRename(ConfuserContext context, INameService service, Protection
//
}
}
}
}
2 changes: 1 addition & 1 deletion Confuser.Renamer/Analyzers/WPFAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void AnalyzeMethod(ConfuserContext context, INameService service, MethodDef meth
if (match.Success)
operand = match.Groups[1].Value;
else if (operand.Contains("/"))
context.Logger.WarnFormat("Fail to extract XAML name from '{0}'.", instr.Operand);
context.Logger.WarnFormat("[WPF] Fail to extract XAML name from '{0}'.", instr.Operand);

var reference = new BAMLStringReference(instr);
operand = operand.TrimStart('/');
Expand Down
29 changes: 20 additions & 9 deletions Confuser.Renamer/BAML/BAMLAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,16 +503,27 @@ void ProcessConverter(PropertyWithConverterRecord rec, TypeDef type) {
if (declType == "System.Windows.ResourceDictionary") {
var src = rec.Value.ToUpperInvariant();
if (src.EndsWith(".BAML") || src.EndsWith(".XAML")) {
var match = WPFAnalyzer.UriPattern.Match(src);
if (match.Success)
src = match.Groups[1].Value;
else if (rec.Value.Contains("/"))
context.Logger.WarnFormat("Fail to extract XAML name from '{0}'.", rec.Value);

if (!src.Contains("//")) {
var rel = new Uri(new Uri(packScheme + "application:,,,/" + CurrentBAMLName), src);
src = rel.LocalPath;
// Relative address
if (src.StartsWith("../")) {
var oldSrc = src;
var fake_domain = "http://Confuser.Ex/";
var uri = new Uri(fake_domain + CurrentBAMLName + "/../" + src);
src = uri.ToString().Substring(fake_domain.Length);

context.Logger.InfoFormat("Convert [{0}] at [{1}] to [{2}].", oldSrc, CurrentBAMLName, src);
} else {
var match = WPFAnalyzer.UriPattern.Match(src);
if (match.Success)
src = match.Groups[1].Value;
else if (rec.Value.Contains("/"))
context.Logger.WarnFormat("[BAML] Fail to extract XAML name from '{0}'.", rec.Value);

if (!src.Contains("//")) {
var rel = new Uri(new Uri(packScheme + "application:,,,/" + CurrentBAMLName), src);
src = rel.LocalPath;
}
}

var reference = new BAMLPropertyReference(rec);
src = src.TrimStart('/');
var baml = src.Substring(0, src.Length - 5) + ".BAML";
Expand Down
12 changes: 7 additions & 5 deletions Confuser.Renamer/NameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ string MakeGenericName(string name, int? count) {
public string ObfuscateName(string name, RenameMode mode) {
string newName = null;
int? count;
name = ParseGenericName(name, out count);

var fullName = name;
name = ParseGenericName(name, out count);

if (string.IsNullOrEmpty(name))
return string.Empty;
Expand All @@ -221,8 +223,8 @@ public string ObfuscateName(string name, RenameMode mode) {
return MakeGenericName(newName, count);
}

if (nameMap1.ContainsKey(name))
return nameMap1[name];
if (nameMap1.ContainsKey(fullName))
return nameMap1[fullName];

byte[] hash = Utils.Xor(Utils.SHA1(Encoding.UTF8.GetBytes(name)), nameSeed);
for (int i = 0; i < 100; i++) {
Expand All @@ -233,8 +235,8 @@ public string ObfuscateName(string name, RenameMode mode) {
}

if ((mode & RenameMode.Decodable) != 0) {
nameMap2[newName] = name;
nameMap1[name] = newName;
nameMap2[newName] = fullName;
nameMap1[fullName] = newName;
}

return MakeGenericName(newName, count);
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ConfuserEx
ConfuserEx-Reborn
========
ConfuserEx is a open-source protector for .NET applications.
It is the successor of [Confuser](http://confuser.codeplex.com) project.
ConfuserEx-Reborn is the continuation of and replacement for the original ConfuserEx project. ConfuserEx Reborn is an open-source obfuscator and protector for C#/.NET applications. It including fixes and tweaks from other users and community members.

Features
--------
* Supports .NET Framework 2.0/3.0/3.5/4.0/4.5
* Symbol renaming (Support WPF/BAML)
* Supports Mono (Some feature restrictions apply)
* Symbol renaming (Support WPF/XAML/BAML)
* Protection against debuggers/profilers
* Protection against memory dumping
* Protection against tampering (method encryption)
Expand All @@ -28,14 +28,14 @@ The format of project file can be found in docs\ProjectFormat.md

Bug Report
----------
See the [Issues Report](http://yck1509.github.io/ConfuserEx/issues/) section of website.

See the [Issues Report](https://github.com/CubeCoders/ConfuserEx-Reborn/issues) section of website.

License
-------
See LICENSE file for details.

Credits
-------
**[0xd4d](https://github.com/0xd4d)** for his awesome work and extensive knowledge!
Members of **[Black Storm Forum](http://board.b-at-s.info/)** for their help!
* **[yck1509](https://github.com/yck1509/ConfuserEx)** for the original ConfuserEx
* **[0xd4d](https://github.com/0xd4d)** for his awesome work and extensive knowledge!
* Members of **[Black Storm Forum](http://board.b-at-s.info/)** for their help!