mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-27 23:37:04 -05:00
includes/std: Drastically improved std::mem::MagicSearch, added find_string and find_string_in_range
This commit is contained in:
@@ -9,18 +9,15 @@ namespace auto std::mem {
|
||||
namespace impl {
|
||||
|
||||
struct MagicSearchImpl<auto Magic, T> {
|
||||
if ($ < (std::mem::base_address() + std::mem::size() - builtin::std::string::length(Magic) - 1)) {
|
||||
char __potentialMagic__[builtin::std::string::length(Magic)] [[hidden, no_unique_address]];
|
||||
|
||||
if (__potentialMagic__ == Magic) {
|
||||
T data [[inline]];
|
||||
} else {
|
||||
padding[1];
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
padding[1];
|
||||
continue;
|
||||
s128 address = builtin::std::mem::find_string_in_range(0, $, builtin::std::mem::size(), Magic);
|
||||
if (address < 0)
|
||||
break;
|
||||
|
||||
$ = address;
|
||||
try {
|
||||
T data [[inline]];
|
||||
} catch {
|
||||
T data;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -63,7 +60,7 @@ namespace auto std::mem {
|
||||
|
||||
|
||||
/**
|
||||
Gets the base address of the memory
|
||||
Gets the base address of the data
|
||||
@return The base address of the memory
|
||||
*/
|
||||
fn base_address() {
|
||||
@@ -71,7 +68,7 @@ namespace auto std::mem {
|
||||
};
|
||||
|
||||
/**
|
||||
Gets the size of the memory
|
||||
Gets the size of the data
|
||||
@return The size of the memory
|
||||
*/
|
||||
fn size() {
|
||||
@@ -79,17 +76,18 @@ namespace auto std::mem {
|
||||
};
|
||||
|
||||
/**
|
||||
Finds a sequence of bytes in the memory
|
||||
Finds a sequence of bytes in the data
|
||||
@param occurrence_index The index of the occurrence to find
|
||||
@param bytes The bytes to find
|
||||
@return The address of the sequence
|
||||
*/
|
||||
fn find_sequence(u128 occurrence_index, auto ... bytes) {
|
||||
return builtin::std::mem::find_sequence_in_range(occurrence_index, builtin::std::mem::base_address(), builtin::std::mem::size(), bytes);
|
||||
const u128 address = builtin::std::mem::base_address();
|
||||
return builtin::std::mem::find_sequence_in_range(occurrence_index, address, address + builtin::std::mem::size(), bytes);
|
||||
};
|
||||
|
||||
/**
|
||||
Finds a sequence of bytes in a specific region of the memory
|
||||
Finds a sequence of bytes in a specific region of the data
|
||||
@param occurrence_index The index of the occurrence to find
|
||||
@param offsetFrom The offset from which to start searching
|
||||
@param offsetTo The offset to which to search
|
||||
@@ -100,6 +98,30 @@ namespace auto std::mem {
|
||||
return builtin::std::mem::find_sequence_in_range(occurrence_index, offsetFrom, offsetTo, bytes);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Finds a string in the data
|
||||
@param occurrence_index The index of the occurrence to find
|
||||
@param string The string to find
|
||||
@return The address of the sequence
|
||||
*/
|
||||
fn find_string(u128 occurrence_index, str string) {
|
||||
const u128 address = builtin::std::mem::base_address();
|
||||
return builtin::std::mem::find_string_in_range(occurrence_index, address, address + builtin::std::mem::size(), string);
|
||||
};
|
||||
|
||||
/**
|
||||
Finds a string in a specific region of the data
|
||||
@param occurrence_index The index of the occurrence to find
|
||||
@param offsetFrom The offset from which to start searching
|
||||
@param offsetTo The offset to which to search
|
||||
@param string The string to find
|
||||
@return The address of the sequence
|
||||
*/
|
||||
fn find_string_in_range(u128 occurrence_index, u128 offsetFrom, u128 offsetTo, str string) {
|
||||
return builtin::std::mem::find_string_in_range(occurrence_index, offsetFrom, offsetTo, string);
|
||||
};
|
||||
|
||||
/**
|
||||
Reads a unsigned value from the memory
|
||||
@param address The address to read from
|
||||
|
||||
Reference in New Issue
Block a user