From 090c04c3e95c3e397c193de799d0ebd5742cc200 Mon Sep 17 00:00:00 2001 From: chenzhch Date: Sat, 22 Jun 2024 15:42:31 +0800 Subject: [PATCH] Add OS bits setting --- README.md | 8 ++++++- shellc.c | 41 ++++++++++++++++++++++------------- "\350\257\264\346\230\216.md" | 9 +++++++- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 6f04f1f..fe82535 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ At present, the program has practical applications in ```AIX```, ```UNIX```, ``` ### User manual - Generate C code command - ```shellc command inputfile [-t] [-s] [-f fix-format] [-e fix-file]``` + ```shellc command inputfile [-t] [-s] [-f fix-format] [-e fix-file] [-b 8|16|32|64]``` command: Execute script commands, such ```sh```,```perl```,```python```,```node```,```ruby```,```Rscript```,```php```, etc. @@ -37,6 +37,8 @@ At present, the program has practical applications in ```AIX```, ```UNIX```, ``` -e option: Fix parameter 0 value by custom external file. + -b option: Operating system bits setting. + - Code pattern differences The normal mode shell script has some code visibility issues in most Linux operating systems, and the code after the ```read``` command can be obtained through ```/proc/[pid]/fd/[pipe]```. The safe mode does not have this issue. @@ -80,6 +82,10 @@ macOS 13|lldb|NO ### History +- v1.2 2024-06-22 + + Add operating system bits setting + - v1.1 2024-06-12 Expand functions in safe mode diff --git a/shellc.c b/shellc.c index 96edcf1..6552fec 100644 --- a/shellc.c +++ b/shellc.c @@ -5,7 +5,7 @@ * Author: ChenZhongChao * E-Mail: nbczc@163.com * Date: 2023-12-25 - * Version: 1.1 + * Version: 1.2 * Github: https://github.com/chenzhch/shellc.git * Gitee: https://gitee.com/chenzhch/shellc.git */ @@ -117,7 +117,6 @@ static const char *head[] = { "#include ", "#include ", "#include ", - "#include ", "#include ", "#include ", "#include ", @@ -148,7 +147,7 @@ static const char *first[] = { " f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48,", " f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, f61, f62, f63, f64", " };", - " srand(time(0));", + " srand(getpid());", " i = 0;", " memset(chr, 0, (size_t) sizeof(chr));", " while (data[i]) {", @@ -278,7 +277,7 @@ static const char *fourth_safe[] = { static const char *sh_start[] = { " if (argc > 1) {", - " srand(time(0));", + " srand(getpid());", " length = rand() % 9 + 16;", " name = malloc((size_t) length);", " memset(name, 0, length);", @@ -590,7 +589,7 @@ int main(int argc, char **argv) int fix_pos = -1; char *code_text, *obscure_text, *text; char *bitmap, *inname = NULL, *outname, *command = NULL; - char *fix_format = NULL, *file_name = NULL; + char *fix_format = NULL, *file_name = NULL, *bit = NULL; char str[1024]; long result, offset1, offset2; long salt1, salt2; @@ -601,12 +600,13 @@ int main(int argc, char **argv) char algorithm[32][17]; int i, j, k, loop, mode; int trace_flag = 0, fix_flag = 0, input_flag = 0, command_flag = 0, file_flag = 0; - int self_flag = 0, safe_flag = 0; + int self_flag = 0, safe_flag = 0, bit_flag = 0; struct utsname sysinfo; struct stat status; char *self_name = "/proc/self/status"; - char *option = "f:e:tsh"; + char *option = "f:e:b:tsh"; char **args = (char **) malloc((argc + 1) * sizeof(char *)); + char *usage = "command inputfile [-t] [-s] [-f fix-format] [-e fix-file] [-b 8|16|32|64]"; j = 0; args[j++] = strdup(argv[0]); @@ -619,7 +619,9 @@ int main(int argc, char **argv) args[j++] = strdup(argv[i]); argv[i] = NULL; if (option[k + 1] == ':') { - args[j++] = strdup(argv[++i]); + i++; + if(i == argc) break; + args[j++] = strdup(argv[i]); argv[i] = NULL; } } else { @@ -636,12 +638,13 @@ int main(int argc, char **argv) switch (opt) { case 'h': printf("%s: Convert script into C code\n", argv[0]); - printf("Usage: %s command inputfile [-t] [-s] [-f fix-format] [-e fix-file] \n", argv[0]); + printf("Usage: %s %s", argv[0], usage); printf("Option: \n"); printf(" -t Make traceable binary\n"); printf(" -s Using safe mode\n"); printf(" -f Fix arguments format\n"); printf(" -e Fix arguments 0 by external file\n"); + printf(" -b Operating system bits\n"); printf(" -h Display help and return\n"); return(0); case 't': @@ -658,10 +661,14 @@ int main(int argc, char **argv) file_flag++; file_name = strdup(optarg); break; + case 'b': + bit_flag++; + bit = strdup(optarg); + break; case '?': return(1); default: - fprintf(stderr, "Usage: %s command inputfile [-t] [-s] [-f fix-format] [-e fix-file]\n", argv[0]); + fprintf(stderr, "Usage: %s %s", argv[0], usage); return(1); } } @@ -676,9 +683,10 @@ int main(int argc, char **argv) } } - if (input_flag != 1 || command_flag != 1 || fix_flag > 1 - || trace_flag > 1 || safe_flag > 1 || file_flag > 1) { - fprintf(stderr, "Usage: %s command inputfile [-t] [-s] [-f fix-format] [-e fix-file]\n", argv[0]); + if (input_flag != 1 || command_flag != 1 || fix_flag > 1 || trace_flag > 1 + || safe_flag > 1 || file_flag > 1 || bit_flag>1 + || bit_flag && strcmp(bit, "8") && strcmp(bit, "16") && strcmp(bit, "32") && strcmp(bit,"64")) { + fprintf(stderr, "Usage: %s %s\n", argv[0], usage); return(1); } @@ -859,8 +867,11 @@ int main(int argc, char **argv) /*Write to the data section*/ fprintf(out, "static const char *data[] = {\n"); - - size = sizeof(long) * 8; + if (bit_flag) { + size = atoi(bit); + } else { + size = sizeof(long) * 8; + } text =(char *) malloc(size); j = 0; while (obscure_length) { diff --git "a/\350\257\264\346\230\216.md" "b/\350\257\264\346\230\216.md" index 66766a5..e7f2a4d 100644 --- "a/\350\257\264\346\230\216.md" +++ "b/\350\257\264\346\230\216.md" @@ -24,7 +24,7 @@ shellc除了解决```shc```存在的问题外,还增加了代码混淆、随 ### 使用手册 - 生成C代码命令 - ```shellc command inputfile [-t] [-s] [-f fix-format] [-e fix-file]``` + ```shellc command inputfile [-t] [-s] [-f fix-format] [-e fix-file] [-b 8|16|32|64]``` command: 执行脚本的命令,如 ```sh```、```perl```、```python```、```node```、```ruby```、```Rscript```、```php``` 等。 @@ -38,6 +38,8 @@ shellc除了解决```shc```存在的问题外,还增加了代码混淆、随 -e 选项: 使用外部文件修复参数0值 + -b 选项: 操作系统位数设置 + - 代码模式区别 通用模式shell脚本在大多数Linux类操作系统中存在部分代码可见问题,可通过```/proc/[pid]/fd/[pipe]```获取read命令后代码,安全模式无此问题。 @@ -80,6 +82,11 @@ macOS 13|lldb|不支持 ### 修改记录 + +- v1.2 2024-06-22 + + 增加操作系统位数设置功能 + - v1.1 2024-06-12 扩充安全模式下功能