mirror of
https://github.com/accelerator74/Cleaner.git
synced 2025-12-08 02:58:28 +00:00
better prints for errors and logging - tell the user when we don't print their string
This commit is contained in:
parent
9482a36c0e
commit
396dcdedfb
@ -17,7 +17,8 @@ int g_iStrings = 0;
|
|||||||
for (int i = 0; i < g_iStrings; ++i)
|
for (int i = 0; i < g_iStrings; ++i)
|
||||||
{
|
{
|
||||||
// make sure we're stripping at least 2 or more chars just in case we accidentally inhale a \0
|
// make sure we're stripping at least 2 or more chars just in case we accidentally inhale a \0
|
||||||
if (strlen(g_szStrings[i]) > 1 && strstr(pMessage, g_szStrings[i]) != 0)
|
// also there's no reason to strip a single char ever
|
||||||
|
if (strlen(g_szStrings[i]) >= 2 && strstr(pMessage, g_szStrings[i]) != 0)
|
||||||
{
|
{
|
||||||
return LR_CONTINUE;
|
return LR_CONTINUE;
|
||||||
}
|
}
|
||||||
@ -30,7 +31,8 @@ int g_iStrings = 0;
|
|||||||
for (int i = 0; i < g_iStrings; ++i)
|
for (int i = 0; i < g_iStrings; ++i)
|
||||||
{
|
{
|
||||||
// make sure we're stripping at least 2 or more chars just in case we accidentally inhale a \0
|
// make sure we're stripping at least 2 or more chars just in case we accidentally inhale a \0
|
||||||
if (strlen(g_szStrings[i]) > 1 && strstr(text, g_szStrings[i]) != 0)
|
// also there's no reason to strip a single char ever
|
||||||
|
if (strlen(g_szStrings[i]) >= 2 && strstr(text, g_szStrings[i]) != 0)
|
||||||
{
|
{
|
||||||
return SPEW_CONTINUE;
|
return SPEW_CONTINUE;
|
||||||
}
|
}
|
||||||
@ -42,14 +44,14 @@ int g_iStrings = 0;
|
|||||||
// https://stackoverflow.com/questions/10178700/c-strip-non-ascii-characters-from-string
|
// https://stackoverflow.com/questions/10178700/c-strip-non-ascii-characters-from-string
|
||||||
static bool badChar(char c)
|
static bool badChar(char c)
|
||||||
{
|
{
|
||||||
// everything below space excluding null term and del or above
|
// everything below space excluding null term and del or above
|
||||||
return (c != 0 && (c < 32 || c > 126));
|
return (c != 0 && (c < 32 || c > 126));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stripBadChars(std::string & str)
|
static void stripBadChars(std::string & str)
|
||||||
{
|
{
|
||||||
// remove all chars matching our "badchar" func
|
// remove all chars matching our "badchar" func
|
||||||
str.erase(remove_if(str.begin(),str.end(), badChar), str.end());
|
str.erase(remove_if(str.begin(),str.end(), badChar), str.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Cleaner::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
bool Cleaner::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
||||||
@ -67,48 +69,50 @@ bool Cleaner::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// step thru the file char by char and log the number of newlines we have
|
// step thru the file char by char and log the number of lines we have
|
||||||
// this is more or less the number of lines we have
|
int lines = 0;
|
||||||
int c, lines = 0;
|
for (int c = fgetc(file); c != EOF; c = fgetc(file))
|
||||||
do
|
|
||||||
{
|
{
|
||||||
c = fgetc(file);
|
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
{
|
{
|
||||||
++lines;
|
++lines;
|
||||||
}
|
}
|
||||||
} while (c != EOF);
|
}
|
||||||
|
|
||||||
|
rootconsole->ConsolePrint("[CLEANER] %i lines in cleaner.cfg", lines);
|
||||||
|
|
||||||
rootconsole->ConsolePrint("[CLEANER] %i lines", lines);
|
|
||||||
rewind(file);
|
rewind(file);
|
||||||
|
|
||||||
g_szStrings = new char*[lines];
|
g_szStrings = new char*[lines];
|
||||||
|
|
||||||
while (!feof(file))
|
while (!feof(file))
|
||||||
{
|
{
|
||||||
|
// we don't need to have 256 chars to work with here as most strings are far smaller than that
|
||||||
g_szStrings[g_iStrings] = new char[128];
|
g_szStrings[g_iStrings] = new char[128];
|
||||||
// fgets stops at n - 1 aka 255
|
// fgets stops at n - 1 aka 127
|
||||||
if (fgets(g_szStrings[g_iStrings], 128, file) != NULL)
|
if (fgets(g_szStrings[g_iStrings], 128, file) != NULL)
|
||||||
{
|
{
|
||||||
// make things a little easier on ourselves
|
// make things a little easier on ourselves
|
||||||
std::string thisstring = g_szStrings[g_iStrings];
|
std::string thisstring = g_szStrings[g_iStrings];
|
||||||
|
|
||||||
// significantly more robust way of stripping evil chars from our string so we don't crash
|
// significantly more robust way of stripping evil chars from our string so we don't crash
|
||||||
stripBadChars( thisstring );
|
// when we try to strip them. this includes newlines, control chars, non ascii unicde, etc.
|
||||||
|
stripBadChars(thisstring);
|
||||||
|
|
||||||
// copy our std::string back to char*
|
// copy our std::string back to char*
|
||||||
|
// Disgusting.
|
||||||
char* c_thisstring = &thisstring[0];
|
char* c_thisstring = &thisstring[0];
|
||||||
|
|
||||||
int len = strlen(c_thisstring);
|
int len = strlen(c_thisstring);
|
||||||
|
|
||||||
// don't strip 0 len strings
|
// don't strip tiny (including 0 len or less) strings
|
||||||
if (len <= 0)
|
if (len <= 1)
|
||||||
{
|
{
|
||||||
//rootconsole->ConsolePrint("[CLEANER] Refusing to strip a string with 0 or less length - line %i", g_iStrings );
|
rootconsole->ConsolePrint("[CLEANER] Not stripping string on -> L%i with 1 or less length! Length: %i", g_iStrings+1, strlen(c_thisstring));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rootconsole->ConsolePrint("[CLEANER] Stripping string on line %i: \"%s\" - length = %i", g_iStrings+1, c_thisstring, strlen(c_thisstring));
|
rootconsole->ConsolePrint("[CLEANER] Stripping string on -> L%i: \"%s\" - length: %i", g_iStrings+1, c_thisstring, strlen(c_thisstring));
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(g_szStrings[g_iStrings], c_thisstring);
|
strcpy(g_szStrings[g_iStrings], c_thisstring);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user