0

How do I get the byte array for PPT and PPTX file types?

I'm currently validating the following:

private static readonly byte[] BMP = { 66, 77 };
private static readonly byte[] DOC = { 208, 207, 17, 224, 161, 177, 26, 225 };
private static readonly byte[] JPG = { 255, 216, 255 };
private static readonly byte[] PDF = { 37, 80, 68, 70, 45, 49, 46 };
private static readonly byte[] PNG = { 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82 };

But these byte arrays were easy to find online.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
  • 2
    https://en.wikipedia.org/wiki/List_of_file_signatures – Amadan Jan 16 '19 at 06:57
  • Those are all hex based, do I just simply convert that to byte array? – Enthused Dragon Jan 16 '19 at 06:59
  • 1
    Yes. There's no difference if you write `{ 66, 77 }` or `{ 0x42, 0x4D }`. – Amadan Jan 16 '19 at 07:01
  • 2
    .pptx uses a zip file as a container (e.g. [this](https://support.office.com/en-us/article/extract-files-or-objects-from-a-powerpoint-file-85511e6f-9e76-41ad-8424-eab8a5bbc517)) so will be indistinguishable from a .zip file from looking only at its first bytes. – Wai Ha Lee Jan 16 '19 at 07:06
  • Thanks, I'll give this a go. I haven't worked with hexes much. Will it always be 0x?? or can would it ever be 1x?? – Enthused Dragon Jan 16 '19 at 07:24
  • @WaiHaLee Very interesting, I never knew that. Thanks for the info. – Enthused Dragon Jan 16 '19 at 07:25
  • It's always `0x` - see, e.g. [What do numbers using 0x notation mean?](https://stackoverflow.com/q/8186965/1364007) (a C question, but the notation followed from C and C++). – Wai Ha Lee Jan 16 '19 at 07:48

0 Answers0