Subdomain Posts
None | 359 days ago
PHP | 374 days ago
PHP | 374 days ago
None | 567 days ago
C | 567 days ago
C | 567 days ago
None | 620 days ago
None | 632 days ago
None | 632 days ago
None | 727 days ago
Recent Posts
HTML | 5 sec ago
PHP | 22 sec ago
Lisp | 35 sec ago
None | 36 sec ago
None | 49 sec ago
None | 52 sec ago
None | 1 min ago
Bash | 1 min ago
None | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By mcuelenaere on the 29th of Aug 2008 12:09:40 PM Download | Raw | Embed | Report
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. /*
  6.  * Made by Maurus Cuelenaere
  7.  *
  8.  * Based on http://minnie.tuhs.org/VSTa/srctree/newsrc/srv/bfs/bfs.h.html
  9.  * and http://www.gruppo4.com/~tobia/zenrecover.shtml
  10.  *
  11.  */
  12.  
  13. struct partition_header
  14. {
  15.     unsigned char end[4];
  16.     unsigned char start[4];
  17.     char name[8];
  18. };
  19.  
  20. struct main_header
  21. {
  22.     char mblk[4];
  23.     unsigned char sector_size[4];
  24.     unsigned char disk_size[8];
  25.     struct partition_header partitions[31];
  26. };
  27.  
  28. struct cfs_header
  29. {
  30.     unsigned char unk[8];
  31.     unsigned char unk2[4];
  32.     unsigned char unk3[4];
  33.     unsigned char unk4[4];
  34.     unsigned char unk5[4];
  35.     char identifier[4];
  36.     unsigned char unk7[4];
  37.     unsigned char unk8[4];
  38.     unsigned char unk9[4];
  39.     unsigned char unk10[4];
  40.     unsigned char unk11[4];
  41. };
  42.  
  43. #define CLUSTER_TO_OFFSET(n) ((n+1)*0x2000)
  44.  
  45. struct cfs_inode
  46. {
  47.     unsigned char magic[4]; /* BE 3B D9 0A */
  48.     unsigned char number[4]; /* Inode number */
  49.     unsigned char parent[4];
  50.     unsigned char unk[4]; /* Always 0xFFFF */
  51.     unsigned char type[4];
  52.     unsigned char created_time[4];
  53.     unsigned char lastmodified_time[4];
  54.     unsigned char unk2[4];
  55.     unsigned char first_class_chain[12][4];
  56.     unsigned char unk3[4];
  57.     unsigned char unk4[4];
  58.     unsigned char second_class_chain_first_cluster[4];
  59.     unsigned char unk9[4];
  60.     unsigned char unk10[4];
  61.     unsigned char second_class_chain_second_cluster[4];
  62.     unsigned char unk11[4];
  63.     unsigned char unk12[4];
  64.     unsigned char unk13[4];
  65.     unsigned char filesize[4];
  66.     unsigned char serial_number[4];
  67.     unsigned char number_of_metadata_records[4];
  68. };
  69.  
  70. struct cfs_inode_metadata
  71. {
  72.     unsigned char identifier[2];
  73.     unsigned char length[2];
  74.     //type   value
  75.     //"06" - uint16, eq 0x0100
  76.     //"07" - wchar_t[], original filename
  77.     //"0=" - wchar_t[], original path
  78.     //"0;" - uint16, eq 0x0002
  79.     //"0>" - uint32, filesize            |
  80.     //"11" - wchar_t[], album            |
  81.     //"12" - wchar_t[], artist           | in general its copy of the
  82.     //"13" - wchar_t[], genre            | metadata stored in the ID3 tag
  83.     //"14" - wchar_t[], title            | of the file
  84.     //"15" - uint16, length in seconds   |
  85.     //"16" - uint16, track number        |
  86.     //"17" - uint16, year                |
  87.     //not all of them must be used in the inode's metadata
  88.     unsigned char tag[6];
  89.     /* unsigned char data[le2int16(length)]; */
  90. };
  91.  
  92. struct cfs_second_class_chain_cluster
  93. {
  94.     /* sequence of cluster numbers that together form the part of the file's contents */
  95.     unsigned char cluster_numbers[2048][4];
  96. };
  97.  
  98. static unsigned short le2int16(unsigned char* buf)
  99. {
  100.    return (buf[1] << 8) | buf[0];
  101. }
  102.  
  103. static unsigned int le2int32(unsigned char* buf)
  104. {
  105.    return (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
  106. }
  107.  
  108. static char* strrev(char *s)
  109. {
  110.     int i;
  111.     static char ret[4];
  112.    
  113.     for(i=0; i<4; i++)
  114.         ret[3-i] = s[i];
  115.     return ret;
  116. }
  117.  
  118. static char* ucs2letochar(unsigned char* s)
  119. {
  120.     static char res[3];
  121.     res[0] = s[2];
  122.     res[1] = s[0];
  123.     res[2] = 0;
  124.     return res;
  125. }
  126.  
  127. static char* ucs2letostring(unsigned char* s)
  128. {
  129.     static char res[256];
  130.     int i, end;
  131.    
  132.     for(i=0; i < 255; i += 2)
  133.     {
  134.         if(s[i] == 0 && s[i+1] == 0)
  135.             end = i;
  136.     }
  137.    
  138.     for(i=0; i<end; i++)
  139.         res[i] = s[i*2];
  140.    
  141.     return (char*)&res;
  142. }
  143.  
  144. int main(int argc, char *argv[])
  145. {
  146.     FILE *image;
  147.     struct main_header hdr;
  148.     struct cfs_header *cfs_hdr;
  149.     struct cfs_inode *inode;
  150.     unsigned int i, j, k;
  151.     struct cfs_inode_metadata *metadata;
  152.     unsigned char* buffer;
  153.    
  154.     image = fopen(argv[1], "rb");
  155.     fread(&hdr, sizeof(struct main_header), 1, image);
  156.    
  157.     printf("[%s]: %d * 0x%x\n", strrev(hdr.mblk), le2int32(hdr.sector_size), le2int32(hdr.disk_size));
  158.     for(i=0; i<31; i++)
  159.     {
  160.         if(hdr.partitions[i].name[0] != 0)
  161.             printf(" * [%s]: 0x%x -> 0x%x\n", hdr.partitions[i].name, le2int32(hdr.partitions[i].start), le2int32(hdr.partitions[i].end));
  162.     }
  163.     printf("\n");
  164.    
  165. #define START     (((le2int32(hdr.partitions[1].start)*le2int32(hdr.sector_size)) & ~0xFFFF) + 0x10000)
  166. #define REL_START ( START - (le2int32(hdr.partitions[1].start)*le2int32(hdr.sector_size)) )
  167.    
  168.     buffer = malloc((le2int32(hdr.partitions[1].end)-le2int32(hdr.partitions[1].start))*le2int32(hdr.sector_size));
  169.     fseek(image, le2int32(hdr.partitions[1].start)*le2int32(hdr.sector_size), SEEK_SET);
  170.     fread(buffer, (le2int32(hdr.partitions[1].end)-le2int32(hdr.partitions[1].start))*le2int32(hdr.sector_size), 1, image);
  171.     fclose(image);
  172.    
  173.     printf("Start of CFS is at 0x%x...\n\n", START);
  174.    
  175.     cfs_hdr = (struct cfs_header*)&buffer[REL_START];
  176.     printf("[%s]\n", strrev(cfs_hdr->identifier));
  177.     printf(" * [%s]: 0x%x\n", "unk2" , le2int32(cfs_hdr->unk2));
  178.     printf(" * [%s]: 0x%x\n", "unk3" , le2int32(cfs_hdr->unk3));
  179.     printf(" * [%s]: 0x%x\n", "unk4" , le2int32(cfs_hdr->unk4));
  180.     printf(" * [%s]: 0x%x\n", "unk5" , le2int32(cfs_hdr->unk5));
  181.     printf(" * [%s]: %d\n", "unk7" , le2int32(cfs_hdr->unk7));
  182.     printf(" * [%s]: %d\n", "unk8" , le2int32(cfs_hdr->unk8));
  183.     printf(" * [%s]: 0x%x\n", "unk9" , le2int32(cfs_hdr->unk9));
  184.     printf(" * [%s]: 0x%x\n", "unk10" , le2int32(cfs_hdr->unk10));
  185.     printf(" * [%s]: 0x%x\n", "unk11" , le2int32(cfs_hdr->unk11));
  186.     printf("\n");
  187.    
  188.     for(i=0; i < (le2int32(hdr.partitions[1].end)-le2int32(hdr.partitions[1].start))*le2int32(hdr.sector_size); i += 4)
  189.     {
  190.         if(le2int32(&buffer[i]) == 0x3bbe0ad9)
  191.         {
  192.             inode = (struct cfs_inode*)&buffer[i];
  193.             printf("[0x%04x] at 0x%08x\n", le2int32(inode->magic), i);
  194.             printf(" * [current]: 0x%04x\n", le2int32(inode->number));
  195.             printf(" * [parent]: 0x%04x\n", le2int32(inode->parent));
  196.             printf(" * [type]: 0x%04x\n", le2int32(inode->type));
  197.             printf(" * [created_time]: %s", ctime((time_t*)inode->created_time));
  198.             printf(" * [lastmodified_time]: %s", ctime((time_t*)inode->lastmodified_time));
  199.             printf(" * [first_class_chain]:\n");
  200.             for(j=0; j<12; j++)
  201.             {
  202.                 if(le2int32(inode->first_class_chain[j]) != 0xFFFFFFFF)
  203.                     printf("   * [%d]: 0x%x\n", j+1, le2int32(inode->first_class_chain[j]));
  204.             }
  205.             printf(" * [second_class_chain]:\n");
  206.             printf("   * [1] 0x%x\n", le2int32(inode->second_class_chain_first_cluster));
  207.             printf("   * [2] 0x%x\n", le2int32(inode->second_class_chain_second_cluster));
  208.             printf(" * [serial_number]: 0x%x\n", le2int32(inode->serial_number));
  209.             printf(" * [metadata_records]: 0x%04x\n", le2int32(inode->number_of_metadata_records));
  210.             k = 0;
  211.             for(j=0; j < le2int32(inode->number_of_metadata_records); j++)
  212.             {
  213.                 metadata = (struct cfs_inode_metadata*)&buffer[i+sizeof(struct cfs_inode)+k];
  214.                 if(le2int16(metadata->length) == 4)
  215.                     printf("   * [%s]: 0x%x\n", ucs2letochar(metadata->tag), le2int32(&buffer[i+sizeof(struct cfs_inode)+k+sizeof(struct cfs_inode_metadata)]));
  216.                 else if(le2int16(metadata->length) == 2)
  217.                     printf("   * [%s]: 0x%x\n", ucs2letochar(metadata->tag), le2int16(&buffer[i+sizeof(struct cfs_inode)+k+sizeof(struct cfs_inode_metadata)]));
  218.                 else
  219.                     printf("   * [%s]: %s\n", ucs2letochar(metadata->tag), ucs2letostring(&buffer[i+sizeof(struct cfs_inode)+k+sizeof(struct cfs_inode_metadata)]));
  220.                 k += sizeof(struct cfs_inode_metadata)+le2int16(metadata->length);
  221.             }
  222.             printf("\n");
  223.         }
  224.     }
  225.    
  226.    
  227.     free(buffer);
  228.     return 0;
  229. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: