Add OS Checks

This commit is contained in:
Yaya4 2021-12-18 14:02:56 +01:00
parent 5262138c94
commit c4f6c66c6d

View File

@ -4,48 +4,55 @@ const args = process.argv.slice(2).join(' ');
const pongoOSDevice = usb.findByIds(0x05ac, 0x4141); const pongoOSDevice = usb.findByIds(0x05ac, 0x4141);
function log(message, type) { function log(message, type) {
switch (type) { switch (type) {
case 'success': case 'success':
console.log("[+] " + message) console.log("[+] " + message)
break; break;
case 'error': case 'error':
console.error("[-] " + message) console.error("[-] " + message)
break; break;
} }
}
if (process.platform != 'darwin' && process.platform != 'linux') {
log(`You can't run this script on (${process.platform}) only works on Darwin/Linux Platform.`, 'error');
process.exit(1);
} }
function checkRoot() { function checkRoot() {
return process.getuid && process.getuid() === 0 return process.getuid && process.getuid() === 0
}; };
log(`Running the script on ${process.platform} and arch ${process.arch}`, "success");
if (!checkRoot()) { if (!checkRoot()) {
log(`Please run ass root (Current UID = ${process.getuid()}, Need UID = 0)`, "error"); log(`Please run ass root (Current UID = ${process.getuid()}, Need UID = 0)`, "error");
process.exit(1); process.exit(1);
}; };
if (!pongoOSDevice) { if (!pongoOSDevice) {
log("No device with pongoOS Booted has been found.", "error"); log("No device with pongoOS Booted has been found.", "error");
process.exit(1); process.exit(1);
}; };
if (!args) { if (!args) {
log("No argumment has been provided.", "error"); log("No argumment has been provided.", "error");
process.exit(1); process.exit(1);
}; };
try { try {
pongoOSDevice.open(true) pongoOSDevice.open(true)
} catch (e) { } catch (e) {
log("An error as occured while i was opening the device.", "error"); log("An error as occured while i was opening the device.", "error");
process.exit(1) process.exit(1)
}; };
if (args.length > 510) { if (args.length > 510) {
log("You reached the length of the argumment.", "error"); log("You reached the length of the argumment.", "error");
process.exit(1) process.exit(1)
}; };
pongoOSDevice.controlTransfer(0x21, 3, 0, 0, new Buffer.from(`${args} \n`), (error) => { pongoOSDevice.controlTransfer(0x21, 3, 0, 0, new Buffer.from(`${args} \n`), (error) => {
if (error) { if (error) {
log(`An error as occured while sending cmd error: ${error}`, "error") log(`An error as occured while sending cmd error: ${error}`, "error")
process.exit(1); process.exit(1);
} }
log(`Success, command "${args}" has been sent.`, "success") log(`Success, command "${args}" has been sent.`, "success")
process.exit(0); process.exit(0);
}) })