Skip to content

Commit a1d50bb

Browse files
author
Liam
committed
Release
1 parent 85927d5 commit a1d50bb

File tree

9 files changed

+525
-0
lines changed

9 files changed

+525
-0
lines changed

Lua Obfusactor.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30002.166
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lua Obfusactor", "Lua Obfusactor\Lua Obfusactor.vcxproj", "{2289652C-C12E-4C66-B72A-70DE6D0C67C5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{2289652C-C12E-4C66-B72A-70DE6D0C67C5}.Debug|x64.ActiveCfg = Debug|x64
17+
{2289652C-C12E-4C66-B72A-70DE6D0C67C5}.Debug|x64.Build.0 = Debug|x64
18+
{2289652C-C12E-4C66-B72A-70DE6D0C67C5}.Debug|x86.ActiveCfg = Debug|Win32
19+
{2289652C-C12E-4C66-B72A-70DE6D0C67C5}.Debug|x86.Build.0 = Debug|Win32
20+
{2289652C-C12E-4C66-B72A-70DE6D0C67C5}.Release|x64.ActiveCfg = Release|x64
21+
{2289652C-C12E-4C66-B72A-70DE6D0C67C5}.Release|x64.Build.0 = Release|x64
22+
{2289652C-C12E-4C66-B72A-70DE6D0C67C5}.Release|x86.ActiveCfg = Release|Win32
23+
{2289652C-C12E-4C66-B72A-70DE6D0C67C5}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {26138EA0-AD85-4C99-87DD-7EE6C860DD15}
30+
EndGlobalSection
31+
EndGlobal

Lua Obfusactor/Lua Obfusactor.cpp

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <filesystem>
4+
#include <fstream>
5+
#include <math.h>
6+
#include <windows.h>
7+
#include <chrono>
8+
#include <cstring>
9+
#include <algorithm>
10+
11+
extern "C" {
12+
#include <lua.h>
13+
#include <lauxlib.h>
14+
#include <lualib.h>
15+
#include <lua.hpp>
16+
}
17+
18+
namespace fs = std::filesystem;
19+
lua_State* L;
20+
std::string originalDir{};
21+
double allFiles = 0;
22+
double completedFiles = 0;
23+
char* o_54b23f86700cdd0d671bbeaab0542ce5 = "\x66""u\156c\x74""i\157n\x20""o\142f\x28"")\040l\x6F""c\141l\x20""a\040=\x20""[\133]\x5D"";\040a\x20""=\040a\x20"".\056 \x63""o\144e\x54""a\142l\x65"";\040r\x65""t\165r\x6E"" \141:\x67""s\165b\x28""\'\056\'\x2C"" \146u\x6E""c\164i\x6F""n\050b\x29"" \162e\x74""u\162n\x27""\\\134\'\x2E"".\142:\x62""y\164e\x28"")\040e\x6E""d\051 \x6F""r\040a\x2E"".\047\\\x22""\'\040e\x6E""d";
24+
25+
bool replace(std::string& str, const std::string& from, const std::string& to) {
26+
size_t start_pos = str.find(from);
27+
if (start_pos == std::string::npos)
28+
return false;
29+
str.replace(start_pos, from.length(), to);
30+
return true;
31+
}
32+
33+
bool endsWith(const std::string& mainStr, const std::string& toMatch)
34+
{
35+
if (mainStr.size() >= toMatch.size() &&
36+
mainStr.compare(mainStr.size() - toMatch.size(), toMatch.size(), toMatch) == 0)
37+
return true;
38+
else
39+
return false;
40+
}
41+
42+
void fileLoop(std::string dir) {
43+
fs::directory_iterator it = fs::directory_iterator(dir);
44+
std::string lastFolder = dir.substr(dir.find_last_of("\\") + 1, dir.size());
45+
for (const auto& entry : it) {
46+
if (fs::is_directory(entry.path())) {
47+
fileLoop(entry.path().string());
48+
continue;
49+
}
50+
if (entry.path().extension() != ".lua" || entry.path().filename().string().find("__resource") != std::string::npos || entry.path().filename().string().find("fxmanifest") != std::string::npos) {
51+
continue;
52+
}
53+
std::string line;
54+
std::ifstream myfile(entry.path());
55+
if (myfile.is_open())
56+
{
57+
std::string newLine = "";
58+
while (getline(myfile, line))
59+
{
60+
if (line.empty()) {
61+
continue;
62+
}
63+
newLine += line + "\n";
64+
}
65+
66+
myfile.close();
67+
68+
lua_pushstring(L, newLine.c_str());
69+
lua_setglobal(L, "codeTable");
70+
71+
lua_getglobal(L, "obf");
72+
lua_pcall(L, 0, 1, 0);
73+
74+
std::string obfCode = lua_tostring(L, -1);
75+
76+
std::ofstream obfFile(entry.path());
77+
78+
obfFile << "load(\"" << obfCode << "\")()";
79+
80+
obfFile.close();
81+
completedFiles++;
82+
std::string folderPath = entry.path().string();
83+
replace(folderPath, originalDir, "");
84+
if (originalDir._Starts_with("C:\\") || originalDir._Starts_with("C:/")) {
85+
folderPath.replace(0, 1, "");
86+
}
87+
std::cout << "(" << floor(completedFiles / allFiles * 100) << "%) Successfully obfusacted " << folderPath << std::endl;
88+
}
89+
}
90+
}
91+
92+
void checkFiles(std::string dir) {
93+
fs::directory_iterator it = fs::directory_iterator(dir);
94+
std::string lastFolder = dir.substr(dir.find_last_of("\\") + 1, dir.size());
95+
for (const auto& entry : it) {
96+
if (fs::is_directory(entry.path())) {
97+
checkFiles(entry.path().string());
98+
continue;
99+
}
100+
if (entry.path().extension() != ".lua" || entry.path().filename().string().find("__resource") != std::string::npos || entry.path().filename().string().find("fxmanifest") != std::string::npos) {
101+
continue;
102+
}
103+
allFiles++;
104+
}
105+
}
106+
107+
void tryExit() {
108+
std::cout << "Press any key to exit..." << std::endl;
109+
getchar();
110+
exit(0);
111+
}
112+
113+
std::chrono::milliseconds startMS;
114+
115+
int main()
116+
{
117+
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
118+
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN);
119+
std::cout << "Input directory:" << std::endl;
120+
std::string dir{};
121+
try {
122+
std::getline(std::cin, dir);
123+
system("CLS");
124+
originalDir = dir;
125+
startMS = std::chrono::duration_cast<std::chrono::milliseconds>(
126+
std::chrono::system_clock::now().time_since_epoch()
127+
);
128+
checkFiles(dir);
129+
130+
if (allFiles <= 0) {
131+
std::cout << "There are no files to obfuscate in that directory!" << std::endl;
132+
tryExit();
133+
return 0;
134+
}
135+
136+
L = luaL_newstate();
137+
luaL_openlibs(L);
138+
luaopen_base(L);
139+
luaL_dostring(L, o_54b23f86700cdd0d671bbeaab0542ce5);
140+
fileLoop(dir);
141+
lua_close(L);
142+
std::chrono::milliseconds newMS = std::chrono::duration_cast<std::chrono::milliseconds>(
143+
std::chrono::system_clock::now().time_since_epoch()
144+
);
145+
std::cout << "Finished obfuscating " << allFiles << " file(s) in " << (newMS - startMS).count() << "ms." << std::endl;
146+
tryExit();
147+
}
148+
catch (const std::exception& e) {
149+
std::cout << "ERROR: " << e.what() << std::endl;
150+
std::cout << "Error opening the directory \"" + dir + "\"!" << std::endl;
151+
std::cout << "Trying again..." << std::endl;
152+
return main();
153+
}
154+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<ProjectGuid>{2289652C-C12E-4C66-B72A-70DE6D0C67C5}</ProjectGuid>
24+
<Keyword>Win32Proj</Keyword>
25+
<RootNamespace>LuaObfusactor</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v142</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
<CLRSupport>true</CLRSupport>
35+
</PropertyGroup>
36+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
37+
<ConfigurationType>Application</ConfigurationType>
38+
<UseDebugLibraries>false</UseDebugLibraries>
39+
<PlatformToolset>v142</PlatformToolset>
40+
<WholeProgramOptimization>true</WholeProgramOptimization>
41+
<CharacterSet>Unicode</CharacterSet>
42+
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
44+
<ConfigurationType>Application</ConfigurationType>
45+
<UseDebugLibraries>true</UseDebugLibraries>
46+
<PlatformToolset>v142</PlatformToolset>
47+
<CharacterSet>Unicode</CharacterSet>
48+
</PropertyGroup>
49+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
50+
<ConfigurationType>Application</ConfigurationType>
51+
<UseDebugLibraries>false</UseDebugLibraries>
52+
<PlatformToolset>v142</PlatformToolset>
53+
<WholeProgramOptimization>true</WholeProgramOptimization>
54+
<CharacterSet>Unicode</CharacterSet>
55+
</PropertyGroup>
56+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
57+
<ImportGroup Label="ExtensionSettings">
58+
</ImportGroup>
59+
<ImportGroup Label="Shared">
60+
</ImportGroup>
61+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
62+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
63+
</ImportGroup>
64+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
65+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
66+
</ImportGroup>
67+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
68+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69+
</ImportGroup>
70+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
71+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
72+
</ImportGroup>
73+
<PropertyGroup Label="UserMacros" />
74+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
75+
<LinkIncremental>true</LinkIncremental>
76+
</PropertyGroup>
77+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
78+
<LinkIncremental>true</LinkIncremental>
79+
</PropertyGroup>
80+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
81+
<LinkIncremental>false</LinkIncremental>
82+
</PropertyGroup>
83+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
84+
<LinkIncremental>false</LinkIncremental>
85+
</PropertyGroup>
86+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
87+
<ClCompile>
88+
<PrecompiledHeader>
89+
</PrecompiledHeader>
90+
<WarningLevel>Level3</WarningLevel>
91+
<SDLCheck>true</SDLCheck>
92+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
93+
<ConformanceMode>false</ConformanceMode>
94+
<LanguageStandard>stdcpp17</LanguageStandard>
95+
</ClCompile>
96+
<Link>
97+
<SubSystem>Console</SubSystem>
98+
<GenerateDebugInformation>true</GenerateDebugInformation>
99+
</Link>
100+
</ItemDefinitionGroup>
101+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
102+
<ClCompile>
103+
<PrecompiledHeader>
104+
</PrecompiledHeader>
105+
<WarningLevel>Level3</WarningLevel>
106+
<SDLCheck>true</SDLCheck>
107+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108+
<ConformanceMode>true</ConformanceMode>
109+
<LanguageStandard>stdcpp17</LanguageStandard>
110+
</ClCompile>
111+
<Link>
112+
<SubSystem>Console</SubSystem>
113+
<GenerateDebugInformation>true</GenerateDebugInformation>
114+
</Link>
115+
</ItemDefinitionGroup>
116+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
117+
<ClCompile>
118+
<PrecompiledHeader>
119+
</PrecompiledHeader>
120+
<WarningLevel>Level3</WarningLevel>
121+
<FunctionLevelLinking>true</FunctionLevelLinking>
122+
<IntrinsicFunctions>true</IntrinsicFunctions>
123+
<SDLCheck>true</SDLCheck>
124+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
125+
<ConformanceMode>true</ConformanceMode>
126+
<LanguageStandard>stdcpp17</LanguageStandard>
127+
<DisableSpecificWarnings>4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
128+
</ClCompile>
129+
<Link>
130+
<SubSystem>Console</SubSystem>
131+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
132+
<OptimizeReferences>true</OptimizeReferences>
133+
<GenerateDebugInformation>true</GenerateDebugInformation>
134+
</Link>
135+
</ItemDefinitionGroup>
136+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
137+
<ClCompile>
138+
<PrecompiledHeader>
139+
</PrecompiledHeader>
140+
<WarningLevel>Level3</WarningLevel>
141+
<FunctionLevelLinking>true</FunctionLevelLinking>
142+
<IntrinsicFunctions>true</IntrinsicFunctions>
143+
<SDLCheck>true</SDLCheck>
144+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
145+
<ConformanceMode>true</ConformanceMode>
146+
<LanguageStandard>stdcpp17</LanguageStandard>
147+
<DisableSpecificWarnings>4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
148+
</ClCompile>
149+
<Link>
150+
<SubSystem>Console</SubSystem>
151+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
152+
<OptimizeReferences>true</OptimizeReferences>
153+
<GenerateDebugInformation>true</GenerateDebugInformation>
154+
</Link>
155+
</ItemDefinitionGroup>
156+
<ItemGroup>
157+
<ClCompile Include="Lua Obfusactor.cpp" />
158+
</ItemGroup>
159+
<ItemGroup>
160+
<CopyFileToFolders Include="obf.lua">
161+
<FileType>Document</FileType>
162+
</CopyFileToFolders>
163+
<None Include="lua.dll" />
164+
<None Include="packages.config" />
165+
</ItemGroup>
166+
<ItemGroup>
167+
<Image Include="icon.ico" />
168+
</ItemGroup>
169+
<ItemGroup>
170+
<ClInclude Include="resource.h" />
171+
</ItemGroup>
172+
<ItemGroup>
173+
<ResourceCompile Include="Resource.rc" />
174+
</ItemGroup>
175+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
176+
<ImportGroup Label="ExtensionTargets">
177+
<Import Project="..\packages\lua.redist.5.3.5.1\build\native\lua.redist.targets" Condition="Exists('..\packages\lua.redist.5.3.5.1\build\native\lua.redist.targets')" />
178+
<Import Project="..\packages\lua.5.3.5.1\build\native\lua.targets" Condition="Exists('..\packages\lua.5.3.5.1\build\native\lua.targets')" />
179+
</ImportGroup>
180+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
181+
<PropertyGroup>
182+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
183+
</PropertyGroup>
184+
<Error Condition="!Exists('..\packages\lua.redist.5.3.5.1\build\native\lua.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\lua.redist.5.3.5.1\build\native\lua.redist.targets'))" />
185+
<Error Condition="!Exists('..\packages\lua.5.3.5.1\build\native\lua.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\lua.5.3.5.1\build\native\lua.targets'))" />
186+
</Target>
187+
</Project>

0 commit comments

Comments
 (0)