Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master in develop #144

Merged
merged 36 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a4c2cce
Merge pull request #115 from prometheus-lua/develop
levno-710 Feb 21, 2023
de54535
Update enums.lua
ccuser44 Feb 24, 2023
90e7e67
Create .editorconfig
ccuser44 Feb 24, 2023
2472efa
Merge pull request #117 from ccuser44/patch-2
levno-710 Feb 24, 2023
11e264b
Merge pull request #116 from ccuser44/patch-1
levno-710 Feb 24, 2023
f2406d2
Escape string pattern for `-`
ccuser44 Feb 24, 2023
e3a435f
Merge pull request #118 from ccuser44/patch-1
levno-710 Feb 24, 2023
7fb7c4c
Fix typo
Knicknacc Feb 26, 2023
8113e62
Merge pull request #120 from Classy-GH/fix-enum
levno-710 Feb 28, 2023
1da166f
Update util.lua
ccuser44 Mar 3, 2023
d75d764
Update util.lua
ccuser44 Mar 3, 2023
4def65a
Merge pull request #121 from ccuser44/patch-2
levno-710 Mar 4, 2023
8be88fd
Update readme.md
Robbie-Wittenhagen Mar 29, 2023
8328a82
Update AntiTamper.lua - lua 5.1.5 debug.sethook bug fix
SpinnySpiwal Mar 31, 2023
76fb1f7
Merge pull request #125 from SpinnySpiwal/patch-2
levno-710 Apr 1, 2023
c75599e
Merge pull request #124 from Robbie-Wittenhagen/patch-1
levno-710 Apr 1, 2023
dd6bf39
Update unparser.lua
levno-710 Apr 18, 2023
216b3f4
Merge pull request #128 from prometheus-lua/levno-710-patch-1
levno-710 Apr 18, 2023
b974163
Create AntiTamper.md
Brohammer5 Apr 19, 2023
8d09e0b
Update and rename AntiTamper.md to antitamper.md
Brohammer5 Apr 19, 2023
1a1f2e5
Update and rename antitamper.md to anti-tamper.md
Brohammer5 Apr 19, 2023
05c26a6
Update anti-tamper.md
Brohammer5 Apr 20, 2023
d8f43d1
Made IDEs correctly use Unix LF instead of CRLF
ccuser44 Apr 21, 2023
1e85999
Made git automatically convert to LF
ccuser44 Apr 21, 2023
0f7ae9d
Merge pull request #130 from ccuser44/patch-2
levno-710 May 1, 2023
4e812db
Merge pull request #129 from Brohammer5/patch-1
levno-710 May 1, 2023
5976191
Update SUMMARY.md
Brohammer5 May 1, 2023
a8d5217
Update using-prometheus-in-your-lua-application.md
Aws0mee May 8, 2023
e921a86
Merge pull request #135 from Aws0mee/patch-1
levno-710 May 12, 2023
3e4619e
Merge pull request #134 from Brohammer5/patch-2
levno-710 Aug 9, 2023
a8a612a
Update unparser.lua
SpinnySpiwal Aug 12, 2023
5990884
Merge pull request #141 from SpinnySpiwal/master
levno-710 Aug 14, 2023
240ba87
Optimized tokenizer.lua
NougatBitz Aug 17, 2023
aec7a3d
Update tokenizer.lua
NougatBitz Aug 17, 2023
86e80d0
Merge pull request #1 from NougatBitz/NougatBitz-edgecase-fix-1
NougatBitz Aug 17, 2023
d214646
Merge pull request #143 from NougatBitz/master
levno-710 Aug 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.lua]
indent_style = tab
indent_size = 4
end_of_line = lf
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.lua text=auto
*.lua eol=lf
2 changes: 2 additions & 0 deletions doc/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* [ProxifyLocals](steps/proxifylocals.md)
* [EncryptStrings](steps/encryptstrings.md)
* [ConstantArray](steps/constantarray.md)
* [AntiTamper](steps/anti-tamper.md)


## advanced

Expand Down
2 changes: 1 addition & 1 deletion doc/advanced/using-prometheus-in-your-lua-application.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Using Prometheus in your Lua Application

Prometheus can also be used as a library for your custom Lua Applications instead of using it's cli tool. 
Prometheus can also be used as a library for your custom Lua Applications instead of using its cli tool. 

In order to do that you'll first need to clone the github repo:

Expand Down
11 changes: 11 additions & 0 deletions doc/steps/anti-tamper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
description: This step provides an obfuscation step, that breaks the script, when someone tries to tamper with it.
---

# Anti Tamper

### Settings

| Name | type | description | values |
| ----------- | ---- | ------------------------------------------- | --------------------------------------- |
| UseDebug | boolean | Uses the debug library in lua. Disable this if you don't have access to debug library | "true","false" |
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ To perform the Prometheus Tests, just run
lua ./tests.lua
```
## Building
Prometheus can currently only be build for and on Windows.
Prometheus can currently only build on Windows.
It requires [srlua.exe](https://github.com/LuaDist/srlua) and [glue.exe](https://github.com/LuaDist/srlua) inside of the root directory. If lua51 was linked dynamically, lua51.dll must also be present. Then Prometheus for Windows can be built using
```batch
build.bat
Expand Down
10 changes: 5 additions & 5 deletions src/prometheus/enums.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Enums.Conventions = {
BinaryNumberChars = {"0", "1"},
DecimalExponent = {"e", "E"},
HexadecimalNums = {"x", "X"},
BinaryNums = false,
BinaryNums = {"b", "B"},
DecimalSeperators = false,

EscapeSequences = {
Expand All @@ -52,9 +52,9 @@ Enums.Conventions = {
["\'"] = "\'";
},
NumericalEscapes = true,
EscapeZIgnoreNextWhitespace = false,
HexEscapes = false,
UnicodeEscapes = false,
EscapeZIgnoreNextWhitespace = true,
HexEscapes = true,
UnicodeEscapes = true,
},
[Enums.LuaVersion.LuaU] = {
Keywords = {
Expand Down Expand Up @@ -103,4 +103,4 @@ Enums.Conventions = {
},
}

return Enums;
return Enums;
40 changes: 23 additions & 17 deletions src/prometheus/steps/AntiTamper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,28 @@ function AntiTamper:apply(ast, pipeline)
local string = RandomStrings.randomString();
code = code .. [[
-- Anti Beautify
local sethook = debug and debug.sethook or function() end;
local allowedLine = nil;
local called = 0;
sethook(function(s, line)
called = called + 1;
if allowedLine then
if allowedLine ~= line then
sethook(error, "l");
end
else
allowedLine = line;
end
end, "l");
(function() end)();
(function() end)();
sethook();
local sethook = debug and debug.sethook or function() end;
local allowedLine = nil;
local called = 0;
sethook(function(s, line)
if not line then
return
end
called = called + 1;
if allowedLine then
if allowedLine ~= line then
sethook(error, "l", 5);
end
else
allowedLine = line;
end
end, "l", 5);
(function() end)();
(function() end)();
sethook();
if called < 2 then
valid = false;
end
if called < 2 then
valid = false;
end
Expand Down Expand Up @@ -173,4 +179,4 @@ end
return ast;
end

return AntiTamper;
return AntiTamper;
41 changes: 35 additions & 6 deletions src/prometheus/tokenizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ Tokenizer.EOF_TOKEN = {
source = "<EOF>",
}

local function getPosition(source, i)
return source:sub(1, i):gsub("[^\n]", ""):len() + 1, i - source:sub(1, i):gsub("[^\r]", ""):len() + 1;
end

local function token(self, startPos, kind, value)
local line, linePos = getPosition(self.source, self.index);
local line, linePos = self:getPosition(self.index);
local annotations = self.annotations
self.annotations = {};
return {
Expand All @@ -65,14 +61,45 @@ local function token(self, startPos, kind, value)
end

local function generateError(self, message)
local line, linePos = getPosition(self.source, self.index);
local line, linePos = self:getPosition(self.index);
return "Lexing Error at Position " .. tostring(line) .. ":" .. tostring(linePos) .. ", " .. message;
end

local function generateWarning(token, message)
return "Warning at Position " .. tostring(token.line) .. ":" .. tostring(token.linePos) .. ", " .. message;
end

function Tokenizer:getPosition(i)
local column = self.columnMap[i]

if not column then --// `i` is bigger than self.length, this shouldnt happen, but it did. (Theres probably some error in the tokenizer, cant find it.)
column = self.columnMap[#self.columnMap]
end

return column.id, column.charMap[i]
end

--// Prepare columnMap for getPosition
function Tokenizer:prepareGetPosition()
local columnMap, column = {}, { charMap = {}, id = 1, length = 0 }

for index = 1, self.length do
local character = string.sub(self.source, index, index) -- NOTE_1: this could use table.clone to reduce amount of NEWTABLE (if that causes any performance issues)

local columnLength = column.length + 1
column.length = columnLength
column.charMap[index] = columnLength

if character == "\n" then
column = { charMap = {}, id = column.id + 1, length = 0 } -- NOTE_1
end

columnMap[index] = column
end

self.columnMap = columnMap
end

-- Constructor for Tokenizer
function Tokenizer:new(settings)
local luaVersion = (settings and (settings.luaVersion or settings.LuaVersion)) or LuaVersion.LuaU;
Expand Down Expand Up @@ -132,12 +159,14 @@ function Tokenizer:reset()
self.length = 0;
self.source = "";
self.annotations = {};
self.columnMap = {};
end

-- Append String to this Tokenizer
function Tokenizer:append(code)
self.source = self.source .. code
self.length = self.length + code:len();
self:prepareGetPosition();
end

-- Function to peek the n'th char in the source of the tokenizer
Expand Down
37 changes: 20 additions & 17 deletions src/prometheus/unparser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -383,25 +383,22 @@ function Unparser:unparseStatement(statement, tabbing)
end
end
elseif self.luaVersion == LuaVersion.LuaU then
if statement.kind == AstKind.CompoundAddStatement then
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "+=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
elseif statement.kind == AstKind.CompoundSubStatement then
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "-=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
elseif statement.kind == AstKind.CompoundMulStatement then
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "*=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
elseif statement.kind == AstKind.CompoundDivStatement then
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "/=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
elseif statement.kind == AstKind.CompoundModStatement then
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "%=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
elseif statement.kind == AstKind.CompoundPowStatement then
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "^=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
elseif statement.kind == AstKind.CompoundConcatStatement then
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "..=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
local compoundOperators = {
[AstKind.CompoundAddStatement] = "+=",
[AstKind.CompoundSubStatement] = "-=",
[AstKind.CompoundMulStatement] = "*=",
[AstKind.CompoundDivStatement] = "/=",
[AstKind.CompoundModStatement] = "%=",
[AstKind.CompoundPowStatement] = "^=",
[AstKind.CompoundConcatStatement] = "..=",
}

local operator = compoundOperators[statement.kind]
if operator then
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. operator .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing)
else
logger:error(string.format("\"%s\" is not a valid unparseable statement in %s!", statement.kind, self.luaVersion));
logger:error(string.format("\"%s\" is not a valid unparseable statement in %s!", statement.kind, self.luaVersion))
end
else
logger:error(string.format("\"%s\" is not a valid unparseable statement in %s!", statement.kind, self.luaVersion));
end

return self:tabs(tabbing, false) .. code;
Expand Down Expand Up @@ -450,6 +447,12 @@ function Unparser:unparseExpression(expression, tabbing)

if(expression.kind == AstKind.NumberExpression) then
local str = tostring(expression.value);
if(str == "inf") then
return "2e1024"
end
if(str == "-inf") then
return "-2e1024"
end
if(str:sub(1, 2) == "0.") then
str = str:sub(2);
end
Expand Down
19 changes: 15 additions & 4 deletions src/prometheus/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
local logger = require("logger");
local bit32 = require("prometheus.bit").bit32;

local MAX_UNPACK_COUNT = 195;

local function lookupify(tb)
local tb2 = {};
for _, v in ipairs(tb) do
Expand All @@ -24,7 +26,7 @@ end

local function escape(str)
return str:gsub(".", function(char)
if char:match('[^ -~\n\t\a\b\v\r\"\']') then -- Check if non Printable ASCII Character
if char:match("[^ %-~\n\t\a\b\v\r\"\']") then -- Check if non Printable ASCII Character
return string.format("\\%03d", string.byte(char))
end
if(char == "\\") then
Expand Down Expand Up @@ -222,11 +224,20 @@ local function readU32(arr)
end

local function bytesToString(arr)
local lenght = arr.n or #arr;

if lenght < MAX_UNPACK_COUNT then
return string.char(table.unpack(arr))
end

local str = "";
for i = 1, #arr do
str = str .. string.char(arr[i]);
local overflow = lenght % MAX_UNPACK_COUNT;

for i = 1, (#arr - overflow) / MAX_UNPACK_COUNT do
str = str .. string.char(table.unpack(arr, (i - 1) * MAX_UNPACK_COUNT + 1, i * MAX_UNPACK_COUNT));
end
return str;

return str..(overflow > 0 and string.char(table.unpack(arr, lenght - overflow + 1, lenght)) or "");
end

local function isNaN(n)
Expand Down
Loading