diff options
| author | pengxuanzheng <[email protected]> | 2020-09-11 14:14:08 +0800 |
|---|---|---|
| committer | pengxuanzheng <[email protected]> | 2020-09-11 14:14:08 +0800 |
| commit | c442fb51354754a029799b2efb26e016e9375d95 (patch) | |
| tree | 1d1c011e82829be3c7f70fd199ab067e0430b8bc | |
| parent | c267f5b51a7014dcd95112cc53a11182b44b5936 (diff) | |
Develop 09.09
| -rw-r--r-- | CMakeLists.txt | 4 | ||||
| -rw-r--r-- | cmake/Package.cmake | 4 | ||||
| -rw-r--r-- | example/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | example/checktools/checktools.conf | 7 | ||||
| -rwxr-xr-x | example/checktools/checktools.lua | 68 | ||||
| -rw-r--r-- | example/checktools/test.data | 1 | ||||
| -rw-r--r-- | example/checktools/test.lua | 3 | ||||
| -rw-r--r-- | example/checktools/test1.data | 1 | ||||
| -rw-r--r-- | example/checktools/test1.lua | 2 | ||||
| -rw-r--r-- | example/luatest/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | example/luatest/build/CMakeFiles/luatest.dir/luatest.cpp.o | bin | 55752 -> 0 bytes | |||
| -rwxr-xr-x | example/luatest/build/luatest | bin | 51664 -> 0 bytes | |||
| -rwxr-xr-x | example/luatest/luatest | bin | 51664 -> 45088 bytes | |||
| -rw-r--r-- | example/luatest/luatest.cpp | 9 | ||||
| -rw-r--r-- | example/luatest/pcap/qqnum.pcap | bin | 0 -> 179126 bytes | |||
| -rw-r--r-- | example/luatest/script/handle_qqnum.lua | 55 | ||||
| -rw-r--r-- | gtest/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | support/CMakeLists.txt | 4 |
19 files changed, 155 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 49a428e..4a2b043 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,10 +12,12 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") set(CMAKE_INSTALL_PREFIX /opt/MESA) +set(LUAJIT_INSTALL_PREFIX /usr/local) add_subdirectory(support) add_subdirectory(src) install(FILES ./src/tsg_lua_interface.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER) +install(PROGRAMS ./example/checktools/checktools.lua DESTINATION ${LUAJIT_INSTALL_PREFIX}/bin) -include(Package)
\ No newline at end of file +include(Package) diff --git a/cmake/Package.cmake b/cmake/Package.cmake index 3f2c8aa..f809415 100644 --- a/cmake/Package.cmake +++ b/cmake/Package.cmake @@ -14,8 +14,8 @@ set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILD}") execute_process(COMMAND bash -c "echo -ne \"`uname -r | awk -F'.' '{print $5\".\"$6\".\"$7}'`\"" OUTPUT_VARIABLE SYSTEM_VERSION) -execute_process(COMMAND sh changelog.sh WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/cmake) -SET(CPACK_RPM_CHANGELOG_FILE ${PROJECT_SOURCE_DIR}/cmake/changelog.txt) +#execute_process(COMMAND sh changelog.sh WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/cmake) +#SET(CPACK_RPM_CHANGELOG_FILE ${PROJECT_SOURCE_DIR}/cmake/changelog.txt) # RPM Build set(CPACK_GENERATOR "RPM") 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 Binary files differdeleted file mode 100644 index 18d0654..0000000 --- a/example/luatest/build/CMakeFiles/luatest.dir/luatest.cpp.o +++ /dev/null diff --git a/example/luatest/build/luatest b/example/luatest/build/luatest Binary files differdeleted file mode 100755 index 2710e2a..0000000 --- a/example/luatest/build/luatest +++ /dev/null diff --git a/example/luatest/luatest b/example/luatest/luatest Binary files differindex 2710e2a..d6a834d 100755 --- a/example/luatest/luatest +++ b/example/luatest/luatest 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 Binary files differnew file mode 100644 index 0000000..21f5e58 --- /dev/null +++ b/example/luatest/pcap/qqnum.pcap 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 + diff --git a/gtest/CMakeLists.txt b/gtest/CMakeLists.txt index 04d924b..7d04559 100644 --- a/gtest/CMakeLists.txt +++ b/gtest/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 2.6) project(gtest_tsg_lua) aux_source_directory(. SRCS) -include_directories("../include") -link_directories("../lib") +include_directories("/opt/MESA/include") +link_directories("/opt/MESA/lib") link_libraries(tsglua gtest gtest_main pthread) add_definitions(-g -W -Wall) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5f01ca5..3dd3177 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.5) SET(CMAKE_CXX_COMPILER /usr/bin/g++) aux_source_directory(. DIR_LIB_SRCS) -include_directories("${CMAKE_CURRENT_BINARY_DIR}/../support/install/include/luajit-2.1") +include_directories("${LUAJIT_INSTALL_PREFIX}/include/luajit-2.1") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -shared -fPIC") SET(CMAKE_CXX_DEBUG_FLAGS "${CMAKE_CXX_DEBUG_FLAGS} -DTSG_LUA_DEBUG") diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index 5f8a8ee..7363e67 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -4,7 +4,7 @@ set(LUAJIT2_ROOT ${CMAKE_CURRENT_BINARY_DIR}) set(LUAJIT2_URL ${CMAKE_CURRENT_SOURCE_DIR}/luajit2-2.1-agentzh.zip) set(LUAJIT2_URL_MD5 6e17cd2263473f9b85b47d0736cf12da) set(LUAJIT2_MAKE cd ${LUAJIT2_ROOT}/luajit2/src/luajit2 && make) -set(LUAJIT2_INSTALL cd ${LUAJIT2_ROOT}/luajit2/src/luajit2 && make install PREFIX=${LUAJIT2_ROOT}/install) +set(LUAJIT2_INSTALL cd ${LUAJIT2_ROOT}/luajit2/src/luajit2 && make install PREFIX=${LUAJIT_INSTALL_PREFIX}) ExternalProject_Add(luajit2 PREFIX luajit2 @@ -20,5 +20,5 @@ ExternalProject_Add(luajit2 add_library(luajit2-static STATIC IMPORTED GLOBAL) add_dependencies(luajit2-static luajit2) -set_property(TARGET luajit2-static PROPERTY IMPORTED_LOCATION ${LUAJIT2_ROOT}/install/lib/libluajit-5.1.a) +set_property(TARGET luajit2-static PROPERTY IMPORTED_LOCATION ${LUAJIT_INSTALL_PREFIX}/lib/libluajit-5.1.a) |
