Skip to content

Commit

Permalink
support generating random string with -n flag
Browse files Browse the repository at this point in the history
  • Loading branch information
liberize committed Dec 7, 2024
1 parent 50d381b commit 4eafd93
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Usage: ./ssc [-u] [-s] [-r] [-e|-E|-M file] [-0] [-n name] [-d date] [-m msg] [-
linux only, works like AppImage. if a directory is specified, create squashfs from it
-0, --fix-argv0 try to fix $0, may not work
if it doesn't work or causes problems, try -n flag or use $SSC_ARGV0 instead
-n, --ps-name change script path in ps output
-n, --ps-name change script path in ps output, may contain 'XXXXXX' which will be replaced with a random string
upon execution, create a symlink to real path and pass it to the interperter
-d, --expire-date expire date, for example, 11/30/2023
-m, --expire-message expire message, default to 'script has expired!'
Expand Down
2 changes: 1 addition & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ssc本身并不是一个编译器,比如cc,它会生成包含脚本代码的
仅适用于Linux,类似AppImage。如果指定的是目录,从这个目录创建squashfs文件
-0, --fix-argv0 尝试修复$0,可能不起作用
如果不起作用或造成问题,请尝试使用-n选项或使用$SSC_ARGV0代替$0
-n, --ps-name 更改ps输出中的脚本路径
-n, --ps-name 更改ps输出中的脚本路径,可包含XXXXXX,运行时替换为随机字符串
在执行时,创建一个指向真实路径的符号链接并将这个链接传递给解释器
-d, --expire-date 过期日期,例如 11/30/2023
-m, --expire-message 过期提示,默认为 script has expired!
Expand Down
21 changes: 16 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string>
#include <iterator>
#include <algorithm>
#include <random>
#include "obfuscate.h"
#include "utils.h"
#include "embed.h"
Expand Down Expand Up @@ -266,14 +267,24 @@ int main(int argc, char* argv[]) {
#endif

#ifdef PS_NAME
if (is_symlink(OBF(STR(PS_NAME)))) {
unlink(OBF(STR(PS_NAME)));
std::string link_name(OBF(STR(PS_NAME)));
pos = link_name.find("XXXXXX");
if (pos != std::string::npos) {
const char *chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
std::mt19937 gen(std::random_device{}());
std::uniform_int_distribution<> dist(0, strlen(chars) - 1);
for (; pos < link_name.size() && link_name[pos] == 'X'; pos++) {
link_name[pos] = chars[dist(gen)];
}
}
if (is_symlink(link_name.c_str())) {
unlink(link_name.c_str());
}
if (symlink(path.c_str(), OBF(STR(PS_NAME))) != 0) {
LOGE("failed to create symlink! path=" STR(PS_NAME) " err=`%s`", strerror(errno));
if (symlink(path.c_str(), link_name.c_str()) != 0) {
LOGE("failed to create symlink! path=%s err=`%s`", link_name.c_str(), strerror(errno));
return 5;
}
path = OBF(STR(PS_NAME));
path = std::move(link_name);
cleaner.add(path);
#endif

Expand Down

0 comments on commit 4eafd93

Please sign in to comment.