Cstrike: Implement CS_OnBuy forward.
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "MemoryUtils.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <fcntl.h>
|
||||
@@ -63,8 +64,6 @@
|
||||
#endif // MAC_OS_X_VERSION_10_6
|
||||
#endif // __APPLE__
|
||||
|
||||
|
||||
|
||||
MemoryUtils g_MemUtils;
|
||||
|
||||
MemoryUtils::MemoryUtils()
|
||||
@@ -103,6 +102,19 @@ MemoryUtils::~MemoryUtils()
|
||||
#endif
|
||||
}
|
||||
|
||||
void *MemoryUtils::DecodeAndFindPattern(const void *libPtr, const char *pattern)
|
||||
{
|
||||
unsigned char real_sig[511];
|
||||
size_t real_bytes = DecodeHexString(real_sig, sizeof(real_sig), pattern);
|
||||
|
||||
if (real_bytes >= 1)
|
||||
{
|
||||
return FindPattern(libPtr, (char*)real_sig, real_bytes);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *MemoryUtils::FindPattern(const void *libPtr, const char *pattern, size_t len)
|
||||
{
|
||||
DynLibInfo lib;
|
||||
@@ -655,3 +667,39 @@ bool MemoryUtils::GetLibraryOfAddress(const void *libPtr, char *buffer, size_t m
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t MemoryUtils::DecodeHexString(unsigned char *buffer, size_t maxlength, const char *hexstr)
|
||||
{
|
||||
size_t written = 0;
|
||||
size_t length = strlen(hexstr);
|
||||
|
||||
for (size_t i = 0; i < length; i++)
|
||||
{
|
||||
if (written >= maxlength)
|
||||
break;
|
||||
|
||||
buffer[written++] = hexstr[i];
|
||||
if (hexstr[i] == '\\' && hexstr[i + 1] == 'x')
|
||||
{
|
||||
if (i + 3 >= length)
|
||||
continue;
|
||||
|
||||
/* Get the hex part. */
|
||||
char s_byte[3];
|
||||
int r_byte;
|
||||
s_byte[0] = hexstr[i + 2];
|
||||
s_byte[1] = hexstr[i + 3];
|
||||
s_byte[2] = '\0';
|
||||
|
||||
/* Read it as an integer */
|
||||
sscanf(s_byte, "%x", &r_byte);
|
||||
|
||||
/* Save the value */
|
||||
buffer[written - 1] = r_byte;
|
||||
|
||||
/* Adjust index */
|
||||
i += 3;
|
||||
}
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
Reference in New Issue
Block a user