Пример #1
0
void setup_context()
{
    // setup stack pointer
    _ctx.reg[1][0] = 0x3FFD0; _ctx.reg[1][1] = 0x0; _ctx.reg[1][2] = 0x0; _ctx.reg[1][3] = 0x0;

    wbe32(_ctx.ls + 0x7060, 0x32000600);

    TextureBlobHeader* header = (TextureBlobHeader*)src_data;
    TextureBlobChunk* chunks = (TextureBlobChunk*)(header + 1);

    wbe32(_ctx.ls + 0x3BE40, be16((u8*)&header->type));
    wbe32(_ctx.ls + 0x3BE44, be16((u8*)&header->quality));
    wbe32(_ctx.ls + 0x3BE48, (u32)src_data + be32((u8*)&chunks[0].offset));
    wbe32(_ctx.ls + 0x3BE4C, be32((u8*)&chunks[0].compressed_size));
    wbe32(_ctx.ls + 0x3BE50, (u32)dst_data);
    wbe32(_ctx.ls + 0x3BE54, be32((u8*)&chunks[0].decompressed_size));
    wbe32(_ctx.ls + 0x3BE58, be16((u8*)&chunks[0].num_batches));
    wbe32(_ctx.ls + 0x3BE5C, be16((u8*)&header->width));
    wbe32(_ctx.ls + 0x3BE60, be16((u8*)&header->height));

    wbe32(_ctx.ls + 0x3BE64, be32((u8*)&header->unk_0x0C));
    wbe32(_ctx.ls + 0x3BE68, be32((u8*)&header->unk_0x10));
    wbe32(_ctx.ls + 0x3BE6C, be32((u8*)&header->unk_0x14));

    wbe32(_ctx.ls + 0x3BE70, be32((u8*)&header->unk_0x18));
    wbe32(_ctx.ls + 0x3BE74, be32((u8*)&header->unk_0x1C));
    wbe32(_ctx.ls + 0x3BE78, be32((u8*)&header->unk_0x20));

    wbe32(_ctx.ls + 0x3BE7C, 0);
    wbe32(_ctx.ls + 0x3BE80, 0);
    wbe32(_ctx.ls + 0x3BE84, 0);
    wbe32(_ctx.ls + 0x3BE8C, 0);
}
Пример #2
0
int recover_HFS(disk_t *disk_car, const hfs_mdb_t *hfs_mdb,partition_t *partition,const int verbose, const int dump_ind, const int backup)
{
  uint64_t part_size;
  if(test_HFS(disk_car,hfs_mdb,partition,verbose,dump_ind)!=0)
    return 1;
  /* The extra 0x400 bytes are for the backup MDB */
  part_size=(uint64_t)be16(hfs_mdb->drNmAlBlks)*be32(hfs_mdb->drAlBlkSiz)+be16(hfs_mdb->drAlBlSt)*512+0x400;
  partition->sborg_offset=0x400;
  partition->sb_size=HFS_SUPERBLOCK_SIZE;
  if(backup>0)
  {
    if(partition->part_offset+2*disk_car->sector_size<part_size)
      return 1;
    partition->sb_offset=part_size-0x400;
    partition->part_offset=partition->part_offset+2*disk_car->sector_size-part_size;
  }
  partition->part_size=part_size;
  set_HFS_info(partition,hfs_mdb);
  partition->part_type_i386=P_HFS;
  partition->part_type_mac=PMAC_HFS;
  partition->part_type_gpt=GPT_ENT_TYPE_MAC_HFS;
  if(verbose>0)
  {
    log_info("part_size %lu\n",(long unsigned)(partition->part_size/disk_car->sector_size));
  }
  return 0;
}
Пример #3
0
static int header_check_ra(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)
{
  if(buffer[4]==0x00 && buffer[5]==0x03)
  { /* V3 */
    const struct ra3_header *ra3=(const struct ra3_header *)buffer;
    reset_file_recovery(file_recovery_new);
    file_recovery_new->extension=file_hint_ra.extension;
    file_recovery_new->calculated_file_size=8 + be16(ra3->header_size) + be32(ra3->data_size);
    file_recovery_new->data_check=&data_check_size;
    file_recovery_new->file_check=&file_check_size;
    return 1;
  }
  else if(buffer[4]==0x00 && buffer[5]==0x04 &&
      buffer[8]=='.' && buffer[9]=='r' && buffer[10]=='a' && buffer[11]=='4')
  { /* V4 */
    const struct ra4_header *ra4=(const struct ra4_header *)buffer;
    reset_file_recovery(file_recovery_new);
    file_recovery_new->extension=file_hint_ra.extension;
    file_recovery_new->calculated_file_size=40 + be16(ra4->header_size) + be32(ra4->data_size);
    file_recovery_new->data_check=&data_check_size;
    file_recovery_new->file_check=&file_check_size;
    return 1;
  }
  return 0;
}
Пример #4
0
static int test_xfs(const disk_t *disk_car, const struct xfs_sb *sb, partition_t *partition, const int verbose)
{
  if (sb->sb_magicnum!=be32(XFS_SB_MAGIC))
    return 1;
  switch(be16(sb->sb_versionnum) & XFS_SB_VERSION_NUMBITS)
  {
    case XFS_SB_VERSION_1:
      partition->upart_type = UP_XFS;
      break;
    case XFS_SB_VERSION_2:
      partition->upart_type = UP_XFS2;
      break;
    case XFS_SB_VERSION_3:
      partition->upart_type = UP_XFS3;
      break;
    case XFS_SB_VERSION_4:
      partition->upart_type = UP_XFS4;
      break;
    default:
      log_error("Unknown XFS version %x\n",be16(sb->sb_versionnum)& XFS_SB_VERSION_NUMBITS);
      partition->upart_type = UP_XFS4;
      break;
  }
  if(verbose>0)
    log_info("\nXFS Marker at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
  return 0;
}
Пример #5
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);
}
Пример #6
0
static void decrypt_spkg(void)
{
	u16 flags;
	u16 type;	
	struct keylist *k;

	flags    = be16(pkg + 0x08);
	type     = be16(pkg + 0x0a);
	hdr_len  = be64(pkg + 0x10);
	dec_size = be64(pkg + 0x18);

	if (type != 3)
		fail("no .spkg file");

	k = keys_get(KEY_SPKG);

	if (k == NULL)
		fail("no key found");

	if (sce_decrypt_header(pkg, k) < 0)
		fail("header decryption failed");

	meta_offset = be32(pkg + 0x0c);
	n_sections  = be32(pkg + meta_offset + 0x60 + 0xc);

	if (n_sections != 3)
		fail("invalid section count: %d", n_sections);
}
Пример #7
0
void parse_brlyt(char *filename)
{
	FILE* fp = fopen(filename, "rb");
	if(fp == NULL) {
		printf("Error! Couldn't open %s!\n", filename);
		exit(1);
	}
	fseek(fp, 0, SEEK_END);
	size_t file_size = ftell(fp);
	dbgprintf("Filesize is %d\n", file_size);
	u8* brlyt_file = (u8*)malloc(file_size);
	dbgprintf("brlyt_file allocated\n");
	fseek(fp, 0, SEEK_SET);
	fread(brlyt_file, file_size, 1, fp);
	dbgprintf("brlyt_file read to.\n");
	BRLYT_fileoffset = 0;
	brlyt_header header;
	BRLYT_ReadDataFromMemory(&header, brlyt_file, sizeof(brlyt_header));
	BRLYT_CheckHeaderSanity(header, file_size);
	brlyt_entry *entries;
	BRLYT_fileoffset = be16(header.lyt_offset);
	brlyt_entry_header tempentry;
	int i;
	dbgprintf("curr %08x max %08x\n", BRLYT_fileoffset, file_size);
	for(i = 0; BRLYT_fileoffset < file_size; i++) {
		BRLYT_ReadDataFromMemoryX(&tempentry, brlyt_file, sizeof(brlyt_entry_header));
		BRLYT_fileoffset += be32(tempentry.length);
		dbgprintf("curr %08x max %08x\n", BRLYT_fileoffset, file_size);
	}
	int entrycount = i;
	entries = (brlyt_entry*)calloc(entrycount, sizeof(brlyt_entry));
	dbgprintf("%08x\n", entries);
	if(entries == NULL) {
		printf("Couldn't allocate for entries!\n");
		exit(1);
	}
	BRLYT_fileoffset = be16(header.lyt_offset);
	for(i = 0; i < entrycount; i++) {
		dbgprintf("&(entries[i]) = %08x\n", &(entries[i]));
		BRLYT_ReadDataFromMemoryX(&tempentry, brlyt_file, sizeof(brlyt_entry_header));
		memcpy(entries[i].magic, tempentry.magic, 4);
		entries[i].length = tempentry.length;
		entries[i].data_location = BRLYT_fileoffset + sizeof(brlyt_entry_header);
		BRLYT_fileoffset += be32(tempentry.length);
	}	
//	int entrycnt = BRLYT_ReadEntries(brlyt_file, file_size, header, entries);
	dbgprintf("%08x\n", entries);
	printf("Parsed BRLYT! Information:\n");
	printf("Main header:\n");
	printf("	Magic: %c%c%c%c\n", header.magic[0], header.magic[1], header.magic[2], header.magic[3]);
	printf("	Unk1: %08x\n", be32(header.unk1));
	printf("	Filesize: %lu\n", be32(header.filesize));
	printf("		%s real file size!\n", be32(header.filesize) == file_size ? "Matches" : "Does not match");
	printf("	Offset to lyt1: %04x\n", be16(header.lyt_offset));
	printf("	Unk2: %04x\n", be16(header.unk2));
	printf("\nBRLYT Entries:");
	PrintBRLYTEntries(entries, entrycount, brlyt_file);
}
Пример #8
0
void PrintBRLYTEntry_img(brlyt_entry entry, u8* brlyt_file)
{
	brlyt_img_chunk data;
	BRLYT_fileoffset = entry.data_location;
	BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_img_chunk));
	printf("		Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]);
	printf("		Number: %d\n", be16(data.num));
	printf("		Offset: %04x\n", be16(data.offs));
}
Пример #9
0
void PrintBRLYTEntry_grp1(brlyt_entry entry, u8* brlyt_file)
{
	brlyt_grp1_chunkbase data;
	BRLYT_fileoffset = entry.data_location;
	char		name[16];
	u16		numsubs;
	u16		unk;
	BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_grp1_chunkbase));
	printf("		Name: %s\n", data.name);
	printf("		Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]);
	printf("		Number of subs: %08x\n", be16(data.numsubs));
	printf("		unk: %08x\n", be16(data.unk));
}
Пример #10
0
u16 BRLAN_ReadAnimations(BRLAN_animation **anims)
{
	BRLAN_fileoffset = 0;
	brlan_header header;
	BRLAN_ReadDataFromMemoryX(&header, BRLAN_file, sizeof(brlan_header));
	BRLAN_fileoffset = be16(header.pai1_offset);
	brlan_pai1_universal universal;
	BRLAN_ReadDataFromMemoryX(&universal, BRLAN_file, sizeof(brlan_pai1_universal));
	
	int pai1_header_type;
	brlan_pai1_header_type1 pai1_header1;
	brlan_pai1_header_type2 pai1_header2;
	brlan_pai1_header_type2 pai1_header;
	
	if((be32(universal.flags) & (1 << 25)) >= 1) {
		pai1_header_type = 2;
		BRLAN_ReadDataFromMemory(&pai1_header2, BRLAN_file, sizeof(brlan_pai1_header_type2));
	} else {
		pai1_header_type = 1;
		BRLAN_ReadDataFromMemory(&pai1_header1, BRLAN_file, sizeof(brlan_pai1_header_type1));
	}
	
	CreateGlobal_pai1(&pai1_header, pai1_header1, pai1_header2, pai1_header_type);
	
	int tagcount = be16(pai1_header.num_entries);
	u32 *taglocations = (u32*)calloc(tagcount, sizeof(u32));
	*anims = (BRLAN_animation*)calloc(tagcount, sizeof(BRLAN_animation));
	fourcc CCs[256];
	memset(CCs, 0, 256*4);
	BRLAN_fileoffset = be32(pai1_header.entry_offset) + be16(header.pai1_offset);
	BRLAN_ReadDataFromMemory(taglocations, BRLAN_file, tagcount * sizeof(u32));
	int animcnt = 1;
	int i;
	for(i = 0; i < tagcount; i++) {
		BRLAN_fileoffset = be32(taglocations[i]) + be16(header.pai1_offset);
		brlan_entry tmpentry;
		BRLAN_ReadDataFromMemory(&tmpentry, BRLAN_file, sizeof(brlan_entry));
		if((be32(tmpentry.flags) & (1 << 25)) >= 1)
			BRLAN_fileoffset += sizeof(u32);
		memcpy(anims[animcnt]->name, tmpentry.name, 20);
		fourcc magick;
		BRLAN_ReadDataFromMemoryX(magick, BRLAN_file, 4);
		memcpy(CCs[i], magick, 4);
		if(FourCCInList(CCs[i]) == 1) {
			anims[animcnt]->offset = BRLAN_fileoffset;
			ReadTagFromBRLAN(anims, animcnt);
			animcnt++;
		}
	}
	return tagcount;
}
Пример #11
0
static void decrypt_retail_pkg(void)
{
	u8 key[0x10];
	u8 iv[0x10];

	if (be16(pkg + 0x06) != 1)
		fail("invalid pkg type: %x", be16(pkg + 0x06));

	if (key_get_simple("gpkg-key", key, 0x10) < 0)
		fail("failed to load the package key.");

	memcpy(iv, pkg + 0x70, 0x10);
	aes128ctr(key, iv, pkg + offset, size, pkg + offset);
}
Пример #12
0
static int header_check_mid(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 midi_header *hdr=(const struct midi_header *)buffer;
    if(be16(hdr->format) > 2 || be16(hdr->tracks) == 0)
        return 0;
    reset_file_recovery(file_recovery_new);
    file_recovery_new->extension=file_hint_mid.extension;
    file_recovery_new->file_check=&file_check_midi;
    if(file_recovery_new->blocksize < 8)
        return 1;
    file_recovery_new->calculated_file_size=4+4+6;
    file_recovery_new->data_check=&data_check_midi;
    return 1;
}
Пример #13
0
static int header_check_psb(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 psb_file_header *hdr=(const struct psb_file_header *)buffer;
#ifdef DEBUG_PSD
  log_info("channels %u\n", be16(hdr->channels));
  log_info("height %u\n", be32(hdr->height));
  log_info("width  %u\n", be32(hdr->width));
  log_info("depth  %u\n", be16(hdr->depth));
  log_info("color_mode %u\n", be16(hdr->color_mode));
#endif
  if(be16(hdr->channels)==0 || be16(hdr->channels)>56 ||
      be32(hdr->height)==0 || be32(hdr->height)>300000 ||
      be32(hdr->width)==0 || be32(hdr->width)>300000 ||
      be16(hdr->depth)==0 || (be16(hdr->depth)!=1 && be16(hdr->depth)%8!=0))
    return 0;
  reset_file_recovery(file_recovery_new);
  file_recovery_new->min_filesize=70;
  file_recovery_new->extension=file_hint_psb.extension;
  if(file_recovery_new->blocksize < 16)
    return 1;
  /* File header */
  file_recovery_new->calculated_file_size=0x1a;
  file_recovery_new->data_check=&psb_skip_color_mode;
  file_recovery_new->file_check=&file_check_psb;
  return 1;
}
Пример #14
0
static int header_check_xfs_sb(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 xfs_sb *sb=(const struct xfs_sb *)buffer;
  if(sb->sb_magicnum!=be32(XFS_SB_MAGIC) ||
      (uint16_t)be16(sb->sb_sectsize)  != (1U << sb->sb_sectlog) ||
      (uint32_t)be32(sb->sb_blocksize) != (1U << sb->sb_blocklog) ||
      (uint16_t)be16(sb->sb_inodesize) != (1U << sb->sb_inodelog))
    return 0;
  reset_file_recovery(file_recovery_new);
  file_recovery_new->extension=file_hint_xfs.extension;
  file_recovery_new->calculated_file_size=be32(sb->sb_blocksize);
  file_recovery_new->data_check=&data_check_size;
  file_recovery_new->file_check=&file_check_size;
  return 1;
}
Пример #15
0
int main(int argc, char *argv[])
{
	if (argc != 2)
		fail("usage: sceverify filename");

	ptr = mmap_file(argv[1]);

	type = be16(ptr + 0x0a);

	if (type == 1)
		read_self_header();
	else if(type == 3)
		read_pkg_header();
	else if(type == 4)
		read_spp_header();
	else
		fail("Unknown type: %d", type);

	if (flags & 0x8000)
		fail("devkit file; nothing to verify");

	if (klist == NULL)
		fail("no key found");

	decrypt();
	verify_signature();
	verify_hashes();

	if (did_fail)
		printf(" * please not that the hash will always fail for "
		       "unaligned non-LOAD phdrs\n");
	return 0;
}
Пример #16
0
int main(int argc, char *argv[])
{
	char *dir;

	if (argc != 2 && argc != 3)
		fail("usage: ungpkg filename.pkg [target]");

	pkg = mmap_file(argv[1]);

	if (argc == 2) {
		dir = malloc(0x31);
		memset(dir, 0, 0x31);
		memset(dir, 0, 0x30);
		memcpy(dir, pkg + 0x30, 0x30);
	} else {
		dir = argv[2];
	}

	MKDIR(dir, 0777);

	if (chdir(dir) != 0)
		fail("chdir(%s)", dir);

	offset = be64(pkg + 0x20);
	size = be64(pkg + 0x28);

	if (be16(pkg + 0x04) & 0x8000)
		decrypt_retail_pkg();
	else
		decrypt_debug_pkg();

	unpack_pkg();

	return 0;
}
Пример #17
0
static void file_check_midi(file_recovery_t *file_recovery)
{
    const uint64_t fs_org=file_recovery->file_size;
    struct midi_header hdr;
    unsigned int i;
    unsigned int tracks;
    uint64_t fs=4+4+6;
    file_recovery->file_size=0;
    if(my_fseek(file_recovery->handle, 0, SEEK_SET) < 0 ||
            fread(&hdr, sizeof(hdr), 1, file_recovery->handle) != 1)
        return ;
    tracks=be16(hdr.tracks);
    for(i=0; i<tracks; i++)
    {
        struct midi_header track;
#ifdef DEBUG_MIDI
        log_info("file_check_midi 0x%08llx\n", (unsigned long long)fs);
#endif
        if(my_fseek(file_recovery->handle, fs, SEEK_SET) < 0 ||
                fread(&track, 8, 1, file_recovery->handle) != 1 ||
                memcmp(&track.magic[0], "MTrk", 4)!=0)
            return ;
        fs+=8+be32(track.len);
    }
    if(fs_org < fs)
        return ;
    file_recovery->file_size=fs;
}
Пример #18
0
static void read_pkg_header(u8* ptr, fileinfo* info)
{
	info->flags    =    be16(ptr + 0x08);
	info->meta_offset = be32(ptr + 0x0c);
	info->header_len =  be64(ptr + 0x10);
	info->filesize =    be64(ptr + 0x18);

	klist = keys_get(KEY_PKG);
}
Пример #19
0
static void read_spp_header(void)
{
	flags    =    be16(ptr + 0x08);
	meta_offset = be32(ptr + 0x0c);
	header_len =  be64(ptr + 0x10);
	filesize =    be64(ptr + 0x18);

	klist = keys_get(KEY_SPP);
}
Пример #20
0
static int header_check_cwk(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 cwk_header *cwk=(const struct cwk_header *)buffer;
  if(be64(cwk->reserved0)!=0 || be16(cwk->reserved1)!=1)
    return 0;
  reset_file_recovery(file_recovery_new);
  file_recovery_new->extension=file_hint_cwk.extension;
  file_recovery_new->file_check=&file_check_cwk;
  return 1;
}
Пример #21
0
int test_HFSP(disk_t *disk_car, const struct hfsp_vh *vh,partition_t *partition,const int verbose, const int dump_ind)
{
  if (be32(vh->free_blocks) > be32(vh->total_blocks))
    return 1;
  /* Blocksize must be a multiple of 512 */
  if (be32(vh->blocksize)<512 ||
      ((be32(vh->blocksize)-1) & be32(vh->blocksize))!=0)
    return 1;
  /* http://developer.apple.com/technotes/tn/tn1150.html */
  if (be16(vh->version)==4 && vh->signature==be16(HFSP_VOLHEAD_SIG))
  {
    partition->upart_type=UP_HFSP;
    if(verbose>0 || dump_ind!=0)
    {
      log_info("\nHFS+ magic value at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
    }
  }
  else if (be16(vh->version)==5 && vh->signature==be16(HFSX_VOLHEAD_SIG))
  {
    partition->upart_type=UP_HFSX;
    if(verbose>0 || dump_ind!=0)
    {
      log_info("\nHFSX magic value at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
    }
  }
  else
  {
    return 1;
  }
  if(dump_ind!=0)
  {
    /* There is a little offset ... */
    dump_log(vh,DEFAULT_SECTOR_SIZE);
  }
  if(verbose>1)
  {
    log_info("blocksize %u\n",(unsigned) be32(vh->blocksize));
    log_info("total_blocks %u\n",(unsigned) be32(vh->total_blocks));
    log_info("free_blocks  %u\n",(unsigned) be32(vh->free_blocks));
  }
  return 0;
}
Пример #22
0
void PrintBRLYTEntries(brlyt_entry *entries, int entrycnt, u8* brlyt_file)
{
	int i;
	
	for(i = 0; i < entrycnt; i++) {
		printf("\n	Index %d (@%08x):\n", i, entries[i].data_location - 8);
		if((FourCCsMatch(entries[i].magic, pic1_magic) == 1) || (FourCCsMatch(entries[i].magic, pan1_magic) == 1) ||
		   (FourCCsMatch(entries[i].magic, bnd1_magic) == 1) || (FourCCsMatch(entries[i].magic, wnd1_magic) == 1)) {
			dbgprintf("pic1\n");
//			PrintBRLYTEntry_pic1(entries[i], brlyt_file);
			brlyt_pic1_chunk data;
			BRLYT_fileoffset = entries[i].data_location;
			BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_pic1_chunk));
			printf("%08x\n", BRLYT_fileoffset);
			printf("		Name: %s (%08x)\n", data.name);
			printf("		Type: %c%c%c%c\n", entries[i].magic[0], entries[i].magic[1], entries[i].magic[2], entries[i].magic[3]);
			printf("		Flags: %04x (%08x)\n", be16(data.flags));
			printf("		Alpha: %04x (%08x)\n", be16(data.alpha));
			printf("		X: %f (%08x) (%08x)\n", be32(data.x), &data.x, &data);
			printf("		Y: %f (%08x)\n", be32(data.y));
			printf("		X Magnification: %f (%08x)\n", be32(data.xmag));
			printf("		Y Magnification: %f (%08x)\n", be32(data.ymag));
			printf("		Width: %f (%08x)\n", be32(data.width));
			printf("		Height: %f (%08x)\n", be32(data.height));
			printf("		Angle: %f (%08x)\n", be32(data.angle));
			printf("		unk1: %f (%08x)\n", be32(data.unk[0]));
			printf("		unk2: %f (%08x)\n", be32(data.unk[1]));
			printf("		unk3: %f (%08x)\n", be32(data.unk[2]));
		}else if((FourCCsMatch(entries[i].magic, lyt1_magic) == 1)) {
			dbgprintf("lyt1\n");
			PrintBRLYTEntry_lyt1(entries[i], brlyt_file);
		}else if((FourCCsMatch(entries[i].magic, grp1_magic) == 1)) {
			dbgprintf("grp1\n");
			PrintBRLYTEntry_grp1(entries[i], brlyt_file);
		}else if((FourCCsMatch(entries[i].magic, txl1_magic) == 1) || (FourCCsMatch(entries[i].magic, mat1_magic) == 1) ||
			 (FourCCsMatch(entries[i].magic, fnl1_magic) == 1)) {
			dbgprintf("img\n");
			PrintBRLYTEntry_img(entries[i], brlyt_file);
		}else
			printf("		Unknown tag (%c%c%c%c)!\n",entries[i].magic[0],entries[i].magic[1],entries[i].magic[2],entries[i].magic[3]);
	}
}
Пример #23
0
static void read_self_header(void)
{
	flags    =    be16(ptr + 0x08);
	meta_offset = be32(ptr + 0x0c);
	header_len =  be64(ptr + 0x10);
	filesize =    be64(ptr + 0x18);
	info_offset = be64(ptr + 0x28);

	app_type =    be32(ptr + info_offset + 0x0c);

	klist = self_load_keys();
}
Пример #24
0
static void read_self_header(u8* ptr, fileinfo* info)
{
	info->flags    =    be16(ptr + 0x08);
	info->meta_offset = be32(ptr + 0x0c);
	info->header_len =  be64(ptr + 0x10);
	info->filesize =    be64(ptr + 0x18);
	info->info_offset = be64(ptr + 0x28);

	info->app_type =    be32(ptr + info->info_offset + 0x0c);

	klist = self_load_keys(info);
}
Пример #25
0
static uint64_t parse_strip_be(FILE *handle, const TIFFDirEntry *entry_strip_offsets, const TIFFDirEntry *entry_strip_bytecounts)
{
  const unsigned int nbr=(be32(entry_strip_offsets->tdir_count)<2048?
      be32(entry_strip_offsets->tdir_count):
      2048);
  unsigned int i;
  uint32_t *offsetp;
  uint32_t *sizep;
  uint64_t max_offset=0;
  if(be32(entry_strip_offsets->tdir_count) != be32(entry_strip_bytecounts->tdir_count))
    return -1;
  if(be32(entry_strip_offsets->tdir_count)==0 ||
      be16(entry_strip_offsets->tdir_type)!=4 ||
      be16(entry_strip_bytecounts->tdir_type)!=4)
    return -1;
  offsetp=(uint32_t *)MALLOC(nbr*sizeof(*offsetp));
  if(fseek(handle, be32(entry_strip_offsets->tdir_offset), SEEK_SET) < 0 ||
      fread(offsetp, sizeof(*offsetp), nbr, handle) != nbr)
  {
    free(offsetp);
    return -1;
  }
  sizep=(uint32_t *)MALLOC(nbr*sizeof(*sizep));
  if(fseek(handle, be32(entry_strip_bytecounts->tdir_offset), SEEK_SET) < 0 ||
      fread(sizep, sizeof(*sizep), nbr, handle) != nbr)
  {
    free(offsetp);
    free(sizep);
    return -1;
  }
  for(i=0; i<nbr; i++)
  {
    const uint64_t tmp=be32(offsetp[i]) + be32(sizep[i]);
    if(max_offset < tmp)
      max_offset=tmp;
  }
  free(offsetp);
  free(sizep);
  return max_offset;
}
Пример #26
0
static void set_xfs_info(const struct xfs_sb *sb, partition_t *partition)
{
  partition->blocksize=be32(sb->sb_blocksize);
  partition->fsname[0]='\0';
  partition->info[0]='\0';
  switch(be16(sb->sb_versionnum) & XFS_SB_VERSION_NUMBITS)
  {
    case XFS_SB_VERSION_1:
      partition->upart_type = UP_XFS;
      snprintf(partition->info, sizeof(partition->info),
	  "XFS <=6.1, blocksize=%u", partition->blocksize);
      break;
    case XFS_SB_VERSION_2:
      partition->upart_type = UP_XFS2;
      snprintf(partition->info, sizeof(partition->info),
	  "XFS 6.2 - attributes, blocksize=%u", partition->blocksize);
      break;
    case XFS_SB_VERSION_3:
      partition->upart_type = UP_XFS3;
      snprintf(partition->info, sizeof(partition->info),
	  "XFS 6.2 - new inode version, blocksize=%u", partition->blocksize);
      break;
    case XFS_SB_VERSION_4:
      partition->upart_type = UP_XFS4;
      snprintf(partition->info, sizeof(partition->info),
	  "XFS 6.2+ - bitmap version, blocksize=%u", partition->blocksize);
      break;
    case XFS_SB_VERSION_5:
      partition->upart_type = UP_XFS5;
      snprintf(partition->info, sizeof(partition->info),
	  "XFS CRC enabled, blocksize=%u", partition->blocksize);
      break;
    default:
      snprintf(partition->info, sizeof(partition->info),
	  "XFS unknown version %u\n", be16(sb->sb_versionnum)& XFS_SB_VERSION_NUMBITS);
      break;
  }
  set_part_name(partition,sb->sb_fname,12);
}
Пример #27
0
static long long get_pts( unsigned char const *&inData,             // i
                          unsigned long        &sizeInOut,          // 
                          signed char           initialChar = -1 )  // sometimes we don't know until we have it
{
   unsigned char const *bytesIn = (unsigned char const *)inData ;
   unsigned long        size = sizeInOut ;

   if( initialChar < 0 )
   {
      initialChar = *bytesIn++ ;
      size-- ;
   }

   long long pts ;
   if( size >= 4 )
   {
      pts = (long long)((initialChar >> 1) & 0x07) << 30;
      unsigned short val = be16( bytesIn, size );
      pts |= (long long)(val >> 1) << 15;
      val = be16( bytesIn, size );
      pts |= (long long)(val >> 1);
   }
Пример #28
0
int xfs_gfun(disk_desc *d, g_module *m)
{
	xfs_sb_t *sb;
	s64_t size;

	m->m_guess = GM_NO;
	sb = (xfs_sb_t *)d->d_sbuf;

	/*
	 * Sanity checks from xfs_mount.c
	 */

	if (be32(sb->sb_magicnum) != XFS_SB_MAGIC)
		return (1);

	if (be32(sb->sb_blocksize) != getpagesize())
		return (1);

	if ((sb->sb_imax_pct > 100) || (sb->sb_sectsize <= 0))
		return (1);

	if ((be16(sb->sb_inodesize) < XFS_DINODE_MIN_SIZE) || (be16(sb->sb_inodesize) > XFS_DINODE_MAX_SIZE))
		return (1);

	if (be32(sb->sb_blocksize) != 1 << sb->sb_blocklog)
		return (1);

	size = be64(sb->sb_logstart) ? (s64_t)be32(sb->sb_logblocks) : 0LL;
	size = be64(sb->sb_dblocks) - size;
	size *= be32(sb->sb_blocksize);
	size /= d->d_ssize;

	m->m_guess = GM_YES;
	m->m_part.p_start = d->d_nsb;
	m->m_part.p_size = (unsigned long)size;
	m->m_part.p_typ = 0x83;

	return (1);
}
Пример #29
0
/* Minolta */
static int header_check_mrw(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 unsigned char prd_header[4]= { 0x00,'P','R','D'};
  const struct hdr *mrmhdr = (const struct hdr*)buffer;
  const struct hdr *prdhdr = (const struct hdr*)&mrmhdr->data;
  /* Picture Raw Dimensions */
  const struct prd *prd = (const struct prd*)&prdhdr->data;
  if(memcmp(&prdhdr->fourcc, prd_header, sizeof(prd_header))!=0)
    return 0;
  reset_file_recovery(file_recovery_new);
  file_recovery_new->extension=file_hint_mrw.extension;
  file_recovery_new->calculated_file_size= be32(mrmhdr->size)+ 8 +
    ((uint64_t)be16(prd->ccd.x) * be16(prd->ccd.y) * prd->datasize + 8 - 1) / 8;
  file_recovery_new->data_check=&data_check_size;
  file_recovery_new->file_check=&file_check_size;
  /*
     log_debug("size=%lu x=%lu y=%lu datasize=%lu\n", be32(mrmhdr->size),
     be16(prd->ccd.x), be16(prd->ccd.y), prd->datasize);
     log_debug("mrw_file_size %lu\n", (long unsigned)file_recovery_new->calculated_file_size);
     */
  return 1;
}
Пример #30
0
static void parse_pkg_sce(void)
{
	u16 flags;
	u16 type;
	u32 hdr_len;
	u8 *ptr;
	struct keylist *k;

	flags    = be16(pkg + 0x08);
	type     = be16(pkg + 0x0a);
	hdr_len  = be64(pkg + 0x10);
	dec_size = be64(pkg + 0x18);

	if (type != 3)
		fail("no update .pkg file");

	if (flags & 0x8000) {
		pkg += hdr_len;
		return parse_pkg();
	}

	k = keys_get(KEY_PKG);

	if (sce_decrypt_header(pkg, k) < 0)
		fail("header decryption failed");

	if (sce_decrypt_data(pkg) < 0)
		fail("data decryption failed");

	ptr = malloc(dec_size);
	memset(ptr, 0, dec_size);

	decompress_pkg(ptr);

	pkg = ptr;

	parse_pkg();
}