Esempio n. 1
0
        private void readWriteAddressMemoryMenuItem_Click(object sender, EventArgs e)
        {
            PromptBox prompt = new PromptBox();

            if (prompt.ShowDialog() == DialogResult.OK)
            {
                IntPtr address       = new IntPtr(-1);
                IntPtr regionAddress = IntPtr.Zero;
                long   regionSize    = 0;
                bool   found         = false;

                try
                {
                    address = ((long)BaseConverter.ToNumberParse(prompt.Value)).ToIntPtr();
                }
                catch
                {
                    PhUtils.ShowError("You have entered an invalid address.");

                    return;
                }

                List <MemoryItem> items = new List <MemoryItem>();

                foreach (MemoryItem item in _provider.Dictionary.Values)
                {
                    items.Add(item);
                }

                items.Sort((i1, i2) => i1.Address.CompareTo(i2.Address));

                int i = 0;

                foreach (MemoryItem item in items)
                {
                    if (item.Address.CompareTo(address) > 0)
                    {
                        MemoryItem regionItem = items[i - 1];

                        listMemory.Items[regionItem.Address.ToString()].Selected = true;
                        listMemory.Items[regionItem.Address.ToString()].EnsureVisible();
                        regionAddress = regionItem.Address;
                        regionSize    = regionItem.Size;
                        found         = true;

                        break;
                    }

                    i++;
                }

                if (!found)
                {
                    PhUtils.ShowError("Unable to find the memory address.");
                    return;
                }

                MemoryEditor m_e = MemoryEditor.ReadWriteMemory(_pid, regionAddress, (int)regionSize, false,
                                                                new Program.MemoryEditorInvokeAction(delegate(MemoryEditor f) { f.Select(address.Decrement(regionAddress).ToInt64(), 1); }));
            }
        }
Esempio n. 2
0
        private void readMemoryModuleMenuItem_Click(object sender, EventArgs e)
        {
            ModuleItem item = (ModuleItem)listModules.SelectedItems[0].Tag;

            MemoryEditor.ReadWriteMemory(_pid, item.BaseAddress.ToIntPtr(), item.Size, true);
        }
Esempio n. 3
0
 public Form1()
 {
     MemoryEditor.Init(false);
     InitializeComponent();
     timer1.Start();
 }
Esempio n. 4
0
 void NodeInformation()
 {
     ImGui.Text("Name: " + selectedNode.Name);
     if (selectedNode.Children != null)
     {
         ImGui.Text(selectedNode.Children.Count + " children");
     }
     else
     {
         ImGui.Text(string.Format("Size: {0}", LibreLancer.DebugDrawing.SizeSuffix(selectedNode.Data.Length)));
         if (ImGui.Button("Hex Editor"))
         {
             hexdata = new byte[selectedNode.Data.Length];
             selectedNode.Data.CopyTo(hexdata, 0);
             mem       = new MemoryEditor();
             hexEditor = true;
         }
         if (ImGui.Button("Float Editor"))
         {
             floats = new float[selectedNode.Data.Length / 4];
             for (int i = 0; i < selectedNode.Data.Length / 4; i++)
             {
                 floats[i] = BitConverter.ToSingle(selectedNode.Data, i * 4);
             }
             floatEditor = true;
         }
         if (ImGui.Button("Int Editor"))
         {
             ints = new int[selectedNode.Data.Length / 4];
             for (int i = 0; i < selectedNode.Data.Length / 4; i++)
             {
                 ints[i] = BitConverter.ToInt32(selectedNode.Data, i * 4);
             }
             intEditor = true;
         }
         if (ImGui.Button("Color Picker"))
         {
             var len = selectedNode.Data.Length / 4;
             if (len < 3)
             {
                 pickcolor4 = true;
                 color4     = new System.Numerics.Vector4(0, 0, 0, 1);
             }
             else if (len == 3)
             {
                 pickcolor4 = false;
                 color3     = new System.Numerics.Vector3(
                     BitConverter.ToSingle(selectedNode.Data, 0),
                     BitConverter.ToSingle(selectedNode.Data, 4),
                     BitConverter.ToSingle(selectedNode.Data, 8));
             }
             else if (len > 3)
             {
                 pickcolor4 = true;
                 color4     = new System.Numerics.Vector4(
                     BitConverter.ToSingle(selectedNode.Data, 0),
                     BitConverter.ToSingle(selectedNode.Data, 4),
                     BitConverter.ToSingle(selectedNode.Data, 8),
                     BitConverter.ToSingle(selectedNode.Data, 12));
             }
             colorPicker = true;
         }
         if (ImGui.Button("Texture Viewer"))
         {
             Texture2D tex = null;
             try
             {
                 using (var stream = new MemoryStream(selectedNode.Data))
                 {
                     tex = LibreLancer.ImageLib.Generic.FromStream(stream);
                 }
                 var title = string.Format("{0} ({1})", selectedNode.Name, Title);
                 var tab   = new TextureViewer(title, tex);
                 main.AddTab(tab);
             }
             catch (Exception)
             {
                 ErrorPopup("Node data couldn't be opened as texture");
             }
         }
         if (ImGui.Button("Play Audio"))
         {
             var data = main.Audio.AllocateData();
             using (var stream = new MemoryStream(selectedNode.Data))
             {
                 main.Audio.PlaySound(stream);
             }
         }
         if (ImGui.Button("Import Data"))
         {
             string path;
             if ((path = FileDialog.Open()) != null)
             {
                 selectedNode.Data = File.ReadAllBytes(path);
             }
         }
         if (ImGui.Button("Export Data"))
         {
             string path;
             if ((path = FileDialog.Save()) != null)
             {
                 File.WriteAllBytes(path, selectedNode.Data);
             }
         }
         if (ImGui.Button("View Model"))
         {
             IDrawable drawable = null;
             try
             {
                 drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources);
                 drawable.Initialize(main.Resources);
             }
             catch (Exception) { ErrorPopup("Could not open as model"); drawable = null; }
             if (drawable != null)
             {
                 main.AddTab(new ModelViewer("Model Viewer", drawable, main.RenderState, main.Viewport));
             }
         }
     }
 }
Esempio n. 5
0
        unsafe void NodeInformation()
        {
            ImGui.BeginChild("##scrollnode");
            ImGui.Text("Name: " + selectedNode.Name);
            if (selectedNode.Children != null)
            {
                ImGui.Text(selectedNode.Children.Count + " children");
                if (selectedNode != Utf.Root)
                {
                    ImGui.Separator();
                    ImGui.Text("Actions:");
                    if (ImGui.Button("Add Data"))
                    {
                        Confirm("Adding data will delete this node's children. Continue?", () =>
                        {
                            selectedNode.Children = null;
                            selectedNode.Data     = new byte[0];
                        });
                    }
                    if (ImGui.Button("Import Data"))
                    {
                        ImGui.OpenPopup("importactions");
                    }
                    if (ImGui.BeginPopup("importactions"))
                    {
                        if (ImGui.MenuItem("File"))
                        {
                            Confirm("Importing data will delete this node's children. Continue?", () =>
                            {
                                string path;
                                if ((path = FileDialog.Open()) != null)
                                {
                                    selectedNode.Children = null;
                                    selectedNode.Data     = File.ReadAllBytes(path);
                                }
                            });
                        }
                        if (ImGui.MenuItem("Texture"))
                        {
                            Confirm("Importing data will delete this node's children. Continue?", () =>
                            {
                                ImportTexture();
                            });
                        }
                        ImGui.EndPopup();
                    }

                    if (selectedNode.Name.StartsWith("joint map", StringComparison.OrdinalIgnoreCase))
                    {
                        if (ImGui.Button("View Joint Map"))
                        {
                            JointMapView jmv;
                            if ((jmv = JointMapView.Create(selectedNode)) != null)
                            {
                                jointViews.Add(jmv);
                            }
                        }
                        ;
                    }

                    if (selectedNode.Name.StartsWith("object map", StringComparison.OrdinalIgnoreCase))
                    {
                        if (ImGui.Button("View Object Map"))
                        {
                            JointMapView jmv;
                            if ((jmv = JointMapView.Create(selectedNode)) != null)
                            {
                                jointViews.Add(jmv);
                            }
                        }
                        ;
                    }
                }
            }
            else if (selectedNode.Data != null)
            {
                ImGui.Text(string.Format("Size: {0}", LibreLancer.DebugDrawing.SizeSuffix(selectedNode.Data.Length)));
                ImGui.Separator();
                if (selectedNode.Data.Length > 0)
                {
                    ImGui.Text("Previews:");
                    //String Preview
                    ImGui.Text("String:");
                    ImGui.SameLine();
                    ImGui.InputText("##strpreview", selectedNode.Data, (uint)Math.Min(selectedNode.Data.Length, 32), ImGuiInputTextFlags.ReadOnly, DummyCallback);
                    //Float Preview
                    ImGui.Text("Float:");
                    fixed(byte *ptr = selectedNode.Data)
                    {
                        for (int i = 0; i < 4 && (i < selectedNode.Data.Length / 4); i++)
                        {
                            ImGui.SameLine();
                            ImGui.Text(((float *)ptr)[i].ToString());
                        }
                    }

                    //Int Preview
                    ImGui.Text("Int:");
                    fixed(byte *ptr = selectedNode.Data)
                    {
                        for (int i = 0; i < 4 && (i < selectedNode.Data.Length / 4); i++)
                        {
                            ImGui.SameLine();
                            ImGui.Text(((int *)ptr)[i].ToString());
                        }
                    }
                }
                else
                {
                    ImGui.Text("Empty Data");
                }
                ImGui.Separator();
                ImGui.Text("Actions:");
                if (ImGui.Button("Edit"))
                {
                    ImGui.OpenPopup("editactions");
                }
                if (ImGui.BeginPopup("editactions"))
                {
                    if (ImGui.MenuItem("String Editor"))
                    {
                        if (selectedNode.Data.Length > 255)
                        {
                            popups.OpenPopup("Confirm?##stringedit");
                        }
                        else
                        {
                            text.SetBytes(selectedNode.Data, selectedNode.Data.Length);
                            popups.OpenPopup("String Editor");
                        }
                    }
                    if (ImGui.MenuItem("Hex Editor"))
                    {
                        hexdata = new byte[selectedNode.Data.Length];
                        selectedNode.Data.CopyTo(hexdata, 0);
                        mem = new MemoryEditor();
                        popups.OpenPopup("Hex Editor");
                    }
                    if (ImGui.MenuItem("Float Editor"))
                    {
                        floats = new float[selectedNode.Data.Length / 4];
                        for (int i = 0; i < selectedNode.Data.Length / 4; i++)
                        {
                            floats[i] = BitConverter.ToSingle(selectedNode.Data, i * 4);
                        }
                        floatEditor = true;
                    }
                    if (ImGui.MenuItem("Int Editor"))
                    {
                        ints = new int[selectedNode.Data.Length / 4];
                        for (int i = 0; i < selectedNode.Data.Length / 4; i++)
                        {
                            ints[i] = BitConverter.ToInt32(selectedNode.Data, i * 4);
                        }
                        intEditor = true;
                    }
                    if (ImGui.MenuItem("Color Picker"))
                    {
                        var len = selectedNode.Data.Length / 4;
                        if (len < 3)
                        {
                            pickcolor4 = true;
                            color4     = Color4.Black;
                        }
                        else if (len == 3)
                        {
                            pickcolor4 = false;
                            color3     = new Vector3(
                                BitConverter.ToSingle(selectedNode.Data, 0),
                                BitConverter.ToSingle(selectedNode.Data, 4),
                                BitConverter.ToSingle(selectedNode.Data, 8));
                        }
                        else if (len > 3)
                        {
                            pickcolor4 = true;
                            color4     = new Vector4(
                                BitConverter.ToSingle(selectedNode.Data, 0),
                                BitConverter.ToSingle(selectedNode.Data, 4),
                                BitConverter.ToSingle(selectedNode.Data, 8),
                                BitConverter.ToSingle(selectedNode.Data, 12));
                        }
                        popups.OpenPopup("Color Picker");
                    }
                    ImGui.EndPopup();
                }
                ImGui.NextColumn();
                if (ImGui.Button("Texture Viewer"))
                {
                    Texture2D tex = null;
                    try
                    {
                        using (var stream = new MemoryStream(selectedNode.Data))
                        {
                            tex = LibreLancer.ImageLib.Generic.FromStream(stream);
                        }
                        var title = string.Format("{0} ({1})", selectedNode.Name, Title);
                        var tab   = new TextureViewer(title, tex, null);
                        main.AddTab(tab);
                    }
                    catch (Exception ex)
                    {
                        ErrorPopup("Node data couldn't be opened as texture:\n" + ex.Message);
                    }
                }
                if (ImGui.Button("Play Audio"))
                {
                    var data = main.Audio.AllocateData();
                    using (var stream = new MemoryStream(selectedNode.Data))
                    {
                        main.Audio.PlayStream(stream);
                    }
                }
                if (ImGui.Button("Import Data"))
                {
                    ImGui.OpenPopup("importactions");
                }
                if (ImGui.BeginPopup("importactions"))
                {
                    if (ImGui.MenuItem("File"))
                    {
                        string path;
                        if ((path = FileDialog.Open()) != null)
                        {
                            selectedNode.Data = File.ReadAllBytes(path);
                        }
                    }
                    if (ImGui.MenuItem("Texture"))
                    {
                        ImportTexture();
                    }
                    ImGui.EndPopup();
                }
                if (ImGui.Button("Export Data"))
                {
                    if (selectedNode.Name.ToLowerInvariant() == "vmeshdata")
                    {
                        ImGui.OpenPopup("exportactions");
                    }
                    else
                    {
                        string path;
                        if ((path = FileDialog.Save()) != null)
                        {
                            File.WriteAllBytes(path, selectedNode.Data);
                        }
                    }
                }
                if (ImGui.BeginPopup("exportactions"))
                {
                    if (ImGui.MenuItem("Raw"))
                    {
                        string path;
                        if ((path = FileDialog.Save()) != null)
                        {
                            File.WriteAllBytes(path, selectedNode.Data);
                        }
                    }
                    if (ImGui.MenuItem("VMeshData"))
                    {
                        string path;
                        if ((path = FileDialog.Save()) != null)
                        {
                            LibreLancer.Utf.Vms.VMeshData dat = null;
                            try
                            {
                                dat = new LibreLancer.Utf.Vms.VMeshData(new ArraySegment <byte>(selectedNode.Data), new EmptyLib(), "");
                            }
                            catch (Exception ex)
                            {
                                ErrorPopup(string.Format("Not a valid VMeshData node\n{0}\n{1}", ex.Message, ex.StackTrace));
                            }
                            if (dat != null)
                            {
                                DumpObject.DumpVmeshData(path, dat);
                            }
                        }
                    }
                    ImGui.EndPopup();
                }
            }
            else
            {
                ImGui.Text("Empty");
                ImGui.Separator();
                ImGui.Text("Actions:");
                if (ImGui.Button("Add Data"))
                {
                    selectedNode.Data = new byte[0];
                }
                if (ImGui.Button("Import Data"))
                {
                    ImGui.OpenPopup("importactions");
                }
                if (ImGui.BeginPopup("importactions"))
                {
                    if (ImGui.MenuItem("File"))
                    {
                        string path;
                        if ((path = FileDialog.Open()) != null)
                        {
                            selectedNode.Data = File.ReadAllBytes(path);
                        }
                    }
                    if (ImGui.MenuItem("Texture"))
                    {
                        ImportTexture();
                    }
                    ImGui.EndPopup();
                }
            }

            var removeJmv = new List <JointMapView>();

            foreach (var jm in jointViews)
            {
                if (!jm.Draw())
                {
                    removeJmv.Add(jm);
                }
            }
            foreach (var jmv in removeJmv)
            {
                jointViews.Remove(jmv);
            }
            ImGui.EndChild();
        }