Skip to content

Instantly share code, notes, and snippets.

@Konctantin
Created December 30, 2013 05:35
Show Gist options
  • Select an option

  • Save Konctantin/8178197 to your computer and use it in GitHub Desktop.

Select an option

Save Konctantin/8178197 to your computer and use it in GitHub Desktop.
static void DumpPacket(DWORD packetType, DWORD connectionId, DWORD packetOpcode, DWORD packetSize, DWORD buffer, const WORD initialReadOffset)
{
// gets the time
time_t rawTime;
time(&rawTime);
DWORD optionalHeaderLength = 0;
if (!fileDump)
{
tm* date = localtime(&rawTime);
// basic file name format:
char fileName[MAX_PATH];
// removes the DLL name from the path
PathRemoveFileSpec(dllPath);
// fills the basic file name format
_snprintf(fileName, MAX_PATH,
"%s\\wowsniff_%s_%u_%d-%02d-%02d_%02d-%02d-%02d.pkt",
dllPath, locale, buildNumber,
date->tm_year + 1900,
date->tm_mon + 1,
date->tm_mday,
date->tm_hour,
date->tm_min,
date->tm_sec);
// some info
printf("Sniff dump: %s\n\n", fileName);
WORD pkt_version = PKT_VERSION;
BYTE sniffer_id = SNIFFER_ID;
DWORD tickCount = GetTickCount();
BYTE sessionKey[40] = { 0 };
fileDump = fopen(fileName, "ab");
// PKT 3.1 header
fwrite("PKT", 3, 1, fileDump); // magic
fwrite((WORD*)&pkt_version, 2, 1, fileDump); // major.minor version
fwrite((BYTE*)&sniffer_id, 1, 1, fileDump); // sniffer id
fwrite((DWORD*)&buildNumber, 4, 1, fileDump); // client build
fwrite(locale, 4, 1, fileDump); // client lang
fwrite(sessionKey, 40,1, fileDump); // session key
fwrite((DWORD*)&rawTime, 4, 1, fileDump); // started time
fwrite((DWORD*)&tickCount, 4, 1, fileDump); // started tick's
fwrite((DWORD*)&optionalHeaderLength, 4, 1, fileDump); // opional header length
fflush(fileDump);
}
DWORD fullSize = packetSize + initialReadOffset;
fwrite((DWORD*)&packetType, 4, 1, fileDump); // direction of the packet
fwrite((DWORD*)&connectionId, 4, 1, fileDump); // connection id
fwrite((DWORD*)&rawTime, 4, 1, fileDump); // timestamp of the packet
fwrite((DWORD*)&optionalHeaderLength, 4, 1, fileDump); // connection id
fwrite((DWORD*)&fullSize, 4, 1, fileDump); // size of the packet + opcode lenght
fwrite((DWORD*)&packetOpcode, 4, 1, fileDump); // opcode
fwrite((BYTE*)(buffer + initialReadOffset), packetSize, 1, fileDump); // data
fflush(fileDump);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment