This isn't finished, but I think represents a better way of handling warnings and errors that doesn't treat warnings as errors

This commit is contained in:
Chris Davies (MSTIC)
2018-12-11 17:37:21 +00:00
parent 60bf6dcd38
commit 1bc253968d
3 changed files with 24 additions and 16 deletions
+14 -15
View File
@@ -10,7 +10,11 @@ namespace YaraSharp
ErrorUtility::ThrowOnError(yr_compiler_create(&TestCompiler));
Compiler = TestCompiler;
Errors = gcnew List<String^>();
// Set up and initialize the error dictionary for errors and warnings
// Which are populated by the callback handler
Errors = gcnew Dictionary<int, List<String^>^>();
Errors->Add(YARA_ERROR_LEVEL_ERROR, gcnew List<String^>());
Errors->Add(YARA_ERROR_LEVEL_WARNING, gcnew List<String^>());
SetCompilerExternals(ExternalVariables);
SetCompilerCallback();
@@ -52,7 +56,11 @@ namespace YaraSharp
}
List<String^>^ CCompiler::GetErrors()
{
return this->Errors;
return this->Errors[YARA_ERROR_LEVEL_ERROR];
}
List<String^>^ CCompiler::GetWarnings()
{
return this->Errors[YARA_ERROR_LEVEL_WARNING];
}
// Set externals
@@ -99,20 +107,11 @@ namespace YaraSharp
UNREFERENCED_PARAMETER(UserData);
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<String^>(Message), LineNumber,
auto msg = String::Format("{0} on line {1} in file: {2}",
marshal_as<String^>(Message), LineNumber,
Filename ? marshal_as<String^>(Filename) : "[none]");
Errors->Add(msg);
Errors[ErrorLevel]->Add(msg);
}
}
+2 -1
View File
@@ -8,7 +8,7 @@ namespace YaraSharp
public ref class CCompiler sealed
{
initonly YR_COMPILER* Compiler;
initonly List<String^>^ Errors;
initonly Dictionary<int, List<String^>^>^ Errors;
public:
CCompiler(Dictionary<String^, Object^>^ ExternalVariables);
@@ -16,6 +16,7 @@ namespace YaraSharp
CRules^ GetRules();
List<String^>^ GetErrors();
List<String^>^ GetWarnings();
int AddFile(String^ FilePath);
void AddFiles(List<String^>^ FilePathList);
+8
View File
@@ -19,6 +19,10 @@ namespace YaraSharp
CompilationErrors->Add(FilePathList[i], TestCompiler->GetErrors());
FilePathList->Remove(FilePathList[i--]);
}
else if (TestCompiler->GetWarnings()->Count > 0)
{
CompilationErrors->Add(FilePathList[i], TestCompiler->GetWarnings());
}
delete TestCompiler;
}
@@ -41,6 +45,10 @@ namespace YaraSharp
delete TestCompiler;
break;
}
else if (TestCompiler->GetWarnings()->Count > 0)
{
CompilationErrors->Add(FilePath, TestCompiler->GetWarnings());
}
}
}