[Solved] copy hexstream in a char buffer to be sent over network [closed]


You’ve converted the binary content to a string when you copied it from Wireshark. The result is a string that represents the binary data in a hex Format.

Instead of revers the convertion you should use an appropriate methop to copy the data. Try Wireshark’s feature “follow XXX stream” and take the “C Arrays” representation, where XXX stands for TCP or UDP.

EDIT:

You can also write a function that takes a C string and converts this string to the binary data.

uint8_t GetByte(const char* pHexByte)
{
    char c = pHexByte[0];
    uint8_t Result = (c <= '9') ? c - '0' : c - '@';
    c = pHexByte[1];
    Result = (Result << 4) | (c <= '9') ? c - '0' : c - '@';
    return Result;
}

bool_t HexStringToBinary(uint8_t *pBinary, size_t BufferSize, const char*pHexString)
{
    while (pHexString[0] && pHexString[1])
    {
        uint8_t DataByte = GetByte(pHexString);

        if (!BufferSize) return FALSE;
        *pBinary++ = DataByte;
        BufferSize--;
        pHexString += 2;
    }

    return TRUE;
}

1

solved copy hexstream in a char buffer to be sent over network [closed]