Skip to content

Commit

Permalink
public release
Browse files Browse the repository at this point in the history
  • Loading branch information
BinBashBanana committed Oct 5, 2024
1 parent f55818d commit 5a427a8
Show file tree
Hide file tree
Showing 47 changed files with 5,382 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
buildroot-2023.02.9-badrecovery
8 changes: 8 additions & 0 deletions assets/br_archive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

if ! [ -d "$1" ]; then
echo "Please specify a valid directory containing buildroot" >&2
exit 1
fi

tar -czvf buildroot-badrecovery.tar.gz --exclude="./dl" -C "$1" . --owner=0 --group=0
Binary file added assets/buildroot-badrecovery.tar.gz
Binary file not shown.
Binary file added assets/bzImage
Binary file not shown.
112 changes: 112 additions & 0 deletions assets/hterm_all.min.js

Large diffs are not rendered by default.

Binary file added assets/images/chunked.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/chunked_workaround.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/code_execution.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/crosh_kiosk.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/policy_persistence.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/postinst.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/root_persistence.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
626 changes: 626 additions & 0 deletions assets/libv86.js

Large diffs are not rendered by default.

Binary file added assets/rootfs.cpio.gz
Binary file not shown.
Binary file added assets/seabios.bin
Binary file not shown.
104 changes: 104 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
body {
font-family: sans-serif;
background-color: #1e1e1e;
color: #ebebeb;
}

a {
color: #3ec3f0;
}

.builderbutton {
display: block;
width: max-content;
user-select: none;
cursor: pointer;
text-align: center;
margin: 16px auto;
font-size: 30px;
font-weight: bold;
}

#displayContainer {
display: none;
}

#displayContainer>* {
margin: 10px;
}

.builderlog * {
}

.builderlog {
font-family: monospace;
color: white;
background-color: black;
width: 40vw;
height: 20vw;
font-family: monospace;
font-size: 13px;
/*box-shadow: 1px 2px 5px 0px rgba(0, 0, 0, 0.5);*/
overflow: hidden;
position: relative;
white-space: pre;
}

#linuxOutput {
display: flex !important;
flex-direction: column;
justify-content: flex-end;
}

#builderOptions {
margin: auto;
margin-bottom: 50px;
width: max-content;
}

#builderOptions input[type=checkbox],
#builderOptions select {
cursor: pointer;
vertical-align: baseline;
outline: none;
}

#builderOptions input[type=checkbox] {
transform: scale(1.2);
}

#builderOptions label {
display: block;
font-size: 16px;
margin: 10px 0px;
}

#builderOptions span {
margin: 5px;
}

.builderfooter {
margin-top: 50px;
text-align: center;
font-size: 16px;
}

.centerBox {
margin: auto;
width: max-content;
max-width: calc(100vw - 16px);
}

.centerBox h1 {
text-align: center;
}

.centertext {
display: block;
text-align: center;
}

.moreLineSpacing {
font-size: 12pt;
line-height: 30px;
}
Binary file added assets/v86.wasm
Binary file not shown.
Binary file added assets/vgabios.bin
Binary file not shown.
203 changes: 203 additions & 0 deletions assets/webbuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
const minDiskSize = (6 * 1024 * 1024 * 1024); // 6 GiB
const maxSingleAlloc = 1024 * 1024 * 1024; // 1 GiB
let builderOptions = document.getElementById("builderOptions");
let startButton = document.getElementById("startButton");
let downloadButton = document.getElementById("downloadButton");
let displayContainer = document.getElementById("displayContainer");
let linuxOutput = document.getElementById("linuxOutput");
let builderOutput;
let building = false;
let builderTextOut = "";
let builderOutputIO;
let curLoadingFile = "";
let uploadedName = "image.bin";

function uploadFile(accept, callback) {
var input = document.createElement("input");
input.type = "file";
input.accept = accept;
input.onchange = async function() {
callback(this.files[0]);
}
input.click();
}

function unzipFile(data) {
return new Promise(async function(resolve, error) {
let entries = await new zip.ZipReader(new zip.Uint8ArrayReader(new Uint8Array(data))).getEntries();
if (entries.length) {
for (var i = 0; i < entries.length; i++) {
if (!entries[i].directory) {
resolve(await entries[i].getData(new zip.Uint8ArrayWriter()));
break;
}
if (i == entries.length - 1) error();
}
}
error();
});
}

function getTime() {
var dateTime = new Date();
return dateTime.getFullYear().toString()+"-"+(dateTime.getMonth()+1).toString()+"-"+dateTime.getDate().toString()+"-"+dateTime.getHours().toString()+"-"+dateTime.getMinutes().toString();
}

function progressFetch(url) {
return new Promise(function(success, fail) {
var req = new XMLHttpRequest();
req.open("GET", url, true);
req.responseType = "arraybuffer";
req.onload = function() {
if (req.status >= 400) {
if (fail) fail(req.status);
} else {
if (success) success(this.response);
}
}
req.onprogress = function(e) {
if (e.lengthComputable) updateLoadProgress(url, e.loaded / e.total);
}
req.onerror = function() {
if (fail) fail("unknown");
}
req.send();
});
}

async function fetchWebBuilderTar() {
console.log("fetching webbuilder.tar.zip");
var webBuilderTarZip = await progressFetch("assets/webbuilder.tar.zip");
var webBuilderTar = await unzipFile(webBuilderTarZip);
return webBuilderTar;
}

function sleep(ms) {
return new Promise(function(resolve) {
setTimeout(resolve, ms);
});
}

async function growBlob(blob, size) {
var totalAddedSize = size - blob.size;
var totalSizeToAdd = totalAddedSize;
var err = false;
while (totalSizeToAdd > 0) {
var addedSize = Math.min(totalAddedSize, maxSingleAlloc);
try {
blob = new Blob([blob, new ArrayBuffer(addedSize)]);
} catch (e) {
console.error(e);
err = true;
break;
}
totalSizeToAdd -= addedSize;
updateLoadProgress("(growing blob)", Math.min(1, 1 - (totalSizeToAdd / totalAddedSize)));
await sleep(0);
}
if (err) builderOutputIO.print("\r\nWarning: failed to grow blob...\r\n");
return blob;
}

async function doneBuilding() {
console.log("done building");
var finalSizeFile = await emulator.read_file("/finalsize");
var finalBytes = parseInt(new TextDecoder().decode(finalSizeFile));
console.log("final bytes: " + finalBytes);
var blob = emulator.disk_images.hda.get_as_file().slice(0, finalBytes, "application/octet-stream");
downloadButton.download = "badrecovery_" + getTime() + "_" + uploadedName;
downloadButton.href = URL.createObjectURL(blob);
downloadButton.style.display = "block";
downloadButton.click();
}

function updateLoadProgress(name, percent) {
if (name != curLoadingFile) {
if (curLoadingFile.length) builderOutputIO.print("\n");
curLoadingFile = name;
}
builderOutputIO.print("\rLoading " + name + " " + Math.round(percent * 100) + "% ");
}

async function initFromFile(file) {
uploadedName = file.name;
if (file.size < minDiskSize) file = new File([await growBlob(file, minDiskSize)], file.name);
builderOptions.querySelectorAll("input, select").forEach(e => e.setAttribute("disabled", ""));
startButton.style.display = "none";
linuxOutput.textContent = "Loading...";
displayContainer.style.display = "block";
console.log("creating emulator...");
window.emulator = new V86Starter({
wasm_path: "assets/v86.wasm",
memory_size: 512 * 1024 * 1024,
vga_memory_size: 2 * 1024 * 1024,
screen_container: document.getElementById("screen_container"),
bios: {
url: "assets/seabios.bin"
},
vga_bios: {
url: "assets/vgabios.bin"
},
bzimage: {
url: "assets/bzImage"
},
initrd: {
url: "assets/rootfs.cpio.gz"
},
hda: {
buffer: file
},
filesystem: {},
autostart: false
});
emulator.add_listener("download-progress", function(p) {
if (p.lengthComputable) updateLoadProgress(p.file_name, p.loaded / p.total);
});
emulator.add_listener("emulator-ready", async function() {
var optsBool = Array.from(builderOptions.querySelectorAll("input[type=checkbox]"));
for (var i = 0; i < optsBool.length; i++) {
if (optsBool[i].checked) await emulator.create_file("/opt." + optsBool[i].name, new Uint8Array());
}
var optsText = Array.from(builderOptions.querySelectorAll("select"));
for (var i = 0; i < optsText.length; i++) {
if (optsText[i].value) await emulator.create_file("/opt." + optsText[i].name, new TextEncoder().encode(optsText[i].value));
}
await emulator.create_file("/web.tar", await fetchWebBuilderTar());
console.log("running...");
emulator.run();
});
emulator.add_listener("serial0-output-byte", async function(byte) {
builderOutputIO.writeUTF8(new Uint8Array([byte]));
builderTextOut += String.fromCharCode(byte);
if (builderTextOut.endsWith("Done building!")) {
building = false;
doneBuilding();
}
});
function writeData(str) {
emulator.serial0_send(str);
}
builderOutputIO.onVTKeystroke = writeData;
builderOutputIO.sendString = writeData;
building = true;
}

function loadWebBuilder() {
builderOutput = new hterm.Terminal({storage: new lib.Storage.Memory()});
builderOutput.decorate(document.getElementById("builderOutput"));
builderOutput.installKeyboard();
builderOutput.onTerminalReady = function() {
builderOutput.setFontSize(13);
builderOutputIO = builderOutput.io.push();
builderOutputIO.print("\x1b[?25l");
startButton.addEventListener("click", function() {
uploadFile(".bin, .img", initFromFile);
}, false);
startButton.classList.remove("disabled");
}
}

window.addEventListener("load", loadWebBuilder, false);
window.onbeforeunload = function() {
if (building) return true;
}
Binary file added assets/webbuilder.tar.zip
Binary file not shown.
1 change: 1 addition & 0 deletions assets/zip.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 5a427a8

Please sign in to comment.