Files
whowechina_diva_pico/tools/ps4key_packer.html
T
2026-04-13 12:32:30 +08:00

470 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 Packer 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(1.5rem, 3vw, 2.4rem);
line-height: 1.1;
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;
}
.panel-main {
margin-top: 12px;
min-width: 800px;
}
.panel-top {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
align-items: stretch;
}
.section {
padding: 24px 24px 2px;
border-right: 1px solid var(--line);
}
.section:last-child {
border-right: none;
}
.button-row {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
margin-top: 0;
padding-top: 0;
}
.button-section {
padding: 2px 24px 24px;
border-right: 1px solid var(--line);
display: flex;
align-items: center;
}
.button-section:last-child {
border-right: none;
}
.button-section.left,
.button-section.right {
justify-content: center;
}
.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;
}
button {
border: none;
border-radius: 999px;
padding: 14px 88px;
font: inherit;
font-weight: 700;
cursor: pointer;
box-shadow: 0 8px 24px rgba(15, 118, 110, 0.10);
transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}
button:hover {
transform: translateY(-1px);
opacity: 0.96;
}
.primay {
color: var(--accent-strong);
background: linear-gradient(135deg, #e6f7f5 0%, #d2f1ed 100%);
border: 1px solid #b6e2de;
box-shadow: 0 8px 24px rgba(15, 118, 110, 0.10);
padding: 14px 88px;
}
.status {
min-height: 24px;
margin-top: 16px;
font-weight: 700;
}
.status.output-status {
margin-top: 0;
margin-bottom: 0;
text-align: left;
}
.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;
}
}
</style>
</head>
<body>
<main>
<section class="hero">
<h1>PS4 Key Packer for Diva Pico</h1>
</section>
<section class="panel panel-main">
<div class="panel-top">
<div class="section">
<h2>Input</h2>
<p>Provide the binary signature, the serial, and the RSA private key files.</p>
<label for="sigFile">signature.bin file</label>
<input id="sigFile" type="file" accept=".bin,application/octet-stream">
<label for="serialFile">serial.txt file</label>
<input id="serialFile" type="file" accept=".txt,text/plain">
<label for="pemFile">key.pem file</label>
<input id="pemFile" type="file" accept=".pem,text/plain">
<div id="status" class="status" aria-live="polite"></div>
<div id="meta" class="meta"></div>
</div>
<div class="section">
<h2>Output</h2>
<textarea id="output" class="output" readonly wrap="soft" placeholder="Packed text will appear here."></textarea>
<div id="outputStatus" class="status output-status" aria-live="polite"></div>
</div>
</div>
<div class="button-row">
<div class="button-section left">
<button id="packButton" class="primay" type="button">Pack the Files</button>
</div>
<div class="button-section right">
<button id="copyButton" class="primay" type="button">Copy to Clipboard</button>
</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("Please upload the signature.bin file.");
}
if (sigBytes.length > SIG_MAX_LENGTH) {
throw new Error(`signature.bin is too large, max ${SIG_MAX_LENGTH} bytes.`);
}
if (!/^\d{16}$/.test(serial)) {
throw new Error("serial.txt must be a 16-digit decimal string.");
}
if (!pem.includes("-----BEGIN RSA PRIVATE KEY-----") ||
!pem.includes("-----END RSA PRIVATE KEY-----")) {
throw new Error("key.pem must contain BEGIN/END RSA PRIVATE KEY markers.");
}
if (pem.length === 0 || pem.length > PEM_MAX_LENGTH) {
throw new Error(`key.pem length must be 1-${PEM_MAX_LENGTH} characters.`);
}
}
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 serialLen = serialBytes.length + 1;
const pemLen = pemBytes.length + 1;
const payloadLength = serialLen + pemLen + sigBytes.length;
const payload = new Uint8Array(payloadLength);
payload.set(serialBytes, 0);
payload[serialBytes.length] = 0;
payload.set(pemBytes, serialLen);
payload[serialLen + pemBytes.length] = 0;
payload.set(sigBytes, serialLen + pemLen);
const header = new Uint8Array(16);
header.set([0x50, 0x53, 0x34, 0x4b], 0);
header[4] = 1;
header[5] = 0;
const view = new DataView(header.buffer);
view.setUint16(6, serialLen, true);
view.setUint16(8, pemLen, true);
view.setUint16(10, sigBytes.length, true);
view.setUint32(12, 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 {
// Pre-file selection validation
if (!sigFileInput.files || !sigFileInput.files[0]) {
setStatus("error", "Please select sig.bin file.");
return;
}
if (!serialFileInput.files || !serialFileInput.files[0]) {
setStatus("error", "Please select serial.txt file.");
return;
}
if (!pemFileInput.files || !pemFileInput.files[0]) {
setStatus("error", "Please select key.pem file.");
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 file read failed or empty.");
return;
}
if (!serialText || serialText.trim().length === 0) {
setStatus("error", "serial.txt file read failed or empty.");
return;
}
if (!pemText || pemText.trim().length === 0) {
setStatus("error", "key.pem file read failed or empty.");
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;
setStatus("ok", `Packed successfully, total ${packed.length} chars.`);
} catch (error) {
output.value = "";
setMeta([]);
setStatus("error", error instanceof Error ? error.message : String(error));
}
}
async function copyOutput() {
if (!output.value) {
return;
}
try {
await navigator.clipboard.writeText(output.value);
output.select();
setOutputStatus("ok", "Output copied to clipboard.");
} catch (error) {
output.focus();
output.select();
}
}
packButton.addEventListener("click", doPack);
copyButton.addEventListener("click", copyOutput);
</script>
</body>
</html>