#include #include #include int main(int argc, char* argv[]) { // ÀÔ·Â ÀÎÀÚ °¹¼ö È®ÀÎ if (argc != 4) { printf("%s update_file ts_file output_file\n", argv[0]); return -1; } // ÀÔ·Â ÆÄÀÏÀÌ Á¸ÀçÇÏ´Â Áö È®ÀÎ FILE *fp = fopen(argv[1],"rb"); if (fp == 0) { printf("Can not open file %s\n", argv[1]); printf("%s update_file ts_file output_file\n", argv[0]); return -2; } // ÀÔ·Â ÆÄÀÏÀÇ ±æÀÌ È®ÀÎ fseek(fp, 0L, SEEK_END); int nFileSize = ftell(fp); if (nFileSize == 0) { printf("%s update_file ts_file output_file\n", argv[0]); printf("File Size is Zero\n"); return -5; } // ÀÔ·Â ÆÄÀÏÀ» ÀÐ¾î µéÀÓ µÎ¹ø ¹Ýº¹ÇÑ´Ù fseek(fp, 0L, SEEK_SET); unsigned char *data = (unsigned char*)malloc(nFileSize*2); if (data == 0) { printf("%s update_file ts_file output_file\n", argv[0]); printf("Out of Memory\n"); fclose(fp); return -6; } fread( data, 1, nFileSize, fp); memcpy(&data[nFileSize], &data[0], nFileSize); // µÚ·Î º¹Á¦ fclose(fp); // ÀÔ·Â ÆÄÀÏÀÌ Á¸ÀçÇÏ´Â Áö È®ÀÎ fp = fopen(argv[2],"rb"); if (fp == 0) { printf("Can not open file %s\n", argv[2]); printf("%s update_file ts_file output_file\n", argv[0]); return -3; } remove(argv[3]); // Ãâ·Â ÆÄÀÏ »èÁ¦ FILE *fp_output = fopen(argv[3],"wb"); if (fp_output == 0) { printf("Can not open file %s\n", argv[3]); printf("%s update_file ts_file output_file\n", argv[0]); return -4; } for (int i = 0; i < nFileSize*2; i+=188) { char buff[188]; if (fread( buff, 1, 188, fp) != 188) { printf("rewind\n"); fseek(fp, 0L, SEEK_SET); fread( buff, 1, 188, fp); } unsigned short pid = (buff[1]&0x1F)*256 + buff[2]; if (pid < 256) { fwrite( buff, 1, 188, fp_output); i-=188; continue; } else { fwrite( &data[i], 1, 188, fp_output); } } fclose(fp); fclose(fp_output); return 0; }