1 #define TRUE			1
2 #define FALSE			0
3 #define SPECIAL_BLOCK	- 3
4 #define END_OF_CHAIN	- 2
5 #define UNUSED			- 1
6 
7 #define NO_ENTRY		0
8 #define STORAGE			1
9 #define STREAM			2
10 #define ROOT			5
11 #define SHORT_BLOCK		3
12 
13 #define FAT_START		0x4c
14 #define OUR_BLK_SIZE	512
15 #define DIRS_PER_BLK	4
16 #ifndef __CYGWIN
17 	#define MIN(x, y)	((x) < (y) ? (x) : (y))
18 #endif
19 
20 #include <stdarg.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include <sys/types.h>
24 #include <unistd.h>
__construct(ServerRequestInterface $request, ResponseInterface $response, array $allowedMethods)25 #include <stdlib.h>
26 #include <fcntl.h>
27 #include <sys/stat.h>
28 #include <ctype.h>
29 
30 struct OLE_HDR
31 {
32 	char			magic[8];				/*0*/
33 	char			clsid[16];				/*8*/
34        __U16_TYPE      uMinorVersion;                  /*24*/
35        __U16_TYPE      uDllVersion;                    /*26*/
36        __U16_TYPE      uByteOrder;                             /*28*/
37        __U16_TYPE      uSectorShift;                   /*30*/
38        __U16_TYPE      uMiniSectorShift;               /*32*/
39        __U16_TYPE      reserved;                               /*34*/
40        u_int32_t       reserved1;                              /*36*/
41        u_int32_t       reserved2;                              /*40*/
42        u_int32_t       num_FAT_blocks;                 /*44*/
43        u_int32_t       root_start_block;               /*48*/
44        u_int32_t       dfsignature;                    /*52*/
45        u_int32_t       miniSectorCutoff;               /*56*/
46        u_int32_t       dir_flag;                               /*60 first sec in the mini fat chain*/
47        u_int32_t       csectMiniFat;                   /*64 number of sectors in the minifat */
48        u_int32_t       FAT_next_block;                 /*68*/
49        u_int32_t       num_extra_FAT_blocks;   /*72*/
50 	/* FAT block list starts here !! first 109 entries  */
51 };
52 
53 struct OLE_DIR
54 {
55 	char			name[64];
56 	unsigned short	namsiz;
57 	char			type;
58 	char			bflags;					//0 or 1
59 	unsigned long	prev_dirent;
60 	unsigned long	next_dirent;
61 	unsigned long	dir_dirent;
62 	char			clsid[16];
63 	unsigned long	userFlags;
64 	int				secs1;
65 	int				days1;
66 	int				secs2;
67 	int				days2;
68 	unsigned long	start_block;			//starting SECT of stream
69 	unsigned long	size;
70 	short			reserved;				//must be 0
71 };
72 
73 struct DIRECTORY
74 {
75 	char	name[64];
76 	int		type;
77 	int		level;
78 	int		start_block;
79 	int		size;
80 	int		next;
81 	int		prev;
82 	int		dir;
83 	int		s1;
84 	int		s2;
85 	int		d1;
86 	int		d2;
87 }
88 *dirlist, *dl;
89 
90 int				get_dir_block(unsigned char *fd, int blknum, int buffersize);
91 int				get_dir_info(unsigned char *src);
92 void			extract_stream(char *fd, int blknum, int size);
93 void			dump_header(struct OLE_HDR *h);
94 int				dump_dirent(int which_one);
95 int				get_block(unsigned char *fd, int blknum, unsigned char *dest, long long int buffersize);
96 int				get_FAT_block(unsigned char *fd, int blknum, int *dest, int buffersize);
97 int				reorder_dirlist(struct DIRECTORY *dir, int level);
98 
99 unsigned char	*get_ole_block(unsigned char *fd, int blknum, unsigned long long buffersize);
100 struct OLE_HDR	*reverseBlock(struct OLE_HDR *dest, struct OLE_HDR *h);
101 
102 void			dump_ole_header(struct OLE_HDR *h);
103 void			*Malloc(size_t bytes);
104 void			die(char *fmt, void *arg);
105 void			init_ole();
106