Code Monkey home page Code Monkey logo

oat's Introduction

Object Analysis Toolkit

Nuget Nuget

Object Analysis Toolkit (OAT) is a rules driven metaprogramming engine for arbitrary C# objects.

Getting OAT

OAT is available as a library on NuGet as Microsoft.CST.OAT.

To enable using C# scripts in rules you also need Microsoft.CST.OAT.Scripting.

OAT Blazor is an experimental WebAssembly app that runs in your browser and allows you to Author Rules and test them in a Sandbox using Objects instantiated from your provided Assembly.

Documentation

Documentation for usage is on the Wiki.

Documentation for the API is available on GitHub Pages

Overview

  • Rules contain a object Target, an int Severity, a string boolean Expression and a List of Clauses which are applied to the targeted object.
  • Clauses perform a specified Operation on a specified Field of the Target. The Field can be any property or subproperty or field of the object. For example, SomeFieldOfTarget.SomeObject.SomeProperty.
  • Clauses can also Capture the result of their operation, to be returned with the applied Rule.
  • The Operation set can be expanded with delegates.
  • The object types supported by existing operations can also be expanded with delegates.

Basic Usage

The basic usage of OAT is applying rules to targets using the Analyze function.

object target;
IEnumerable<Rule> rules;
var analyzer = new Analyzer();
var rulesWhichApply = analyzer.Analyze(rules,target);

Capturing

OAT also supports capturing and returning results of clauses.

object target;
IEnumerable<Rule> rules;
var analyzer = new Analyzer();
var res = analyzer.GetCaptures(rules, target);

Detailed Usage

A full walkthrough including creating a custom operation and validating your custom operation rules and capturing Clause values is available on the wiki.

Authoring Rules

Detailed information on how to author rules is available on on the wiki.

Delegates

Documentation for implementing each delegate is available on the wiki.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

oat's People

Contributors

bchavez avatar daalcant avatar dependabot[bot] avatar gfs avatar microsoftopensource avatar scovetta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oat's Issues

ListStringInput does not properly set new value for nullable underlying type

Description:
The Sandbox contains broken "Add String" buttons when viewing the following object types:

  • DriverObject under "LinkedAgainst"
  • FirewallObject under "LocalAddresses"
  • FirewallObject under "LocalPorts"
  • FirewallObject under "RemoteAddresses"
  • FirewallObject under "RemotePorts"
  • RegistryObject under "Permissions"
  • RegistryObject under "SubKeys"

Expected behavior:
The "Add String" buttons should add strings to a list displayed as a dropdown

To Reproduce:
Steps to reproduce the behavior:

  1. Run ASA, open GUI
  2. Click Sandbox page
  3. Select any of the above mentioned types, e.g. DriverObject
  4. Create the object
  5. Click 'View' tab to view the object, expand its contents
  6. Find some broken "Add String" buttons

Configuration:

  • ASA Application Version: v2.3.146-beta
  • OAT Application Version: 718b12b

Unable to identify which Clause Data element resulted in the match

For reporting purposes it is valuable to identify which of N number of patterns in a Clause represented in the Data list were actually responsible for the capture. There doesn't appear to be a way to determine that today. For example:

        var trueRegexObject = "zcash";

        var regexRule = new Rule("Regex Rule")
        {
            Clauses = new List<Clause>()
            {
                new Clause(Operation.Regex)
                {
                    Data = new List<string>()
                    {
                        "cardano|ethereum|cryptocurrency",
                        "p2pool|miner|ripple|nxt|tether|ether|btc|zcash|monero|merkleroot|xmr|eth"
                    }
                }
            }
        };

        var regexAnalyzer = new Analyzer();
        var ruleList = new List<Rule>() { regexRule };
        IEnumerable<RuleCapture> captures = regexAnalyzer.GetCaptures(ruleList, trueRegexObject);

Sandbox: Flag enum content is not displayed in 'View' mode

Description:
In the Sandbox, objects containing flag enum members do not display corresponding enum content when viewed. Only the label is displayed.
E.g. see FirewallObject flag enum member 'Profiles'

Expected behavior:
Objects in 'View' mode should display all possible enum flag values as checkboxes, defaulting to unchecked.

To Reproduce:
Steps to reproduce the behavior:

  1. Run ASA, open GUI
  2. Click Sandbox page
  3. Select type that contains flag enum input, e.g. FirewallObject
  4. Create the object
  5. Click 'View' tab to view the object, expand its contents
  6. See labels where flag enum inputs are not being populated, for example 'Profiles' label when viewing FirewallObject

Configuration:

  • ASA Application Version: v2.3.146-beta
  • OAT Application Version: 718b12b

Add Lambda support to Clauses

Proposed Change

Add a string field Lambda to clause that when not null contains C# code to execute in lieu of writing a delegate ahead of time.

New Behavior:

  • When Lambda is set Lambda is used.
  • Otherwise, the operation delegates set in the analyzer are checked as usual against the CustomOperation field.
  • CustomOperation is still required to label the operation.
  • During validate rules only attempt to compile the lambda
  • During validate rules ensure there is a defined operator in the dictionary as usual or a lambda.

See: https://www.strathweb.com/2018/01/easy-way-to-create-a-c-lambda-expression-from-a-string-with-roslyn/

DictionaryStringStringInput does not properly set when underlying type is nullable

Description:
The Sandbox contains broken "Add KVP" buttons when viewing the following object types:

  • DriverObject under "Properties"
  • FileSystemObject under "Permissions"
  • RegistryObject under "Values"
  • UserAccountObject under "Properties"
  • GroupAccountObject under "Properties"

Expected behavior:
The "Add KVP" buttons should add KVP to a list displayed as a dropdown

To Reproduce:
Steps to reproduce the behavior:

  1. Run ASA, open GUI
  2. Click Sandbox page
  3. Select any of the above mentioned types, e.g. DriverObject
  4. Create the object
  5. Click 'View' tab to view the object, expand its contents
  6. Find some broken "Add KVP" buttons

Configuration:

  • ASA Application Version: v2.3.146-beta
  • OAT Application Version: 718b12b

Support Sub-Referenced Assemblies in Blazor

Desired Goal

When calling ctors for objects in Blazor we should include all the assemblies that the user has loaded so that Types that require components from another Assembly can be created.

Collapsible warning window on Sandbox

You may get a lot of warnings when loading stuff in the sandbox which pushes the interactive content way down the page. The messages should scroll or collapse or some other hiding method by default to reduce the amoutn of page they take up.

Blazor Sandbox

Create a blazor sandbox to play with the demo objects and rules and to create your own objects and rules based on assemblies you provide.

Sandbox: Constructor parameters with enum types are displayed as text input

Description:
In the Sandbox, constructor parameters with enum types are displayed as text input fields in 'Create' mode.

Expected behavior:
Enums should be displayed as dropdown selection boxes that contain enum values in 'Create' mode.

To Reproduce:
Steps to reproduce the behavior:

  1. Run ASA, open GUI
  2. Click Sandbox page
  3. Select type to create that contains enum input, e.g. ComObject or CryptographicKeyObject
  4. See text input fields where dropdown is expected.
    For example with ComObject, see constructor 'View' field
    For example with CryptographicKeyObject, see constructor 'tpmAlgId' field.

Configuration:

  • ASA Application Version: v2.3.146-beta
  • OAT Application Version: 718b12b

Add Blazor Components for Other Keyed Dictionaries of arbitrary objects

Follow up from #81. Dictionaries keyed with other objects may be useful. For example, ASA has a dictionary keyed with a tuple of an Enum and a uint.

Also should improve the handling of what can be contained in the value of a dictionary as currently it uses a scaffold for the second parameter even if it doesn't need one

The fields of a value type cannot be set by the Set helper

For example, if you try to change the value of a field of a ValueTuple it will successfully recursively get the valuetuple and then successfully set the value of the field. But because it was passed by value it only changes the value in the local copy, not the original that was passed in.

Show List of Assemblies Loaded

Show the full list of assemblies that the user has loaded in the Sandbox and Author pages

Probably as a Select dropdown.

Build WASM as Release

Currently when you try to build release you get a linker error about Blazor.FileReader. We need to resolve this so we can publish a trimmed Release version of OAT Wasm.

  Fatal error in Mono IL Linker
/Users/gabe/.nuget/packages/microsoft.aspnetcore.components.webassembly.build/3.2.1/targets/Blazor.MonoRuntime.targets(326,5): error : Unhandled exception. Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Blazor.FileReader, Version=0.11.19128.0, Culture=neutral, PublicKeyToken=null' [/Users/gabe/Documents/GitHub/OAT/OAT.Blazor/OAT.Blazor.csproj]
   ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Blazor.FileReader, Version=0.11.19128.0, Culture=neutral, PublicKeyToken=null'
     at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
     at Mono.Linker.AssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
     at Mono.Linker.LinkContext.Resolve(IMetadataScope scope)
     at Mono.Linker.LinkContext.Resolve(IMetadataScope scope)
     at Mono.Linker.LinkContext.ResolveReferences(AssemblyDefinition assembly)
     at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
     at Mono.Linker.Steps.LoadReferencesStep.ProcessAssembly(AssemblyDefinition assembly)
     at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
     at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
     at Mono.Linker.Pipeline.Process(LinkContext context)
     at Mono.Linker.Driver.Run(ILogger customLogger)
     at Mono.Linker.Driver.Execute(String[] args, ILogger customLogger)
     at Mono.Linker.Driver.Main(String[] args)
/Users/gabe/.nuget/packages/microsoft.aspnetcore.components.webassembly.build/3.2.1/targets/Blazor.MonoRuntime.targets(326,5): error : ILLink failed with exit code 134. [/Users/gabe/Documents/GitHub/OAT/OAT.Blazor/OAT.Blazor.csproj]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.