Skip to content

Commit

Permalink
Add OS bits setting
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhch committed Jun 22, 2024
1 parent 33c7c23 commit 090c04c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
41 changes: 26 additions & 15 deletions shellc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Author: ChenZhongChao
* E-Mail: [email protected]
* Date: 2023-12-25
* Version: 1.1
* Version: 1.2
* Github: https://github.com/chenzhch/shellc.git
* Gitee: https://gitee.com/chenzhch/shellc.git
*/
Expand Down Expand Up @@ -117,7 +117,6 @@ static const char *head[] = {
"#include <stdio.h>",
"#include <string.h>",
"#include <stdlib.h>",
"#include <time.h>",
"#include <signal.h>",
"#include <unistd.h>",
"#include <sys/types.h>",
Expand Down Expand Up @@ -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]) {",
Expand Down Expand Up @@ -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);",
Expand Down Expand Up @@ -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;
Expand All @@ -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]);
Expand All @@ -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 {
Expand All @@ -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':
Expand All @@ -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);
}
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion 说明.md
Original file line number Diff line number Diff line change
Expand Up @@ -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``` 等。

Expand All @@ -38,6 +38,8 @@ shellc除了解决```shc```存在的问题外,还增加了代码混淆、随

-e 选项: 使用外部文件修复参数0值

-b 选项: 操作系统位数设置

- 代码模式区别

通用模式shell脚本在大多数Linux类操作系统中存在部分代码可见问题,可通过```/proc/[pid]/fd/[pipe]```获取read命令后代码,安全模式无此问题。
Expand Down Expand Up @@ -80,6 +82,11 @@ macOS 13|lldb|不支持


### 修改记录

- v1.2 2024-06-22

增加操作系统位数设置功能

- v1.1 2024-06-12

扩充安全模式下功能
Expand Down

0 comments on commit 090c04c

Please sign in to comment.