From: <ny...@us...> - 2006-12-24 15:38:22
|
Revision: 196 http://svn.sourceforge.net/pmplib/?rev=196&view=rev Author: nyaochi Date: 2006-12-24 07:38:22 -0800 (Sun, 24 Dec 2006) Log Message: ----------- Read and dump routines for db.dic Modified Paths: -------------- trunk/pmplib/lib/pmp_iriverplus3/dat.h trunk/pmplib/lib/pmp_iriverplus3/dic.c trunk/pmplib/lib/pmp_iriverplus3/dic.h trunk/pmplib/lib/pmp_iriverplus3/idx.c trunk/pmplib/lib/pmp_iriverplus3/ip3db.c trunk/pmplib/lib/pmp_iriverplus3/ip3db.h Modified: trunk/pmplib/lib/pmp_iriverplus3/dat.h =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/dat.h 2006-12-24 05:09:19 UTC (rev 195) +++ trunk/pmplib/lib/pmp_iriverplus3/dat.h 2006-12-24 15:38:22 UTC (rev 196) @@ -19,16 +19,16 @@ * */ -/* $Id:$ */ +/* $Id$ */ #ifndef __IP3DB_DAT_H__ #define __IP3DB_DAT_H__ typedef struct { - uint32_t uid; - uint32_t parent_uid; - uint8_t properties; - uint16_t filetype; + uint32_t uid; + uint32_t parent_uid; + uint8_t properties; + uint16_t filetype; ucs2char_t* object_name; ucs2char_t* name; uint32_t filesize; @@ -48,32 +48,32 @@ } dat_objects_t; typedef struct { - ucs2char_t* artist; - ucs2char_t* album; - ucs2char_t* genre; - ucs2char_t* title; - ucs2char_t* filepath; - ucs2char_t* filename; - uint32_t duration; - uint16_t rating; - uint32_t use_count; - uint16_t format; - uint16_t tracknumber; - uint8_t drm; - uint8_t lyric; - uint8_t purchase; - uint16_t protection; - uint32_t samplerate; - uint32_t bitrate; - uint8_t changed_flag; - uint32_t codec; - uint32_t clusm; - uint32_t clusa; - uint32_t albumart_pos; - ucs2char_t* release; - ucs2char_t* album_artist; - uint32_t object_uid; - uint32_t ratingtime; + ucs2char_t* artist; + ucs2char_t* album; + ucs2char_t* genre; + ucs2char_t* title; + ucs2char_t* filepath; + ucs2char_t* filename; + uint32_t duration; + uint16_t rating; + uint32_t use_count; + uint16_t format; + uint16_t tracknumber; + uint8_t drm; + uint8_t lyric; + uint8_t purchase; + uint16_t protection; + uint32_t samplerate; + uint32_t bitrate; + uint8_t changed_flag; + uint32_t codec; + uint32_t clusm; + uint32_t clusa; + uint32_t albumart_pos; + ucs2char_t* release; + ucs2char_t* album_artist; + uint32_t object_uid; + uint32_t ratingtime; } dat_music_t; typedef struct { Modified: trunk/pmplib/lib/pmp_iriverplus3/dic.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/dic.c 2006-12-24 05:09:19 UTC (rev 195) +++ trunk/pmplib/lib/pmp_iriverplus3/dic.c 2006-12-24 15:38:22 UTC (rev 196) @@ -19,7 +19,7 @@ * */ -/* $Id:$ */ +/* $Id$ */ /* Some important findings from db.dic: @@ -38,17 +38,99 @@ #include <ucs2char.h> #include "serialize.h" +#include "util.h" #include "ip3db.h" +#include "dic.h" -/* -typedef struct { - uint32_t next; - uint32_t type; - uint32_t idx_root; - ucs2char_t* name; -} dic_entry_t; -*/ +dic_t* dic_new() +{ + dic_t* dic = (dic_t*)malloc(sizeof(dic_t)); + if (dic) { + memset(dic, 0, sizeof(*dic)); + dic->num_music_fields = IP3DBF_MUSIC_LAST; + dic->music_fields = (dic_entry_t*)calloc(dic->num_music_fields, sizeof(dic_entry_t)); + dic->num_objects_fields = IP3DBF_OBJECTS_LAST; + dic->objects_fields = (dic_entry_t*)calloc(dic->num_objects_fields, sizeof(dic_entry_t)); + } + return dic; +} +void dic_finish(dic_t* dic) +{ + if (dic) { + free(dic->music_fields); + free(dic->objects_fields); + free(dic); + } +} + +static size_t dic_serialize_field(uint8_t* block, dic_entry_t* entry, int is_storing) +{ + uint8_t *p = block; + p += serialize_uint32be(p, &entry->next, 0); + p += serialize_uint32be(p, &entry->type, 0); + p += serialize_uint32be(p, &entry->idx_root, 0); + if (is_storing) { + p += (serialize_ucs2be_string_var(p, entry->name, is_storing) + 1) * sizeof(ucs2char_t); + } else { + p += (serialize_ucs2be_string_var_alloc(p, &entry->name) + 1) * sizeof(ucs2char_t); + } + return (size_t)(p - block); +} + +int dic_serialize(dic_t* dic, uint8_t* buffer, int is_storing) +{ + int i; + uint32_t next = 0; + + next = 0x00000056; + for (i = 0;i < IP3DBF_MUSIC_LAST;++i) { + dic_serialize_field(buffer + next, &dic->music_fields[i], is_storing); + next = dic->music_fields[i].next; + } + + next = 0x0000099A; + for (i = 0;i < IP3DBF_OBJECTS_LAST;++i) { + dic_serialize_field(buffer + next, &dic->objects_fields[i], is_storing); + next = dic->objects_fields[i].next; + } + + return 0; +} + +void dic_dump(dic_t* dic, FILE *fp) +{ + int i; + + fprintf(fp, "===== db.dic =====\n"); + + fprintf(fp, "MUSIC {\n"); + for (i = 0;i < IP3DBF_MUSIC_LAST;++i) { + const dic_entry_t* entry = &dic->music_fields[i]; + fprintf(fp, " FIELD %d = {\n", i); + fprintf(fp, " next: 0x%08X\n", entry->next); + fprintf(fp, " type: 0x%08X\n", entry->type); + fprintf(fp, " idx_root: 0x%08X\n", entry->idx_root); + fprints(fp, " name: %s\n", entry->name); + fprintf(fp, " }\n"); + } + fprintf(fp, "}\n"); + + fprintf(fp, "OBJECTS {\n"); + for (i = 0;i < IP3DBF_OBJECTS_LAST;++i) { + const dic_entry_t* entry = &dic->objects_fields[i]; + fprintf(fp, " FIELD %d = {\n", i); + fprintf(fp, " next: 0x%08X\n", entry->next); + fprintf(fp, " type: 0x%08X\n", entry->type); + fprintf(fp, " idx_root: 0x%08X\n", entry->idx_root); + fprints(fp, " name: %s\n", entry->name); + fprintf(fp, " }\n"); + } + fprintf(fp, "}\n"); + + fprintf(fp, "\n"); +} + uint32_t dic_get_idxroot(uint8_t *buffer, int field) { uint32_t value; Modified: trunk/pmplib/lib/pmp_iriverplus3/dic.h =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/dic.h 2006-12-24 05:09:19 UTC (rev 195) +++ trunk/pmplib/lib/pmp_iriverplus3/dic.h 2006-12-24 15:38:22 UTC (rev 196) @@ -19,11 +19,31 @@ * */ -/* $Id:$ */ +/* $Id$ */ #ifndef __IP3DB_DIC_H__ #define __IP3DB_DIC_H__ +typedef struct { + uint32_t next; + uint32_t type; + uint32_t idx_root; + ucs2char_t* name; +} dic_entry_t; + +struct tag_dic_t { + int num_music_fields; + dic_entry_t *music_fields; + int num_objects_fields; + dic_entry_t *objects_fields; +}; +typedef struct tag_dic_t dic_t; + +dic_t* dic_new(); +void dic_finish(dic_t* dic); +int dic_serialize(dic_t* dic, uint8_t* buffer, int is_storing); +void dic_dump(dic_t* dic, FILE *fp); + uint32_t dic_get_idxroot(uint8_t *buffer, int field); #endif/*__IP3DB_DIC_H__*/ Modified: trunk/pmplib/lib/pmp_iriverplus3/idx.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/idx.c 2006-12-24 05:09:19 UTC (rev 195) +++ trunk/pmplib/lib/pmp_iriverplus3/idx.c 2006-12-24 15:38:22 UTC (rev 196) @@ -19,7 +19,7 @@ * */ -/* $Id:$ */ +/* $Id$ */ /* Brief summary of db.idx structure: @@ -61,16 +61,6 @@ uint32_t next; } tail_t; -typedef struct { - uint32_t type; - union { - uint8_t byte; - uint16_t word; - uint32_t dword; - ucs2char_t* str; - } value; -} variant_t; - static size_t idx_serialize_header(uint8_t *block, header_t *header, int is_storing) { uint8_t *p = block; @@ -98,13 +88,13 @@ return sizeof(tail_t); } -void variant_init(variant_t* var, int type) +void variant_init(ip3db_variant_t* var, int type) { memset(var, 0, sizeof(*var)); var->type = type; } -void variant_finish(variant_t* var) +void variant_finish(ip3db_variant_t* var) { if (var->type == IP3DBVT_STRING) { ucs2free(var->value.str); @@ -127,7 +117,7 @@ uint8_t* buffer, uint32_t offset, node_t* node, - variant_t* key, + ip3db_variant_t* key, int* types, int level, int flag, @@ -144,7 +134,7 @@ ) { node_t node; - variant_t key; + ip3db_variant_t key; int type = types[level]; uint8_t* p = buffer + offset; @@ -203,7 +193,7 @@ uint8_t* buffer, uint32_t offset, node_t* node, - variant_t* key, + ip3db_variant_t* key, int* types, int level, int flag, Modified: trunk/pmplib/lib/pmp_iriverplus3/ip3db.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/ip3db.c 2006-12-24 05:09:19 UTC (rev 195) +++ trunk/pmplib/lib/pmp_iriverplus3/ip3db.c 2006-12-24 15:38:22 UTC (rev 196) @@ -31,8 +31,9 @@ #include <ucs2char.h> #include "util.h" +#include "ip3db.h" #include "dat.h" -#include "ip3db.h" +#include "dic.h" static ip3db_index_param_t ip3db_index_param[IP3DBIDX_LAST] = { {"Music.Title", 0x0086, {IP3DBVT_STRING, IP3DBVT_NONE, IP3DBVT_NONE}}, @@ -61,10 +62,14 @@ void ip3db_init(ip3db_t* db) { memset(db, 0, sizeof(*db)); + db->dat = dat_new(); + db->dic = dic_new(); } void ip3db_finish(ip3db_t* db) { + dic_finish(db->dic); + dat_finish(db->dat); free(db->dat_buffer); free(db->dic_buffer); free(db->idx_buffer); @@ -74,7 +79,6 @@ result_t ip3db_read(ip3db_t* db, const ucs2char_t* datfn, const ucs2char_t* dicfn, const ucs2char_t* idxfn) { FILE *fp = 0; - ucs2char_t filename[MAX_PATH]; fp = ucs2fopen(datfn, "rb"); if (!fp) { @@ -100,18 +104,28 @@ fread_all(fp, &db->idx_buffer, &db->idx_size); fclose(fp); + if (dic_serialize(db->dic, db->dic_buffer, 0) != 0) { + ip3db_finish(db); + return 1; + } + + if (dat_serialize(db->dat_buffer, db->dat, 0) != 0) { + ip3db_finish(db); + return 1; + } + return 0; } result_t ip3db_dump(ip3db_t* db, FILE *fpo) { + /* Dump db.dic */ + dic_dump(db->dic, fpo); + /* Dump db.dat */ - dat_t* dat = dat_new(); - dat_serialize(db->dat_buffer, dat, 0); - dat_dump(fpo, dat); - dat_finish(dat); + dat_dump(fpo, db->dat); /* Dump db.idx */ idx_dump(fpo, db); return 0; -} \ No newline at end of file +} Modified: trunk/pmplib/lib/pmp_iriverplus3/ip3db.h =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/ip3db.h 2006-12-24 05:09:19 UTC (rev 195) +++ trunk/pmplib/lib/pmp_iriverplus3/ip3db.h 2006-12-24 15:38:22 UTC (rev 196) @@ -48,15 +48,79 @@ IP3DBIDX_MAX_KEYLEVEL = 3, }; +/** + * Field type IDs used in db.dic (Do not change the associated values) + */ enum { - IP3DBVT_NONE, - IP3DBVT_BYTE, - IP3DBVT_WORD, - IP3DBVT_DWORD, - IP3DBVT_STRING, + IP3DBVT_NONE = 0, + IP3DBVT_STRING = 1, + IP3DBVT_BYTE = 2, + IP3DBVT_WORD = 3, + IP3DBVT_DWORD = 4, }; +/** + * Variant type for field values. + */ +typedef struct { + uint32_t type; + union { + uint8_t byte; + uint16_t word; + uint32_t dword; + ucs2char_t* str; + } value; +} ip3db_variant_t; +enum { + IP3DBF_MUSIC_BEGIN = 0, + IP3DBF_MUSIC_ARTIST = 0, + IP3DBF_MUSIC_ALBUM, + IP3DBF_MUSIC_GENRE, + IP3DBF_MUSIC_TITLE, + IP3DBF_MUSIC_FILEPATH, + IP3DBF_MUSIC_FILENAME, + IP3DBF_MUSIC_DURATION, + IP3DBF_MUSIC_RATING, + IP3DBF_MUSIC_USECOUNT, + IP3DBF_MUSIC_FILEFORMAT, + IP3DBF_MUSIC_TRACKNUMBER, + IP3DBF_MUSIC_DRM, + IP3DBF_MUSIC_LYRIC, + IP3DBF_MUSIC_PURCHASE, + IP3DBF_MUSIC_PROTECTIONSTATUS, + IP3DBF_MUSIC_SAMPLERATE, + IP3DBF_MUSIC_BITRATE, + IP3DBF_MUSIC_CHANGEDFLAG, + IP3DBF_MUSIC_AUDIOWAVECODEC, + IP3DBF_MUSIC_CLUSM, + IP3DBF_MUSIC_CLUSA, + IP3DBF_MUSIC_ALBUMARTPOS, + IP3DBF_MUSIC_ORGRELEASEDATE, + IP3DBF_MUSIC_UID, + IP3DBF_MUSIC_RATINGTIME, + IP3DBF_MUSIC_LAST, +}; + +enum { + IP3DBF_OBJECTS_BEGIN = 0, + IP3DBF_OBJECTS_UID = 0, + IP3DBF_OBJECTS_PARENTUID, + IP3DBF_OBJECTS_PROPERTIES, + IP3DBF_OBJECTS_FILETYPE, + IP3DBF_OBJECTS_OBJECTNAME, + IP3DBF_OBJECTS_NAME, + IP3DBF_OBJECTS_FILESIZE, + IP3DBF_OBJECTS_DATECREA, + IP3DBF_OBJECTS_RAWID, + IP3DBF_OBJECTS_PUOID1, + IP3DBF_OBJECTS_PUOID2, + IP3DBF_OBJECTS_LAST, +}; + + + + typedef struct { const char* name; uint32_t dic_offset; @@ -64,6 +128,7 @@ } ip3db_index_param_t; struct tag_dat_t; typedef struct tag_dat_t dat_t; +struct tag_dic_t; typedef struct tag_dic_t dic_t; typedef struct { uint8_t* dat_buffer; @@ -74,6 +139,7 @@ long idx_size; dat_t* dat; + dic_t* dic; } ip3db_t; int idx_dump(FILE *fpo, ip3db_t* db); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |