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

控制流平坦化(flatten)bug及修复 #179

Open
lxraa opened this issue Jan 26, 2024 · 0 comments
Open

控制流平坦化(flatten)bug及修复 #179

lxraa opened this issue Jan 26, 2024 · 0 comments

Comments

@lxraa
Copy link

lxraa commented Jan 26, 2024

当入口块(insert)的后继块不等于origBB的第一个元素时,会导致控制流出错,demo:

 extern "C" __attribute((__annotate__(("fla")))) void func(){
    //人类不太会这样写,但是一些生成代码比方说unity的il2cpp时会出现这样的代码
    printf("block1\n");
	int a = 0;
	goto label2;

label:
    printf("block2\n");
    a = 1;
label2:
    {
        printf("block3\n");
        if(a % 2 == 0){
            goto label;
        }
    }
label3:
    {
        printf("block4\n");
        printf("%d\n",a);
        return;
    }
 }

可以在预处理第一个块的时候只要有后继就split,这样就保证了origBB的第一个元素一定是入口块的后继:
原代码

// Flattening.cpp : bool Flattening::flatten(Function *f)
 if ((br != NULL && br->isConditional()) ||
      insert->getTerminator()->getNumSuccessors() > 1) {
...

修复代码:

// Flattening.cpp : bool Flattening::flatten(Function *f)
 if ((br != NULL && br->isConditional()) ||
      insert->getTerminator()->getNumSuccessors() >= 1) {
....
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

1 participant