Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

字符串加密不支持全局变量 #28

Open
doself opened this issue Dec 23, 2020 · 4 comments
Open

字符串加密不支持全局变量 #28

doself opened this issue Dec 23, 2020 · 4 comments

Comments

@doself
Copy link

doself commented Dec 23, 2020

多次测试发现全局变量都没有被混淆,后面会做这部分的支持吗

@amimo
Copy link
Owner

amimo commented Dec 25, 2020

代码贴出来看下。

@doself
Copy link
Author

doself commented Dec 26, 2020

代码贴出来看下。

int printf(const char *format, ...)
{
    return *(int*)format;
 
}
 
struct StringStruct {
    int i;
    const char *s;
};
 
static const struct StringStruct global_struct_string[] = {
    {123, "string in global struct123"},
    {456, "string in global struct456"}
};
 
 
char* global_var_string1 = "string in global var1";
char* global_var_string2 = "string in global var2";
 
char global_array_string[] = "string in global array";
const char const_global_array_string[] = "const string in global array";
 
// wchar_t* global_unicode_string = L"unicode global string";
 
int main(int argc, char *argv[])
{
    printf("", L"unicode arg string");
    // printf("", global_unicode_string);
 
 
 
    printf((char*)global_array_string[0]);
    printf(global_array_string);
 
    printf((char*)const_global_array_string[0]);
    printf(const_global_array_string);
 
    printf("string in arg1");
    printf("string in arg2", "string in arg2");
 
    printf(global_var_string1);
    printf(global_var_string2, global_var_string2);
 
 
 
    char* stack_var_string = "string in stack var";
    printf(stack_var_string);
 
 
    char* stack_var_string2 = "string in stack var2";
    printf(stack_var_string2, stack_var_string2);
 
 
 
    printf(global_struct_string[0].s);
    printf(global_struct_string[1].s, global_struct_string[1].s);
 
    struct StringStruct stack_struct_string = {
        789,
        "string in stack struct"
    };
    printf(stack_struct_string.s);
    printf(stack_struct_string.s, stack_struct_string.s);
 
 
    return 0;
}

以上为测试代码,想确认下字符串混淆的覆盖范围,结果发现全局变量几乎都是明文:
image

@amimo
Copy link
Owner

amimo commented Dec 26, 2020

使用static定义试试。不使用static的话,我会保留一份给外部引用,当前模块应该会使用本地加密的副本。

@doself
Copy link
Author

doself commented Dec 26, 2020

使用static定义试试。不使用static的话,我会保留一份给外部引用,当前模块应该会使用本地加密的副本。

加上了static定义还是不行,而且这种静态全局变量外部模块不能直接访问吧,对一些工程好像还是会有影响

static char* global_var_string1 = "string in global var1";
static char* global_var_string2 = "string in global var2";
 
static char global_array_string[] = "string in global array";

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants