mirror of
https://github.com/stellarbear/YaraSharp
synced 2026-06-08 17:36:09 +00:00
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:
+14
-15
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user