Skip to content

Commit

Permalink
fix issues of -c flag on freebsd and cygwin
Browse files Browse the repository at this point in the history
  • Loading branch information
liberize committed Dec 4, 2024
1 parent d4b3945 commit 6e03ce2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <mach-o/dyld.h>
#elif defined(__FreeBSD__)
#include <sys/sysctl.h>
#elif defined(__CYGWIN__)
#include <Windows.h>
#endif
#include "obfuscate.h"

Expand All @@ -30,7 +32,7 @@ inline int is_big_endian() {

FORCE_INLINE std::string get_exe_path() {
char buf[PATH_MAX] = {0};
#if defined(__linux__) || defined(__CYGWIN__)
#if defined(__linux__)
int size = sizeof(buf);
size = readlink(OBF("/proc/self/exe"), buf, size);
return size == -1 ? std::string() : std::string(buf, size);
Expand All @@ -41,6 +43,8 @@ FORCE_INLINE std::string get_exe_path() {
size_t size = sizeof(buf);
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid() };
return sysctl(mib, 4, buf, &size, nullptr, 0) ? std::string() : std::string(buf);
#elif defined(__CYGWIN__)
return !GetModuleFileNameA(NULL, buf, sizeof(buf)) ? std::string() : std::string(buf);
#else
#error unsupported operating system!
#endif
Expand Down
2 changes: 1 addition & 1 deletion ssc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ if [ -n "$VERIFY_CHECKSUM" ]; then
echo '=> build crc32 tool...'
g++ -std=$CXX_STANDARD -w "$DIR/crc32.cpp" -o crc32 || exit 1
echo '=> write checksum to binary...'
OFFSET="$(LC_ALL=C awk -v RS='ssccksum' '{print length($0); exit}' <"$2")" # grep -abo is not portable
OFFSET="$(grep -abo ssccksum "$2" | grep -o '^[0-9]*')"
CKSUM="$(./crc32 "$2")"
#echo "offset=$OFFSET cksum=$CKSUM"
perl -e "open(my \$fh,'+<','$2'); seek(\$fh,$OFFSET,0); print \$fh pack('V',$OFFSET),pack('V',$CKSUM)"
Expand Down

0 comments on commit 6e03ce2

Please sign in to comment.