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

Issue about Globalvariable names #636

Closed
seviezhou opened this issue Sep 4, 2019 · 6 comments
Closed

Issue about Globalvariable names #636

seviezhou opened this issue Sep 4, 2019 · 6 comments

Comments

@seviezhou
Copy link
Contributor

I use bin2llvmir to translate an ELF file and I get Globalvariables look like:

@global_var_6dbd10.1702 = global [2 x i8] c"-\00" 
@global_var_6dc940.2028 = global [2 x i8] c" \00"  
@global_var_6dc942.2029 = global [2 x i8] c" \00"

They have numbers in the terminal, it is because these Globalvariables are create in same names more than once. After looking into bin2llvmir/utils/ir_modifier.cpp file, I think I can add a single line of code and solve this problem. In function IrModifier::getGlobalVariable , and add a new piece of code after line 687:

		auto* conv = IrModifier::convertConstantToType(ngv, gv->getType());
		if (conv != gv)
		{
			gv->replaceAllUsesWith(conv);
		}
		gv->eraseFromParent();
		gv = ngv;

+		ngv->setName(name);
        }

Then we can get:

@global_var_6dbd10.1702 = global [2 x i8] c"-\00" 
@global_var_6dc940.2028 = global [2 x i8] c" \00"  
@global_var_6dc942.2029 = global [2 x i8] c" \00"
@s3rvac
Copy link
Member

s3rvac commented Sep 4, 2019

Hi! The current and new outputs look identical (see the two red rectangles below). Could you please verify that the new output is correct?

Screenshot:
diff

@seviezhou
Copy link
Contributor Author

My mistake, I wrongly paste the original output, the new is here:

@global_var_6dbd10 = global [2 x i8] c"-\00"
@global_var_6dc940 = global [2 x i8] c" \00"
@global_var_6dc942 = global [2 x i8] c" \00"

@s3rvac
Copy link
Member

s3rvac commented Sep 4, 2019

Thank you. @PeterMatula, what do you think about this?

@xkubov
Copy link
Contributor

xkubov commented Sep 9, 2019

Hi, I've tried the change in ir_modifier.cpp suggested by @seviezhou and all regression tests will pass. Furthermore, I've looked into decompilation output of some regression tests and decompilation seems to be improved because now in some cases the C code output includes comments about the address of a global variable.

For example you can see the code taken from decompilation of bashbot sample in retdec-regression-tests:

before modification:

  // --------------------- Global Variables ---------------------
  
  int32_t g1 = 0; // ebp
  int32_t g2 = 0; // ebx
  int32_t g3 = 0; // edi         
  int32_t g4 = 0; // esi
  int32_t g5 = 0; // esp
  int32_t g6 = 0x200072;
  char (*g7)[20] = "188.209.52.143:8080";
  int32_t g8 = -1;
  uint32_t g9 = 0x587c4;
  int32_t g10 = 4095;
  char * g11;
  int32_t g12 = 0;
  int32_t g13 = 0;
  char * g14;
  int32_t g15 = 0;
  int32_t g16 = 0;
  int32_t g17 = 0;
  char * g18;         
  char g19 = 0;
  char g20 = 0;
  char g21 = 0;
  char g22 = 0;
  char g23 = 0;
  int32_t g24 = 0;
  int32_t g25 = 0;
  int32_t g26 = 0;
  int32_t g27;
  int32_t g28;

after modification:

 // --------------------- Global Variables ---------------------
  
  int32_t g1 = 0; // eax
  int32_t g2 = 0; // ebp
  int32_t g3 = 0; // ebx
  int32_t g4 = 0; // edi
  int32_t g5 = 0; // esi
  int32_t g6 = 0; // esp
  int32_t g7 = -1; // 0x804f1e0
  int32_t g8 = 0x200072; // 0x804f853
  int32_t g9 = -1; // 0x8051058
  bool g10 = true; // 0x8051060
  int32_t g11 = 0; // 0x8051064
  char (*g12)[20] = "188.209.52.143:8080"; // 0x8051260
  int32_t g13 = -1; // 0x8051264
  uint32_t g14 = 0x587c4; // 0x8051364
  int32_t g15 = 4095; // 0x8051368
  char g16 = 0; // 0x8051380
  int32_t g17 = 0; // 0x8051384
  char * g18; // 0x80513a0
  int32_t g19 = 0; // 0x80513a8
  int32_t g20 = 0; // 0x80513ac
  char * g21; // 0x80513b0
  int32_t g22 = 0; // 0x80513c0
  int32_t g23 = 0; // 0x80513c4
  int32_t g24 = 0; // 0x80513c8
  char * g25; // 0x80553c0
  char g26 = 0; // 0x80553c5
  char g27 = 0; // 0x80553c6
  char g28 = 0; // 0x80553c7
  char g29 = 0; // 0x80553c8
  char g30 = 0; // 0x80553c9
  int32_t g31 = 0; // 0x80553cc
  int32_t g32 = 0; // 0x80553d0
  int32_t g33 = 0; // 0x80553d4
  int32_t g34;
  int32_t g35;

@PeterMatula
Copy link
Collaborator

Looks ok. Will you open a Pull Request, or should we do the change? No problem either way.

seviezhou added a commit to seviezhou/retdec that referenced this issue Sep 10, 2019
PeterMatula pushed a commit that referenced this issue Sep 11, 2019
PeterMatula added a commit to avast/retdec-regression-tests that referenced this issue Sep 11, 2019
@PeterMatula
Copy link
Collaborator

Fixed. Regression test added in avast/retdec-regression-tests@7523176.

PeterMatula added a commit to avast/retdec-regression-tests that referenced this issue Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants