/* Primary superblock is at 0x8000 */ int recover_JFS(disk_t *disk_car, const struct jfs_superblock *sb,partition_t *partition,const int verbose, const int dump_ind) { if(test_JFS(disk_car, sb, partition, dump_ind)!=0) return 1; set_JFS_info(sb, partition); partition->part_type_i386=P_LINUX; partition->part_type_sun=PSUN_LINUX; partition->part_type_mac=PMAC_LINUX; partition->part_type_gpt=GPT_ENT_TYPE_LINUX_DATA; partition->part_size=(uint64_t)le32(sb->s_pbsize) * le64(sb->s_size) + le32(sb->s_bsize) * (le24(sb->s_fsckpxd.len)+le24(sb->s_logpxd.len)); partition->sborg_offset=64*512; partition->sb_size=JFS_SUPERBLOCK_SIZE; partition->sb_offset=0; guid_cpy(&partition->part_uuid, (const efi_guid_t *)&sb->s_uuid); if(verbose>0) { log_info("\n"); log_info("recover_JFS: s_blocksize=%u\n",partition->blocksize); log_info("recover_JFS: s_size %lu\n",(long unsigned int)le64(sb->s_size)); log_info("recover_JFS: s_fsckpxd.len:%d\n", (int)le24(sb->s_fsckpxd.len)); log_info("recover_JFS: s_logpxd.len:%d\n", (int)le24(sb->s_logpxd.len)); log_info("recover_JFS: part_size %lu\n",(long unsigned)(partition->part_size/disk_car->sector_size)); } return 0; }
static int get_reply(libusb_device_handle* dev) { unsigned char dump[512]; bootloader_status_code buffer = ((bootloader_status_code*)dump)[0]; int res; int transferred; res = libusb_bulk_transfer(dev, 0x81, (unsigned char*)&buffer, 512, &transferred, 0); if(res != 0 || transferred != sizeof(bootloader_status_code)) { LOG("Error reading reply: %d\ttransferred: %d (expected %d)\n", res, transferred, (int)(sizeof(bootloader_status_code))); return res; } if(le32(buffer.magic) != 0x0a6fe000) { LOG("Error reading reply: invalid magic %08X\n",buffer.magic); return -1; } if(le32(buffer.tag) != tag) { LOG("Error reading reply: non-matching taguence number %08X (expected %08X)\n", buffer.tag, tag); return -1; } if(le32(buffer.status) != 0) { LOG("Notice reading reply: last uint32_t was nonzero: %d\n", buffer.status); } LOG("Reading reply: "); int i; for(i = 0; i < transferred; ++i) { LOG("%02X ", ((unsigned char*)(&buffer))[i]); } LOG("\n"); return res; }
static int header_check_indd(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const struct InDesignMasterPage *hdr; const struct InDesignMasterPage *hdr0 = (const struct InDesignMasterPage *)buffer; const struct InDesignMasterPage *hdr1 = (const struct InDesignMasterPage *)&buffer[4096]; hdr=(le64(hdr0->fSequenceNumber) > le64(hdr1->fSequenceNumber) ? hdr0 : hdr1); if(hdr->fObjectStreamEndian!=1 && hdr->fObjectStreamEndian!=2) return 0; if(le32(hdr->fFilePages)==0) return 0; if(file_recovery->file_stat!=NULL && file_recovery->file_stat->file_hint==&file_hint_indd) { if(header_ignored_adv(file_recovery, file_recovery_new)==0) return 0; } reset_file_recovery(file_recovery_new); #ifdef DJGPP file_recovery_new->extension="ind"; #else file_recovery_new->extension=file_hint_indd.extension; #endif /* Contiguous object pages may follow, file_check_indd will search for them */ file_recovery_new->calculated_file_size=(uint64_t)(le32(hdr->fFilePages))*4096; file_recovery_new->file_check=&file_check_indd; #ifdef DEBUG_INDD log_info("header_check_indd: Guessed length: %llu.\n", (long long unsigned)file_recovery_new->calculated_file_size); #endif return 1; }
int set_led(libusb_device_handle* dev, led_state state) { int transferred = 0; int res = 0; motor_command cmd; cmd.magic = le32(0x06022009); cmd.tag = le32(tag_seq++); cmd.arg1 = le32(0); cmd.cmd = le32(0x10); cmd.arg2 = (uint32_t)(le32((int32_t)state)); unsigned char buffer[20]; memcpy(buffer, &cmd, 20); // Send command to set LED to solid green LOG("About to send bulk transfer:"); int i; for(i = 0; i < 20 ; i++) { LOG(" %02X", buffer[i]); } LOG("\n"); res = libusb_bulk_transfer(dev, 0x01, buffer, 20, &transferred, 0); if (res != 0) { LOG("set_led(): libusb_bulk_transfer failed: %d (transferred = %d)\n", res, transferred); return res; } return get_reply(dev); }
int set_tilt(libusb_device_handle* dev, int tilt_degrees) { if (tilt_degrees > 31 || tilt_degrees < -31) { LOG("set_tilt(): degrees %d out of safe range [-31, 31]\n", tilt_degrees); return -1; } motor_command cmd; cmd.magic = le32(0x06022009); cmd.tag = le32(tag_seq++); cmd.arg1 = le32(0); cmd.cmd = le32(0x803b); cmd.arg2 = (uint32_t)(le32((int32_t)tilt_degrees)); int transferred = 0; int res = 0; unsigned char buffer[20]; memcpy(buffer, &cmd, 20); LOG("About to send bulk transfer:"); int i; for(i = 0; i < 20 ; i++) { LOG(" %02X", buffer[i]); } LOG("\n"); res = libusb_bulk_transfer(dev, 0x01, buffer, 20, &transferred, 0); if (res != 0) { LOG("set_tilt(): libusb_bulk_transfer failed: %d (transferred = %d)\n", res, transferred); return res; } return get_reply(dev); }
static int header_check_arj(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const struct arj_main_header *arj=(const struct arj_main_header*)buffer; if(memcmp(buffer, arj_header, sizeof(arj_header))==0 && le16(arj->basic_header_size) > 0 && le16(arj->basic_header_size) <= 2600 && arj->archiver_ver_min <= arj->archiver_ver && arj->archiver_ver <=12 && (arj->flags&0x01)==0 && arj->file_type==2) { reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_arj.extension; file_recovery_new->time=le32(arj->ctime); if(file_recovery_new->time < le32(arj->mtime)) file_recovery_new->time=le32(arj->mtime); if((arj->flags&0x040)!=0) { file_recovery_new->calculated_file_size=le32(arj->size); file_recovery_new->data_check=&data_check_size; file_recovery_new->file_check=&file_check_size; } else file_recovery_new->file_check=&file_check_arj; return 1; } return 0; }
void section_hdr(u32 offset){ uint32_t sh_name = le32(self+offset); /* section name */ offset+=sizeof(uint32_t); uint32_t sh_type = le32(self+offset); /* section type */ offset+=sizeof(uint32_t); uint32_t sh_flags = le32(self+offset); /* section attributes */ offset+=sizeof(uint32_t); uint32_t sh_addr = le32(self+offset); /* virtual address in memory */ offset+=sizeof(uint32_t); uint32_t sh_offset = le32(self+offset); /* offset in file */ offset+=sizeof(uint32_t); uint32_t sh_size = le32(self+offset); /* size of section */ offset+=sizeof(uint32_t); uint32_t sh_link = le32(self+offset); /* link to other section */ offset+=sizeof(uint32_t); uint32_t sh_info = le32(self+offset); /* miscellaneous information */ offset+=sizeof(uint32_t); uint32_t sh_addralign = le32(self+offset); /* address alignment boundary */ offset+=sizeof(uint32_t); uint32_t sh_entsize = le32(self+offset); /* size of entries, if section has table */ offset+=sizeof(uint32_t); printf("--- SELF PROGRAM INFO ---\n"); printf("Name 0x%08x\n",sh_name); printf("Type 0x%08x\n",sh_type); printf("Flags 0x%08x\n",sh_flags); printf("Virtual Address 0x%08x\n",sh_addr); printf("Offset 0x%08x (%u Bytes)\n",sh_offset,sh_offset); printf("Size 0x%08x\n",sh_size); printf("Link to other section 0x%08x\n",sh_link); printf("Info 0x%08x\n",sh_info); printf("Address Alignment 0x%08x\n",sh_addralign); printf("Size Entries 0x%08x (%u Bytes)\n",sh_entsize,sh_entsize); }
void PartitionHandle::CheckEBR(u8 PartNum, sec_t ebr_lba) { EXTENDED_BOOT_RECORD *ebr = (EXTENDED_BOOT_RECORD*)MEM2_alloc(MAX_BYTES_PER_SECTOR); if(ebr == NULL) return; sec_t next_erb_lba = 0; do { // Read and validate the extended boot record if(!interface->readSectors(ebr_lba + next_erb_lba, 1, ebr)) { MEM2_free(ebr); return; } if(ebr->signature != EBR_SIGNATURE && ebr->signature != EBR_SIGNATURE_MOD) { MEM2_free(ebr); return; } if(le32(ebr->partition.block_count) > 0 && !IsExisting(ebr_lba + next_erb_lba + le32(ebr->partition.lba_start))) { AddPartition(PartFromType(ebr->partition.type), ebr_lba + next_erb_lba + le32(ebr->partition.lba_start), le32(ebr->partition.block_count), (ebr->partition.status == PARTITION_BOOTABLE), ebr->partition.type, PartNum); } // Get the start sector of the current partition // and the next extended boot record in the chain next_erb_lba = le32(ebr->next_ebr.lba_start); } while(next_erb_lba > 0); MEM2_free(ebr); }
static int zip_parse_data_desc(file_recovery_t *fr) { struct { uint32_t crc32; /** Checksum (CRC32) */ uint32_t compressed_size; /** Compressed size (bytes) */ uint32_t uncompressed_size; /** Uncompressed size (bytes) */ } __attribute__ ((__packed__)) desc; if (fread(&desc, sizeof(desc), 1, fr->handle) != 1) { #ifdef DEBUG_ZIP log_trace("zip: Unexpected EOF reading header of data_desc\n"); #endif return -1; } fr->file_size += sizeof(desc); #ifdef DEBUG_ZIP log_info("%u %u CRC32=0x%08X\n", le32(desc.compressed_size), le32(desc.uncompressed_size), le32(desc.crc32)); #endif if(le32(desc.compressed_size)!=expected_compressed_size) return -1; return 0; }
static uint32_t *OLE_load_MiniFAT(FILE *IN, const struct OLE_HDR *header, const uint32_t *fat, const unsigned int fat_entries) { unsigned char*minifat_pos; uint32_t *minifat; unsigned int block; unsigned int i; if(le32(header->csectMiniFat)==0) return NULL; minifat=(uint32_t*)MALLOC(le32(header->csectMiniFat) << le16(header->uSectorShift)); minifat_pos=(unsigned char*)minifat; block=le32(header->MiniFat_block); for(i=0; i < le32(header->csectMiniFat) && block < fat_entries; i++) { if(my_fseek(IN, ((uint64_t)1+block) << le16(header->uSectorShift), SEEK_SET) < 0) { free(minifat); return NULL; } if(fread(minifat_pos, 1 << le16(header->uSectorShift), 1, IN) != 1) { free(minifat); return NULL; } minifat_pos+=1 << le16(header->uSectorShift); block=le32(fat[block]); } return minifat; }
static int test_sun_i386(const disk_t *disk_car, const sun_partition_i386 *sunlabel, const partition_t *partition, const int verbose) { if ((le16(sunlabel->magic) != SUN_LABEL_MAGIC) || (le32(sunlabel->magic_start) != SUN_LABEL_MAGIC_START)) return 1; if(verbose>0) log_info("\nSUN Marker at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset), offset2head(disk_car,partition->part_offset), offset2sector(disk_car,partition->part_offset)); { int i; partition_t *new_partition=partition_new(NULL); for(i=0;i<16;i++) { if (sunlabel->partitions[i].num_sectors > 0 && sunlabel->partitions[i].id > 0) // && sunlabel->partitions[i].id != WHOLE_DISK) { partition_reset(new_partition, &arch_sun); new_partition->order=i; new_partition->part_type_sun=sunlabel->partitions[i].id; new_partition->part_offset=partition->part_offset+(uint64_t)le32(sunlabel->partitions[i].start_sector) * le16(sunlabel->sector_size); new_partition->part_size=(uint64_t)le32(sunlabel->partitions[i].num_sectors) * le16(sunlabel->sector_size); new_partition->status=STATUS_PRIM; log_partition(disk_car,new_partition); } } free(new_partition); } return 0; }
static void ReadTagFromBRLAN(BRLAN_animation **anims, int idx) { int taghead_location = BRLAN_fileoffset; tag_header head; tag_entry* entries; tag_entryinfo* entryinfo; BRLAN_ReadDataFromMemory(&head, BRLAN_file, sizeof(tag_header)); memcpy(anims[idx]->type, head.magic, 4); anims[idx]->entrycount = head.entry_count; int i, z; entries = (tag_entry*)calloc(anims[idx]->entrycount, sizeof(tag_entry)); entryinfo = (tag_entryinfo*)calloc(anims[idx]->entrycount, sizeof(tag_entryinfo)); for(i = 0; i < anims[idx]->entrycount; i++) { BRLAN_ReadDataFromMemory(&entries[i], BRLAN_file, sizeof(tag_entry)); } for(i = 0; i < anims[idx]->entrycount; i++) { BRLAN_fileoffset = be32(entries[i].offset) + taghead_location; BRLAN_ReadDataFromMemory(&entryinfo[i], BRLAN_file, sizeof(tag_entryinfo)); anims[idx]->entries[i].animtype = be16(entryinfo[i].type); anims[idx]->entries[i].tripletcount = be16(entryinfo[i].coord_count); for(z = 0; z < be16(entryinfo[i].coord_count); z++) { BRLAN_ReadDataFromMemory(&anims[idx]->entries[i].triplets[z], BRLAN_file, sizeof(f32) * 3); anims[idx]->entries[i].triplets[z].frame = le32(anims[idx]->entries[i].triplets[z].frame); anims[idx]->entries[i].triplets[z].value = le32(anims[idx]->entries[i].triplets[z].value); anims[idx]->entries[i].triplets[z].blend = le32(anims[idx]->entries[i].triplets[z].blend); } } free(entries); free(entryinfo); }
static int header_check_elf(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const Elf32_Ehdr *hdr32=(const Elf32_Ehdr *)buffer; if(hdr32->e_ident[EI_DATA]!=ELFDATA2LSB && hdr32->e_ident[EI_DATA]!=ELFDATA2MSB) return 0; if((hdr32->e_ident[EI_DATA]==ELFDATA2LSB ? le32(hdr32->e_version) : be32(hdr32->e_version)) != 1) return 0; /* http://en.wikipedia.org/wiki/Executable_and_Linkable_Format */ reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_elf.extension; if(hdr32->e_ident[EI_CLASS]==ELFCLASS32) { const uint32_t tmp=(hdr32->e_ident[EI_DATA]==ELFDATA2LSB ? le32(hdr32->e_shoff) : be32(hdr32->e_shoff)); file_recovery_new->min_filesize=(hdr32->e_ident[EI_DATA]==ELFDATA2LSB ? le32(hdr32->e_phoff) : be32(hdr32->e_phoff)); if(file_recovery_new->min_filesize < tmp) file_recovery_new->min_filesize=tmp; } else { const Elf64_Ehdr *hdr64=(const Elf64_Ehdr *)buffer; const uint64_t tmp=(hdr64->e_ident[EI_DATA]==ELFDATA2LSB ? le64(hdr64->e_shoff) : be64(hdr64->e_shoff)); file_recovery_new->min_filesize=(hdr64->e_ident[EI_DATA]==ELFDATA2LSB ? le64(hdr64->e_phoff) : be64(hdr64->e_phoff)); if(file_recovery_new->min_filesize < tmp) file_recovery_new->min_filesize=tmp; } return 1; }
static int log_fat_info(const struct fat_boot_sector*fh1, const upart_type_t upart_type, const unsigned int sector_size) { log_info("sector_size %u\n", fat_sector_size(fh1)); log_info("cluster_size %u\n", fh1->sectors_per_cluster); log_info("reserved %u\n", le16(fh1->reserved)); log_info("fats %u\n", fh1->fats); log_info("dir_entries %u\n", get_dir_entries(fh1)); log_info("sectors %u\n", fat_sectors(fh1)); log_info("media %02X\n", fh1->media); log_info("fat_length %u\n", le16(fh1->fat_length)); log_info("secs_track %u\n", le16(fh1->secs_track)); log_info("heads %u\n", le16(fh1->heads)); log_info("hidden %u\n", (unsigned int)le32(fh1->hidden)); log_info("total_sect %u\n", (unsigned int)le32(fh1->total_sect)); if(upart_type==UP_FAT32) { log_info("fat32_length %u\n", (unsigned int)le32(fh1->fat32_length)); log_info("flags %04X\n", le16(fh1->flags)); log_info("version %u.%u\n", fh1->version[0], fh1->version[1]); log_info("root_cluster %u\n", (unsigned int)le32(fh1->root_cluster)); log_info("info_sector %u\n", le16(fh1->info_sector)); log_info("backup_boot %u\n", le16(fh1->backup_boot)); if(fat32_get_free_count((const unsigned char*)fh1,sector_size)==0xFFFFFFFF) log_info("free_count uninitialised\n"); else log_info("free_count %lu\n",fat32_get_free_count((const unsigned char*)fh1,sector_size)); if(fat32_get_next_free((const unsigned char*)fh1,sector_size)==0xFFFFFFFF) log_info("next_free uninitialised\n"); else log_info("next_free %lu\n",fat32_get_next_free((const unsigned char*)fh1,sector_size)); } return 0; }
void PartitionHandle::CheckEBR(int PartNum, sec_t ebr_lba) { EXTENDED_BOOT_RECORD *ebr = (EXTENDED_BOOT_RECORD *) malloc(MAX_SECTOR_SIZE); if(!ebr) return; sec_t next_erb_lba = 0; do { // Read and validate the extended boot record if (!interface->readSectors(ebr_lba + next_erb_lba, 1, ebr)) break; if (ebr->signature != EBR_SIGNATURE) break; PARTITION_RECORD * partition = (PARTITION_RECORD *) &ebr->partition; if(le32(partition->block_count) > 0) { AddPartition(PartFromType(partition->type), ebr_lba + next_erb_lba + le32(partition->lba_start), le32(partition->block_count), (partition->status == PARTITION_BOOTABLE), partition->type, PartNum, ebr_lba + next_erb_lba); } // Get the start sector of the current partition // and the next extended boot record in the chain next_erb_lba = le32(ebr->next_ebr.lba_start); } while(next_erb_lba > 0); free(ebr); }
void WavDecoder::OpenFile() { SWaveHdr Header; SWaveFmtChunk FmtChunk; memset(&Header, 0, sizeof(SWaveHdr)); memset(&FmtChunk, 0, sizeof(SWaveFmtChunk)); file_fd->read((u8 *) &Header, sizeof(SWaveHdr)); file_fd->read((u8 *) &FmtChunk, sizeof(SWaveFmtChunk)); if (Header.magicRIFF != 'RIFF') { CloseFile(); return; } else if(Header.magicWAVE != 'WAVE') { CloseFile(); return; } else if(FmtChunk.magicFMT != 'fmt ') { CloseFile(); return; } DataOffset = sizeof(SWaveHdr)+le32(FmtChunk.size)+8; file_fd->seek(DataOffset, SEEK_SET); SWaveChunk DataChunk; file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk)); while(DataChunk.magicDATA != 'data') { DataOffset += 8+le32(DataChunk.size); file_fd->seek(DataOffset, SEEK_SET); int ret = file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk)); if(ret <= 0) { CloseFile(); return; } } DataOffset += 8; DataSize = le32(DataChunk.size); Is16Bit = (le16(FmtChunk.bps) == 16); SampleRate = le32(FmtChunk.freq); if (le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 1) Format = VOICE_MONO_8BIT; else if (le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 2) Format = VOICE_MONO_16BIT; else if (le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 2) Format = VOICE_STEREO_8BIT; else if (le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 4) Format = VOICE_STEREO_16BIT; Decode(); }
int recover_Linux_SWAP(const union swap_header *swap_header, partition_t *partition) { if(test_Linux_SWAP(swap_header, partition)!=0) return 1; set_Linux_SWAP_info(swap_header,partition); partition->part_type_i386=P_LINSWAP; partition->part_type_sun=PSUN_LINSWAP; partition->part_type_mac=PMAC_SWAP; partition->part_type_gpt=GPT_ENT_TYPE_LINUX_SWAP; switch(partition->upart_type) { case UP_LINSWAP: { int i, j; for(i=PAGE_SIZE-10-1;i>=0;i--) if(swap_header->magic.reserved[i]!=(char)0) break; for(j=7;j>=0;j--) if((swap_header->magic.reserved[i]&(1<<j))!=(char)0) break; partition->part_size=(uint64_t)((8*i+j+1)*PAGE_SIZE); } break; case UP_LINSWAP2: if(swap_header->info.last_page==0) partition->part_size=PAGE_SIZE; else partition->part_size=(uint64_t)(le32(swap_header->info.last_page) - 1)*PAGE_SIZE; break; case UP_LINSWAP_8K: { int i, j; for(i=PAGE_8K - 10 - 1; i>=0; i--) if(swap_header->magic8k.reserved[i]!=(char)0) break; for(j=7;j>=0;j--) if((swap_header->magic8k.reserved[i]&(1<<j))!=(char)0) break; partition->part_size=(uint64_t)((8*i+j+1)*PAGE_8K); } break; case UP_LINSWAP2_8K: if(swap_header->info.last_page==0) partition->part_size=PAGE_8K; else partition->part_size=(uint64_t)(le32(swap_header->info.last_page) - 1)*PAGE_8K; break; case UP_LINSWAP2_8KBE: if(swap_header->info.last_page==0) partition->part_size=PAGE_8K; else partition->part_size=(uint64_t)(be32(swap_header->info.last_page) - 1)*PAGE_8K; break; default: return 1; } return 0; }
static int header_check_ddf4(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const struct MasterHeader *h=(const struct MasterHeader *)buffer; if(le32(h->m_nNumRawBeams)!=96 && le32(h->m_nNumRawBeams)!=48) return 0; if(le32(h->m_nSamplesPerChannel)!=512) return 0; return header_check_aux(buffer, file_recovery_new); }
int log_fat2_info(const struct fat_boot_sector*fh1, const struct fat_boot_sector*fh2, const upart_type_t upart_type, const unsigned int sector_size) { switch(upart_type) { case UP_FAT12: log_info("\nFAT12\n"); break; case UP_FAT16: log_info("\nFAT16\n"); break; case UP_FAT32: log_info("\nFAT32\n"); break; default: return 1; } log_info("sector_size %u %u\n", fat_sector_size(fh1),fat_sector_size(fh2)); log_info("cluster_size %u %u\n", fh1->sectors_per_cluster,fh2->sectors_per_cluster); log_info("reserved %u %u\n", le16(fh1->reserved),le16(fh2->reserved)); log_info("fats %u %u\n", fh1->fats,fh2->fats); log_info("dir_entries %u %u\n", get_dir_entries(fh1),get_dir_entries(fh2)); log_info("sectors %u %u\n", fat_sectors(fh1),fat_sectors(fh2)); log_info("media %02X %02X\n", fh1->media,fh2->media); log_info("fat_length %u %u\n", le16(fh1->fat_length),le16(fh2->fat_length)); log_info("secs_track %u %u\n", le16(fh1->secs_track),le16(fh2->secs_track)); log_info("heads %u %u\n", le16(fh1->heads),le16(fh2->heads)); log_info("hidden %u %u\n", (unsigned int)le32(fh1->hidden),(unsigned int)le32(fh2->hidden)); log_info("total_sect %u %u\n", (unsigned int)le32(fh1->total_sect),(unsigned int)le32(fh2->total_sect)); if(upart_type==UP_FAT32) { log_info("fat32_length %u %u\n", (unsigned int)le32(fh1->fat32_length),(unsigned int)le32(fh2->fat32_length)); log_info("flags %04X %04X\n", le16(fh1->flags),le16(fh2->flags)); log_info("version %u.%u %u.%u\n", fh1->version[0], fh1->version[1],fh2->version[0], fh2->version[1]); log_info("root_cluster %u %u\n", (unsigned int)le32(fh1->root_cluster),(unsigned int)le32(fh2->root_cluster)); log_info("info_sector %u %u\n", le16(fh1->info_sector),le16(fh2->info_sector)); log_info("backup_boot %u %u\n", le16(fh1->backup_boot),le16(fh2->backup_boot)); log_info("free_count "); if(fat32_get_free_count((const unsigned char*)fh1,sector_size)==0xFFFFFFFF) log_info("uninitialised "); else log_info("%lu ",fat32_get_free_count((const unsigned char*)fh1,sector_size)); if(fat32_get_free_count((const unsigned char*)fh2,sector_size)==0xFFFFFFFF) log_info("uninitialised"); else log_info("%lu",fat32_get_free_count((const unsigned char*)fh2,sector_size)); log_info("\nnext_free "); if(fat32_get_next_free((const unsigned char*)fh1,sector_size)==0xFFFFFFFF) log_info("uninitialised "); else log_info("%lu ",fat32_get_next_free((const unsigned char*)fh1,sector_size)); if(fat32_get_next_free((const unsigned char*)fh2,sector_size)==0xFFFFFFFF) log_info("uninitialised\n"); else log_info("%lu\n",fat32_get_next_free((const unsigned char*)fh2,sector_size)); } return 0; }
int PartitionHandle::CheckGPT(int PartNum) { GPT_HEADER *gpt_header = (GPT_HEADER *) malloc(MAX_SECTOR_SIZE); if(!gpt_header) return -1; // Read and validate the extended boot record if (!interface->readSectors(1, 1, gpt_header)) { free(gpt_header); return -1; } if(strncmp(gpt_header->magic, "EFI PART", 8) != 0) { free(gpt_header); return -1; } gpt_header->part_table_lba = le64(gpt_header->part_table_lba); gpt_header->part_entries = le32(gpt_header->part_entries); gpt_header->part_entry_size = le32(gpt_header->part_entry_size); gpt_header->part_entry_checksum = le32(gpt_header->part_entry_checksum); u8 * sector_buf = (u8 *) malloc(MAX_SECTOR_SIZE); if(!sector_buf) { free(gpt_header); return -1; } u64 next_lba = gpt_header->part_table_lba; for(u32 i = 0; i < gpt_header->part_entries; ++i) { if (!interface->readSectors(next_lba, 1, sector_buf)) break; for(u32 n = 0; n < sectorSize/gpt_header->part_entry_size; ++n, ++i) { GUID_PART_ENTRY * part_entry = (GUID_PART_ENTRY *) (sector_buf+gpt_header->part_entry_size*n); if(memcmp(part_entry->part_type_guid, TYPE_UNUSED, 16) == 0) continue; bool bootable = (memcmp(part_entry->part_type_guid, TYPE_BIOS, 16) == 0); AddPartition("GUID-Entry", le64(part_entry->part_first_lba), le64(part_entry->part_last_lba), bootable, PARTITION_TYPE_GPT, PartNum); } next_lba++; } free(sector_buf); free(gpt_header); return 0; }
static int header_check_axx(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const struct SHeader *header=(const struct SHeader *)&buffer[0x10+0x15]; if(le32(header->aoLength) < 5) return 0; reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_axx.extension; file_recovery_new->file_check=&file_check_axx; file_recovery_new->min_filesize=0x25+le32(header->aoLength); return 1; }
int rl_snddata_create( rl_snddata_t* snddata, const void* data, size_t size ) { const wave_t* wave = (const wave_t*)data; if ( wave->chunkid[ 0 ] != 'R' || wave->chunkid[ 1 ] != 'I' || wave->chunkid[ 2 ] != 'F' || wave->chunkid[ 3 ] != 'F' ) { return -1; } if ( wave->format[ 0 ] != 'W' || wave->format[ 1 ] != 'A' || wave->format[ 2 ] != 'V' || wave->format[ 3 ] != 'E' ) { return -1; } if ( wave->subchunk1id[ 0 ] != 'f' || wave->subchunk1id[ 1 ] != 'm' || wave->subchunk1id[ 2 ] != 't' || wave->subchunk1id[ 3 ] != ' ' ) { return -1; } if ( wave->subchunk2id[ 0 ] != 'd' || wave->subchunk2id[ 1 ] != 'a' || wave->subchunk2id[ 2 ] != 't' || wave->subchunk2id[ 3 ] != 'a' ) { return -1; } snddata->bps = le16( wave->bitspersample ); snddata->channels = le16( wave->numchannels ); snddata->freq = le32( wave->samplerate ); if ( le16( wave->audioformat ) != 1 ) { return -1; } if ( snddata->channels != 1 && snddata->channels != 2 ) { return -1; } if ( snddata->bps != 8 && snddata->bps != 16 ) { return -1; } snddata->size = le32( wave->subchunk2size ); snddata->samples = malloc( snddata->size ); if ( snddata->samples ) { memcpy( (void*)snddata->samples, (void*)wave->data, snddata->size ); return 0; } return -1; }
static int header_check_x3f(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const struct x3f_header *h=(const struct x3f_header *)buffer; const unsigned int rotation=le32(h->rotation); if(le32(h->rows)==0 || le32(h->columns)==0) return 0; if(rotation!=0 && rotation!=90 && rotation!=180 && rotation!=270) return 0; reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_x3f.extension; return 1; }
static int header_check_hds(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const struct parallels_header *hdr=(const struct parallels_header *)buffer; if(le32(hdr->heads)==0 || le32(hdr->cylinders)==0 || le32(hdr->tracks)==0 || le32(hdr->nb_sectors)==0) return 0; reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_hds.extension; return 1; }
static int header_check_1cd(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const struct header_1cd *hdr=(const struct header_1cd *)buffer; if(le32(hdr->size)==0) return 0; reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_1cd.extension; file_recovery_new->calculated_file_size=le32(hdr->size)<<12; file_recovery_new->data_check=&data_check_size; file_recovery_new->file_check=&file_check_size; return 1; }
static int set_JFS_info(const struct jfs_superblock *sb, partition_t *partition) { partition->blocksize=le32(sb->s_bsize); snprintf(partition->info, sizeof(partition->info), "JFS %u, blocksize=%u", (unsigned int)le32(sb->s_version), partition->blocksize); partition->fsname[0]='\0'; if(le32(sb->s_version)==1) { set_part_name(partition,sb->s_fpack,11); } return 0; }
static int header_check_d2s(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const struct d2s_header *d2s=(const struct d2s_header*)buffer; if(le32(d2s->size) < sizeof(struct d2s_header)) return 0; reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_d2s.extension; file_recovery_new->calculated_file_size=le32(d2s->size); file_recovery_new->data_check=&data_check_size; file_recovery_new->file_check=&file_check_size; file_recovery_new->file_rename=&file_rename_d2s; return 1; }
int dump_2fat_info_ncurses(const struct fat_boot_sector*fh1, const struct fat_boot_sector*fh2, const upart_type_t upart_type, const unsigned int sector_size) { switch(upart_type) { case UP_FAT12: wprintw(stdscr,"FAT : 12\n"); break; case UP_FAT16: wprintw(stdscr,"FAT : 16\n"); break; case UP_FAT32: wprintw(stdscr,"FAT : 32\n"); break; default: wprintw(stdscr,"Not a FAT\n"); return 1; } wprintw(stdscr,"cluster_size %u %u\n", fh1->sectors_per_cluster, fh2->sectors_per_cluster); wprintw(stdscr,"reserved %u %u\n", le16(fh1->reserved),le16(fh2->reserved)); if(fat_sectors(fh1)!=0 || fat_sectors(fh2)!=0) wprintw(stdscr,"sectors %u %u\n", fat_sectors(fh1), fat_sectors(fh2)); if(le32(fh1->total_sect)!=0 || le32(fh2->total_sect)!=0) wprintw(stdscr,"total_sect %u %u\n", (unsigned int)le32(fh1->total_sect), (unsigned int)le32(fh2->total_sect)); if(upart_type==UP_FAT32) { wprintw(stdscr,"fat32_length %u %u\n", (unsigned int)le32(fh1->fat32_length), (unsigned int)le32(fh2->fat32_length)); wprintw(stdscr,"root_cluster %u %u\n", (unsigned int)le32(fh1->root_cluster), (unsigned int)le32(fh2->root_cluster)); wprintw(stdscr,"free_count "); if(fat32_get_free_count((const unsigned char*)fh1,sector_size)==0xFFFFFFFF) wprintw(stdscr,"uninitialised "); else wprintw(stdscr,"%lu ",fat32_get_free_count((const unsigned char*)fh1,sector_size)); if(fat32_get_free_count((const unsigned char*)fh2,sector_size)==0xFFFFFFFF) wprintw(stdscr,"uninitialised\n"); else wprintw(stdscr,"%lu\n",fat32_get_free_count((const unsigned char*)fh2,sector_size)); wprintw(stdscr,"next_free "); if(fat32_get_next_free((const unsigned char*)fh1,sector_size)==0xFFFFFFFF) wprintw(stdscr,"uninitialised "); else wprintw(stdscr,"%lu ",fat32_get_next_free((const unsigned char*)fh1,sector_size)); if(fat32_get_next_free((const unsigned char*)fh2,sector_size)==0xFFFFFFFF) wprintw(stdscr,"uninitialised\n"); else wprintw(stdscr,"%lu\n",fat32_get_next_free((const unsigned char*)fh2,sector_size)); } else { wprintw(stdscr,"fat_length %u %u\n", le16(fh1->fat_length), le16(fh2->fat_length)); wprintw(stdscr,"dir_entries %u %u\n", get_dir_entries(fh1), get_dir_entries(fh2)); } return 0; }
static int header_check_flp(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const struct flp_header *hdr=(const struct flp_header *)buffer; if(strncmp(hdr->magic2, "FLdt", 4)!=0) return 0; if(le32(hdr->len2)==0) return 0; reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_flp.extension; file_recovery_new->calculated_file_size=le32(hdr->len2) + 0x16; file_recovery_new->data_check=&data_check_size; file_recovery_new->file_check=&file_check_size; return 1; }
void program_hdr(u32 offset){ uint32_t p_type = le32(self+offset); /* type of segment */ offset+=sizeof(uint32_t); uint32_t p_flags = le32(self+offset); /* segment attributes */ offset+=sizeof(uint32_t); uint32_t p_offset = le32(self+offset); /* offset in file */ offset+=sizeof(uint32_t); uint32_t p_vaddr = le32(self+offset); /* virtual address in memory */ offset+=sizeof(uint32_t); uint32_t p_paddr = le32(self+offset); /* reserved */ offset+=sizeof(uint32_t); uint32_t p_filesz = le32(self+offset); /* size of segment in file */ offset+=sizeof(uint32_t); uint32_t p_memsz = le32(self+offset); /* size of segment in memory */ offset+=sizeof(uint32_t); uint32_t p_align = le32(self+offset); /* alignment of segment */ offset+=sizeof(uint32_t); const char* p_type_char = prg_type(p_type); const char* p_flags_char = prg_flags(p_flags); printf("--- SELF PROGRAM INFO ---\n"); printf("Type 0x%08x [%s]\n",p_type,p_type_char); printf("Flags 0x%08x [%s]\n",p_flags,p_flags_char); printf("Offset 0x%08x\n",p_offset); printf("Virtual Address 0x%08x\n",p_vaddr); printf("Reserved Adderess 0x%08x\n",p_paddr); printf("Real Size 0x%08x (%u Bytes)\n",p_filesz,p_filesz); printf("Size in Memory 0x%08x (%u Bytes)\n",p_memsz,p_memsz); printf("Alignment 0x%08x (%u)\n",p_align,p_align); }