!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 

uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/usr/libexec/netdata/node.d/node_modules/lib/ber/   drwxr-xr-x
Free 12.97 GB of 57.97 GB (22.38%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     reader.js (5.36 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
// SPDX-License-Identifier: MIT

var assert = require('assert');

var ASN1 = require('./types');
var errors = require('./errors');


///--- Globals

var InvalidAsn1Error = errors.InvalidAsn1Error;



///--- API

function Reader(data) {
	if (!data || !Buffer.isBuffer(data))
		throw new TypeError('data must be a node Buffer');

	this._buf = data;
	this._size = data.length;

	// These hold the "current" state
	this._len = 0;
	this._offset = 0;
}

Object.defineProperty(Reader.prototype, 'length', {
	enumerable: true,
	get: function () { return (this._len); }
});

Object.defineProperty(Reader.prototype, 'offset', {
	enumerable: true,
	get: function () { return (this._offset); }
});

Object.defineProperty(Reader.prototype, 'remain', {
	get: function () { return (this._size - this._offset); }
});

Object.defineProperty(Reader.prototype, 'buffer', {
	get: function () { return (this._buf.slice(this._offset)); }
});


/**
 * Reads a single byte and advances offset; you can pass in `true` to make this
 * a "peek" operation (i.e., get the byte, but don't advance the offset).
 *
 * @param {Boolean} peek true means don't move offset.
 * @return {Number} the next byte, null if not enough data.
 */
Reader.prototype.readByte = function(peek) {
	if (this._size - this._offset < 1)
		return null;

	var b = this._buf[this._offset] & 0xff;

	if (!peek)
		this._offset += 1;

	return b;
};


Reader.prototype.peek = function() {
	return this.readByte(true);
};


/**
 * Reads a (potentially) variable length off the BER buffer.  This call is
 * not really meant to be called directly, as callers have to manipulate
 * the internal buffer afterwards.
 *
 * As a result of this call, you can call `Reader.length`, until the
 * next thing called that does a readLength.
 *
 * @return {Number} the amount of offset to advance the buffer.
 * @throws {InvalidAsn1Error} on bad ASN.1
 */
Reader.prototype.readLength = function(offset) {
	if (offset === undefined)
		offset = this._offset;

	if (offset >= this._size)
		return null;

	var lenB = this._buf[offset++] & 0xff;
	if (lenB === null)
		return null;

	if ((lenB & 0x80) == 0x80) {
		lenB &= 0x7f;

		if (lenB == 0)
			throw InvalidAsn1Error('Indefinite length not supported');

		if (lenB > 4)
			throw InvalidAsn1Error('encoding too long');

		if (this._size - offset < lenB)
			return null;

		this._len = 0;
		for (var i = 0; i < lenB; i++)
			this._len = (this._len << 8) + (this._buf[offset++] & 0xff);

	} else {
		// Wasn't a variable length
		this._len = lenB;
	}

	return offset;
};


/**
 * Parses the next sequence in this BER buffer.
 *
 * To get the length of the sequence, call `Reader.length`.
 *
 * @return {Number} the sequence's tag.
 */
Reader.prototype.readSequence = function(tag) {
	var seq = this.peek();
	if (seq === null)
		return null;
	if (tag !== undefined && tag !== seq)
		throw InvalidAsn1Error('Expected 0x' + tag.toString(16) +
															': got 0x' + seq.toString(16));

	var o = this.readLength(this._offset + 1); // stored in `length`
	if (o === null)
		return null;

	this._offset = o;
	return seq;
};


Reader.prototype.readInt = function(tag) {
	if (typeof(tag) !== 'number')
		tag = ASN1.Integer;

	return this._readTag(ASN1.Integer);
};


Reader.prototype.readBoolean = function(tag) {
	if (typeof(tag) !== 'number')
		tag = ASN1.Boolean;

	return (this._readTag(tag) === 0 ? false : true);
};


Reader.prototype.readEnumeration = function(tag) {
	if (typeof(tag) !== 'number')
		tag = ASN1.Enumeration;

	return this._readTag(ASN1.Enumeration);
};


Reader.prototype.readString = function(tag, retbuf) {
	if (!tag)
		tag = ASN1.OctetString;

	var b = this.peek();
	if (b === null)
		return null;

	if (b !== tag)
		throw InvalidAsn1Error('Expected 0x' + tag.toString(16) +
															': got 0x' + b.toString(16));

	var o = this.readLength(this._offset + 1); // stored in `length`

	if (o === null)
		return null;

	if (this.length > this._size - o)
		return null;

	this._offset = o;

	if (this.length === 0)
		return retbuf ? new Buffer(0) : '';

	var str = this._buf.slice(this._offset, this._offset + this.length);
	this._offset += this.length;

	return retbuf ? str : str.toString('utf8');
};

Reader.prototype.readOID = function(tag) {
	if (!tag)
		tag = ASN1.OID;

	var b = this.readString(tag, true);
	if (b === null)
		return null;

	var values = [];
	var value = 0;

	for (var i = 0; i < b.length; i++) {
		var byte = b[i] & 0xff;

		value <<= 7;
		value += byte & 0x7f;
		if ((byte & 0x80) == 0) {
			values.push(value >>> 0);
			value = 0;
		}
	}

	value = values.shift();
	values.unshift(value % 40);
	values.unshift((value / 40) >> 0);

	return values.join('.');
};


Reader.prototype._readTag = function(tag) {
	assert.ok(tag !== undefined);

	var b = this.peek();

	if (b === null)
		return null;

	if (b !== tag)
		throw InvalidAsn1Error('Expected 0x' + tag.toString(16) +
															': got 0x' + b.toString(16));

	var o = this.readLength(this._offset + 1); // stored in `length`
	if (o === null)
		return null;

	if (this.length > 4)
		throw InvalidAsn1Error('Integer too long: ' + this.length);

	if (this.length > this._size - o)
		return null;
	this._offset = o;

	var fb = this._buf[this._offset];
	var value = 0;

	for (var i = 0; i < this.length; i++) {
		value <<= 8;
		value |= (this._buf[this._offset++] & 0xff);
	}

	if ((fb & 0x80) == 0x80 && i !== 4)
		value -= (1 << (i * 8));

	return value >> 0;
};



///--- Exported API

module.exports = Reader;

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0055 ]--