pongoOS-Controller/index.js

51 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-04-23 02:38:30 +02:00
const usb = require('usb')
const args = process.argv.slice(2).join(' ');
const pongoOSDevice = usb.findByIds(0x05ac, 0x4141);
2021-05-06 01:02:06 +02:00
function log(message, type) {
switch (type) {
case 'success':
console.log("[+] " + message)
break;
case 'error':
console.error("[-] " + message)
break;
}
2021-04-23 02:38:30 +02:00
}
2021-05-06 01:02:06 +02:00
function checkRoot() {
return process.getuid && process.getuid() === 0
};
2021-04-23 02:38:30 +02:00
if (!checkRoot()) {
2021-12-14 22:58:10 +01:00
log(`Please run ass root (Current UID = ${process.getuid()}, Need UID = 0)`, "error");
2021-05-06 01:02:06 +02:00
process.exit(1);
};
2021-04-23 02:38:30 +02:00
if (!pongoOSDevice) {
2021-05-06 01:02:06 +02:00
log("No device with pongoOS Booted has been found.", "error");
process.exit(1);
};
2021-04-23 02:38:30 +02:00
if (!args) {
2021-05-06 01:02:06 +02:00
log("No argumment has been provided.", "error");
process.exit(1);
};
2021-04-23 02:38:30 +02:00
try {
2021-05-06 01:02:06 +02:00
pongoOSDevice.open(true)
} catch (e) {
log("An error as occured while i was opening the device.", "error");
process.exit(1)
};
if (args.length > 510) {
log("You reached the length of the argumment.", "error");
process.exit(1)
};
2021-04-23 02:38:30 +02:00
pongoOSDevice.controlTransfer(0x21, 3, 0, 0, new Buffer.from(`${args} \n`), (error) => {
2021-05-06 01:02:06 +02:00
if (error) {
log(`An error as occured while sending cmd error: ${error}`, "error")
process.exit(1);
}
log(`Success, command "${args}" has been sent.`, "success")
process.exit(0);
2021-04-23 02:38:30 +02:00
})