Overview of byte_func.inc

Public Variable Summary

Public variables are intended to be accessed by the code that imports this library.

Name Summary
BYTE_ORDER

Public Function Summary

Public functions are intended to be called by the code that imports this library.

Name Summary
dec2bin
getdword
getword
mkdword
mkpad
mkword
set_byte_order

Public Variable Details

BYTE_ORDER

top

Public Function Details

dec2bin

Named Parameters

dec

Code

function dec2bin(dec) {

  local_var dnum, res;

  dnum = int(dec);

  if(dnum == 0)
    return dnum;

  while (dnum > 0) {
    res = string(dnum & 1) + res;
    dnum = dnum >>= 1;
  }

  while(strlen(res) < 8) {
    res = string(0) + res;
  }

  return res;

}



		
top

getdword

Named Parameters

blob
pos

Code

function getdword(blob,pos) {
 local_var value,DATA;

 if( ! pos ) pos = 0;

 if(!blob = substr(blob,pos))return 0;

 if (BYTE_ORDER == BYTE_ORDER_BIG_ENDIAN) {
  DATA = ord(blob[0]) << 24 | ord(blob[1]) << 16 | ord(blob[2]) << 8 | ord(blob[3]);
 }  else {
  DATA = ord(blob[0]) | ord(blob[1]) << 8 | ord(blob[2]) << 16 | ord(blob[3]) << 24;
 }
return DATA;
}

function dec2bin(dec) {

		
top

getword

Named Parameters

blob
pos

Code

function getword(blob,pos) {
 local_var value,DATA;

 if( ! pos ) pos = 0;

 if(!blob = substr(blob,pos))return 0;

 if(BYTE_ORDER == BYTE_ORDER_BIG_ENDIAN) {
  DATA = ord(blob[0]) << 8 | ord(blob[1]);
 } else {
  DATA = ord(blob[0]) | ord(blob[1]) << 8;
 }
 return DATA;
}

function getdword(blob,pos) {

		
top

mkdword

Named Parameters

Code

function mkdword() {
 local_var value,DATA;

 if(isnull(_FCT_ANON_ARGS[0])) {
  return 0;
 }

 value = _FCT_ANON_ARGS[0];

 if(BYTE_ORDER == BYTE_ORDER_BIG_ENDIAN) {
    DATA =  raw_string((value >> 24) & 255, (value >> 16) & 255, (value >>  8) & 255, (value) & 255);
 } else {
    DATA =  raw_string(value & 255, (value >> 8) & 255, (value >> 16) & 255, (value >> 24) & 255);
 }
 return DATA;
}

function mkpad() {

		
top

mkpad

Named Parameters

Code

function mkpad() {
 local_var length,DATA;
 if(isnull(_FCT_ANON_ARGS[0])) {
  length = 1000;
 } else {
  length = _FCT_ANON_ARGS[0];
 }
 DATA = crap(data:raw_string(0x00), length:length);
 return DATA;
}

function getword(blob,pos) {

		
top

mkword

Named Parameters

Code

function mkword() {
  local_var value,DATA;

  if(isnull(_FCT_ANON_ARGS[0])) {
     return 0;
  }
  value = _FCT_ANON_ARGS[0];
  if (BYTE_ORDER == BYTE_ORDER_BIG_ENDIAN) {
    DATA = raw_string((value >> 8) & 255, value & 255);
  } else {
    DATA = raw_string(value & 255, (value >> 8) & 255);
  }  
 return DATA;
}

function set_byte_order() {

		
top

set_byte_order

Named Parameters

Code

function set_byte_order() {
  if(!isnull(_FCT_ANON_ARGS[0])) {
    if(_FCT_ANON_ARGS[0] == BYTE_ORDER_BIG_ENDIAN || _FCT_ANON_ARGS[0] == BYTE_ORDER_LITTLE_ENDIAN) {
      BYTE_ORDER = _FCT_ANON_ARGS[0];
    }  
  }   
}

function mkdword() {

		
top