Version OK. TAF : Revoir la recherche de l'adresse dans la pile et les cast, faire le changement de clefs

This commit is contained in:
Paul Faure 2021-03-12 23:19:56 +01:00
parent f3f0dd37d9
commit de7e4a2bd3
4 changed files with 150 additions and 0 deletions

107
lib/rondoudouPatch.c Normal file
View file

@ -0,0 +1,107 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "rondoudouPatch.h"
//WARNING SUR TOUT LES TYPES !!!
struct t_pile_addrs {
int index;
void ** tab[TAB_SIZE];
struct t_pile_addrs * next;
};
uintptr_t rondoudou_patch_key;
struct t_pile_addrs * pile_addrs;
void rondoudou_patch_init(void) {
pile_addrs = (struct t_pile_addrs *)malloc(sizeof(struct t_pile_addrs));
pile_addrs->index = -1;
pile_addrs->next = NULL;
rondoudou_patch_key = 12345;
}
int print_pile_aux(int profondeur, struct t_pile_addrs * pile) {
if (pile != NULL) {
int prof_max = print_pile_aux(profondeur + 1, pile->next);
int i;
int max;
if (pile->index != TAB_SIZE) {
max = pile->index + 1;
} else {
max = TAB_SIZE;
}
for (i = 0; i<max; i++) {
printf("%d -> %p\n", (prof_max - profondeur)*TAB_SIZE + i, pile->tab[i]);
}
return prof_max;
} else {
return profondeur - 1;
}
}
void print_pile(void) {
print_pile_aux(0, pile_addrs);
}
/*
*
* ATTENTION !!!!! FONCTION ULTRA CHELOUE
*
*/
void ** find_address_in_stack(void * addr) {
void ** ret = 0;
int trouve = 0;
int i;
for (i=0; i<1000; i++) {
if ((*(&ret + i)) == addr) {
if (trouve) {
ret = (void **)(&ret + i);
break;
}
trouve = 1;
}
}
return ret;
}
void cipher(void * address) {
void ** addr = find_address_in_stack(address);
if (addr != 0) {
*addr = (void *)((uintptr_t)*addr ^ (uintptr_t)rondoudou_patch_key);
if ((pile_addrs->index) == (TAB_SIZE - 1)) {
struct t_pile_addrs * aux = (struct t_pile_addrs *)malloc(sizeof(struct t_pile_addrs));
aux->index = 0;
aux->next = pile_addrs;
pile_addrs = aux;
} else {
pile_addrs->index++;
}
pile_addrs->tab[pile_addrs->index] = addr;
printf("APPEL A CIPHER\n");
print_pile();
}
}
void decipher(void) {
if (pile_addrs->index == -1) {
if (pile_addrs->next == NULL) {
printf("Ouille ouille ouille qu'est ce que j'ai mal aux nouilles ! \n");
exit(2);
} else {
struct t_pile_addrs * aux = pile_addrs;
pile_addrs = pile_addrs->next;
free(aux);
}
}
*((pile_addrs->tab)[pile_addrs->index]) = (void *)((uintptr_t)(*((pile_addrs->tab)[pile_addrs->index])) ^ (uintptr_t)rondoudou_patch_key);
pile_addrs->index--;
printf("APPEL A DECIPHER\n");
print_pile();
}
void changekey(void);

7
lib/rondoudouPatch.h Normal file
View file

@ -0,0 +1,7 @@
#define TAB_SIZE 3
void cipher(void * addr);
void decipher(void);
void changekey(void);
void rondoudou_patch_init(void);

BIN
lib/test Executable file

Binary file not shown.

36
lib/test_chiffrement.c Normal file
View file

@ -0,0 +1,36 @@
#include "rondoudouPatch.h"
#include <stdio.h>
void f() {
cipher(__builtin_return_address(0));
printf("Dans f()\n");
decipher();
}
void g() {
cipher(__builtin_return_address(0));
printf("Dans g()\n");
f();
decipher();
}
void h() {
cipher(__builtin_return_address(0));
printf("Dans h()\n");
g();
decipher();
}
void i() {
cipher(__builtin_return_address(0));
printf("Dans i()\n");
h();
decipher();
}
int main() {
rondoudou_patch_init();
cipher(__builtin_return_address(0));
i();
decipher();
}