-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
59 lines (50 loc) · 1.78 KB
/
app.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
#!/usr/bin/env node
'use strict';
let parser = require('./ttn-v3/imbuildings-decoder');
let config = {
arguments: {}
}
function getArguments(){
config.arguments = {};
for(let i = 0; i < process.argv.length; i++){
let currentArg = process.argv[i];
if(currentArg.substr(0,2) == '--'){
//This is an argument
let splitted = currentArg.split('=');
if(splitted.length > 1){
let setting = splitted[0].substr(2).toLowerCase();
let value = splitted[1];
config.arguments[setting] = value;
}
}
}
}
getArguments();
if(config.arguments.payload){
console.log(`Translating payload: ${config.arguments.payload} as buffer...\r\n`)
let input = {fPort: parseInt(config.arguments.fport), bytes: Buffer.from(config.arguments.payload,'hex')};
let parsedData = parser.decode(input);
if(parsedData){
console.log(parsedData);
}else{
console.log('Payload structure unknown');
}
}else if(config.arguments.base64){
console.log(`Translating payload: ${config.arguments.base64} as base64...\r\n`)
console.log(`Hex view: ${Buffer.from(config.arguments.base64,'base64').toString('hex')}`);
let input = {fPort: parseInt(config.arguments.fport), bytes: Buffer.from(config.arguments.base64,'base64')};
let parsedData = parser.decode(input);
if(parsedData){
console.log(parsedData);
} else{
console.log('Payload structure unknown');
}
}else{
console.log(`
Please run this applition with the following argument:
--payload= Enter your payload in as a HEX string
OR
--base64= Enter your payload as Base64 string
In case the header is not in the payload you can add --fport= for port based decoding.
`);
}