summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/CMakeLists.txt2
-rw-r--r--example/checktools/checktools.conf7
-rwxr-xr-xexample/checktools/checktools.lua68
-rw-r--r--example/checktools/test.data1
-rw-r--r--example/checktools/test.lua3
-rw-r--r--example/checktools/test1.data1
-rw-r--r--example/checktools/test1.lua2
-rw-r--r--example/luatest/CMakeLists.txt8
-rw-r--r--example/luatest/build/CMakeFiles/luatest.dir/luatest.cpp.obin55752 -> 0 bytes
-rwxr-xr-xexample/luatest/build/luatestbin51664 -> 0 bytes
-rwxr-xr-xexample/luatest/luatestbin51664 -> 45088 bytes
-rw-r--r--example/luatest/luatest.cpp9
-rw-r--r--example/luatest/pcap/qqnum.pcapbin0 -> 179126 bytes
-rw-r--r--example/luatest/script/handle_qqnum.lua55
14 files changed, 145 insertions, 11 deletions
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index 5914f69..d31b4d4 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)
project (single_thread)
project (multithread)
-link_directories("../lib")
+link_directories("/opt/MESA/lib")
link_libraries(tsglua pthread)
add_definitions(-g -W -Wall)
diff --git a/example/checktools/checktools.conf b/example/checktools/checktools.conf
new file mode 100644
index 0000000..80ca361
--- /dev/null
+++ b/example/checktools/checktools.conf
@@ -0,0 +1,7 @@
+[script]
+test.lua
+test1.lua
+
+[data]
+test.data
+test1.data
diff --git a/example/checktools/checktools.lua b/example/checktools/checktools.lua
new file mode 100755
index 0000000..be36345
--- /dev/null
+++ b/example/checktools/checktools.lua
@@ -0,0 +1,68 @@
+#!/usr/local/bin/luajit
+local flag = 0 -- 0: init;1: script;2: data
+local script_num = 0
+local script_list = {}
+local data_num = 0
+local data_list = {}
+TSG = {}
+local conf_file = "./checktools.conf"
+
+if arg[1] then
+ if arg[1] == "-h" then
+ print("usage: checktools.lua [conf] default conf is './checktools.conf'")
+ else
+ conf_file = arg[1]
+ end
+end
+
+function file_is_exit(path)
+ local file = io.open(path)
+ if not file then
+ return false
+ end
+ io.close(file)
+ return true
+end
+
+if not file_is_exit(conf_file) then
+ print("error: conf file: ".. file .." not exits.")
+ return false
+end
+
+for line in io.lines(conf_file) do
+ if string.byte(line, 1) == '#' then
+ --do nothing
+ elseif string.len(line) == 0 then
+ --do nothing
+ elseif line == "[script]" then
+ flag = 1
+ elseif line == "[data]" then
+ flag = 2
+ else
+ if flag == 1 then
+ script_num = script_num + 1
+ script_list[script_num] = line
+ elseif flag == 2 then
+ data_num = data_num + 1
+ local file = io.open(line, "r")
+ if not file then
+ print("error: ".. file .." not exits")
+ end
+ io.input(file)
+ data_list[data_num] = io.read("*a")
+ io.close(file)
+ end
+ end
+end
+
+for _, script in ipairs(script_list) do
+ if not file_is_exit(script) then
+ print("error: script: ".. script .." not exits.")
+ return false
+ end
+ for _, data in ipairs(data_list) do
+ TSG.data = data
+ dofile(script)
+ end
+end
+
diff --git a/example/checktools/test.data b/example/checktools/test.data
new file mode 100644
index 0000000..eb064cb
--- /dev/null
+++ b/example/checktools/test.data
@@ -0,0 +1 @@
+hello lua
diff --git a/example/checktools/test.lua b/example/checktools/test.lua
new file mode 100644
index 0000000..bdabc4a
--- /dev/null
+++ b/example/checktools/test.lua
@@ -0,0 +1,3 @@
+print("this is test.lua")
+local data = TSG.data
+print(data)
diff --git a/example/checktools/test1.data b/example/checktools/test1.data
new file mode 100644
index 0000000..707a908
--- /dev/null
+++ b/example/checktools/test1.data
@@ -0,0 +1 @@
+hello C
diff --git a/example/checktools/test1.lua b/example/checktools/test1.lua
new file mode 100644
index 0000000..9fc7c28
--- /dev/null
+++ b/example/checktools/test1.lua
@@ -0,0 +1,2 @@
+print("this is test1.lua")
+print(TSG.data)
diff --git a/example/luatest/CMakeLists.txt b/example/luatest/CMakeLists.txt
index 57138df..4b8186b 100644
--- a/example/luatest/CMakeLists.txt
+++ b/example/luatest/CMakeLists.txt
@@ -1,13 +1,11 @@
cmake_minimum_required(VERSION 3.5)
project (luatest)
-include_directories("/usr/local/include/gperftools")
-include_directories("../../include")
-link_directories("../../lib")
-link_libraries(tsglua pthread dl tcmalloc)
+include_directories("/opt/MESA/include")
+link_directories("/opt/MESA/lib")
+link_libraries(tsglua pthread dl)
add_definitions(-g -W -Wall -O0 -rdynamic)
add_executable(luatest luatest.cpp)
target_link_libraries(luatest pcap tsglua pthread dl)
-
diff --git a/example/luatest/build/CMakeFiles/luatest.dir/luatest.cpp.o b/example/luatest/build/CMakeFiles/luatest.dir/luatest.cpp.o
deleted file mode 100644
index 18d0654..0000000
--- a/example/luatest/build/CMakeFiles/luatest.dir/luatest.cpp.o
+++ /dev/null
Binary files differ
diff --git a/example/luatest/build/luatest b/example/luatest/build/luatest
deleted file mode 100755
index 2710e2a..0000000
--- a/example/luatest/build/luatest
+++ /dev/null
Binary files differ
diff --git a/example/luatest/luatest b/example/luatest/luatest
index 2710e2a..d6a834d 100755
--- a/example/luatest/luatest
+++ b/example/luatest/luatest
Binary files differ
diff --git a/example/luatest/luatest.cpp b/example/luatest/luatest.cpp
index 7c614a5..af63394 100644
--- a/example/luatest/luatest.cpp
+++ b/example/luatest/luatest.cpp
@@ -19,7 +19,6 @@ extern "C"
#include<sys/stat.h>
#include<dirent.h>
}
-#include<tcmalloc.h>
#include"tsg_lua_interface.h"
@@ -449,7 +448,7 @@ static void *c_file_handle(void *ptr)
char file_name[100][256];
c_text_info_t text_info;
- debuginfo = (char *)tc_malloc(10240);
+ debuginfo = (char *)malloc(10240);
if (debuginfo == NULL)
{
perror(" ");
@@ -729,7 +728,7 @@ static void *lua_file_handle(void *ptr)
struct stat s_buf;
char file_name[100][256];
- debuginfo = (char *)tc_malloc(10240);
+ debuginfo = (char *)malloc(10240);
if (debuginfo == NULL)
{
perror(" ");
@@ -932,7 +931,7 @@ int main(int argc, char *argv[])
{
printf("%s", retval);
fwrite(retval, strlen(retval), 1, log);
- tc_free(retval);
+ free(retval);
}
}
#endif
@@ -968,7 +967,7 @@ int main(int argc, char *argv[])
{
printf("%s", retval);
fwrite(retval, strlen(retval), 1, log);
- tc_free(retval);
+ free(retval);
}
}
diff --git a/example/luatest/pcap/qqnum.pcap b/example/luatest/pcap/qqnum.pcap
new file mode 100644
index 0000000..21f5e58
--- /dev/null
+++ b/example/luatest/pcap/qqnum.pcap
Binary files differ
diff --git a/example/luatest/script/handle_qqnum.lua b/example/luatest/script/handle_qqnum.lua
new file mode 100644
index 0000000..fc0d1a4
--- /dev/null
+++ b/example/luatest/script/handle_qqnum.lua
@@ -0,0 +1,55 @@
+----------------------------------------------------------------------------------------------
+-- 脚本功能:在数据中查找符合特征的qqnum --
+-- 输入: --
+-- TSG.data --
+-- 特征如下: --
+-- 特征一: --
+-- 00 00 0b db 00 00 00 0b 01 00 00 --
+-- 第1、2、5、6、7、10、11位必须为0x00,第9为必须为0x01 --
+-- 特征二: --
+-- 00 00 00 00 0d --
+-- 连续4个0x00后面紧跟一个字节的qq num 字符长度, --
+-- 该长度实际值为当前值减4,并且实际值不大于12 --
+----------------------------------------------------------------------------------------------
+local data = TSG.data --TSG.data 获取待处理数据
+local data_len = string.len(data)
+local max_qqnum_len = 12
+local locate = 1 -- 字符串中当前正在处理的位置
+
+-- 判断特征一
+if (string.byte(data, 1) ~= 0) or (string.byte(data, 2) ~= 0) or (string.byte(data, 5) ~= 0) or
+ (string.byte(data, 6) ~= 0) or (string.byte(data, 7) ~= 0) or (string.byte(data, 9) ~= 1) or
+ (string.byte(data, 10) ~= 0) or (string.byte(data, 11) ~= 0) then
+ return 1, false
+end
+
+-- 判断特征二
+-- 命中特征"\0\0\0\0"
+local _, _end = string.find(data, "\0\0\0\0")
+if not _end then
+ return 1, false
+end
+-- 获取qqnum长度
+local qqnum_len = string.byte(data, _end + 1)
+if not qqnum_len then
+ return 1,false
+end
+locate = _end + 1
+qqnum_len = qqnum_len - 4
+-- 判断qqnum长度的合法性
+if qqnum_len > 12 or qqnum_len > (data_len - locate) then
+ return 1, false
+end
+locate = locate + 1
+-- 获取qqnum
+local qqnum = string.sub(data, locate, locate + qqnum_len - 1)
+if not qqnum then
+ return 1, false
+end
+-- 验证qqnum由全数字组成
+if not tonumber(qqnum) then
+ return 1, false
+end
+
+return qqnum_len, qqnum
+