static void Main() { string compress = "lz77"; string eamuse_info = "1-5cf9445d-0dfe"; byte[] data = HexToBytes("93b01743b29ca06e7500db42d83c70843dc776d0617ac96ba0768dd6b457554591d4b8b5f963e12d5fbb5075684c2a9acbfc462aa52686a720c57b3e44373008178684f9fd7ddad3c3a1e9fe1422ae08b9b872520a64cc195a9c04585149ec8de30220345c023663ae916068117ab7d5619362019d18a6f789bbd27e4ee027ce236d2b8d6c0f0917c8990083b741b3958cdf770f970df13088f931da949d1c9f685ba7848a15c3b77083357a6fb430b8a914bf55249f092c2baf14adfa8a7ab6bd430cc6ca5b4a35ea8c893aaa0c88ae6305240d5ae479976caf35e29d943ec628752c191ae40d0998c28e3280b6a55f8198ae"); compress = compress.ToLower(); IEnumerable <byte> decryptedData = data; if (eamuse_info != null) { decryptedData = RC4.ApplyEAmuseInfo(eamuse_info, data); } var rawData = decryptedData; if (compress == "lz77") { rawData = LZ77.Decompress(decryptedData); } else if (compress != "none") { throw new ArgumentException("Unsupported compression algorithm"); } KBinXML kbinxml = new KBinXML(rawData.ToArray()); Console.WriteLine(kbinxml); //GenerateEchidnaSQL(kbinxml); }
private async Task <InputFormatterResult> ProcessInputData(byte[] data, string eAmuseInfo, string compAlgo) { data = await Task.Run(() => { IEnumerable <byte> rawData = data; if (eAmuseInfo != null) { rawData = RC4.ApplyEAmuseInfo(eAmuseInfo, data); } switch (compAlgo.ToLower()) { case "lz77": return(LZ77.Decompress(rawData).ToArray()); case "none": return(rawData.ToArray()); default: return(null); } }); if (data == null) { return(await InputFormatterResult.FailureAsync()); } KBinXML result = await Task.Run(() => { try { return(new KBinXML(data)); } catch (Exception) { Console.WriteLine("Got invalid binary XML input!"); return(null); } }); if (result == null) { return(await InputFormatterResult.FailureAsync()); } return(await InputFormatterResult.SuccessAsync(new EamuseXrpcData() { Document = result.Document, Encoding = result.BinEncoding, EamuseInfo = eAmuseInfo })); }
public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context) { var response = context.HttpContext.Response; if (!(context.Object is EamuseXrpcData data)) { throw new ArgumentNullException("Input EamuseXrpcData is null"); } (byte[] rawData, string compAlgo) = await Task.Run(() => { byte[] resData; if (data.Encoding != null) { resData = new KBinXML(data.Document, data.Encoding).Bytes; } else { resData = new KBinXML(data.Document).Bytes; } string algo = "none"; byte[] compressed = LZ77.Compress(resData, 32); if (compressed.Length < resData.Length) { resData = compressed; algo = "lz77"; } compressed = null; if (data.EamuseInfo != null) { RC4.ApplyEAmuseInfo(data.EamuseInfo, resData); } return(resData, algo); }); if (data.EamuseInfo != null) { response.Headers.Add("X-Eamuse-Info", data.EamuseInfo); } response.Headers.Add("X-Compress", compAlgo); response.ContentType = "application/octet-stream"; response.ContentLength = rawData.Length; await response.Body.WriteAsync(rawData, 0, rawData.Length); }