Skip to content

Commit c69a787

Browse files
committed
Fix for string.char hook
1 parent 98f156f commit c69a787

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/prometheus/steps/EncryptStrings.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,29 @@ function EncryptStrings:CreateEncrypionService()
103103
local code = [[
104104
do
105105
local floor = math.floor
106+
local random = math.random;
107+
local remove = table.remove;
108+
local char = string.char;
106109
local param_mul_8 = ]] .. tostring(param_mul_8) .. [[
107110
local param_mul_45 = ]] .. tostring(param_mul_45) .. [[
108111
local param_add_45 = ]] .. tostring(param_add_45) .. [[
109112
local state_45 = 0
110113
local state_8 = 2
114+
local digits = {}
115+
local charmap = {};
116+
local i = 0;
117+
118+
local nums = {};
119+
for i = 1, 256 do
120+
nums[i] = i;
121+
end
122+
123+
repeat
124+
local idx = random(1, #nums);
125+
local n = remove(nums, idx);
126+
charmap[n] = char(n - 1);
127+
until #nums == 0;
128+
111129
local prev_values = {}
112130
local function get_next_pseudo_random_byte()
113131
if #prev_values == 0 then
@@ -145,7 +163,7 @@ do
145163
local len = string.len(str);
146164
local out = "";
147165
for i=1, len do
148-
out = out .. string.char((string.byte(str, i) - get_next_pseudo_random_byte()) % 256);
166+
out = out .. charmap[(string.byte(str, i) - get_next_pseudo_random_byte()) % 256 + 1];
149167
end
150168
realStrings[seed] = out;
151169
return seed;

0 commit comments

Comments
 (0)