Skip to content

Commit 760eff4

Browse files
committed
Added 'AMF Encode' and 'AMF Decode' operations
1 parent ba12ad8 commit 760eff4

5 files changed

Lines changed: 153 additions & 0 deletions

File tree

package-lock.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"worker-loader": "^3.0.8"
8787
},
8888
"dependencies": {
89+
"@astronautlabs/amf": "^0.0.6",
8990
"@babel/polyfill": "^7.12.1",
9091
"@blu3r4y/lzma": "^2.3.3",
9192
"arrive": "^2.4.1",
@@ -151,6 +152,7 @@
151152
"process": "^0.11.10",
152153
"protobufjs": "^6.11.3",
153154
"qr-image": "^3.2.0",
155+
"reflect-metadata": "^0.1.13",
154156
"scryptsy": "^2.1.0",
155157
"snackbarjs": "^1.1.0",
156158
"sortablejs": "^1.15.0",

src/core/config/Categories.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
"From Quoted Printable",
4747
"To Punycode",
4848
"From Punycode",
49+
"AMF Encode",
50+
"AMF Decode",
4951
"To Hex Content",
5052
"From Hex Content",
5153
"PEM to Hex",

src/core/operations/AMFDecode.mjs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @author n1474335 [n1474335@gmail.com]
3+
* @copyright Crown Copyright 2022
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation.mjs";
8+
import "reflect-metadata"; // Required as a shim for the amf library
9+
import { AMF0, AMF3 } from "@astronautlabs/amf";
10+
11+
/**
12+
* AMF Decode operation
13+
*/
14+
class AMFDecode extends Operation {
15+
16+
/**
17+
* AMFDecode constructor
18+
*/
19+
constructor() {
20+
super();
21+
22+
this.name = "AMF Decode";
23+
this.module = "Encodings";
24+
this.description = "Action Message Format (AMF) is a binary format used to serialize object graphs such as ActionScript objects and XML, or send messages between an Adobe Flash client and a remote service, usually a Flash Media Server or third party alternatives.";
25+
this.infoURL = "https://wikipedia.org/wiki/Action_Message_Format";
26+
this.inputType = "ArrayBuffer";
27+
this.outputType = "JSON";
28+
this.args = [
29+
{
30+
name: "Format",
31+
type: "option",
32+
value: ["AMF0", "AMF3"],
33+
defaultIndex: 1
34+
}
35+
];
36+
}
37+
38+
/**
39+
* @param {ArrayBuffer} input
40+
* @param {Object[]} args
41+
* @returns {JSON}
42+
*/
43+
run(input, args) {
44+
const [format] = args;
45+
const handler = format === "AMF0" ? AMF0 : AMF3;
46+
const encoded = new Uint8Array(input);
47+
return handler.Value.deserialize(encoded);
48+
}
49+
50+
}
51+
52+
export default AMFDecode;

src/core/operations/AMFEncode.mjs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @author n1474335 [n1474335@gmail.com]
3+
* @copyright Crown Copyright 2022
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation.mjs";
8+
import "reflect-metadata"; // Required as a shim for the amf library
9+
import { AMF0, AMF3 } from "@astronautlabs/amf";
10+
11+
/**
12+
* AMF Encode operation
13+
*/
14+
class AMFEncode extends Operation {
15+
16+
/**
17+
* AMFEncode constructor
18+
*/
19+
constructor() {
20+
super();
21+
22+
this.name = "AMF Encode";
23+
this.module = "Encodings";
24+
this.description = "Action Message Format (AMF) is a binary format used to serialize object graphs such as ActionScript objects and XML, or send messages between an Adobe Flash client and a remote service, usually a Flash Media Server or third party alternatives.";
25+
this.infoURL = "https://wikipedia.org/wiki/Action_Message_Format";
26+
this.inputType = "JSON";
27+
this.outputType = "ArrayBuffer";
28+
this.args = [
29+
{
30+
name: "Format",
31+
type: "option",
32+
value: ["AMF0", "AMF3"],
33+
defaultIndex: 1
34+
}
35+
];
36+
}
37+
38+
/**
39+
* @param {JSON} input
40+
* @param {Object[]} args
41+
* @returns {ArrayBuffer}
42+
*/
43+
run(input, args) {
44+
const [format] = args;
45+
const handler = format === "AMF0" ? AMF0 : AMF3;
46+
const output = handler.Value.any(input).serialize();
47+
return output.buffer;
48+
}
49+
50+
}
51+
52+
export default AMFEncode;

0 commit comments

Comments
 (0)