/// This function points to a scalar reference implementation of the CRC-32C /// algorithm that yields the correct value. It is optimized for portability, /// not for speed on modern architectures. uint32_t Microslice::compute_crc() const { assert(content_ptr_); assert(desc_ptr_); boost::crc_optimal<32, 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc_32; crc_32.process_bytes(content_ptr_, desc_ptr_->size); return crc_32(); }
/** * Add a crc to a given data packet. * * @param data the packet * @param len the length of the packet * @param offset the offset where we want to write our checksum. */ void packet_add_crc(char *data, size_t len, unsigned int offset) { char *ptr = data + offset; uint32_t new_crc; uint32_t *crc_ptr = (uint32_t *)ptr; *crc_ptr = 0x00000000; new_crc = GUINT32_TO_LE(crc_32(data, len, 0xEDB88320)); *crc_ptr = new_crc; }
static bool read_nvram_data(char* buf, int max_len) { unsigned crc32 = 0xffffffff; int var_count = 0, i = 0, buf_pos = 0; #ifndef HAVE_RTC_RAM int fd = open(NVRAM_FILE, O_RDONLY); int bytes; if (fd < 0) return false; memset(buf,0,max_len); bytes = read(fd,buf,max_len); close(fd); if (bytes < 8) /* min is 8 bytes,magic, ver, vars, crc32 */ return false; #else memset(buf,0,max_len); /* read rtc block */ for (i=0; i < max_len; i++ ) buf[i] = rtc_read(0x14+i); #endif /* check magic, version */ if ((buf[0] != 'R') || (buf[1] != 'b') || (buf[2] != NVRAM_CONFIG_VERSION)) return false; /* check crc32 */ crc32 = crc_32(&buf[NVRAM_DATA_START], max_len-NVRAM_DATA_START-1,0xffffffff); if (memcmp(&crc32,&buf[4],4)) return false; /* all good, so read in the settings */ var_count = buf[3]; buf_pos = NVRAM_DATA_START; for(i=0; i<nb_settings; i++) { int nvram_bytes = (settings[i].flags&F_NVRAM_BYTES_MASK) >>F_NVRAM_MASK_SHIFT; if (nvram_bytes) { if ((var_count>0) && (buf_pos<max_len)) { memcpy(settings[i].setting,&buf[buf_pos],nvram_bytes); buf_pos += nvram_bytes; var_count--; } else /* should only happen when new items are added to the end */ { memcpy(settings[i].setting, &settings[i].default_val, nvram_bytes); } } } return true; }
static bool write_nvram_data(char* buf, int max_len) { unsigned crc32 = 0xffffffff; int i = 0, buf_pos = 0; char var_count = 0; #ifndef HAVE_RTC_RAM int fd; #endif memset(buf,0,max_len); /* magic, version */ buf[0] = 'R'; buf[1] = 'b'; buf[2] = NVRAM_CONFIG_VERSION; buf_pos = NVRAM_DATA_START; for(i=0; (i<nb_settings) && (buf_pos<max_len); i++) { int nvram_bytes = (settings[i].flags&F_NVRAM_BYTES_MASK) >>F_NVRAM_MASK_SHIFT; if (nvram_bytes) { memcpy(&buf[buf_pos],settings[i].setting,nvram_bytes); buf_pos += nvram_bytes; var_count++; } } /* count and crc32 */ buf[3] = var_count; crc32 = crc_32(&buf[NVRAM_DATA_START], max_len-NVRAM_DATA_START-1,0xffffffff); memcpy(&buf[4],&crc32,4); #ifndef HAVE_RTC_RAM fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY, 0666); if (fd >= 0) { int len = write(fd,buf,max_len); close(fd); if (len < 8) return false; } #else /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so that it would write a number of bytes at a time since the RTC chip supports that, but this will have to do for now 8-) */ for (i=0; i < NVRAM_BLOCK_SIZE; i++ ) { int r = rtc_write(0x14+i, buf[i]); if (r) return false; } #endif return true; }
void printChosen(char* s, unsigned size, struct information info) { printf("Length: %u bytes\n", size-1); if(info.hex) { if(info.doXor) printf("XOR: 0x%02x\n", xor_hash(s, size)); if(info.doCrc16) printf("CRC-16: 0x%04x\n", crc_16(s, size)); if(info.doCrc32) printf("CRC-32: 0x%08x\n", crc_32(s, size)); } else { if(info.doXor) printf("XOR: %u\n", xor_hash(s, size)); if(info.doCrc16) printf("CRC-16: %u\n", crc_16(s, size)); if(info.doCrc32) printf("CRC-32: %u\n", crc_32(s, size)); } if(info.doMd5) { printf("MD5: "); printMD5(s, size); printf("\n"); } }
/* ts A90830 : changed return type to int @return 0= failure 1= success */ int sector_headers(struct burn_write_opts *o, unsigned char *out, int mode, int leadin) { #ifdef Libburn_ecma130ab_includeD struct burn_drive *d = o->drive; unsigned int crc; int min, sec, frame; int modebyte = -1; int ret; ret = sector_headers_is_ok(o, mode); if (ret != 2) return !!ret; modebyte = 1; out[0] = 0; memset(out + 1, 0xFF, 10); /* sync */ out[11] = 0; if (leadin) { burn_lba_to_msf(d->rlba, &min, &sec, &frame); out[12] = dec_to_bcd(min) + 0xA0; out[13] = dec_to_bcd(sec); out[14] = dec_to_bcd(frame); out[15] = modebyte; } else { burn_lba_to_msf(d->alba, &min, &sec, &frame); out[12] = dec_to_bcd(min); out[13] = dec_to_bcd(sec); out[14] = dec_to_bcd(frame); out[15] = modebyte; } if (mode & BURN_MODE1) { #ifdef Libburn_no_crc_C crc = 0; /* dummy */ #else crc = crc_32(out, 2064); #endif out[2064] = crc & 0xFF; crc >>= 8; out[2065] = crc & 0xFF; crc >>= 8; out[2066] = crc & 0xFF; crc >>= 8; out[2067] = crc & 0xFF; }
/* No need to access it from outside */ static struct message1 * encode_connection_request(struct connection_request * req) { struct message1 * msg; msg = (struct message1 *)calloc(1, sizeof(struct message1)); msg->function = GUINT32_TO_LE(0x0003bef4); msg->counter = GUINT32_TO_LE(1); msg->client_size = 9; memcpy(msg->client, "TeamSpeak", 9); /* cut machine if too long */ if(strlen(req->machine) > 29) req->machine[29] = '\0'; msg->machine_size = (uint8_t)strlen(req->machine); memcpy(msg->machine, req->machine, strlen(req->machine)); msg->data1 = GUINT32_TO_LE(0x02000000); msg->data2 = GUINT32_TO_LE(0x20003C00); msg->assign_nick = req->assign_nick; msg->always1 = 0x01; /* Insert login */ if(strlen(req->login) > 29) req->login[29] = '\0'; msg->login_size = (uint8_t)strlen(req->login); memcpy(msg->login, req->login, strlen(req->login)); /* Insert password */ if(strlen(req->pass) > 29) req->pass[29] = '\0'; msg->pass_size = (uint8_t)strlen(req->pass); memcpy(msg->pass, req->pass, strlen(req->pass)); /* Insert nick */ if(strlen(req->nick) > 29) req->nick[29] = '\0'; msg->nick_size = (uint8_t)strlen(req->nick); memcpy(msg->nick, req->nick, strlen(req->nick)); msg->checksum = GINT32_TO_LE(crc_32(msg, sizeof(struct message1), 0xEDB88320)); return msg; }
/** * Check the crc of a packet * * @param data the packet * @param len the length of the packet * @param offset the offset where the checksum is located. */ int packet_check_crc(char *data, size_t len, unsigned int offset) { char *buff, *ptr; uint32_t old_crc; uint32_t new_crc; uint32_t *crc_ptr; buff = (char *)calloc(len, sizeof(char)); if (buff == NULL) { printf("(WW) packet_check_crc, buffer allocation failed : %s.\n", strerror(errno)); return 0; } memcpy(buff, data, len); ptr = buff + offset; crc_ptr = (uint32_t *)ptr; old_crc = *crc_ptr; *crc_ptr = 0x00000000; new_crc = GUINT32_TO_LE(crc_32(buff, len, 0xEDB88320)); free(buff); return new_crc == old_crc; }
int make_LUH() { FILE *fp_luh,*f_su; struct multi_file_crc files; int k,i,m; int luh_file_length; int luh_fpos; int len,ret; uint64_t len_64; unsigned int su_len; unsigned short length,nu_tar,nu_with,nu_posi,nu_file; unsigned short file_num; unsigned short load_count; unsigned short check_type,check_type_temp; unsigned short crc_type_8,crc_type_16,crc_type_32; unsigned short data_crc_8[10],sup_crc_8[10],multi_crc8; unsigned short data_crc_16[10],sup_crc_16[10]; unsigned short sup_total_crc_16,multi_crc16,header_file_crc; unsigned int data_crc_32[10],sup_crc_32[10]; unsigned int multi_crc32,load_crc; char *ch; char s[15]="load_"; char path_name[50],luh_name[70],data_name[70],sup_name[70]; char target_ID[10][30]= { "luh_target_ID_001","luh_target_ID_002","luh_target_ID_003", "luh_target_ID_004","luh_target_ID_005", "luh_target_ID_006","luh_target_ID_007","luh_target_ID_008", "luh_target_ID_009","luh_target_ID_010" }; char target_with_position[10][40]= { "luh_target_with_position_001","luh_target_with_position_002","luh_target_with_position_003", "luh_target_with_position_004","luh_target_with_position_005", "luh_target_with_position_006","luh_target_with_position_007","luh_target_with_position_008", "luh_target_with_position_009","luh_target_with_position_010" }; char number_target_position[10][40]= { "luh_number_target_position_001","luh_number_target_position_002","luh_number_target_position_003", "luh_number_target_position_004","luh_number_target_position_005", "luh_number_target_position_006","luh_number_target_position_007","luh_number_target_position_008", "luh_number_target_position_009","luh_number_target_position_010" }; char position[10][5][30]= { {"luh_position_001_001","luh_position_001_002","luh_position_001_003","luh_position_001_004","luh_position_001_005"}, {"luh_position_002_001","luh_position_002_002","luh_position_002_003","luh_position_002_004","luh_position_002_005"}, {"luh_position_003_001","luh_position_003_002","luh_position_003_003","luh_position_003_004","luh_position_003_005"}, {"luh_position_004_001","luh_position_004_002","luh_position_004_003","luh_position_004_004","luh_position_004_005"}, {"luh_position_005_001","luh_position_005_002","luh_position_005_003","luh_position_005_004","luh_position_005_005"}, {"luh_position_006_001","luh_position_006_002","luh_position_006_003","luh_position_006_004","luh_position_006_005"}, {"luh_position_007_001","luh_position_007_002","luh_position_007_003","luh_position_007_004","luh_position_007_005"}, {"luh_position_008_001","luh_position_008_002","luh_position_008_003","luh_position_008_004","luh_position_008_005"}, {"luh_position_009_001","luh_position_009_002","luh_position_009_003","luh_position_009_004","luh_position_009_005"}, {"luh_position_010_001","luh_position_010_002","luh_position_010_003","luh_position_010_004","luh_position_010_005"} }; /***************data file*******************/ char data_file_p[10][30]= { "0x0000","0x0000","0x0000", "0x0000","0x0000", "0x0000","0x0000","0x0000", "0x0000","0x0000" }; char data_file_name[10][30]= { "luh_data_file_name_001","luh_data_file_name_002","luh_data_file_name_003", "luh_data_file_name_004","luh_data_file_name_005", "luh_data_file_name_006","luh_data_file_name_007","luh_data_file_name_008", "luh_data_file_name_009","luh_data_file_name_010" }; char data_file_PN[10][30]= { "luh_data_file_PN_001","luh_data_file_PN_002","luh_data_file_PN_003", "luh_data_file_PN_004","luh_data_file_PN_005", "luh_data_file_PN_006","luh_data_file_PN_007","luh_data_file_PN_008", "luh_data_file_PN_009","luh_data_file_PN_010" }; char data_check_value_type[10][40]= { "luh_data_file_check_value_type_001","luh_data_file_check_value_type_002","luh_data_file_check_value_type_003", "luh_data_file_check_value_type_004","luh_data_file_check_value_type_005", "luh_data_file_check_value_type_006","luh_data_file_check_value_type_007","luh_data_file_check_value_type_008", "luh_data_file_check_value_type_009","luh_data_file_check_value_type_010" }; /***************support file*******************/ char support_file_p[10][30]= { "0x0000","0x0000","0x0000", "0x0000","0x0000", "0x0000","0x0000","0x0000", "0x0000","0x0000" }; char support_file_name[10][30]= { "luh_support_file_name_001","luh_support_file_name_002","luh_support_file_name_003", "luh_support_file_name_004","luh_support_file_name_005", "luh_support_file_name_006","luh_support_file_name_007","luh_support_file_name_008", "luh_support_file_name_009","luh_support_file_name_010" }; char support_file_PN[10][30]= { "luh_support_file_PN_001","luh_support_file_PN_002","luh_support_file_PN_003", "luh_support_file_PN_004","luh_support_file_PN_005", "luh_support_file_PN_006","luh_support_file_PN_007","luh_support_file_PN_008", "luh_support_file_PN_009","luh_support_file_PN_010" }; char support_check_value_type[10][40]= { "luh_support_file_check_value_type_001","luh_support_file_check_value_type_002","luh_support_file_check_value_type_003", "luh_support_file_check_value_type_004","luh_support_file_check_value_type_005", "luh_support_file_check_value_type_006","luh_support_file_check_value_type_007","luh_support_file_check_value_type_008", "luh_support_file_check_value_type_009","luh_support_file_check_value_type_010" }; ret=select_section("[media_set]"); if(FAILED==ret) { printf("select_section error\n"); return FAILED; } ch=get_config_var("load_count"); if(ch==NULL) { printf("get load_count error\n"); return FAILED; } load_count=htoi(ch); for(m=1;m<=load_count;m++)//make multi luh files { sprintf(s,"[load_%.3d]",m); //printf("s=%s\n",s); ret=select_section(s); if(FAILED==ret) { printf("select_section error\n"); return FAILED; } strcpy(path_name,"./media665-3"); ch=get_config_var("load_path"); if(ch==NULL) { printf("get load_path error\n"); return FAILED; } change_symbol(ch); strcat(path_name,ch); ch=get_config_var("head_file_name"); if(ch==NULL) { printf("get head_file_name error\n"); return FAILED; } strcpy(luh_name,path_name); strcat(luh_name,ch); fp_luh=fopen(luh_name, "wb+"); if (NULL == fp_luh) { printf("can't open '%s' as config file:%s\n",fp_luh,strerror(errno)); goto EXIT; } /********make LUH**********/ fseek(fp_luh,4,0);//the leading four bytes is file length ch=get_config_var("luh_file_version"); if(ch==NULL) { printf("get luh_file_version error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_part_flags"); if(ch==NULL) { printf("get luh_part_flags error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_PN_length"); if(ch==NULL) { printf("get luh_p_PN_length error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_target_ID"); if(ch==NULL) { printf("get luh_p_target_ID error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_number_data_file"); if(ch==NULL) { printf("get luh_p_number_data_file error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_number_support_file"); if(ch==NULL) { printf("get luh_p_number_support_file error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_user_defined_data"); if(ch==NULL) { printf("get luh_p_user_defined_data error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_type_description_length"); if(ch==NULL) { printf("get luh_p_type_description_length error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_number_target_positions"); if(ch==NULL) { printf("get luh_p_number_target_positions error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_check_value_length"); if(ch==NULL) { printf("get luh_p_check_value_length error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_load_PN"); if(ch==NULL) { printf("get luh_load_PN error\n"); return FAILED; } length=htons(strlen(ch)); ret=fwrite(&length,sizeof(short),1,fp_luh);//write PN length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write load PN if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if((strlen(ch)%2)!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } }//if odd ,add 0x00 ch=get_config_var("luh_type_description"); if(ch==NULL) { printf("get luh_type_description error\n"); } length=htons(strlen(ch)); fwrite(&length,sizeof(short),1,fp_luh);//write description length if(ret<0) { printf("fwrite error\n"); } ret=fwrite_chars(ch,fp_luh);//write description if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } ch=get_config_var("luh_type_ID"); if(ch==NULL) { printf("get luh_type_ID error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_number_target_ID"); if(ch==NULL) { printf("get luh_number_target_ID error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } nu_tar=htoi(ch); for(k=0;k<nu_tar;k++) //number of target HW ID { ch=get_config_var(target_ID[k]); if(ch==NULL) { printf("get target_ID error\n"); return FAILED; } length=htons(strlen(ch)); fwrite(&length,sizeof(short),1,fp_luh);//write position length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write target id if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } } ch=get_config_var("luh_number_target_with_position"); if(ch==NULL) { printf("get luh_number_target_with_position error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } nu_with=htoi(ch); for(k=0;k<nu_with;k++) //number of target HW ID with position循环 { ch=get_config_var(target_with_position[k]); if(ch==NULL) { printf("get target_with_position error\n"); return FAILED; } length=htons(strlen(ch)); fwrite(&length,sizeof(short),1,fp_luh);//write length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write target with position if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } ch=get_config_var(number_target_position[k]); if(ch==NULL) { printf("get number_target_position error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } nu_posi=htoi(ch); for(i=0;i<nu_posi;i++) //number of target HW ID position { ch=get_config_var(position[k][i]); if(ch==NULL) { printf("get position error\n"); return FAILED; } length=htons(strlen(ch)); fwrite(&length,sizeof(short),1,fp_luh);//write length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write position if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } } } crc_type_8=htons(CRC_8_TYPE); crc_type_16=htons(CRC_16_TYPE); crc_type_32=htons(CRC_32_TYPE); /***************data file*******************/ #if 1 ch=get_config_var("luh_number_data_file"); if(ch==NULL) { printf("get luh_number_data_file error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } file_num=htoi(ch); for(k=0;k<file_num;k++) { ret=fwrite_atohex(data_file_p[k],fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var(data_file_name[k]); if(ch==NULL) { printf("get data_file_name error\n"); return FAILED; } //printf("k=%d\n",k); strcpy(data_name,path_name); strcat(data_name,ch); //printf("data_name=%s\n",data_name); strcpy(files.data_file_name[k],data_name); length=htons(strlen(ch)); ret=fwrite(&length,sizeof(short),1,fp_luh);//write file name length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write name if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } ch=get_config_var(data_file_PN[k]); if(ch==NULL) { printf("get data_file_PN error\n"); return FAILED; } length=htons(strlen(ch)); ret=fwrite(&length,sizeof(short),1,fp_luh);//write data PN length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write data PN if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } len=calculate_file_length_32(data_name); if(len%2!=0) { len=(len+1)/2; } else { len=len/2; } len=htonl(len); ret=fwrite(&len,sizeof(int),1,fp_luh);//write data file length if(ret<0) { printf("fwrite error\n"); return FAILED; } data_crc_16[k]=crc_16(data_name); //CRC_16校验 printf("data_crc_16[%d]=0x%x\n",k,data_crc_16[k]); data_crc_16[k]=htons(data_crc_16[k]); ret=fwrite(&data_crc_16[k],sizeof(short),1,fp_luh); if(ret<0) { printf("fwrite error\n"); return FAILED; } len_64=calculate_file_length_64(data_name); //printf("*****data file length_64: %x\n",len); len_64=hton64(len_64);//big end or small end //printf("*****change data file length_64: %llx\n",len); ret=fwrite(&len_64,sizeof(char),8,fp_luh); //write data file length in bytes if(ret<0) { printf("fwrite error\n"); return FAILED; } ch=get_config_var(data_check_value_type[k]); if(ch==NULL) { printf("get data_check_value_type error\n"); return FAILED; } check_type=chtoshort_hex(ch); //printf("data file check type=0x%x\n",check_type); check_type_temp=htons(check_type); switch(check_type) { case 1: ret=fwrite(&crc_type_8,sizeof(short),1,fp_luh);//write data check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write data check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } data_crc_8[k]=crc_8(data_name); //printf("data_crc_8[%d]=0x%x\n",k,data_crc_8[k]); data_crc_8[k]=htonl(data_crc_8[k]); ret=fwrite(&data_crc_8[k],sizeof(char),1,fp_luh);//write data check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 2: ret=fwrite(&crc_type_16,sizeof(short),1,fp_luh);//write data check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write data check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&data_crc_16[k],sizeof(short),1,fp_luh);//write data check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 3: ret=fwrite(&crc_type_32,sizeof(short),1,fp_luh);//write data check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write data check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } data_crc_32[k]=crc_32(data_name); //printf("data_crc_32[%d]=0x%x\n",k,data_crc_32[k]); data_crc_32[k]=htonl(data_crc_32[k]); ret=fwrite(&data_crc_32[k],sizeof(int),1,fp_luh);//write data check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; default: ; } } #endif /*******support file*********/ ch=get_config_var("luh_number_support_file"); if(ch==NULL) { printf("get luh_number_support_file error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } nu_file=htoi(ch); for(k=0;k<nu_file;k++) //number of support files { ret=fwrite_atohex(support_file_p[k],fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var(support_file_name[k]); if(ch==NULL) { printf("get support_file_name error\n"); return FAILED; } strcpy(sup_name,path_name); strcat(sup_name,ch); //printf("sup_name=%s\n",sup_name); strcpy(files.su_file_name[k],sup_name); f_su=fopen(sup_name,"r"); if(f_su==NULL) { printf("can`t open support file\n"); return FAILED; } length=htons(strlen(ch)); ret=fwrite(&length,sizeof(short),1,fp_luh);//write support file name length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write name if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } ch=get_config_var(support_file_PN[k]); if(ch==NULL) { printf("get support_file_PN error\n"); return FAILED; } length=htons(strlen(ch)); ret=fwrite(&length,sizeof(short),1,fp_luh);//write PN length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write PN if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } fseek(f_su,0,2);//move to the file end su_len=ftell(f_su); su_len=htonl(su_len); ret=fwrite(&su_len,sizeof(unsigned int),1,fp_luh);//write support file length if(ret<0) { printf("fwrite error\n"); return FAILED; } rewind(f_su);//move to the file start fclose(f_su); sup_crc_16[k]=crc_16(sup_name); sup_crc_16[k]=htons(sup_crc_16[k]); ret=fwrite(&sup_crc_16[k],sizeof(short),1,fp_luh);//write support file crc if(ret<0) { printf("fwrite error\n"); return FAILED; } //printf("sup_crc_16[%d]=0x%x\n",k,sup_crc_16[k]); ch=get_config_var(support_check_value_type[k]); if(ch==NULL) { printf("get support_check_value_type error\n"); return FAILED; } check_type=chtoshort_hex(ch); //printf("support file check type=0x%x\n",check_type); check_type_temp=htons(check_type); switch(check_type) { case 1: ret=fwrite(&crc_type_8,sizeof(short),1,fp_luh); if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh); if(ret<0) { printf("fwrite error\n"); return FAILED; } sup_crc_8[k]=crc_8(sup_name); //printf("sup_crc_8[%d]=0x%x\n",k,sup_crc_8[k]); sup_crc_8[k]=htonl(sup_crc_8[k]); ret=fwrite(&sup_crc_8[k],sizeof(char),1,fp_luh); if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 2: ret=fwrite(&crc_type_16,sizeof(short),1,fp_luh);//write support check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write support check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&sup_crc_16[k],sizeof(short),1,fp_luh);//write support check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 3: ret=fwrite(&crc_type_32,sizeof(short),1,fp_luh);//write support check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write support check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } sup_crc_32[k]=crc_32(sup_name); // printf("sup_crc_32[%d]=0x%x\n",k,sup_crc_32[k]); sup_crc_32[k]=htonl(sup_crc_32[k]); ret=fwrite(&sup_crc_32[k],sizeof(int),1,fp_luh);//write support check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; default: ; } } ch=get_config_var("luh_user_defined_data"); if(ch==NULL) { printf("get luh_user_defined_data error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh); if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } luh_fpos=ftell(fp_luh); files.data_file_num=file_num; files.su_file_num=nu_file; strcpy(files.luh_file_name,luh_name); files.luh_length=luh_fpos; ch=get_config_var("luh_load_check_value_type"); if(ch==NULL) { printf("get luh_load_check_value_type error\n"); return FAILED; } check_type=chtoshort_hex(ch); //printf("load check type=0x%x\n",check_type); check_type_temp=htons(check_type); switch(check_type) { case 1: ret=fwrite(&crc_type_8,sizeof(short),1,fp_luh);//write load crc check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write load crc check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } multi_crc8=multi_crc_8(files); //printf("multi_crc8=0x%x\n",multi_crc8); multi_crc8=htons(multi_crc8); ret=fwrite(&multi_crc8,sizeof(short),1,fp_luh);//write load crc check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 2: ret=fwrite(&crc_type_16,sizeof(short),1,fp_luh);//write load crc check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write load crc check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } multi_crc16=multi_crc_16(files); //printf("multi_crc16=0x%x\n",multi_crc16); multi_crc16=htons(multi_crc16); ret=fwrite(&multi_crc16,sizeof(short),1,fp_luh);//write load crc check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 3: ret=fwrite(&crc_type_32,sizeof(short),1,fp_luh);//write load crc check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write load crc check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } multi_crc32=multi_crc_32(files); //printf("multi_crc32=0x%x\n",multi_crc32); multi_crc32=htonl(multi_crc32); ret=fwrite(&multi_crc32,sizeof(int),1,fp_luh);//write load crc check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; default: ; } luh_fpos=ftell(fp_luh); header_file_crc=crc_file_pos_16(luh_name,luh_fpos); printf("header_file_crc=0x%x\n",header_file_crc); header_file_crc=htons(header_file_crc); ret=fwrite(&header_file_crc,sizeof(short),1,fp_luh);//header file crc if(ret<0) { printf("fwrite error\n"); return FAILED; } luh_fpos=ftell(fp_luh); load_crc=crc_file_pos_32(luh_name,luh_fpos); printf("load_crc=0x%x\n",load_crc); load_crc=htons(load_crc); ret=fwrite(&load_crc,sizeof(int),1,fp_luh);//load crc if(ret<0) { printf("fwrite error\n"); return FAILED; } fseek(fp_luh,0,2);//move to the file end luh_file_length=ftell(fp_luh); luh_file_length=htonl(luh_file_length); rewind(fp_luh);//move to the file start ret=fwrite(&luh_file_length,sizeof(long),1,fp_luh); if(ret<0) { printf("fwrite error\n"); return FAILED; } EXIT: fclose(fp_luh); return FAILED; } return OK; }
bool dbg_hw_info(void) { #ifndef HAVE_LCD_BITMAP int button; int currval = 0; #else int bitmask = HW_MASK; #endif int rom_version = ROM_VERSION; unsigned manu, id; /* flash IDs */ bool got_id; /* flag if we managed to get the flash IDs */ unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */ bool has_bootrom; /* flag for boot ROM present */ int oldmode; /* saved memory guard mode */ oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */ /* get flash ROM type */ got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */ if (!got_id) got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */ /* check if the boot ROM area is a flash mirror */ has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0); if (has_bootrom) /* if ROM and Flash different */ { /* calculate CRC16 checksum of boot ROM */ rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff); } system_memory_guard(oldmode); /* re-enable memory guard */ lcd_clear_display(); #ifdef HAVE_LCD_BITMAP lcd_setfont(FONT_SYSFIXED); lcd_puts(0, 0, "[Hardware info]"); lcd_putsf(0, 1, "ROM: %d.%02d", rom_version/100, rom_version%100); lcd_putsf(0, 2, "Mask: 0x%04x", bitmask); if (got_id) lcd_putsf(0, 3, "Flash: M=%02x D=%02x", manu, id); else lcd_puts(0, 3, "Flash: M=?? D=??"); /* unknown, sorry */ if (has_bootrom) { if (rom_crc == 0x56DBA4EE) /* known Version 1 */ lcd_puts(0, 4, "Boot ROM: V1"); else lcd_putsf(0, 4, "ROMcrc: 0x%08x", rom_crc); } else { lcd_puts(0, 4, "Boot ROM: none"); } lcd_update(); /* wait for exit */ while (button_get_w_tmo(HZ/10) != (DEBUG_CANCEL|BUTTON_REL)); lcd_setfont(FONT_UI); #else /* !HAVE_LCD_BITMAP */ lcd_puts(0, 0, "[HW Info]"); while(1) { switch(currval) { case 0: lcd_putsf(0, 1, "ROM: %d.%02d", rom_version/100, rom_version%100); break; case 1: if (got_id) lcd_putsf(0, 1, "Flash:%02x,%02x", manu, id); else lcd_puts(0, 1, "Flash:??,??"); /* unknown, sorry */ break; case 2: if (has_bootrom) { if (rom_crc == 0x56DBA4EE) /* known Version 1 */ lcd_puts(0, 1, "BootROM: V1"); else if (rom_crc == 0x358099E8) lcd_puts(0, 1, "BootROM: V2"); /* alternative boot ROM found in one single player so far */ else lcd_putsf(0, 1, "R: %08x", rom_crc); } else lcd_puts(0, 1, "BootROM: no"); } lcd_update(); button = button_get_w_tmo(HZ/10); switch(button) { case BUTTON_STOP: return false; case BUTTON_LEFT: currval--; if(currval < 0) currval = 2; break; case BUTTON_RIGHT: currval++; if(currval > 2) currval = 0; break; } } #endif return false; }
@total_records uint16 transform uint16_depend (@this_records @total_records) @directory_size uint32 @directory_start uint32 $dirstr1 transform offset_u32 ($filestream @directory_start) $directory_stream transform size_u32 ($dirstr1 @directory_size) @comment_length uint16 comment n_of @comment_length uint8 files apply $directory_stream n_of @total_directory_records dir_fileheader($filestream) } dir_fileheader($filestream) = { /*cut for brevity*/ uint32 = 0x02014b50/*...*/ @compressed_size uint16 /*...*/ @crc32 uint32/*...*/ @file_name_len uint16/*...*/ @off uint32 filename n_of @file_name_len uint8/*...*/ $contentstream transform offset_u32 ($filestream @off) contents apply $contentstream fileentry(@crc32,@compressed_size /*...*/) } fileentry(@crc32 uint32,@size uint32/*...*/) = { uint32 = 0x04034b50/*...*/ @crc_local uint32/*...*/ $compressed transform size_u32 ($current @size) $uncompressed transform zip_compression ($compressed @size/*...*/) transform crc_32 ($uncompressed @crc32) contents apply $uncompressed many uint8 transform uint16_depend (@crc_local @crc32)/*...*/ }