62 lines
1.4 KiB
Lua
62 lines
1.4 KiB
Lua
require("sensitive_words_list")
|
|
|
|
function read(filename)
|
|
|
|
local file = io.open(filename)
|
|
if file then
|
|
local content = file:read("*a")
|
|
file:close()
|
|
return content
|
|
end
|
|
end
|
|
|
|
function split(str, delimiter)
|
|
local result = {}
|
|
if str == nil then
|
|
return str
|
|
end
|
|
|
|
local pos = 1
|
|
while true do
|
|
local next_pos = str:find(delimiter, pos)
|
|
if not next_pos then
|
|
table.insert(result, str:sub(pos))
|
|
break
|
|
end
|
|
table.insert(result, str:sub(pos, next_pos - 1))
|
|
pos = next_pos + 1
|
|
end
|
|
return result
|
|
end
|
|
|
|
-- 读取Protobuf文件
|
|
local proto_file = "proto_google/client_msg.proto"
|
|
local proto_data = assert(read(proto_file), "Failed to read proto file")
|
|
|
|
-- 检查文件中是否存在敏感词
|
|
local line_numbers = {}
|
|
local lines = split(proto_data, "\n")
|
|
|
|
for i = 1, #lines do
|
|
local line = lines[i]
|
|
for _, word in ipairs(data_sensitive_words) do
|
|
local pos = line:find(word, 1, true)
|
|
if pos then
|
|
local prev_char = pos > 1 and line:sub(pos - 1, pos - 1) or ""
|
|
local next_char = line:sub(pos + #word, pos + #word)
|
|
if (prev_char == "_" or prev_char == "") and (next_char == "_" or next_char == "") then
|
|
table.insert(line_numbers, {i, word, line})
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
-- 输出结果
|
|
if #line_numbers > 0 then
|
|
print("Sensitive words found in the following lines:")
|
|
for _, line_number in ipairs(line_numbers) do
|
|
print(line_number[1], line_number[2], line_number[3])
|
|
end
|
|
else
|
|
print("No sensitive words found in the proto file.")
|
|
end |