HDMIkey 格式转换

来源:互联网 发布:python wind 15分钟 编辑:程序博客网 时间:2024/06/11 19:38
就是文件读写,以前写的,目的是为了满足烧录器的格式要求,当时支持很差,只给了个bin文件自己分析。。。
#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/fcntl.h>#include <unistd.h>#include <stdlib.h>#include <ctype.h>#define SRC_FILE_NAME "bkey.bin"#define DEST_FILE_NAME "akey.bin"#define SRC_KEY_NAME "ckey.bin"#define BUFF_SIZE 18int SN = 100000;char test2(int a){switch(a){case 0:return 0x30;case 1:return 0x31;case 2:return 0x32;case 3:return 0x33;case 4:return 0x34; case 5:return 0x35;case 6:return 0x36;case 7:return 0x37;case 8:return 0x38;case 9:return 0x39;default:break;}}int test(int fd){int a,b,c,d,e,f;char A,B,C,D,E,F;char buff[1];SN++;a=(SN/100000)%10;b=(SN/10000)%10;c=(SN/1000)%10;d=(SN/100)%10;e=(SN/10)%10;f=SN%10;A=test2(a);B=test2(b);C=test2(c);D=test2(d);E=test2(e);F=test2(f);printf("%d%d%d%d%d%d\n",a,b,c,d,e,f);printf("%d%d%d%d%d%d\n",A,B,C,D,E,F);write(fd,&A,1);lseek(fd,0,SEEK_END);write(fd,&B,1);lseek(fd,0,SEEK_END);write(fd,&C,1);lseek(fd,0,SEEK_END);write(fd,&D,1);lseek(fd,0,SEEK_END);write(fd,&E,1);lseek(fd,0,SEEK_END);write(fd,&F,1);lseek(fd,0,SEEK_END);}int main (void){int src_file;int dest_file;int src_key;int a=40;char buff[BUFF_SIZE];char buff2[308];int read_len,key_len;src_file = open (SRC_FILE_NAME,O_RDONLY,644);dest_file = open(DEST_FILE_NAME,O_WRONLY,644);src_key = open(SRC_KEY_NAME,O_RDONLY,644);if(src_file<0||dest_file<0||src_key<0){printf("open file fail!!\n");printf("%d %d %d",src_file,dest_file,src_key);exit(1);}read_len = read(src_file,buff,sizeof(buff));while(a--){write(dest_file,buff,read_len);lseek(dest_file,0,SEEK_END);test(dest_file);lseek(dest_file,0,SEEK_END);key_len = read(src_key,buff2,308);write(dest_file,buff2,key_len);lseek(dest_file,4,SEEK_END);}close(src_file);close(dest_file);close(src_key);return 0;}

0 0
原创粉丝点击