├── .gitignore ├── CMakeLists.txt ├── Include ├── ClangParsing │ ├── ASTConsumer.cpp │ ├── ASTConsumer.h │ ├── ASTFrontendAction.cpp │ ├── ASTFrontendAction.h │ ├── ASTVisitorGlobal.cpp │ ├── ASTVisitorGlobal.h │ ├── ASTVisitorLocal.cpp │ ├── ASTVisitorLocal.h │ ├── CommandLineOptions.cpp │ ├── CommandLineOptions.h │ ├── GlobalDecls.cpp │ ├── GlobalDecls.h │ └── Helpers │ │ ├── FunctionData.cpp │ │ ├── FunctionData.h │ │ ├── Script.cpp │ │ ├── Script.h │ │ ├── StaticData.cpp │ │ └── StaticData.h ├── Compiler │ ├── BuildTarget.h │ ├── Compiler.cpp │ ├── Compiler.h │ ├── Opcode.cpp │ ├── Opcode.h │ └── OpcodeConsts.h ├── Compression │ ├── SourceAnnotations.H │ ├── sal.h │ ├── xcompress.h │ ├── zconf.h │ └── zlib.h ├── Crypto │ ├── aes256.c │ └── aes256.h ├── Utils │ ├── ClangUtils.cpp │ ├── ClangUtils.h │ ├── ConsoleColor.h │ ├── ConstExpr.h │ ├── Utils.cpp │ ├── Utils.h │ └── rapidxml │ │ ├── license.txt │ │ ├── rapidxml.hpp │ │ ├── rapidxml_iterators.hpp │ │ ├── rapidxml_print.hpp │ │ └── rapidxml_utils.hpp └── Version │ └── Version.h ├── README.md ├── SC-CL.cpp ├── bin ├── Debug │ └── show_help.bat ├── Release │ ├── PC_Natives.bin │ ├── xcompress32.dll │ └── zlib1.dll ├── include │ ├── GTAIV │ │ ├── consts32.h │ │ ├── natives32.h │ │ └── natives32Old.h │ ├── GTAV │ │ ├── consts32.h │ │ ├── consts64.h │ │ ├── constsShared.h │ │ ├── natives32.h │ │ └── natives64.h │ ├── RDR │ │ ├── consts32.h │ │ └── natives32.h │ ├── common.c │ ├── common.h │ ├── constants.h │ ├── intrinsics.h │ ├── natives.h │ ├── types.h │ └── varargs.h └── projects │ ├── MenuBase │ ├── Include │ │ ├── Menu Internals │ │ │ ├── ItemExecution.c │ │ │ ├── ItemExecution.h │ │ │ ├── MenuExecutionHandling.c │ │ │ ├── MenuExecutionHandling.h │ │ │ ├── MenuUiHandling.c │ │ │ └── MenuUiHandling.h │ │ └── Utilities │ │ │ ├── Memory.c │ │ │ ├── Memory.h │ │ │ ├── Utils.c │ │ │ └── Utils.h │ ├── MenuBase.c │ ├── MenuBase.sln │ ├── MenuBase.vcxproj │ ├── MenuBase.vcxproj.filters │ └── MenuBase.vcxproj.user │ ├── printfTest.c │ └── testing │ ├── compile.bat │ ├── funcs.c │ ├── inc.c │ ├── inc.h │ ├── rdr2_test.c │ ├── test.VC.db │ ├── test.c │ ├── test.sln │ ├── test.vcxproj │ ├── test.vcxproj.filters │ └── test.vcxproj.user ├── contributors.txt └── lib ├── xcompress64.lib └── zlibstatic.lib /.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | !BuildTarget.h 4 | !CMakeLists.txt 5 | !Include/ 6 | !lib/ 7 | !xcompress64.lib 8 | !zlibstatic.lib 9 | !Compiler/ 10 | !Crypto/ 11 | !Compression/ 12 | !ASM Compiler/ 13 | !Utils/ 14 | !ClangParsing/ 15 | !Helpers/ 16 | !Version/ 17 | !Version.h 18 | !zconf.h 19 | !zlib.h 20 | !sal.h 21 | !SourceAnnotations.H 22 | !xcompress.h 23 | !aes256.h 24 | !aes256.c 25 | !ConsoleColor.h 26 | !contributors.txt 27 | !ASTConsumer.cpp 28 | !ASTConsumer.h 29 | !ASTFrontendAction.cpp 30 | !ASTFrontendAction.h 31 | !ASTVisitorGlobal.cpp 32 | !ASTVisitorGlobal.h 33 | !ASTVisitorLocal.cpp 34 | !ASTVisitorLocal.h 35 | !CommandLineOptions.cpp 36 | !CommandLineOptions.h 37 | !GlobalDecls.cpp 38 | !GlobalDecls.h 39 | !FunctionData.cpp 40 | !FunctionData.h 41 | !Opcode.h 42 | !Opcode.cpp 43 | !SC-CL.cpp 44 | !rapidxml/ 45 | !rapidxml.hpp 46 | !rapidxml_iterators.hpp 47 | !rapidxml_print.hpp 48 | !rapidxml_utils.hpp 49 | !license.txt 50 | !Utils.cpp 51 | !Utils.h 52 | !ClangUtils.cpp 53 | !ClangUtils.h 54 | !Compiler.cpp 55 | !Compiler.h 56 | !ConstExpr.h 57 | !OpcodeConsts.h 58 | !Script.h 59 | !Script.cpp 60 | !StaticData.h 61 | !StaticData.cpp 62 | !bin/ 63 | !Debug/ 64 | !include/ 65 | !Release/ 66 | !projects/ 67 | !testing/ 68 | !MenuBase/ 69 | !Menu Internals/ 70 | !Utilities/ 71 | !RDR/ 72 | !GTAV/ 73 | !GTAIV/ 74 | !*.c 75 | !*.h 76 | ASM Compiler/XscCompilerRaw (RDR)/obj/ 77 | ASM Compiler/XscCompilerRaw (RDR)/bin/ 78 | ASM Compiler/XscCompilerRaw/bin/ 79 | ASM Compiler/XscCompilerRaw/obj/New Text Document.txt 80 | bin/Debug/*.exe 81 | bin/Debug/*.ilk 82 | bin/projects/*/*.xsc 83 | bin/projects/*/*.sco 84 | bin/projects/*/*.newsco 85 | bin/projects/*/*.xsa* 86 | bin/projects/*/*.csc 87 | bin/projects/*/*.ysc 88 | bin/projects/*/*.csa* 89 | bin/projects/*/*.sca* 90 | bin/projects/*/*.ysa* 91 | bin/projects/MenuBase/Debug 92 | bin/projects/MenuBase/GTAV 93 | bin/projects/MenuBase/Release 94 | bin/projects/MenuBase/*.bat 95 | bin/projects/MenuBase/*.db 96 | bin/projects/MenuBase/*.opendb 97 | bin/projects/MenuBase/*.TMP 98 | *.exe 99 | /bin/projects/Network Protection 100 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20.4) 2 | 3 | set(LLVM_LINK_COMPONENTS support) 4 | set(LLVM_USED_LIBS clangTooling clangBasic clangAST) 5 | 6 | set(CMAKE_CXX_STANDARD 20) 7 | 8 | set(source_list 9 | "Include/ClangParsing/ASTConsumer.cpp" 10 | "Include/ClangParsing/ASTFrontendAction.cpp" 11 | "Include/ClangParsing/ASTVisitorGlobal.cpp" 12 | "Include/ClangParsing/ASTVisitorLocal.cpp" 13 | "Include/ClangParsing/CommandLineOptions.cpp" 14 | "Include/ClangParsing/GlobalDecls.cpp" 15 | "Include/ClangParsing/Helpers/FunctionData.cpp" 16 | "Include/ClangParsing/Helpers/Script.cpp" 17 | "Include/ClangParsing/Helpers/StaticData.cpp" 18 | "Include/Utils/Utils.cpp" 19 | "Include/Utils/ClangUtils.cpp" 20 | "Include/Compiler/Compiler.cpp" 21 | "Include/Compiler/Opcode.cpp" 22 | "Include/Crypto/aes256.c" 23 | ) 24 | 25 | set(header_list 26 | "Include/ClangParsing/ASTConsumer.h" 27 | "Include/ClangParsing/ASTFrontendAction.h" 28 | "Include/ClangParsing/ASTVisitorGlobal.h" 29 | "Include/ClangParsing/ASTVisitorLocal.h" 30 | "Include/ClangParsing/CommandLineOptions.h" 31 | "Include/ClangParsing/GlobalDecls.h" 32 | "Include/ClangParsing/Helpers/FunctionData.h" 33 | "Include/ClangParsing/Helpers/Script.h" 34 | "Include/ClangParsing/Helpers/StaticData.h" 35 | "Include/Compiler/BuildTarget.h" 36 | "Include/Compiler/Compiler.h" 37 | "Include/Compiler/Opcode.h" 38 | "Include/Compiler/OpcodeConsts.h" 39 | "Include/Compression/zconf.h" 40 | "Include/Compression/zlib.h" 41 | "Include/Compression/sal.h" 42 | "Include/Compression/SourceAnnotations.H" 43 | "Include/Compression/xcompress.h" 44 | "Include/Crypto/aes256.h" 45 | "Include/Utils/ClangUtils.h" 46 | "Include/Utils/ConsoleColor.h" 47 | "Include/Utils/ConstExpr.h" 48 | "Include/Utils/Utils.h" 49 | "Include/Utils/rapidxml/rapidxml.hpp" 50 | "Include/Utils/rapidxml/rapidxml_iterators.hpp" 51 | "Include/Utils/rapidxml/rapidxml_print.hpp" 52 | "Include/Utils/rapidxml/rapidxml_utils.hpp" 53 | ) 54 | 55 | set(resource_list 56 | "CMakeLists.txt" 57 | ".gitignore" 58 | "contributors.txt" 59 | ) 60 | 61 | link_directories(lib) 62 | 63 | add_clang_executable(SC-CL 64 | SC-CL.cpp 65 | ${source_list} 66 | ${header_list} 67 | ) 68 | 69 | 70 | 71 | include_directories(Include) 72 | 73 | target_link_libraries(SC-CL 74 | PUBLIC clangTooling 75 | PUBLIC clangBasic 76 | PUBLIC clangASTMatchers 77 | PUBLIC zlibstatic 78 | PUBLIC legacy_stdio_definitions 79 | PUBLIC xcompress64 80 | ) 81 | 82 | foreach(source IN LISTS source_list) 83 | get_filename_component(source_path "${source}" PATH) 84 | string(REPLACE "Include" "Source Files" source_path_temp "${source_path}") 85 | string(REPLACE "/" "\\" source_path_msvc "${source_path_temp}") 86 | source_group("${source_path_msvc}" FILES "${source}") 87 | endforeach() 88 | 89 | foreach(header IN LISTS header_list) 90 | get_filename_component(header_path "${header}" PATH) 91 | string(REPLACE "Include" "Header Files" header_path_temp "${header_path}") 92 | string(REPLACE "/" "\\" header_path_msvc "${header_path_temp}") 93 | source_group("${header_path_msvc}" FILES "${header}") 94 | endforeach() 95 | 96 | foreach(resource IN LISTS resource_list) 97 | get_filename_component(resource_path "${resource}" PATH) 98 | source_group("Resource Files\\${resource_path}" FILES "${resource}") 99 | endforeach() 100 | -------------------------------------------------------------------------------- /Include/ClangParsing/ASTConsumer.cpp: -------------------------------------------------------------------------------- 1 | #include "ClangParsing/ASTConsumer.h" 2 | 3 | using namespace clang; 4 | 5 | bool SCCL::ASTConsumer::HandleTopLevelDecl(DeclGroupRef DR) 6 | { 7 | for (Decl* decl : DR) 8 | { 9 | // Traverse the declaration using our AST visitor. 10 | GlobalVisitor.TraverseDecl(decl); 11 | } 12 | 13 | for (Decl* decl : DR) 14 | { 15 | // Traverse the declaration using our AST visitor. 16 | LocalVisitor.TraverseDecl(decl); 17 | } 18 | 19 | return true; 20 | } -------------------------------------------------------------------------------- /Include/ClangParsing/ASTConsumer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Utils/ClangUtils.h" 3 | #include "clang/Lex/PreProcessor.h" 4 | #include "stdint.h" 5 | #include "ClangParsing/GlobalDecls.h" 6 | #include "ClangParsing/ASTVisitorGlobal.h" 7 | #include "ClangParsing/ASTVisitorLocal.h" 8 | 9 | namespace SCCL 10 | { 11 | class ASTConsumer : public clang::ASTConsumer 12 | { 13 | public: 14 | ASTConsumer(clang::Rewriter &R, const clang::ASTContext &context, Script& scriptData) : LocalVisitor(R, context, scriptData), GlobalVisitor(R, context, scriptData) 15 | { 16 | 17 | } 18 | 19 | // Override the method that gets called for each parsed top-level 20 | // declaration. 21 | bool HandleTopLevelDecl(clang::DeclGroupRef DR) override; 22 | 23 | private: 24 | ASTVisitorLocal LocalVisitor; 25 | ASTVisitorGlobal GlobalVisitor; 26 | }; 27 | } -------------------------------------------------------------------------------- /Include/ClangParsing/ASTFrontendAction.cpp: -------------------------------------------------------------------------------- 1 | #include "ClangParsing\ASTFrontendAction.h" 2 | #include "Version\Version.h" 3 | #include "ClangParsing\ASTConsumer.h" 4 | 5 | using namespace std; 6 | using namespace clang; 7 | 8 | void SCCL::ASTFrontendAction::AddDefines(Preprocessor &PP) 9 | { 10 | string preDefines = PP.getPredefines(); 11 | 12 | int major = 0, minor = 0, revision = 0, patchlevel = 0; 13 | sscanf(VERSION, "%d.%d.%d.%d", &major, &minor, &revision, &patchlevel); 14 | preDefines += "\n#define __SCCL_major__ " + to_string(major); 15 | preDefines += "\n#define __SCCL_minor__ " + to_string(minor); 16 | preDefines += "\n#define __SCCL_revision__ " + to_string(revision); 17 | preDefines += "\n#define __SCCL_patchlevel__ " + to_string(patchlevel); 18 | 19 | preDefines += 20 | "\n#define __SCCL__ 1" 21 | 22 | "\n#define ENDIAN_BIG 0" 23 | "\n#define ENDIAN_LITTLE 1" 24 | 25 | "\n#define PLATFORM_X360 0" 26 | "\n#define PLATFORM_PS3 1" 27 | "\n#define PLATFORM_PC 2" 28 | 29 | "\n#define TARGET_GTAIV 0" 30 | "\n#define TARGET_GTAV 1" 31 | "\n#define TARGET_RDR 2" 32 | 33 | "\n#define FILETYPE_XSC 0" 34 | "\n#define FILETYPE_YSC 1" 35 | "\n#define FILETYPE_CSC 2" 36 | "\n#define FILETYPE_SCO 3" 37 | 38 | "\n#define SUBTARGET_TBOGT 0" 39 | "\n#define SUBTARGET_TLAD 1"; 40 | 41 | switch (scriptData->getBuildPlatform()) 42 | { 43 | case P_XBOX: 44 | preDefines += 45 | "\n#define PLATFORM PLATFORM_X360" 46 | "\n#define ENDIAN ENDIAN_BIG"; 47 | break; 48 | case P_PSX: 49 | preDefines += 50 | "\n#define PLATFORM PLATFORM_PS3" 51 | "\n#define ENDIAN ENDIAN_BIG"; 52 | break; 53 | case P_PC: 54 | preDefines += 55 | "\n#define PLATFORM PLATFORM_PC" 56 | "\n#define ENDIAN ENDIAN_LITTLE"; 57 | break; 58 | } 59 | switch (scriptData->getBuildType()) 60 | { 61 | case BT_GTAIV_TLAD: 62 | preDefines += 63 | "\n#define SUBTARGET SUBTARGET_TLAD" 64 | "\n#define TARGET TARGET_GTAIV" 65 | "\n#define FILETYPE FILETYPE_SCO" 66 | "\n#define PTRWIDTH 32"; 67 | break; 68 | case BT_GTAIV_TBOGT: 69 | preDefines += 70 | "\n#define SUBTARGET SUBTARGET_TBOGT"; 71 | case BT_GTAIV: 72 | preDefines += 73 | "\n#define TARGET TARGET_GTAIV" 74 | "\n#define FILETYPE FILETYPE_SCO" 75 | "\n#define PTRWIDTH 32"; 76 | break; 77 | case BT_RDR_XSC: 78 | preDefines += 79 | "\n#define TARGET TARGET_RDR" 80 | "\n#define PTRWIDTH 32" 81 | "\n#define FILETYPE FILETYPE_" + scriptData->getPlatformAbvUpper() + string("SC"); 82 | break; 83 | case BT_RDR_SCO: 84 | preDefines += 85 | "\n#define TARGET TARGET_RDR" 86 | "\n#define PTRWIDTH 32" 87 | "\n#define FILETYPE FILETYPE_SCO"; 88 | break; 89 | case BT_GTAV: 90 | preDefines += 91 | "\n#define TARGET TARGET_GTAV" 92 | "\n#define FILETYPE FILETYPE_" + scriptData->getPlatformAbvUpper() + string("SC"); 93 | if (scriptData->getBuildPlatform() == P_PC) 94 | preDefines += "\n#define PTRWIDTH 64"; 95 | else 96 | preDefines += "\n#define PTRWIDTH 32"; 97 | 98 | break; 99 | 100 | case BT_RDR2: 101 | preDefines += 102 | "\n#define TARGET TARGET_RDR2" 103 | "\n#define FILETYPE FILETYPE_" + scriptData->getPlatformAbvUpper() + string("SC"); 104 | preDefines += "\n#define PTRWIDTH 64"; 105 | 106 | break; 107 | } 108 | preDefines += "\n#undef _MSC_VER"; 109 | 110 | PP.setPredefines(preDefines.data()); 111 | } 112 | 113 | void SCCL::ASTFrontendAction::ModifyClangWarnings(DiagnosticsEngine& DE) 114 | { 115 | #define DisableClangWarning(str) DE.setSeverityForGroup(diag::Flavor::WarningOrError, str, diag::Severity::Ignored, SourceLocation()); 116 | #define ElevateClangWarning(str) DE.setSeverityForGroup(diag::Flavor::WarningOrError, str, diag::Severity::Error, SourceLocation()); 117 | 118 | DisableClangWarning("main-return-type"); 119 | DisableClangWarning("incompatible-library-redeclaration"); 120 | DisableClangWarning("microsoft-enum-value");//this allows enums to be in hex without : unsigned int tag 121 | ElevateClangWarning("return-type"); 122 | ElevateClangWarning("dangling-else"); 123 | 124 | #undef DisableClangWarning 125 | #undef ElevateClangWarning 126 | } 127 | 128 | std::unique_ptr SCCL::ASTFrontendAction::CreateASTConsumer(CompilerInstance &CI, StringRef file) 129 | { 130 | llvm::errs() << "Compiling: " << file << "\n"; 131 | 132 | diagnostics = &CI.getDiagnostics(); 133 | CI.getLangOpts().Freestanding = true; 134 | 135 | TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); 136 | rewriter = &TheRewriter; 137 | 138 | 139 | //const SourceManager &SM = TheRewriter.getSourceMgr(); 140 | //string fileName(string(SM.getFileEntryForID(SM.getMainFileID())->getName())); 141 | 142 | //is CompilerInstance constant? if so these can be done once instead of being applied every file 143 | ModifyClangWarnings(*diagnostics); 144 | AddDefines(CI.getPreprocessor()); 145 | 146 | 147 | return std::make_unique(TheRewriter, CI.getASTContext(), *scriptData); 148 | } 149 | -------------------------------------------------------------------------------- /Include/ClangParsing/ASTFrontendAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Utils/ClangUtils.h" 3 | #include "clang/Lex/Preprocessor.h" 4 | #include "stdint.h" 5 | #include "ClangParsing/GlobalDecls.h" 6 | 7 | namespace SCCL 8 | { 9 | class ASTFrontendAction : public clang::ASTFrontendAction 10 | { 11 | public: 12 | 13 | ASTFrontendAction() 14 | { 15 | CurrentFileId++; 16 | } 17 | 18 | ~ASTFrontendAction() 19 | { 20 | scriptData->updateStaticStatics(); 21 | scriptData->resetStaticStatics(); 22 | 23 | //this should not be needed anymore 24 | if (diagnostics->getClient()->getNumErrors()) 25 | exit(EXIT_FAILURE); 26 | } 27 | 28 | std::unique_ptr CreateASTConsumer(clang::CompilerInstance& CI, llvm::StringRef file) override; 29 | 30 | private: 31 | clang::DiagnosticsEngine* diagnostics = NULL; 32 | clang::Rewriter TheRewriter; 33 | std::string outDir; 34 | 35 | void AddDefines(clang::Preprocessor &PP); 36 | void ModifyClangWarnings(clang::DiagnosticsEngine& DE); 37 | 38 | }; 39 | } -------------------------------------------------------------------------------- /Include/ClangParsing/ASTVisitorGlobal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Utils/ClangUtils.h" 3 | #include "clang/Lex/PreProcessor.h" 4 | #include "stdint.h" 5 | #include "ClangParsing/GlobalDecls.h" 6 | 7 | namespace SCCL 8 | { 9 | class ASTVisitorGlobal : public clang::RecursiveASTVisitor 10 | { 11 | public: 12 | ASTVisitorGlobal(clang::Rewriter &R, const clang::ASTContext &context, Script& scriptData) : TheRewriter(R), context(context), scriptData(scriptData) 13 | { 14 | 15 | } 16 | 17 | /// Gets the name of a function 18 | /// Function to get name 19 | /// The function name 20 | std::string getNameForFunc(const clang::FunctionDecl *decl); 21 | 22 | void addStaticPadding(size_t count); 23 | 24 | void addStatic(int32_t value); 25 | 26 | int32_t ParseLiteral(const clang::Expr *e, bool isAddr = false, bool isLtoRValue = false); 27 | 28 | bool VisitDecl(clang::Decl *D); 29 | 30 | std::string dumpName(const clang::NamedDecl *ND); 31 | 32 | inline void resetIntIndex(); 33 | 34 | 35 | 36 | private: 37 | clang::VarDecl* globalVarDecl; 38 | uint32_t intIndex = 0; 39 | clang::Type* savedType = nullptr; 40 | bool isCurrentExprEvaluable = true; 41 | bool doesCurrentValueNeedSet = false; 42 | 43 | clang::Rewriter &TheRewriter; 44 | const clang::ASTContext &context; 45 | Script& scriptData; 46 | }; 47 | } -------------------------------------------------------------------------------- /Include/ClangParsing/ASTVisitorLocal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Utils/ClangUtils.h" 3 | #include "clang/Lex/PreProcessor.h" 4 | #include "stdint.h" 5 | #include "ClangParsing/GlobalDecls.h" 6 | 7 | namespace SCCL 8 | { 9 | class ASTVisitorLocal : public clang::RecursiveASTVisitor 10 | { 11 | public: 12 | ASTVisitorLocal(clang::Rewriter &R, const clang::ASTContext& context, Script& scriptData) : TheRewriter(R), context(context), scriptData(scriptData) {} 13 | 14 | #pragma region Misc_Functions 15 | void ComplexToBoolean(bool floating); 16 | 17 | #pragma endregion 18 | 19 | #pragma region Name_Resolution 20 | std::string dumpName(const clang::NamedDecl *ND); 21 | std::string getNameForFunc(const clang::FunctionDecl *decl); 22 | #pragma endregion 23 | 24 | #pragma region Parsing 25 | std::string parseCast(const clang::CastExpr *castExpr); 26 | #pragma endregion 27 | 28 | #pragma region Decl_Handling 29 | void printDeclWithKey(const std::string& key, bool isAddr, bool isLtoRValue, bool isAssign, const clang::DeclRefExpr* declref); 30 | bool handleParmVarDecl(clang::ParmVarDecl *D); 31 | bool handleDecl(clang::DeclStmt* decl); 32 | #pragma endregion 33 | 34 | #pragma region Parse/Visit_Functions 35 | void parseCallProto(const clang::CallExpr* call, bool& isVariadic, size_t& NumParams); 36 | 37 | bool isPushString(const clang::Expr* e); 38 | bool EvaluateAsString(const clang::Expr* cExpr, std::string& outStr); 39 | 40 | bool checkIntrinsic(const clang::CallExpr* call); 41 | 42 | bool findAnyLabel(const clang::Stmt* stmt); 43 | void parseJumpFalse(const clang::Expr* conditional, const std::string& jumpFalseLoc); 44 | 45 | void parseCondition(const clang::Expr* conditional, const std::string& trueLoc, const std::string& falseLoc); 46 | void parseCondition2(const clang::Expr* conditional, const std::string& trueLoc, const std::string& falseLoc); 47 | void parseJumpTrue(const clang::Expr* conditional, const std::string& jumpTrueLoc); 48 | bool parseStatement(clang::Stmt *s, const std::string& breakLoc, const std::string& continueLoc); 49 | 50 | /// 51 | /// Parses the expression. 52 | /// 53 | /// The e. 54 | /// if set to true [is addr]. 55 | /// if set to true [is lto r value]. 56 | /// if set to true [print v table]. 57 | /// if set to true [is assign]. 58 | /// 59 | int parseExpression(const clang::Expr *e, bool isAddr = false, bool isLtoRValue = false, bool printVTable = true, bool isAssign = false, bool isArrToPtrDecay = false); 60 | 61 | bool parseArraySubscriptExpr(const clang::Expr *e, bool addrOf, bool LValueToRValue = false, bool isArrToPtrDecay = false); 62 | 63 | bool VisitFunctionDecl(clang::FunctionDecl *f); 64 | #pragma endregion 65 | 66 | public: 67 | clang::Rewriter &TheRewriter; 68 | const clang::ASTContext &context; 69 | 70 | const clang::FunctionDecl *currFunction; 71 | Script& scriptData; 72 | }; 73 | } -------------------------------------------------------------------------------- /Include/ClangParsing/CommandLineOptions.cpp: -------------------------------------------------------------------------------- 1 | #include "ClangParsing/CommandLineOptions.h" 2 | 3 | using namespace llvm::cl; 4 | 5 | namespace SCCL 6 | { 7 | OptionCategory ClangOptions("Clang Options"); 8 | OptionCategory CompilerOptions("Compiler Options"); 9 | 10 | opt Help("h", desc("Alias for -help"), Hidden); 11 | opt BuildPath("p", desc("Build path"), Optional, cat(ClangOptions)); 12 | list SourcePaths(Positional, desc(" [... ]"), cat(ClangOptions)); 13 | list ArgsAfter("extra-arg", desc("Additional argument to append to the compiler command line"), cat(ClangOptions)); 14 | list ArgsBefore("extra-arg-before", desc("Additional argument to prepend to the compiler command line"), cat(ClangOptions)); 15 | 16 | opt Option_Platform( 17 | "platform", desc("Choose target platform:"), 18 | Required, 19 | ValueRequired, 20 | cat(CompilerOptions), 21 | values( 22 | clEnumValN(Platform::P_XBOX, "XBOX", "Target Xbox"), 23 | clEnumValN(Platform::P_PSX, "PSX", "Target Playstation"), 24 | clEnumValN(Platform::P_PC, "PC", "Target PC") 25 | )); 26 | 27 | opt Option_BuildType( 28 | "target", desc("Choose build target:"), 29 | Required, 30 | ValueRequired, 31 | cat(CompilerOptions), 32 | values( 33 | clEnumValN(BuildType::BT_GTAIV, "GTAIV", "Grand Theft Auto IV (sco output)"), 34 | clEnumValN(BuildType::BT_GTAIV_TLAD, "GTAIV_TLAD", "Grand Theft Auto IV The Lost and Damned (sco output)"), 35 | clEnumValN(BuildType::BT_GTAIV_TBOGT, "GTAIV_TBOGT", "Grand Theft Auto IV The Ballad of Gay Tony (sco output)"), 36 | clEnumValN(BuildType::BT_GTAV, "GTAV", "Grand Theft Auto V (#sc output)"), 37 | clEnumValN(BuildType::BT_RDR_SCO, "RDR_SCO", "Red Dead Redemption (sco output)"), 38 | clEnumValN(BuildType::BT_RDR_XSC, "RDR_#SC", "Red Dead Redemption (#sc output)"), 39 | clEnumValN(BuildType::BT_RDR2, "RDR2", "Red Dead Redemption 2 (#sc output)") 40 | )); 41 | 42 | opt Option_OutputFileName( 43 | "name", desc("File name of output script, defaults to input file name"), 44 | ValueRequired, 45 | cat(CompilerOptions 46 | )); 47 | 48 | opt Option_ObfuscationLevel( 49 | desc("Choose obfuscation level: (This option is experimental use at your own risk)"), 50 | cat(CompilerOptions), 51 | values( 52 | clEnumValN(obf_string, "Fs", "Obfuscate string table - GTA V and RDR2 Only"), 53 | clEnumValN(obf_low, "F1", "Enable low obfuscations"), 54 | clEnumValN(obf_default, "F2", "Enable default obfuscations"), 55 | clEnumValN(obf_high, "F3", "Enable high obfuscations"), 56 | clEnumValN(obf_veryhigh, "F4", "Enable very high obfuscations"), 57 | clEnumValN(obf_max, "F5", "Enable max obfuscations") 58 | )); 59 | 60 | opt Option_GTAIVSCRFlag( 61 | "ivscr", desc("Choose GTAIV sco output config:"), 62 | ValueRequired, 63 | cat(CompilerOptions), 64 | values( 65 | clEnumValN(GTAIVSCRFlags::SCRF_CompressedEncrypted, "CompressEncrypt", "Sco output with compression and encryption (Default)"), 66 | clEnumValN(GTAIVSCRFlags::SCRF_Standard, "None", "Sco output with no compression or encryption"), 67 | clEnumValN(GTAIVSCRFlags::SCRF_Encrypted, "Encrypt", "Sco output with encryption") 68 | )); 69 | 70 | opt Option_HostVarIndex( 71 | "hvi", desc("Sets the starting index for host variables to ignore"), 72 | ValueRequired, 73 | cat(CompilerOptions) 74 | ); 75 | 76 | opt Option_HostVarSize( 77 | "hvs", desc("Sets the amount of host variables to ignore"), 78 | ValueRequired, 79 | cat(CompilerOptions) 80 | ); 81 | 82 | opt Option_PlayerVarIndex( 83 | "pvi", desc("Sets the starting index for player variables to ignore"), 84 | ValueRequired, 85 | cat(CompilerOptions) 86 | ); 87 | 88 | opt Option_PlayerVarSize( 89 | "pvs", desc("Sets the amount of player variables to ignore"), 90 | ValueRequired, 91 | cat(CompilerOptions) 92 | ); 93 | 94 | opt Option_OptimizationLevel( 95 | desc("Choose optimization level:"), 96 | cat(CompilerOptions), 97 | values( 98 | clEnumValN(OptimisationLevel::OL_None, "g", "No optimizations, enable debugging"), 99 | clEnumValN(OptimisationLevel::OL_Trivial, "O1", "Enable trivial optimizations"), 100 | clEnumValN(OptimisationLevel::OL_Normal, "O2", "Enable default optimizations"), 101 | clEnumValN(OptimisationLevel::OL_Full, "O3", "Enable expensive optimizations") 102 | )); 103 | 104 | opt Option_EmitAsm( 105 | "emit-asm", desc("Emits the pre compiled ASM representation of the script"), 106 | cat(CompilerOptions) 107 | ); 108 | 109 | opt Option_AsmOnly( 110 | "emit-asm-only", desc("Only emits the pre compiled ASM representation of the script"), 111 | cat(CompilerOptions) 112 | ); 113 | 114 | opt Option_NoRSC7( 115 | "no-rsc7", desc("Removes the RSC7 header from the output (GTAV)"), 116 | cat(CompilerOptions) 117 | ); 118 | 119 | opt Option_OutputDirectory( 120 | "out-dir", desc("Specify the output directory of the script"), 121 | ValueRequired, 122 | cat(CompilerOptions) 123 | ); 124 | 125 | opt Option_VCXPROJ( 126 | "vcx", 127 | desc("Parses source files out of a vcxproj file to allow for seamless linking in Visual Studio"), 128 | value_desc("vcxproj path"), 129 | cat(CompilerOptions) 130 | ); 131 | 132 | #pragma region Bool_Group 133 | //Grouping is for multi bool set support ex: -snb 134 | opt Option_Singleton( 135 | "s", desc("Limits script to one instance on runtime (RDR2 | GTAV | GTAIV)"), 136 | Grouping, 137 | cat(CompilerOptions) 138 | ); 139 | 140 | opt Option_DisableFunctionNames( 141 | "n", desc("Disable function names in script output, Enabled when optimisations are turned on"), 142 | Grouping, 143 | cat(CompilerOptions) 144 | ); 145 | 146 | //TODO: if selected set initializers in code 147 | opt Option_EntryFunctionPadding( 148 | "b", desc("Adds buffer to the entry function to allow script injection"), 149 | Hidden, 150 | Grouping, 151 | cat(CompilerOptions) 152 | ); 153 | 154 | #pragma endregion 155 | } -------------------------------------------------------------------------------- /Include/ClangParsing/CommandLineOptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Utils/ClangUtils.h" 3 | #include "ClangParsing/Helpers/Script.h" 4 | #include "stdint.h" 5 | 6 | namespace SCCL 7 | { 8 | extern llvm::cl::OptionCategory ClangOptions; 9 | extern llvm::cl::OptionCategory CompilerOptions; 10 | 11 | extern llvm::cl::opt Help; 12 | extern llvm::cl::opt BuildPath; 13 | extern llvm::cl::list SourcePaths; 14 | extern llvm::cl::list ArgsAfter; 15 | extern llvm::cl::list ArgsBefore; 16 | 17 | extern llvm::cl::opt Option_Platform; 18 | extern llvm::cl::opt Option_BuildType; 19 | extern llvm::cl::opt Option_OutputFileName; 20 | 21 | typedef enum ObfLevel 22 | { 23 | obf_none, 24 | obf_string, //just xor string table 25 | obf_low, //low: int maxBlockSize = 50, int minBlockSize = 30, bool keepEndReturn = true, bool makeJumpTable = false 26 | obf_default, //default: int maxBlockSize = 30, int minBlockSize = 15, bool keepEndReturn = false, bool makeJumpTable = false 27 | obf_high, //high: int maxBlockSize = 30, int minBlockSize = 15, bool keepEndReturn = false, bool makeJumpTable = true 28 | obf_veryhigh, //very high: int maxBlockSize = 15, int minBlockSize = 5, bool keepEndReturn = false, bool makeJumpTable = true 29 | obf_max, //max: int maxBlockSize = 5, int minBlockSize = 1, bool keepEndReturn = false, bool makeJumpTable = true 30 | } ObfLevel; 31 | 32 | extern llvm::cl::opt Option_ObfuscationLevel; 33 | 34 | extern llvm::cl::opt Option_PCVerison; 35 | 36 | extern llvm::cl::opt Option_HostVarIndex; 37 | extern llvm::cl::opt Option_HostVarSize; 38 | extern llvm::cl::opt Option_PlayerVarIndex; 39 | extern llvm::cl::opt Option_PlayerVarSize; 40 | extern llvm::cl::opt Option_OptimizationLevel; 41 | extern llvm::cl::opt Option_GTAIVSCRFlag; 42 | 43 | extern llvm::cl::opt Option_EmitAsm; 44 | extern llvm::cl::opt Option_AsmOnly; 45 | extern llvm::cl::opt Option_NoRSC7; 46 | 47 | extern llvm::cl::opt Option_OutputDirectory; 48 | 49 | extern llvm::cl::opt Option_VCXPROJ; 50 | 51 | #pragma region Bool_Group 52 | //Grouping is for multi bool set support ex: -snb 53 | extern llvm::cl::opt Option_Singleton; 54 | extern llvm::cl::opt Option_DisableFunctionNames; 55 | extern llvm::cl::opt Option_EntryFunctionPadding; 56 | #pragma endregion 57 | 58 | //extern llvm::cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage); 59 | //extern llvm::cl::extrahelp ProgramHelp("\nTemp text...\n"); 60 | 61 | } -------------------------------------------------------------------------------- /Include/ClangParsing/GlobalDecls.cpp: -------------------------------------------------------------------------------- 1 | #include "ClangParsing/GlobalDecls.h" 2 | #include "Utils\Utils.h" 3 | 4 | using namespace std; 5 | using namespace clang; 6 | using namespace Utils::System; 7 | using namespace Utils::DataConversion; 8 | 9 | namespace SCCL 10 | { 11 | local_scope LocalVariables; 12 | 13 | string globalDirectory; 14 | unique_ptr