tags:

views:

47

answers:

1

EDIT: (secid + 1) * 512 should be (secid + 1) * sec_size

hi.

having a bit of a struggle wrestling with the compound document format. I'm working in C at the moment but i am having problems with locating the directory sector. I can obtain the compound doc header which is trivial and i know the formula for finding a file offset of a sector id ( secid + 1 << sec_size), but whenever i use this formula to convert the secid to fileoffset for the directory i get random values. can someone help me understand how i resolve secid offsets properly and maybe also how to develop secid chains from the sector allocation table in a compound document.

Thanks.

Here is an example of what ive tried.(excuse the awful code lol)

  comp_doc_header* cdh((comp_doc_header*)buffer);
  printf("cdoc header:%d\n", sizeof(cd_dir_entry));
  if(cdh->rev_num == 0x003E)printf("rev match\n");
  //check magic number
  if(cdh->comp_doc_id[0] != (unsigned char)0xD0 ||
     cdh->comp_doc_id[1] != (unsigned char)0xCF ||
     cdh->comp_doc_id[2] != (unsigned char)0x11 ||
     cdh->comp_doc_id[3] != (unsigned char)0xE0 ||
     cdh->comp_doc_id[4] != (unsigned char)0xA1 ||
     cdh->comp_doc_id[5] != (unsigned char)0xB1 ||
     cdh->comp_doc_id[6] != (unsigned char)0x1A ||
     cdh->comp_doc_id[7] != (unsigned char)0xE1)
    return 0;

  buffer += 512;

  //here i try and get the first directory entry
  cd_dir_entry* cde((cd_dir_entry*)&buffer[(cdh->first_sector_id + 1) << 512]);
A: 

Is this C? I can't parse your first or last posted lines

cd_dir_entry* cde((cd_dir_entry*)&buffer[(cdh->first_sector_id + 1) << 512]);

It appears you're declaring cde as a function that returns a pointer to a cd_dir_entry; but the parameter prototype is all wrong ... so you're calling the function and multiplying the result by cd_dir_entry and promptly ignoring the result of the multiplication.


Edit

My simplification trying to understand the line

cd_dir_entry* cde(<cast>&buffer[(cdh->first_sector_id + 1) << 512]);
cd_dir_entry* cde(<cast>&buffer[<elem>]);
cd_dir_entry* cde(<parameter>);
/* this is either a function prototype */
/* or a multiplication with `cd_dir_entry` and the value returned from cde() */
/* in either case it does nothing (no side-effects present), */
/* unless cde messes with global variables */
pmg
hmmmm. im using a c++ compiler. thats and initialization! maybe(probably) ansi c does not support function style initialization. old habits you see.
jmgunn87
what i am doing is i am casting a char*(buffer) at index([cdh->first_sector_id +1)<<512]) into a cd_dir_entry*. where are there any function calls in that line of code?
jmgunn87
oh and btw you wont be able to parse it in any case because i haven't provided and headers for it. your compiler won't know what a cd_dir_entry* is unless of course you have that as a built in type and the chances of that bieng the case are very remote.
jmgunn87
I don't need no headers :)
pmg
lol ok!........
jmgunn87
So ... it's `C++`. I'm off then.
pmg
heres even simpler. cde is a variable being initialized
jmgunn87
cde is not a function. cd_dir_entry* cde = (cd_dir_entry*) get me?
jmgunn87