forked from fpv-wtf/margerine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
margerine.js
78 lines (66 loc) · 2.44 KB
/
margerine.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const SerialPort = require('serialport')
const yargs = require('yargs')
const chalk = require('chalk')
/* we use Sentry to help debug in case of errors in the obfuscated build and basic analytics */
const Sentry = require("@sentry/node");
const Tracing = require("@sentry/tracing");
Sentry.init({
dsn: "https://[email protected]/6247631",
tracesSampleRate: 1.0,
});
const { lock, unlock } = require("./src/exploit")
const { wrapSentry } = require("./src/utils")
console.log(chalk.hex("#0057b7")("margerine - brought to you with love by the fpv.wtf team"))
console.log(chalk.hex("#ffd700")("special thanks to @tmbinc, @bin4ry, @jaanuke and @funnel\n"))
async function getDevice(argv) {
if(argv.serialport) {
return argv.serialport
}
else {
return SerialPort.list()
.then(portInfos => {
var dji = portInfos.filter(pinfo => `${pinfo.vendorId}`.match(/2CA3/i))
if(!dji.length) {
console.log("no dji devices detected\nyou may wish to specify a COM port, see node margerine.js --help")
process.exit(1)
}
return dji[0].path
})
}
}
const argv = yargs
.command('unlock [serialport]', 'unlock device and enable adb', (yargs) => {
return yargs
.positional('serialport', {
describe: '(optional) serial port to connect to'
})
}, (argv) => {
wrapSentry("unlock", async () => {
return await getDevice(argv)
.then(unlock)
.then(() => {
console.log("\ndevice should be unlocked, try 'adb devices'")
console.log("please consider donating: https://github.com/fpv-wtf/margerine#support-the-effort")
})
.catch((error)=>{
console.error("couldn't do the magic. please read the notes in README.md, restart your device and try again")
throw error
})
})
})
.command('lock [serialport]', 'disable startup patches', (yargs) => {
return yargs
.positional('serialport', {
describe: '(optional) serial port to connect to'
})
}, (argv) => {
wrapSentry("lock", () => {
return getDevice(argv)
.then(lock)
.then(() => {
console.log("\nstartup patches should be disabled now, you should probably re-flash your device")
})
})
})
.demandCommand()
.argv