Unescaper C++ library for KISS special characters
kiss-unescaper replaces special characters in KISS protocol with the original data.
C0 | → | (delete) |
DB DC | → | C0 |
DB DD | → | DB |
-
before
F8 F9 C0 C0 00 01 DB DC 10 11 DB DD 13 14 C0 C0 FA FB
-
after
F8 F9 00 01 C0 10 11 DB 13 14 FA FB
All you have to do is call unescape
method.
This method accepts input of a binary file or an array of some packets,
then writes unescaped data to buf
, and returns the size of buf
as a result.
-
Unescape a binary file.
-
address of pointer to unescaped data
(unescaped data is written here) -
a binary file to be unescaped
size of unescaped data [byte]
-
-
Unescape an array of some packets.
-
address of pointer to unescaped data
(unescaped data is written here) -
an array to be unescaped
-
size of the packets [byte]
size of unescaped data [byte]
-
#include "../KissUnescaper.h"
using namespace std;
int main()
{
KissUnescaper unescaper;
/**
* Unescape a binary file
*/
FILE *fp = fopen("test.log", "rb"); // raw file (mode must be "rb")
unsigned char *data = NULL;
unsigned data_size;
data_size = unescaper.unescape(&data, fp);
fclose(fp);
// print unescaped data
for (int i = 0; i < data_size; i++)
{
cout << uppercase << hex << int(data[i]) << " ";
}
cout << endl
<< endl;
/**
* Unescape an array of some packets
*/
unsigned char packets[] = {0xC0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0xC0}; // raw packets
unsigned char *data2 = NULL;
unsigned data_size2;
data_size2 = unescaper.unescape(&data2, packets, sizeof(packets));
// print unescaped data
for (int i = 0; i < data_size2; i++)
{
cout << uppercase << hex << int(data2[i]) << " ";
}
cout << endl;
return 0;
}