Exemplo n.º 1
0
        public static int CalcNameOffset(IntPtr address, bool isNoneAddress = true)
        {
            if (isNoneAddress)
            {
                long curAddress   = address.ToInt64();
                uint sizeOfStruct = (uint)Marshal.SizeOf <Win32.MemoryBasicInformation>();

                while (
                    Win32.VirtualQueryEx(MemObj.ProcessHandle, (IntPtr)curAddress, out var info, sizeOfStruct) == sizeOfStruct &&
                    info.BaseAddress != (ulong)curAddress &&
                    curAddress >= address.ToInt64() - 0x10)
                {
                    --curAddress;
                }

                return((int)(address.ToInt64() - curAddress));
            }

            var noneSig   = PatternScanner.Parse("None", 0, "4E 6F 6E 65 00");
            var sigResult = PatternScanner.FindPattern(MemObj, address, address + 0x18, new List <PatternScanner.Pattern> {
                noneSig
            }, true).Result;

            if (sigResult.ContainsKey("None"))
            {
                return((int)(sigResult["None"][0].ToInt64() - address.ToInt64()));
            }

            return(-1);
        }
Exemplo n.º 2
0
        private static bool IsValidGNamesAddress(IntPtr address, bool chunkCheck)
        {
            if (MemObj == null || !IsValidRemoteAddress(address))
            {
                return(false);
            }

            if (!chunkCheck && !IsValidRemotePointer(address, out _))
            {
                return(false);
            }

            if (!chunkCheck)
            {
                address = MemObj.ReadAddress(address);
            }

            int nullCount = 0;

            // Chunks array must have null pointers, if not then it's not valid
            for (int i = 0; i < 50 && nullCount <= 3; i++)
            {
                // Read Chunk Address
                var offset       = i * GamePointerSize();
                var chunkAddress = MemObj.ReadAddress(address + offset);
                if (chunkAddress == IntPtr.Zero)
                {
                    ++nullCount;
                }
            }

            if (nullCount <= 3)
            {
                return(false);
            }

            // Read First FName Address
            var noneFName = MemObj.ReadAddress(MemObj.ReadAddress(address));

            if (!IsValidRemoteAddress(noneFName))
            {
                return(false);
            }

            // Search for none FName
            var pattern = PatternScanner.Parse("NoneSig", 0, "4E 6F 6E 65 00");
            var result  = PatternScanner.FindPattern(MemObj, noneFName, noneFName + 0x50, new List <PatternScanner.Pattern> {
                pattern
            }, true).Result;

            return(result["NoneSig"].Count > 0);
        }
Exemplo n.º 3
0
        public static bool Initialize()
        {
            _overrideTypes           = new Dictionary <string, string>();
            _predefinedMembers       = new Dictionary <string, List <PredefinedMember> >();
            _predefinedStaticMembers = new Dictionary <string, List <PredefinedMember> >();
            _predefinedMethods       = new Dictionary <string, List <PredefinedMethod> >();
            _virtualFunctionPattern  = new Dictionary <string, VirtualFunctionPatterns>();

            // BadKeywords
            _badKeywords = new Dictionary <string, string>
            {
                { "return", "returnValue" },
                { "continue", "continueValue" },
                { "break", "breakValue" },
                { "int", "intValue" },
                { "bool", "boolValue" }
            };

            // BacChar
            _badChars = new Dictionary <string, string>
            {
                { ",", "" },
                { "!", "" },
                { "-", "" },
                { "`", "" }
            };

            // AlignasClasses
            _alignasClasses = new Dictionary <string, int>
            {
                { "ScriptStruct CoreUObject.Plane", 16 },
                { "ScriptStruct CoreUObject.Quat", 16 },
                { "ScriptStruct CoreUObject.Transform", 16 },
                { "ScriptStruct CoreUObject.Vector4", 16 },
                { "ScriptStruct Engine.RootMotionSourceGroup", 8 }
            };

            // VirtualFunctionPattern
            _virtualFunctionPattern["Class CoreUObject.Object"] = new VirtualFunctionPatterns
            {
                {
                    PatternScanner.Parse("ProcessEvent", 0, "4C 8B DC 57 48 81 EC"),
                    @"	inline void ProcessEvent(class UFunction* function, void* parms)
	{
		GetVFunction<void(*)(UObject*, class UFunction*, void*)>(this, %d)(this, function, parms);
	}"
                }
            };
            _virtualFunctionPattern["Class CoreUObject.Class"] = new VirtualFunctionPatterns
            {
                {
                    PatternScanner.Parse("CreateDefaultObject", 0, "4C 8B DC 57 48 81 EC"),
                    @"	inline UObject* CreateDefaultObject()
	{
		GetVFunction<UObject*(*)(UClass*)>(this, %d)(this);
	}"
                }
            };

            // PredefinedMembers
            _predefinedMembers["Class CoreUObject.Object"]   = GetJsonStructPreMembers("UObject");
            _predefinedMembers["Class CoreUObject.Field"]    = GetJsonStructPreMembers("UField");
            _predefinedMembers["Class CoreUObject.Struct"]   = GetJsonStructPreMembers("UStruct");
            _predefinedMembers["Class CoreUObject.Function"] = GetJsonStructPreMembers("UFunction");

            // PredefinedStaticMembers
            _predefinedStaticMembers["Class CoreUObject.Object"] = new List <PredefinedMember>
            {
                new PredefinedMember("FUObjectArray*", "GObjects")
            };

            // PredefinedMethods
            _predefinedMethods["ScriptStruct CoreUObject.Vector2D"] = new List <PredefinedMethod>
            {
                PredefinedMethod.Inline(@"	inline FVector2D()
		: X(0), Y(0)
	{ }"    ),
                PredefinedMethod.Inline(@"	inline FVector2D(float x, float y)
        : X(x), Y(y)
    { }")
            };
            _predefinedMethods["ScriptStruct CoreUObject.LinearColor"] = new List <PredefinedMethod>
            {
                PredefinedMethod.Inline(@"	inline FLinearColor()
		: R(0), G(0), B(0), A(0)
	{ }"    ),
                PredefinedMethod.Inline(@"	inline FLinearColor(float r, float g, float b, float a)
		: R(r),
		  G(g),
		  B(b),
		  A(a)
	{ }"    )
            };
            _predefinedMethods["Class CoreUObject.Object"] = new List <PredefinedMethod>
            {
                PredefinedMethod.Inline(@"	static inline TUObjectArray& GetGlobalObjects()
	{
		return GObjects->ObjObjects;
	}"    ),
                PredefinedMethod.Default("std::string GetName() const", @"std::string UObject::GetName() const
{
	std::string name(Name.GetName());
	if (Name.Number > 0)
	{
		name += '_' + std::to_string(Name.Number);
	}

	auto pos = name.rfind('/');
	if (pos == std::string::npos)
	{
		return name;
	}
	
	return name.substr(pos + 1);
}"),
                PredefinedMethod.Default("std::string GetFullName() const", @"std::string UObject::GetFullName() const
{
	std::string name;

	if (Class != nullptr)
	{
		std::string temp;
		for (auto p = Outer; p; p = p->Outer)
		{
			temp = p->GetName() + ""."" + temp;
		}

		name = Class->GetName();
		name += "" "";
		name += temp;
		name += GetName();
	}

	return name;
}"),
                PredefinedMethod.Inline(@"	template<typename T>
	static T* FindObject(const std::string& name)
	{
		for (int i = 0; i < GetGlobalObjects().Num(); ++i)
		{
			auto object = GetGlobalObjects().GetByIndex(i);
	
			if (object == nullptr)
			{
				continue;
			}
	
			if (object->GetFullName() == name)
			{
				return static_cast<T*>(object);
			}
		}
		return nullptr;
	}"    ),
                PredefinedMethod.Inline(@"	template<typename T>
	static T* FindObject()
	{
		auto v = T::StaticClass();
		for (int i = 0; i < SDK::UObject::GetGlobalObjects().Num(); ++i)
		{
			auto object = SDK::UObject::GetGlobalObjects().GetByIndex(i);

			if (object == nullptr)
			{
				continue;
			}

			if (object->IsA(v))
			{
				return static_cast<T*>(object);
			}
		}
		return nullptr;
	}"    ),
                PredefinedMethod.Inline(@"	template<typename T>
	static std::vector<T*> FindObjects(const std::string& name)
	{
		std::vector<T*> ret;
		for (int i = 0; i < GetGlobalObjects().Num(); ++i)
		{
			auto object = GetGlobalObjects().GetByIndex(i);

			if (object == nullptr)
			{
				continue;
			}

			if (object->GetFullName() == name)
			{
				ret.push_back(static_cast<T*>(object));
			}
		}
		return ret;
	}"    ),
                PredefinedMethod.Inline(@"	template<typename T>
	static std::vector<T*> FindObjects()
	{
		std::vector<T*> ret;
		auto v = T::StaticClass();
		for (int i = 0; i < SDK::UObject::GetGlobalObjects().Num(); ++i)
		{
			auto object = SDK::UObject::GetGlobalObjects().GetByIndex(i);

			if (object == nullptr)
			{
				continue;
			}

			if (object->IsA(v))
			{
				ret.push_back(static_cast<T*>(object));
			}
		}
		return ret;
	}"    ),
                PredefinedMethod.Inline(@"	static UClass* FindClass(const std::string& name)
	{
		return FindObject<UClass>(name);
	}"    ),
                PredefinedMethod.Inline(@"	template<typename T>
	static T* GetObjectCasted(std::size_t index)
	{
		return static_cast<T*>(GetGlobalObjects().GetByIndex(index));
	}"    ),
                PredefinedMethod.Default("bool IsA(UClass* cmp) const", @"bool UObject::IsA(UClass* cmp) const
{
	for (auto super = Class; super; super = static_cast<UClass*>(super->SuperField))
	{
		if (super == cmp)
		{
			return true;
		}
	}

	return false;
}"),
            };
            _predefinedMethods["Class CoreUObject.Class"] = new List <PredefinedMethod>
            {
                PredefinedMethod.Inline(@"template<typename T>
	inline T* CreateDefaultObject()
	{
		return static_cast<T*>(CreateDefaultObject());
	}"    )
            };

            /*
             * predefinedMethods["Class Engine.GameViewportClient"] =
             * {
             *  PredefinedMethod::Inline(R"(	inline void PostRender(UCanvas* Canvas)
             * {
             * return GetVFunction<void(*)(UGameViewportClient*, UCanvas*)>(this, %d)(this, Canvas);
             * })")
             * };
             */

            return(true);
        }