0

I'm trying to port an AS3 function's code to C#.

Using C# I want to send an AMF request which contains a bytearray similar to how this AS3 function shown below does it.

public static function serialize(param1:Object) : ByteArray
  {
     var _loc2_:ByteArray = new ByteArray();
     _loc2_.writeObject(param1);
     return _loc2_;
  }

I recorded this array in an AMF request using Charles web debugger and I got this:

pic

0a0b011d4d6f7669654163746f7252656c730a0743666c65782e6d6573736167696e672e696f2e4172726179436f6c6c656374696f6e090d010a531b4d6f7669654163746f7252656c0f4d6f76696549640b5374617465194669677572654e756d6265721f4d6f7669654163746f7252656c49640f4163746f724964040004000400040004889dfa2d0a0904000400040104000487fa99010a090400040004020400048791f9a20a0904000400040304000487bcd2630a0904000400040404000487edc7580a0904000400040504000487b0a7c317436c6f7468657344617461090d010a0113457965536861646f77011f457965536861646f77436f6c6f72730115436c6f746865734d696e0909010a0123436c6f7468657343617465676f72794964040217436f6c6f72536368656d6501234163746f72436c6f7468657352656c49640541bf3556890000000d536b696e4964040213436c6f74686573496404c8761146696c656e616d6506010b436f6c6f72061f3078333333332c307839393939393913697357656172696e67040107535746063b4d6f766b696e67626972645f323031345f626f797353756974315f64670b5363616c65053fd3333333333333010a011804031a011c0541bf35568a0000001e04022004a73b22060124061130783433366239632804012a0649486970737465725f323031325f4d616c6542617369634a65616e735f6d735f66697865642e053fd3333333333333010a0118040a1a011c0541bf3556870000001e04002004c32122060124065930783030303030302c30783538464630302c30783030423146462c30784646393930302c30784633303046462804012a0633776174657253706c6173685f323031345f73686f65735f6d662e053fd3333333333333010a011804011a011c0541bf3556880000001e04022004c75322060124062330784246383733332c30783845353430452804012a063963616665436f75747572655f323031345f6d616c65486169725f6d662e053fd3333333333333010b4d6f7574680a81733c0f4d6f75746849641b4469616d6f6e647350726963651e1b44656661756c74436f6c6f7273094e616d650d68696464656e1d6c6173744e6577546167446174652a0b50726963650756697015447261676f6e426f6e650b69734e657713736f72746f7264657211446973636f756e74155265674e6577557365720404040004000101020106196d616c655f6d6f7574685f310400040002040004000400040013457965436f6c6f7273062330783333363630302c307830303030303013536b696e436f6c6f7206113135373038383038094e6f73650a8173620d4e6f73654964401e424446482a4a4c4e5052545604050400040001010201060d6e6f73655f3404000400020400040004000400174d6f757468436f6c6f72730625736b696e636f6c6f722c30786363393939390f6163746f72496404889dfa2d074579650a81736e0b4579654964401e424446482a4a4c4e50525456042504000400010102010621457965735f5468654d616e5f3230313304000400030400040004000400010a0112011401160909010a0118040a1a011c0541bdd4aac40000001e04002004c43022060124062330783030303030302c30783333333333332804012a0639526f6164547269705f323031345f626f6f7473556e697365785f464a2e053fd3333333333333010a011804021a011c0541bdd4aac20000001e04012004c82322060124063d3078302c30783636323630612c30786666666666662c30783333333333332804012a062d4d6f7669654e696768745f323031345f7465655f464a2e053fd3333333333333010a011804031a011c0541bdd4aac30000001e04012004c8192206012406073078302804012a063b43616665436f75747572655f323031345f4849676857616973745f464a2e053fd3333333333333010a011804011a011c0541bdd4aac10000001e04012004c47c22060124061130786463626335652804012a06255465656e5f323031345f48616972315f464a2e053fd3333333333333013c0a0d04010400040001010201061d66656d616c655f6d6f7574685f31040004000204000400040004005a062330783636393963632c30783030303030305e06113133333337313636620a11040b04000400010102010619686f6e65795f6e6f73655f3704000400020400040004000400680681086c0487fa99016e0a15042c04000400010102010627457965735f4d6f766965537461725f3230313304000400030400040004000400010a0112011401160907010a011804011a011c0541b9cef9460000001e04002004955e2206012406012804012a0629646563656d6265725f6d616c655f686169725f342e053fd3333333333333010a0118040d1a011c0541bb8ce8cf0000001e04002004d63a2206012406012804012a0635586d617343616c656e6461725f4561726d756666735f323031352e053fd3333333333333010a011804021a011c0541b8d4c8760000001e04012004d5132206012406012804012a06474e69636b656c6f64656f6e5f3130305468696e67735f6769726c7364726573735f464a2e053fd3333333333333013c0a0d04070400040001010201061d66656d616c655f6d6f7574685f33040004000204000400040004005a062330783333363633332c30783030303030305e06113135393731393635620a1104010400040001010201060d6e6f73655f3504000400020400040004000400680625736b696e636f6c6f722c31363736343035376c048791f9a26e0a15042a0400040001010201062d457965735f4769726c4e657874446f6f725f3230313304000400030400040004000400010a011201140116090b010a011804011a011c0541babf61840000001e04022004c7532206012406382804012a063a2e053fd3333333333333010a011804031a011c0541babf61860000001e04022004a73b22060124067c2804012a06322e053fd3333333333333010a0118040a1a011c0541babf61870000001e04022004c64122060124064f30786363303033332c3078302c30786666666666662c30786666666666662c30786666666666662804012a06314d696e69536b38727a5f323031345f536e65616b735f464a2e053fd3333333333333010a011804021a011c0541be8df5220000001e04022004cf7b2206012406012804012a063d6e69636b656c6f64656f6e5f323031355f6d616c65546f705265645f6d662e053fd3333333333333010a0118042d1a011c0541be9619820000001e04002004967c2206012406012804012a062b6a616e5f323031315f6163635f6769726c735f32382e053fd3333333333333013c0a0d040404000400010102010658040004000204000400040004005a065c5e06113136373634303537620a1104040400040001010201060d6e6f73655f3304000400020400040004000400680681286c0487bcd2636e0a1504250400040001010201067204000400030400040004000400010a0112011401160909010a011804021a011c0541bd6c015e0000001e04012004cb3122060124061130786666636366662804012a0639436f756e7472794d616e6f725f323031345f72656463726f705f64672e053fd3333333333333010a011804031a011c0541bd6c015f0000001e04012004c81922060124061130784343454146372804012a067e2e053fd3333333333333010a011804011a011c0541bd6c015d0000001e04012004c47e22060124061130784344423037382804012a062b5465656e5f323031345f506f6e795461696c5f464a2e053fd3333333333333010a0118040a1a011c0541bd6c01600000001e04002004c51522060124063530783135304330362c30784646464646462c30783036303731352804012a063563616d7075735f323031345f756e6973657853686f65735f64672e053fd3333333333333013c0a0d04070400040001010201068114040004000204000400040004005a061130783030303066665e060f39353237313035620a110401040004000101020106811a04000400020400040004000400680625736b696e636f6c6f722c30786161303030306c0487edc7586e0a15042a040004000101020106811e04000400030400040004000400010a0112011401160909010a011804031a011c0541ba352a130000001e04012004ab5222060124063530783030303030302c30786666666666662c30784343434343432804012a06454361726e6976616c4c6f76655f323031325f66656d616c65626f74746f6d735f64672e053fd3333333333333010a011804011a011c0541ba352a110000001e04002004947c22060124061130783333333333332804012a0629646563656d6265725f6d616c655f686169725f312e053fd3333333333333010a0118040a1a011c0541bd75d2a90000001e04012004c64d22060124065930786666666666662c30786666666666662c30786666666666662c30784646464646462c30784646464646462804012a0681222e053fd3333333333333010a011804021a011c0541bd9cf3f40000001e04012004de0d22060124062d3078636366662c3078323936362c30783030303033332804012a06217369645f323031365f746565325f64672e053fd3333333333333013c0a0d04010400040001010201068104040004000204000400040004005a061f3078636366662c30783030303030305e068118620a11040b040004000101020106810a0400040002040004000400040068061130786666303030306c0487b0a7c36e0a15042a040004000101020106811e040004000304000400040004000101

How can I get this same bytearray result with C#. I want to be able to send AMF request using C# code only.

cheers,
Niklas

7
  • yeah i just want to send exactly the same object using c#. i dont want to change it or anything. just sending exactly the same Commented Apr 23, 2016 at 15:27
  • Also I hope you understand that the input parameter in that function is type Object which in AS3 is a table of entries. See this guide. Also for AMF check the format specifications to understand what bytes you should be making. The Wikipedia article might help also . Make your C# version from those guides not decompiled code. Commented Apr 23, 2016 at 15:28
  • already tried to build upon this but because im german and my english isnt the best i didnt get the result which i wanted with this Commented Apr 23, 2016 at 15:31
  • Firstly, my mistake Charles bytes are okay I was checking them wrong way. Secondly, what exactly is the problem...? If you have a HEX Editor, just put your bytes in there to see what it looks like (entries). You can download a free one (on Win PC, there is HxD). Look at your bytes there and check the Wiki article to follow its structure. Read from section AMF0 up to first Hex / ASCII example shown. Thats all you need. Commented Apr 23, 2016 at 16:11
  • oh man.. im absultely the sillyest guy ive ever met. the libary which i use to send amf request using c# already ported the as3 byte array class.. Commented Apr 23, 2016 at 18:00

2 Answers 2

1

You can use a BinaryFormatter to serialize an object, along with a MemoryStream to write the serialization result to a byte[].

Sign up to request clarification or add additional context in comments.

1 Comment

can you write it a little bit more detailed?
0

To serialize this you need an fluorinefx libray. Your code has to have an FluorineFx.AMF3 lib imported. To serialize that code you need to do code like this:

using FluorineFx.AMF3;
   public static ByteArray serialize(Object param1)
   ByteArray BA = new ByteArray();
   for(var i = 0; i < 1000000; i++) {
        BA.WriteObject
   } 
   return BA;
}

You can keep the loc2 name from the MovieStarPlanet script if you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.