Files
whowechina_diva_pico/tools/ps4key_packer.html
T

469 lines
15 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PS4 Key Serialization for Diva Pico</title>
<style>
:root {
--bg: #f4efe6;
--panel: rgba(255, 251, 245, 0.86);
--ink: #162521;
--muted: #53635d;
--accent: #0f766e;
--accent-strong: #0b525b;
--line: rgba(22, 37, 33, 0.14);
--warn: #b45309;
--error: #b91c1c;
--shadow: 0 24px 60px rgba(34, 44, 39, 0.12);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
font-family: "Space Grotesk", "Segoe UI", sans-serif;
color: var(--ink);
background:
radial-gradient(circle at top left, rgba(15, 118, 110, 0.18), transparent 32%),
radial-gradient(circle at 85% 15%, rgba(180, 83, 9, 0.16), transparent 22%),
linear-gradient(160deg, #f7f1e7 0%, #efe5d4 44%, #f9f6ef 100%);
padding: 32px 20px 48px;
}
main {
max-width: 1080px;
margin: 0 auto;
}
.hero {
display: grid;
gap: 12px;
margin-bottom: 24px;
}
h1 {
margin: 0;
font-size: clamp(2rem, 4vw, 3.8rem);
line-height: 0.95;
letter-spacing: -0.04em;
}
.subtitle {
margin: 0;
max-width: 760px;
color: var(--muted);
font-size: 1rem;
line-height: 1.6;
}
.panel {
background: var(--panel);
backdrop-filter: blur(12px);
border: 1px solid var(--line);
border-radius: 24px;
box-shadow: var(--shadow);
overflow: hidden;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
.section {
padding: 24px;
border-right: 1px solid var(--line);
}
.section:last-child {
border-right: none;
}
.section h2 {
margin: 0 0 8px;
font-size: 1rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section p {
margin: 0 0 18px;
color: var(--muted);
line-height: 1.5;
}
label {
display: block;
margin: 16px 0 8px;
font-size: 0.9rem;
font-weight: 700;
}
input[type="text"],
textarea,
input[type="file"] {
width: 100%;
border: 1px solid rgba(15, 118, 110, 0.2);
border-radius: 16px;
padding: 14px 16px;
font: inherit;
color: var(--ink);
background: rgba(255, 255, 255, 0.88);
transition: border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}
input[type="text"]:focus,
textarea:focus,
input[type="file"]:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
transform: translateY(-1px);
}
textarea {
min-height: 280px;
resize: vertical;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 20px;
}
.output-actions {
display: flex;
justify-content: flex-end;
margin-top: 12px;
}
button {
border: none;
border-radius: 999px;
padding: 14px 22px;
font: inherit;
font-weight: 700;
cursor: pointer;
transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}
button:hover {
transform: translateY(-1px);
}
.primary {
color: #f7fffe;
background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
box-shadow: 0 14px 30px rgba(15, 118, 110, 0.24);
}
.secondary {
color: var(--ink);
background: rgba(255, 255, 255, 0.78);
border: 1px solid var(--line);
}
.status {
min-height: 24px;
margin-top: 16px;
font-weight: 700;
}
.status.output-status {
margin-top: 0;
margin-bottom: 0;
text-align: right;
}
.status.warn {
color: var(--warn);
}
.status.error {
color: var(--error);
}
.status.ok {
color: var(--accent-strong);
}
.meta {
display: flex;
flex-wrap: wrap;
gap: 12px 18px;
margin-top: 12px;
color: var(--muted);
font-size: 0.9rem;
}
.output {
min-height: 360px;
font-family: "Cascadia Code", "Consolas", monospace;
white-space: pre-wrap;
overflow: auto;
word-break: break-word;
overflow-wrap: anywhere;
}
@media (max-width: 760px) {
body {
padding: 20px 14px 32px;
}
.grid {
grid-template-columns: 1fr;
}
.section {
border-right: none;
border-bottom: 1px solid var(--line);
}
.section:last-child {
border-bottom: none;
}
}
</style>
</head>
<body>
<main>
<section class="hero">
<h1>PS4 Key Serialization for Diva Pico</h1>
<p class="subtitle">Pack <strong>signature.bin</strong>, <strong>serial.txt</strong>, and <strong>key.pem</strong> into one copy-friendly plain text string for the new <strong>ps4key</strong> CLI command. The format is <strong>PS4K1 + Base64(binary payload)</strong> with a CRC32 over the raw payload bytes.</p>
</section>
<section class="panel grid">
<div class="section">
<h2>Input</h2>
<p>Provide the binary signature, the 16-digit serial, and the RSA private key text. Validation is intentionally strict to catch common mistakes before flashing.</p>
<label for="sigFile">signature.bin 文件</label>
<input id="sigFile" type="file" accept=".bin,application/octet-stream">
<label for="serialFile">serial.txt 文件</label>
<input id="serialFile" type="file" accept=".txt,text/plain">
<label for="pemFile">key.pem 文件</label>
<input id="pemFile" type="file" accept=".pem,text/plain">
<div class="actions">
<button id="packButton" class="primary" type="button">Pack</button>
</div>
<div id="status" class="status" aria-live="polite"></div>
<div id="meta" class="meta"></div>
</div>
<div class="section">
<h2>Output</h2>
<p>Single-line plain text, suitable for direct paste into the CLI as <strong>ps4key &lt;serialized_key&gt;</strong>.</p>
<textarea id="output" class="output" readonly wrap="soft" placeholder="Packed text will appear here."></textarea>
<div class="output-actions">
<button id="copyButton" class="secondary" type="button">Copy Output</button>
</div>
<div id="outputStatus" class="status output-status" aria-live="polite"></div>
</div>
</section>
</main>
<script>
const PREFIX = "PS4K1";
const SERIAL_LENGTH = 16;
const PEM_MAX_LENGTH = 2048;
const SIG_MAX_LENGTH = 512;
const sigFileInput = document.getElementById("sigFile");
const serialFileInput = document.getElementById("serialFile");
const pemFileInput = document.getElementById("pemFile");
const output = document.getElementById("output");
const status = document.getElementById("status");
const meta = document.getElementById("meta");
const packButton = document.getElementById("packButton");
const copyButton = document.getElementById("copyButton");
const encoder = new TextEncoder();
function setStatus(kind, message) {
status.className = `status ${kind}`;
status.textContent = message;
}
function setOutputStatus(kind, message) {
const outputStatus = document.getElementById("outputStatus");
outputStatus.className = `status output-status ${kind}`;
outputStatus.textContent = message;
}
function setMeta(parts) {
meta.innerHTML = "";
for (const part of parts) {
const span = document.createElement("span");
span.textContent = part;
meta.appendChild(span);
}
}
function normalizePem(text) {
return text.replace(/\r\n?/g, "\n").trim();
}
function assertInputs(serial, pem, sigBytes) {
if (!sigBytes || sigBytes.length === 0) {
throw new Error("请上传 signature.bin 二进制文件。");
}
if (sigBytes.length > SIG_MAX_LENGTH) {
throw new Error(`signature.bin 二进制文件过大,最大 ${SIG_MAX_LENGTH} 字节。`);
}
if (!/^\d{16}$/.test(serial)) {
throw new Error("serial.txt 必须是 16 位十进制字符串。");
}
if (!pem.includes("-----BEGIN RSA PRIVATE KEY-----") ||
!pem.includes("-----END RSA PRIVATE KEY-----")) {
throw new Error("key.pem 必须包含 BEGIN/END RSA PRIVATE KEY 标记。");
}
if (pem.length === 0 || pem.length > PEM_MAX_LENGTH) {
throw new Error(`key.pem 长度必须在 1-${PEM_MAX_LENGTH} 字符之间。`);
}
}
function crc32(bytes) {
let crc = 0xffffffff;
for (const byte of bytes) {
crc ^= byte;
for (let bit = 0; bit < 8; bit += 1) {
const mask = -(crc & 1);
crc = (crc >>> 1) ^ (0xedb88320 & mask);
}
}
return (crc ^ 0xffffffff) >>> 0;
}
function bytesToBase64(bytes) {
let binary = "";
const chunk = 0x8000;
for (let i = 0; i < bytes.length; i += chunk) {
binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
}
return btoa(binary);
}
function packPayload(serial, pem, sigBytes) {
const serialBytes = encoder.encode(serial);
const pemBytes = encoder.encode(pem);
const payloadLength = serialBytes.length + pemBytes.length + sigBytes.length;
const payload = new Uint8Array(payloadLength);
payload.set(serialBytes, 0);
payload.set(pemBytes, serialBytes.length);
payload.set(sigBytes, serialBytes.length + pemBytes.length);
const header = new Uint8Array(15);
header.set([0x50, 0x53, 0x34, 0x4b], 0);
header[4] = 1;
const view = new DataView(header.buffer);
view.setUint16(5, serialBytes.length, true);
view.setUint16(7, pemBytes.length, true);
view.setUint16(9, sigBytes.length, true);
view.setUint32(11, crc32(payload), true);
const packed = new Uint8Array(header.length + payload.length);
packed.set(header, 0);
packed.set(payload, header.length);
return PREFIX + bytesToBase64(packed);
}
async function readFileAsText(input) {
const file = input.files && input.files[0];
if (!file) return null;
return await file.text();
}
async function readFileAsBytes(input) {
const file = input.files && input.files[0];
if (!file) return null;
return new Uint8Array(await file.arrayBuffer());
}
async function doPack() {
try {
// 前置文件选择校验
if (!sigFileInput.files || !sigFileInput.files[0]) {
setStatus("error", "请先选择 sig.bin 文件。");
return;
}
if (!serialFileInput.files || !serialFileInput.files[0]) {
setStatus("error", "请先选择 serial.txt 文件。");
return;
}
if (!pemFileInput.files || !pemFileInput.files[0]) {
setStatus("error", "请先选择 key.pem 文件。");
return;
}
const sigBytes = await readFileAsBytes(sigFileInput);
const serialText = await readFileAsText(serialFileInput);
const pemText = await readFileAsText(pemFileInput);
if (!sigBytes || sigBytes.length === 0) {
setStatus("error", "sig.bin 文件读取失败或为空。");
return;
}
if (!serialText || serialText.trim().length === 0) {
setStatus("error", "serial.txt 文件读取失败或为空。");
return;
}
if (!pemText || pemText.trim().length === 0) {
setStatus("error", "key.pem 文件读取失败或为空。");
return;
}
const serial = serialText ? serialText.replace(/\s+/g, "").trim() : "";
const pem = pemText ? normalizePem(pemText) : "";
assertInputs(serial, pem, sigBytes);
const packed = packPayload(serial, pem, sigBytes);
output.value = packed;
setMeta([
`serial: ${serial.length} bytes`,
`pem: ${pem.length} bytes`,
`sig: ${sigBytes.length} bytes`,
`output: ${packed.length} chars`
]);
setStatus("ok", "打包成功。");
} catch (error) {
output.value = "";
setMeta([]);
setStatus("error", error instanceof Error ? error.message : String(error));
}
}
async function copyOutput() {
if (!output.value) {
setOutputStatus("warn", "Nothing to copy.");
return;
}
try {
await navigator.clipboard.writeText(output.value);
output.select();
setOutputStatus("ok", "Output copied to clipboard.");
} catch (error) {
output.focus();
output.select();
setOutputStatus("warn", "Clipboard API is unavailable. The output has been selected.");
}
}
packButton.addEventListener("click", doPack);
copyButton.addEventListener("click", copyOutput);
</script>
</body>
</html>