Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ctype

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ctype - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

ctf.js

180

ctio.js

@@ -67,6 +67,20 @@ /*

*/
function ruint16(buffer, endian, offset)
function rgint16(buffer, endian, offset)
{
var val = 0;
if (endian == 'big') {
val = buffer[offset] << 8;
val |= buffer[offset+1];
} else {
val = buffer[offset];
val |= buffer[offset+1] << 8;
}
return (val);
}
function ruint16(buffer, endian, offset)
{
if (endian === undefined)

@@ -84,11 +98,3 @@ throw (new Error('missing endian'));

if (endian == 'big') {
val = buffer[offset] << 8;
val |= buffer[offset+1];
} else {
val = buffer[offset];
val |= buffer[offset+1] << 8;
}
return (val);
return (rgint16(buffer, endian, offset));
}

@@ -107,9 +113,19 @@

*/
function rgint32(buffer, endian, offset)
{
var val = 0;
/*
* Handle the case of losing our MSBit
*/
function fixu32(upper, lower)
{
return ((upper * (1 << 24)) + lower);
if (endian == 'big') {
val = buffer[offset+1] << 16;
val |= buffer[offset+2] << 8;
val |= buffer[offset+3];
val = val + (buffer[offset] << 24 >>> 0);
} else {
val = buffer[offset+2] << 16;
val |= buffer[offset+1] << 8;
val |= buffer[offset];
val = val + (buffer[offset + 3] << 24 >>> 0);
}
return (val);
}

@@ -119,4 +135,2 @@

{
var val = 0;
if (endian === undefined)

@@ -134,15 +148,3 @@ throw (new Error('missing endian'));

if (endian == 'big') {
val = buffer[offset+1] << 16;
val |= buffer[offset+2] << 8;
val |= buffer[offset+3];
val = fixu32(buffer[offset], val);
} else {
val = buffer[offset+2] << 16;
val |= buffer[offset+1] << 8;
val |= buffer[offset];
val = fixu32(buffer[offset+3], val);
}
return (val);
return (rgint32(buffer, endian, offset));
}

@@ -166,6 +168,19 @@

*/
function ruint64(buffer, endian, offset)
function rgint64(buffer, endian, offset)
{
var val = new Array(2);
if (endian == 'big') {
val[0] = ruint32(buffer, endian, offset);
val[1] = ruint32(buffer, endian, offset+4);
} else {
val[0] = ruint32(buffer, endian, offset+4);
val[1] = ruint32(buffer, endian, offset);
}
return (val);
}
function ruint64(buffer, endian, offset)
{
if (endian === undefined)

@@ -183,11 +198,3 @@ throw (new Error('missing endian'));

if (endian == 'big') {
val[0] = ruint32(buffer, endian, offset);
val[1] = ruint32(buffer, endian, offset+4);
} else {
val[0] = ruint32(buffer, endian, offset+4);
val[1] = ruint32(buffer, endian, offset);
}
return (val);
return (rgint64(buffer, endian, offset));
}

@@ -294,3 +301,3 @@

val = ruint16(buffer, endian, offset);
val = rgint16(buffer, endian, offset);
neg = val & 0x8000;

@@ -327,3 +334,3 @@ if (!neg)

val = ruint32(buffer, endian, offset);
val = rgint32(buffer, endian, offset);
neg = val & 0x80000000;

@@ -356,3 +363,3 @@ if (!neg)

val = ruint64(buffer, endian, offset);
val = rgint64(buffer, endian, offset);
neg = val[0] & 0x80000000;

@@ -710,2 +717,13 @@

*/
function wgint16(val, endian, buffer, offset)
{
if (endian == 'big') {
buffer[offset] = (val & 0xff00) >>> 8;
buffer[offset+1] = val & 0x00ff;
} else {
buffer[offset+1] = (val & 0xff00) >>> 8;
buffer[offset] = val & 0x00ff;
}
}
function wuint16(value, endian, buffer, offset)

@@ -731,9 +749,3 @@ {

val = prepuint(value, 0xffff);
if (endian == 'big') {
buffer[offset] = (val & 0xff00) >>> 8;
buffer[offset+1] = val & 0x00ff;
} else {
buffer[offset+1] = (val & 0xff00) >>> 8;
buffer[offset] = val & 0x00ff;
}
wgint16(val, endian, buffer, offset);
}

@@ -752,2 +764,18 @@

*/
function wgint32(val, endian, buffer, offset)
{
if (endian == 'big') {
buffer[offset] = (val - (val & 0x00ffffff)) / Math.pow(2, 24);
buffer[offset+1] = (val >>> 16) & 0xff;
buffer[offset+2] = (val >>> 8) & 0xff;
buffer[offset+3] = val & 0xff;
} else {
buffer[offset+3] = (val - (val & 0x00ffffff)) /
Math.pow(2, 24);
buffer[offset+2] = (val >>> 16) & 0xff;
buffer[offset+1] = (val >>> 8) & 0xff;
buffer[offset] = val & 0xff;
}
}
function wuint32(value, endian, buffer, offset)

@@ -773,14 +801,3 @@ {

val = prepuint(value, 0xffffffff);
if (endian == 'big') {
buffer[offset] = (val - (val & 0x00ffffff)) / Math.pow(2, 24);
buffer[offset+1] = (val >>> 16) & 0xff;
buffer[offset+2] = (val >>> 8) & 0xff;
buffer[offset+3] = val & 0xff;
} else {
buffer[offset+3] = (val - (val & 0x00ffffff)) /
Math.pow(2, 24);
buffer[offset+2] = (val >>> 16) & 0xff;
buffer[offset+1] = (val >>> 8) & 0xff;
buffer[offset] = val & 0xff;
}
wgint32(val, endian, buffer, offset);
}

@@ -793,2 +810,13 @@

*/
function wgint64(value, endian, buffer, offset)
{
if (endian == 'big') {
wgint32(value[0], endian, buffer, offset);
wgint32(value[1], endian, buffer, offset+4);
} else {
wgint32(value[0], endian, buffer, offset+4);
wgint32(value[1], endian, buffer, offset);
}
}
function wuint64(value, endian, buffer, offset)

@@ -819,10 +847,3 @@ {

prepuint(value[1], 0xffffffff);
if (endian == 'big') {
wuint32(value[0], endian, buffer, offset);
wuint32(value[1], endian, buffer, offset+4);
} else {
wuint32(value[0], endian, buffer, offset+4);
wuint32(value[1], endian, buffer, offset);
}
wgint64(value, endian, buffer, offset);
}

@@ -948,5 +969,5 @@

if (val >= 0)
wuint16(val, endian, buffer, offset);
wgint16(val, endian, buffer, offset);
else
wuint16(0xffff + val + 1, endian, buffer, offset);
wgint16(0xffff + val + 1, endian, buffer, offset);

@@ -980,5 +1001,5 @@ }

if (val >= 0)
wuint32(val, endian, buffer, offset);
wgint32(val, endian, buffer, offset);
else
wuint32(0xffffffff + val + 1, endian, buffer, offset);
wgint32(0xffffffff + val + 1, endian, buffer, offset);
}

@@ -1031,10 +1052,3 @@

}
if (endian == 'big') {
wuint32(vals[0], endian, buffer, offset);
wuint32(vals[1], endian, buffer, offset+4);
} else {
wuint32(vals[0], endian, buffer, offset+4);
wuint32(vals[1], endian, buffer, offset);
}
wgint64(vals, endian, buffer, offset);
}

@@ -1041,0 +1055,0 @@

@@ -37,2 +37,3 @@ /*

var mod_ctf = require('./ctf.js');
var mod_ctio = require('./ctio.js');

@@ -283,3 +284,3 @@ var ASSERT = require('assert');

var ii, jj;
var req, keys, key, exists;
var req, keys, key;
var found = {};

@@ -321,3 +322,2 @@

if (isNaN(parseInt(key['len'], 10))) {
exists = false;
if (!(key['len'] in found))

@@ -823,2 +823,10 @@ throw (new Error('Given an array ' +

function parseCTF(json, conf)
{
var ctype = new CTypeParser(conf);
mod_ctf.ctfParseJson(json, ctype);
return (ctype);
}
/*

@@ -832,2 +840,4 @@ * Export the few things we actually want to. Currently this is just the CType

exports.parseCTF = parseCTF;
exports.ruint8 = mod_ctio.ruint8;

@@ -834,0 +844,0 @@ exports.ruint16 = mod_ctio.ruint16;

{
"name": "ctype",
"version": "0.1.0",
"version": "0.2.0",
"description": "read and write binary structures and data types",
"homepage": "https://github.com/rmustacc/node-ctype",
"author": "Robert Mustacchi <rm@fingolfin.org>",
"engines": { "node": "0.4" },
"engines": { "node": "0.4 || 0.5" },
"main": "ctype.js"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc