Changelog
13 December 2005: Work began.
13 December 2005: Added DWORD creation.
14 December 2005: Added removal functions.
14 December 2005: Made numerous two-second bugfixes due to stupid things I forgot.
To-do
Remove WORD / DWORD.
Test.
Example - Creating SID_AUTH_INFO
insert_int32(0);
insert_void("68XIRATS");
insert_int32(0xCD);
insert_int32(0);
insert_int32(0);
insert_int32(0);
insert_int32(0);
insert_int32(0);
insert_string("CAN");
insert_string("Canada");
$data = return_bncs(0x50);
The Code~
<?
/*
* PHP Packet Buffer
*
* Module: pbuffer.php
* Author: Joe LaFrance
* Purpose: Constructing BNCS packets.
*
* Copyright (C) 2005 Joe LaFrance
*/
$buffer = "";
// This is where we'll construct the packet
function clear() {
$buffer = "";
}
/*
* Create packets
*/
/* Attaches the BNCS header to a string of data */
function return_bncs($packetID) {
return chr(0xFF) . chr($packetID) . make_int16(strlen($buffer)) . $data;
clear();
}
/* Insert an NTString, also just called a string */
function insert_string($data) {
$buffer = $buffer . $data . chr(0);
}
/* Appends a void, also known as NonNTString */
function insert_void($data) {
$buffer = $buffer . $data;
}
/* Appends a little endian 8-bit integer (BYTE) */
function insert_int8($data) {
$buffer = $buffer . chr($data);
}
/* Appends a little endian 16-bit integer (WORD) */
function insert_int16($data) {
$buffer = $buffer . make_int16($data);
}
/* Append a little endian 32-bit integer (DWORD) */
function insert_int32($data) {
$buffer = $buffer . make_int32($data);
}
/*
* Packet "debuffer" functions
*/
/* Set the buffer data */
function setbuffer($data) {
clear();
$buffer = $data;
}
/* Remove the header */
function remove_header() {
return substr($buffer, 0, 4);
$buffer = substr($buffer, 4);
}
/* Remove a null terminated string */
function remove_string() {
$ntpos = strpos ($buffer, chr(0));
$ret = substr($buffer, 0, $ntpos);
$buffer = substr(strstr($buffer, chr(0)), 1);
return $ret;
}
/* Remove a void of length $len */
function remove_void($len) {
$ret = substr($buffer, 0, $len);
$buffer = substr($buffer, $len+1);
return $ret;
}
/* Remove a 8-bit little endian integer (BYTE) */
function remove_int8() {
$ret = (int)substr($buffer, 0, 1);
$buffer = substr($buffer, 1);
}
/* Remove a 16-bit little endian integer (WORD) */
function remove_int16() {
// stub
}
/* Remove a 32-bit little endian integer (WORD) */
function remove_int32() {
// stub
}
/*
* Create integral data structures
*/
/* Create a little-endian 16-bit integer (WORD) */
function make_int16($data) {
$A = $data % (256 ^ 1);
$B = $data + $a;
return chr($A) . chr($B);
}
/* Create a little-endian 32-bit integer (DWORD) */
function make_int32($data) {
$A = $data % (256 ^ 3);
$B = $data % (256 ^ 2);
$C = $data % (256 ^ 1);
$D = $data - ($A + $B + $C);
return chr($A) . chr($B) . chr($C) . chr($D);
}
/* Parse a little-endian 16-bit integer (WORD) */
function get_int16() {
// stub
}
/* Parse a little-endian 32-bit integer (DWORD) */
function get_int32() {
// stub
}
?>