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

Intial work on type propgation #10451

Merged
merged 1 commit into from
Jun 23, 2018
Merged

Conversation

sivaramaaa
Copy link
Contributor

@sivaramaaa sivaramaaa commented Jun 22, 2018

C source code :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main() {
	int length, length2;
	char *final;
	char *s1 = "Hello";
	char *s2 = "World";

	length = strlen (s1);
	length2 = strlen (s2);
        if (length == length2) {
           ...
        }
	....
}

r2 output

/ (fcn) sym.main 157
|   sym.main ();
|           ; var size_t local_20h @ rbp-0x20
|           ; var size_t size @ rbp-0x1c
|           ; var char *src @ rbp-0x18
|           ; var char *s2 @ rbp-0x10
|           ; var char *dest @ rbp-0x8

|           0x000007aa      55             push rbp
|           0x000007ab      4889e5         mov rbp, rsp
|           0x000007ae      4883ec20       sub rsp, 0x20
|           0x000007b2      488d051b0100.  lea rax, str.Hello          ; 0x8d4 ; "Hello"
|           0x000007b9      488945e8       mov qword [src], rax
|           0x000007bd      488d05160100.  lea rax, str.r2_folks       ; 0x8da ; " r2-folks"
|           0x000007c4      488945f0       mov qword [s2], rax
|           0x000007c8      488b45e8       mov rax, qword [src]
|           0x000007cc      4889c7         mov rdi, rax   
  • Tested with ELF - x86 arch for both 32 bit and 64 bit binaries

  • Yet has to test for various architecture and lot's of improvement has to be done, which will be dealt in subsequent PR's

  • Added test to r2r #1369

@radare radare merged commit 31eeef0 into radareorg:master Jun 23, 2018
}
// longer name tends to be meaningful like "src" instead of "s1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

char *ntype = type;
if (!strncmp (type, "const ", 6)) {
// Droping const from type
//TODO: Infering const type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to check how constant propagation works, could be helpful in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup sure !

@sivaramaaa sivaramaaa deleted the type-inference branch July 2, 2018 12:07
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

Successfully merging this pull request may close these issues.

3 participants