/*
 * PYC patcher
 *
 * Gets the modification time of one file and puts it in the header of
 * a .pyc file
 *
 * Uses? many ;)    dreyer
 */


#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>



int main(int argc, char *argv[]) {
    int fd;
    struct stat sf;

    printf("PYCPATCH - \033[1;33mdreyer\033[0m '05\n");
    printf("Modifies file.pyc to not recompile its contents from file.py\n");
    if(argc!=3) {
        fprintf(stderr,"Usage: %s file.py file.pyc\n",argv[0]);
	exit(1);
    }
    if(stat(argv[1],&sf)) {
        fprintf(stderr,"[-] error while doing stat on %s\n",argv[1]);
	exit(1);
    }
    fd=open(argv[2],O_WRONLY); 
    if(fd==-1) {
        fprintf(stderr,"[-] error while while opening %s\n",argv[2]);
	exit(1);
    }
    printf("[+] Modifying data on %s(fd=%d)\n",argv[2],fd);
    if(!lseek(fd,4,SEEK_SET)) {
        fprintf(stderr,"[-] error while seeking\n");
    }
    if(write(fd,(char *)&sf.st_mtime,sizeof(time_t))==-1) {
        perror("mec");
	exit(1);
    }
    close(fd);
}

