diff --git a/Include/Aurora/Parse/Parser.hpp b/Include/Aurora/Parse/Parser.hpp index e9c76319..f361de1e 100644 --- a/Include/Aurora/Parse/Parser.hpp +++ b/Include/Aurora/Parse/Parser.hpp @@ -192,4 +192,7 @@ namespace Aurora::Parse AUKN_SYM void SerializeToken(ParsableTag type, const ParseValue &value, AuString &str); AUKN_SYM void Serialize(const ParsedObject &structure, AuString &ret); + + AUKN_SYM AuResult ParseSInt(const char *begin, const char *&end); + AUKN_SYM AuResult ParseUInt(const char *begin, const char *&end); } \ No newline at end of file diff --git a/Source/Parse/Parser.cpp b/Source/Parse/Parser.cpp index f634acd6..d621bc74 100644 --- a/Source/Parse/Parser.cpp +++ b/Source/Parse/Parser.cpp @@ -4,6 +4,9 @@ File: Parser.cpp Date: 2021-6-12 Author: Reece + Note: Horrible gen 1 parser. + I'm not removing or significantly improving this. + Just build around what works, could probably wrangle a command list parser on top. ***/ #include #include "Parser.hpp" @@ -50,7 +53,6 @@ namespace Aurora::Parse }; } - template static AuFunction IsTerminating(ParseState &state, const AuUInt8(&arry)[Z]) { @@ -189,7 +191,7 @@ namespace Aurora::Parse //SysAssert(!stringLevel, "Parsed tag of string type must end with \", got {}", out); if (stringLevel) { - AuLogWarn("Parsed tag of string type must end with \", got {}", out); + SysPushErrorSyntaxError("Parsed tag of string type must end with \", got {}", out); return false; } @@ -216,18 +218,18 @@ namespace Aurora::Parse return (T(0) < val) - (val < T(0)); } - template - bool ParseInt(const AuString &in, T &out) + template + bool ParseInt(Iterator begin, Iterator &end, T &out) { T res = 0; T sign = 1; out = 0; - auto itr = in.begin(); + auto itr = begin; if constexpr (AuIsSame_v) { - if (itr != in.end()) + if (itr != end) { if (*itr == '-') { @@ -237,8 +239,9 @@ namespace Aurora::Parse } } + int perf {}; for (; - (itr != in.end()) && + (itr != end) && (*itr != '\0'); itr++) { @@ -254,75 +257,61 @@ namespace Aurora::Parse res *= 10; res += static_cast(*itr) - static_cast('0'); - if constexpr (AuIsSame_v) + if ((perf++) >= 5) { - if (old > res) + if constexpr (AuIsSame_v) { - SysPushErrorSyntaxError("Unsigned integer overflow: {}", in); - return false; + if (old > res) + { + SysPushErrorSyntaxError("Unsigned integer overflow: {}", AuString(begin, end)); + end = itr; + return false; + } } - } - else if constexpr (AuIsSame_v) - { - if (SignBit(old) != SignBit(res)) + else if constexpr (AuIsSame_v) { - SysPushErrorSyntaxError("Signed integer overflow: {}", in); - return false; + if (SignBit(old) != SignBit(res)) + { + SysPushErrorSyntaxError("Signed integer overflow: {}", AuString(begin, end)); + end = itr; + return false; + } } } } + end = itr; out = res * sign; return true; } - template - bool ParseUInt(const AuString &in, T &out) + AUKN_SYM AuResult ParseUInt(const char *begin, const char *&end) { - auto temp = AuUInt{}; - out = 0; + AuUInt temp{}; - if (!ParseInt(in, temp)) + if (!ParseInt(begin, end, temp)) { - return false; + return {}; } - if (temp > AuNumericLimits::max()) - { - return false; - } - - out = temp; - return true; + return temp; } - template - bool ParseSInt(const AuString &in, T &out) + AUKN_SYM AuResult ParseSInt(const char *begin, const char *&end) { - auto temp = AuSInt{}; - out = 0; + AuSInt temp{}; - if (!ParseInt(in, temp)) + if (!ParseInt(begin, end, temp)) { - return false; + return {}; } - if (temp > AuNumericLimits::max()) - { - return false; - } - - if (temp < AuNumericLimits::min()) - { - return false; - } - - out = temp; - return true; + return temp; } static bool ConsumeTokenPrimitiveish(ParseState &state, ParseContext &context, ParsableTag type, ParseValue &out) { + AuCtorCode_t code; AuString str; if (!ConsumeStringifedToken(state, context, type, str)) @@ -336,16 +325,16 @@ namespace Aurora::Parse } AuOptional uuid; - + auto end = str.end(); switch (type) { case ParsableTag::kParseUInt: { - return ParseUInt(str, out.primitive.uint); + return ParseInt(str.begin(), end, out.primitive.uint) && end == str.end(); } case ParsableTag::kParseSInt: { - return ParseSInt(str, out.primitive.sint); + return ParseInt(str.begin(), end, out.primitive.sint) && end == str.end(); } case ParsableTag::kParseNumber: { @@ -354,7 +343,7 @@ namespace Aurora::Parse case ParsableTag::kParseString: case ParsableTag::kParseStringVararg: { - out.string = str; + out.string = AuMove(str); break; } case ParsableTag::kParseUUID: @@ -362,7 +351,7 @@ namespace Aurora::Parse uuid = uuids::uuid::from_string(str); if (!uuid.has_value()) { - AuLogWarn("Parse Error: invalid UUID {}", str); + SysPushErrorSyntaxError("Parse Error: invalid UUID {}", str); return false; } out.UUID = uuid.value(); @@ -370,17 +359,21 @@ namespace Aurora::Parse } case ParsableTag::kParseBoolean: { - if ((str == "0") || (stricmp(str.c_str(), "false") == 0) || (stricmp(str.c_str(), "no") == 0)) + if ((str == "0") || + (stricmp(str.c_str(), "false") == 0) || + (stricmp(str.c_str(), "no") == 0)) { out.primitive.boolean = false; } - else if ((str == "1") || (stricmp(str.c_str(), "true") == 0) || (stricmp(str.c_str(), "yes") == 0)) + else if ((str == "1") || + (stricmp(str.c_str(), "true") == 0) || + (stricmp(str.c_str(), "yes") == 0)) { out.primitive.boolean = true; } else { - AuLogWarn("Parsed tag of boolean type wasn't parsable given the English string {}", str); + SysPushErrorSyntaxError("Parsed tag of boolean type wasn't parsable given the English string {}", str); return false; } break; @@ -450,7 +443,7 @@ namespace Aurora::Parse if (!ConsumeToken(state, context, ParsableTag::kParseUInt, arrayLengthBit)) { - AuLogWarn("Couldn't consume array length, label: {}, tag {}", parseBit.label, parseBit.tag); + SysPushErrorSyntaxError("Couldn't consume array length, label: {}, tag {}", parseBit.label, parseBit.tag); return false; } @@ -498,14 +491,18 @@ namespace Aurora::Parse break; } - AuLogWarn("Syntax error around: label: {}, tag {}", parseBit.label, parseBit.tag); + SysPushErrorSyntaxError("Syntax error around: label: {}, tag {}", parseBit.label, parseBit.tag); return false; } if (parseBit.vararg || parseBit.array) { parsed.count++; - parsed.value.array.push_back(parsedSingle); + if (!AuTryInsert(parsed.value.array, parsedSingle)) + { + SysPushErrorMem(); + return false; + } parsed.isArray = true; } else @@ -610,7 +607,10 @@ namespace Aurora::Parse { if (parsed.isArray) { - ret += " "; + if (ret.size()) + { + ret += " "; + } ret += AuToString(parsed.count); } @@ -618,7 +618,10 @@ namespace Aurora::Parse for (int i = 0; ((i < parsed.count)); i++) { - ret += " "; + if (ret.size()) + { + ret += " "; + } ParseValueEx parsedSingle = {}; ParseResult nestedresult = {}; @@ -648,7 +651,5 @@ namespace Aurora::Parse } } } - - ret = ret.substr(1); } } \ No newline at end of file diff --git a/Source/Process/ProcessMap.Linux.cpp b/Source/Process/ProcessMap.Linux.cpp index 3d1a06dd..e2951300 100644 --- a/Source/Process/ProcessMap.Linux.cpp +++ b/Source/Process/ProcessMap.Linux.cpp @@ -1,7 +1,29 @@ /*** - Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: ModuleInfo.Linux.cpp - Date: 2021-6-12 + Date: 2022-4-20 Author: Reece ***/ +#include +#include "ProcessMap.Linux.hpp" +#include "ProcessMap.hpp" + +namespace Aurora::Process +{ + void InitProcessMapLinux() + { + + } + + void DeinitProcessMapLinux() + { + + } + + void RescanMaps() + { + + } + +} \ No newline at end of file diff --git a/Source/Process/ProcessMap.Linux.hpp b/Source/Process/ProcessMap.Linux.hpp index 27e258ec..d30a66d8 100644 --- a/Source/Process/ProcessMap.Linux.hpp +++ b/Source/Process/ProcessMap.Linux.hpp @@ -5,3 +5,12 @@ Date: 2021-6-12 Author: Reece ***/ +#pragma once + +namespace Aurora::Process +{ + void RescanMaps(); + + void InitProcessMapLinux(); + void DeinitProcessMapLinux(); +} \ No newline at end of file diff --git a/Source/Process/ProcessMap.cpp b/Source/Process/ProcessMap.cpp index f8db6676..b8a74508 100644 --- a/Source/Process/ProcessMap.cpp +++ b/Source/Process/ProcessMap.cpp @@ -16,6 +16,10 @@ #include "ProcessMap.NT.hpp" #endif +#if defined(AURORA_IS_LINUX_DERIVED) + #include "ProcessMap.Linux.hpp" +#endif + namespace Aurora::Process { struct ModuleBasePairHash @@ -59,7 +63,12 @@ namespace Aurora::Process static const auto kPageBufferPad = 20; static AuThreadPrimitives::MutexUnique_t gMutexUnique; - static AuHashMap, ModuleBasePairHash, ModuleBasePairEq> gModuleMap; + static AuHashMap, + ModuleBasePairHash, // TODO: this precede auhashcode + ModuleBasePairEq> + gModuleMap; + static AuList
gOtherSections; static AuUInt ToLowestPageAlignment(AuUInt in) { @@ -162,6 +171,10 @@ namespace Aurora::Process InitProcessMapNt(); #endif + #if defined(AURORA_IS_LINUX_DERIVED) + InitProcessMapLinux(); + #endif + TryRescanSlow(); } @@ -170,6 +183,11 @@ namespace Aurora::Process #if defined(AURORA_PLATFORM_WIN32) MakeToolHelp32Snapshot(); #endif + + #if defined(AURORA_IS_LINUX_DERIVED) + RescanMaps(); + #endif + } void DeinitProcessMap() @@ -179,6 +197,16 @@ namespace Aurora::Process #if defined(AURORA_IS_MODERNNT_DERIVED) DeinitProcessMapNt(); #endif + + #if defined(AURORA_IS_LINUX_DERIVED) + DeinitProcessMapLinux(); + #endif + } + + void BorrowOtherSectionArray(const AuConsumer> &callback) + { + AU_LOCK_GUARD(gMutexUnique); + callback(gOtherSections); } AUKN_SYM AuOptional
GetSection(AuUInt pointer) @@ -227,6 +255,7 @@ namespace Aurora::Process AUKN_SYM Sections DumpExecutableAll() { + AU_LOCK_GUARD(gMutexUnique); try { Sections ret; @@ -234,6 +263,9 @@ namespace Aurora::Process { ret.insert(ret.end(), ptr->sections.begin(), ptr->sections.end()); } + + ret.insert(ret.end(), gOtherSections.begin(), gOtherSections.end()); + return ret; } catch (...) diff --git a/Source/Process/ProcessMap.hpp b/Source/Process/ProcessMap.hpp index f6bbd19e..e2974758 100644 --- a/Source/Process/ProcessMap.hpp +++ b/Source/Process/ProcessMap.hpp @@ -15,6 +15,8 @@ namespace Aurora::Process AuUInt modBase; }; + void BorrowOtherSectionArray(const AuConsumer> &callback); + PublicModule GetFromModuleCache(AuUInt handle); void InsertModuleCache(const ModuleBasePair &pair, const AuSPtr &mod); void RemoveModuleCache(const ModuleBasePair &eitherOr);