http://prntscr.com/2ctnozC++ WSAsend包的奇怪的十六進制轉儲
我鉤住WSAsend功能和傾倒的數據包。 ASCII轉儲工作,但十六進制轉儲有時顯示的東西,你可以看到在屏幕上(FFFFFFDD),任何想法爲什麼?
代碼:
int WINAPI myWSASend(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesSent, DWORD dwFlags, LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
//Packet Log
if (bLogPacketS == TRUE)
{
for (unsigned int i = 0; i < lpBuffers->len; i = i + 8)
{
printf("%02X %02X %02X %02X %02X %02X %02X %02X\t\t%c %c %c %c %c %c %c %c\n",
(unsigned int)lpBuffers->buf[i], (unsigned int)lpBuffers->buf[i+1], (unsigned int)lpBuffers->buf[i+2],
(unsigned int)lpBuffers->buf[i+3], (unsigned int)lpBuffers->buf[i+4], (unsigned int)lpBuffers->buf[i+5],
(unsigned int)lpBuffers->buf[i+6], (unsigned int)lpBuffers->buf[i+7],
(drawable((unsigned int)lpBuffers->buf[i])) ? (unsigned int)lpBuffers->buf[i] : '.',
(drawable((unsigned int)lpBuffers->buf[i+1])) ? (unsigned int)lpBuffers->buf[i+1] : '.',
(drawable((unsigned int)lpBuffers->buf[i+2])) ? (unsigned int)lpBuffers->buf[i+2] : '.',
(drawable((unsigned int)lpBuffers->buf[i+3])) ? (unsigned int)lpBuffers->buf[i+3] : '.',
(drawable((unsigned int)lpBuffers->buf[i+4])) ? (unsigned int)lpBuffers->buf[i+4] : '.',
(drawable((unsigned int)lpBuffers->buf[i+5])) ? (unsigned int)lpBuffers->buf[i+5] : '.',
(drawable((unsigned int)lpBuffers->buf[i+6])) ? (unsigned int)lpBuffers->buf[i+6] : '.',
(drawable((unsigned int)lpBuffers->buf[i+7])) ? (unsigned int)lpBuffers->buf[i+7] : '.');
}
printf("\n\n");
}
return (oWSASend)(s, lpBuffers, dwBufferCount, lpNumberOfBytesSent, dwFlags, lpOverlapped, lpCompletionRoutine);
}
bool drawable(unsigned int value)
{
if (value > 32 && value < 127)
return true;
else
return false;
}
是否有某種'年度printf'比賽正在進行? –
如果是這樣,我可能會贏,我知道它不是最好的辦法,但我不能想到更好的方式 – LemoniscooL
@MartinJames:這不是*那*壞... –