5eeada1fd5
Added PS4 Firmware Detection
76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
/* Copyright (C) 2023 anonymous
|
|
|
|
This file is part of PSFree.
|
|
|
|
PSFree is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
PSFree is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
|
|
import { Int } from './int64.mjs';
|
|
|
|
export function die(msg) {
|
|
alert(msg);
|
|
undefinedFunction();
|
|
}
|
|
|
|
export function debug_log(msg) {
|
|
let textNode = document.createTextNode(msg);
|
|
let node = document.createElement("p").appendChild(textNode);
|
|
|
|
document.body.appendChild(node);
|
|
document.body.appendChild(document.createElement("br"));
|
|
}
|
|
|
|
export function clear_log() {
|
|
document.body.innerHTML = null;
|
|
}
|
|
|
|
export function str2array(str, length, offset) {
|
|
if (offset === undefined) {
|
|
offset = 0;
|
|
}
|
|
let a = new Array(length);
|
|
for (let i = 0; i < length; i++) {
|
|
a[i] = str.charCodeAt(i + offset);
|
|
}
|
|
return a;
|
|
}
|
|
|
|
// alignment must be 32 bits and is a power of 2
|
|
export function align(a, alignment) {
|
|
if (!(a instanceof Int)) {
|
|
a = new Int(a);
|
|
}
|
|
const mask = -alignment & 0xffffffff;
|
|
let type = a.constructor;
|
|
let low = a.low() & mask;
|
|
return new type(low, a.high());
|
|
}
|
|
|
|
export async function send(url, buffer, file_name, onload=() => {}) {
|
|
const file = new File(
|
|
[buffer],
|
|
file_name,
|
|
{type:'application/octet-stream'}
|
|
);
|
|
const form = new FormData();
|
|
form.append('upload', file);
|
|
|
|
debug_log('send');
|
|
const response = await fetch(url, {method: 'POST', body: form});
|
|
|
|
if (!response.ok) {
|
|
throw Error(`Network response was not OK, status: ${response.status}`);
|
|
}
|
|
onload();
|
|
}
|