From f1ac2efec5c9a0b767cad124331aef65227c6fbd Mon Sep 17 00:00:00 2001 From: mrexodia Date: Sun, 10 Jan 2016 22:44:03 +0100 Subject: [PATCH] Static.Pattern documentation --- GleeBug/Static.Pattern.cpp | 2 +- GleeBug/Static.Pattern.h | 55 +++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/GleeBug/Static.Pattern.cpp b/GleeBug/Static.Pattern.cpp index d16d9ed..1cb74d1 100644 --- a/GleeBug/Static.Pattern.cpp +++ b/GleeBug/Static.Pattern.cpp @@ -104,7 +104,7 @@ namespace GleeBug return -1; } - size_t Pattern::Find(const uint8* data, size_t datasize, unsigned char* pattern, size_t patternsize) + size_t Pattern::Find(const uint8* data, size_t datasize, const uint8* pattern, size_t patternsize) { if (patternsize > datasize) patternsize = datasize; diff --git a/GleeBug/Static.Pattern.h b/GleeBug/Static.Pattern.h index 3ed0482..5cdfa62 100644 --- a/GleeBug/Static.Pattern.h +++ b/GleeBug/Static.Pattern.h @@ -17,12 +17,65 @@ namespace GleeBug } nibble[2]; }; + /** + \brief Formats pattern string to only contain [0-9A-Fa-f\?]. + \param pattern Pattern to format. + \return The formatted pattern. + */ static std::string FormatPattern(const std::string & pattern); + + /** + \brief Transforms a string pattern to a nibble structure. + \param patterntext The pattern string to find. + \param [out] pattern Transformed pattern. + \return true if it succeeds, false otherwise. + */ static bool Transform(const std::string & patterntext, std::vector & pattern); + + /** + \brief Finds the first occurrence of a pattern in a buffer. + \param data The buffer to search in. + \param datasize The size of the buffer. + \param pattern The pattern to find. + \return Offset of the first occurrence found. -1 when not found. + */ static size_t Find(const uint8* data, size_t datasize, const std::vector & pattern); - static size_t Find(const uint8* data, size_t datasize, unsigned char* pattern, size_t patternsize); + + /** + \brief Finds the first occurrence of a pattern in a buffer. + \param data The buffer to search in. + \param datasize The size of the buffer. + \param pattern The pattern to find. The pattern supports wildcards (1? ?? ?6 78). + \return Offset of the first occurrence found. -1 when not found. + */ static size_t Find(const uint8* data, size_t datasize, const char* pattern); + + /** + \brief Finds the first occurrence of a pattern in a buffer. + \param data The buffer to search in. + \param datasize The size of the buffer. + \param pattern The pattern to find. + \param patternsize The size of the pattern to find. + \return Offset of the first occurrence found. -1 when not found. + */ + static size_t Find(const uint8* data, size_t datasize, const uint8* pattern, size_t patternsize); + + /** + \brief Writes a pattern in a buffer. This function writes as many bytes as possible from the pattern. + \param [in,out] data The buffer to write the pattern in. + \param datasize The size of the buffer. + \param pattern Specifies the pattern. The pattern supports wildcards (1? ?? ?6 78). + */ static void Write(uint8* data, size_t datasize, const char* pattern); + + /** + \brief Search and replace a pattern in a buffer. + \param [in,out] data The buffer to search and replace in. + \param datasize The size of the buffer. + \param searchpattern The pattern to find. The pattern supports wildcards (1? ?? ?6 78). + \param replacepattern The pattern to replace the found occurrence with. The pattern supports wildcards (1? ?? ?6 78). + \return true if it succeeds, false if it fails. + */ static bool Snr(uint8* data, size_t datasize, const char* searchpattern, const char* replacepattern); }; };