mirror of https://github.com/x64dbg/TitanEngine
add DynBuf dynamic buffer class and IsStrEqual() (unused)
This commit is contained in:
parent
41c8fa80c3
commit
7f05518560
|
|
@ -0,0 +1,40 @@
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include "Helper.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool IsStrEqual( const char* const a, const char* const b, bool considercase/*=true*/ )
|
||||||
|
{
|
||||||
|
const int stringlen = std::strlen(a);
|
||||||
|
if(stringlen != std::strlen(b))
|
||||||
|
return false; //cheap
|
||||||
|
|
||||||
|
if(considercase)
|
||||||
|
{
|
||||||
|
//plain old strcmp
|
||||||
|
return std::strcmp(a, b)==0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(int i=0; i<stringlen; i++)
|
||||||
|
{
|
||||||
|
if (tolower(a[i]) != tolower(b[i]))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void* MemAlloc( size_t sz )
|
||||||
|
{
|
||||||
|
void* r = malloc(sz);
|
||||||
|
if(r)
|
||||||
|
memset(r, 0, sz);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemFree( void* mem )
|
||||||
|
{
|
||||||
|
free(mem);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
#ifndef Helper_h__
|
||||||
|
#define Helper_h__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
/*
|
||||||
|
Compares two strings
|
||||||
|
a : string 1
|
||||||
|
b : string 2
|
||||||
|
considercase : casesensitivity
|
||||||
|
*/
|
||||||
|
bool IsStrEqual(const char* const a, const char* const b, bool considercase=true);
|
||||||
|
|
||||||
|
/*
|
||||||
|
A basic dynamic buffer, exception free.
|
||||||
|
*/
|
||||||
|
class DynBuf
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DynBuf(size_t sz=0)
|
||||||
|
{
|
||||||
|
Allocate(sz);
|
||||||
|
}
|
||||||
|
typedef std::vector<char> DynBufVec;
|
||||||
|
|
||||||
|
void* Allocate(size_t sz)
|
||||||
|
{
|
||||||
|
void* r=NULL;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(Size() < sz)
|
||||||
|
mem.resize(sz);
|
||||||
|
if(Size())
|
||||||
|
r = GetPtr();
|
||||||
|
if(r && sz)
|
||||||
|
memset(r, 0, sz);
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
void* GetPtr()
|
||||||
|
{
|
||||||
|
if(Size())
|
||||||
|
return &mem.front(); //in c++11: .data()
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
void Free()
|
||||||
|
{
|
||||||
|
mem.clear();
|
||||||
|
}
|
||||||
|
DynBufVec& GetVector() {return mem;}
|
||||||
|
const DynBufVec& GetVector() const {return mem;}
|
||||||
|
size_t Size() const {return mem.size();}
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
char& operator[](std::size_t idx)
|
||||||
|
{
|
||||||
|
return mem[idx];
|
||||||
|
};
|
||||||
|
const char& operator[](std::size_t idx) const
|
||||||
|
{
|
||||||
|
return mem[idx];
|
||||||
|
};
|
||||||
|
|
||||||
|
DynBufVec mem;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//Unused malloc/free wrappers
|
||||||
|
|
||||||
|
/*
|
||||||
|
malloc wrapper
|
||||||
|
*/
|
||||||
|
void* MemAlloc(size_t sz);
|
||||||
|
|
||||||
|
/*
|
||||||
|
free wrapper
|
||||||
|
*/
|
||||||
|
void MemFree(void* mem);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // Helper_h__
|
||||||
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
#include "aplib.h"
|
#include "aplib.h"
|
||||||
#include "LzmaDec.h"
|
#include "LzmaDec.h"
|
||||||
|
|
||||||
|
#include "Helper.h"
|
||||||
|
|
||||||
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L) // ntsubauth
|
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L) // ntsubauth
|
||||||
|
|
||||||
// Engine.Internal:
|
// Engine.Internal:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue