Created
July 6, 2018 12:42
-
-
Save tuliopaim/a6744e0aa2d9cfebe062531b3a920cc7 to your computer and use it in GitHub Desktop.
SB lab22 ex3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| typedef int (*FuncPtr)(int); | |
| unsigned char codigo[] = { | |
| 0x55, | |
| 0x48, 0x89, 0xe5, | |
| 0x48, 0x83, 0xec, 0x10, | |
| 0x89, 0x7d, 0xfc, | |
| 0x8b, 0x45, 0xfc, | |
| 0x89, 0xc7, | |
| 0xe8, 0x00, 0x00, 0x00, 0x00, | |
| 0xc9, | |
| 0xc3 | |
| }; | |
| int sum(int v) { return v+2; } | |
| int mul(int v) { return 2*v; } | |
| int main(){ | |
| int i; | |
| FuncPtr f; | |
| long addsum = (long)∑ | |
| long addprox = (long)&codigo[21]; | |
| long disp = addsum - addprox; | |
| //printf("%ld\n", disp); | |
| //--------------------------------------- | |
| // Deslocamento de “sum” aqui | |
| //--------------------------------------- | |
| // Chama a função | |
| int *ptr = (int*)&codigo[17]; | |
| *ptr = (int)disp; | |
| //printf("%d\n", *ptr); | |
| f = (FuncPtr)codigo; | |
| i = f(10); | |
| printf("%d\n", i); | |
| //--------------------------------------- | |
| // Deslocamento de “mul” aqui | |
| //--------------------------------------- | |
| // Chama a função | |
| //f = (FuncPtr)codigo; | |
| //i = f(10); | |
| //printf("%d\n", i); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment