Skip to content

Commit

Permalink
Merge branch 'feature/54_wf_dataprop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaring committed Jun 1, 2019
2 parents af03aa4 + 2b07ed9 commit 48a7409
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
10 changes: 10 additions & 0 deletions Confuser.Core/Services/TraceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ public int[] TraceArguments(Instruction instr) {
index++;
}

if (evalStack.Count > argCount) {
// There are too many instructions on the eval stack.
// That means that there are instructions for following commands.
// To handle things properly we're only using the required amount on the top of the stack.
var tmp = evalStack.ToArray();
evalStack.Clear();
foreach(var idx in tmp.Take(argCount).Reverse())
evalStack.Push(idx);
}

if (evalStack.Count != argCount)
return null;
if (ret != null && !evalStack.SequenceEqual(ret))
Expand Down
2 changes: 1 addition & 1 deletion Confuser.Renamer/Analyzers/WinFormsAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void AnalyzeMethod(ConfuserContext context, INameService service, MethodDef meth
continue;
}

var argumentIndex = 0;
var argumentIndex = 1;
var propertyName = ResolveNameInstruction(method, args, ref argumentIndex);
if (propertyName.OpCode.Code != Code.Ldstr) {
if (!erred)
Expand Down
43 changes: 28 additions & 15 deletions Tests/Confuser.UnitTest/XUnitLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,59 @@

namespace Confuser.UnitTest {
public sealed class XunitLogger : ILogger {
private readonly ITestOutputHelper outputHelper;
private readonly ITestOutputHelper _outputHelper;
private readonly Action<string> _outputAction;

public XunitLogger(ITestOutputHelper outputHelper) =>
this.outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper));
public XunitLogger(ITestOutputHelper outputHelper) : this(outputHelper, null) { }

void ILogger.Debug(string msg) =>
outputHelper.WriteLine("[DEBUG] " + msg);
public XunitLogger(ITestOutputHelper outputHelper, Action<string> outputAction) {
_outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper));
_outputAction = outputAction;
}

void ILogger.Debug(string msg) =>
ProcessOutput("[DEBUG] " + msg);

void ILogger.DebugFormat(string format, params object[] args) =>
outputHelper.WriteLine("[DEBUG] " + format, args);
ProcessOutput("[DEBUG] " + format, args);

void ILogger.EndProgress() { }

void ILogger.Error(string msg) =>
void ILogger.Error(string msg) =>
throw new Exception(msg);

void ILogger.ErrorException(string msg, Exception ex) =>
void ILogger.ErrorException(string msg, Exception ex) =>
throw new Exception(msg, ex);

void ILogger.ErrorFormat(string format, params object[] args) =>
void ILogger.ErrorFormat(string format, params object[] args) =>
throw new Exception(string.Format(format, args));

void ILogger.Finish(bool successful) =>
outputHelper.WriteLine("[DONE]");
ProcessOutput("[DONE]");

void ILogger.Info(string msg) =>
outputHelper.WriteLine("[INFO] " + msg);
ProcessOutput("[INFO] " + msg);

void ILogger.InfoFormat(string format, params object[] args) =>
outputHelper.WriteLine("[INFO] " + format, args);
ProcessOutput("[INFO] " + format, args);

void ILogger.Progress(int progress, int overall) { }

void ILogger.Warn(string msg) =>
outputHelper.WriteLine("[WARN] " + msg);
ProcessOutput("[WARN] " + msg);

void ILogger.WarnException(string msg, Exception ex) =>
outputHelper.WriteLine("[WARN] " + msg + Environment.NewLine + ex.ToString());
ProcessOutput("[WARN] " + msg + Environment.NewLine + ex.ToString());

void ILogger.WarnFormat(string format, params object[] args) =>
outputHelper.WriteLine("[WARN] " + format, args);
ProcessOutput("[WARN] " + format, args);

private void ProcessOutput(string format, params object[] args) =>
ProcessOutput(string.Format(format, args));

private void ProcessOutput(string message) {
_outputAction?.Invoke(message);
_outputHelper.WriteLine(message);
}
}
}
6 changes: 5 additions & 1 deletion Tests/WinFormsRenaming.Test/RenameDataPropertyNameTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public RenameDataPropertyNameTest(ITestOutputHelper outputHelper) =>
[Trait("Category", "Protection")]
[Trait("Protection", "rename")]
[Trait("Technology", "Windows Forms")]
[Trait("Issue", "https://github.com/mkaring/ConfuserEx/issues/54")]
public async Task RenameWindowsFormsTest() {
var baseDir = Environment.CurrentDirectory;
var outputDir = Path.Combine(baseDir, "testtmp");
Expand All @@ -33,10 +34,13 @@ public async Task RenameWindowsFormsTest() {
new SettingItem<Protection>("rename")
});

void AssertLog(string message) {
Assert.DoesNotContain("Failed to extract binding property name in", message);
}

var parameters = new ConfuserParameters {
Project = proj,
Logger = new XunitLogger(outputHelper)
Logger = new XunitLogger(outputHelper, AssertLog)
};

await ConfuserEngine.Run(parameters);
Expand Down

0 comments on commit 48a7409

Please # to comment.