diff --git a/Boaz.py b/Boaz.py index 99d66af..2342938 100644 --- a/Boaz.py +++ b/Boaz.py @@ -636,6 +636,22 @@ def run_obfuscation(loader_path): def compile_output(loader_path, output_name, compiler, sleep_flag, anti_emulation, insert_junk_api_calls, api_unhooking=False, mllvm_options=None, god_speed=False, encoding=None, loader_number=1, dream=None, etw=False, compile_as_dll=False, compile_as_cpl = False): + + # Find the latest MinGW directory + mingw_dir_command = "ls -d /usr/lib/gcc/x86_64-w64-mingw32/*-win32 | sort -V | tail -n 1" + mingw_dir = subprocess.check_output(mingw_dir_command, shell=True, text=True).strip() + + if not mingw_dir: + print("Error: No x86_64-w64-mingw32 directory found.") + sys.exit(1) + + print(f"Using MinGW directory: {mingw_dir} \n") + + + if not mingw_dir: + print("Error: No x86_64-w64-mingw32 directory found.") + sys.exit(1) + if loader_number == 1 or 39 or 40 or 41: try: subprocess.run(['nasm', '-f', 'win64', 'assembly.asm', '-o', 'assembly.o'], check=True) @@ -644,7 +660,13 @@ def compile_output(loader_path, output_name, compiler, sleep_flag, anti_emulatio print(f"[-] NASM assembly compilation failed: {e}") return # Exit the function if NASM compilation fails - + if not output_name: + raise ValueError("output_name is empty. Please provide a valid output name.") + + # Ensure output_name has a path + if not os.path.dirname(output_name): + output_name = "./" + output_name + output_dir = os.path.dirname(output_name) if not os.path.exists(output_dir): os.makedirs(output_dir) @@ -677,9 +699,11 @@ def compile_output(loader_path, output_name, compiler, sleep_flag, anti_emulatio elif compile_as_cpl: compile_command.append('-shared') output_name = output_name.replace('.exe', '.cpl') - compile_command.extend(['-o', output_name, '-v', '-L/usr/lib/gcc/x86_64-w64-mingw32/12-win32', + compile_command.extend(['-o', output_name, '-v', f'-L{mingw_dir}', '-L./clang_test_include', '-I./c++/', '-I./c++/mingw32/']) elif compiler == "akira": + + # Default LLVM options for Akira # default_akira_options = ['-irobf-indbr', '-irobf-icall', '-irobf-indgv', '-irobf-cse', '-irobf-cff'] # akira_options = mllvm_options if mllvm_options else default_akira_options @@ -696,7 +720,7 @@ def compile_output(loader_path, output_name, compiler, sleep_flag, anti_emulatio elif compile_as_cpl: compile_command.append('-shared') output_name = output_name.replace('.exe', '.cpl') - compile_command.extend(['-o', output_name, '-v', '-L/usr/lib/gcc/x86_64-w64-mingw32/12-win32', + compile_command.extend(['-o', output_name, '-v', f'-L{mingw_dir}', '-L./clang_test_include', '-I./c++/', '-I./c++/mingw32/']) for option in akira_options: compile_command.extend(['-mllvm', option]) @@ -818,14 +842,14 @@ def compile_with_syswhisper(loader_path, output_name, syswhisper_option, sleep_f compile_command = ["./akira_built/bin/clang++", '-I.', '-I./converter', '-I./evader', "-D", "nullptr=NULL", "-mllvm", "-irobf-indbr", "-mllvm", "-irobf-icall", "-mllvm", "-irobf-indgv", "-mllvm", "-irobf-cse", "-mllvm", "-irobf-cff", "-target", "x86_64-w64-mingw32", loader_path, "./classic_stubs/syscalls.c", "./classic_stubs/syscallsstubs.std.x64.s", "-o", output_name, "-v", - "-L/usr/lib/gcc/x86_64-w64-mingw32/12-win32", "-L./clang_test_include", "-I./c++/", "-I./c++/mingw32/"] + additional_sources + f"-L{mingw_dir}", "-L./clang_test_include", "-I./c++/", "-I./c++/mingw32/"] + additional_sources subprocess.run(compile_command, check=True) elif compiler == "pluto": # Pluto-specific compilation command compile_command = ["./llvm_obfuscator_pluto/bin/clang++", '-I.', '-I./converter', '-I./evader', "-fms-extensions", "-D", "nullptr=NULL", "-O3", "-flto", "-fuse-ld=lld", "-mllvm", "-passes=mba,sub,idc,bcf,fla,gle", "-Xlinker", "-mllvm", "-Xlinker", "-passes=hlw,idc", "-target", "x86_64-w64-mingw32", loader_path, "./classic_stubs/syscalls.c", "./classic_stubs/syscallsstubs.std.x64.s", "-o", output_name, "-v", - "-L/usr/lib/gcc/x86_64-w64-mingw32/12-win32", "-L./clang_test_include", "-I./c++/", "-I./c++/mingw32/"] + additional_sources + f"-L{mingw_dir}", "-L./clang_test_include", "-I./c++/", "-I./c++/mingw32/"] + additional_sources subprocess.run(compile_command, check=True) elif syswhisper_option == 1: # Random syscall jumps compilation diff --git a/clang_test_include/algorithm b/clang_test_include/algorithm new file mode 100644 index 0000000..9122ec7 --- /dev/null +++ b/clang_test_include/algorithm @@ -0,0 +1,6 @@ +#pragma once + +namespace std { + template constexpr const T& min(const T& a, const T& b); + template constexpr const T& max(const T& a, const T& b); +} \ No newline at end of file diff --git a/clang_test_include/climits b/clang_test_include/climits new file mode 100644 index 0000000..929762e --- /dev/null +++ b/clang_test_include/climits @@ -0,0 +1,4 @@ +#pragma once + +#define INT_MIN -2147483648 +#define INT_MAX 2147483647 diff --git a/clang_test_include/cmath b/clang_test_include/cmath new file mode 100644 index 0000000..20e3489 --- /dev/null +++ b/clang_test_include/cmath @@ -0,0 +1,236 @@ +#pragma once + +// __clang_cuda_(c)math(.h) also provide `abs` which actually belong in +// cstdlib. We could split them out but for now we just include cstdlib from +// cmath.h which is what the systems I've seen do as well. +#include + +#include + +double acos(double); +float acos(float); +double acosh(double); +float acosh(float); +double asin(double); +float asin(float); +double asinh(double); +float asinh(float); +double atan2(double, double); +float atan2(float, float); +double atan(double); +float atan(float); +double atanh(double); +float atanh(float); +double cbrt(double); +float cbrt(float); +double ceil(double); +float ceil(float); +double copysign(double, double); +float copysign(float, float); +double cos(double); +float cos(float); +double cosh(double); +float cosh(float); +double erfc(double); +float erfc(float); +double erf(double); +float erf(float); +double exp2(double); +float exp2(float); +double exp(double); +float exp(float); +double expm1(double); +float expm1(float); +double fdim(double, double); +float fdim(float, float); +double floor(double); +float floor(float); +double fma(double, double, double); +float fma(float, float, float); +double fmax(double, double); +float fmax(float, float); +float max(float, float); +double max(double, double); +double fmin(double, double); +float fmin(float, float); +float min(float, float); +double min(double, double); +double fmod(double, double); +float fmod(float, float); +int fpclassify(double); +int fpclassify(float); +double frexp(double, int *); +float frexp(float, int *); +double hypot(double, double); +float hypot(float, float); +int ilogb(double); +int ilogb(float); +bool isfinite(long double); +bool isfinite(double); +bool isfinite(float); +bool isgreater(double, double); +bool isgreaterequal(double, double); +bool isgreaterequal(float, float); +bool isgreater(float, float); +bool isinf(long double); +bool isinf(double); +bool isinf(float); +bool isless(double, double); +bool islessequal(double, double); +bool islessequal(float, float); +bool isless(float, float); +bool islessgreater(double, double); +bool islessgreater(float, float); +bool isnan(long double); +#ifdef USE_ISNAN_WITH_INT_RETURN +int isnan(double); +int isnan(float); +#else +bool isnan(double); +bool isnan(float); +#endif +bool isnormal(double); +bool isnormal(float); +bool isunordered(double, double); +bool isunordered(float, float); +double ldexp(double, int); +float ldexp(float, int); +double lgamma(double); +float lgamma(float); +long long llrint(double); +long long llrint(float); +double log10(double); +float log10(float); +double log1p(double); +float log1p(float); +double log2(double); +float log2(float); +double logb(double); +float logb(float); +double log(double); +float log(float); +long lrint(double); +long lrint(float); +long lround(double); +long lround(float); +long long llround(float); // No llround(double). +double modf(double, double *); +float modf(float, float *); +double nan(const char *); +float nanf(const char *); +double nearbyint(double); +float nearbyint(float); +double nextafter(double, double); +float nextafter(float, float); +double pow(double, double); +double pow(double, int); +float pow(float, float); +float pow(float, int); +double remainder(double, double); +float remainder(float, float); +double remquo(double, double, int *); +float remquo(float, float, int *); +double rint(double); +float rint(float); +double round(double); +float round(float); +double scalbln(double, long); +float scalbln(float, long); +double scalbn(double, int); +float scalbn(float, int); +bool signbit(double); +bool signbit(float); +long double sin(long double); +double sin(double); +float sin(float); +double sinh(double); +float sinh(float); +double sqrt(double); +float sqrt(float); +double tan(double); +float tan(float); +double tanh(double); +float tanh(float); +double tgamma(double); +float tgamma(float); +double trunc(double); +float trunc(float); + +namespace std { + +using ::acos; +using ::acosh; +using ::asin; +using ::asinh; +using ::atan; +using ::atan2; +using ::atanh; +using ::cbrt; +using ::ceil; +using ::copysign; +using ::cos; +using ::cosh; +using ::erf; +using ::erfc; +using ::exp; +using ::exp2; +using ::expm1; +using ::fdim; +using ::floor; +using ::fma; +using ::fmax; +using ::fmin; +using ::fmod; +using ::fpclassify; +using ::frexp; +using ::hypot; +using ::ilogb; +using ::isfinite; +using ::isgreater; +using ::isgreaterequal; +using ::isinf; +using ::isless; +using ::islessequal; +using ::islessgreater; +using ::isnan; +using ::isnormal; +using ::isunordered; +using ::ldexp; +using ::lgamma; +using ::llrint; +using ::log; +using ::log10; +using ::log1p; +using ::log2; +using ::logb; +using ::lrint; +using ::lround; +using ::llround; +using ::modf; +using ::nan; +using ::nanf; +using ::nearbyint; +using ::nextafter; +using ::pow; +using ::remainder; +using ::remquo; +using ::rint; +using ::round; +using ::scalbln; +using ::scalbn; +using ::signbit; +using ::sin; +using ::sinh; +using ::sqrt; +using ::tan; +using ::tanh; +using ::tgamma; +using ::trunc; + +} // namespace std + +#define FP_NAN 0 +#define FP_INFINITE 1 +#define FP_ZERO 2 +#define FP_SUBNORMAL 3 +#define FP_NORMAL 4 diff --git a/clang_test_include/complex b/clang_test_include/complex new file mode 100644 index 0000000..bd43cd9 --- /dev/null +++ b/clang_test_include/complex @@ -0,0 +1,412 @@ +#pragma once + +#include + +#define INFINITY (__builtin_inff()) +#define NAN (__builtin_nanf ("")) + +namespace std { + +// Taken from libc++ +template +class complex { +public: + typedef _Tp value_type; + +private: + value_type __re_; + value_type __im_; + +public: + complex(const value_type &__re = value_type(), const value_type &__im = value_type()) + : __re_(__re), __im_(__im) {} + template + complex(const complex<_Xp> &__c) + : __re_(__c.real()), __im_(__c.imag()) {} + + value_type real() const { return __re_; } + value_type imag() const { return __im_; } + + void real(value_type __re) { __re_ = __re; } + void imag(value_type __im) { __im_ = __im; } + + complex &operator=(const value_type &__re) { + __re_ = __re; + __im_ = value_type(); + return *this; + } + complex &operator+=(const value_type &__re) { + __re_ += __re; + return *this; + } + complex &operator-=(const value_type &__re) { + __re_ -= __re; + return *this; + } + complex &operator*=(const value_type &__re) { + __re_ *= __re; + __im_ *= __re; + return *this; + } + complex &operator/=(const value_type &__re) { + __re_ /= __re; + __im_ /= __re; + return *this; + } + + template + complex &operator=(const complex<_Xp> &__c) { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template + complex &operator+=(const complex<_Xp> &__c) { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template + complex &operator-=(const complex<_Xp> &__c) { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template + complex &operator*=(const complex<_Xp> &__c) { + *this = *this * complex(__c.real(), __c.imag()); + return *this; + } + template + complex &operator/=(const complex<_Xp> &__c) { + *this = *this / complex(__c.real(), __c.imag()); + return *this; + } +}; + +template +inline complex<_Tp> +operator+(const complex<_Tp> &__x, const complex<_Tp> &__y) { + complex<_Tp> __t(__x); + __t += __y; + return __t; +} + +template +inline complex<_Tp> +operator+(const complex<_Tp> &__x, const _Tp &__y) { + complex<_Tp> __t(__x); + __t += __y; + return __t; +} + +template +inline complex<_Tp> +operator+(const _Tp &__x, const complex<_Tp> &__y) { + complex<_Tp> __t(__y); + __t += __x; + return __t; +} + +template +inline complex<_Tp> +operator-(const complex<_Tp> &__x, const complex<_Tp> &__y) { + complex<_Tp> __t(__x); + __t -= __y; + return __t; +} + +template +inline complex<_Tp> +operator-(const complex<_Tp> &__x, const _Tp &__y) { + complex<_Tp> __t(__x); + __t -= __y; + return __t; +} + +template +inline complex<_Tp> +operator-(const _Tp &__x, const complex<_Tp> &__y) { + complex<_Tp> __t(-__y); + __t += __x; + return __t; +} + +template +complex<_Tp> +operator*(const complex<_Tp> &__z, const complex<_Tp> &__w) { + _Tp __a = __z.real(); + _Tp __b = __z.imag(); + _Tp __c = __w.real(); + _Tp __d = __w.imag(); + _Tp __ac = __a * __c; + _Tp __bd = __b * __d; + _Tp __ad = __a * __d; + _Tp __bc = __b * __c; + _Tp __x = __ac - __bd; + _Tp __y = __ad + __bc; + if (std::isnan(__x) && std::isnan(__y)) { + bool __recalc = false; + if (std::isinf(__a) || std::isinf(__b)) { + __a = copysign(std::isinf(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(std::isinf(__b) ? _Tp(1) : _Tp(0), __b); + if (std::isnan(__c)) + __c = copysign(_Tp(0), __c); + if (std::isnan(__d)) + __d = copysign(_Tp(0), __d); + __recalc = true; + } + if (std::isinf(__c) || std::isinf(__d)) { + __c = copysign(std::isinf(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(std::isinf(__d) ? _Tp(1) : _Tp(0), __d); + if (std::isnan(__a)) + __a = copysign(_Tp(0), __a); + if (std::isnan(__b)) + __b = copysign(_Tp(0), __b); + __recalc = true; + } + if (!__recalc && (std::isinf(__ac) || std::isinf(__bd) || + std::isinf(__ad) || std::isinf(__bc))) { + if (std::isnan(__a)) + __a = copysign(_Tp(0), __a); + if (std::isnan(__b)) + __b = copysign(_Tp(0), __b); + if (std::isnan(__c)) + __c = copysign(_Tp(0), __c); + if (std::isnan(__d)) + __d = copysign(_Tp(0), __d); + __recalc = true; + } + if (__recalc) { + __x = _Tp(INFINITY) * (__a * __c - __b * __d); + __y = _Tp(INFINITY) * (__a * __d + __b * __c); + } + } + return complex<_Tp>(__x, __y); +} + +template +inline complex<_Tp> +operator*(const complex<_Tp> &__x, const _Tp &__y) { + complex<_Tp> __t(__x); + __t *= __y; + return __t; +} + +template +inline complex<_Tp> +operator*(const _Tp &__x, const complex<_Tp> &__y) { + complex<_Tp> __t(__y); + __t *= __x; + return __t; +} + +template +complex<_Tp> +operator/(const complex<_Tp> &__z, const complex<_Tp> &__w) { + int __ilogbw = 0; + _Tp __a = __z.real(); + _Tp __b = __z.imag(); + _Tp __c = __w.real(); + _Tp __d = __w.imag(); + _Tp __logbw = logb(fmax(fabs(__c), fabs(__d))); + if (std::isfinite(__logbw)) { + __ilogbw = static_cast(__logbw); + __c = scalbn(__c, -__ilogbw); + __d = scalbn(__d, -__ilogbw); + } + _Tp __denom = __c * __c + __d * __d; + _Tp __x = scalbn((__a * __c + __b * __d) / __denom, -__ilogbw); + _Tp __y = scalbn((__b * __c - __a * __d) / __denom, -__ilogbw); + if (std::isnan(__x) && std::isnan(__y)) { + if ((__denom == _Tp(0)) && (!std::isnan(__a) || !std::isnan(__b))) { + __x = copysign(_Tp(INFINITY), __c) * __a; + __y = copysign(_Tp(INFINITY), __c) * __b; + } else if ((std::isinf(__a) || std::isinf(__b)) && std::isfinite(__c) && std::isfinite(__d)) { + __a = copysign(std::isinf(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(std::isinf(__b) ? _Tp(1) : _Tp(0), __b); + __x = _Tp(INFINITY) * (__a * __c + __b * __d); + __y = _Tp(INFINITY) * (__b * __c - __a * __d); + } else if (std::isinf(__logbw) && __logbw > _Tp(0) && std::isfinite(__a) && std::isfinite(__b)) { + __c = copysign(std::isinf(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(std::isinf(__d) ? _Tp(1) : _Tp(0), __d); + __x = _Tp(0) * (__a * __c + __b * __d); + __y = _Tp(0) * (__b * __c - __a * __d); + } + } + return complex<_Tp>(__x, __y); +} + +template +inline complex<_Tp> +operator/(const complex<_Tp> &__x, const _Tp &__y) { + return complex<_Tp>(__x.real() / __y, __x.imag() / __y); +} + +template +inline complex<_Tp> +operator/(const _Tp &__x, const complex<_Tp> &__y) { + complex<_Tp> __t(__x); + __t /= __y; + return __t; +} + +template +inline complex<_Tp> +operator+(const complex<_Tp> &__x) { + return __x; +} + +template +inline complex<_Tp> +operator-(const complex<_Tp> &__x) { + return complex<_Tp>(-__x.real(), -__x.imag()); +} + +template +inline bool +operator==(const complex<_Tp> &__x, const complex<_Tp> &__y) { + return __x.real() == __y.real() && __x.imag() == __y.imag(); +} + +template +inline bool +operator==(const complex<_Tp> &__x, const _Tp &__y) { + return __x.real() == __y && __x.imag() == 0; +} + +template +inline bool +operator==(const _Tp &__x, const complex<_Tp> &__y) { + return __x == __y.real() && 0 == __y.imag(); +} + +template +inline bool +operator!=(const complex<_Tp> &__x, const complex<_Tp> &__y) { + return !(__x == __y); +} + +template +inline bool +operator!=(const complex<_Tp> &__x, const _Tp &__y) { + return !(__x == __y); +} + +template +inline bool +operator!=(const _Tp &__x, const complex<_Tp> &__y) { + return !(__x == __y); +} + +template _Tp abs(const std::complex<_Tp> &__c); + +// arg + +template _Tp arg(const std::complex<_Tp> &__c); + +// norm + +template _Tp norm(const std::complex<_Tp> &__c); + +// conj + +template std::complex<_Tp> conj(const std::complex<_Tp> &__c); + +// proj + +template std::complex<_Tp> proj(const std::complex<_Tp> &__c); + +// polar + +template +complex<_Tp> polar(const _Tp &__rho, const _Tp &__theta = _Tp()); + +// log + +template std::complex<_Tp> log(const std::complex<_Tp> &__x); + +// log10 + +template std::complex<_Tp> log10(const std::complex<_Tp> &__x); + +// sqrt + +template +std::complex<_Tp> sqrt(const std::complex<_Tp> &__x); + +// exp + +template +std::complex<_Tp> exp(const std::complex<_Tp> &__x); + +// pow + +template +std::complex<_Tp> pow(const std::complex<_Tp> &__x, + const std::complex<_Tp> &__y); + +// __sqr, computes pow(x, 2) + +template std::complex<_Tp> __sqr(const std::complex<_Tp> &__x); + +// asinh + +template +std::complex<_Tp> asinh(const std::complex<_Tp> &__x); + +// acosh + +template +std::complex<_Tp> acosh(const std::complex<_Tp> &__x); + +// atanh + +template +std::complex<_Tp> atanh(const std::complex<_Tp> &__x); + +// sinh + +template +std::complex<_Tp> sinh(const std::complex<_Tp> &__x); + +// cosh + +template +std::complex<_Tp> cosh(const std::complex<_Tp> &__x); + +// tanh + +template +std::complex<_Tp> tanh(const std::complex<_Tp> &__x); + +// asin + +template +std::complex<_Tp> asin(const std::complex<_Tp> &__x); + +// acos + +template +std::complex<_Tp> acos(const std::complex<_Tp> &__x); + +// atan + +template +std::complex<_Tp> atan(const std::complex<_Tp> &__x); + +// sin + +template +std::complex<_Tp> sin(const std::complex<_Tp> &__x); + +// cos + +template std::complex<_Tp> cos(const std::complex<_Tp> &__x); + +// tan + +template +std::complex<_Tp> tan(const std::complex<_Tp> &__x); + +} // namespace std diff --git a/clang_test_include/complex.h b/clang_test_include/complex.h new file mode 100644 index 0000000..1ed5f53 --- /dev/null +++ b/clang_test_include/complex.h @@ -0,0 +1,3 @@ +#pragma once + +#define complex _Complex diff --git a/clang_test_include/crt/device_double_functions.hpp b/clang_test_include/crt/device_double_functions.hpp new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/crt/device_double_functions.hpp @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/crt/device_functions.hpp b/clang_test_include/crt/device_functions.hpp new file mode 100644 index 0000000..41dc872 --- /dev/null +++ b/clang_test_include/crt/device_functions.hpp @@ -0,0 +1,3 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once +__device__ void __brkpt(); diff --git a/clang_test_include/crt/device_runtime.h b/clang_test_include/crt/device_runtime.h new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/crt/device_runtime.h @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/crt/host_runtime.h b/clang_test_include/crt/host_runtime.h new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/crt/host_runtime.h @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/crt/math_functions.hpp b/clang_test_include/crt/math_functions.hpp new file mode 100644 index 0000000..fbd2bb5 --- /dev/null +++ b/clang_test_include/crt/math_functions.hpp @@ -0,0 +1,12 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once +__device__ int __isinff(float); +__device__ int __isinf(double); +__device__ int __finitef(float); +__device__ int __isfinited(double); +__device__ int __isnanf(float); +__device__ int __isnan(double); +__device__ int __signbitf(float); +__device__ int __signbitd(double); +__device__ double max(double, double); +__device__ float max(float, float); diff --git a/clang_test_include/crt/sm_70_rt.hpp b/clang_test_include/crt/sm_70_rt.hpp new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/crt/sm_70_rt.hpp @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/cstdlib b/clang_test_include/cstdlib new file mode 100644 index 0000000..0b0adf4 --- /dev/null +++ b/clang_test_include/cstdlib @@ -0,0 +1,30 @@ +#pragma once + +#include + +#if __cplusplus >= 201703L +extern int abs (int __x) throw() __attribute__ ((__const__)) ; +extern long int labs (long int __x) throw() __attribute__ ((__const__)) ; +#else +extern int abs (int __x) __attribute__ ((__const__)) ; +extern long int labs (long int __x) __attribute__ ((__const__)) ; +#endif + +namespace std +{ + +using ::abs; + +inline long +abs(long __i) { return __builtin_labs(__i); } + +inline long long +abs(long long __x) { return __builtin_llabs (__x); } + +float fabs(float __x) { return __builtin_fabs(__x); } + +float abs(float __x) { return fabs(__x); } +double abs(double __x) { return fabs(__x); } + +} + diff --git a/clang_test_include/cuda.h b/clang_test_include/cuda.h new file mode 100644 index 0000000..d840297 --- /dev/null +++ b/clang_test_include/cuda.h @@ -0,0 +1,145 @@ +/* Minimal declarations for CUDA support. Testing purposes only. */ +#pragma once + +// Make this file work with nvcc, for testing compatibility. + +#ifndef __NVCC__ +#define __constant__ __attribute__((constant)) +#define __device__ __attribute__((device)) +#define __global__ __attribute__((global)) +#define __host__ __attribute__((host)) +#define __shared__ __attribute__((shared)) +#define __managed__ __attribute__((managed)) +#define __launch_bounds__(...) __attribute__((launch_bounds(__VA_ARGS__))) + +struct dim3 { + unsigned x, y, z; + __host__ __device__ dim3(unsigned x, unsigned y = 1, unsigned z = 1) : x(x), y(y), z(z) {} +}; + +// Host- and device-side placement new overloads. +void *operator new(__SIZE_TYPE__, void *p) { return p; } +void *operator new[](__SIZE_TYPE__, void *p) { return p; } +__device__ void *operator new(__SIZE_TYPE__, void *p) { return p; } +__device__ void *operator new[](__SIZE_TYPE__, void *p) { return p; } + +#define CUDA_VERSION 10100 + +struct char2 { + char x, y; + __host__ __device__ char2(char x = 0, char y = 0) : x(x), y(y) {} +}; +struct char4 { + char x, y, z, w; + __host__ __device__ char4(char x = 0, char y = 0, char z = 0, char w = 0) : x(x), y(y), z(z), w(w) {} +}; + +struct uchar2 { + unsigned char x, y; + __host__ __device__ uchar2(unsigned char x = 0, unsigned char y = 0) : x(x), y(y) {} +}; +struct uchar4 { + unsigned char x, y, z, w; + __host__ __device__ uchar4(unsigned char x = 0, unsigned char y = 0, unsigned char z = 0, unsigned char w = 0) : x(x), y(y), z(z), w(w) {} +}; + +struct short2 { + short x, y; + __host__ __device__ short2(short x = 0, short y = 0) : x(x), y(y) {} +}; +struct short4 { + short x, y, z, w; + __host__ __device__ short4(short x = 0, short y = 0, short z = 0, short w = 0) : x(x), y(y), z(z), w(w) {} +}; + +struct ushort2 { + unsigned short x, y; + __host__ __device__ ushort2(unsigned short x = 0, unsigned short y = 0) : x(x), y(y) {} +}; +struct ushort4 { + unsigned short x, y, z, w; + __host__ __device__ ushort4(unsigned short x = 0, unsigned short y = 0, unsigned short z = 0, unsigned short w = 0) : x(x), y(y), z(z), w(w) {} +}; + +struct int2 { + int x, y; + __host__ __device__ int2(int x = 0, int y = 0) : x(x), y(y) {} +}; +struct int4 { + int x, y, z, w; + __host__ __device__ int4(int x = 0, int y = 0, int z = 0, int w = 0) : x(x), y(y), z(z), w(w) {} +}; + +struct uint2 { + unsigned x, y; + __host__ __device__ uint2(unsigned x = 0, unsigned y = 0) : x(x), y(y) {} +}; +struct uint3 { + unsigned x, y, z; + __host__ __device__ uint3(unsigned x = 0, unsigned y = 0, unsigned z = 0) : x(x), y(y), z(z) {} +}; +struct uint4 { + unsigned x, y, z, w; + __host__ __device__ uint4(unsigned x = 0, unsigned y = 0, unsigned z = 0, unsigned w = 0) : x(x), y(y), z(z), w(w) {} +}; + +struct longlong2 { + long long x, y; + __host__ __device__ longlong2(long long x = 0, long long y = 0) : x(x), y(y) {} +}; +struct longlong4 { + long long x, y, z, w; + __host__ __device__ longlong4(long long x = 0, long long y = 0, long long z = 0, long long w = 0) : x(x), y(y), z(z), w(w) {} +}; + +struct ulonglong2 { + unsigned long long x, y; + __host__ __device__ ulonglong2(unsigned long long x = 0, unsigned long long y = 0) : x(x), y(y) {} +}; +struct ulonglong4 { + unsigned long long x, y, z, w; + __host__ __device__ ulonglong4(unsigned long long x = 0, unsigned long long y = 0, unsigned long long z = 0, unsigned long long w = 0) : x(x), y(y), z(z), w(w) {} +}; + +struct float2 { + float x, y; + __host__ __device__ float2(float x = 0, float y = 0) : x(x), y(y) {} +}; +struct float4 { + float x, y, z, w; + __host__ __device__ float4(float x = 0, float y = 0, float z = 0, float w = 0) : x(x), y(y), z(z), w(w) {} +}; + +struct double2 { + double x, y; + __host__ __device__ double2(double x = 0, double y = 0) : x(x), y(y) {} +}; +struct double4 { + double x, y, z, w; + __host__ __device__ double4(double x = 0, double y = 0, double z = 0, double w = 0) : x(x), y(y), z(z), w(w) {} +}; + +typedef unsigned long long cudaTextureObject_t; + +enum cudaTextureReadMode { + cudaReadModeNormalizedFloat, + cudaReadModeElementType +}; + +enum { + cudaTextureType1D, + cudaTextureType2D, + cudaTextureType3D, + cudaTextureTypeCubemap, + cudaTextureType1DLayered, + cudaTextureType2DLayered, + cudaTextureTypeCubemapLayered +}; + +struct textureReference {}; +template +struct __attribute__((device_builtin_texture_type)) texture + : public textureReference {}; + +#endif // !__NVCC__ diff --git a/clang_test_include/cuda_runtime.h b/clang_test_include/cuda_runtime.h new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/cuda_runtime.h @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/curand_mtgp32_kernel.h b/clang_test_include/curand_mtgp32_kernel.h new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/curand_mtgp32_kernel.h @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/device_atomic_functions.h b/clang_test_include/device_atomic_functions.h new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/device_atomic_functions.h @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/device_atomic_functions.hpp b/clang_test_include/device_atomic_functions.hpp new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/device_atomic_functions.hpp @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/device_double_functions.h b/clang_test_include/device_double_functions.h new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/device_double_functions.h @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/driver_types.h b/clang_test_include/driver_types.h new file mode 100644 index 0000000..b5d366a --- /dev/null +++ b/clang_test_include/driver_types.h @@ -0,0 +1,4 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once + +#include diff --git a/clang_test_include/float.h b/clang_test_include/float.h new file mode 100644 index 0000000..616a02c --- /dev/null +++ b/clang_test_include/float.h @@ -0,0 +1,2 @@ +#pragma once +#define FLOAT_LOCAL_DEF 1 diff --git a/clang_test_include/host_config.h b/clang_test_include/host_config.h new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/host_config.h @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/host_defines.h b/clang_test_include/host_defines.h new file mode 100644 index 0000000..03fed3a --- /dev/null +++ b/clang_test_include/host_defines.h @@ -0,0 +1,3 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once +#define __forceinline__ diff --git a/clang_test_include/limits b/clang_test_include/limits new file mode 100644 index 0000000..fbee11e --- /dev/null +++ b/clang_test_include/limits @@ -0,0 +1,10 @@ +#pragma once + +namespace std +{ +struct __numeric_limits_base + {}; +template + struct numeric_limits : public __numeric_limits_base + {}; +} diff --git a/clang_test_include/math.h b/clang_test_include/math.h new file mode 100644 index 0000000..b13b14f --- /dev/null +++ b/clang_test_include/math.h @@ -0,0 +1,203 @@ +#pragma once + +// __clang_cuda_(c)math(.h) also provide `abs` which actually belong in +// cstdlib. We could split them out but for now we just include cstdlib from +// cmath.h which is what the systems I've seen do as well. +#include + +double fabs(double __a); +double acos(double __a); +float acosf(float __a); +double acosh(double __a); +float acoshf(float __a); +double asin(double __a); +float asinf(float __a); +double asinh(double __a); +float asinhf(float __a); +double atan(double __a); +double atan2(double __a, double __b); +float atan2f(float __a, float __b); +float atanf(float __a); +double atanh(double __a); +float atanhf(float __a); +double cbrt(double __a); +float cbrtf(float __a); +double ceil(double __a); +float ceilf(float __a); +double copysign(double __a, double __b); +float copysignf(float __a, float __b); +double cos(double __a); +float cosf(float __a); +double cosh(double __a); +float coshf(float __a); +double cospi(double __a); +float cospif(float __a); +double cyl_bessel_i0(double __a); +float cyl_bessel_i0f(float __a); +double cyl_bessel_i1(double __a); +float cyl_bessel_i1f(float __a); +double erf(double __a); +double erfc(double __a); +float erfcf(float __a); +double erfcinv(double __a); +float erfcinvf(float __a); +double erfcx(double __a); +float erfcxf(float __a); +float erff(float __a); +double erfinv(double __a); +float erfinvf(float __a); +double exp(double __a); +double exp10(double __a); +float exp10f(float __a); +double exp2(double __a); +float exp2f(float __a); +float expf(float __a); +double expm1(double __a); +float expm1f(float __a); +float fabsf(float __a); +double fdim(double __a, double __b); +float fdimf(float __a, float __b); +double fdivide(double __a, double __b); +float fdividef(float __a, float __b); +double floor(double __f); +float floorf(float __f); +double fma(double __a, double __b, double __c); +float fmaf(float __a, float __b, float __c); +double fmax(double __a, double __b); +float fmaxf(float __a, float __b); +double fmin(double __a, double __b); +float fminf(float __a, float __b); +double fmod(double __a, double __b); +float fmodf(float __a, float __b); +double frexp(double __a, int *__b); +float frexpf(float __a, int *__b); +double hypot(double __a, double __b); +float hypotf(float __a, float __b); +int ilogb(double __a); +int ilogbf(float __a); +double j0(double __a); +float j0f(float __a); +double j1(double __a); +float j1f(float __a); +double jn(int __n, double __a); +float jnf(int __n, float __a); +double ldexp(double __a, int __b); +float ldexpf(float __a, int __b); +double lgamma(double __a); +float lgammaf(float __a); +long long llmax(long long __a, long long __b); +long long llmin(long long __a, long long __b); +long long llrint(double __a); +long long llrintf(float __a); +long long llround(double __a); +long long llroundf(float __a); +double log(double __a); +double log10(double __a); +float log10f(float __a); +double log1p(double __a); +float log1pf(float __a); +double log2(double __a); +float log2f(float __a); +double logb(double __a); +float logbf(float __a); +float logf(float __a); +long lrint(double __a); +long lrintf(float __a); +long lround(double __a); +long lroundf(float __a); +int max(int __a, int __b); +int min(int __a, int __b); +double modf(double __a, double *__b); +float modff(float __a, float *__b); +double nearbyint(double __a); +float nearbyintf(float __a); +double nextafter(double __a, double __b); +float nextafterf(float __a, float __b); +double norm(int __dim, const double *__t); +double norm3d(double __a, double __b, double __c); +float norm3df(float __a, float __b, float __c); +double norm4d(double __a, double __b, double __c, double __d); +float norm4df(float __a, float __b, float __c, float __d); +double normcdf(double __a); +float normcdff(float __a); +double normcdfinv(double __a); +float normcdfinvf(float __a); +float normf(int __dim, const float *__t); +double pow(double __a, double __b); +float powf(float __a, float __b); +double powi(double __a, int __b); +float powif(float __a, int __b); +double rcbrt(double __a); +float rcbrtf(float __a); +double remainder(double __a, double __b); +float remainderf(float __a, float __b); +double remquo(double __a, double __b, int *__c); +float remquof(float __a, float __b, int *__c); +double rhypot(double __a, double __b); +float rhypotf(float __a, float __b); +double rint(double __a); +float rintf(float __a); +double rnorm(int __a, const double *__b); +double rnorm3d(double __a, double __b, double __c); +float rnorm3df(float __a, float __b, float __c); +double rnorm4d(double __a, double __b, double __c, double __d); +float rnorm4df(float __a, float __b, float __c, float __d); +float rnormf(int __dim, const float *__t); +double round(double __a); +float roundf(float __a); +double rsqrt(double __a); +float rsqrtf(float __a); +double scalbn(double __a, int __b); +float scalbnf(float __a, int __b); +double scalbln(double __a, long __b); +float scalblnf(float __a, long __b); +double sin(double __a); +void sincos(double __a, double *__s, double *__c); +void sincosf(float __a, float *__s, float *__c); +void sincospi(double __a, double *__s, double *__c); +void sincospif(float __a, float *__s, float *__c); +float sinf(float __a); +double sinh(double __a); +float sinhf(float __a); +double sinpi(double __a); +float sinpif(float __a); +double sqrt(double __a); +float sqrtf(float __a); +double tan(double __a); +float tanf(float __a); +double tanh(double __a); +float tanhf(float __a); +double tgamma(double __a); +float tgammaf(float __a); +double trunc(double __a); +float truncf(float __a); +unsigned long long ullmax(unsigned long long __a, + unsigned long long __b); +unsigned long long ullmin(unsigned long long __a, + unsigned long long __b); +unsigned int umax(unsigned int __a, unsigned int __b); +unsigned int umin(unsigned int __a, unsigned int __b); +double y0(double __a); +float y0f(float __a); +double y1(double __a); +float y1f(float __a); +double yn(int __a, double __b); +float ynf(int __a, float __b); + +/** + * A positive float constant expression. HUGE_VALF evaluates + * to +infinity. Used as an error value returned by the built-in + * math functions. + */ +#define HUGE_VALF (__builtin_huge_valf()) + +/** + * A positive double constant expression. HUGE_VAL evaluates + * to +infinity. Used as an error value returned by the built-in + * math functions. + */ +#define HUGE_VAL (__builtin_huge_val()) + +#ifdef __cplusplus +#include +#endif diff --git a/clang_test_include/math_functions_dbl_ptx3.hpp b/clang_test_include/math_functions_dbl_ptx3.hpp new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/math_functions_dbl_ptx3.hpp @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/new b/clang_test_include/new new file mode 100644 index 0000000..5110731 --- /dev/null +++ b/clang_test_include/new @@ -0,0 +1,8 @@ +#pragma once + +namespace std +{ + +struct nothrow_t { explicit nothrow_t() = default; }; + +} diff --git a/clang_test_include/omp.h b/clang_test_include/omp.h new file mode 100644 index 0000000..9a6c115 --- /dev/null +++ b/clang_test_include/omp.h @@ -0,0 +1,21 @@ +#ifndef __OMP_H +#define __OMP_H + +#if _OPENMP +// Follows the pattern in interface.h +// Clang sema checks this type carefully, needs to closely match that from omp.h +typedef enum omp_allocator_handle_t { + omp_null_allocator = 0, + omp_default_mem_alloc = 1, + omp_large_cap_mem_alloc = 2, + omp_const_mem_alloc = 3, + omp_high_bw_mem_alloc = 4, + omp_low_lat_mem_alloc = 5, + omp_cgroup_mem_alloc = 6, + omp_pteam_mem_alloc = 7, + omp_thread_mem_alloc = 8, + KMP_ALLOCATOR_MAX_HANDLE = ~(0U) +} omp_allocator_handle_t; +#endif + +#endif diff --git a/clang_test_include/setjmp.h b/clang_test_include/setjmp.h new file mode 100644 index 0000000..3d5e903 --- /dev/null +++ b/clang_test_include/setjmp.h @@ -0,0 +1,8 @@ +#ifndef SETJMP_H +#define SETJMP_H + +typedef struct { + int x[42]; +} jmp_buf; + +#endif diff --git a/clang_test_include/sm_20_atomic_functions.hpp b/clang_test_include/sm_20_atomic_functions.hpp new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/sm_20_atomic_functions.hpp @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/sm_20_intrinsics.hpp b/clang_test_include/sm_20_intrinsics.hpp new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/sm_20_intrinsics.hpp @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/sm_32_atomic_functions.hpp b/clang_test_include/sm_32_atomic_functions.hpp new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/sm_32_atomic_functions.hpp @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/sm_60_atomic_functions.hpp b/clang_test_include/sm_60_atomic_functions.hpp new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/sm_60_atomic_functions.hpp @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/sm_61_intrinsics.hpp b/clang_test_include/sm_61_intrinsics.hpp new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/sm_61_intrinsics.hpp @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/stdint.h b/clang_test_include/stdint.h new file mode 100644 index 0000000..5bf26a7 --- /dev/null +++ b/clang_test_include/stdint.h @@ -0,0 +1,19 @@ +#ifndef STDINT_H +#define STDINT_H + +#ifdef __INT32_TYPE__ +typedef unsigned __INT32_TYPE__ uint32_t; +#endif + +#ifdef __INT64_TYPE__ +typedef unsigned __INT64_TYPE__ uint64_t; +#endif + +#ifdef __INTPTR_TYPE__ +typedef __INTPTR_TYPE__ intptr_t; +typedef unsigned __INTPTR_TYPE__ uintptr_t; +#else +#error Every target should have __INTPTR_TYPE__ +#endif + +#endif /* STDINT_H */ diff --git a/clang_test_include/stdlib.h b/clang_test_include/stdlib.h new file mode 100644 index 0000000..47cd80c --- /dev/null +++ b/clang_test_include/stdlib.h @@ -0,0 +1,9 @@ +#pragma once +typedef __SIZE_TYPE__ size_t; + +void *malloc(size_t); +void free(void*); + +#ifndef __cplusplus +extern int abs(int __x) __attribute__((__const__)); +#endif diff --git a/clang_test_include/string.h b/clang_test_include/string.h new file mode 100644 index 0000000..98cf77f --- /dev/null +++ b/clang_test_include/string.h @@ -0,0 +1,3 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once +void* memcpy(void* dst, const void* src, size_t num); diff --git a/clang_test_include/texture_fetch_functions.h b/clang_test_include/texture_fetch_functions.h new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/texture_fetch_functions.h @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/texture_indirect_functions.h b/clang_test_include/texture_indirect_functions.h new file mode 100644 index 0000000..bffa775 --- /dev/null +++ b/clang_test_include/texture_indirect_functions.h @@ -0,0 +1,2 @@ +// required for __clang_cuda_runtime_wrapper.h tests +#pragma once diff --git a/clang_test_include/type_traits b/clang_test_include/type_traits new file mode 100644 index 0000000..9fd02d5 --- /dev/null +++ b/clang_test_include/type_traits @@ -0,0 +1,43 @@ +/// Copied from libcxx type_traits and simplified + +#pragma once + +namespace std { + +template +struct integral_constant { + static const _Tp value = __v; + typedef _Tp value_type; + typedef integral_constant type; +}; + +typedef integral_constant true_type; +typedef integral_constant false_type; + +// is_same, functional +template struct is_same : public false_type {}; +template struct is_same<_Tp, _Tp> : public true_type {}; + +// is_integral, for some types. +template struct is_integral + : public integral_constant {}; +template <> struct is_integral + : public integral_constant {}; +template <> struct is_integral + : public integral_constant {}; +template <> struct is_integral + : public integral_constant {}; +template <> struct is_integral + : public integral_constant {}; +template <> struct is_integral + : public integral_constant {}; +template <> struct is_integral + : public integral_constant {}; + +// enable_if, functional +template struct enable_if{}; +template struct enable_if{ + using type = _Tp; +}; + +} diff --git a/clang_test_include/utility b/clang_test_include/utility new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/clang_test_include/utility @@ -0,0 +1,2 @@ +#pragma once + diff --git a/requirements.sh b/requirements.sh index ed7ca59..354bc4a 100644 --- a/requirements.sh +++ b/requirements.sh @@ -10,7 +10,17 @@ pip3 install pyopenssl sudo apt install build-essential -y # Install required packages -sudo apt install -y git cmake ninja-build python3 gcc g++ zlib1g-dev wine mingw-w64 mingw-w64-tools x86_64-w64-mingw32-g++ +sudo apt install -y git +sudo apt install -y cmake +sudo apt install -y ninja-build +sudo apt install -y python3 +sudo apt install -y gcc +sudo apt install -y g++ +sudo apt install -y zlib1g-dev +sudo apt install -y wine +sudo apt install -y mingw-w64 +sudo apt install -y mingw-w64-tools +sudo apt install -y x86_64-w64-mingw32-g++ if [ -f "./donut" ]; then echo "'donut' is already installed in the current directory." @@ -20,7 +30,7 @@ fi echo "Installing pe2sh..." -if [ -f "./pe2shc.exe" ]; then +if [ -f "./PIC/pe2shc.exe" ]; then echo "'pe2shc.exe' is already installed in the current directory." else echo "'pe2shc.exe' not found. Installing..." @@ -83,10 +93,18 @@ cd .. # Install Syswhisper2 (adjust with actual repository if different) echo "Installing Syswhisper2..." -git clone https://github.com/jthuraisamy/SysWhispers2 -cd syswhisper2 -python3 ./syswhispers.py --preset common -o syscalls_common -cd .. +## if fodler SysWhispers2 does not exits: +if [ ! -d "./SysWhispers2" ]; then + git clone https://github.com/jthuraisamy/SysWhispers2 + cd SysWhispers2 + python3 ./syswhispers.py --preset common -o syscalls_common + cd .. +else + cd SysWhispers2 + python3 ./syswhispers.py --preset common -o syscalls_common + cd .. +fi + # Clone and build llvm-obfuscator (Akira-obfuscator) echo "Cloning and building Akira llvm-obfuscator..." @@ -94,10 +112,37 @@ git clone https://github.com/thomasxm/Akira-obfuscator.git cd Akira-obfuscator && mkdir -p akira_built cd akira_built && cmake -DCMAKE_CXX_FLAGS="" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb" -G "Ninja" ../llvm ninja -j2 -mv ./akira_built/* ../../akira_built/ +cd .. && mv ./akira_built/ ../ + +# Locate the installed version of x86_64-w64-mingw32 +MINGW_DIR=$(ls -d /usr/lib/gcc/x86_64-w64-mingw32/*-win32 | sort -V | tail -n 1) + +if [ -z "$MINGW_DIR" ]; then + echo "Error: No x86_64-w64-mingw32 directory found." + exit 1 +fi + +echo "Using MinGW directory: $MINGW_DIR" + echo "start unit test:" -cd ../../ && ./akira_built/bin/clang++ -D nullptr=NULL -mllvm -irobf-indbr -mllvm -irobf-icall -mllvm -irobf-indgv -mllvm -irobf-cse -mllvm -irobf-cff -target x86_64-w64-mingw32 loader2_test.c classic_stubs/syscalls.c ./classic_stubs/syscallsstubs.std.x64.s -o test.exe -v -L/usr/lib/gcc/x86_64-w64-mingw32/12-win32 -L./clang_test_include -I./c++/ -I./c++/mingw32/ -lws2_32 -lpsapi ./normal_api.c -wine ./test.exe +cd ../ +./akira_built/bin/clang++ -D nullptr=NULL -mllvm -irobf-indbr -mllvm -irobf-icall -mllvm -irobf-indgv -mllvm -irobf-cse -mllvm -irobf-cff -target x86_64-w64-mingw32 loader2_test.c classic_stubs/syscalls.c ./classic_stubs/syscallsstubs.std.x64.s -o test.exe -v -L$MINGW_DIR -L./clang_test_include -I./c++/ -I./c++/mingw32/ -lws2_32 -lpsapi +## if ./test.exe exists, run it with wine +# Check if the build was successful +if [ $? -ne 0 ]; then + echo "Error: Build failed." + exit 1 +fi + +if [ -f "./test.exe" ]; then + wine ./test.exe +fi + +# Check if the test run was successful +if [ $? -ne 0 ]; then + echo "Error: Running test.exe with Wine failed." + exit 1 +fi # Clone and build Pluto echo "Cloning and building Pluto-obfuscator..." @@ -145,8 +190,8 @@ if [ $? -eq 0 ]; then echo "Executable created successfully." else echo "Failed to create the executable." - exit 1 + fi - +mv dist/Boaz . echo "Setup completed successfully." echo "Main program can be run with python3 Boaz.py or ./Boaz" \ No newline at end of file