Skip to content

Commit 0d5f2cd

Browse files
secDre4merNeo23x0
andauthored
Add additional functions to math module (#1483)
* feat: Implement stats module Add a new statistics module. For now, the module supports counting the occurrences of specific bytes (or returning the occurrence rate as a percentage) and calculating the most common byte for an area. * Another example * feat: Implement stats module Add a new statistics module. For now, the module supports counting the occurrences of specific bytes (or returning the occurrence rate as a percentage) and calculating the most common byte for an area. * refactor: Integrate stats module into math module Integrate the new functionality into the math module instead of creating a new module. * chore: Adjust module name in documentation * chore: Fix memory leak issue Fixes a memory leak where a temporary array (used for match counting) wasn't released properly. * fix: Remove global char count function, optimize char count Remove a redundant (and slow) function to count a char globally. Rework the remaining char count function to be more efficient. It still requires O(n*m) in worst case and O(n) in best case. * chore: Update documentation * chore: Remove string counting function Due to the new "x of them in ..." syntax, string counting is no longer required (it already is supported and this function is slower in most circumstances). * chore: remove test functions for string count Co-authored-by: Florian Roth <[email protected]>
1 parent 83acb20 commit 0d5f2cd

File tree

3 files changed

+341
-135
lines changed

3 files changed

+341
-135
lines changed

docs/modules/math.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,42 @@ file and create signatures based on those results.
126126
Returns the absolute value of the signed integer.
127127

128128
*Example: math.abs(@a - @b) == 1*
129+
130+
.. c:function:: count(byte, offset, size)
131+
132+
.. versionadded:: 4.2.0
133+
134+
Returns how often a specific byte occurs, starting at *offset*
135+
and looking at the next *size* bytes. When scanning a
136+
running process the *offset* argument should be a virtual address within
137+
the process address space.
138+
*offset* and *size* are optional; if left empty, the complete file is searched.
139+
140+
*Example: math.count(0x4A) >= 10*
141+
142+
.. c:function:: percentage(byte, offset, size)
143+
144+
.. versionadded:: 4.2.0
145+
146+
Returns the occurrence rate of a specific byte, starting at *offset*
147+
and looking at the next *size* bytes. When scanning a
148+
running process the *offset* argument should be a virtual address within
149+
the process address space. The returned value is a float between 0 and 1.
150+
*offset* and *size* are optional; if left empty, the complete file is searched.
151+
152+
153+
*Example: math.percentage(0xFF, filesize-1024, filesize) >= 0.9*
154+
155+
*Example: math.percentage(0x4A) >= 0.4*
156+
157+
.. c:function:: mode(offset, size)
158+
159+
.. versionadded:: 4.2.0
160+
161+
Returns the most common byte, starting at *offset* and looking at the next
162+
*size* bytes. When scanning a
163+
running process the *offset* argument should be a virtual address within
164+
the process address space. The returned value is a float.
165+
*offset* and *size* are optional; if left empty, the complete file is searched.
166+
167+
*Example: math.mode(0, filesize) == 0xFF*

0 commit comments

Comments
 (0)