Exemple #1
0
    public void Objects()
    {
        // object
        Assert.AreEqual(@"{""a"":6,""b"":""hello""}", JsonReflector.Reflect(new { a = 6, b = "hello" }));

        // array
        Assert.AreEqual(@"[1,2,3,4]", JsonReflector.Reflect(new int[] { 1, 2, 3, 4 }));

        // list
        Assert.AreEqual(@"[1,2,3,4]", JsonReflector.Reflect(new List <int>()
        {
            1, 2, 3, 4
        }));

        // dictionary

        var dict = new Dictionary <string, int>()
        {
            { "k1", 1 },
            { "k2", 2 },
            { "k3", 3 },
        };

        Assert.AreEqual(@"{""k1"":1,""k2"":2,""k3"":3}", JsonReflector.Reflect(dict));

        var nonStringKeys = new Dictionary <object, int>()
        {
            { new { x = 1 }, 1 },
            { new { z = 1 }, 2 },
            { new { fish = 1, z = 2 }, 3 },
        };

        Assert.AreEqual(@"{""{ x = 1 }"":1,""{ z = 1 }"":2,""{ fish = 1, z = 2 }"":3}", JsonReflector.Reflect(nonStringKeys));
    }
Exemple #2
0
        public override void Process(string includePath)
        {
            // Read File
            var fileStr = ReadThisFile(includePath);

            // Replace Main stuff
            fileStr.BaseStr.Replace("/*!!INCLUDE!!*/", TargetLang.GetFileHeader(_pragmas, _include, true));
            fileStr.BaseStr.Replace("/*!!FOOTER!!*/", TargetLang.GetFileFooter());

            var    jStruct         = JsonReflector.GetStruct("FUObjectItem");
            string fUObjectItemStr = string.Empty;

            // Replace
            foreach (var(_, var) in jStruct.Vars)
            {
                fUObjectItemStr += var.VarType.All(char.IsDigit)
                    ? $"\tunsigned char {var.Name} [{var.VarType}];{Utils.NLine}"
                    : $"\t{var.VarType} {var.Name};{Utils.NLine}";
            }

            fileStr.BaseStr.Replace("/*!!DEFINE!!*/", Generator.IsGObjectsChunks ? "#define GOBJECTS_CHUNKS" : "");
            fileStr.BaseStr.Replace("/*!!POINTER_SIZE!!*/", Utils.GamePointerSize().ToString());
            fileStr.BaseStr.Replace("/*!!FUObjectItem_MEMBERS!!*/", fUObjectItemStr);

            // Write File
            CopyToSdk(fileStr);
        }
Exemple #3
0
        //----------------------------------------------------------------------------------------------------

        public static void Query(RequestAdapter req, string path)
        {
            // if we have already cached the query then use that

            if (req.CachedContext != null)
            {
                var cache = req.CachedContext as CachedQuery;
                var query = cache.Q;

                if (cache.Reselect)
                {
                    query.Select();
                    req.Respond(JsonReflector.Reflect(query.Execute()));
                    query.Clear();
                }
                else
                {
                    req.Respond(JsonReflector.Reflect(query.Execute()));
                }
            }

            // otherwise execute it

            else
            {
                var query = new Query(path, Unium.Root).Select();
                req.Respond(JsonReflector.Reflect(query.Execute()));
            }
        }
Exemple #4
0
    public void EnumsAndValueTypes()
    {
        Assert.AreEqual(@"""Second""", JsonReflector.Reflect(TestEnum.Second));
        Assert.AreEqual(@"null", JsonReflector.Reflect((TestEnum)100));

        Assert.AreEqual(@"{""x"":3,""y"":5,""z"":100}", JsonReflector.Reflect(new Vector3(3.0f, 5.0f, 100.0f)));
    }
Exemple #5
0
    public void Converters()
    {
        JsonSerialiser aSerializer = new SerialiseType();

        JsonReflector.Add(typeof(A), aSerializer);
        Assert.AreEqual(@"TestReflection+A", JsonReflector.Reflect(new A()));
        Assert.AreEqual(@"TestReflection+B", JsonReflector.Reflect(new B()));
    }
Exemple #6
0
        //----------------------------------------------------------------------------------------------------

        public static void HandlerStatus(RequestAdapter req, string path)
        {
            req.Respond(JsonReflector.Reflect(new
            {
                FPS         = 1.0f / Time.smoothDeltaTime,
                RunningTime = Time.realtimeSinceStartup,
                Scene       = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name,
            }));
        }
Exemple #7
0
    public void PrimitiveTypes()
    {
        Assert.AreEqual("null", JsonReflector.Reflect(null));
        Assert.AreEqual("true", JsonReflector.Reflect(true));
        Assert.AreEqual("7", JsonReflector.Reflect(7));
        Assert.AreEqual("3.14", JsonReflector.Reflect(3.14));
        Assert.AreEqual(@"""c""", JsonReflector.Reflect('c'));
        Assert.AreEqual(@"""hello""", JsonReflector.Reflect("hello"));

        // edge cases

        Assert.AreEqual(int.MaxValue.ToString(), JsonReflector.Reflect(int.MaxValue));
        Assert.AreEqual(@"""':\\{}\""""", JsonReflector.Reflect(@"':\{}"""));
    }
Exemple #8
0
        //----------------------------------------------------------------------------------------------------

        public static void HandlerAbout(RequestAdapter req, string path)
        {
            req.Respond(JsonReflector.Reflect(new
            {
                Unium       = Unium.Version.ToString(2),
                Unity       = Application.unityVersion,
                Mono        = Environment.Version.ToString(),
                IsEditor    = Application.isEditor,
                Product     = Application.productName,
                Company     = Application.companyName,
                Version     = Application.version,
                IPAddress   = Util.DetectPublicIPAddress(),
                FPS         = 1.0f / Time.smoothDeltaTime,
                RunningTime = Time.realtimeSinceStartup,
                Scene       = SceneManager.GetActiveScene().name,
            }));
        }
Exemple #9
0
        override public string Convert(object o)
        {
            var t = o as Transform;

            if (t == null)
            {
                return("null");
            }

            var json = new JsonBuilder();

            json.BeginObject();

            json.Name("name");
            json.StringValue(t.name);


            json.Name("position");
            json.Value(JsonReflector.Reflect(t.position));

            json.Name("rotation");
            json.Value(JsonReflector.Reflect(t.rotation));

            json.Name("scale");
            json.Value(JsonReflector.Reflect(t.localScale));

            json.Name("children");
            json.BeginArray();

            foreach (Transform c in t)
            {
                if (c != null)
                {
                    json.StringValue(c.name);
                }
            }

            json.EndArray();

            json.EndObject();

            return(json.GetString());
        }
Exemple #10
0
        //----------------------------------------------------------------------------------------------------

        static void DownloadFile(RequestAdapter req, string filepath)
        {
#if UNITY_ANDROID
            /*
             * var data = new WWW( filepath );
             *
             * while( !data.isDone )
             * {
             *  Thread.Sleep( 10 );
             * }
             *
             * if( string.IsNullOrEmpty( data.error ) )
             * {
             *  req.SetContentType( GetMimeType( filepath ) );
             *  req.Respond( data.bytes );
             * }
             * else
             * {
             *  req.Reject( ResponseCode.InternalServerError );
             * }
             */
            req.Reject(ResponseCode.InternalServerError);
#else
            // System.IO

            if ((File.GetAttributes(filepath) & FileAttributes.Directory) == FileAttributes.Directory)
            {
                // list contents of directory

                var files = from c in Directory.GetFileSystemEntries(filepath) select Path.GetFileName(c);

                req.Respond(JsonReflector.Reflect(files.ToArray()));
            }
            else
            {
                // dump bytes

                req.SetContentType(GetMimeType(filepath));
                req.Respond(File.ReadAllBytes(filepath));
            }
#endif
        }
Exemple #11
0
        //----------------------------------------------------------------------------------------------------

        static void DownloadFileNative(RequestAdapter req, string filepath)
        {
            // System.IO

            if ((File.GetAttributes(filepath) & FileAttributes.Directory) == FileAttributes.Directory)
            {
                // list contents of directory

                var files = from c in Directory.GetFileSystemEntries(filepath) select Path.GetFileName(c);

                req.Respond(JsonReflector.Reflect(files.ToArray()));
            }
            else
            {
                // dump bytes

                req.SetContentType(GetMimeType(filepath));
                req.Respond(File.ReadAllBytes(filepath));
            }
        }
Exemple #12
0
        private static IEnumerator LoadScene(RequestAdapter req, string name)
        {
            var asyncOp = SceneManager.LoadSceneAsync(name, LoadSceneMode.Single);

            if (asyncOp == null)
            {
                req.Reject(ResponseCode.NotFound);
            }
            else
            {
                asyncOp.allowSceneActivation = true;

                while (asyncOp.isDone == false)
                {
                    yield return(asyncOp);
                }

                req.Respond(JsonReflector.Reflect(new { scene = name }));
            }
        }
Exemple #13
0
        //----------------------------------------------------------------------------------------------------

        public static void HandlerScene(RequestAdapter req, string path)
        {
            // if path empty then list all loaded scenes

            if (string.IsNullOrEmpty(path) || path.Length <= 1)
            {
                var scenes = new List <object>();

#if UNITY_EDITOR
                foreach (var scene in EditorBuildSettings.scenes)
                {
                    scenes.Add(new
                    {
                        name    = Path.GetFileNameWithoutExtension(scene.path),
                        path    = scene.path,
                        enabled = scene.enabled
                    });
                }
#else
                for (int i = 0; i < SceneManager.sceneCount; i++)
                {
                    var scene = SceneManager.GetSceneAt(i);

                    scenes.Add(new {
                        name    = scene.name,
                        path    = scene.path,
                        enabled = true
                    });
                }
#endif

                req.Respond(JsonReflector.Reflect(scenes.ToArray()));
            }

            // otherwise load scene

            else
            {
                UniumComponent.Singleton.StartCoroutine(LoadScene(req, path.Substring(1)));
            }
        }
Exemple #14
0
        private static async Task Test()
        {
            Utils.MemObj  = new Memory.Memory(Utils.DetectUnrealGame());
            Utils.ScanObj = new Scanner(Utils.MemObj);

            Utils.MemObj.SuspendProcess();
            JsonReflector.LoadJsonEngine("EngineBase");

            await new SdkGenerator((IntPtr)0x7FF759482B00, (IntPtr)0x7FF75959F1A8).Start(new AgentRequestInfo());

            //var fPointer = new EngineClasses.UField();
            //await fPointer.ReadData((IntPtr)0x228E0C92B30);
            //var ss = JsonReflector.StructsList;
            //var gg = await GObjectsFinder.Find();
            //var gg = await GNamesFinder.Find();
            //var gg = await new Scanner(Utils.MemObj).Scan(50, Scanner.ScanAlignment.Alignment4Bytes, Scanner.ScanType.TypeExact);
            //var pat = PatternScanner.Parse("None", 0, "4E 6F 6E 65 00", 0xFF);
            //var gg = await PatternScanner.FindPattern(Utils.MemObj, new List<PatternScanner.Pattern>() { pat });

            Console.WriteLine("FINIIIISHED");
        }
Exemple #15
0
        private static List <PredefinedMember> GetJsonStructPreMembers(string jStructName)
        {
            var jStruct = JsonReflector.GetStruct(jStructName);
            var varList = new List <PredefinedMember>();

            foreach (var(_, jStructVar) in jStruct.Vars)
            {
                if (jStructVar.FromSuper)
                {
                    continue;
                }

                string jVarType = jStructVar.VarType
                                  .Replace("int32", "int32_t")
                                  .Replace("int16", "int16_t")
                                  .Replace("int8", "int8_t")

                                  .Replace("uint32", "uint32_t")
                                  .Replace("uint16", "uint16_t")
                                  .Replace("uint8", "uint8_t");

                PredefinedMember cur;
                if (Utils.IsNumber(jVarType))
                {
                    cur.Name = $"{jStructVar.Name}[{jVarType}]";
                    cur.Type = "unsigned char ";
                }
                else
                {
                    cur.Name = jStructVar.Name;
                    cur.Type = jStructVar.IsPointer && !jVarType.Contains("void*") ? $"class {jVarType}" : jVarType;
                }

                varList.Add(cur);
            }

            return(varList);
        }
Exemple #16
0
        public static bool IsValidGObjectsAddress(IntPtr chunksAddress)
        {
            if (JsonReflector.StructsList.Count == 0)
            {
                throw new NullReferenceException("You must init `JsonReflector` first.");
            }

            // => Get information
            var objectItem     = JsonReflector.GetStruct("FUObjectItem");
            var objectItemSize = objectItem.GetSize();

            var objectInfo       = JsonReflector.GetStruct("UObject");
            var objOuter         = objectInfo["Outer"].Offset;
            var objInternalIndex = objectInfo["InternalIndex"].Offset;
            var objNameIndex     = objectInfo["Name"].Offset;
            // => Get information

            IntPtr addressHolder = chunksAddress;

            if (MemObj == null)
            {
                throw new NullReferenceException("`MemObj` is null !!");
            }

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

            /*
             * NOTE:
             * Nested loops will be slow, split-ed best.
             */
            const int objCount = 2;
            var       objects  = new IntPtr[objCount];
            var       vTables  = new IntPtr[objCount];

            // Check (UObject*) Is Valid Pointer
            for (int i = 0; i < objCount; i++)
            {
                int offset = objectItemSize * i;
                if (!IsValidRemotePointer(addressHolder + offset, out objects[i]))
                {
                    return(false);
                }
            }

            // Check (VTable) Is Valid Pointer
            for (int i = 0; i < objCount; i++)
            {
                if (!IsValidRemotePointer(objects[i], out vTables[i]))
                {
                    return(false);
                }
            }

            // Check (InternalIndex) Is Valid
            for (int i = 0; i < objCount; i++)
            {
                int internalIndex = MemObj.Read <int>(objects[i] + objInternalIndex);
                if (internalIndex != i)
                {
                    return(false);
                }
            }

            // Check (Outer) Is Valid
            // first object must have Outer == nullptr(0x0000000000)
            int uOuter = MemObj.Read <int>(objects[0] + objOuter);

            if (uOuter != 0)
            {
                return(false);
            }

            // Check (FName_index) Is Valid
            // 2nd object must have FName_index == 100
            int uFNameIndex = MemObj.Read <int>(objects[1] + objNameIndex);

            return(uFNameIndex == 100);
        }
Exemple #17
0
        private static async Task ExecuteTasks(UsersInfo curUser, QuestionPrediction uTask, SocketUserMessage messageParam, SocketCommandContext context)
        {
            var requestInfo = new AgentRequestInfo
            {
                User          = curUser,
                SocketMessage = messageParam,
                Context       = context
            };

            #region Lock process, auto detect process
            if (uTask.TypeEnum() == EQuestionType.LockProcess ||
                uTask.TypeEnum() == EQuestionType.Find && uTask.TaskEnum() == EQuestionTask.Process ||
                uTask.TypeEnum() == EQuestionType.Set && uTask.TaskEnum() == EQuestionTask.Process)
            {
                // Try to get process id
                bool findProcessId = !context.Message.Content.Contains("0x")
                    ? int.TryParse(Regex.Match(context.Message.Content, @"\d+").Value, out int processId)
                    : int.TryParse(context.Message.Content.Split("0x")[1], NumberStyles.HexNumber, new NumberFormatInfo(), out processId);

                // Try auto detect it
                if (!findProcessId)
                {
                    processId = Utils.DetectUnrealGame();
                }

                // not valid process
                if (processId == 0 || !Memory.Memory.IsValidProcess(processId))
                {
                    await context.User.SendMessageAsync($"I can't found your `target`. " +
                                                        (!findProcessId ? "\nI tried to `detect any running target`, but i can't `see anyone`. !! " : null) +
                                                        DiscordText.GetRandomSadEmoji());

                    return;
                }

                // Setup Memory
                Utils.MemObj  = new Memory.Memory(processId);
                Utils.ScanObj = new Scanner(Utils.MemObj);

                Utils.MemObj.SuspendProcess();

                // Get Game Unreal Version
                if (!Utils.UnrealEngineVersion(out string ueVersion) || string.IsNullOrWhiteSpace(ueVersion))
                {
                    ueVersion = "Can Not Detected";
                }

                // Load Engine File
                // TODO: Make engine name dynamically stetted by user
                string corePath  = Path.Combine(ConfigPath, "EngineCore");
                var    coreNames = Directory.EnumerateFiles(corePath).Select(Path.GetFileName).ToList();

                string ueVersionO = ueVersion;
                ueVersion = await Utils.DiscordManager.OptionsQuestion(
                    requestInfo,
                    $"Select EngineCore file to use.{Utils.NLine}(Detected For Your Target Is `{ueVersion}`)",
                    coreNames);

                JsonReflector.LoadJsonEngine(ueVersion);

                var emb = new EmbedBuilder
                {
                    Color       = Color.Green,
                    Title       = "Target Info",
                    Description = "**Information** about your __target__.",
                };
                emb.WithUrl(Utils.DonateUrl);
                emb.WithFooter(Utils.DiscordFooterText, Utils.DiscordFooterImg);

                emb.AddField("Process ID", $"0x{Utils.MemObj.TargetProcess.Id:X} | {Utils.MemObj.TargetProcess.Id}");
                emb.AddField("Game Architecture", Utils.MemObj.Is64Bit ? "64Bit" : "32bit");
                emb.AddField("Window Name", Utils.MemObj.TargetProcess.MainWindowTitle);
                emb.AddField("Exe Name", Path.GetFileName(Utils.MemObj.TargetProcess.MainModule?.FileName));
                emb.AddField("Modules Count", Utils.MemObj.TargetProcess.Modules.Count);
                emb.AddField("Unreal Version", ueVersionO);

                await context.User.SendMessageAsync(embed : emb.Build());
            }
            #endregion

            #region Finder
            else if (uTask.TypeEnum() == EQuestionType.Find)
            {
                if (Utils.MemObj == null)
                {
                    if (uTask.TaskEnum() == EQuestionTask.None)
                    {
                        await context.User.SendMessageAsync(DiscordText.GetRandomNotUnderstandString());
                    }
                    else
                    {
                        await context.User.SendMessageAsync($"Give me your target FIRST !!");
                    }
                    curUser.LastOrder = UserOrder.GetProcess;
                    return;
                }

                if (uTask.TaskEnum() == EQuestionTask.None)
                {
                    await context.User.SendMessageAsync(DiscordText.GetRandomNotUnderstandString());

                    return;
                }

                var lastMessage = await context.User.SendMessageAsync($":white_check_mark: Working on that.");

                // Do work
                var finderResult = new List <IntPtr>();
                switch (uTask.TaskEnum())
                {
                case EQuestionTask.GNames:
                    finderResult = await GNamesFinder.Find(requestInfo);

                    break;

                case EQuestionTask.GObject:
                    finderResult = await GObjectsFinder.Find(requestInfo);

                    break;
                }

                if (finderResult.Empty())
                {
                    await lastMessage.ModifyAsync(msg => msg.Content = ":x: Can't found any thing !!");

                    return;
                }

                var emb = new EmbedBuilder
                {
                    Color       = Color.Green,
                    Title       = $"Finder Result ({uTask.TaskEnum():G})",
                    Description = "That's what i found for you :-\n\n",
                };
                emb.WithUrl(Utils.DonateUrl);
                emb.WithFooter(Utils.DiscordFooterText, Utils.DiscordFooterImg);

                bool isGnames = uTask.TaskEnum() == EQuestionTask.GNames;
                for (int i = 0; i < finderResult.Count; i++)
                {
                    string validStr = (isGnames ? Utils.IsValidGNamesAddress(finderResult[i]) : Utils.IsTUobjectArray(finderResult[i])) ? "Valid" : "Not Valid";
                    emb.Description += $"{DiscordText.GetEmojiNumber(i + 1, true)}) `0x{finderResult[i].ToInt64():X}` ({validStr}).{Utils.NLine}";
                }

                await lastMessage.ModifyAsync(msg =>
                {
                    msg.Content = string.Empty;
                    msg.Embed   = emb.Build();
                });

                await lastMessage.AddReactionsAsync(DiscordText.GenEmojiNumberList(finderResult.Count, false));
            }
            #endregion

            #region Sdk Generator
            else if (uTask.TypeEnum() == EQuestionType.SdkDump)
            {
                if (Utils.MemObj == null)
                {
                    await context.User.SendMessageAsync($"Give me your target FIRST !!");

                    curUser.LastOrder = UserOrder.GetProcess;
                    return;
                }

                var dumpState = await new SdkGenerator(curUser.GobjectsPtr, curUser.GnamesPtr).Start(requestInfo);
                if (dumpState.State == SdkGenerator.GeneratorState.Good)
                {
                    await context.Channel.SendMessageAsync($"__Take__ => {DateTime.Now - dumpState.StartTime:t}");
                }
                else
                {
                    await context.Channel.SendMessageAsync($"__Problem__ => {dumpState.State:G}");
                }
            }
            #endregion

            #region Open
            else if (uTask.TypeEnum() == EQuestionType.Open)
            {
                if (uTask.TaskEnum() == EQuestionTask.Sdk)
                {
                    Utils.OpenFolder(GenPath);
                }
                else if (uTask.TaskEnum() == EQuestionTask.Tool)
                {
                    Utils.OpenFolder(Environment.CurrentDirectory);
                }
            }
            #endregion

            #region Help
            else if (uTask.TypeEnum() == EQuestionType.Help)
            {
                var emb = new EmbedBuilder();
                emb.WithUrl(Utils.DonateUrl);
                emb.WithFooter(Utils.DiscordFooterText, Utils.DiscordFooterImg);

                emb.Title       = "How To Use";
                emb.Description = File.ReadAllText(Path.Combine(ConfigPath, "help.txt"));

                await context.Channel.SendMessageAsync(embed : emb.Build());
            }
            #endregion

            #region Set
            else if (uTask.TypeEnum() == EQuestionType.Set)
            {
                if (Utils.MemObj == null)
                {
                    if (uTask.TaskEnum() == EQuestionTask.None)
                    {
                        await context.User.SendMessageAsync(DiscordText.GetRandomNotUnderstandString());
                    }
                    else
                    {
                        await context.User.SendMessageAsync($"Give me your target FIRST !!");
                    }
                    curUser.LastOrder = UserOrder.GetProcess;
                    return;
                }

                bool foundAddress;
                long address;

                if (context.Message.Content.Contains("0x"))
                {
                    foundAddress = long.TryParse(context.Message.Content.Split("0x")[1],
                                                 NumberStyles.HexNumber, new NumberFormatInfo(), out address);
                }
                else
                {
                    foundAddress = false;
                    address      = 0x0;
                }

                if (!foundAddress)
                {
                    await context.Channel.SendMessageAsync($"**What to set** !!, __I can't see any thing__.!");

                    return;
                }

                if (uTask.TaskEnum() == EQuestionTask.GNames)
                {
                    if (Utils.IsValidGNamesAddress((IntPtr)address))
                    {
                        curUser.GnamesPtr = (IntPtr)address;
                    }
                    else
                    {
                        await context.Channel.SendMessageAsync($"**Looks wrong address** !!, `Remember i need a static address`.");
                    }
                }
                else if (uTask.TaskEnum() == EQuestionTask.GObject)
                {
                    if (Utils.IsTUobjectArray((IntPtr)address))
                    {
                        curUser.GobjectsPtr = (IntPtr)address;
                    }
                    else
                    {
                        await context.Channel.SendMessageAsync($"**Looks wrong address** !!, `Remember i need a static address`.");
                    }
                }
            }
            #endregion
        }
 public void Reply(object data)
 {
     Socket.Send(id, "data", JsonReflector.Reflect(data));
 }
Exemple #19
0
    public static string ExecuteGQL(string queryString)
    {
        var query = new Query(queryString, Unium.Root).Select();

        return(JsonReflector.Reflect(query.Execute()));
    }
Exemple #20
0
        //----------------------------------------------------------------------------------------------------
        // serialisers for value types

        static void SetupTypeHandlers()
        {
            JsonReflector.Add(typeof(GameObject), new SerialiseGameObject());
            JsonReflector.Add(typeof(Transform), new SerialiseTransform());
        }
Exemple #21
0
 private void Reply(object data)
 {
     SendImpl(ID, "data", JsonReflector.Reflect(data));
 }