Add Synalysis plugin for hex editor field definition layouts

This commit is contained in:
Michael Becker 2019-11-08 21:35:18 -05:00
parent ee190dab6a
commit 010dcf46f9
No known key found for this signature in database
GPG Key ID: 389DFF5D73781A12
6 changed files with 295 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<UniversalEditor Version="4.0">
<Associations>
<Association>
<Filters>
<Filter Title="Synalysis XML grammar definition">
<FileNameFilters>
<FileNameFilter>*.grammar</FileNameFilter>
</FileNameFilters>
</Filter>
</Filters>
<ObjectModels>
<ObjectModel TypeName="UniversalEditor.ObjectModels.BinaryGrammar.BinaryGrammarObjectModel" />
</ObjectModels>
<DataFormats>
<DataFormat TypeName="UniversalEditor.Plugins.Synalysis.DataFormats.XMLBinaryGrammar.XMLBinaryGrammarDataFormat" />
</DataFormats>
</Association>
</Associations>
</UniversalEditor>

View File

@ -704,6 +704,7 @@
<None Include="Images\SplashScreen.png" />
<None Include="Images\SplashScreen.xcf" />
<None Include="Editors\Multimedia\Audio\Synthesized\PianoRoll\Toolbox.uexml" />
<None Include="Extensions\SoftwareDeveloper\Associations\BinaryGrammar\SynalysisBinaryGrammarDataFormat.uexml" />
</ItemGroup>
<Target Name="Build">
<Copy SourceFiles="@(Content)" DestinationFiles="@(Content-&gt;'$(OutputPath)%(RelativeDir)%(Filename)%(Extension)')" />

View File

@ -0,0 +1,170 @@
//
// XMLBinaryGrammarDataFormat.cs
//
// Author:
// Mike Becker <alcexhim@gmail.com>
//
// Copyright (c) 2019 Mike Becker
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using UniversalEditor.DataFormats.Markup.XML;
using UniversalEditor.IO;
using UniversalEditor.ObjectModels.BinaryGrammar;
using UniversalEditor.ObjectModels.BinaryGrammar.GrammarItems;
using UniversalEditor.ObjectModels.Markup;
namespace UniversalEditor.Plugins.Synalysis.DataFormats.XMLBinaryGrammar
{
public class XMLBinaryGrammarDataFormat : XMLDataFormat
{
private static DataFormatReference _dfr = null;
protected override DataFormatReference MakeReferenceInternal()
{
if (_dfr == null)
{
_dfr = base.MakeReferenceInternal();
_dfr.Capabilities.Add(typeof(BinaryGrammarObjectModel), DataFormatCapabilities.All);
}
return _dfr;
}
protected override void BeforeLoadInternal(Stack<ObjectModel> objectModels)
{
base.BeforeLoadInternal(objectModels);
objectModels.Push(new MarkupObjectModel());
}
protected override void AfterLoadInternal(Stack<ObjectModel> objectModels)
{
base.AfterLoadInternal(objectModels);
MarkupObjectModel mom = (objectModels.Pop() as MarkupObjectModel);
BinaryGrammarObjectModel grammar = (objectModels.Pop() as BinaryGrammarObjectModel);
MarkupTagElement tagUFWB = (mom.Elements["ufwb"] as MarkupTagElement);
if (tagUFWB == null)
throw new InvalidDataFormatException("xml file does not contain top-level 'ufwb' tag");
MarkupTagElement tagGrammar = (tagUFWB.Elements["grammar"] as MarkupTagElement);
if (tagGrammar == null)
throw new InvalidDataFormatException("'ufwb' tag does not contain child-level 'grammar' tag");
MarkupAttribute attStart = tagGrammar.Attributes["start"];
if (attStart == null)
throw new InvalidDataFormatException("'grammar' tag does not contain 'start' attribute (entry point)");
grammar.Name = tagGrammar.Attributes["name"]?.Value;
grammar.Author = tagGrammar.Attributes["author"]?.Value;
grammar.FileExtension = tagGrammar.Attributes["fileextension"]?.Value;
grammar.UniversalTypeIdentifier = tagGrammar.Attributes["uti"]?.Value;
grammar.IsComplete = (tagGrammar.Attributes["complete"]?.Value.Equals("yes")).GetValueOrDefault();
grammar.Description = (tagGrammar.Elements["description"] as MarkupTagElement)?.Value;
for (int i = 0; i < tagGrammar.Elements.Count; i++)
{
MarkupTagElement tag = (tagGrammar.Elements[i] as MarkupTagElement);
if (tag == null) continue;
if (tag.FullName == "structure")
{
GrammarItemStructure s = LoadStructure(tag);
if (attStart.Value.Equals(String.Format("id:{0}", s.ID)) || attStart.Value.Equals(s.Name))
{
grammar.InitialStructure = s;
}
grammar.Structures.Add(s);
}
}
}
private GrammarItemStructure LoadStructure(MarkupTagElement tag)
{
GrammarItemStructure s = new GrammarItemStructure();
s.ID = tag.Attributes["id"]?.Value;
s.Name = tag.Attributes["name"]?.Value;
s.Length = tag.Attributes["length"]?.Value;
s.Encoding = tag.Attributes["encoding"]?.Value;
s.Endianness = "big".Equals(tag.Attributes["endian"]?.Value) ? Endianness.BigEndian : Endianness.LittleEndian;
s.Signed = !"no".Equals(tag.Attributes["signed"]?.Value);
s.Extends = tag.Attributes["extends"]?.Value;
foreach (MarkupElement el in tag.Elements)
{
MarkupTagElement tag1 = (el as MarkupTagElement);
if (tag1 == null) continue;
GrammarItem item = null;
string fieldName = tag1.Attributes["name"]?.Value;
string fieldID = tag1.Attributes["id"]?.Value;
string fieldLength = tag1.Attributes["length"]?.Value;
string repeatMax = tag1.Attributes["repeatmax"]?.Value;
switch (tag1.FullName.ToLower())
{
case "structref":
{
item = new GrammarItemStructureReference();
(item as GrammarItemStructureReference).Structure = tag1.Attributes["structure"]?.Value;
break;
}
case "number":
{
item = new GrammarItemNumber();
break;
}
case "string":
{
item = new GrammarItemString();
break;
}
}
if (item != null)
{
item.Name = fieldName;
item.ID = fieldID;
item.Length = fieldLength;
MarkupTagElement tagFixedValues = (tag1.Elements["fixedvalues"] as MarkupTagElement);
if (tagFixedValues != null)
{
foreach (MarkupElement elFixedValue in tagFixedValues.Elements)
{
MarkupTagElement tagFixedValue = (elFixedValue as MarkupTagElement);
if (tagFixedValue == null) continue;
FixedValue val = new FixedValue();
val.Name = tagFixedValue.Attributes["name"]?.Value;
val.Value = tagFixedValue.Attributes["value"]?.Value;
s.FixedValues.Add(val);
}
}
s.Items.Add(item);
}
}
return s;
}
protected override void BeforeSaveInternal(Stack<ObjectModel> objectModels)
{
base.BeforeSaveInternal(objectModels);
BinaryGrammarObjectModel grammar = (objectModels.Pop() as BinaryGrammarObjectModel);
MarkupObjectModel mom = new MarkupObjectModel();
}
}
}

View File

@ -0,0 +1,46 @@
//
// AssemblyInfo.cs
//
// Author:
// Mike Becker <alcexhim@gmail.com>
//
// Copyright (c) 2019 Mike Becker
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("UniversalEditor.Plugins.Synalysis")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Mike Becker")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0EEC3646-9749-48AF-848E-0F699247E76F}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>UniversalEditor.Plugins.Synalysis</RootNamespace>
<AssemblyName>UniversalEditor.Plugins.Synalysis</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Output\Debug\Plugins</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>..\..\Output\Release\Plugins</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="DataFormats\XMLBinaryGrammar\XMLBinaryGrammarDataFormat.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="DataFormats\" />
<Folder Include="DataFormats\XMLBinaryGrammar\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Core\UniversalEditor.Core.csproj">
<Project>{2D4737E6-6D95-408A-90DB-8DFF38147E85}</Project>
<Name>UniversalEditor.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Essential\UniversalEditor.Essential.csproj">
<Project>{30467E5C-05BC-4856-AADC-13906EF4CADD}</Project>
<Name>UniversalEditor.Essential</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -145,6 +145,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MBS.Framework", "..\..\MBS.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.CRI", "Plugins\UniversalEditor.Plugins.CRI\UniversalEditor.Plugins.CRI.csproj", "{BB080ED6-A8D2-43B0-BC9F-323D3D587F91}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Synalysis", "Plugins\UniversalEditor.Plugins.Synalysis\UniversalEditor.Plugins.Synalysis.csproj", "{0EEC3646-9749-48AF-848E-0F699247E76F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -417,6 +419,10 @@ Global
{BB080ED6-A8D2-43B0-BC9F-323D3D587F91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB080ED6-A8D2-43B0-BC9F-323D3D587F91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BB080ED6-A8D2-43B0-BC9F-323D3D587F91}.Release|Any CPU.Build.0 = Release|Any CPU
{0EEC3646-9749-48AF-848E-0F699247E76F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EEC3646-9749-48AF-848E-0F699247E76F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EEC3646-9749-48AF-848E-0F699247E76F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EEC3646-9749-48AF-848E-0F699247E76F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6F0AB1AF-E1A1-4D19-B19C-05BBB15C94B2} = {05D15661-E684-4EC9-8FBD-C014BA433CC5}
@ -484,6 +490,7 @@ Global
{EA724755-2670-4520-86AA-657C8A124DB7} = {2ED32D16-6C06-4450-909A-40D32DA67FB4}
{00266B21-35C9-4A7F-A6BA-D54D7FDCC25C} = {20F315E0-52AE-479F-AF43-3402482C1FC8}
{BB080ED6-A8D2-43B0-BC9F-323D3D587F91} = {2ED32D16-6C06-4450-909A-40D32DA67FB4}
{0EEC3646-9749-48AF-848E-0F699247E76F} = {2ED32D16-6C06-4450-909A-40D32DA67FB4}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0