mirror of
https://github.com/stellarbear/YaraSharp
synced 2026-06-08 17:36:09 +00:00
129 lines
4.1 KiB
C++
129 lines
4.1 KiB
C++
#include "Stdafx.h"
|
|
|
|
// ErrorUtility
|
|
namespace YaraSharp
|
|
{
|
|
void ErrorUtility::ThrowOnError(int error)
|
|
{
|
|
switch (error)
|
|
{
|
|
case ERROR_SUCCESS:
|
|
return;
|
|
|
|
case ERROR_INSUFICIENT_MEMORY:
|
|
throw gcnew OutOfMemoryException();
|
|
|
|
default:
|
|
throw gcnew Exception(String::Format("Yara error: {0}. Code {1}", NiceErrorCode(error), error));
|
|
}
|
|
}
|
|
void ErrorUtility::ThrowOnError(String^ error)
|
|
{
|
|
throw gcnew Exception(String::Format("Error: {0}", error));
|
|
}
|
|
|
|
String^ ErrorUtility::NiceErrorCode(int error)
|
|
{
|
|
// TODO: ñäåëàòü íîðìàëüíîå îïèñàíèó
|
|
switch (error)
|
|
{
|
|
case ERROR_INSUFICIENT_MEMORY:
|
|
return "ERROR_INSUFICIENT_MEMORY";
|
|
case ERROR_COULD_NOT_ATTACH_TO_PROCESS:
|
|
return "COULD_NOT_ATTACH_TO_PROCESS";
|
|
case ERROR_COULD_NOT_OPEN_FILE:
|
|
return "ERROR_COULD_NOT_OPEN_FILE";
|
|
case ERROR_COULD_NOT_MAP_FILE:
|
|
return "ERROR_COULD_NOT_MAP_FILE";
|
|
case ERROR_INVALID_FILE:
|
|
return "ERROR_INVALID_FILE";
|
|
case ERROR_CORRUPT_FILE:
|
|
return "ERROR_CORRUPT_FILE";
|
|
case ERROR_UNSUPPORTED_FILE_VERSION:
|
|
return "ERROR_UNSUPPORTED_FILE_VERSION";
|
|
case ERROR_INVALID_REGULAR_EXPRESSION:
|
|
return "ERROR_INVALID_REGULAR_EXPRESSION";
|
|
case ERROR_INVALID_HEX_STRING:
|
|
return "ERROR_INVALID_HEX_STRING";
|
|
case ERROR_SYNTAX_ERROR:
|
|
return "ERROR_SYNTAX_ERROR";
|
|
case ERROR_LOOP_NESTING_LIMIT_EXCEEDED:
|
|
return "ERROR_LOOP_NESTING_LIMIT_EXCEEDED";
|
|
case ERROR_DUPLICATED_LOOP_IDENTIFIER:
|
|
return "ERROR_DUPLICATED_LOOP_IDENTIFIER";
|
|
case ERROR_DUPLICATED_IDENTIFIER:
|
|
return "ERROR_DUPLICATED_IDENTIFIER";
|
|
case ERROR_DUPLICATED_TAG_IDENTIFIER:
|
|
return "ERROR_DUPLICATED_TAG_IDENTIFIER";
|
|
case ERROR_DUPLICATED_META_IDENTIFIER:
|
|
return "ERROR_DUPLICATED_META_IDENTIFIER";
|
|
case ERROR_DUPLICATED_STRING_IDENTIFIER:
|
|
return "ERROR_DUPLICATED_STRING_IDENTIFIER";
|
|
case ERROR_UNREFERENCED_STRING:
|
|
return "ERROR_UNREFERENCED_STRING";
|
|
case ERROR_UNDEFINED_STRING:
|
|
return "ERROR_UNDEFINED_STRING";
|
|
case ERROR_UNDEFINED_IDENTIFIER:
|
|
return "ERROR_UNDEFINED_IDENTIFIER";
|
|
case ERROR_MISPLACED_ANONYMOUS_STRING:
|
|
return "ERROR_MISPLACED_ANONYMOUS_STRING";
|
|
case ERROR_INCLUDES_CIRCULAR_REFERENCE:
|
|
return "ERROR_INCLUDES_CIRCULAR_REFERENCE";
|
|
case ERROR_INCLUDE_DEPTH_EXCEEDED:
|
|
return "ERROR_INCLUDE_DEPTH_EXCEEDED";
|
|
case ERROR_WRONG_TYPE:
|
|
return "ERROR_WRONG_TYPE";
|
|
case ERROR_EXEC_STACK_OVERFLOW:
|
|
return "ERROR_EXEC_STACK_OVERFLOW";
|
|
case ERROR_SCAN_TIMEOUT:
|
|
return "ERROR_SCAN_TIMEOUT";
|
|
case ERROR_TOO_MANY_SCAN_THREADS:
|
|
return "ERROR_TOO_MANY_SCAN_THREADS";
|
|
case ERROR_CALLBACK_ERROR:
|
|
return "ERROR_CALLBACK_ERROR";
|
|
case ERROR_INVALID_ARGUMENT:
|
|
return "ERROR_INVALID_ARGUMENT";
|
|
case ERROR_TOO_MANY_MATCHES:
|
|
return "ERROR_TOO_MANY_MATCHES";
|
|
case ERROR_INTERNAL_FATAL_ERROR:
|
|
return "ERROR_INTERNAL_FATAL_ERROR";
|
|
case ERROR_NESTED_FOR_OF_LOOP:
|
|
return "ERROR_NESTED_FOR_OF_LOOP";
|
|
case ERROR_INVALID_FIELD_NAME:
|
|
return "ERROR_INVALID_FIELD_NAME";
|
|
case ERROR_UNKNOWN_MODULE:
|
|
return "ERROR_UNKNOWN_MODULE";
|
|
case ERROR_NOT_A_STRUCTURE:
|
|
return "ERROR_NOT_A_STRUCTURE";
|
|
case ERROR_NOT_INDEXABLE:
|
|
return "ERROR_NOT_INDEXABLE";
|
|
case ERROR_NOT_A_FUNCTION:
|
|
return "ERROR_NOT_A_FUNCTION";
|
|
case ERROR_INVALID_FORMAT:
|
|
return "ERROR_INVALID_FORMAT";
|
|
case ERROR_TOO_MANY_ARGUMENTS:
|
|
return "ERROR_TOO_MANY_ARGUMENTS";
|
|
case ERROR_WRONG_ARGUMENTS:
|
|
return "ERROR_WRONG_ARGUMENTS";
|
|
case ERROR_WRONG_RETURN_TYPE:
|
|
return "ERROR_WRONG_RETURN_TYPE";
|
|
case ERROR_DUPLICATED_STRUCTURE_MEMBER:
|
|
return "ERROR_DUPLICATED_STRUCTURE_MEMBER";
|
|
case ERROR_EMPTY_STRING:
|
|
return "ERROR_EMPTY_STRING";
|
|
case ERROR_DIVISION_BY_ZERO:
|
|
return "ERROR_DIVISION_BY_ZERO";
|
|
case ERROR_REGULAR_EXPRESSION_TOO_LARGE:
|
|
return "ERROR_REGULAR_EXPRESSION_TOO_LARGE";
|
|
case ERROR_TOO_MANY_RE_FIBERS:
|
|
return "ERROR_TOO_MANY_RE_FIBERS";
|
|
case ERROR_COULD_NOT_READ_PROCESS_MEMORY:
|
|
return "ERROR_COULD_NOT_READ_PROCESS_MEMORY";
|
|
case ERROR_INVALID_EXTERNAL_VARIABLE_TYPE:
|
|
return "ERROR_INVALID_EXTERNAL_VARIABLE_TYPE";
|
|
default:
|
|
return "UNKNOWN";
|
|
}
|
|
}
|
|
}
|