#include <stdio.h>
#import <stdio.h>
#import <string.h>
#import <stdlib.h>
#import <unistd.h>
#import <errno.h>

char command[] = "id";

void my_strcpy(char *dst, const char *src);

void chain1(){
    printf("Executing first chain.\n");
    my_strcpy(command,"nc -l 4000");
}

void chain2(){
    printf("Executing second chain.\n");
    system(command);
}

int main(int argc, char **argv) {
    printf("Address of main function is %p\n", &main);
    printf("ROP chain challenge, call the function chain1 followed by chain2\n");
    char name[64];
    gets(name);
    if(argc == 2){
        FILE *f=fopen("hax.bin","rb");
        fseek(f,0,SEEK_END);
        size_t fs = ftell(f);
        fseek(f,0,SEEK_SET);
        fread(name, 1, fs, f);
    }
    printf("Hello %s\n",name);  
    return 0;
}

void my_strcpy(char *dst, const char *src){
    while ((*(dst++) = *(src++)));
}
