2018-05-14 14:31:04 +00:00
/ * *
* @ author n1474335 [ n1474335 @ gmail . com ]
* @ copyright Crown Copyright 2017
* @ license Apache - 2.0
* /
2019-07-09 12:23:59 +01:00
import Operation from "../Operation.mjs" ;
2019-12-02 14:15:21 +00:00
import magicObject from "../lib/MagicObject.mjs" ;
2018-05-14 14:31:04 +00:00
/ * *
* Decode NetBIOS Name operation
* /
class DecodeNetBIOSName extends Operation {
/ * *
* DecodeNetBIOSName constructor
* /
constructor ( ) {
super ( ) ;
this . name = "Decode NetBIOS Name" ;
this . module = "Default" ;
this . description = "NetBIOS names as seen across the client interface to NetBIOS are exactly 16 bytes long. Within the NetBIOS-over-TCP protocols, a longer representation is used.<br><br>There are two levels of encoding. The first level maps a NetBIOS name into a domain system name. The second level maps the domain system name into the 'compressed' representation required for interaction with the domain name system.<br><br>This operation decodes the first level of encoding. See RFC 1001 for full details." ;
2018-08-21 19:07:13 +01:00
this . infoURL = "https://wikipedia.org/wiki/NetBIOS" ;
2018-05-14 14:31:04 +00:00
this . inputType = "byteArray" ;
this . outputType = "byteArray" ;
this . args = [
{
"name" : "Offset" ,
"type" : "number" ,
"value" : 65
}
] ;
2019-12-02 14:15:21 +00:00
this . checks = new magicObject ( [
2019-11-26 16:43:54 +00:00
{
2019-11-27 10:24:31 +00:00
match : "^\\s*\\S{32}$" ,
2019-11-26 16:43:54 +00:00
flags : "" ,
2019-12-04 14:12:27 +00:00
magic : true ,
2019-11-26 16:43:54 +00:00
args : [ 65 ]
}
2019-12-02 14:15:21 +00:00
] ) ;
2018-05-14 14:31:04 +00:00
}
/ * *
* @ param { byteArray } input
* @ param { Object [ ] } args
* @ returns { byteArray }
* /
run ( input , args ) {
const output = [ ] ,
offset = args [ 0 ] ;
if ( input . length <= 32 && ( input . length % 2 ) === 0 ) {
for ( let i = 0 ; i < input . length ; i += 2 ) {
output . push ( ( ( ( input [ i ] & 0xff ) - offset ) << 4 ) |
( ( ( input [ i + 1 ] & 0xff ) - offset ) & 0xf ) ) ;
}
for ( let i = output . length - 1 ; i > 0 ; i -- ) {
if ( output [ i ] === 32 ) output . splice ( i , i ) ;
else break ;
}
}
return output ;
}
}
export default DecodeNetBIOSName ;