diff --git a/Confuser.CLI/Program.cs b/Confuser.CLI/Program.cs index 0e258f6..bf73269 100644 --- a/Confuser.CLI/Program.cs +++ b/Confuser.CLI/Program.cs @@ -25,8 +25,7 @@ namespace Confuser.CLI { xmlDoc.Load(args[0]); proj.Load(xmlDoc); proj.BaseDirectory = Path.Combine(Path.GetDirectoryName(args[0]), proj.BaseDirectory); - } - catch (Exception ex) { + } catch (Exception ex) { WriteLineWithColor(ConsoleColor.Red, "Failed to load project:"); WriteLineWithColor(ConsoleColor.Red, ex.ToString()); return -1; @@ -46,8 +45,7 @@ namespace Confuser.CLI { } return logger.ReturnValue; - } - finally { + } finally { Console.ForegroundColor = original; Console.Title = originalTitle; } @@ -143,8 +141,7 @@ namespace Confuser.CLI { Console.Title = "ConfuserEx - Success"; WriteLineWithColor(ConsoleColor.Green, "Finished " + timeString); ReturnValue = 0; - } - else { + } else { Console.Title = "ConfuserEx - Fail"; WriteLineWithColor(ConsoleColor.Red, "Failed " + timeString); ReturnValue = 1; diff --git a/Confuser.CLI/Properties/AssemblyInfo.cs b/Confuser.CLI/Properties/AssemblyInfo.cs index 95c7591..4c63326 100644 --- a/Confuser.CLI/Properties/AssemblyInfo.cs +++ b/Confuser.CLI/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; [assembly: AssemblyTitle("ConfuserEx Command-line")] [assembly: AssemblyDescription("Command-line interface of ConfuserEx")] \ No newline at end of file diff --git a/Confuser.Core/ConfuserComponent.cs b/Confuser.Core/ConfuserComponent.cs index f131510..1052113 100644 --- a/Confuser.Core/ConfuserComponent.cs +++ b/Confuser.Core/ConfuserComponent.cs @@ -1,4 +1,6 @@ -namespace Confuser.Core { +using System; + +namespace Confuser.Core { /// /// Represent a component in Confuser /// diff --git a/Confuser.Core/ConfuserEngine.cs b/Confuser.Core/ConfuserEngine.cs index e5c31eb..122f465 100644 --- a/Confuser.Core/ConfuserEngine.cs +++ b/Confuser.Core/ConfuserEngine.cs @@ -21,11 +21,11 @@ namespace Confuser.Core { /// The processing engine of ConfuserEx. /// public static class ConfuserEngine { - /// - /// The version of ConfuserEx. + /// The version of ConfuserEx. /// public static readonly string Version; + private static readonly string Copyright; static ConfuserEngine() { diff --git a/Confuser.Core/ConfuserParameters.cs b/Confuser.Core/ConfuserParameters.cs index 774df5e..f1e9b85 100644 --- a/Confuser.Core/ConfuserParameters.cs +++ b/Confuser.Core/ConfuserParameters.cs @@ -1,4 +1,5 @@ -using Confuser.Core.Project; +using System; +using Confuser.Core.Project; namespace Confuser.Core { /// diff --git a/Confuser.Core/CoreComponent.cs b/Confuser.Core/CoreComponent.cs index 992863d..bb94080 100644 --- a/Confuser.Core/CoreComponent.cs +++ b/Confuser.Core/CoreComponent.cs @@ -1,4 +1,5 @@ -using Confuser.Core.Services; +using System; +using Confuser.Core.Services; namespace Confuser.Core { /// diff --git a/Confuser.Core/DnlibUtils.cs b/Confuser.Core/DnlibUtils.cs index ea4e54f..a7535ff 100644 --- a/Confuser.Core/DnlibUtils.cs +++ b/Confuser.Core/DnlibUtils.cs @@ -224,8 +224,7 @@ namespace Confuser.Core { ret.Add(genInst.GenericType.TypeDefOrRef); foreach (TypeSig genArg in genInst.GenericArguments) FindTypeRefsInternal(genArg, ret); - } - else if (typeSig is TypeDefOrRefSig) + } else if (typeSig is TypeDefOrRefSig) ret.Add(((TypeDefOrRefSig)typeSig).TypeDefOrRef); } diff --git a/Confuser.Core/Helpers/InjectHelper.cs b/Confuser.Core/Helpers/InjectHelper.cs index f1c3eab..1ad08ef 100644 --- a/Confuser.Core/Helpers/InjectHelper.cs +++ b/Confuser.Core/Helpers/InjectHelper.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using dnlib.DotNet; using dnlib.DotNet.Emit; @@ -62,8 +63,7 @@ namespace Confuser.Core.Helpers { if (!ctx.Map.TryGetValue(typeDef, out existing)) { ret = Clone(typeDef); ctx.Map[typeDef] = ret; - } - else + } else ret = (TypeDef)existing; foreach (TypeDef nestedType in typeDef.NestedTypes) diff --git a/Confuser.Core/LZMA/Common/CRC.cs b/Confuser.Core/LZMA/Common/CRC.cs index a16d293..bc2259b 100644 --- a/Confuser.Core/LZMA/Common/CRC.cs +++ b/Confuser.Core/LZMA/Common/CRC.cs @@ -1,5 +1,7 @@ // Common/CRC.cs +using System; + namespace SevenZip { internal class CRC { public static readonly uint[] Table; diff --git a/Confuser.Core/LZMA/Common/InBuffer.cs b/Confuser.Core/LZMA/Common/InBuffer.cs index 9928f73..4845a86 100644 --- a/Confuser.Core/LZMA/Common/InBuffer.cs +++ b/Confuser.Core/LZMA/Common/InBuffer.cs @@ -1,5 +1,6 @@ // InBuffer.cs +using System; using System.IO; namespace SevenZip.Buffer { diff --git a/Confuser.Core/LZMA/Common/OutBuffer.cs b/Confuser.Core/LZMA/Common/OutBuffer.cs index 681ec12..57cfe3b 100644 --- a/Confuser.Core/LZMA/Common/OutBuffer.cs +++ b/Confuser.Core/LZMA/Common/OutBuffer.cs @@ -1,5 +1,6 @@ // OutBuffer.cs +using System; using System.IO; namespace SevenZip.Buffer { diff --git a/Confuser.Core/LZMA/Compress/LZ/LzBinTree.cs b/Confuser.Core/LZMA/Compress/LZ/LzBinTree.cs index a393f1a..e4e1b58 100644 --- a/Confuser.Core/LZMA/Compress/LZ/LzBinTree.cs +++ b/Confuser.Core/LZMA/Compress/LZ/LzBinTree.cs @@ -116,8 +116,7 @@ namespace SevenZip.Compression.LZ { temp ^= ((UInt32)(_bufferBase[cur + 2]) << 8); hash3Value = temp & (kHash3Size - 1); hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask; - } - else + } else hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8); UInt32 curMatch = _hash[kFixHashSize + hashValue]; @@ -196,8 +195,7 @@ namespace SevenZip.Compression.LZ { ptr1 = cyclicPos + 1; curMatch = _son[ptr1]; len1 = len; - } - else { + } else { _son[ptr0] = curMatch; ptr0 = cyclicPos; curMatch = _son[ptr0]; @@ -234,8 +232,7 @@ namespace SevenZip.Compression.LZ { UInt32 hash3Value = temp & (kHash3Size - 1); _hash[kHash3Offset + hash3Value] = _pos; hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask; - } - else + } else hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8); UInt32 curMatch = _hash[kFixHashSize + hashValue]; @@ -276,8 +273,7 @@ namespace SevenZip.Compression.LZ { ptr1 = cyclicPos + 1; curMatch = _son[ptr1]; len1 = len; - } - else { + } else { _son[ptr0] = curMatch; ptr0 = cyclicPos; curMatch = _son[ptr0]; @@ -294,8 +290,7 @@ namespace SevenZip.Compression.LZ { kNumHashDirectBytes = 0; kMinMatchCheck = 4; kFixHashSize = kHash2Size + kHash3Size; - } - else { + } else { kNumHashDirectBytes = 2; kMinMatchCheck = 2 + 1; kFixHashSize = 0; diff --git a/Confuser.Core/LZMA/Compress/LZ/LzOutWindow.cs b/Confuser.Core/LZMA/Compress/LZ/LzOutWindow.cs index dbe7b6d..3a20ffe 100644 --- a/Confuser.Core/LZMA/Compress/LZ/LzOutWindow.cs +++ b/Confuser.Core/LZMA/Compress/LZ/LzOutWindow.cs @@ -1,5 +1,6 @@ // LzOutWindow.cs +using System; using System.IO; namespace SevenZip.Compression.LZ { diff --git a/Confuser.Core/LZMA/Compress/LZMA/LzmaBase.cs b/Confuser.Core/LZMA/Compress/LZMA/LzmaBase.cs index 6c7fa5a..b8ae580 100644 --- a/Confuser.Core/LZMA/Compress/LZMA/LzmaBase.cs +++ b/Confuser.Core/LZMA/Compress/LZMA/LzmaBase.cs @@ -1,5 +1,7 @@ // LzmaBase.cs +using System; + namespace SevenZip.Compression.LZMA { internal abstract class Base { public const uint kNumRepDistances = 4; diff --git a/Confuser.Core/LZMA/Compress/LZMA/LzmaDecoder.cs b/Confuser.Core/LZMA/Compress/LZMA/LzmaDecoder.cs index 5f4f7e3..71d5fd1 100644 --- a/Confuser.Core/LZMA/Compress/LZMA/LzmaDecoder.cs +++ b/Confuser.Core/LZMA/Compress/LZMA/LzmaDecoder.cs @@ -71,8 +71,7 @@ namespace SevenZip.Compression.LZMA { m_OutWindow.PutByte(b); state.UpdateChar(); nowPos64++; - } - else { + } else { uint len; if (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1) { if (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0) { @@ -82,13 +81,11 @@ namespace SevenZip.Compression.LZMA { nowPos64++; continue; } - } - else { + } else { UInt32 distance; if (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0) { distance = rep1; - } - else { + } else { if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0) distance = rep2; else { @@ -102,8 +99,7 @@ namespace SevenZip.Compression.LZMA { } len = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen; state.UpdateRep(); - } - else { + } else { rep3 = rep2; rep2 = rep1; rep1 = rep0; @@ -121,8 +117,7 @@ namespace SevenZip.Compression.LZMA { numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits); rep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder); } - } - else + } else rep0 = posSlot; } if (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck) { diff --git a/Confuser.Core/LZMA/Compress/LZMA/LzmaEncoder.cs b/Confuser.Core/LZMA/Compress/LZMA/LzmaEncoder.cs index 3dd271d..2a9f969 100644 --- a/Confuser.Core/LZMA/Compress/LZMA/LzmaEncoder.cs +++ b/Confuser.Core/LZMA/Compress/LZMA/LzmaEncoder.cs @@ -117,8 +117,7 @@ namespace SevenZip.Compression.LZMA { progress.SetProgress(processedInSize, processedOutSize); } } - } - finally { + } finally { ReleaseStreams(); } } @@ -333,8 +332,7 @@ namespace SevenZip.Compression.LZMA { if (repIndex == 0) { price = _isRepG0[state.Index].GetPrice0(); price += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1(); - } - else { + } else { price = _isRepG0[state.Index].GetPrice1(); if (repIndex == 1) price += _isRepG1[state.Index].GetPrice0(); @@ -404,8 +402,7 @@ namespace SevenZip.Compression.LZMA { UInt32 lenMain, numDistancePairs; if (!_longestMatchWasFound) { ReadMatchDistances(out lenMain, out numDistancePairs); - } - else { + } else { lenMain = _longestMatchLength; numDistancePairs = _numDistancePairs; _longestMatchWasFound = false; @@ -552,27 +549,23 @@ namespace SevenZip.Compression.LZMA { state.UpdateRep(); else state.UpdateMatch(); - } - else + } else state = _optimum[posPrev].State; state.UpdateChar(); - } - else + } else state = _optimum[posPrev].State; if (posPrev == cur - 1) { if (_optimum[cur].IsShortRep()) state.UpdateShortRep(); else state.UpdateChar(); - } - else { + } else { UInt32 pos; if (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2) { posPrev = _optimum[cur].PosPrev2; pos = _optimum[cur].BackPrev2; state.UpdateRep(); - } - else { + } else { pos = _optimum[cur].BackPrev; if (pos < Base.kNumRepDistances) state.UpdateRep(); @@ -586,27 +579,23 @@ namespace SevenZip.Compression.LZMA { reps[1] = opt.Backs1; reps[2] = opt.Backs2; reps[3] = opt.Backs3; - } - else if (pos == 1) { + } else if (pos == 1) { reps[0] = opt.Backs1; reps[1] = opt.Backs0; reps[2] = opt.Backs2; reps[3] = opt.Backs3; - } - else if (pos == 2) { + } else if (pos == 2) { reps[0] = opt.Backs2; reps[1] = opt.Backs0; reps[2] = opt.Backs1; reps[3] = opt.Backs3; - } - else { + } else { reps[0] = opt.Backs3; reps[1] = opt.Backs0; reps[2] = opt.Backs1; reps[3] = opt.Backs2; } - } - else { + } else { reps[0] = (pos - Base.kNumRepDistances); reps[1] = opt.Backs0; reps[2] = opt.Backs1; @@ -910,13 +899,11 @@ namespace SevenZip.Compression.LZMA { if (!_state.IsCharState()) { Byte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset)); subCoder.EncodeMatched(_rangeEncoder, matchByte, curByte); - } - else + } else subCoder.Encode(_rangeEncoder, curByte); _previousByte = curByte; _state.UpdateChar(); - } - else { + } else { _isMatch[complexState].Encode(_rangeEncoder, 1); if (pos < Base.kNumRepDistances) { _isRep[_state.Index].Encode(_rangeEncoder, 1); @@ -926,8 +913,7 @@ namespace SevenZip.Compression.LZMA { _isRep0Long[complexState].Encode(_rangeEncoder, 0); else _isRep0Long[complexState].Encode(_rangeEncoder, 1); - } - else { + } else { _isRepG0[_state.Index].Encode(_rangeEncoder, 1); if (pos == 1) _isRepG1[_state.Index].Encode(_rangeEncoder, 0); @@ -948,8 +934,7 @@ namespace SevenZip.Compression.LZMA { _repDistances[i] = _repDistances[i - 1]; _repDistances[0] = distance; } - } - else { + } else { _isRep[_state.Index].Encode(_rangeEncoder, 0); _state.UpdateMatch(); _lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState); @@ -1127,15 +1112,13 @@ namespace SevenZip.Compression.LZMA { if (symbol < Base.kNumLowLenSymbols) { _choice.Encode(rangeEncoder, 0); _lowCoder[posState].Encode(rangeEncoder, symbol); - } - else { + } else { symbol -= Base.kNumLowLenSymbols; _choice.Encode(rangeEncoder, 1); if (symbol < Base.kNumMidLenSymbols) { _choice2.Encode(rangeEncoder, 0); _midCoder[posState].Encode(rangeEncoder, symbol); - } - else { + } else { _choice2.Encode(rangeEncoder, 1); _highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols); } diff --git a/Confuser.Core/LZMA/Compress/RangeCoder/RangeCoder.cs b/Confuser.Core/LZMA/Compress/RangeCoder/RangeCoder.cs index 3f2dbd6..2eae386 100644 --- a/Confuser.Core/LZMA/Compress/RangeCoder/RangeCoder.cs +++ b/Confuser.Core/LZMA/Compress/RangeCoder/RangeCoder.cs @@ -182,8 +182,7 @@ namespace SevenZip.Compression.RangeCoder { if (Code < newBound) { symbol = 0; Range = newBound; - } - else { + } else { symbol = 1; Code -= newBound; Range -= newBound; diff --git a/Confuser.Core/LZMA/Compress/RangeCoder/RangeCoderBit.cs b/Confuser.Core/LZMA/Compress/RangeCoder/RangeCoderBit.cs index 65bdf23..21663ce 100644 --- a/Confuser.Core/LZMA/Compress/RangeCoder/RangeCoderBit.cs +++ b/Confuser.Core/LZMA/Compress/RangeCoder/RangeCoderBit.cs @@ -40,8 +40,7 @@ namespace SevenZip.Compression.RangeCoder { if (symbol == 0) { encoder.Range = newBound; Prob += (kBitModelTotal - Prob) >> kNumMoveBits; - } - else { + } else { encoder.Low += newBound; encoder.Range -= newBound; Prob -= (Prob) >> kNumMoveBits; diff --git a/Confuser.Core/Marker.cs b/Confuser.Core/Marker.cs index a7083e4..8354ace 100644 --- a/Confuser.Core/Marker.cs +++ b/Confuser.Core/Marker.cs @@ -76,8 +76,7 @@ namespace Confuser.Core { return new StrongNameKey(rsa.ExportCspBlob(true)); } return new StrongNameKey(path); - } - catch (Exception ex) { + } catch (Exception ex) { context.Logger.ErrorException("Cannot load the Strong Name Key located at: " + path, ex); throw new ConfuserException(ex); } @@ -161,8 +160,7 @@ namespace Confuser.Core { foreach (Rule rule in proj.Rules.Concat(module.Rules)) { try { ret.Add(rule, parser.Parse(rule.Pattern)); - } - catch (InvalidPatternException ex) { + } catch (InvalidPatternException ex) { context.Logger.ErrorFormat("Invalid rule pattern: " + rule.Pattern + ".", ex); throw new ConfuserException(ex); } diff --git a/Confuser.Core/MarkerResult.cs b/Confuser.Core/MarkerResult.cs index 672791c..ebe5cec 100644 --- a/Confuser.Core/MarkerResult.cs +++ b/Confuser.Core/MarkerResult.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using dnlib.DotNet; namespace Confuser.Core { diff --git a/Confuser.Core/Packer.cs b/Confuser.Core/Packer.cs index 57fdb1c..fa588f8 100644 --- a/Confuser.Core/Packer.cs +++ b/Confuser.Core/Packer.cs @@ -66,8 +66,7 @@ namespace Confuser.Core { Project = proj, PackerInitiated = true }, context.token).Wait(); - } - catch (AggregateException ex) { + } catch (AggregateException ex) { context.Logger.Error("Failed to protect packer stub."); throw new ConfuserException(ex); } diff --git a/Confuser.Core/PluginDiscovery.cs b/Confuser.Core/PluginDiscovery.cs index 6673632..40d55c4 100644 --- a/Confuser.Core/PluginDiscovery.cs +++ b/Confuser.Core/PluginDiscovery.cs @@ -33,7 +33,7 @@ namespace Confuser.Core { } /// - /// Determines whether the specified type has an accessible default constructor. + /// Determines whether the specified type has an accessible default constructor. /// /// The type. /// true if the specified type has an accessible default constructor; otherwise, false. @@ -61,24 +61,19 @@ namespace Confuser.Core { if (typeof (Protection).IsAssignableFrom(i)) { try { protections.Add((Protection)Activator.CreateInstance(i)); - } - catch (Exception ex) { + } catch (Exception ex) { context.Logger.ErrorException("Failed to instantiate protection '" + i.Name + "'.", ex); } - } - else if (typeof (Packer).IsAssignableFrom(i)) { + } else if (typeof (Packer).IsAssignableFrom(i)) { try { packers.Add((Packer)Activator.CreateInstance(i)); - } - catch (Exception ex) { + } catch (Exception ex) { context.Logger.ErrorException("Failed to instantiate packer '" + i.Name + "'.", ex); } - } - else if (typeof (ConfuserComponent).IsAssignableFrom(i)) { + } else if (typeof (ConfuserComponent).IsAssignableFrom(i)) { try { components.Add((ConfuserComponent)Activator.CreateInstance(i)); - } - catch (Exception ex) { + } catch (Exception ex) { context.Logger.ErrorException("Failed to instantiate component '" + i.Name + "'.", ex); } } @@ -99,24 +94,21 @@ namespace Confuser.Core { try { Assembly protAsm = Assembly.Load("Confuser.Protections"); AddPlugins(context, protections, packers, components, protAsm); - } - catch (Exception ex) { + } catch (Exception ex) { context.Logger.WarnException("Failed to load built-in protections.", ex); } try { Assembly renameAsm = Assembly.Load("Confuser.Renamer"); AddPlugins(context, protections, packers, components, renameAsm); - } - catch (Exception ex) { + } catch (Exception ex) { context.Logger.WarnException("Failed to load renamer.", ex); } try { Assembly renameAsm = Assembly.Load("Confuser.DynCipher"); AddPlugins(context, protections, packers, components, renameAsm); - } - catch (Exception ex) { + } catch (Exception ex) { context.Logger.WarnException("Failed to load dynamic cipher library.", ex); } @@ -125,8 +117,7 @@ namespace Confuser.Core { try { Assembly plugin = Assembly.LoadFile(realPath); AddPlugins(context, protections, packers, components, plugin); - } - catch (Exception ex) { + } catch (Exception ex) { context.Logger.WarnException("Failed to load plugin '" + pluginPath + "'.", ex); } } diff --git a/Confuser.Core/Project/ConfuserProject.cs b/Confuser.Core/Project/ConfuserProject.cs index 2a1e417..6165a4d 100644 --- a/Confuser.Core/Project/ConfuserProject.cs +++ b/Confuser.Core/Project/ConfuserProject.cs @@ -458,9 +458,9 @@ namespace Confuser.Core.Project { doc.Schemas.Add(Schema); var exceptions = new List(); doc.Validate((sender, e) => { - if (e.Severity != XmlSeverityType.Error) return; - exceptions.Add(e.Exception); - }); + if (e.Severity != XmlSeverityType.Error) return; + exceptions.Add(e.Exception); + }); if (exceptions.Count > 0) { throw new ProjectValidationException(exceptions); } @@ -490,18 +490,14 @@ namespace Confuser.Core.Project { var rule = new Rule(); rule.Load(i); Rules.Add(rule); - } - else if (i.Name == "packer") { + } else if (i.Name == "packer") { Packer = new SettingItem(); Packer.Load(i); - } - else if (i.Name == "probePath") { + } else if (i.Name == "probePath") { ProbePaths.Add(i.InnerText); - } - else if (i.Name == "plugin") { + } else if (i.Name == "plugin") { PluginPaths.Add(i.InnerText); - } - else { + } else { var asm = new ProjectModule(); asm.Load(i); Add(asm); diff --git a/Confuser.Core/Project/PatternParser.cs b/Confuser.Core/Project/PatternParser.cs index d413a8b..24783c7 100644 --- a/Confuser.Core/Project/PatternParser.cs +++ b/Confuser.Core/Project/PatternParser.cs @@ -46,8 +46,7 @@ namespace Confuser.Core.Project { if (PeekToken() != null) throw new InvalidPatternException("Extra tokens beyond the end of pattern."); return ret; - } - catch (Exception ex) { + } catch (Exception ex) { if (ex is InvalidPatternException) throw; throw new InvalidPatternException("Invalid pattern.", ex); @@ -124,8 +123,7 @@ namespace Confuser.Core.Project { throw UnexpectedToken(token); op.OperandA = ParseExpression(); ret = op; - } - else if (IsFunction(token)) { + } else if (IsFunction(token)) { // function PatternFunction fn = fns[token.Value](); @@ -154,8 +152,7 @@ namespace Confuser.Core.Project { throw MismatchParens(parens.Position.Value); ret = fn; - } - else { + } else { bool boolValue; if (bool.TryParse(token.Value, out boolValue)) ret = new LiteralExpression(boolValue); diff --git a/Confuser.Core/Project/PatternToken.cs b/Confuser.Core/Project/PatternToken.cs index dc02ac4..595315c 100644 --- a/Confuser.Core/Project/PatternToken.cs +++ b/Confuser.Core/Project/PatternToken.cs @@ -1,4 +1,6 @@ -namespace Confuser.Core.Project { +using System; + +namespace Confuser.Core.Project { /// /// The type of pattern tokens /// diff --git a/Confuser.Core/Project/Patterns/AndOperator.cs b/Confuser.Core/Project/Patterns/AndOperator.cs index 394eb07..e55f27a 100644 --- a/Confuser.Core/Project/Patterns/AndOperator.cs +++ b/Confuser.Core/Project/Patterns/AndOperator.cs @@ -1,4 +1,5 @@ -using dnlib.DotNet; +using System; +using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { /// diff --git a/Confuser.Core/Project/Patterns/DeclTypeFunction.cs b/Confuser.Core/Project/Patterns/DeclTypeFunction.cs index 0349ad6..40af325 100644 --- a/Confuser.Core/Project/Patterns/DeclTypeFunction.cs +++ b/Confuser.Core/Project/Patterns/DeclTypeFunction.cs @@ -1,4 +1,5 @@ -using dnlib.DotNet; +using System; +using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { /// diff --git a/Confuser.Core/Project/Patterns/FullNameFunction.cs b/Confuser.Core/Project/Patterns/FullNameFunction.cs index 816d02b..4fbd7b9 100644 --- a/Confuser.Core/Project/Patterns/FullNameFunction.cs +++ b/Confuser.Core/Project/Patterns/FullNameFunction.cs @@ -1,4 +1,5 @@ -using dnlib.DotNet; +using System; +using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { /// diff --git a/Confuser.Core/Project/Patterns/LiteralExpression.cs b/Confuser.Core/Project/Patterns/LiteralExpression.cs index d8b4e0d..1495b6a 100644 --- a/Confuser.Core/Project/Patterns/LiteralExpression.cs +++ b/Confuser.Core/Project/Patterns/LiteralExpression.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { @@ -30,8 +31,7 @@ namespace Confuser.Core.Project.Patterns { if (Literal is bool) { var value = (bool)Literal; tokens.Add(new PatternToken(TokenType.Identifier, value.ToString().ToLowerInvariant())); - } - else + } else tokens.Add(new PatternToken(TokenType.Literal, Literal.ToString())); } } diff --git a/Confuser.Core/Project/Patterns/MatchFunction.cs b/Confuser.Core/Project/Patterns/MatchFunction.cs index 31c451a..94ff40e 100644 --- a/Confuser.Core/Project/Patterns/MatchFunction.cs +++ b/Confuser.Core/Project/Patterns/MatchFunction.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using System; +using System.Text.RegularExpressions; using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { diff --git a/Confuser.Core/Project/Patterns/ModuleFunction.cs b/Confuser.Core/Project/Patterns/ModuleFunction.cs index 4fd649a..4c12346 100644 --- a/Confuser.Core/Project/Patterns/ModuleFunction.cs +++ b/Confuser.Core/Project/Patterns/ModuleFunction.cs @@ -1,4 +1,5 @@ -using dnlib.DotNet; +using System; +using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { /// diff --git a/Confuser.Core/Project/Patterns/NameFunction.cs b/Confuser.Core/Project/Patterns/NameFunction.cs index 332b86c..c6d8d49 100644 --- a/Confuser.Core/Project/Patterns/NameFunction.cs +++ b/Confuser.Core/Project/Patterns/NameFunction.cs @@ -1,4 +1,5 @@ -using dnlib.DotNet; +using System; +using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { /// diff --git a/Confuser.Core/Project/Patterns/NamespaceFunction.cs b/Confuser.Core/Project/Patterns/NamespaceFunction.cs index ecabf92..d005ace 100644 --- a/Confuser.Core/Project/Patterns/NamespaceFunction.cs +++ b/Confuser.Core/Project/Patterns/NamespaceFunction.cs @@ -1,4 +1,5 @@ -using dnlib.DotNet; +using System; +using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { /// @@ -27,7 +28,7 @@ namespace Confuser.Core.Project.Patterns { if (type == null) type = ((IMemberDef)definition).DeclaringType; - while (type.IsNested) + while (type.IsNested) type = type.DeclaringType; return type != null && type.Namespace == ns.ToString(); diff --git a/Confuser.Core/Project/Patterns/NotOperator.cs b/Confuser.Core/Project/Patterns/NotOperator.cs index 0018f1f..65dd31f 100644 --- a/Confuser.Core/Project/Patterns/NotOperator.cs +++ b/Confuser.Core/Project/Patterns/NotOperator.cs @@ -1,4 +1,5 @@ -using dnlib.DotNet; +using System; +using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { /// diff --git a/Confuser.Core/Project/Patterns/OrOperator.cs b/Confuser.Core/Project/Patterns/OrOperator.cs index 6213496..112150e 100644 --- a/Confuser.Core/Project/Patterns/OrOperator.cs +++ b/Confuser.Core/Project/Patterns/OrOperator.cs @@ -1,4 +1,5 @@ -using dnlib.DotNet; +using System; +using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { /// diff --git a/Confuser.Core/Project/Patterns/PatternExpression.cs b/Confuser.Core/Project/Patterns/PatternExpression.cs index a229b66..e0700ef 100644 --- a/Confuser.Core/Project/Patterns/PatternExpression.cs +++ b/Confuser.Core/Project/Patterns/PatternExpression.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { diff --git a/Confuser.Core/Project/Patterns/PatternFunction.cs b/Confuser.Core/Project/Patterns/PatternFunction.cs index d5d97fa..29aeae9 100644 --- a/Confuser.Core/Project/Patterns/PatternFunction.cs +++ b/Confuser.Core/Project/Patterns/PatternFunction.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Confuser.Core.Project.Patterns { /// diff --git a/Confuser.Core/Project/Patterns/PatternOperator.cs b/Confuser.Core/Project/Patterns/PatternOperator.cs index 6dc9cf9..46ef981 100644 --- a/Confuser.Core/Project/Patterns/PatternOperator.cs +++ b/Confuser.Core/Project/Patterns/PatternOperator.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Confuser.Core.Project.Patterns { /// @@ -34,8 +35,7 @@ namespace Confuser.Core.Project.Patterns { if (IsUnary) { tokens.Add(new PatternToken(TokenType.Identifier, Name)); OperandA.Serialize(tokens); - } - else { + } else { OperandA.Serialize(tokens); tokens.Add(new PatternToken(TokenType.Identifier, Name)); OperandB.Serialize(tokens); diff --git a/Confuser.Core/Properties/AssemblyInfo.cs b/Confuser.Core/Properties/AssemblyInfo.cs index 8d2c3db..0fe6779 100644 --- a/Confuser.Core/Properties/AssemblyInfo.cs +++ b/Confuser.Core/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; [assembly: AssemblyTitle("ConfuserEx Core")] [assembly: AssemblyDescription("Core framework of ConfuserEx")] \ No newline at end of file diff --git a/Confuser.Core/Protection.cs b/Confuser.Core/Protection.cs index 214a67a..f7bb080 100644 --- a/Confuser.Core/Protection.cs +++ b/Confuser.Core/Protection.cs @@ -1,4 +1,6 @@ -namespace Confuser.Core { +using System; + +namespace Confuser.Core { /// /// Base class of Confuser protections. /// diff --git a/Confuser.Core/ProtectionPhase.cs b/Confuser.Core/ProtectionPhase.cs index d358481..69c7624 100644 --- a/Confuser.Core/ProtectionPhase.cs +++ b/Confuser.Core/ProtectionPhase.cs @@ -1,4 +1,6 @@ -namespace Confuser.Core { +using System; + +namespace Confuser.Core { /// /// Base class of protection phases. /// diff --git a/Confuser.Core/ProtectionPipeline.cs b/Confuser.Core/ProtectionPipeline.cs index e5cb78e..f4933f6 100644 --- a/Confuser.Core/ProtectionPipeline.cs +++ b/Confuser.Core/ProtectionPipeline.cs @@ -161,14 +161,14 @@ namespace Confuser.Core { if (phase.ProcessAll) return filter.ToList(); return filter.Where(def => { - ProtectionSettings parameters = ProtectionParameters.GetParameters(context, def); - Debug.Assert(parameters != null); - if (parameters == null) { - context.Logger.ErrorFormat("'{0}' not marked for obfuscation, possibly a bug."); - throw new ConfuserException(null); - } - return parameters.ContainsKey(phase.Parent); - }).ToList(); + ProtectionSettings parameters = ProtectionParameters.GetParameters(context, def); + Debug.Assert(parameters != null); + if (parameters == null) { + context.Logger.ErrorFormat("'{0}' not marked for obfuscation, possibly a bug."); + throw new ConfuserException(null); + } + return parameters.ContainsKey(phase.Parent); + }).ToList(); } } } \ No newline at end of file diff --git a/Confuser.Core/ProtectionPreset.cs b/Confuser.Core/ProtectionPreset.cs index e495d40..28e0b74 100644 --- a/Confuser.Core/ProtectionPreset.cs +++ b/Confuser.Core/ProtectionPreset.cs @@ -1,4 +1,6 @@ -namespace Confuser.Core { +using System; + +namespace Confuser.Core { /// /// Various presets of protections. /// diff --git a/Confuser.Core/ProtectionSettings.cs b/Confuser.Core/ProtectionSettings.cs index a586edf..0c4d74b 100644 --- a/Confuser.Core/ProtectionSettings.cs +++ b/Confuser.Core/ProtectionSettings.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Confuser.Core { /// diff --git a/Confuser.Core/Services/RandomService.cs b/Confuser.Core/Services/RandomService.cs index 7153ed0..0358275 100644 --- a/Confuser.Core/Services/RandomService.cs +++ b/Confuser.Core/Services/RandomService.cs @@ -84,8 +84,7 @@ namespace Confuser.Core.Services { offset += stateFilled; length -= stateFilled; stateFilled = 0; - } - else { + } else { Buffer.BlockCopy(state, 32 - stateFilled, buffer, offset, length); stateFilled -= length; length = 0; diff --git a/Confuser.Core/Services/TraceService.cs b/Confuser.Core/Services/TraceService.cs index a20fd68..94c7a38 100644 --- a/Confuser.Core/Services/TraceService.cs +++ b/Confuser.Core/Services/TraceService.cs @@ -162,8 +162,7 @@ namespace Confuser.Core.Services { beforeDepths[targetIndex] = currentStack; fromInstrs.AddListEntry(offset2index[target.Offset], instr); } - } - else { + } else { int targetIndex = offset2index[((Instruction)instr.Operand).Offset]; if (beforeDepths[targetIndex] == int.MinValue) beforeDepths[targetIndex] = currentStack; @@ -264,8 +263,7 @@ namespace Confuser.Core.Services { if (stackUsage < 0) { Debug.Assert(stackUsage == -1); // i.e. push evalStack.Push(index); - } - else { + } else { if (evalStack.Count < stackUsage) return null; @@ -282,14 +280,11 @@ namespace Confuser.Core.Services { working2.Enqueue(Tuple.Create(targetIndex, new Stack(evalStack))); index++; } - } - - else if (currentInstr.Operand is Instruction[]) { + } else if (currentInstr.Operand is Instruction[]) { foreach (Instruction targetInstr in (Instruction[])currentInstr.Operand) working2.Enqueue(Tuple.Create(offset2index[targetInstr.Offset], new Stack(evalStack))); index++; - } - else + } else index++; } diff --git a/Confuser.Core/Tuples.cs b/Confuser.Core/Tuples.cs index 6c32907..1d26709 100644 --- a/Confuser.Core/Tuples.cs +++ b/Confuser.Core/Tuples.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Confuser.Core { /// diff --git a/Confuser.DynCipher/AST/ArrayIndexExpression.cs b/Confuser.DynCipher/AST/ArrayIndexExpression.cs index 8062206..f084536 100644 --- a/Confuser.DynCipher/AST/ArrayIndexExpression.cs +++ b/Confuser.DynCipher/AST/ArrayIndexExpression.cs @@ -1,4 +1,6 @@ -namespace Confuser.DynCipher.AST { +using System; + +namespace Confuser.DynCipher.AST { public class ArrayIndexExpression : Expression { public Expression Array { get; set; } public int Index { get; set; } diff --git a/Confuser.DynCipher/AST/AssignmentStatement.cs b/Confuser.DynCipher/AST/AssignmentStatement.cs index 31a2ef9..b02d5c3 100644 --- a/Confuser.DynCipher/AST/AssignmentStatement.cs +++ b/Confuser.DynCipher/AST/AssignmentStatement.cs @@ -1,4 +1,6 @@ -namespace Confuser.DynCipher.AST { +using System; + +namespace Confuser.DynCipher.AST { public class AssignmentStatement : Statement { public Expression Target { get; set; } public Expression Value { get; set; } diff --git a/Confuser.DynCipher/AST/Expression.cs b/Confuser.DynCipher/AST/Expression.cs index ecc2106..144e367 100644 --- a/Confuser.DynCipher/AST/Expression.cs +++ b/Confuser.DynCipher/AST/Expression.cs @@ -1,4 +1,6 @@ -namespace Confuser.DynCipher.AST { +using System; + +namespace Confuser.DynCipher.AST { public abstract class Expression { public object Tag { get; set; } public abstract override string ToString(); diff --git a/Confuser.DynCipher/AST/LiteralExpression.cs b/Confuser.DynCipher/AST/LiteralExpression.cs index c611c19..fa6257c 100644 --- a/Confuser.DynCipher/AST/LiteralExpression.cs +++ b/Confuser.DynCipher/AST/LiteralExpression.cs @@ -1,4 +1,6 @@ -namespace Confuser.DynCipher.AST { +using System; + +namespace Confuser.DynCipher.AST { public class LiteralExpression : Expression { public uint Value { get; set; } diff --git a/Confuser.DynCipher/AST/LoopStatement.cs b/Confuser.DynCipher/AST/LoopStatement.cs index 222be06..b3fee19 100644 --- a/Confuser.DynCipher/AST/LoopStatement.cs +++ b/Confuser.DynCipher/AST/LoopStatement.cs @@ -1,4 +1,5 @@ -using System.Text; +using System; +using System.Text; namespace Confuser.DynCipher.AST { // i.e. for loop diff --git a/Confuser.DynCipher/AST/Statement.cs b/Confuser.DynCipher/AST/Statement.cs index d078ad5..24f5c53 100644 --- a/Confuser.DynCipher/AST/Statement.cs +++ b/Confuser.DynCipher/AST/Statement.cs @@ -1,4 +1,6 @@ -namespace Confuser.DynCipher.AST { +using System; + +namespace Confuser.DynCipher.AST { public abstract class Statement { public object Tag { get; set; } public abstract override string ToString(); diff --git a/Confuser.DynCipher/AST/StatementBlock.cs b/Confuser.DynCipher/AST/StatementBlock.cs index aa5e209..b209fc3 100644 --- a/Confuser.DynCipher/AST/StatementBlock.cs +++ b/Confuser.DynCipher/AST/StatementBlock.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Text; namespace Confuser.DynCipher.AST { diff --git a/Confuser.DynCipher/AST/Variable.cs b/Confuser.DynCipher/AST/Variable.cs index a767f33..856f9b0 100644 --- a/Confuser.DynCipher/AST/Variable.cs +++ b/Confuser.DynCipher/AST/Variable.cs @@ -1,4 +1,6 @@ -namespace Confuser.DynCipher.AST { +using System; + +namespace Confuser.DynCipher.AST { public class Variable { public Variable(string name) { Name = name; diff --git a/Confuser.DynCipher/AST/VariableExpression.cs b/Confuser.DynCipher/AST/VariableExpression.cs index 0d066f7..1e6836d 100644 --- a/Confuser.DynCipher/AST/VariableExpression.cs +++ b/Confuser.DynCipher/AST/VariableExpression.cs @@ -1,4 +1,6 @@ -namespace Confuser.DynCipher.AST { +using System; + +namespace Confuser.DynCipher.AST { public class VariableExpression : Expression { public Variable Variable { get; set; } diff --git a/Confuser.DynCipher/DynCipherComponent.cs b/Confuser.DynCipher/DynCipherComponent.cs index 4ab39a2..a7c4389 100644 --- a/Confuser.DynCipher/DynCipherComponent.cs +++ b/Confuser.DynCipher/DynCipherComponent.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; namespace Confuser.DynCipher { internal class DynCipherComponent : ConfuserComponent { diff --git a/Confuser.DynCipher/DynCipherService.cs b/Confuser.DynCipher/DynCipherService.cs index 1597209..bba7c4c 100644 --- a/Confuser.DynCipher/DynCipherService.cs +++ b/Confuser.DynCipher/DynCipherService.cs @@ -1,4 +1,5 @@ -using Confuser.Core.Services; +using System; +using Confuser.Core.Services; using Confuser.DynCipher.AST; using Confuser.DynCipher.Generation; diff --git a/Confuser.DynCipher/Elements/AddKey.cs b/Confuser.DynCipher/Elements/AddKey.cs index 3e840ab..5a5c62d 100644 --- a/Confuser.DynCipher/Elements/AddKey.cs +++ b/Confuser.DynCipher/Elements/AddKey.cs @@ -1,4 +1,5 @@ -using Confuser.Core.Services; +using System; +using Confuser.Core.Services; using Confuser.DynCipher.AST; using Confuser.DynCipher.Generation; diff --git a/Confuser.DynCipher/Elements/BinOp.cs b/Confuser.DynCipher/Elements/BinOp.cs index 8876d22..24fe75d 100644 --- a/Confuser.DynCipher/Elements/BinOp.cs +++ b/Confuser.DynCipher/Elements/BinOp.cs @@ -1,4 +1,5 @@ -using Confuser.Core.Services; +using System; +using Confuser.Core.Services; using Confuser.DynCipher.AST; using Confuser.DynCipher.Generation; diff --git a/Confuser.DynCipher/Elements/CryptoElement.cs b/Confuser.DynCipher/Elements/CryptoElement.cs index f422b12..6f68c89 100644 --- a/Confuser.DynCipher/Elements/CryptoElement.cs +++ b/Confuser.DynCipher/Elements/CryptoElement.cs @@ -1,4 +1,5 @@ -using Confuser.Core.Services; +using System; +using Confuser.Core.Services; using Confuser.DynCipher.Generation; namespace Confuser.DynCipher.Elements { diff --git a/Confuser.DynCipher/Elements/NumOp.cs b/Confuser.DynCipher/Elements/NumOp.cs index f89dc87..edf3d26 100644 --- a/Confuser.DynCipher/Elements/NumOp.cs +++ b/Confuser.DynCipher/Elements/NumOp.cs @@ -1,4 +1,5 @@ -using Confuser.Core.Services; +using System; +using Confuser.Core.Services; using Confuser.DynCipher.AST; using Confuser.DynCipher.Generation; diff --git a/Confuser.DynCipher/Elements/RotateBit.cs b/Confuser.DynCipher/Elements/RotateBit.cs index 26e1c6a..c71dbb3 100644 --- a/Confuser.DynCipher/Elements/RotateBit.cs +++ b/Confuser.DynCipher/Elements/RotateBit.cs @@ -1,4 +1,5 @@ -using Confuser.Core.Services; +using System; +using Confuser.Core.Services; using Confuser.DynCipher.AST; using Confuser.DynCipher.Generation; diff --git a/Confuser.DynCipher/Elements/Swap.cs b/Confuser.DynCipher/Elements/Swap.cs index 045461d..84e7fba 100644 --- a/Confuser.DynCipher/Elements/Swap.cs +++ b/Confuser.DynCipher/Elements/Swap.cs @@ -1,4 +1,5 @@ -using Confuser.Core.Services; +using System; +using Confuser.Core.Services; using Confuser.DynCipher.AST; using Confuser.DynCipher.Generation; @@ -40,8 +41,7 @@ namespace Confuser.DynCipher.Elements { Target = b }); } - } - else { + } else { var mask = (LiteralExpression)Mask; var notMask = (LiteralExpression)~Mask; /* t = (a & mask) * k; diff --git a/Confuser.DynCipher/Generation/CILCodeGen.cs b/Confuser.DynCipher/Generation/CILCodeGen.cs index 56f60b6..0a343e3 100644 --- a/Confuser.DynCipher/Generation/CILCodeGen.cs +++ b/Confuser.DynCipher/Generation/CILCodeGen.cs @@ -60,8 +60,7 @@ namespace Confuser.DynCipher.Generation { EmitLoad(arrIndex.Array); Emit(Instruction.CreateLdcI4(arrIndex.Index)); Emit(Instruction.Create(OpCodes.Ldelem_U4)); - } - else if (exp is BinOpExpression) { + } else if (exp is BinOpExpression) { var binOp = (BinOpExpression)exp; EmitLoad(binOp.Left); EmitLoad(binOp.Right); @@ -98,8 +97,7 @@ namespace Confuser.DynCipher.Generation { throw new NotSupportedException(); } Emit(Instruction.Create(op)); - } - else if (exp is UnaryOpExpression) { + } else if (exp is UnaryOpExpression) { var unaryOp = (UnaryOpExpression)exp; EmitLoad(unaryOp.Value); OpCode op; @@ -114,16 +112,13 @@ namespace Confuser.DynCipher.Generation { throw new NotSupportedException(); } Emit(Instruction.Create(op)); - } - else if (exp is LiteralExpression) { + } else if (exp is LiteralExpression) { var literal = (LiteralExpression)exp; Emit(Instruction.CreateLdcI4((int)literal.Value)); - } - else if (exp is VariableExpression) { + } else if (exp is VariableExpression) { var var = (VariableExpression)exp; LoadVar(var.Variable); - } - else + } else throw new NotSupportedException(); } @@ -134,13 +129,11 @@ namespace Confuser.DynCipher.Generation { Emit(Instruction.CreateLdcI4(arrIndex.Index)); EmitLoad(value); Emit(Instruction.Create(OpCodes.Stelem_I4)); - } - else if (exp is VariableExpression) { + } else if (exp is VariableExpression) { var var = (VariableExpression)exp; EmitLoad(value); StoreVar(var.Variable); - } - else + } else throw new NotSupportedException(); } @@ -148,8 +141,7 @@ namespace Confuser.DynCipher.Generation { if (statement is AssignmentStatement) { var assignment = (AssignmentStatement)statement; EmitStore(assignment.Target, assignment.Value); - } - else if (statement is LoopStatement) { + } else if (statement is LoopStatement) { var loop = (LoopStatement)statement; /* * ldc.i4 begin @@ -181,12 +173,10 @@ namespace Confuser.DynCipher.Generation { Emit(Instruction.CreateLdcI4(loop.Limit)); Emit(Instruction.Create(OpCodes.Blt, lbl)); Emit(Instruction.Create(OpCodes.Pop)); - } - else if (statement is StatementBlock) { + } else if (statement is StatementBlock) { foreach (Statement child in ((StatementBlock)statement).Statements) EmitStatement(child); - } - else + } else throw new NotSupportedException(); } } diff --git a/Confuser.DynCipher/Generation/CipherGenerator.cs b/Confuser.DynCipher/Generation/CipherGenerator.cs index bb8539e..3472aca 100644 --- a/Confuser.DynCipher/Generation/CipherGenerator.cs +++ b/Confuser.DynCipher/Generation/CipherGenerator.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Confuser.Core.Services; using Confuser.DynCipher.AST; diff --git a/Confuser.DynCipher/Generation/DMCodeGen.cs b/Confuser.DynCipher/Generation/DMCodeGen.cs index d500e79..4c0fd7d 100644 --- a/Confuser.DynCipher/Generation/DMCodeGen.cs +++ b/Confuser.DynCipher/Generation/DMCodeGen.cs @@ -66,8 +66,7 @@ namespace Confuser.DynCipher.Generation { EmitLoad(arrIndex.Array); ilGen.Emit(OpCodes.Ldc_I4, arrIndex.Index); ilGen.Emit(OpCodes.Ldelem_U4); - } - else if (exp is BinOpExpression) { + } else if (exp is BinOpExpression) { var binOp = (BinOpExpression)exp; EmitLoad(binOp.Left); EmitLoad(binOp.Right); @@ -104,8 +103,7 @@ namespace Confuser.DynCipher.Generation { throw new NotSupportedException(); } ilGen.Emit(op); - } - else if (exp is UnaryOpExpression) { + } else if (exp is UnaryOpExpression) { var unaryOp = (UnaryOpExpression)exp; EmitLoad(unaryOp.Value); OpCode op; @@ -120,16 +118,13 @@ namespace Confuser.DynCipher.Generation { throw new NotSupportedException(); } ilGen.Emit(op); - } - else if (exp is LiteralExpression) { + } else if (exp is LiteralExpression) { var literal = (LiteralExpression)exp; ilGen.Emit(OpCodes.Ldc_I4, (int)literal.Value); - } - else if (exp is VariableExpression) { + } else if (exp is VariableExpression) { var var = (VariableExpression)exp; LoadVar(var.Variable); - } - else + } else throw new NotSupportedException(); } @@ -140,13 +135,11 @@ namespace Confuser.DynCipher.Generation { ilGen.Emit(OpCodes.Ldc_I4, arrIndex.Index); EmitLoad(value); ilGen.Emit(OpCodes.Stelem_I4); - } - else if (exp is VariableExpression) { + } else if (exp is VariableExpression) { var var = (VariableExpression)exp; EmitLoad(value); StoreVar(var.Variable); - } - else + } else throw new NotSupportedException(); } @@ -154,8 +147,7 @@ namespace Confuser.DynCipher.Generation { if (statement is AssignmentStatement) { var assignment = (AssignmentStatement)statement; EmitStore(assignment.Target, assignment.Value); - } - else if (statement is LoopStatement) { + } else if (statement is LoopStatement) { var loop = (LoopStatement)statement; /* * ldc.i4 begin @@ -188,12 +180,10 @@ namespace Confuser.DynCipher.Generation { ilGen.Emit(OpCodes.Ldc_I4, loop.Limit); ilGen.Emit(OpCodes.Blt, lbl); ilGen.Emit(OpCodes.Pop); - } - else if (statement is StatementBlock) { + } else if (statement is StatementBlock) { foreach (Statement child in ((StatementBlock)statement).Statements) EmitStatement(child); - } - else + } else throw new NotSupportedException(); } } diff --git a/Confuser.DynCipher/Generation/ExpressionGenerator.cs b/Confuser.DynCipher/Generation/ExpressionGenerator.cs index 2af4e63..9389af7 100644 --- a/Confuser.DynCipher/Generation/ExpressionGenerator.cs +++ b/Confuser.DynCipher/Generation/ExpressionGenerator.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using Confuser.Core; using Confuser.Core.Services; @@ -45,8 +46,7 @@ namespace Confuser.DynCipher.Generation { } SwapOperands(random, binExp.Left); SwapOperands(random, binExp.Right); - } - else if (exp is UnaryOpExpression) + } else if (exp is UnaryOpExpression) SwapOperands(random, ((UnaryOpExpression)exp).Value); else if (exp is LiteralExpression || exp is VariableExpression) return; @@ -64,11 +64,9 @@ namespace Confuser.DynCipher.Generation { else if (exp is BinOpExpression) { var binExp = (BinOpExpression)exp; ret = HasVariable(binExp.Left, hasVar) || HasVariable(binExp.Right, hasVar); - } - else if (exp is UnaryOpExpression) { + } else if (exp is UnaryOpExpression) { ret = HasVariable(((UnaryOpExpression)exp).Value, hasVar); - } - else + } else throw new UnreachableException(); hasVar[exp] = ret; } @@ -86,8 +84,7 @@ namespace Confuser.DynCipher.Generation { Value = result }; exp = unaryOp.Value; - } - else if (exp is BinOpExpression) { + } else if (exp is BinOpExpression) { var binOp = (BinOpExpression)exp; bool leftHasVar = hasVar[binOp.Left]; Expression varExp = leftHasVar ? binOp.Left : binOp.Right; @@ -108,8 +105,7 @@ namespace Confuser.DynCipher.Generation { Left = result, Right = constExp }; - } - else { + } else { // k - v = r => v = k - r result = new BinOpExpression { Operation = BinOps.Sub, @@ -117,9 +113,7 @@ namespace Confuser.DynCipher.Generation { Right = result }; } - } - - else if (binOp.Operation == BinOps.Mul) { + } else if (binOp.Operation == BinOps.Mul) { Debug.Assert(constExp is LiteralExpression); uint val = ((LiteralExpression)constExp).Value; val = MathsUtils.modInv(val); @@ -128,9 +122,7 @@ namespace Confuser.DynCipher.Generation { Left = result, Right = (LiteralExpression)val }; - } - - else if (binOp.Operation == BinOps.Xor) + } else if (binOp.Operation == BinOps.Xor) result = new BinOpExpression { Operation = BinOps.Xor, Left = result, diff --git a/Confuser.DynCipher/Generation/x86CodeGen.cs b/Confuser.DynCipher/Generation/x86CodeGen.cs index f27f283..b823282 100644 --- a/Confuser.DynCipher/Generation/x86CodeGen.cs +++ b/Confuser.DynCipher/Generation/x86CodeGen.cs @@ -27,8 +27,7 @@ namespace Confuser.DynCipher.Generation { try { return ((x86RegisterOperand)Emit(expression, loadArg)).Register; - } - catch (Exception ex) { + } catch (Exception ex) { if (ex.Message == "Register overflowed.") return null; throw; diff --git a/Confuser.DynCipher/Properties/AssemblyInfo.cs b/Confuser.DynCipher/Properties/AssemblyInfo.cs index 177421e..de693e3 100644 --- a/Confuser.DynCipher/Properties/AssemblyInfo.cs +++ b/Confuser.DynCipher/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; [assembly: AssemblyTitle("ConfuserEx Dynamic Cipher Library")] [assembly: AssemblyDescription("Cipher generator of ConfuserEx")] \ No newline at end of file diff --git a/Confuser.DynCipher/Transforms/ConvertVariables.cs b/Confuser.DynCipher/Transforms/ConvertVariables.cs index a7ed836..dd6c4d4 100644 --- a/Confuser.DynCipher/Transforms/ConvertVariables.cs +++ b/Confuser.DynCipher/Transforms/ConvertVariables.cs @@ -1,4 +1,5 @@ -using Confuser.DynCipher.AST; +using System; +using Confuser.DynCipher.AST; namespace Confuser.DynCipher.Transforms { internal class ConvertVariables { @@ -12,12 +13,10 @@ namespace Confuser.DynCipher.Transforms { } if (exp is ArrayIndexExpression) { ((ArrayIndexExpression)exp).Array = ReplaceVar(((ArrayIndexExpression)exp).Array, buff); - } - else if (exp is BinOpExpression) { + } else if (exp is BinOpExpression) { ((BinOpExpression)exp).Left = ReplaceVar(((BinOpExpression)exp).Left, buff); ((BinOpExpression)exp).Right = ReplaceVar(((BinOpExpression)exp).Right, buff); - } - else if (exp is UnaryOpExpression) { + } else if (exp is UnaryOpExpression) { ((UnaryOpExpression)exp).Value = ReplaceVar(((UnaryOpExpression)exp).Value, buff); } return exp; diff --git a/Confuser.DynCipher/Transforms/ExpansionTransform.cs b/Confuser.DynCipher/Transforms/ExpansionTransform.cs index b5e59a4..6ccc8f3 100644 --- a/Confuser.DynCipher/Transforms/ExpansionTransform.cs +++ b/Confuser.DynCipher/Transforms/ExpansionTransform.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Confuser.DynCipher.AST; namespace Confuser.DynCipher.Transforms { diff --git a/Confuser.DynCipher/Transforms/MulToShiftTransform.cs b/Confuser.DynCipher/Transforms/MulToShiftTransform.cs index 049898e..55f195f 100644 --- a/Confuser.DynCipher/Transforms/MulToShiftTransform.cs +++ b/Confuser.DynCipher/Transforms/MulToShiftTransform.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Confuser.DynCipher.AST; @@ -38,16 +39,13 @@ namespace Confuser.DynCipher.Transforms { x += i; return x; } - } - else { + } else { binOp.Left = ProcessExpression(binOp.Left); binOp.Right = ProcessExpression(binOp.Right); } - } - else if (exp is ArrayIndexExpression) { + } else if (exp is ArrayIndexExpression) { ((ArrayIndexExpression)exp).Array = ProcessExpression(((ArrayIndexExpression)exp).Array); - } - else if (exp is UnaryOpExpression) { + } else if (exp is UnaryOpExpression) { ((UnaryOpExpression)exp).Value = ProcessExpression(((UnaryOpExpression)exp).Value); } return exp; diff --git a/Confuser.DynCipher/Transforms/NormalizeBinOpTransform.cs b/Confuser.DynCipher/Transforms/NormalizeBinOpTransform.cs index 519539e..6270dd3 100644 --- a/Confuser.DynCipher/Transforms/NormalizeBinOpTransform.cs +++ b/Confuser.DynCipher/Transforms/NormalizeBinOpTransform.cs @@ -1,4 +1,5 @@ -using Confuser.DynCipher.AST; +using System; +using Confuser.DynCipher.AST; namespace Confuser.DynCipher.Transforms { internal class NormalizeBinOpTransform { @@ -25,11 +26,9 @@ namespace Confuser.DynCipher.Transforms { if (binOp.Right is LiteralExpression && ((LiteralExpression)binOp.Right).Value == 0 && binOp.Operation == BinOps.Add) // x + 0 => x return binOp.Left; - } - else if (exp is ArrayIndexExpression) { + } else if (exp is ArrayIndexExpression) { ((ArrayIndexExpression)exp).Array = ProcessExpression(((ArrayIndexExpression)exp).Array); - } - else if (exp is UnaryOpExpression) { + } else if (exp is UnaryOpExpression) { ((UnaryOpExpression)exp).Value = ProcessExpression(((UnaryOpExpression)exp).Value); } return exp; diff --git a/Confuser.DynCipher/Transforms/ShuffleTransform.cs b/Confuser.DynCipher/Transforms/ShuffleTransform.cs index f12f951..0722a68 100644 --- a/Confuser.DynCipher/Transforms/ShuffleTransform.cs +++ b/Confuser.DynCipher/Transforms/ShuffleTransform.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Confuser.Core.Services; using Confuser.DynCipher.AST; @@ -13,13 +14,11 @@ namespace Confuser.DynCipher.Transforms { else if (exp is ArrayIndexExpression) { foreach (Variable i in GetVariableUsage(((ArrayIndexExpression)exp).Array)) yield return i; - } - else if (exp is BinOpExpression) { + } else if (exp is BinOpExpression) { foreach (Variable i in GetVariableUsage(((BinOpExpression)exp).Left) .Concat(GetVariableUsage(((BinOpExpression)exp).Right))) yield return i; - } - else if (exp is UnaryOpExpression) { + } else if (exp is UnaryOpExpression) { foreach (Variable i in GetVariableUsage(((UnaryOpExpression)exp).Value)) yield return i; } diff --git a/Confuser.DynCipher/Utils.cs b/Confuser.DynCipher/Utils.cs index 74577b9..144a0e7 100644 --- a/Confuser.DynCipher/Utils.cs +++ b/Confuser.DynCipher/Utils.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using Confuser.DynCipher.Generation; namespace Confuser.DynCipher { diff --git a/Confuser.Protections/AntiDebugProtection.cs b/Confuser.Protections/AntiDebugProtection.cs index 5becf45..41cc3d7 100644 --- a/Confuser.Protections/AntiDebugProtection.cs +++ b/Confuser.Protections/AntiDebugProtection.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Confuser.Core; using Confuser.Core.Helpers; @@ -109,8 +110,7 @@ namespace Confuser.Protections { CustomAttribute ca = method.CustomAttributes.Find(attrName); if (ca != null) ca.Constructor = attr.FindMethod(".ctor"); - } - else if (member is FieldDef) { + } else if (member is FieldDef) { var field = (FieldDef)member; if (field.Access == FieldAttributes.Public) field.Access = FieldAttributes.Assembly; diff --git a/Confuser.Protections/AntiDumpProtection.cs b/Confuser.Protections/AntiDumpProtection.cs index eaf3710..fc3f065 100644 --- a/Confuser.Protections/AntiDumpProtection.cs +++ b/Confuser.Protections/AntiDumpProtection.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Confuser.Core; using Confuser.Core.Helpers; diff --git a/Confuser.Protections/AntiILDasmProtection.cs b/Confuser.Protections/AntiILDasmProtection.cs index dd270c4..bc6ff61 100644 --- a/Confuser.Protections/AntiILDasmProtection.cs +++ b/Confuser.Protections/AntiILDasmProtection.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Confuser.Core; using dnlib.DotNet; diff --git a/Confuser.Protections/AntiTamper/IKeyDeriver.cs b/Confuser.Protections/AntiTamper/IKeyDeriver.cs index ff5c2f4..a89fb95 100644 --- a/Confuser.Protections/AntiTamper/IKeyDeriver.cs +++ b/Confuser.Protections/AntiTamper/IKeyDeriver.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Confuser.Core; using Confuser.Core.Services; using dnlib.DotNet; diff --git a/Confuser.Protections/AntiTamper/IModeHandler.cs b/Confuser.Protections/AntiTamper/IModeHandler.cs index 4ac034e..c7ccc66 100644 --- a/Confuser.Protections/AntiTamper/IModeHandler.cs +++ b/Confuser.Protections/AntiTamper/IModeHandler.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; namespace Confuser.Protections.AntiTamper { internal interface IModeHandler { diff --git a/Confuser.Protections/AntiTamper/JITBody.cs b/Confuser.Protections/AntiTamper/JITBody.cs index 88018db..701234f 100644 --- a/Confuser.Protections/AntiTamper/JITBody.cs +++ b/Confuser.Protections/AntiTamper/JITBody.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; @@ -138,8 +139,7 @@ namespace Confuser.Protections.AntiTamper { if (body.Variables.Count > 0) { var local = new LocalSig(body.Variables.Select(var => var.Type).ToList()); jitBody.LocalVars = SignatureWriter.Write(metadata, local); - } - else + } else jitBody.LocalVars = new byte[0]; using (var ms = new MemoryStream()) { @@ -171,8 +171,7 @@ namespace Confuser.Protections.AntiTamper { jitBody.Options |= 0x80; jitBody.EHs[i].ClassTokenOrFilterOffset = token; - } - else if (eh.HandlerType == ExceptionHandlerType.Filter) { + } else if (eh.HandlerType == ExceptionHandlerType.Filter) { jitBody.EHs[i].ClassTokenOrFilterOffset = GetOffset(eh.FilterStart); } } diff --git a/Confuser.Protections/AntiTamper/NormalDeriver.cs b/Confuser.Protections/AntiTamper/NormalDeriver.cs index e5a4738..52ac662 100644 --- a/Confuser.Protections/AntiTamper/NormalDeriver.cs +++ b/Confuser.Protections/AntiTamper/NormalDeriver.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Confuser.Core; using Confuser.Core.Services; using dnlib.DotNet; diff --git a/Confuser.Protections/AntiTamper/NormalMode.cs b/Confuser.Protections/AntiTamper/NormalMode.cs index db23b70..36198f8 100644 --- a/Confuser.Protections/AntiTamper/NormalMode.cs +++ b/Confuser.Protections/AntiTamper/NormalMode.cs @@ -57,8 +57,7 @@ namespace Confuser.Protections.AntiTamper { Instruction instr = instrs[i]; if (instr.OpCode == OpCodes.Ldtoken) { instr.Operand = context.CurrentModule.GlobalType; - } - else if (instr.OpCode == OpCodes.Call) { + } else if (instr.OpCode == OpCodes.Call) { var method = (IMethod)instr.Operand; if (method.DeclaringType.Name == "Mutation" && method.Name == "Crypt") { @@ -100,8 +99,7 @@ namespace Confuser.Protections.AntiTamper { var writer = (ModuleWriter)sender; if (e.WriterEvent == ModuleWriterEvent.MDEndCreateTables) { CreateSections(writer); - } - else if (e.WriterEvent == ModuleWriterEvent.BeginStrongNameSign) { + } else if (e.WriterEvent == ModuleWriterEvent.BeginStrongNameSign) { EncryptSection(writer); } } @@ -185,8 +183,7 @@ namespace Confuser.Protections.AntiTamper { if (nameHash == name1 * name2) { encSize = reader.ReadUInt32(); encLoc = reader.ReadUInt32(); - } - else if (nameHash != 0) { + } else if (nameHash != 0) { uint sectSize = reader.ReadUInt32(); uint sectLoc = reader.ReadUInt32(); Hash(stream, reader, sectLoc, sectSize); diff --git a/Confuser.Protections/Compress/IKeyDeriver.cs b/Confuser.Protections/Compress/IKeyDeriver.cs index 68fb179..5284205 100644 --- a/Confuser.Protections/Compress/IKeyDeriver.cs +++ b/Confuser.Protections/Compress/IKeyDeriver.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Confuser.Core; using Confuser.Core.Services; using dnlib.DotNet; diff --git a/Confuser.Protections/Compress/NormalDeriver.cs b/Confuser.Protections/Compress/NormalDeriver.cs index 8a90dc9..1938497 100644 --- a/Confuser.Protections/Compress/NormalDeriver.cs +++ b/Confuser.Protections/Compress/NormalDeriver.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Confuser.Core; using Confuser.Core.Services; using dnlib.DotNet; diff --git a/Confuser.Protections/Compress/StubProtection.cs b/Confuser.Protections/Compress/StubProtection.cs index cdaaeb1..9cadee1 100644 --- a/Confuser.Protections/Compress/StubProtection.cs +++ b/Confuser.Protections/Compress/StubProtection.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.Security.Cryptography; using Confuser.Core; using dnlib.DotNet; @@ -55,25 +56,25 @@ namespace Confuser.Protections.Compress { protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { context.CurrentModuleWriterListener.OnWriterEvent += (sender, e) => { - if (e.WriterEvent == ModuleWriterEvent.MDBeginCreateTables) { - // Add key signature - var writer = (ModuleWriter)sender; - var prot = (StubProtection)Parent; - uint blob = writer.MetaData.BlobHeap.Add(prot.ctx.KeySig); - uint rid = writer.MetaData.TablesHeap.StandAloneSigTable.Add(new RawStandAloneSigRow(blob)); - Debug.Assert((0x11000000 | rid) == prot.ctx.KeyToken); + if (e.WriterEvent == ModuleWriterEvent.MDBeginCreateTables) { + // Add key signature + var writer = (ModuleWriter)sender; + var prot = (StubProtection)Parent; + uint blob = writer.MetaData.BlobHeap.Add(prot.ctx.KeySig); + uint rid = writer.MetaData.TablesHeap.StandAloneSigTable.Add(new RawStandAloneSigRow(blob)); + Debug.Assert((0x11000000 | rid) == prot.ctx.KeyToken); - // Add File reference - byte[] hash = SHA1.Create().ComputeHash(prot.ctx.OriginModule); - uint hashBlob = writer.MetaData.BlobHeap.Add(hash); + // Add File reference + byte[] hash = SHA1.Create().ComputeHash(prot.ctx.OriginModule); + uint hashBlob = writer.MetaData.BlobHeap.Add(hash); - MDTable fileTbl = writer.MetaData.TablesHeap.FileTable; - uint fileRid = fileTbl.Add(new RawFileRow( - (uint)FileAttributes.ContainsMetaData, - writer.MetaData.StringsHeap.Add("koi"), - hashBlob)); - } - }; + MDTable fileTbl = writer.MetaData.TablesHeap.FileTable; + uint fileRid = fileTbl.Add(new RawFileRow( + (uint)FileAttributes.ContainsMetaData, + writer.MetaData.StringsHeap.Add("koi"), + hashBlob)); + } + }; } } } diff --git a/Confuser.Protections/Constants/CEContext.cs b/Confuser.Protections/Constants/CEContext.cs index 842c919..edff388 100644 --- a/Confuser.Protections/Constants/CEContext.cs +++ b/Confuser.Protections/Constants/CEContext.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Confuser.Core; using Confuser.Core.Services; using Confuser.DynCipher; diff --git a/Confuser.Protections/Constants/ConstantProtection.cs b/Confuser.Protections/Constants/ConstantProtection.cs index 8350ef8..7a1fb5c 100644 --- a/Confuser.Protections/Constants/ConstantProtection.cs +++ b/Confuser.Protections/Constants/ConstantProtection.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Protections.Constants; using dnlib.DotNet; diff --git a/Confuser.Protections/Constants/DynamicMode.cs b/Confuser.Protections/Constants/DynamicMode.cs index 888e057..495469b 100644 --- a/Confuser.Protections/Constants/DynamicMode.cs +++ b/Confuser.Protections/Constants/DynamicMode.cs @@ -43,14 +43,14 @@ namespace Confuser.Protections.Constants { uint k1 = ctx.Random.NextUInt32() | 1; uint k2 = ctx.Random.NextUInt32(); MutationHelper.ReplacePlaceholder(decoder, arg => { - var repl = new List(); - repl.AddRange(arg); - repl.Add(Instruction.Create(OpCodes.Ldc_I4, (int)MathsUtils.modInv(k1))); - repl.Add(Instruction.Create(OpCodes.Mul)); - repl.Add(Instruction.Create(OpCodes.Ldc_I4, (int)k2)); - repl.Add(Instruction.Create(OpCodes.Xor)); - return repl.ToArray(); - }); + var repl = new List(); + repl.AddRange(arg); + repl.Add(Instruction.Create(OpCodes.Ldc_I4, (int)MathsUtils.modInv(k1))); + repl.Add(Instruction.Create(OpCodes.Mul)); + repl.Add(Instruction.Create(OpCodes.Ldc_I4, (int)k2)); + repl.Add(Instruction.Create(OpCodes.Xor)); + return repl.ToArray(); + }); return Tuple.Create(k1, k2); } diff --git a/Confuser.Protections/Constants/EncodePhase.cs b/Confuser.Protections/Constants/EncodePhase.cs index ca704fe..3493e07 100644 --- a/Confuser.Protections/Constants/EncodePhase.cs +++ b/Confuser.Protections/Constants/EncodePhase.cs @@ -45,24 +45,19 @@ namespace Confuser.Protections.Constants { foreach (var entry in ldc.WithProgress(context.Logger)) { if (entry.Key is string) { EncodeString(moduleCtx, (string)entry.Key, entry.Value); - } - else if (entry.Key is int) { + } else if (entry.Key is int) { EncodeConstant32(moduleCtx, (uint)(int)entry.Key, context.CurrentModule.CorLibTypes.Int32, entry.Value); - } - else if (entry.Key is long) { + } else if (entry.Key is long) { EncodeConstant64(moduleCtx, (uint)((long)entry.Key >> 32), (uint)(long)entry.Key, context.CurrentModule.CorLibTypes.Int64, entry.Value); - } - else if (entry.Key is float) { + } else if (entry.Key is float) { var t = new RTransform(); t.R4 = (float)entry.Key; EncodeConstant32(moduleCtx, t.Hi, context.CurrentModule.CorLibTypes.Single, entry.Value); - } - else if (entry.Key is double) { + } else if (entry.Key is double) { var t = new RTransform(); t.R8 = (double)entry.Key; EncodeConstant64(moduleCtx, t.Hi, t.Lo, context.CurrentModule.CorLibTypes.Double, entry.Value); - } - else + } else throw new UnreachableException(); context.CheckCancellation(); } @@ -115,14 +110,14 @@ namespace Confuser.Protections.Constants { new[] { 0, 1 }, new[] { encryptedBuffer.Length / 4, (int)keySeed }); MutationHelper.ReplacePlaceholder(moduleCtx.InitMethod, arg => { - var repl = new List(); - repl.AddRange(arg); - repl.Add(Instruction.Create(OpCodes.Dup)); - repl.Add(Instruction.Create(OpCodes.Ldtoken, moduleCtx.DataField)); - repl.Add(Instruction.Create(OpCodes.Call, moduleCtx.Module.Import( - typeof (RuntimeHelpers).GetMethod("InitializeArray")))); - return repl.ToArray(); - }); + var repl = new List(); + repl.AddRange(arg); + repl.Add(Instruction.Create(OpCodes.Dup)); + repl.Add(Instruction.Create(OpCodes.Ldtoken, moduleCtx.DataField)); + repl.Add(Instruction.Create(OpCodes.Call, moduleCtx.Module.Import( + typeof (RuntimeHelpers).GetMethod("InitializeArray")))); + return repl.ToArray(); + }); } private void EncodeString(CEContext moduleCtx, string value, List> references) { @@ -257,8 +252,7 @@ namespace Confuser.Protections.Constants { if (string.IsNullOrEmpty(operand) && (moduleCtx.Elements & EncodeElements.Primitive) == 0) continue; eligible = true; - } - else if (instr.OpCode == OpCodes.Call && (moduleCtx.Elements & EncodeElements.Initializers) != 0) { + } else if (instr.OpCode == OpCodes.Call && (moduleCtx.Elements & EncodeElements.Initializers) != 0) { var operand = (IMethod)instr.Operand; if (operand.DeclaringType.DefinitionAssembly.IsCorLib() && operand.DeclaringType.Namespace == "System.Runtime.CompilerServices" && @@ -295,27 +289,23 @@ namespace Confuser.Protections.Constants { Buffer.BlockCopy(dataField.InitialValue, 0, value, 4, dataField.InitialValue.Length); ldInit.AddListEntry(value, Tuple.Create(method, instr)); } - } - else if ((moduleCtx.Elements & EncodeElements.Numbers) != 0) { + } else if ((moduleCtx.Elements & EncodeElements.Numbers) != 0) { if (instr.OpCode == OpCodes.Ldc_I4) { var operand = (int)instr.Operand; if ((operand >= -1 && operand <= 8) && (moduleCtx.Elements & EncodeElements.Primitive) == 0) continue; eligible = true; - } - else if (instr.OpCode == OpCodes.Ldc_I8) { + } else if (instr.OpCode == OpCodes.Ldc_I8) { var operand = (long)instr.Operand; if ((operand >= -1 && operand <= 1) && (moduleCtx.Elements & EncodeElements.Primitive) == 0) continue; eligible = true; - } - else if (instr.OpCode == OpCodes.Ldc_R4) { + } else if (instr.OpCode == OpCodes.Ldc_R4) { var operand = (float)instr.Operand; if ((operand == -1 || operand == 0 || operand == 1) && (moduleCtx.Elements & EncodeElements.Primitive) == 0) continue; eligible = true; - } - else if (instr.OpCode == OpCodes.Ldc_R8) { + } else if (instr.OpCode == OpCodes.Ldc_R8) { var operand = (double)instr.Operand; if ((operand == -1 || operand == 0 || operand == 1) && (moduleCtx.Elements & EncodeElements.Primitive) == 0) continue; diff --git a/Confuser.Protections/Constants/IEncodeMode.cs b/Confuser.Protections/Constants/IEncodeMode.cs index deacc95..9df0aa6 100644 --- a/Confuser.Protections/Constants/IEncodeMode.cs +++ b/Confuser.Protections/Constants/IEncodeMode.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using dnlib.DotNet; using dnlib.DotNet.Emit; diff --git a/Confuser.Protections/Constants/InjectPhase.cs b/Confuser.Protections/Constants/InjectPhase.cs index 11b0fad..8ad5785 100644 --- a/Confuser.Protections/Constants/InjectPhase.cs +++ b/Confuser.Protections/Constants/InjectPhase.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using Confuser.Core; @@ -8,6 +9,7 @@ using Confuser.DynCipher; using Confuser.Renamer; using dnlib.DotNet; using dnlib.DotNet.Emit; +using dnlib.DotNet.MD; namespace Confuser.Protections.Constants { internal class InjectPhase : ProtectionPhase { @@ -50,8 +52,8 @@ namespace Confuser.Protections.Constants { break; case Mode.x86: moduleCtx.ModeHandler = new x86Mode(); - if ((context.CurrentModule.Cor20HeaderFlags & dnlib.DotNet.MD.ComImageFlags.ILOnly) != 0) - context.CurrentModuleWriterOptions.Cor20HeaderOptions.Flags &= ~dnlib.DotNet.MD.ComImageFlags.ILOnly; + if ((context.CurrentModule.Cor20HeaderFlags & ComImageFlags.ILOnly) != 0) + context.CurrentModuleWriterOptions.Cor20HeaderOptions.Flags &= ~ComImageFlags.ILOnly; break; default: throw new UnreachableException(); @@ -59,10 +61,10 @@ namespace Confuser.Protections.Constants { // Inject helpers MethodDef decomp = compression.GetRuntimeDecompressor(context.CurrentModule, member => { - name.MarkHelper(member, marker); - if (member is MethodDef) - ProtectionParameters.GetParameters(context, member).Remove(Parent); - }); + name.MarkHelper(member, marker); + if (member is MethodDef) + ProtectionParameters.GetParameters(context, member).Remove(Parent); + }); InjectHelpers(context, compression, rt, moduleCtx); // Mutate codes @@ -117,9 +119,8 @@ namespace Confuser.Protections.Constants { method.DeclaringType.Name == "Mutation" && method.Name == "Value") { decoderInst.Body.Instructions[j] = Instruction.Create(OpCodes.Sizeof, new GenericMVar(0).ToTypeDefOrRef()); - } - else if (instr.OpCode == OpCodes.Ldsfld && - method.DeclaringType.Name == "Constant") { + } else if (instr.OpCode == OpCodes.Ldsfld && + method.DeclaringType.Name == "Constant") { if (field.Name == "b") instr.Operand = moduleCtx.BufferField; else throw new UnreachableException(); } @@ -160,9 +161,8 @@ namespace Confuser.Protections.Constants { instrs.RemoveAt(i - 1); instrs.RemoveAt(i - 2); instrs.InsertRange(i - 2, moduleCtx.ModeHandler.EmitDecrypt(moduleCtx.InitMethod, moduleCtx, (Local)ldBlock.Operand, (Local)ldKey.Operand)); - } - else if (method.DeclaringType.Name == "Lzma" && - method.Name == "Decompress") { + } else if (method.DeclaringType.Name == "Lzma" && + method.Name == "Decompress") { instr.Operand = decomp; } } diff --git a/Confuser.Protections/Constants/Mode.cs b/Confuser.Protections/Constants/Mode.cs index 1fd250f..29cacb7 100644 --- a/Confuser.Protections/Constants/Mode.cs +++ b/Confuser.Protections/Constants/Mode.cs @@ -1,4 +1,6 @@ -namespace Confuser.Protections.Constants { +using System; + +namespace Confuser.Protections.Constants { internal enum Mode { Normal, Dynamic, diff --git a/Confuser.Protections/Constants/NormalMode.cs b/Confuser.Protections/Constants/NormalMode.cs index b8a90ad..cc4d8e6 100644 --- a/Confuser.Protections/Constants/NormalMode.cs +++ b/Confuser.Protections/Constants/NormalMode.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using Confuser.Core; using Confuser.Core.Helpers; @@ -34,14 +35,14 @@ namespace Confuser.Protections.Constants { uint k1 = ctx.Random.NextUInt32() | 1; uint k2 = ctx.Random.NextUInt32(); MutationHelper.ReplacePlaceholder(decoder, arg => { - var repl = new List(); - repl.AddRange(arg); - repl.Add(Instruction.Create(OpCodes.Ldc_I4, (int)MathsUtils.modInv(k1))); - repl.Add(Instruction.Create(OpCodes.Mul)); - repl.Add(Instruction.Create(OpCodes.Ldc_I4, (int)k2)); - repl.Add(Instruction.Create(OpCodes.Xor)); - return repl.ToArray(); - }); + var repl = new List(); + repl.AddRange(arg); + repl.Add(Instruction.Create(OpCodes.Ldc_I4, (int)MathsUtils.modInv(k1))); + repl.Add(Instruction.Create(OpCodes.Mul)); + repl.Add(Instruction.Create(OpCodes.Ldc_I4, (int)k2)); + repl.Add(Instruction.Create(OpCodes.Xor)); + return repl.ToArray(); + }); return Tuple.Create(k1, k2); } diff --git a/Confuser.Protections/Constants/x86Mode.cs b/Confuser.Protections/Constants/x86Mode.cs index b02348d..b3d56dd 100644 --- a/Confuser.Protections/Constants/x86Mode.cs +++ b/Confuser.Protections/Constants/x86Mode.cs @@ -44,11 +44,11 @@ namespace Confuser.Protections.Constants { var encoding = new x86Encoding(); encoding.Compile(ctx); MutationHelper.ReplacePlaceholder(decoder, arg => { - var repl = new List(); - repl.AddRange(arg); - repl.Add(Instruction.Create(OpCodes.Call, encoding.native)); - return repl.ToArray(); - }); + var repl = new List(); + repl.AddRange(arg); + repl.Add(Instruction.Create(OpCodes.Call, encoding.native)); + return repl.ToArray(); + }); return encoding; } @@ -125,8 +125,7 @@ namespace Confuser.Protections.Constants { var writer = (ModuleWriter)sender; if (e.WriterEvent == ModuleWriterEvent.MDEndWriteMethodBodies) { codeChunk = writer.MethodBodies.Add(new MethodBody(code)); - } - else if (e.WriterEvent == ModuleWriterEvent.EndCalculateRvasAndFileOffsets) { + } else if (e.WriterEvent == ModuleWriterEvent.EndCalculateRvasAndFileOffsets) { uint rid = writer.MetaData.GetRid(native); writer.MetaData.TablesHeap.MethodTable[rid].RVA = (uint)codeChunk.RVA; } diff --git a/Confuser.Protections/ControlFlow/BlockParser.cs b/Confuser.Protections/ControlFlow/BlockParser.cs index 772a620..fbbdd98 100644 --- a/Confuser.Protections/ControlFlow/BlockParser.cs +++ b/Confuser.Protections/ControlFlow/BlockParser.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using Confuser.Core; @@ -23,8 +24,7 @@ namespace Confuser.Protections.ControlFlow { if (eh.FilterStart != null) { var filterBlock = new ScopeBlock(BlockType.Filter, eh); ehScopes[eh] = Tuple.Create(tryBlock, handlerBlock, filterBlock); - } - else + } else ehScopes[eh] = Tuple.Create(tryBlock, handlerBlock, (ScopeBlock)null); } diff --git a/Confuser.Protections/ControlFlow/Blocks.cs b/Confuser.Protections/ControlFlow/Blocks.cs index 847d134..4819433 100644 --- a/Confuser.Protections/ControlFlow/Blocks.cs +++ b/Confuser.Protections/ControlFlow/Blocks.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Text; using dnlib.DotNet.Emit; @@ -71,11 +72,9 @@ namespace Confuser.Protections.ControlFlow { if (Type == BlockType.Try) { Handler.TryStart = GetFirstInstr(); Handler.TryEnd = GetLastInstr(); - } - else if (Type == BlockType.Filter) { + } else if (Type == BlockType.Filter) { Handler.FilterStart = GetFirstInstr(); - } - else { + } else { Handler.HandlerStart = GetFirstInstr(); Handler.HandlerEnd = GetLastInstr(); } diff --git a/Confuser.Protections/ControlFlow/CFContext.cs b/Confuser.Protections/ControlFlow/CFContext.cs index 1f92335..31fa5b2 100644 --- a/Confuser.Protections/ControlFlow/CFContext.cs +++ b/Confuser.Protections/ControlFlow/CFContext.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Confuser.Core; using Confuser.Core.Services; using Confuser.DynCipher; diff --git a/Confuser.Protections/ControlFlow/ControlFlowPhase.cs b/Confuser.Protections/ControlFlow/ControlFlowPhase.cs index 141f79a..3e6458a 100644 --- a/Confuser.Protections/ControlFlow/ControlFlowPhase.cs +++ b/Confuser.Protections/ControlFlow/ControlFlowPhase.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.Linq; using Confuser.Core; using Confuser.Core.Services; diff --git a/Confuser.Protections/ControlFlow/ControlFlowProtection.cs b/Confuser.Protections/ControlFlow/ControlFlowProtection.cs index b7408b2..bba86c2 100644 --- a/Confuser.Protections/ControlFlow/ControlFlowProtection.cs +++ b/Confuser.Protections/ControlFlow/ControlFlowProtection.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Protections.ControlFlow; using dnlib.DotNet; diff --git a/Confuser.Protections/ControlFlow/IPredicate.cs b/Confuser.Protections/ControlFlow/IPredicate.cs index 42bc2d8..4dc1152 100644 --- a/Confuser.Protections/ControlFlow/IPredicate.cs +++ b/Confuser.Protections/ControlFlow/IPredicate.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using dnlib.DotNet.Emit; namespace Confuser.Protections.ControlFlow { diff --git a/Confuser.Protections/ControlFlow/JumpMangler.cs b/Confuser.Protections/ControlFlow/JumpMangler.cs index 28e9901..a01b106 100644 --- a/Confuser.Protections/ControlFlow/JumpMangler.cs +++ b/Confuser.Protections/ControlFlow/JumpMangler.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using dnlib.DotNet.Emit; diff --git a/Confuser.Protections/ControlFlow/ManglerBase.cs b/Confuser.Protections/ControlFlow/ManglerBase.cs index e719354..8e42e29 100644 --- a/Confuser.Protections/ControlFlow/ManglerBase.cs +++ b/Confuser.Protections/ControlFlow/ManglerBase.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using dnlib.DotNet.Emit; namespace Confuser.Protections.ControlFlow { diff --git a/Confuser.Protections/ControlFlow/SwitchMangler.cs b/Confuser.Protections/ControlFlow/SwitchMangler.cs index 04c5f30..c972a7e 100644 --- a/Confuser.Protections/ControlFlow/SwitchMangler.cs +++ b/Confuser.Protections/ControlFlow/SwitchMangler.cs @@ -109,8 +109,7 @@ namespace Confuser.Protections.ControlFlow { predicate.Init(body); switchHdr.Add(Instruction.CreateLdcI4(predicate.GetSwitchKey(key[1]))); predicate.EmitSwitchLoad(switchHdr); - } - else { + } else { switchHdr.Add(Instruction.CreateLdcI4(key[1])); } @@ -143,9 +142,7 @@ namespace Confuser.Protections.ControlFlow { operands[key[i]] = newStatement[0]; converted = true; } - } - - else if (newStatement.Last().IsConditionalBranch()) { + } else if (newStatement.Last().IsConditionalBranch()) { // Conditional var target = (Instruction)newStatement.Last().Operand; @@ -189,8 +186,7 @@ namespace Confuser.Protections.ControlFlow { ctx.AddJunk(newStatement); operands[key[i]] = newStatement[0]; } - } - else + } else operands[key[i]] = switchHdr[0]; current.Value = newStatement.ToArray(); diff --git a/Confuser.Protections/ControlFlow/x86Predicate.cs b/Confuser.Protections/ControlFlow/x86Predicate.cs index c7166db..7964033 100644 --- a/Confuser.Protections/ControlFlow/x86Predicate.cs +++ b/Confuser.Protections/ControlFlow/x86Predicate.cs @@ -95,8 +95,7 @@ namespace Confuser.Protections.ControlFlow { var writer = (ModuleWriter)sender; if (e.WriterEvent == ModuleWriterEvent.MDEndWriteMethodBodies) { codeChunk = writer.MethodBodies.Add(new MethodBody(code)); - } - else if (e.WriterEvent == ModuleWriterEvent.EndCalculateRvasAndFileOffsets) { + } else if (e.WriterEvent == ModuleWriterEvent.EndCalculateRvasAndFileOffsets) { uint rid = writer.MetaData.GetRid(native); writer.MetaData.TablesHeap.MethodTable[rid].RVA = (uint)codeChunk.RVA; } diff --git a/Confuser.Protections/InvalidMetadataProtection.cs b/Confuser.Protections/InvalidMetadataProtection.cs index 5182ab3..e96d0db 100644 --- a/Confuser.Protections/InvalidMetadataProtection.cs +++ b/Confuser.Protections/InvalidMetadataProtection.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using Confuser.Core; @@ -118,8 +119,7 @@ namespace Confuser.Protections { writer.Options.MetaDataOptions.OtherHeapsEnd.Add(new RawHeap("#Strings", new byte[1])); writer.Options.MetaDataOptions.OtherHeapsEnd.Add(new RawHeap("#Blob", new byte[1])); writer.Options.MetaDataOptions.OtherHeapsEnd.Add(new RawHeap("#Schema", new byte[1])); - } - else if (e.WriterEvent == ModuleWriterEvent.MDOnAllTablesSorted) { + } else if (e.WriterEvent == ModuleWriterEvent.MDOnAllTablesSorted) { writer.MetaData.TablesHeap.DeclSecurityTable.Add(new RawDeclSecurityRow( unchecked(0x7fff), 0xffff7fff, 0xffff7fff)); /* diff --git a/Confuser.Protections/Properties/AssemblyInfo.cs b/Confuser.Protections/Properties/AssemblyInfo.cs index 84a665c..142f8fe 100644 --- a/Confuser.Protections/Properties/AssemblyInfo.cs +++ b/Confuser.Protections/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; [assembly: AssemblyTitle("ConfuserEx Protections")] [assembly: AssemblyDescription("Protections and packers of ConfuserEx")] \ No newline at end of file diff --git a/Confuser.Protections/ReferenceProxy/ExpressionEncoding.cs b/Confuser.Protections/ReferenceProxy/ExpressionEncoding.cs index c77a8db..96f15fb 100644 --- a/Confuser.Protections/ReferenceProxy/ExpressionEncoding.cs +++ b/Confuser.Protections/ReferenceProxy/ExpressionEncoding.cs @@ -62,8 +62,7 @@ namespace Confuser.Protections.ReferenceProxy { if (var.Name == "{RESULT}") { foreach (Instruction instr in arg) base.Emit(instr); - } - else + } else base.LoadVar(var); } } diff --git a/Confuser.Protections/ReferenceProxy/IRPEncoding.cs b/Confuser.Protections/ReferenceProxy/IRPEncoding.cs index dda1bf5..0c16e62 100644 --- a/Confuser.Protections/ReferenceProxy/IRPEncoding.cs +++ b/Confuser.Protections/ReferenceProxy/IRPEncoding.cs @@ -1,4 +1,5 @@ -using dnlib.DotNet; +using System; +using dnlib.DotNet; using dnlib.DotNet.Emit; namespace Confuser.Protections.ReferenceProxy { diff --git a/Confuser.Protections/ReferenceProxy/MildMode.cs b/Confuser.Protections/ReferenceProxy/MildMode.cs index 4b3f57c..4d28366 100644 --- a/Confuser.Protections/ReferenceProxy/MildMode.cs +++ b/Confuser.Protections/ReferenceProxy/MildMode.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Confuser.Core; using dnlib.DotNet; using dnlib.DotNet.Emit; @@ -60,8 +61,7 @@ namespace Confuser.Protections.ReferenceProxy { proxy.Name, proxy.MethodSig, new GenericInstSig((ClassOrValueTypeSig)ctx.Method.DeclaringType.ToTypeSig(), genArgs).ToTypeDefOrRef()); - } - else + } else invoke.Operand = proxy; } diff --git a/Confuser.Protections/ReferenceProxy/NormalEncoding.cs b/Confuser.Protections/ReferenceProxy/NormalEncoding.cs index 57a7834..ab984ba 100644 --- a/Confuser.Protections/ReferenceProxy/NormalEncoding.cs +++ b/Confuser.Protections/ReferenceProxy/NormalEncoding.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Confuser.Core; using Confuser.Core.Services; using Confuser.DynCipher; @@ -15,8 +16,7 @@ namespace Confuser.Protections.ReferenceProxy { if (ctx.Random.NextBoolean()) { ret.Add(Instruction.Create(OpCodes.Ldc_I4, key.Item1)); ret.AddRange(arg); - } - else { + } else { ret.AddRange(arg); ret.Add(Instruction.Create(OpCodes.Ldc_I4, key.Item1)); } diff --git a/Confuser.Protections/ReferenceProxy/RPContext.cs b/Confuser.Protections/ReferenceProxy/RPContext.cs index 77ae8d7..a7f88d4 100644 --- a/Confuser.Protections/ReferenceProxy/RPContext.cs +++ b/Confuser.Protections/ReferenceProxy/RPContext.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Confuser.Core; using Confuser.Core.Services; using Confuser.DynCipher; diff --git a/Confuser.Protections/ReferenceProxy/RPMode.cs b/Confuser.Protections/ReferenceProxy/RPMode.cs index 1879b44..8a80cb8 100644 --- a/Confuser.Protections/ReferenceProxy/RPMode.cs +++ b/Confuser.Protections/ReferenceProxy/RPMode.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using Confuser.Core; @@ -24,10 +25,10 @@ namespace Confuser.Protections.ReferenceProxy { Debug.Assert(method.MethodSig.HasThis); Debug.Assert(method.Name == ".ctor"); TypeSig[] paramTypes = method.MethodSig.Params.Select(type => { - if (ctx.TypeErasure && type.IsClassSig && method.MethodSig.HasThis) - return module.CorLibTypes.Object; - return type; - }).ToArray(); + if (ctx.TypeErasure && type.IsClassSig && method.MethodSig.HasThis) + return module.CorLibTypes.Object; + return type; + }).ToArray(); TypeSig retType; if (ctx.TypeErasure) // newobj will not be used with value types @@ -37,13 +38,12 @@ namespace Confuser.Protections.ReferenceProxy { retType = Import(ctx, declType).ToTypeSig(); } return MethodSig.CreateStatic(retType, paramTypes); - } - else { + } else { IEnumerable paramTypes = method.MethodSig.Params.Select(type => { - if (ctx.TypeErasure && type.IsClassSig && method.MethodSig.HasThis) - return module.CorLibTypes.Object; - return type; - }); + if (ctx.TypeErasure && type.IsClassSig && method.MethodSig.HasThis) + return module.CorLibTypes.Object; + return type; + }); if (method.MethodSig.HasThis && !method.MethodSig.ExplicitThis) { TypeDef declType = method.DeclaringType.ResolveTypeDefThrow(); if (ctx.TypeErasure && !declType.IsValueType) diff --git a/Confuser.Protections/ReferenceProxy/ReferenceProxyPhase.cs b/Confuser.Protections/ReferenceProxy/ReferenceProxyPhase.cs index 0c13f39..6e0435b 100644 --- a/Confuser.Protections/ReferenceProxy/ReferenceProxyPhase.cs +++ b/Confuser.Protections/ReferenceProxy/ReferenceProxyPhase.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Confuser.Core; using Confuser.Core.Services; @@ -6,6 +7,7 @@ using Confuser.DynCipher; using Confuser.Renamer; using dnlib.DotNet; using dnlib.DotNet.Emit; +using dnlib.DotNet.MD; namespace Confuser.Protections.ReferenceProxy { internal class ReferenceProxyPhase : ProtectionPhase { @@ -67,10 +69,10 @@ namespace Confuser.Protections.ReferenceProxy { break; case EncodingType.x86: ret.EncodingHandler = store.x86 ?? (store.x86 = new x86Encoding()); - - if ((context.CurrentModule.Cor20HeaderFlags & dnlib.DotNet.MD.ComImageFlags.ILOnly) != 0) - context.CurrentModuleWriterOptions.Cor20HeaderOptions.Flags &= ~dnlib.DotNet.MD.ComImageFlags.ILOnly; - break; + + if ((context.CurrentModule.Cor20HeaderFlags & ComImageFlags.ILOnly) != 0) + context.CurrentModuleWriterOptions.Cor20HeaderOptions.Flags &= ~ComImageFlags.ILOnly; + break; default: throw new UnreachableException(); } diff --git a/Confuser.Protections/ReferenceProxy/ReferenceProxyProtection.cs b/Confuser.Protections/ReferenceProxy/ReferenceProxyProtection.cs index b406188..3a411ff 100644 --- a/Confuser.Protections/ReferenceProxy/ReferenceProxyProtection.cs +++ b/Confuser.Protections/ReferenceProxy/ReferenceProxyProtection.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Protections.ReferenceProxy; using dnlib.DotNet; diff --git a/Confuser.Protections/ReferenceProxy/StrongMode.cs b/Confuser.Protections/ReferenceProxy/StrongMode.cs index 5b8394e..ca211ec 100644 --- a/Confuser.Protections/ReferenceProxy/StrongMode.cs +++ b/Confuser.Protections/ReferenceProxy/StrongMode.cs @@ -78,8 +78,7 @@ namespace Confuser.Protections.ReferenceProxy { if (fallBack) { ProcessBridge(ctx, instrIndex); - } - else { + } else { ProcessInvoke(ctx, instrIndex, begin.Value); } } @@ -102,8 +101,7 @@ namespace Confuser.Protections.ReferenceProxy { instr.Operand = proxy.Item2; return; } - } - else + } else proxy = new Tuple(null, null); MethodSig sig = CreateProxySignature(ctx, target, instr.OpCode.Code == Code.Newobj); @@ -145,8 +143,7 @@ namespace Confuser.Protections.ReferenceProxy { new Instruction(OpCodes.Call, delegateType.FindMethod("Invoke"))); instr.OpCode = OpCodes.Ldsfld; instr.Operand = proxy.Item1; - } - else { + } else { Instruction argBegin = ctx.Body.Instructions[argBeginIndex]; ctx.Body.Instructions.Insert(argBeginIndex + 1, new Instruction(argBegin.OpCode, argBegin.Operand)); @@ -223,10 +220,10 @@ namespace Confuser.Protections.ReferenceProxy { MethodDef ctor = injectedAttr.FindMethod(".ctor"); MutationHelper.ReplacePlaceholder(ctor, arg => { - var invCompiled = new List(); - new CodeGen(arg, ctor, invCompiled).GenerateCIL(inverse); - return invCompiled.ToArray(); - }); + var invCompiled = new List(); + new CodeGen(arg, ctor, invCompiled).GenerateCIL(inverse); + return invCompiled.ToArray(); + }); keyAttrs[index] = Tuple.Create(injectedAttr, expCompiled); ctx.Module.AddAsNonNestedType(injectedAttr); @@ -235,8 +232,7 @@ namespace Confuser.Protections.ReferenceProxy { if (def.Name == "GetHashCode") { ctx.Name.MarkHelper(def, ctx.Marker); ((MethodDef)def).Access = MethodAttributes.Public; - } - else + } else ctx.Name.MarkHelper(def, ctx.Marker); } } @@ -385,8 +381,7 @@ namespace Confuser.Protections.ReferenceProxy { if (var.Name == "{RESULT}") { foreach (Instruction instr in arg) base.Emit(instr); - } - else + } else base.LoadVar(var); } } diff --git a/Confuser.Protections/ReferenceProxy/x86Encoding.cs b/Confuser.Protections/ReferenceProxy/x86Encoding.cs index 6de614b..aebd700 100644 --- a/Confuser.Protections/ReferenceProxy/x86Encoding.cs +++ b/Confuser.Protections/ReferenceProxy/x86Encoding.cs @@ -73,8 +73,7 @@ namespace Confuser.Protections.ReferenceProxy { if (e.WriterEvent == ModuleWriterEvent.MDEndWriteMethodBodies) { foreach (var native in nativeCodes) native.Item3 = writer.MethodBodies.Add(new MethodBody(native.Item2)); - } - else if (e.WriterEvent == ModuleWriterEvent.EndCalculateRvasAndFileOffsets) { + } else if (e.WriterEvent == ModuleWriterEvent.EndCalculateRvasAndFileOffsets) { foreach (var native in nativeCodes) { uint rid = writer.MetaData.GetRid(native.Item1); writer.MetaData.TablesHeap.MethodTable[rid].RVA = (uint)native.Item3.RVA; @@ -105,8 +104,7 @@ namespace Confuser.Protections.ReferenceProxy { if (var.Name == "{RESULT}") { foreach (Instruction instr in arg) base.Emit(instr); - } - else + } else base.LoadVar(var); } } diff --git a/Confuser.Protections/Resources/IEncodeMode.cs b/Confuser.Protections/Resources/IEncodeMode.cs index 883cdae..5fd04c2 100644 --- a/Confuser.Protections/Resources/IEncodeMode.cs +++ b/Confuser.Protections/Resources/IEncodeMode.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using dnlib.DotNet; using dnlib.DotNet.Emit; diff --git a/Confuser.Protections/Resources/InjectPhase.cs b/Confuser.Protections/Resources/InjectPhase.cs index f4e1bc7..b30cf84 100644 --- a/Confuser.Protections/Resources/InjectPhase.cs +++ b/Confuser.Protections/Resources/InjectPhase.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; @@ -54,10 +55,10 @@ namespace Confuser.Protections.Resources { // Inject helpers MethodDef decomp = compression.GetRuntimeDecompressor(context.CurrentModule, member => { - name.MarkHelper(member, marker); - if (member is MethodDef) - ProtectionParameters.GetParameters(context, member).Remove(Parent); - }); + name.MarkHelper(member, marker); + if (member is MethodDef) + ProtectionParameters.GetParameters(context, member).Remove(Parent); + }); InjectHelpers(context, compression, rt, moduleCtx); // Mutate codes @@ -113,9 +114,8 @@ namespace Confuser.Protections.Resources { instrs.RemoveAt(i - 1); instrs.RemoveAt(i - 2); instrs.InsertRange(i - 2, moduleCtx.ModeHandler.EmitDecrypt(moduleCtx.InitMethod, moduleCtx, (Local)ldBlock.Operand, (Local)ldKey.Operand)); - } - else if (method.DeclaringType.Name == "Lzma" && - method.Name == "Decompress") { + } else if (method.DeclaringType.Name == "Lzma" && + method.Name == "Decompress") { instr.Operand = decomp; } } @@ -125,14 +125,14 @@ namespace Confuser.Protections.Resources { moduleCtx.InitMethod.Body.Instructions.Add(instr); MutationHelper.ReplacePlaceholder(moduleCtx.InitMethod, arg => { - var repl = new List(); - repl.AddRange(arg); - repl.Add(Instruction.Create(OpCodes.Dup)); - repl.Add(Instruction.Create(OpCodes.Ldtoken, moduleCtx.DataField)); - repl.Add(Instruction.Create(OpCodes.Call, moduleCtx.Module.Import( - typeof (RuntimeHelpers).GetMethod("InitializeArray")))); - return repl.ToArray(); - }); + var repl = new List(); + repl.AddRange(arg); + repl.Add(Instruction.Create(OpCodes.Dup)); + repl.Add(Instruction.Create(OpCodes.Ldtoken, moduleCtx.DataField)); + repl.Add(Instruction.Create(OpCodes.Call, moduleCtx.Module.Import( + typeof (RuntimeHelpers).GetMethod("InitializeArray")))); + return repl.ToArray(); + }); moduleCtx.Context.Registry.GetService().ExcludeMethod(moduleCtx.Context, moduleCtx.InitMethod); } } diff --git a/Confuser.Protections/Resources/Mode.cs b/Confuser.Protections/Resources/Mode.cs index 22f60ae..f32d313 100644 --- a/Confuser.Protections/Resources/Mode.cs +++ b/Confuser.Protections/Resources/Mode.cs @@ -1,4 +1,6 @@ -namespace Confuser.Protections.Resources { +using System; + +namespace Confuser.Protections.Resources { internal enum Mode { Normal, Dynamic diff --git a/Confuser.Protections/Resources/NormalMode.cs b/Confuser.Protections/Resources/NormalMode.cs index 99c1788..bd37689 100644 --- a/Confuser.Protections/Resources/NormalMode.cs +++ b/Confuser.Protections/Resources/NormalMode.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using dnlib.DotNet; using dnlib.DotNet.Emit; diff --git a/Confuser.Protections/Resources/REContext.cs b/Confuser.Protections/Resources/REContext.cs index b411864..0166c8b 100644 --- a/Confuser.Protections/Resources/REContext.cs +++ b/Confuser.Protections/Resources/REContext.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Core.Services; using Confuser.DynCipher; using Confuser.Renamer; diff --git a/Confuser.Protections/Resources/ResourceProtection.cs b/Confuser.Protections/Resources/ResourceProtection.cs index 5015ab7..d9f4df5 100644 --- a/Confuser.Protections/Resources/ResourceProtection.cs +++ b/Confuser.Protections/Resources/ResourceProtection.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Protections.Resources; namespace Confuser.Protections { diff --git a/Confuser.Renamer/AnalyzePhase.cs b/Confuser.Renamer/AnalyzePhase.cs index f2c3964..d05cee8 100644 --- a/Confuser.Renamer/AnalyzePhase.cs +++ b/Confuser.Renamer/AnalyzePhase.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Confuser.Core; using dnlib.DotNet; @@ -35,8 +36,7 @@ namespace Confuser.Renamer { var module = (ModuleDef)def; foreach (Resource res in module.Resources) service.SetOriginalName(res, res.Name); - } - else + } else service.SetOriginalName(def, def.Name); if (def is TypeDef) { @@ -68,7 +68,7 @@ namespace Confuser.Renamer { else if (def is ModuleDef) service.SetCanRename(def, false); - if (!runAnalyzer || parameters.GetParameter(context, def, "forceRen", false)) + if (!runAnalyzer || parameters.GetParameter(context, def, "forceRen", false)) return; foreach (IRenamer renamer in service.Renamers) @@ -76,18 +76,16 @@ namespace Confuser.Renamer { } private void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, TypeDef type) { - if (type.IsVisibleOutside() && !parameters.GetParameter(context, type, "renPublic", false)) { + if (type.IsVisibleOutside() && !parameters.GetParameter(context, type, "renPublic", false)) { service.SetCanRename(type, false); - } - else if (type.IsRuntimeSpecialName || type.IsSpecialName) { + } else if (type.IsRuntimeSpecialName || type.IsSpecialName) { service.SetCanRename(type, false); - } - else if (type.FullName == "ConfusedByAttribute") { + } else if (type.FullName == "ConfusedByAttribute") { // Courtesy service.SetCanRename(type, false); } - if (parameters.GetParameter(context, type, "forceRen", false)) + if (parameters.GetParameter(context, type, "forceRen", false)) return; if (type.InheritsFromCorlib("System.Attribute")) { @@ -97,14 +95,14 @@ namespace Confuser.Renamer { private void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, MethodDef method) { if (method.DeclaringType.IsVisibleOutside() && - (method.IsFamily || method.IsFamilyOrAssembly || method.IsPublic) && - !parameters.GetParameter(context, method, "renPublic", false)) + (method.IsFamily || method.IsFamilyOrAssembly || method.IsPublic) && + !parameters.GetParameter(context, method, "renPublic", false)) service.SetCanRename(method, false); else if (method.IsRuntimeSpecialName || method.IsSpecialName) service.SetCanRename(method, false); - else if (parameters.GetParameter(context, method, "forceRen", false)) + else if (parameters.GetParameter(context, method, "forceRen", false)) return; else if (method.DeclaringType.IsComImport() && !method.HasAttribute("System.Runtime.InteropServices.DispIdAttribute")) @@ -116,8 +114,8 @@ namespace Confuser.Renamer { private void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, FieldDef field) { if (field.DeclaringType.IsVisibleOutside() && - (field.IsFamily || field.IsFamilyOrAssembly || field.IsPublic) && - !parameters.GetParameter(context, field, "renPublic", false)) + (field.IsFamily || field.IsFamilyOrAssembly || field.IsPublic) && + !parameters.GetParameter(context, field, "renPublic", false)) service.SetCanRename(field, false); else if (field.IsRuntimeSpecialName || field.IsSpecialName) @@ -126,13 +124,13 @@ namespace Confuser.Renamer { private void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, PropertyDef property) { if (property.DeclaringType.IsVisibleOutside() && - !parameters.GetParameter(context, property, "renPublic", false)) + !parameters.GetParameter(context, property, "renPublic", false)) service.SetCanRename(property, false); else if (property.IsRuntimeSpecialName || property.IsSpecialName) service.SetCanRename(property, false); - else if (parameters.GetParameter(context, property, "forceRen", false)) + else if (parameters.GetParameter(context, property, "forceRen", false)) return; else if (property.DeclaringType.Implements("System.ComponentModel.INotifyPropertyChanged")) @@ -144,7 +142,7 @@ namespace Confuser.Renamer { private void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, EventDef evt) { if (evt.DeclaringType.IsVisibleOutside() && - !parameters.GetParameter(context, evt, "renPublic", false)) + !parameters.GetParameter(context, evt, "renPublic", false)) service.SetCanRename(evt, false); else if (evt.IsRuntimeSpecialName || evt.IsSpecialName) diff --git a/Confuser.Renamer/Analyzers/InterReferenceAnalyzer.cs b/Confuser.Renamer/Analyzers/InterReferenceAnalyzer.cs index ae53309..e7f0663 100644 --- a/Confuser.Renamer/Analyzers/InterReferenceAnalyzer.cs +++ b/Confuser.Renamer/Analyzers/InterReferenceAnalyzer.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Renamer.References; using dnlib.DotNet; using dnlib.DotNet.MD; diff --git a/Confuser.Renamer/Analyzers/LdtokenEnumAnalyzer.cs b/Confuser.Renamer/Analyzers/LdtokenEnumAnalyzer.cs index 1a20757..3a7d130 100644 --- a/Confuser.Renamer/Analyzers/LdtokenEnumAnalyzer.cs +++ b/Confuser.Renamer/Analyzers/LdtokenEnumAnalyzer.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using dnlib.DotNet; using dnlib.DotNet.Emit; @@ -20,30 +21,25 @@ namespace Confuser.Renamer.Analyzers { IMemberForwarded member = ((MemberRef)instr.Operand).ResolveThrow(); if (context.Modules.Contains((ModuleDefMD)member.Module)) service.SetCanRename(member, false); - } - else if (instr.Operand is IField) { + } else if (instr.Operand is IField) { FieldDef field = ((IField)instr.Operand).ResolveThrow(); if (context.Modules.Contains((ModuleDefMD)field.Module)) service.SetCanRename(field, false); - } - else if (instr.Operand is IMethod) { + } else if (instr.Operand is IMethod) { MethodDef m = ((IMethod)instr.Operand).ResolveThrow(); if (context.Modules.Contains((ModuleDefMD)m.Module)) service.SetCanRename(method, false); - } - else if (instr.Operand is ITypeDefOrRef) { + } else if (instr.Operand is ITypeDefOrRef) { if (!(instr.Operand is TypeSpec)) { TypeDef type = ((ITypeDefOrRef)instr.Operand).ResolveTypeDefThrow(); if (context.Modules.Contains((ModuleDefMD)type.Module) && HandleTypeOf(context, service, method, i)) DisableRename(service, type, false); } - } - else + } else throw new UnreachableException(); - } - else if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt) && - ((IMethod)instr.Operand).Name == "ToString") { + } else if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt) && + ((IMethod)instr.Operand).Name == "ToString") { HandleEnum(context, service, method, i); } } @@ -74,8 +70,7 @@ namespace Confuser.Renamer.Analyzers { if (prevInstr.Operand is MemberRef) { var memberRef = (MemberRef)prevInstr.Operand; targetType = memberRef.IsFieldRef ? memberRef.FieldSig.Type : memberRef.MethodSig.RetType; - } - else if (prevInstr.Operand is IField) + } else if (prevInstr.Operand is IField) targetType = ((IField)prevInstr.Operand).FieldSig.Type; else if (prevInstr.Operand is IMethod) diff --git a/Confuser.Renamer/Analyzers/ResourceAnalyzer.cs b/Confuser.Renamer/Analyzers/ResourceAnalyzer.cs index 87e0544..fc78d57 100644 --- a/Confuser.Renamer/Analyzers/ResourceAnalyzer.cs +++ b/Confuser.Renamer/Analyzers/ResourceAnalyzer.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Text.RegularExpressions; using Confuser.Core; using Confuser.Renamer.References; @@ -37,8 +38,7 @@ namespace Confuser.Renamer.Analyzers { } service.AddReference(type, new ResourceReference(res, type, format)); } - } - else { + } else { string format = "{0}.resources"; foreach (Resource res in module.Resources) { Match match = ResourceNamePattern.Match(res.Name); diff --git a/Confuser.Renamer/Analyzers/TypeBlobAnalyzer.cs b/Confuser.Renamer/Analyzers/TypeBlobAnalyzer.cs index 810b469..33409b5 100644 --- a/Confuser.Renamer/Analyzers/TypeBlobAnalyzer.cs +++ b/Confuser.Renamer/Analyzers/TypeBlobAnalyzer.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using Confuser.Core; @@ -102,8 +103,7 @@ namespace Confuser.Renamer.Analyzers { service.ReduceRenameMode(typeDef, RenameMode.ASCII); } } - } - else if (arg.Value is CAArgument[]) { + } else if (arg.Value is CAArgument[]) { foreach (CAArgument elem in (CAArgument[])arg.Value) AnalyzeCAArgument(context, service, elem); } diff --git a/Confuser.Renamer/Analyzers/VTableAnalyzer.cs b/Confuser.Renamer/Analyzers/VTableAnalyzer.cs index 05103ed..3531b8a 100644 --- a/Confuser.Renamer/Analyzers/VTableAnalyzer.cs +++ b/Confuser.Renamer/Analyzers/VTableAnalyzer.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using Confuser.Core; using Confuser.Renamer.References; @@ -18,8 +19,7 @@ namespace Confuser.Renamer.Analyzers { if (method.IsAbstract) { service.SetCanRename(method, false); - } - else { + } else { foreach (VTableSlot baseSlot in slot.Overrides) { // Better on safe side, add references to both methods. service.AddReference(method, new OverrideDirectiveReference(slot, baseSlot)); diff --git a/Confuser.Renamer/Analyzers/WPFAnalyzer.cs b/Confuser.Renamer/Analyzers/WPFAnalyzer.cs index fabcdbf..8fb2fad 100644 --- a/Confuser.Renamer/Analyzers/WPFAnalyzer.cs +++ b/Confuser.Renamer/Analyzers/WPFAnalyzer.cs @@ -91,10 +91,8 @@ namespace Confuser.Renamer.Analyzers { if (regMethod.DeclaringType.FullName == "System.Windows.DependencyProperty" && regMethod.Name.String.StartsWith("Register")) { dpRegInstrs.Add(Tuple.Create(regMethod.Name.String.StartsWith("RegisterAttached"), instr)); - } - - else if (regMethod.DeclaringType.FullName == "System.Windows.EventManager" && - regMethod.Name.String == "RegisterRoutedEvent") { + } else if (regMethod.DeclaringType.FullName == "System.Windows.EventManager" && + regMethod.Name.String == "RegisterRoutedEvent") { routedEvtRegInstrs.Add(instr); } } diff --git a/Confuser.Renamer/BAML/BAMLAnalyzer.cs b/Confuser.Renamer/BAML/BAMLAnalyzer.cs index 4076b88..719761b 100644 --- a/Confuser.Renamer/BAML/BAMLAnalyzer.cs +++ b/Confuser.Renamer/BAML/BAMLAnalyzer.cs @@ -52,8 +52,7 @@ namespace Confuser.Renamer.BAML { this.bamlName = bamlName; if (module.IsClr40) { things = thingsv4 ?? (thingsv4 = new KnownThingsv4(context, module)); - } - else { + } else { things = thingsv3 ?? (thingsv3 = new KnownThingsv3(context, module)); } @@ -127,8 +126,7 @@ namespace Confuser.Renamer.BAML { if (typeRefs.TryGetValue(rec.OwnerTypeId, out declType)) { TypeDef type = declType.ToBasicTypeDefOrRef().ResolveTypeDefThrow(); attrRefs[rec.AttributeId] = AnalyzeAttributeReference(type, rec); - } - else { + } else { Debug.Assert((short)rec.OwnerTypeId < 0); TypeDef declTypeDef = things.Types((KnownTypes)(-(short)rec.OwnerTypeId)); attrRefs[rec.AttributeId] = AnalyzeAttributeReference(declTypeDef, rec); @@ -177,8 +175,7 @@ namespace Confuser.Renamer.BAML { prefix = ""; if (!xmlns.TryGetValue(prefix, out clrNs)) return null; - } - else { + } else { prefix = typeName.Substring(0, index); if (!xmlns.TryGetValue(prefix, out clrNs)) return null; @@ -243,8 +240,7 @@ namespace Confuser.Renamer.BAML { AnalyzePropertyPath(cnt.Value); } } - } - else if (elem.Type.FullName == "System.Windows.Markup.TypeExtension") { + } else if (elem.Type.FullName == "System.Windows.Markup.TypeExtension") { foreach (BamlElement child in elem.Children) { if (child.Header.Type == BamlRecordType.ConstructorParametersStart) { var cnt = (TextRecord)child.Body[0]; @@ -322,15 +318,13 @@ namespace Confuser.Renamer.BAML { if (rec is PropertyWithConverterRecord) { ProcessConverter((PropertyWithConverterRecord)rec, type); } - } - else if (rec is PropertyComplexStartRecord) { + } else if (rec is PropertyComplexStartRecord) { Tuple attrInfo = ResolveAttribute(((PropertyComplexStartRecord)rec).AttributeId); type = attrInfo.Item2; attr = attrInfo.Item1; if (attr != null) type = GetAttributeType(attr); - } - else if (rec is ContentPropertyRecord) { + } else if (rec is ContentPropertyRecord) { Tuple attrInfo = ResolveAttribute(((ContentPropertyRecord)rec).AttributeId); type = attrInfo.Item2; attr = attrInfo.Item1; @@ -340,8 +334,7 @@ namespace Confuser.Renamer.BAML { child.Type = type; child.Attribute = attr; } - } - else if (rec is PropertyCustomRecord) { + } else if (rec is PropertyCustomRecord) { var customRec = (PropertyCustomRecord)rec; Tuple attrInfo = ResolveAttribute(customRec.AttributeId); type = attrInfo.Item2; @@ -353,8 +346,7 @@ namespace Confuser.Renamer.BAML { // See BamlRecordReader.GetCustomDependencyPropertyValue. // Umm... Well, actually nothing to do, since this record only describe DP, which already won't be renamed. } - } - else if (rec is PropertyWithExtensionRecord) { + } else if (rec is PropertyWithExtensionRecord) { var extRec = (PropertyWithExtensionRecord)rec; Tuple attrInfo = ResolveAttribute(extRec.AttributeId); type = attrInfo.Item2; @@ -376,8 +368,7 @@ namespace Confuser.Renamer.BAML { if (enumField != null) service.AddReference(enumField, new BAMLEnumReference(enumField, rec)); } - } - else if (converter.FullName == "System.Windows.Input.CommandConverter") { + } else if (converter.FullName == "System.Windows.Input.CommandConverter") { string cmd = rec.Value.Trim(); int index = cmd.IndexOf('.'); if (index != -1) { @@ -408,17 +399,13 @@ namespace Confuser.Renamer.BAML { } } } - } - else if (converter.FullName == "System.Windows.Markup.DependencyPropertyConverter") { + } else if (converter.FullName == "System.Windows.Markup.DependencyPropertyConverter") { // Umm... Again nothing to do, DP already won't be renamed. - } - else if (converter.FullName == "System.Windows.PropertyPathConverter") { + } else if (converter.FullName == "System.Windows.PropertyPathConverter") { AnalyzePropertyPath(rec.Value); - } - else if (converter.FullName == "System.Windows.Markup.RoutedEventConverter") { + } else if (converter.FullName == "System.Windows.Markup.RoutedEventConverter") { throw new NotImplementedException(); - } - else if (converter.FullName == "System.Windows.Markup.TypeTypeConverter") { + } else if (converter.FullName == "System.Windows.Markup.TypeTypeConverter") { string prefix; TypeSig sig = ResolveType(rec.Value.Trim(), out prefix); if (sig != null && context.Modules.Contains((ModuleDefMD)sig.ToBasicTypeDefOrRef().ResolveTypeDefThrow().Module)) { @@ -471,8 +458,7 @@ namespace Confuser.Renamer.BAML { AddTypeSigReference(sig, reference); } } - } - else { + } else { List candidates; if (properties.TryGetValue(part.Name, out candidates)) foreach (PropertyDef property in candidates) { diff --git a/Confuser.Renamer/BAML/BamlDocument.cs b/Confuser.Renamer/BAML/BamlDocument.cs index 79f104a..2b0c52c 100644 --- a/Confuser.Renamer/BAML/BamlDocument.cs +++ b/Confuser.Renamer/BAML/BamlDocument.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Confuser.Renamer.BAML { internal class BamlDocument : List { diff --git a/Confuser.Renamer/BAML/BamlElement.cs b/Confuser.Renamer/BAML/BamlElement.cs index 5545ab3..3086ac0 100644 --- a/Confuser.Renamer/BAML/BamlElement.cs +++ b/Confuser.Renamer/BAML/BamlElement.cs @@ -102,8 +102,7 @@ namespace Confuser.Renamer.BAML { current.Parent = prev; stack.Push(prev); } - } - else if (IsFooter(document[i])) { + } else if (IsFooter(document[i])) { if (current == null) throw new Exception("Unexpected footer."); @@ -115,8 +114,7 @@ namespace Confuser.Renamer.BAML { current.Footer = document[i]; if (stack.Count > 0) current = stack.Pop(); - } - else + } else current.Body.Add(document[i]); } Debug.Assert(stack.Count == 0); diff --git a/Confuser.Renamer/BAML/PropertyPath.cs b/Confuser.Renamer/BAML/PropertyPath.cs index 8f172b7..b69048a 100644 --- a/Confuser.Renamer/BAML/PropertyPath.cs +++ b/Confuser.Renamer/BAML/PropertyPath.cs @@ -33,8 +33,7 @@ namespace Confuser.Renamer.BAML { // type = null means the property is on the same type type = null; property = name.Trim(); - } - else { + } else { int dot = name.LastIndexOf('.'); type = name.Substring(0, dot).Trim(); property = name.Substring(dot + 1).Trim(); @@ -84,16 +83,13 @@ namespace Confuser.Renamer.BAML { if (c == '(') { index++; state = STATE_TYPE; - } - else if (c == '^') { + } else if (c == '^') { valueString.Append(path[++index]); index++; state = STATE_VALUE; - } - else if (char.IsWhiteSpace(c)) { + } else if (char.IsWhiteSpace(c)) { index++; - } - else { + } else { valueString.Append(path[index++]); state = STATE_VALUE; } @@ -102,12 +98,10 @@ namespace Confuser.Renamer.BAML { if (c == ')') { index++; state = STATE_VALUE; - } - else if (c == '^') { + } else if (c == '^') { typeString.Append(path[++index]); index++; - } - else { + } else { typeString.Append(path[index++]); } break; @@ -116,18 +110,15 @@ namespace Confuser.Renamer.BAML { valueString.Append(path[index++]); level++; trim = false; - } - else if (c == '^') { + } else if (c == '^') { valueString.Append(path[++index]); index++; trim = false; - } - else if (level > 0 && c == ']') { + } else if (level > 0 && c == ']') { level--; valueString.Append(path[index++]); trim = false; - } - else if (c == ']' || c == ',') { + } else if (c == ']' || c == ',') { string value = valueString.ToString(); // Note: it may be a WPF bug that if the value is "^ " (2 spaces after caret), all spaces will be trimmed. // According to http://msdn.microsoft.com/en-us/library/ms742451.aspx, the result should have one space. @@ -147,8 +138,7 @@ namespace Confuser.Renamer.BAML { state = STATE_WAIT; else state = STATE_DONE; - } - else { + } else { valueString.Append(path[index++]); if (c == ' ' && level == 0) trim = true; diff --git a/Confuser.Renamer/INameReference.cs b/Confuser.Renamer/INameReference.cs index 1c9c632..47d28d9 100644 --- a/Confuser.Renamer/INameReference.cs +++ b/Confuser.Renamer/INameReference.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; namespace Confuser.Renamer { public interface INameReference { diff --git a/Confuser.Renamer/IRenamer.cs b/Confuser.Renamer/IRenamer.cs index 0157ab3..10cd7cf 100644 --- a/Confuser.Renamer/IRenamer.cs +++ b/Confuser.Renamer/IRenamer.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using dnlib.DotNet; namespace Confuser.Renamer { diff --git a/Confuser.Renamer/NameProtection.cs b/Confuser.Renamer/NameProtection.cs index 296f683..e42d141 100644 --- a/Confuser.Renamer/NameProtection.cs +++ b/Confuser.Renamer/NameProtection.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; namespace Confuser.Renamer { internal class NameProtection : Protection { diff --git a/Confuser.Renamer/NameService.cs b/Confuser.Renamer/NameService.cs index b7602e1..45b708e 100644 --- a/Confuser.Renamer/NameService.cs +++ b/Confuser.Renamer/NameService.cs @@ -170,15 +170,13 @@ namespace Confuser.Renamer { method.Access = MethodAttributes.Assembly; if (!method.IsSpecialName && !method.IsRuntimeSpecialName && !method.DeclaringType.IsDelegate()) method.Name = RandomName(); - } - else if (def is FieldDef) { + } else if (def is FieldDef) { var field = (FieldDef)def; field.Access = FieldAttributes.Assembly; field.Name = RandomName(); if (!field.IsSpecialName && !field.IsRuntimeSpecialName) field.Name = RandomName(); - } - else if (def is TypeDef) { + } else if (def is TypeDef) { var type = (TypeDef)def; type.Visibility = type.DeclaringType == null ? TypeAttributes.NotPublic : TypeAttributes.NestedAssembly; type.Namespace = ""; diff --git a/Confuser.Renamer/PostRenamePhase.cs b/Confuser.Renamer/PostRenamePhase.cs index e72fb96..6de13b5 100644 --- a/Confuser.Renamer/PostRenamePhase.cs +++ b/Confuser.Renamer/PostRenamePhase.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using dnlib.DotNet; namespace Confuser.Renamer { diff --git a/Confuser.Renamer/Properties/AssemblyInfo.cs b/Confuser.Renamer/Properties/AssemblyInfo.cs index ae7d1d5..0c38931 100644 --- a/Confuser.Renamer/Properties/AssemblyInfo.cs +++ b/Confuser.Renamer/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; [assembly: AssemblyTitle("ConfuserEx Renamer")] [assembly: AssemblyDescription("Renaming analysis of ConfuserEx")] \ No newline at end of file diff --git a/Confuser.Renamer/References/BAMLAttributeReference.cs b/Confuser.Renamer/References/BAMLAttributeReference.cs index ce4995a..4aa7d57 100644 --- a/Confuser.Renamer/References/BAMLAttributeReference.cs +++ b/Confuser.Renamer/References/BAMLAttributeReference.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Renamer.BAML; using dnlib.DotNet; diff --git a/Confuser.Renamer/References/BAMLConverterMemberReference.cs b/Confuser.Renamer/References/BAMLConverterMemberReference.cs index 8b3a9e4..ddf6782 100644 --- a/Confuser.Renamer/References/BAMLConverterMemberReference.cs +++ b/Confuser.Renamer/References/BAMLConverterMemberReference.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Renamer.BAML; using dnlib.DotNet; diff --git a/Confuser.Renamer/References/BAMLConverterTypeReference.cs b/Confuser.Renamer/References/BAMLConverterTypeReference.cs index d3f797d..1d4f24f 100644 --- a/Confuser.Renamer/References/BAMLConverterTypeReference.cs +++ b/Confuser.Renamer/References/BAMLConverterTypeReference.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Renamer.BAML; using dnlib.DotNet; diff --git a/Confuser.Renamer/References/BAMLEnumReference.cs b/Confuser.Renamer/References/BAMLEnumReference.cs index c35b3d0..bf64be4 100644 --- a/Confuser.Renamer/References/BAMLEnumReference.cs +++ b/Confuser.Renamer/References/BAMLEnumReference.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Renamer.BAML; using dnlib.DotNet; diff --git a/Confuser.Renamer/References/BAMLPathTypeReference.cs b/Confuser.Renamer/References/BAMLPathTypeReference.cs index 550f21c..396ab78 100644 --- a/Confuser.Renamer/References/BAMLPathTypeReference.cs +++ b/Confuser.Renamer/References/BAMLPathTypeReference.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Renamer.BAML; using dnlib.DotNet; @@ -30,8 +31,7 @@ namespace Confuser.Renamer.References { name = prefix + ":" + name; if (indexer != null) { indexer.Type = name; - } - else { + } else { string oldType, property; attachedDP.ExtractAttachedDP(out oldType, out property); attachedDP.Name = string.Format("({0}.{1})", name, property); diff --git a/Confuser.Renamer/References/BAMLTypeReference.cs b/Confuser.Renamer/References/BAMLTypeReference.cs index d3bf41b..e5066e0 100644 --- a/Confuser.Renamer/References/BAMLTypeReference.cs +++ b/Confuser.Renamer/References/BAMLTypeReference.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using Confuser.Renamer.BAML; using dnlib.DotNet; diff --git a/Confuser.Renamer/References/CAMemberReference.cs b/Confuser.Renamer/References/CAMemberReference.cs index 6f22e81..45b4839 100644 --- a/Confuser.Renamer/References/CAMemberReference.cs +++ b/Confuser.Renamer/References/CAMemberReference.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using dnlib.DotNet; namespace Confuser.Renamer.References { diff --git a/Confuser.Renamer/References/MemberRefReference.cs b/Confuser.Renamer/References/MemberRefReference.cs index 321d26c..ab3261a 100644 --- a/Confuser.Renamer/References/MemberRefReference.cs +++ b/Confuser.Renamer/References/MemberRefReference.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using dnlib.DotNet; namespace Confuser.Renamer.References { diff --git a/Confuser.Renamer/References/OverrideDirectiveReference.cs b/Confuser.Renamer/References/OverrideDirectiveReference.cs index 693acae..c870e21 100644 --- a/Confuser.Renamer/References/OverrideDirectiveReference.cs +++ b/Confuser.Renamer/References/OverrideDirectiveReference.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Confuser.Core; using dnlib.DotNet; @@ -20,8 +21,7 @@ namespace Confuser.Renamer.References { var declType = (GenericInstSig)baseSlot.DeclaringType; target = new MemberRefUser(method.Module, baseSlot.MethodDef.Name, baseSlot.MethodDef.MethodSig, declType.ToTypeDefOrRef()); target = (IMethodDefOrRef)new Importer(method.Module, ImporterOptions.TryToUseTypeDefs).Import(target); - } - else { + } else { target = baseSlot.MethodDef; if (target.Module != method.Module) target = (IMethodDefOrRef)new Importer(method.Module, ImporterOptions.TryToUseTypeDefs).Import(baseSlot.MethodDef); diff --git a/Confuser.Renamer/References/ResourceReference.cs b/Confuser.Renamer/References/ResourceReference.cs index 7f0405d..68ea433 100644 --- a/Confuser.Renamer/References/ResourceReference.cs +++ b/Confuser.Renamer/References/ResourceReference.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using dnlib.DotNet; namespace Confuser.Renamer.References { diff --git a/Confuser.Renamer/References/TypeRefReference.cs b/Confuser.Renamer/References/TypeRefReference.cs index d296703..923af75 100644 --- a/Confuser.Renamer/References/TypeRefReference.cs +++ b/Confuser.Renamer/References/TypeRefReference.cs @@ -1,4 +1,5 @@ -using Confuser.Core; +using System; +using Confuser.Core; using dnlib.DotNet; namespace Confuser.Renamer.References { diff --git a/Confuser.Renamer/RenameMode.cs b/Confuser.Renamer/RenameMode.cs index 1c1a974..04f438c 100644 --- a/Confuser.Renamer/RenameMode.cs +++ b/Confuser.Renamer/RenameMode.cs @@ -1,4 +1,6 @@ -namespace Confuser.Renamer { +using System; + +namespace Confuser.Renamer { public enum RenameMode { Empty, Unicode, diff --git a/Confuser.Renamer/RenamePhase.cs b/Confuser.Renamer/RenamePhase.cs index 7066f7a..73ee271 100644 --- a/Confuser.Renamer/RenamePhase.cs +++ b/Confuser.Renamer/RenamePhase.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Confuser.Core; using dnlib.DotNet; @@ -52,13 +53,11 @@ namespace Confuser.Renamer { if (parameters.GetParameter(context, def, "flatten", true)) { typeDef.Name = service.ObfuscateName(typeDef.FullName, mode); typeDef.Namespace = ""; - } - else { + } else { typeDef.Namespace = service.ObfuscateName(typeDef.Namespace, mode); typeDef.Name = service.ObfuscateName(typeDef.Name, mode); } - } - else + } else def.Name = service.ObfuscateName(def.Name, mode); foreach (INameReference refer in references.ToList()) { diff --git a/Confuser.Renamer/VTable.cs b/Confuser.Renamer/VTable.cs index 774ccd9..a1f850a 100644 --- a/Confuser.Renamer/VTable.cs +++ b/Confuser.Renamer/VTable.cs @@ -117,8 +117,7 @@ namespace Confuser.Renamer { if (!slot.MethodDef.IsFinal) { slotList.Add(slot); Slots.Add(slot); - } - else + } else Finals.Add(slot); } @@ -133,8 +132,7 @@ namespace Confuser.Renamer { if (!slot.MethodDef.IsFinal) { slotDict.AddListEntry(slot.Signature, slot); Slots.Add(slot); - } - else + } else Finals.Add(slot); } @@ -151,16 +149,13 @@ namespace Confuser.Renamer { slotList.Add(slot); Slots.Add(slot); } - } - else + } else throw new UnreachableException(); - } - else { + } else { slotList.Add(slot); Slots.Add(slot); } - } - else { + } else { slotDict.AddListEntry(slot.Signature, slot); Slots.Add(slot); } @@ -256,18 +251,15 @@ namespace Confuser.Renamer { if (sig is TypeDefOrRefSig) { TypeDef typeDef = ((TypeDefOrRefSig)sig).TypeDefOrRef.ResolveTypeDefThrow(); return GetOrConstruct(typeDef); - } - else if (sig is GenericInstSig) { + } else if (sig is GenericInstSig) { var genInst = (GenericInstSig)sig; TypeDef openType = genInst.GenericType.TypeDefOrRef.ResolveTypeDefThrow(); VTable vTable = GetOrConstruct(openType); return ResolveGenericArgument(openType, genInst, vTable); - } - else + } else throw new NotSupportedException("Unexpected type: " + type.ToString()); - } - else + } else throw new UnreachableException(); } diff --git a/Confuser.Runtime/AntiDebug.Win32.cs b/Confuser.Runtime/AntiDebug.Win32.cs index 784cd59..2f5b717 100644 --- a/Confuser.Runtime/AntiDebug.Win32.cs +++ b/Confuser.Runtime/AntiDebug.Win32.cs @@ -55,8 +55,7 @@ namespace Confuser.Runtime { // CloseHandle try { CloseHandle(IntPtr.Zero); - } - catch { + } catch { Environment.FailFast(""); } diff --git a/Confuser.Runtime/AntiDump.cs b/Confuser.Runtime/AntiDump.cs index 0ad64fa..de26371 100644 --- a/Confuser.Runtime/AntiDump.cs +++ b/Confuser.Runtime/AntiDump.cs @@ -104,8 +104,7 @@ namespace Confuser.Runtime { mdHdr++; } } - } - else //Flat + } else //Flat { //VirtualProtect(ptr - 16, 8, 0x40, out old); //*(uint*)(ptr - 12) = 0; diff --git a/Confuser.Runtime/AntiTamper.JIT.cs b/Confuser.Runtime/AntiTamper.JIT.cs index e04d79e..bab05a6 100644 --- a/Confuser.Runtime/AntiTamper.JIT.cs +++ b/Confuser.Runtime/AntiTamper.JIT.cs @@ -32,8 +32,7 @@ namespace Confuser.Runtime { if (g == (uint)Mutation.KeyI0) { e = (uint*)(b + (f ? *(r + 3) : *(r + 1))); l = (f ? *(r + 2) : *(r + 0)) >> 2; - } - else if (g != 0) { + } else if (g != 0) { var q = (uint*)(b + (f ? *(r + 3) : *(r + 1))); uint j = *(r + 2) >> 2; for (uint k = 0; k < j; k++) { @@ -75,8 +74,7 @@ namespace Confuser.Runtime { ulong* str = stackalloc ulong[1]; str[0] = 0x0061746144705f6d; //m_pData. moduleHnd = (IntPtr)m.GetType().GetField(new string((sbyte*)str), BindingFlags.NonPublic | BindingFlags.Instance).GetValue(m); - } - else + } else moduleHnd = *(IntPtr*)(&hnd); Hook(); @@ -96,8 +94,7 @@ namespace Confuser.Runtime { if (ver) { ptr[0] = 0x642e74696a726c63; //clrjit.d ptr[1] = 0x0000000000006c6c; //ll...... - } - else { + } else { ptr[0] = 0x74696a726f63736d; //mscorjit ptr[1] = 0x000000006c6c642e; //.dll.... } @@ -117,8 +114,7 @@ namespace Confuser.Runtime { VirtualProtect(trampoline, 12, 0x40, out oldPl); Marshal.WriteIntPtr(trampoline, 2, original); - } - else { + } else { trampoline = Marshal.AllocHGlobal(8); var tptr = (ulong*)trampoline; tptr[0] = 0x90e0ffffffffffb8; @@ -145,8 +141,7 @@ namespace Confuser.Runtime { sigInfo = (CORINFO_SIG_INFO_x64*)((uint*)(info + 1) + 5) + 1; else sigInfo = (CORINFO_SIG_INFO_x86*)((uint*)(info + 1) + 4) + 1; - } - else { + } else { if (IntPtr.Size == 8) sigInfo = (CORINFO_SIG_INFO_x64*)((uint*)(info + 1) + 3) + 1; else @@ -164,8 +159,7 @@ namespace Confuser.Runtime { if ((b & 0x80) == 0) { numArgs = b; args = (IntPtr)(localVar + 1); - } - else { + } else { numArgs = (ushort)(((uint)(b & ~0x80) << 8) | *(localVar + 1)); args = (IntPtr)(localVar + 2); } @@ -177,8 +171,7 @@ namespace Confuser.Runtime { sigInfox64->flags = 1; sigInfox64->numArgs = numArgs; sigInfox64->args = args; - } - else { + } else { var sigInfox86 = (CORINFO_SIG_INFO_x86*)sigInfo; sigInfox86->callConv = 0; sigInfox86->retType = 1; @@ -234,8 +227,7 @@ namespace Confuser.Runtime { *((uint*)(info + 1) + 0) = data->MaxStack; *((uint*)(info + 1) + 1) = data->EHCount; *((uint*)(info + 1) + 2) = data->Options; - } - else { + } else { *((ushort*)(info + 1) + 0) = (ushort)data->MaxStack; *((ushort*)(info + 1) + 1) = (ushort)data->EHCount; *((uint*)(info + 1) + 1) = data->Options; @@ -258,8 +250,7 @@ namespace Confuser.Runtime { hook1.Dispose(); return ret; - } - finally { + } finally { Marshal.FreeHGlobal((IntPtr)newPtr); } } @@ -275,8 +266,8 @@ namespace Confuser.Runtime { [StructLayout(LayoutKind.Sequential, Pack = 1)] private struct CORINFO_METHOD_INFO { - public readonly IntPtr ftn; - public readonly IntPtr scope; + public IntPtr ftn; + public IntPtr scope; public byte* ILCode; public uint ILCodeSize; } @@ -284,34 +275,34 @@ namespace Confuser.Runtime { [StructLayout(LayoutKind.Sequential)] private struct CORINFO_SIG_INFO_x64 { public uint callConv; - private readonly uint pad1; - public readonly IntPtr retTypeClass; - public readonly IntPtr retTypeSigClass; + private uint pad1; + public IntPtr retTypeClass; + public IntPtr retTypeSigClass; public byte retType; public byte flags; public ushort numArgs; - private readonly uint pad2; - public readonly CORINFO_SIG_INST_x64 sigInst; + private uint pad2; + public CORINFO_SIG_INST_x64 sigInst; public IntPtr args; public IntPtr sig; - public readonly IntPtr scope; - public readonly uint token; - private readonly uint pad3; + public IntPtr scope; + public uint token; + private uint pad3; } [StructLayout(LayoutKind.Sequential)] private struct CORINFO_SIG_INFO_x86 { public uint callConv; - public readonly IntPtr retTypeClass; - public readonly IntPtr retTypeSigClass; + public IntPtr retTypeClass; + public IntPtr retTypeSigClass; public byte retType; public byte flags; public ushort numArgs; - public readonly CORINFO_SIG_INST_x86 sigInst; + public CORINFO_SIG_INST_x86 sigInst; public IntPtr args; public IntPtr sig; - public readonly IntPtr scope; - public readonly uint token; + public IntPtr scope; + public uint token; } [StructLayout(LayoutKind.Sequential, Size = 32)] @@ -390,8 +381,7 @@ namespace Confuser.Runtime { private void hookEHInfo(IntPtr self, IntPtr ftn, uint EHnumber, CORINFO_EH_CLAUSE* clause) { if (ftn == this.ftn) { *clause = clauses[EHnumber]; - } - else { + } else { o_getEHinfo(self, ftn, EHnumber, clause); } } diff --git a/Confuser.Runtime/AntiTamper.Normal.cs b/Confuser.Runtime/AntiTamper.Normal.cs index 074d504..9704a87 100644 --- a/Confuser.Runtime/AntiTamper.Normal.cs +++ b/Confuser.Runtime/AntiTamper.Normal.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; using System.Runtime.InteropServices; namespace Confuser.Runtime { @@ -21,8 +22,7 @@ namespace Confuser.Runtime { if (g == (uint)Mutation.KeyI0) { e = (uint*)(b + (f ? *(r + 3) : *(r + 1))); l = (f ? *(r + 2) : *(r + 0)) >> 2; - } - else if (g != 0) { + } else if (g != 0) { var q = (uint*)(b + (f ? *(r + 3) : *(r + 1))); uint j = *(r + 2) >> 2; for (uint k = 0; k < j; k++) { diff --git a/Confuser.Runtime/Constant.cs b/Confuser.Runtime/Constant.cs index f47a110..b551bd0 100644 --- a/Confuser.Runtime/Constant.cs +++ b/Confuser.Runtime/Constant.cs @@ -56,8 +56,7 @@ namespace Confuser.Runtime { var v = new T[1]; Buffer.BlockCopy(b, (int)id, v, 0, Mutation.Value()); ret = v[0]; - } - else if (t == Mutation.KeyI2) { + } else if (t == Mutation.KeyI2) { int s = b[id++] | (b[id++] << 8) | (b[id++] << 16) | (b[id++] << 24); int l = b[id++] | (b[id++] << 8) | (b[id++] << 16) | (b[id++] << 24); Array v = Array.CreateInstance(typeof (T).GetElementType(), l); diff --git a/Confuser.Runtime/Lzma.cs b/Confuser.Runtime/Lzma.cs index aaf1670..977cf67 100644 --- a/Confuser.Runtime/Lzma.cs +++ b/Confuser.Runtime/Lzma.cs @@ -294,8 +294,7 @@ namespace Confuser.Runtime { m_OutWindow.PutByte(b); state.UpdateChar(); nowPos64++; - } - else { + } else { uint len; if (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1) { if (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0) { @@ -305,13 +304,11 @@ namespace Confuser.Runtime { nowPos64++; continue; } - } - else { + } else { UInt32 distance; if (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0) { distance = rep1; - } - else { + } else { if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0) distance = rep2; else { @@ -325,8 +322,7 @@ namespace Confuser.Runtime { } len = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + kMatchMinLen; state.UpdateRep(); - } - else { + } else { rep3 = rep2; rep2 = rep1; rep1 = rep0; @@ -344,8 +340,7 @@ namespace Confuser.Runtime { numDirectBits - kNumAlignBits) << kNumAlignBits); rep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder); } - } - else + } else rep0 = posSlot; } if (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck) { diff --git a/Confuser.Runtime/Mutation.cs b/Confuser.Runtime/Mutation.cs index 4cb7a82..c958817 100644 --- a/Confuser.Runtime/Mutation.cs +++ b/Confuser.Runtime/Mutation.cs @@ -1,4 +1,6 @@ -internal class Mutation { +using System; + +internal class Mutation { public static readonly int KeyI0 = 0; public static readonly int KeyI1 = 1; public static readonly int KeyI2 = 2; diff --git a/Confuser.Runtime/Properties/AssemblyInfo.cs b/Confuser.Runtime/Properties/AssemblyInfo.cs index 9832778..aa3a74d 100644 --- a/Confuser.Runtime/Properties/AssemblyInfo.cs +++ b/Confuser.Runtime/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; [assembly: AssemblyTitle("ConfuserEx Runtime")] [assembly: AssemblyDescription("Runtime library of ConfuserEx")] \ No newline at end of file diff --git a/Confuser.Runtime/antinet/AntiManagedDebugger.cs b/Confuser.Runtime/antinet/AntiManagedDebugger.cs index c52e829..013e339 100644 --- a/Confuser.Runtime/antinet/AntiManagedDebugger.cs +++ b/Confuser.Runtime/antinet/AntiManagedDebugger.cs @@ -123,11 +123,9 @@ namespace Confuser.Runtime { continue; return pDebuggerRCThread; - } - catch { } + } catch { } } - } - catch { } + } catch { } return IntPtr.Zero; } diff --git a/Confuser.Runtime/antinet/AntiManagedProfiler.cs b/Confuser.Runtime/antinet/AntiManagedProfiler.cs index f8b976c..b83baa6 100644 --- a/Confuser.Runtime/antinet/AntiManagedProfiler.cs +++ b/Confuser.Runtime/antinet/AntiManagedProfiler.cs @@ -62,8 +62,7 @@ namespace Confuser.Runtime { if (profilerDetector == null) return false; return profilerDetector.IsProfilerAttached(); - } - catch { } + } catch { } return false; } } @@ -78,8 +77,7 @@ namespace Confuser.Runtime { if (profilerDetector == null) return false; return profilerDetector.WasProfilerAttached(); - } - catch { } + } catch { } return false; } } @@ -189,8 +187,7 @@ namespace Confuser.Runtime { addr = new IntPtr((void*)*(uint*)(p + 2)); else addr = new IntPtr(p + 7 + *(int*)(p + 2)); - } - else + } else continue; if (!PEInfo.IsAligned(addr, 4)) @@ -200,8 +197,7 @@ namespace Confuser.Runtime { try { *(uint*)addr = *(uint*)addr; - } - catch { + } catch { continue; } @@ -212,8 +208,7 @@ namespace Confuser.Runtime { if (count >= MAX_COUNTS) break; } - } - catch { } + } catch { } IntPtr foundAddr = GetMax(addrCounts, 5); if (foundAddr == IntPtr.Zero) return false; @@ -352,8 +347,7 @@ namespace Confuser.Runtime { } return CreateNamedPipeWait(); - } - catch { } + } catch { } return false; } @@ -379,8 +373,7 @@ namespace Confuser.Runtime { try { // Set default timeout to 0 to make sure it fails immediately *(uint*)((byte*)timeOutOptionAddr + ConfigDWORDInfo_defValue) = 0; - } - finally { + } finally { VirtualProtect(timeOutOptionAddr, (int)ConfigDWORDInfo_defValue + 4, oldProtect, out oldProtect); } @@ -392,8 +385,7 @@ namespace Confuser.Runtime { var rand = new Random(); for (int i = 0; i < ProfAPIMaxWaitForTriggerMs_name.Length; i++) name[i] = (char)rand.Next(1, ushort.MaxValue); - } - finally { + } finally { VirtualProtect(nameAddr, IntPtr.Size, oldProtect, out oldProtect); } } @@ -499,15 +491,13 @@ namespace Confuser.Runtime { if ((uint)(p[1] - 0xE8) > 7) continue; p += 3; - } - else if (*p == 0x85) { + } else if (*p == 0x85) { int reg = (p[1] >> 3) & 7; int rm = p[1] & 7; if (reg != rm) continue; p += 2; - } - else + } else continue; // 74 / 0F 84 XX je there @@ -527,11 +517,9 @@ namespace Confuser.Runtime { continue; return addr; - } - catch { } + } catch { } } - } - catch { } + } catch { } return IntPtr.Zero; } @@ -566,11 +554,9 @@ namespace Confuser.Runtime { continue; return new IntPtr(p); - } - catch { } + } catch { } } - } - catch { } + } catch { } return IntPtr.Zero; } @@ -636,16 +622,14 @@ namespace Confuser.Runtime { p[2] = 0xC2; p[3] = 0x04; p[4] = 0x00; - } - else { + } else { // xor eax,eax p[0] = 0x33; p[1] = 0xC0; // retn p[2] = 0xC3; } - } - finally { + } finally { VirtualProtect(new IntPtr(p), 5, oldProtect, out oldProtect); } return true; @@ -694,8 +678,7 @@ namespace Confuser.Runtime { return threadProc; } - } - else { + } else { for (; p < end; p++) { // Find this code: // 45 33 C9 xor r9d,r9d @@ -722,8 +705,7 @@ namespace Confuser.Runtime { return threadProc; } } - } - catch { } + } catch { } return IntPtr.Zero; } @@ -749,8 +731,7 @@ namespace Confuser.Runtime { if (*(uint*)(p + i) == 0x4000) return true; } - } - catch { } + } catch { } return false; } @@ -801,8 +782,7 @@ namespace Confuser.Runtime { addr = new IntPtr((void*)*(uint*)(p + 2)); else addr = new IntPtr(p + 7 + *(int*)(p + 2)); - } - else + } else continue; if (!PEInfo.IsAligned(addr, 4)) @@ -815,8 +795,7 @@ namespace Confuser.Runtime { if (*(uint*)addr > 4) continue; *(uint*)addr = *(uint*)addr; - } - catch { + } catch { continue; } @@ -827,8 +806,7 @@ namespace Confuser.Runtime { if (count >= MAX_COUNTS) break; } - } - catch { } + } catch { } IntPtr foundAddr = GetMax(addrCounts, 5); if (foundAddr == IntPtr.Zero) return false; diff --git a/Confuser.Runtime/antinet/HandleProcessCorruptedStateExceptionsAttribute.cs b/Confuser.Runtime/antinet/HandleProcessCorruptedStateExceptionsAttribute.cs index e7e3f58..bed11b6 100644 --- a/Confuser.Runtime/antinet/HandleProcessCorruptedStateExceptionsAttribute.cs +++ b/Confuser.Runtime/antinet/HandleProcessCorruptedStateExceptionsAttribute.cs @@ -1,4 +1,6 @@ -namespace System.Runtime.ExceptionServices { +using System; + +namespace System.Runtime.ExceptionServices { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] internal class HandleProcessCorruptedStateExceptionsAttribute : Attribute { } } \ No newline at end of file diff --git a/ConfuserEx/Skin.cs b/ConfuserEx/Skin.cs index ab53eb5..f8a77f1 100644 --- a/ConfuserEx/Skin.cs +++ b/ConfuserEx/Skin.cs @@ -10,9 +10,9 @@ namespace ConfuserEx { public static readonly DependencyProperty TabsDisabledProperty = DependencyProperty.RegisterAttached("TabsDisabled", typeof (bool), typeof (Skin), new UIPropertyMetadata(false)); - + public static readonly DependencyProperty FocusOverlayProperty = - DependencyProperty.RegisterAttached("FocusOverlay", typeof(bool), typeof(Skin), new UIPropertyMetadata(true)); + DependencyProperty.RegisterAttached("FocusOverlay", typeof (bool), typeof (Skin), new UIPropertyMetadata(true)); public static readonly DependencyProperty RTBDocumentProperty = DependencyProperty.RegisterAttached("RTBDocument", typeof (FlowDocument), typeof (Skin), new FrameworkPropertyMetadata(null, OnRTBDocumentChanged)); @@ -24,7 +24,7 @@ namespace ConfuserEx { public static void SetEmptyPrompt(DependencyObject obj, string value) { obj.SetValue(EmptyPromptProperty, value); } - + public static bool GetFocusOverlay(DependencyObject obj) { return (bool)obj.GetValue(FocusOverlayProperty); } @@ -46,8 +46,7 @@ namespace ConfuserEx { if (dpe.NewValue != null) { rtb.Document = (FlowDocument)dpe.NewValue; rtb.TextChanged += (sender, e) => rtb.ScrollToEnd(); - } - else + } else rtb.Document = new FlowDocument(); } diff --git a/ConfuserEx/Skin.xaml b/ConfuserEx/Skin.xaml index fc9cac7..ab94a69 100644 --- a/ConfuserEx/Skin.xaml +++ b/ConfuserEx/Skin.xaml @@ -584,7 +584,7 @@ - + - +