稍微优化
This commit is contained in:
parent
fbfc828997
commit
e4243709c2
6
Makefile
6
Makefile
@ -2,16 +2,16 @@ CROSS_COMPILE ?=
|
||||
CC := $(CROSS_COMPILE)gcc
|
||||
STRIP := $(CROSS_COMPILE)strip
|
||||
CFLAGS += -g -Wall -Os
|
||||
LIBS = -static
|
||||
LDFLAGS +=
|
||||
OBJ := sha
|
||||
|
||||
all: aes.o sha.o
|
||||
$(CC) $(CFLAGS) -o $(OBJ) $^ $(LIBS)
|
||||
$(CC) $(CFLAGS) -o $(OBJ) $^ $(LDFLAGS)
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
install:
|
||||
cp $(OBJ) /bin/sha
|
||||
cp $(OBJ) /bin/
|
||||
|
||||
uninstall:
|
||||
rm /bin/$(OBJ)
|
||||
|
58
sha.c
58
sha.c
@ -548,7 +548,7 @@ char *source_c[] = {
|
||||
"}",
|
||||
"",
|
||||
"#endif // #if defined(CTR) && (CTR == 1)",
|
||||
|
||||
"",
|
||||
"static int oneHexChar2Hex(char hex)",
|
||||
"{",
|
||||
" int outHex = 0;",
|
||||
@ -596,7 +596,7 @@ char *source_c[] = {
|
||||
"}",
|
||||
"",
|
||||
|
||||
"int is_Resolver(char *shll_text, char *shbin)",
|
||||
"static int is_Resolver(char *shll_text, char *shbin)",
|
||||
"{",
|
||||
" char *p, *p1;",
|
||||
" char temp[270];",
|
||||
@ -631,48 +631,46 @@ char *source_c[] = {
|
||||
" }",
|
||||
" return 0;",
|
||||
"}",
|
||||
|
||||
"",
|
||||
"#define BUFFER_SIZE 270",
|
||||
"",
|
||||
"int main(int argc, char *argv[])",
|
||||
"{",
|
||||
" uint8_t *Hex_string = (uint8_t *) malloc(encrypted_text_len*2);",
|
||||
" char *shbin = (char *) malloc(270);",
|
||||
"",
|
||||
" memset(shbin, 0, 270);",
|
||||
" memset(Hex_string, 0, encrypted_text_len*2);",
|
||||
"",
|
||||
"",
|
||||
" char *argvs[BUFFER_SIZE];",
|
||||
" int l=1;",
|
||||
" int i=4;",
|
||||
" static uint8_t key[16] = \"aixiao\";",
|
||||
" struct AES_ctx ctx;",
|
||||
" uint8_t *Hex_string = (uint8_t *) malloc(encrypted_text_len*2);",
|
||||
" char *shbin = NULL;",
|
||||
"",
|
||||
"",
|
||||
" AES_init_ctx(&ctx, key);",
|
||||
"",
|
||||
"",
|
||||
|
||||
" memset(Hex_string, 0, encrypted_text_len*2);",
|
||||
" HexString2Hex((char *)Encrypted_data, (char *)Hex_string, sizeof(Encrypted_data));",
|
||||
"",
|
||||
"",
|
||||
|
||||
|
||||
" AES_ECB_decrypt(&ctx, Hex_string);",
|
||||
" //printf(\"%s\\n\", Hex_string);",
|
||||
"",
|
||||
"",
|
||||
" shbin = (char *) malloc(BUFFER_SIZE);",
|
||||
" memset(shbin, 0, BUFFER_SIZE);",
|
||||
" if (-1 == is_Resolver((char *)Hex_string, shbin))",
|
||||
" {",
|
||||
" goto EXIT;",
|
||||
" }",
|
||||
" //printf(\"%s\\n\", shbin);",
|
||||
"",
|
||||
" char *argvs[270];",
|
||||
"",
|
||||
" argvs[0] = argv[0];",
|
||||
" argvs[1] = \"-c\";",
|
||||
" argvs[2] = (char *)Hex_string;",
|
||||
" argvs[3] = argv[0];",
|
||||
"",
|
||||
" int j=1;",
|
||||
" int i=4;",
|
||||
" for(i=4; i<=argc-1+4; i++)",
|
||||
" {",
|
||||
" argvs[i] = argv[j];",
|
||||
" j++;",
|
||||
" argvs[i] = argv[l];",
|
||||
" l++;",
|
||||
|
||||
" }",
|
||||
"",
|
||||
@ -699,7 +697,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
open_file(argv[1]);
|
||||
|
||||
|
||||
struct AES_ctx ctx;
|
||||
static uint8_t key[16] = "aixiao";
|
||||
uint8_t text_content[file_size * 2];
|
||||
uint8_t text_content_out[file_size * 2];
|
||||
@ -727,18 +726,16 @@ int main(int argc, char *argv[])
|
||||
memset(buildcmd, 0, BUFFER_SIZE*10);
|
||||
|
||||
|
||||
|
||||
memcpy(text_content, buff, strlen(buff));
|
||||
|
||||
|
||||
struct AES_ctx ctx;
|
||||
AES_init_ctx(&ctx, key);
|
||||
AES_ECB_encrypt(&ctx, text_content);
|
||||
|
||||
|
||||
//转16进制字符串
|
||||
hex2str(text_content, file_size, (char *)hexString);
|
||||
printf("%s\n", hexString);
|
||||
//printf("%s\n", hexString);
|
||||
|
||||
|
||||
//拼接
|
||||
@ -780,24 +777,32 @@ int main(int argc, char *argv[])
|
||||
sprintf(buildcmd, "gcc -Wall -Os %s -o %s", sourcefile, binfile);
|
||||
|
||||
|
||||
strcat(buildcmd, " && strip ");
|
||||
strcat(buildcmd, binfile);
|
||||
// 编译
|
||||
if (0 != system(buildcmd)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
remove(sourcefile);
|
||||
free(buff);
|
||||
|
||||
// 压缩
|
||||
if (0 == system("which upx 1> /dev/null")) {
|
||||
FILE *fp = NULL;
|
||||
char upxcommand[BUFFER_SIZE];
|
||||
memset(upxcommand, 0, BUFFER_SIZE);
|
||||
strcpy(upxcommand, "upx -9 ");
|
||||
strcat(upxcommand, binfile);
|
||||
sleep(1);
|
||||
if (0 != system(upxcommand)) {
|
||||
fp = popen(upxcommand, "r");
|
||||
if (NULL == fp)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
}
|
||||
|
||||
|
||||
@ -805,4 +810,3 @@ int main(int argc, char *argv[])
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user