This commit is contained in:
yck1509 2014-06-23 16:49:16 +08:00
Родитель 19b7fdfd17
Коммит bb127b5046
169 изменённых файлов: 632 добавлений и 726 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -1,4 +1,5 @@
using System.Reflection;
using System;
using System.Reflection;
[assembly: AssemblyTitle("ConfuserEx Command-line")]
[assembly: AssemblyDescription("Command-line interface of ConfuserEx")]

Просмотреть файл

@ -1,4 +1,6 @@
namespace Confuser.Core {
using System;
namespace Confuser.Core {
/// <summary>
/// Represent a component in Confuser
/// </summary>

Просмотреть файл

@ -21,11 +21,11 @@ namespace Confuser.Core {
/// The processing engine of ConfuserEx.
/// </summary>
public static class ConfuserEngine {
/// <summary>
/// The version of ConfuserEx.
/// The version of ConfuserEx.
/// </summary>
public static readonly string Version;
private static readonly string Copyright;
static ConfuserEngine() {

Просмотреть файл

@ -1,4 +1,5 @@
using Confuser.Core.Project;
using System;
using Confuser.Core.Project;
namespace Confuser.Core {
/// <summary>

Просмотреть файл

@ -1,4 +1,5 @@
using Confuser.Core.Services;
using System;
using Confuser.Core.Services;
namespace Confuser.Core {
/// <summary>

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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)

Просмотреть файл

@ -1,5 +1,7 @@
// Common/CRC.cs
using System;
namespace SevenZip {
internal class CRC {
public static readonly uint[] Table;

Просмотреть файл

@ -1,5 +1,6 @@
// InBuffer.cs
using System;
using System.IO;
namespace SevenZip.Buffer {

Просмотреть файл

@ -1,5 +1,6 @@
// OutBuffer.cs
using System;
using System.IO;
namespace SevenZip.Buffer {

Просмотреть файл

@ -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;

Просмотреть файл

@ -1,5 +1,6 @@
// LzOutWindow.cs
using System;
using System.IO;
namespace SevenZip.Compression.LZ {

Просмотреть файл

@ -1,5 +1,7 @@
// LzmaBase.cs
using System;
namespace SevenZip.Compression.LZMA {
internal abstract class Base {
public const uint kNumRepDistances = 4;

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -182,8 +182,7 @@ namespace SevenZip.Compression.RangeCoder {
if (Code < newBound) {
symbol = 0;
Range = newBound;
}
else {
} else {
symbol = 1;
Code -= newBound;
Range -= newBound;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using dnlib.DotNet;
namespace Confuser.Core {

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -33,7 +33,7 @@ namespace Confuser.Core {
}
/// <summary>
/// Determines whether the specified type has an accessible default constructor.
/// Determines whether the specified type has an accessible default constructor.
/// </summary>
/// <param name="type">The type.</param>
/// <returns><c>true</c> if the specified type has an accessible default constructor; otherwise, <c>false</c>.</returns>
@ -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);
}
}

Просмотреть файл

@ -458,9 +458,9 @@ namespace Confuser.Core.Project {
doc.Schemas.Add(Schema);
var exceptions = new List<XmlSchemaException>();
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>();
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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -1,4 +1,6 @@
namespace Confuser.Core.Project {
using System;
namespace Confuser.Core.Project {
/// <summary>
/// The type of pattern tokens
/// </summary>

Просмотреть файл

@ -1,4 +1,5 @@
using dnlib.DotNet;
using System;
using dnlib.DotNet;
namespace Confuser.Core.Project.Patterns {
/// <summary>

Просмотреть файл

@ -1,4 +1,5 @@
using dnlib.DotNet;
using System;
using dnlib.DotNet;
namespace Confuser.Core.Project.Patterns {
/// <summary>

Просмотреть файл

@ -1,4 +1,5 @@
using dnlib.DotNet;
using System;
using dnlib.DotNet;
namespace Confuser.Core.Project.Patterns {
/// <summary>

Просмотреть файл

@ -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()));
}
}

Просмотреть файл

@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using System;
using System.Text.RegularExpressions;
using dnlib.DotNet;
namespace Confuser.Core.Project.Patterns {

Просмотреть файл

@ -1,4 +1,5 @@
using dnlib.DotNet;
using System;
using dnlib.DotNet;
namespace Confuser.Core.Project.Patterns {
/// <summary>

Просмотреть файл

@ -1,4 +1,5 @@
using dnlib.DotNet;
using System;
using dnlib.DotNet;
namespace Confuser.Core.Project.Patterns {
/// <summary>

Просмотреть файл

@ -1,4 +1,5 @@
using dnlib.DotNet;
using System;
using dnlib.DotNet;
namespace Confuser.Core.Project.Patterns {
/// <summary>
@ -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();

Просмотреть файл

@ -1,4 +1,5 @@
using dnlib.DotNet;
using System;
using dnlib.DotNet;
namespace Confuser.Core.Project.Patterns {
/// <summary>

Просмотреть файл

@ -1,4 +1,5 @@
using dnlib.DotNet;
using System;
using dnlib.DotNet;
namespace Confuser.Core.Project.Patterns {
/// <summary>

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using dnlib.DotNet;
namespace Confuser.Core.Project.Patterns {

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace Confuser.Core.Project.Patterns {
/// <summary>

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace Confuser.Core.Project.Patterns {
/// <summary>
@ -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);

Просмотреть файл

@ -1,4 +1,5 @@
using System.Reflection;
using System;
using System.Reflection;
[assembly: AssemblyTitle("ConfuserEx Core")]
[assembly: AssemblyDescription("Core framework of ConfuserEx")]

Просмотреть файл

@ -1,4 +1,6 @@
namespace Confuser.Core {
using System;
namespace Confuser.Core {
/// <summary>
/// Base class of Confuser protections.
/// </summary>

Просмотреть файл

@ -1,4 +1,6 @@
namespace Confuser.Core {
using System;
namespace Confuser.Core {
/// <summary>
/// Base class of protection phases.
/// </summary>

Просмотреть файл

@ -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();
}
}
}

Просмотреть файл

@ -1,4 +1,6 @@
namespace Confuser.Core {
using System;
namespace Confuser.Core {
/// <summary>
/// Various presets of protections.
/// </summary>

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace Confuser.Core {
/// <summary>

Просмотреть файл

@ -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;

Просмотреть файл

@ -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<int>(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<int>(evalStack)));
index++;
}
else
} else
index++;
}

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace Confuser.Core {
/// <summary>

Просмотреть файл

@ -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; }

Просмотреть файл

@ -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; }

Просмотреть файл

@ -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();

Просмотреть файл

@ -1,4 +1,6 @@
namespace Confuser.DynCipher.AST {
using System;
namespace Confuser.DynCipher.AST {
public class LiteralExpression : Expression {
public uint Value { get; set; }

Просмотреть файл

@ -1,4 +1,5 @@
using System.Text;
using System;
using System.Text;
namespace Confuser.DynCipher.AST {
// i.e. for loop

Просмотреть файл

@ -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();

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text;
namespace Confuser.DynCipher.AST {

Просмотреть файл

@ -1,4 +1,6 @@
namespace Confuser.DynCipher.AST {
using System;
namespace Confuser.DynCipher.AST {
public class Variable {
public Variable(string name) {
Name = name;

Просмотреть файл

@ -1,4 +1,6 @@
namespace Confuser.DynCipher.AST {
using System;
namespace Confuser.DynCipher.AST {
public class VariableExpression : Expression {
public Variable Variable { get; set; }

Просмотреть файл

@ -1,4 +1,5 @@
using Confuser.Core;
using System;
using Confuser.Core;
namespace Confuser.DynCipher {
internal class DynCipherComponent : ConfuserComponent {

Просмотреть файл

@ -1,4 +1,5 @@
using Confuser.Core.Services;
using System;
using Confuser.Core.Services;
using Confuser.DynCipher.AST;
using Confuser.DynCipher.Generation;

Просмотреть файл

@ -1,4 +1,5 @@
using Confuser.Core.Services;
using System;
using Confuser.Core.Services;
using Confuser.DynCipher.AST;
using Confuser.DynCipher.Generation;

Просмотреть файл

@ -1,4 +1,5 @@
using Confuser.Core.Services;
using System;
using Confuser.Core.Services;
using Confuser.DynCipher.AST;
using Confuser.DynCipher.Generation;

Просмотреть файл

@ -1,4 +1,5 @@
using Confuser.Core.Services;
using System;
using Confuser.Core.Services;
using Confuser.DynCipher.Generation;
namespace Confuser.DynCipher.Elements {

Просмотреть файл

@ -1,4 +1,5 @@
using Confuser.Core.Services;
using System;
using Confuser.Core.Services;
using Confuser.DynCipher.AST;
using Confuser.DynCipher.Generation;

Просмотреть файл

@ -1,4 +1,5 @@
using Confuser.Core.Services;
using System;
using Confuser.Core.Services;
using Confuser.DynCipher.AST;
using Confuser.DynCipher.Generation;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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();
}
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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();
}
}

Просмотреть файл

@ -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,

Просмотреть файл

@ -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;

Просмотреть файл

@ -1,4 +1,5 @@
using System.Reflection;
using System;
using System.Reflection;
[assembly: AssemblyTitle("ConfuserEx Dynamic Cipher Library")]
[assembly: AssemblyDescription("Cipher generator of ConfuserEx")]

Просмотреть файл

@ -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;

Просмотреть файл

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using Confuser.DynCipher.AST;
namespace Confuser.DynCipher.Transforms {

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using Confuser.DynCipher.Generation;
namespace Confuser.DynCipher {

Просмотреть файл

@ -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;

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Confuser.Core;
using Confuser.Core.Helpers;

Просмотреть файл

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using Confuser.Core;
using dnlib.DotNet;

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Confuser.Core;
using Confuser.Core.Services;
using dnlib.DotNet;

Просмотреть файл

@ -1,4 +1,5 @@
using Confuser.Core;
using System;
using Confuser.Core;
namespace Confuser.Protections.AntiTamper {
internal interface IModeHandler {

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Confuser.Core;
using Confuser.Core.Services;
using dnlib.DotNet;

Просмотреть файл

@ -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);

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Confuser.Core;
using Confuser.Core.Services;
using dnlib.DotNet;

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Confuser.Core;
using Confuser.Core.Services;
using dnlib.DotNet;

Просмотреть файл

@ -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<RawFileRow> fileTbl = writer.MetaData.TablesHeap.FileTable;
uint fileRid = fileTbl.Add(new RawFileRow(
(uint)FileAttributes.ContainsMetaData,
writer.MetaData.StringsHeap.Add("koi"),
hashBlob));
}
};
MDTable<RawFileRow> fileTbl = writer.MetaData.TablesHeap.FileTable;
uint fileRid = fileTbl.Add(new RawFileRow(
(uint)FileAttributes.ContainsMetaData,
writer.MetaData.StringsHeap.Add("koi"),
hashBlob));
}
};
}
}
}

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Confuser.Core;
using Confuser.Core.Services;
using Confuser.DynCipher;

Просмотреть файл

@ -1,4 +1,5 @@
using Confuser.Core;
using System;
using Confuser.Core;
using Confuser.Protections.Constants;
using dnlib.DotNet;

Просмотреть файл

@ -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<Instruction>();
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<Instruction>();
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);
}

Просмотреть файл

@ -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<Instruction>();
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<Instruction>();
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<Tuple<MethodDef, Instruction>> 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;

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using dnlib.DotNet;
using dnlib.DotNet.Emit;

Просмотреть файл

@ -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;
}
}

Просмотреть файл

@ -1,4 +1,6 @@
namespace Confuser.Protections.Constants {
using System;
namespace Confuser.Protections.Constants {
internal enum Mode {
Normal,
Dynamic,

Просмотреть файл

@ -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<Instruction>();
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<Instruction>();
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);
}

Просмотреть файл

@ -44,11 +44,11 @@ namespace Confuser.Protections.Constants {
var encoding = new x86Encoding();
encoding.Compile(ctx);
MutationHelper.ReplacePlaceholder(decoder, arg => {
var repl = new List<Instruction>();
repl.AddRange(arg);
repl.Add(Instruction.Create(OpCodes.Call, encoding.native));
return repl.ToArray();
});
var repl = new List<Instruction>();
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;
}

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Confuser.Core;
using Confuser.Core.Services;
using Confuser.DynCipher;

Просмотреть файл

@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.Linq;
using Confuser.Core;
using Confuser.Core.Services;

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше