Here is what I am trying to do:
Suppose you have two filters
void f1(int *v) { *v = 55; } void f2(int *v) { *v = 44; } char *template; template = allocExecutablePages(...); char *allocExecutablePages (int pages) { template = (char *) valloc (getpagesize () * pages); if (mprotect (template, getpagesize (), PROT_READ|PROT_EXEC|PROT_WRITE) == -1) { perror ("mprotect"); } }
I would like to make a comparison between f1 and f2 (so tell me what is identical and what is not) (so we get the conveyor lines of this function and do a line-by-line comparison) And then put this line in my template.
Is there a way in C to do this?
thanks
Update
Thank you for all that you answered the guys, but maybe I did not correctly explain my need.
Basically I am trying to write a small obfuscation method. The idea is to allow two or more functions to share the same memory location. The memory area (which we will call the template) is configured, containing some of the machine codes of bytes from the functions, or rather, those that they all have in common. Before executing a specific function, editing a script is used to fix the template with the necessary bytes of machine code to create a full version of this function. When another function is assigned to the same template to be executed, the process repeats, this time using another editing script. To illustrate this, suppose you want to confuse which contains two functions f1 and f2. The first (f1) has the following machine byte codes
Address Machine code 0 10 1 5 2 6 3 20 and the second one (f2) has Address Machine code 0 10 1 9 2 3 3 20 At obfuscation time, one will replace f1 and f2 by the template Address Machine code 0 10 1 ? 2 ? 3 20 and by the two edit scripts e1 = {1 becomes 5, 2 becomes 6} and e2 = {1 becomes 9, 2 becomes 3}.
So I need to write a diff function. which will take the addresses of my two functions and will generate a template with an associated script.
That's why I would like to compare bytes by bytes, my two functions
Sorry for my first post, which was not very clear!
thanks