Coder Social home page Coder Social logo

mtanksl / amf.net Goto Github PK

View Code? Open in Web Editor NEW
15.0 3.0 1.0 525 KB

An implementation in C# of both AMF0 and AMF3 binary format that is used to serialize ActionScript object graphs.

License: MIT License

C# 100.00%
amf amf0 amf3 csharp implementation serialization deserialization

amf.net's Introduction

AMF.net

An implementation in C# of both AMF0 and AMF3 binary format that is used to serialize ActionScript object graphs.

Install using NuGet

Nuget

dotnet add package mtanksl.ActionMessageFormat --version 1.0.4

Why?

So, Flash is dead and Adobe will end support of Flash Player on December 31, 2020. I actually never used Flash and had no knowledge of it's build in communication protocol. It turns out that I had to automate a creepy old software written in Flash. Since I did not find any good library, I've written my own.

Audience

Probably nobody. But hey, It is fun to learn and implement a protocol. I kind liked this one (but no, I will never use it again).

Specification

Here is the official Action Message Format AMF0 Specification and Action Message Format AMF3 Specification.

How to serialize an object

var writer = new AmfWriter();

writer.WriteAmfPacket(new AmfPacket()
{
    Version = AmfVersion.Amf3,
    Headers = new List<AmfHeader>(),
    Messages = new List<AmfMessage>()
    {
        new AmfMessage()
        {
            TargetUri = "null",
            ResponseUri = "/1",
            Data = new CommandMessageExt()
            {
                Operation = 5,
                CorrelationId = "",
                TimeToLive = 0,
                Timestamp = 0,
                Headers = new { DSMessagingVersion = 1, DSId = "nil" },
                Body = new { },
                ClientId = null,
                Destination = "",
                MessageId = Guid.NewGuid().ToString()
            }
        }
    }
} );

How to deserialize an object

var reader = new AmfReader(writer.Data);

var packet = reader.ReadAmfPacket();

Object Viewer

I've also implemented a custom object viewer. Please note that IExternalizable classes need the definition models within the project. Use [TraitClass] and [TraitMember] attributes to map custom classes and properties.

Object Viewer

Fiddler Inspector

I've also implemented a custom Fiddler Inspector. Please note that IExternalizable classes need the definition models within the project. Use [TraitClass] and [TraitMember] attributes to map custom classes and properties. To build, add a reference to C:\Users<USER>\AppData\Local\Programs\Fiddler\Fiddler.exe After build, copy all dlls to C:\Users<USER>\Documents\Fiddler2\Inspectors\

Fiddler Inspector

amf.net's People

Contributors

mtanksl avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

gxcreations

amf.net's Issues

Need help with externalized object

Hello mtanksl,

I really appreciated your work on this project. Nice job!!

I need to automate an old program just like you but this program sends Externalized object to server which I didn't know the map of it.

Is there any way I create a custom class with externalizable interface and see what is inside the request which program is sending.

I want to see inside of that externalized object that sended by program but don't know how to use [traitclass] or [traitmember]. I only got class name of externalized object from program but when I create a class in my code and give [trairclass]("name of the class from request send by program") I can't see anything inside that class. There is no members in it.

So please give me a hand about this.

Thx

Regards.

Use AMFPacket.Messages.Data in C# program

Not an issue per se, but I couldn't find anything elsewhere.

So I'm currently trying to create a program that reads AMF requests stored in a file (the file path passed through an argument in the terminal), and generates an AMF response based on the request.

I have a problem though: when reading an AMF packet and trying to read its data from its messages, I can't figure out a way to actually use the Data object in the message, I can only return its type through Console.WriteLine. This is probably due to my inexperience in C#, but can someone help me figure this out?

The included viewer can read the object just fine, so I probably am missing something here, but I can't figure out what.

Here's an extract of what I did:

                byte[] amfRequest = File.ReadAllBytes("the_path_to_my_file.req");
                var reader = new AmfReader(amfRequest);
                var packet = reader.ReadAmfPacket();

                Console.WriteLine(packet.Version);
                for (int i = 0; i < packet.Headers.Count; i++) {
                    var serializedHdr = packet.Headers[i].Data;
                    Console.WriteLine(serializedHdr);
                }
                for(int i = 0; i < packet.Messages.Count; i++)
                {
                    var serializedMsgTargetURI = packet.Messages[i].TargetUri;
                    var serializedMsgResponseURI = packet.Messages[i].ResponseUri;
                    var serializedMsgContent = packet.Messages[i].Data;

                    Console.WriteLine(serializedMsgTargetURI);
                    Console.WriteLine(serializedMsgResponseURI);
                    Console.WriteLine(serializedMsgContent);

                }

The terminal's output with a provided AMF request file:
image

And here's the viewer's output using the same request:
image

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.