diff --git a/index.js b/index.js index f811522..3b7c236 100644 --- a/index.js +++ b/index.js @@ -4,48 +4,55 @@ const args = process.argv.slice(2).join(' '); const pongoOSDevice = usb.findByIds(0x05ac, 0x4141); function log(message, type) { - switch (type) { - case 'success': - console.log("[+] " + message) - break; - case 'error': - console.error("[-] " + message) - break; - } + switch (type) { + case 'success': + console.log("[+] " + message) + break; + case 'error': + console.error("[-] " + message) + 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() { - 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()) { - log(`Please run ass root (Current UID = ${process.getuid()}, Need UID = 0)`, "error"); - process.exit(1); + log(`Please run ass root (Current UID = ${process.getuid()}, Need UID = 0)`, "error"); + process.exit(1); }; if (!pongoOSDevice) { - log("No device with pongoOS Booted has been found.", "error"); - process.exit(1); + log("No device with pongoOS Booted has been found.", "error"); + process.exit(1); }; if (!args) { - log("No argumment has been provided.", "error"); - process.exit(1); + log("No argumment has been provided.", "error"); + process.exit(1); }; try { - pongoOSDevice.open(true) + pongoOSDevice.open(true) } catch (e) { - log("An error as occured while i was opening the device.", "error"); - process.exit(1) + 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) + log("You reached the length of the argumment.", "error"); + process.exit(1) }; pongoOSDevice.controlTransfer(0x21, 3, 0, 0, new Buffer.from(`${args} \n`), (error) => { - 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); + 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); }) \ No newline at end of file