From 72e38cf50b9db5e9c14aa3a38bb20e0769425c0d Mon Sep 17 00:00:00 2001 From: AdamWhite Date: Sun, 6 Feb 2022 23:03:48 -0700 Subject: [PATCH] 1) Added YaraSharp.YSScanner.ScanMemory overload to take an array instead of a pointer, since this is a C# wrapper, and it is expected of C# wrappers to insulate you from such constructs. 2) Added overload to class signature in header. 3) Fixed minor spelling error in exception message ('intialization' is missing an 'i'). --- YaraSharp/Scanner.cpp | 17 ++++++++++++++++- YaraSharp/Scanner.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/YaraSharp/Scanner.cpp b/YaraSharp/Scanner.cpp index 2422eff..ad0d803 100644 --- a/YaraSharp/Scanner.cpp +++ b/YaraSharp/Scanner.cpp @@ -41,12 +41,27 @@ namespace YaraSharp (marshal_as(Path)).c_str())); return matches; } + List^ YSScanner::ScanMemory(uint8_t* Buffer, int Length) { YSException::ThrowOnError(yr_scanner_scan_mem(scanner, Buffer, Length)); return matches; } + List^ YSScanner::ScanMemory(array^ buffer) + { + if (buffer == nullptr || buffer->Length == 0) + { + return gcnew List(); + } + else + { + pin_ptr bufferPointer = &buffer[0]; + YSException::ThrowOnError(yr_scanner_scan_mem(scanner, bufferPointer, buffer->Length)); + return matches; + } + } + // Set externals void YSScanner::SetScannerExternals(Dictionary^ externalVariables) { @@ -72,7 +87,7 @@ namespace YaraSharp throw gcnew NotSupportedException(String::Format("Unsupported external variable: '{0}'", VariableType->Name)); if (ExternalError != ERROR_SUCCESS) - YSException::ThrowOnError("(Scanner) Error during external variable intialization"); + YSException::ThrowOnError("(Scanner) Error during external variable initialization"); } } } diff --git a/YaraSharp/Scanner.h b/YaraSharp/Scanner.h index 829e0ca..949f862 100644 --- a/YaraSharp/Scanner.h +++ b/YaraSharp/Scanner.h @@ -18,6 +18,7 @@ namespace YaraSharp List^ ScanProcess(int pID); List^ ScanFile(String^ path); List^ ScanMemory(uint8_t* buffer, int length); + List^ ScanMemory(array^ buffer); int HandleScannerCallback(int message, void* data, void* context); private: void SetScannerCallback();