From f3aa1901e7a038450a9f5f37a74563616c91d00c Mon Sep 17 00:00:00 2001 From: "Chris Davies (MSTIC)" Date: Mon, 3 Dec 2018 14:21:56 +0000 Subject: [PATCH] Fixed an issue where warnings were not being surfaced, unless in conjunction with an error --- YaraSharp/Compiler.cpp | 15 +++++++++++++-- YaraSharp/YaraSharp.cpp | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/YaraSharp/Compiler.cpp b/YaraSharp/Compiler.cpp index 1975204..009d7ec 100644 --- a/YaraSharp/Compiler.cpp +++ b/YaraSharp/Compiler.cpp @@ -98,8 +98,19 @@ namespace YaraSharp UNREFERENCED_PARAMETER(ErrorLevel); UNREFERENCED_PARAMETER(UserData); - auto msg = String::Format("{0} in line {1} in file: {2}", - marshal_as(Message), LineNumber, + String^ errorLevel; + + if (ErrorLevel == YARA_ERROR_LEVEL_ERROR) + { + errorLevel = "ERROR"; + } + else if (ErrorLevel == YARA_ERROR_LEVEL_WARNING) + { + errorLevel = "WARNING"; + } + + auto msg = String::Format("{0}: {1} on line {2} in file: {3}", + errorLevel, marshal_as(Message), LineNumber, Filename ? marshal_as(Filename) : "[none]"); Errors->Add(msg); diff --git a/YaraSharp/YaraSharp.cpp b/YaraSharp/YaraSharp.cpp index cdd2eeb..4f4ae3c 100644 --- a/YaraSharp/YaraSharp.cpp +++ b/YaraSharp/YaraSharp.cpp @@ -14,7 +14,7 @@ namespace YaraSharp { CCompiler^ TestCompiler = gcnew CCompiler(ExternalVariables); - if (TestCompiler->AddFile(FilePathList[i])) + if (TestCompiler->AddFile(FilePathList[i]) || TestCompiler->GetErrors()->Count > 0) { CompilationErrors->Add(FilePathList[i], TestCompiler->GetErrors()); FilePathList->Remove(FilePathList[i--]); @@ -31,7 +31,7 @@ namespace YaraSharp CCompiler^ TestCompiler = gcnew CCompiler(ExternalVariables); for each (auto FilePath in FilePathList) { - if (TestCompiler->AddFile(FilePath)) + if (TestCompiler->AddFile(FilePath) || TestCompiler->GetErrors()->Count > 0) { CompilationErrors->Add(FilePath, TestCompiler->GetErrors()); FilePathList->Remove(FilePath);