mirror of
https://gitea.tendokyu.moe/eamuse/docs.git
synced 2024-12-03 02:27:18 +01:00
53 lines
2.7 KiB
HTML
53 lines
2.7 KiB
HTML
{% extends "base.html" %}
|
|
{% block title %}Network format{% endblock %}
|
|
{% block body %}
|
|
<h1>Network format</h1>
|
|
|
|
<p>eAmuse packets are sent and received over HTTP (no S), with requests being in the body of <code>POST</code> requests,
|
|
and replies being in the, well, reply.</p>
|
|
<p>The packets are typically both encrypted and compressed. The compression format used is indicated by the
|
|
<code>X-Compress</code> header, and valid values are
|
|
</p>
|
|
<ul>
|
|
<li><code>none</code></li>
|
|
<li><code>lz77</code></li>
|
|
</ul>
|
|
<details>
|
|
<summary>Source code details</summary>
|
|
<figure>
|
|
<img src="./images/lz77.png">
|
|
<figcaption><code>libavs-win32-ea3.dll:0x1000fa29</code></figcaption>
|
|
</figure>
|
|
</details>
|
|
<p>Encryption is performed <b>after</b> compression, and uses RC4. RC4 is symmetric, so decryption is performed the same
|
|
as encryption. That is, <code>packet = encrypt(compress(data))</code> and
|
|
<code>data = decompress(decrypt(data))</code>.
|
|
</p>
|
|
|
|
<h2 id="keys">Encryption keys</h2>
|
|
<p>Encryption is not performed using a single static key. Instead, each request and response has its own key that is
|
|
generated.</p>
|
|
<p>These keys are generated baesd on the <code>X-Eamuse-Info</code> header.</p>
|
|
<p>This header loosely follows the format <code>1-[0-9a-f]{8}-[0-9a-f]{4}</code>. This corresponds to
|
|
<code>[version]-[serial]-[salt]</code>. <b>TODO: Confirm this</b>
|
|
</p>
|
|
<p>Our per-packet key is then generated using <code>md5(serial | salt | KEY)</code>. Identifying <code>KEY</code> is
|
|
left as an exercise for the reader, however should not be especially challenging. <span style="color: #fff">Check
|
|
the page source if you're stuck.</span></p>
|
|
<!-- libavs-win32-ea3.dll:0x10054160 -->
|
|
|
|
<h2 id="lz77">LZ77</h2>
|
|
<p>Packets are compressed using lzss. The compressed data structure is a repeating cycle of an 8 bit flags byte,
|
|
followed by 8 values. Each value is either a single literal byte, if the corresponding bit in the preceeding flag is
|
|
high, or is a two byte lookup into the window.</p>
|
|
<p>The lookup bytes are structured as <code>pppppppp ppppllll</code> where <code>p</code> is a 12 bit index in the
|
|
window, and <code>l</code> is a 4 bit integer that determines how many times to repeat the value located at that
|
|
index in the window.</p>
|
|
|
|
<p>The exact algorithm used for compression is not especially important, as long as it follows this format. One can
|
|
feasibly perform no compression at all, and instead insert <code>0xFF</code> every 8 bytes (starting at index 0), to
|
|
indicate that all values are literals. While obviously poor for compression, this is an easy way to test without
|
|
first implementing a compressor.</p>
|
|
|
|
<a href="./index.html">Prev page</a> | <a href="./packet.html">Next page</a>
|
|
{% endblock %} |