This commit is contained in:
BtbN
2019-05-31 23:53:09 +02:00
parent eab3bd6628
commit e901a9c0be
13 changed files with 434 additions and 64 deletions

View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using ClanServer.Formatters;
using ClanServer.Routing;
namespace ClanServer.Controllers.Core
{
[ApiController, Route("core")]
public class FacilityController : ControllerBase
{
[HttpPost, XrpcCall("facility.get")]
public ActionResult<EamuseXrpcData> Get([FromBody] EamuseXrpcData data)
{
var facilityReq = data.Document.Element("call").Element("facility");
string requestedEncoding = facilityReq.Attribute("encoding").Value;
string method = facilityReq.Attribute("method").Value;
var Str = new XAttribute("__type", "str");
var U8 = new XAttribute("__type", "u8");
var U16 = new XAttribute("__type", "u16");
var S32 = new XAttribute("__type", "s32");
var IP4 = new XAttribute("__type", "ip4");
data.Document = new XDocument(new XElement("response", new XElement("facility",
new XElement("location",
new XElement("id", Str, "53BDC526"),
new XElement("country", Str, "US"),
new XElement("region", Str, "1"),
new XElement("name", Str, ""),
new XElement("type", U8, "0")
),
new XElement("line",
new XElement("id", Str, ""),
new XElement("class", U8, "0")
),
new XElement("portfw",
new XElement("globalip", IP4, HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString()),
new XElement("globalport", U16, "5700"),
new XElement("privateport", U16, "5700")
),
new XElement("public",
new XElement("flag", U8, "0"),
new XElement("name", Str, ""),
new XElement("latitude", Str, ""),
new XElement("longitude", Str, "")
),
new XElement("share",
new XElement("eacoin",
new XElement("notchamount", S32, "0"),
new XElement("notchcount", S32, "0"),
new XElement("supplylimit", S32, "100000")
),
new XElement("url",
new XElement("eapass", Str, "http://eagate.573.jp/"),
new XElement("arcadefan", Str, "http://eagate.573.jp/"),
new XElement("konaminetdx", Str, "http://eagate.573.jp/"),
new XElement("konamiid", Str, "http://eagate.573.jp/"),
new XElement("eagate", Str, "http://eagate.573.jp/")
)
)
)));
if (requestedEncoding == "Shift-JIS")
{
data.Encoding = Encoding.GetEncoding(932);
}
else
{
Console.WriteLine("Unknown encoding requested, ignoring.");
}
return data;
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using ClanServer.Formatters;
using ClanServer.Routing;
namespace ClanServer.Controllers.Core
{
[ApiController, Route("core")]
public class MessageController : ControllerBase
{
[HttpPost, XrpcCall("message.get")]
public ActionResult<EamuseXrpcData> Get([FromBody] EamuseXrpcData data)
{
data.Document = new XDocument(new XElement("response", new XElement("message")));
return data;
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using ClanServer.Formatters;
using ClanServer.Routing;
namespace ClanServer.Controllers.Core
{
[ApiController, Route("core")]
public class PackageController : ControllerBase
{
[HttpPost, XrpcCall("package.list")]
public ActionResult<EamuseXrpcData> List([FromBody] EamuseXrpcData data)
{
data.Document = new XDocument(new XElement("response", new XElement("package")));
return data;
}
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using ClanServer.Formatters;
using ClanServer.Routing;
namespace ClanServer.Controllers.Core
{
[ApiController, Route("core")]
public class PcbEventController : ControllerBase
{
[HttpPost, XrpcCall("pcbevent.put")]
public ActionResult<EamuseXrpcData> Put([FromBody] EamuseXrpcData data, [FromQuery] string model)
{
Console.WriteLine(data.Document);
data.Document = new XDocument(new XElement("response", new XElement("pcbevent")));
return data;
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using ClanServer.Formatters;
using ClanServer.Routing;
namespace ClanServer.Controllers.Core
{
[ApiController, Route("core")]
public class PcbTrackerController : ControllerBase
{
[HttpPost, XrpcCall("pcbtracker.alive")]
public ActionResult<EamuseXrpcData> Alive([FromBody] EamuseXrpcData data, [FromQuery] string model)
{
data.Document = new XDocument(new XElement("response", new XElement("pcbtracker", new XAttribute("ecenable", "1"))));
return data;
}
}
}

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using ClanServer.Formatters;
using ClanServer.Routing;
namespace ClanServer.Controllers.Core
{
[ApiController, Route("core")]
public class ServicesController : ControllerBase
{
[HttpPost, XrpcCall("services.get")]
public ActionResult<EamuseXrpcData> Get([FromBody] EamuseXrpcData data, [FromQuery] string model)
{
string url = Request.Scheme + "://" + Request.Host.Host + ":" + (Request.Host.Port ?? Startup.Port);
string coreUrl = url + "/core";
string modelUrl;
string[] modelItems;
if (model == "L44:J:E:A:2018070901")
{
modelItems = new[]
{
"local",
"local2",
"lobby",
"lobby2"
};
modelUrl = url + "/L44/8";
}
else
{
return NotFound();
}
XElement servicesElement = new XElement("services",
new XAttribute("expire", "600"),
new XAttribute("method", "get"),
new XAttribute("mode", "operation"),
new XAttribute("status", "0"));
string[] coreItems = new[]
{
"cardmng",
"facility",
"message",
"numbering",
"package",
"pcbevent",
"pcbtracker",
"pkglist",
"posevent",
"userdata",
"userid",
"eacoin",
};
foreach (string coreItem in coreItems)
servicesElement.Add(new XElement("item", new XAttribute("name", coreItem), new XAttribute("url", coreUrl)));
foreach (string modelItem in modelItems)
servicesElement.Add(new XElement("item", new XAttribute("name", modelItem), new XAttribute("url", modelUrl)));
servicesElement.Add(new XElement("item", new XAttribute("name", "ntp"), new XAttribute("url", "ntp://pool.ntp.org/")));
servicesElement.Add(new XElement("item", new XAttribute("name", "keepalive"), new XAttribute("url", "http://127.0.0.1/keepalive?pa=127.0.0.1&ia=127.0.0.1&ga=127.0.0.1&ma=127.0.0.1&t1=2&t2=10")));
data.Document = new XDocument(new XElement("response", servicesElement));
return data;
}
}
}

View File

@@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using eAmuseCore.KBinXML;
using ClanServer.Formatters;
using ClanServer.Routing;
namespace ClanServer.Controllers
{
[ApiController, Route("core")]
public class ValuesController : ControllerBase
{
[HttpGet]
public IActionResult Get()
{
return new BadRequestResult();
}
[HttpPost, XrpcCall("services.get")]
public EamuseXrpcData GetServices([FromBody] EamuseXrpcData data, [FromQuery] string model)
{
Console.WriteLine("Model: " + model);
Console.WriteLine();
Console.WriteLine(data.Data.ToString());
return data;
}
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using ClanServer.Formatters;
using ClanServer.Routing;
namespace ClanServer.Controllers.Core
{
[ApiController, Route("L44")]
public class DemodataController : ControllerBase
{
[HttpPost, Route("8"), XrpcCall("demodata.get_info")]
public ActionResult<EamuseXrpcData> GetInfo([FromBody] EamuseXrpcData data)
{
var S32 = new XAttribute("__type", "s32");
var C64 = new XAttribute("__count", "64");
data.Document = new XDocument(new XElement("response", new XElement("demodata", new XElement("data", new XElement("info",
new XElement("black_jacket_list", S32, C64, "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0")
)))));
return data;
}
[HttpPost, Route("8"), XrpcCall("demodata.get_news")]
public ActionResult<EamuseXrpcData> GetNews([FromBody] EamuseXrpcData data)
{
data.Document = new XDocument(new XElement("response", new XElement("demodata", new XElement("data",
new XElement("officialnews", new XAttribute("count", 0))
))));
return data;
}
[HttpPost, Route("8"), XrpcCall("demodata.get_jbox_list")]
public ActionResult<EamuseXrpcData> GetJboxList([FromBody] EamuseXrpcData data)
{
data.Document = new XDocument(new XElement("response", new XElement("demodata")));
return data;
}
}
}

View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using ClanServer.Formatters;
using ClanServer.Routing;
namespace ClanServer.Controllers.Core
{
[ApiController, Route("L44")]
public class ShopinfoController : ControllerBase
{
[HttpPost, Route("8"), XrpcCall("shopinfo.regist")]
public ActionResult<EamuseXrpcData> Regist([FromBody] EamuseXrpcData data)
{
string locationId = data.Document.Element("call").Element("shopinfo").Element("shop").Element("locationid").Value;
var Str = new XAttribute("__type", "str");
var U8 = new XAttribute("__type", "u8");
var S16 = new XAttribute("__type", "s16");
var S32 = new XAttribute("__type", "s32");
var U32 = new XAttribute("__type", "u32");
var U64 = new XAttribute("__type", "u64");
var Bool = new XAttribute("__type", "bool");
var C16 = new XAttribute("__count", "16");
var C64 = new XAttribute("__count", "64");
data.Document = new XDocument(new XElement("response", new XElement("shopinfo", new XElement("data",
new XElement("cabid", U32, "1"),
new XElement("locationid", Str, locationId),
new XElement("tax_phase", U8, "0"),
new XElement("facility",
new XElement("exist", U32, "0")
),
new XElement("event_flag", U64, "0"),
new XElement("info",
new XElement("event_info",
new XElement("event", new XAttribute("type", "15"),
new XElement("state", U8, "1")
),
new XElement("event", new XAttribute("type", "5"),
new XElement("state", U8, "0")
),
new XElement("event", new XAttribute("type", "6"),
new XElement("state", U8, "0")
)
),
new XElement("share_music"),
new XElement("genre_def_music"),
new XElement("black_jacket_list", S32, C64, "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"),
new XElement("white_music_list", S32, C64, "-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1"),
new XElement("white_marker_list", S32, C16, "-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1"),
new XElement("white_theme_list", S32, C16, "-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1"),
new XElement("open_music_list", S32, C64, "-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1"),
new XElement("shareable_music_list", S32, C64, "-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1"),
new XElement("jbox",
new XElement("point", S32, "1"),
new XElement("emblem",
new XElement("normal",
new XElement("index", S16, "50")
),
new XElement("premium",
new XElement("index", S16, "50")
)
)
),
new XElement("collection",
new XElement("rating_s")
),
new XElement("expert_option",
new XElement("is_available", Bool, "1")
),
new XElement("all_music_matching",
new XElement("is_available", Bool, "0")
),
new XElement("department",
new XElement("pack_list")
)
)
))));
return data;
}
}
}

View File

@@ -2,18 +2,22 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc.Formatters;
using eAmuseCore.Compression;
using eAmuseCore.Crypto;
using eAmuseCore.KBinXML;
using System.IO;
using System.Text;
namespace ClanServer.Formatters
{
public class EamuseXrpcData
{
public KBinXML Data;
public XDocument Document;
public Encoding Encoding;
public string EamuseInfo;
}
@@ -38,9 +42,6 @@ namespace ClanServer.Formatters
if (userAgent != "EAMUSE.XRPC/1.0")
return false;
if (!context.HttpContext.Request.Headers.ContainsKey("X-Eamuse-Info"))
return false;
if (!context.HttpContext.Request.Headers.TryGetValue("X-Compress", out ua))
return false;
@@ -65,16 +66,15 @@ namespace ClanServer.Formatters
{
var request = context.HttpContext.Request;
if (!context.HttpContext.Request.Headers.TryGetValue("X-Eamuse-Info", out var header))
return await InputFormatterResult.FailureAsync();
string eAmuseInfo = header.ToString();
if (!context.HttpContext.Request.Headers.TryGetValue("X-Compress", out header))
if (!context.HttpContext.Request.Headers.TryGetValue("X-Compress", out var header))
return await InputFormatterResult.FailureAsync();
string compAlgo = header.ToString();
string eAmuseInfo = null;
if (context.HttpContext.Request.Headers.TryGetValue("X-Eamuse-Info", out header))
eAmuseInfo = header.ToString();
byte[] data;
using (var ms = new MemoryStream((int)(request.ContentLength ?? 512L)))
@@ -90,13 +90,16 @@ namespace ClanServer.Formatters
{
data = await Task.Run(() =>
{
var decrypted = RC4.ApplyEAmuseInfo(eAmuseInfo, data);
IEnumerable<byte> rawData = data;
if (eAmuseInfo != null)
rawData = RC4.ApplyEAmuseInfo(eAmuseInfo, data);
switch (compAlgo.ToLower())
{
case "lz77":
return LZ77.Decompress(decrypted).ToArray();
return LZ77.Decompress(rawData).ToArray();
case "none":
return decrypted.ToArray();
return rawData.ToArray();
default:
return null;
}
@@ -122,7 +125,8 @@ namespace ClanServer.Formatters
return await InputFormatterResult.SuccessAsync(new EamuseXrpcData()
{
Data = result,
Document = result.Document,
Encoding = result.BinEncoding,
EamuseInfo = eAmuseInfo
});
}
@@ -149,7 +153,12 @@ namespace ClanServer.Formatters
(byte[] rawData, string compAlgo) = await Task.Run(() =>
{
byte[] resData = data.Data.Bytes;
byte[] resData;
if (data.Encoding != null)
resData = new KBinXML(data.Document, data.Encoding).Bytes;
else
resData = new KBinXML(data.Document).Bytes;
string algo = "none";
var compressed = LZ77.Compress(resData).ToArray();
@@ -160,7 +169,8 @@ namespace ClanServer.Formatters
}
compressed = null;
resData = RC4.ApplyEAmuseInfo(data.EamuseInfo, resData).ToArray();
if (data.EamuseInfo != null)
resData = RC4.ApplyEAmuseInfo(data.EamuseInfo, resData).ToArray();
return (resData, algo);
});

View File

@@ -28,7 +28,7 @@ namespace ClanServer
private static void ConfigureKestrel(WebHostBuilderContext context, KestrelServerOptions options)
{
options.ListenLocalhost(9091);
options.ListenLocalhost(Startup.Port);
}
}
}

View File

@@ -14,6 +14,8 @@ namespace ClanServer
{
public class Startup
{
public const int Port = 9091;
public Startup(IConfiguration configuration)
{
Configuration = configuration;
@@ -34,20 +36,15 @@ namespace ClanServer
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
app.Use(async (context, next) =>
{
Console.WriteLine($"[{context.Connection.RemoteIpAddress}] | {context.Request.Path}");
Console.WriteLine($"[{context.Connection.RemoteIpAddress}] | {context.Request.Path}{context.Request.QueryString}");
await next.Invoke();
});
app.UseMvc();
}
}
}

View File

@@ -16,12 +16,15 @@ namespace eAmuseTest
static void Main(string[] args)
{
string compress = "lz77";
string eamuse_info = "1-5cf04a27-11ad";
byte[] data = HexToBytes("");
string eamuse_info = "1-5cf049c8-6ec5";
byte[] data = HexToBytes("6e84f02c117651c66313a5c17fa0ddc40e3f4cd52a94bd34f460e763f610e03d5d01f876");
compress = compress.ToLower();
var decryptedData = RC4.ApplyEAmuseInfo(eamuse_info, data);
IEnumerable<byte> decryptedData = data;
if (eamuse_info != null)
decryptedData = RC4.ApplyEAmuseInfo(eamuse_info, data);
var rawData = decryptedData;
if (compress == "lz77")
rawData = LZ77.Decompress(decryptedData);
@@ -30,7 +33,9 @@ namespace eAmuseTest
KBinXML kbinxml = new KBinXML(rawData.ToArray());
GenerateEchidnaSQL(kbinxml);
Console.WriteLine(kbinxml);
//GenerateEchidnaSQL(kbinxml);
}
private static void GenerateEchidnaSQL(KBinXML get_mdata_data)