pull/105/head
ApexLiu 2017-10-29 18:22:15 +08:00
parent 8019bf8be3
commit 3d2754799f
4 changed files with 30 additions and 19 deletions

View File

@ -25,10 +25,10 @@
//======================================================= //=======================================================
// ΤΆ³ΜΑ¬½ΣΧΣΠ­<CEA0>ι // ΤΆ³ΜΑ¬½ΣΧΣΠ­<CEA0>ι
//======================================================= //=======================================================
#define TP_PROTOCOL_SUB_TYPE_RDP 100 #define TP_PROTOCOL_TYPE_RDP_DESKTOP 100
#define TP_PROTOCOL_SUB_TYPE_SSH 200 #define TP_PROTOCOL_TYPE_SSH_SHELL 200
#define TP_PROTOCOL_SUB_TYPE_SFTP 201 #define TP_PROTOCOL_TYPE_SSH_SFTP 201
#define TP_PROTOCOL_SUB_TYPE_TELNET 300 #define TP_PROTOCOL_TYPE_TELNET_SHELL 300
//======================================================= //=======================================================

View File

@ -51,7 +51,7 @@ typedef struct TS_RECORD_HEADER_BASIC
// RDP专有 // RDP专有
ex_u8 rdp_security; // 0 = RDP, 1 = TLS ex_u8 rdp_security; // 0 = RDP, 1 = TLS
ex_u8 _reserve[512 - 4 - 2 - 2 - 2 - 8 - 2 - 2 - 64 - 64 - 40 - 2 - 40 - 40 - 1 - ts_record_header_info_size]; ex_u8 _reserve[512 - 2 - 2 - 8 - 2 - 2 - 64 - 64 - 40 - 40 - 2 - 40 - 1 - ts_record_header_info_size];
}TS_RECORD_HEADER_BASIC; }TS_RECORD_HEADER_BASIC;
#define ts_record_header_basic_size sizeof(TS_RECORD_HEADER_BASIC) #define ts_record_header_basic_size sizeof(TS_RECORD_HEADER_BASIC)

View File

@ -14,6 +14,8 @@ TppSshRec::TppSshRec()
m_file_info = NULL; m_file_info = NULL;
m_file_data = NULL; m_file_data = NULL;
m_file_cmd = NULL; m_file_cmd = NULL;
m_save_full_header = false;
} }
TppSshRec::~TppSshRec() TppSshRec::~TppSshRec()
@ -25,7 +27,7 @@ bool TppSshRec::_on_begin(const TPP_CONNECT_INFO* info)
{ {
if (NULL == info) if (NULL == info)
return false; return false;
m_head.basic.timestamp = m_start_time;//(ex_u64)time(NULL); m_head.basic.timestamp = (ex_u64)time(NULL);
m_head.basic.protocol_type = (ex_u16)info->protocol_type; m_head.basic.protocol_type = (ex_u16)info->protocol_type;
m_head.basic.protocol_sub_type = (ex_u16)info->protocol_sub_type; m_head.basic.protocol_sub_type = (ex_u16)info->protocol_sub_type;
m_head.basic.conn_port = (ex_u16)info->conn_port; m_head.basic.conn_port = (ex_u16)info->conn_port;
@ -87,8 +89,6 @@ void TppSshRec::record(ex_u8 type, const ex_u8* data, size_t size)
{ {
if (data == NULL || 0 == size) if (data == NULL || 0 == size)
return; return;
m_head.info.packages++;
m_head.info.time_ms = (ex_u32)(m_last_time - m_start_time);
if (sizeof(TS_RECORD_PKG) + size + m_cache.size() > m_cache.buffer_size()) if (sizeof(TS_RECORD_PKG) + size + m_cache.size() > m_cache.buffer_size())
_save_to_data_file(); _save_to_data_file();
@ -102,8 +102,12 @@ void TppSshRec::record(ex_u8 type, const ex_u8* data, size_t size)
{ {
m_last_time = ex_get_tick_count(); m_last_time = ex_get_tick_count();
pkg.time_ms = (ex_u32)(m_last_time - m_start_time); pkg.time_ms = (ex_u32)(m_last_time - m_start_time);
m_head.info.time_ms = pkg.time_ms;
} }
m_head.info.packages++;
m_cache.append((ex_u8*)&pkg, sizeof(TS_RECORD_PKG)); m_cache.append((ex_u8*)&pkg, sizeof(TS_RECORD_PKG));
m_cache.append(data, size); m_cache.append(data, size);
} }
@ -112,6 +116,7 @@ void TppSshRec::record_win_size_startup(int width, int height)
{ {
m_head.basic.width = (ex_u16)width; m_head.basic.width = (ex_u16)width;
m_head.basic.height = (ex_u16)height; m_head.basic.height = (ex_u16)height;
m_save_full_header = true;
} }
void TppSshRec::record_win_size_change(int width, int height) void TppSshRec::record_win_size_change(int width, int height)
@ -163,7 +168,7 @@ bool TppSshRec::_save_to_data_file()
} }
// first time to save header, write whole header. // first time to save header, write whole header.
fwrite(&m_head, ts_record_header_size, 1, m_file_info); m_save_full_header = true;
} }
if(m_file_data == NULL) { if(m_file_data == NULL) {
@ -196,17 +201,21 @@ bool TppSshRec::_save_to_data_file()
// return false; // return false;
// } // }
ex_u32 size = (ex_u32)m_cache.size(); if(m_cache.size() > 0) {
fwrite(&size, sizeof(ex_u32), 1, m_file_data); fwrite(m_cache.data(), m_cache.size(), 1, m_file_data);
fwrite(m_cache.data(), m_cache.size(), 1, m_file_data); fflush(m_file_data);
// fflush(f); }
// fclose(f);
fseek(m_file_info, 0L, SEEK_SET); fseek(m_file_info, 0L, SEEK_SET);
fwrite(&m_head.info, ts_record_header_info_size, 1, m_file_info); if(m_save_full_header) {
fwrite(&m_head, ts_record_header_size, 1, m_file_info);
//m_head.file_count++; fflush(m_file_info);
//m_head.file_size += m_cache.size(); m_save_full_header = false;
} else {
fwrite(&m_head.info, ts_record_header_info_size, 1, m_file_info);
fflush(m_file_info);
}
m_cache.empty(); m_cache.empty();
return true; return true;
@ -240,7 +249,7 @@ bool TppSshRec::_save_to_cmd_file()
// } // }
fwrite(m_cmd_cache.data(), m_cmd_cache.size(), 1, m_file_cmd); fwrite(m_cmd_cache.data(), m_cmd_cache.size(), 1, m_file_cmd);
// fflush(f); fflush(m_file_cmd);
// fclose(f); // fclose(f);
m_cmd_cache.empty(); m_cmd_cache.empty();

View File

@ -70,6 +70,8 @@ protected:
MemBuffer m_cmd_cache; MemBuffer m_cmd_cache;
bool m_save_full_header;
FILE* m_file_info; FILE* m_file_info;
FILE* m_file_data; FILE* m_file_data;
FILE* m_file_cmd; FILE* m_file_cmd;