Example #1
0
function tlv_close() {
	var tlv_hdr_len_offset = 4;
	var tlv_hdr_crc_offset = 8;
	var tlv_crc_buf = tlv_buf.slice(tlv_hdr_len, tlv_buf_offset);

	tlv_buf.writeUInt32LE(tlv_buf_offset, tlv_hdr_len_offset, 4, 'hex');
	tlv_buf.writeUInt32LE(wmcrc.crc32(tlv_crc_buf), tlv_hdr_crc_offset, 4, 'hex');
}
Example #2
0
function add_tlv_data(type, length, value, encoding) {
	tlv_buf.writeUInt32LE(type, tlv_buf_offset, 1, 'hex');
	tlv_buf_offset += 1;
	tlv_buf.writeUInt32LE(length, tlv_buf_offset, 2, 'hex');
	tlv_buf_offset += 2;
	if (typeof encoding === "undefined")
		tlv_buf.write(value, tlv_buf_offset, length, 'hex');
	else if (encoding === 'hex')
		tlv_buf.writeUInt32LE(value, tlv_buf_offset, length, 'hex');
	else
		tlv_buf.write(value, tlv_buf_offset, length, encoding);
	tlv_buf_offset += length;
}
Example #3
0
/* Initialize TLV header */
function tlv_init() {
	tlv_hdr_len = tlv_hdr_magic.BYTES_PER_ELEMENT +
		tlv_hdr_len.BYTES_PER_ELEMENT +
		tlv_hdr_crc.BYTES_PER_ELEMENT;
	tlv_hdr_magic = 0x53424648;
	/* CRC is initialized to max tlv size(4K) */
	tlv_hdr_crc = 0x00001000;

	/* Write initial values to tlv buffer */
	tlv_buf.writeUInt32BE(tlv_hdr_magic, tlv_buf_offset, 4, 'hex');
	tlv_buf_offset += 4;
	tlv_buf.writeUInt32LE(tlv_hdr_len, tlv_buf_offset, 4, 'hex');
	tlv_buf_offset += 4;
	tlv_buf.writeUInt32LE(tlv_hdr_crc, tlv_buf_offset, 4, 'hex');
	tlv_buf_offset += 4;
}
Example #4
0
 documents.map(function(el) {
     rb = write_buf(rb, el.type);
     rb = write_buf(rb,'\u0000');
     rb.writeUInt32LE(el.contents.length, rb._pos);
     rb._pos += 4;
     rb = write_buf(rb, el.contents);
 });
Example #5
0
Framer.prototype.settingsFrame = function settingsFrame(options) {
  var settings;

  if (!(settings = Framer.settingsCache[options.maxStreams])) {
    settings = new Buffer(20);

    settings.writeUInt32BE(0x80020004, 0, true); // Version and type
    settings.writeUInt32BE(0x0000000C, 4, true); // length
    settings.writeUInt32BE(0x00000001, 8, true); // Count of entries
    settings.writeUInt32LE(0x01000004, 12, true); // Entry ID and Persist flag
    settings.writeUInt32BE(options.maxStreams, 16, true);

    Framer.settingsCache[options.maxStreams] = settings;
  }

  return settings;
};
Example #6
0
  ['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) {
    buf.fill(0xFF);
    written = buf.write('abcd', 0, 2, encoding);
    console.log(buf);
    assert.equal(written, 2);
    assert.equal(buf[0], 0x61);
    assert.equal(buf[1], 0x00);
    assert.equal(buf[2], 0xFF);
    assert.equal(buf[3], 0xFF);
  });
}

{
  // test offset returns are correct
  const b = new Buffer(16);
  assert.equal(4, b.writeUInt32LE(0, 0));
  assert.equal(6, b.writeUInt16LE(0, 4));
  assert.equal(7, b.writeUInt8(0, 6));
  assert.equal(8, b.writeInt8(0, 7));
  assert.equal(16, b.writeDoubleLE(0, 8));
}

{
  // test unmatched surrogates not producing invalid utf8 output
  // ef bf bd = utf-8 representation of unicode replacement character
  // see https://codereview.chromium.org/121173009/
  const buf = new Buffer('ab\ud800cd', 'utf8');
  assert.equal(buf[0], 0x61);
  assert.equal(buf[1], 0x62);
  assert.equal(buf[2], 0xef);
  assert.equal(buf[3], 0xbf);
Example #7
0
        stream.pipe(message_parser);        
    } else {
        return new Parser(emitter, stream);
    }
}


var ConnectionValidation = new buffer.Buffer(14);
ConnectionValidation.write('IceP');                 // magic
ConnectionValidation.writeUInt8(1, 4);              // Protocol Major version
ConnectionValidation.writeUInt8(0, 5);              // Protocol Minor version
ConnectionValidation.writeUInt8(1, 6);              // Encoding Major version
ConnectionValidation.writeUInt8(0, 7);              // Encoding Minor version
ConnectionValidation.writeUInt8(3, 8);              // "Connection Validation" Type
ConnectionValidation.writeUInt8(0, 9);              // Compression type (always zero for validation)
ConnectionValidation.writeUInt32LE(ice_message_header_length, 10);


var stringified_message_type = function(integer) {
    switch (integer) {
        case 0: return 'request';
        case 1: return 'batch request';
        case 2: return 'reply';
        case 3: return 'validate connection';
        case 4: return 'close connection';

        default:
            throw new Error('Ice message type ' + integer + ' is not known!');
    };
};
Example #8
0
assert.ok(buf instanceof Buffer);
// For backwards compatibility of old .parent property test that if buf is not
// a slice then .parent should be undefined.
assert.equal(buf.parent, undefined);
assert.equal(buf.buffer, ab);
assert.equal(buf.length, ab.byteLength);


buf.fill(0xC);
for (let i = 0; i < LENGTH; i++) {
  assert.equal(ui[i], 0xC);
  ui[i] = 0xF;
  assert.equal(buf[i], 0xF);
}

buf.writeUInt32LE(0xF00, 0);
buf.writeUInt32BE(0xB47, 4);
buf.writeDoubleLE(3.1415, 8);

assert.equal(dv.getUint32(0, true), 0xF00);
assert.equal(dv.getUint32(4), 0xB47);
assert.equal(dv.getFloat64(8, true), 3.1415);


// Now test protecting users from doing stupid things

assert.throws(function() {
  function AB() { }
  AB.__proto__ = ArrayBuffer;
  AB.prototype.__proto__ = ArrayBuffer.prototype;
  new Buffer(new AB());
Example #9
0
NetWriter.prototype.writeUInt32LE = function (value) {
    var buffer = new Buffer(4);
    buffer.writeUInt32LE(value, 0, true);
    this.content.push(buffer);
    this.size += 4;
};
Example #10
0
var myArgs = require('minimist')(process.argv.slice(2));

var Buffer = require('buffer').Buffer;
var fs = require('fs');

if (myArgs.h === true || myArgs.help === true) {
	Usage();
	process.exit(0);
}

function Usage() {
	console.log("Usage:\r\nnode gen_wifi_fw.js --inf <input file> [--outf <output file>]");
}

var ip_file = new Buffer(fs.readFileSync(myArgs.inf), 'hex');
var op_file = myArgs.outf;

var magic = 0x57464c57;
var buf = new Buffer(8);

buf.writeUInt32LE(magic, 0, 4, 'hex');
buf.writeUInt32LE(ip_file.length, 4, 4, 'hex');

if (typeof op_file === "undefined") {
	op_file = "a.bin";
}

fs.writeFileSync(op_file, buf, 'hex');
fs.appendFileSync(op_file, ip_file, 'hex');
console.log("Generated " + op_file);