'How to edit ELF files in Linux?
I have written two similar C programs. How can I make the outputs of both code same by editing one of the ELF files not the actual code?
/**
* prg1.c
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 5;
int b = 10;
int sum;
sum = a + b;
printf("sum is %d\n", sum);
return(0);
}
/**
* prg2.c
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 5;
int b = 20;
int sum;
sum = a + b;
printf("sum is %d\n", sum);
return(0);
}
Solution 1:[1]
In your second program's elf file find the occurrence of 20 and change it to 10.
To do that you can do something like this - Find 14 (hex of 20) in your elf file and change it to A and making sure length is same by adding extra 0. To do this you can use any elf editor, I use 'Hex Fiend' for mac.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | shivam bansal |