[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 3 wimlib - Library for working with WIM files 4 Copyright (C) 2010 Carl Thijssen 5 6 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. 7 8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 9 10 You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 11 12 */ 13 14 #include <stdio.h> 15 #include <stdlib.h> 16 #include <string.h> 17 #include <sys/stat.h> 18 #include "lzx.h" 19 20 typedef char CHAR ; 21 typedef unsigned long DWORD ; 22 typedef char GUID[16] ; 23 typedef unsigned short USHORT ; 24 typedef char BYTE ; 25 typedef unsigned long long ULONGLONG; 26 typedef long long LARGE_INTEGER; 27 typedef unsigned long long ULARGE_INTEGER; 28 29 typedef struct _RESHDR_DISK_SHORT 30 { 31 LARGE_INTEGER Size; 32 BYTE Flags; 33 LARGE_INTEGER Offset; 34 LARGE_INTEGER OriginalSize; 35 } RESHDR_DISK_SHORT ; 36 37 38 typedef struct _FILE_RESOURCE_HEADER 39 { 40 RESHDR_DISK_SHORT ResourceHeader; 41 USHORT PartNumber; 42 DWORD ReferenceCount; 43 BYTE Hash[20]; 44 LARGE_INTEGER ResourceHeaderIndex; 45 } FILE_RESOURCE_HEADER; 46 47 typedef struct _SECURITY_DATA 48 { 49 DWORD TotalLength; 50 DWORD NumEntries; 51 ULARGE_INTEGER *Sizes; 52 BYTE **Descriptors; 53 } SECURITY_DATA; 54 55 typedef struct _STREAM_ENTRY 56 { 57 LARGE_INTEGER Length; 58 LARGE_INTEGER Unused1; 59 BYTE Hash[20]; 60 USHORT StreamNameLength; 61 CHAR *StreamName; 62 } STREAM_ENTRY; 63 64 typedef struct _DIRENTRY 65 { 66 LARGE_INTEGER Length; 67 DWORD Attributes; 68 DWORD SecurityId; 69 LARGE_INTEGER SubdirOffset; 70 LARGE_INTEGER Unused1; 71 LARGE_INTEGER Unused2; 72 LARGE_INTEGER CreationTime; 73 LARGE_INTEGER LastAccessTime; 74 LARGE_INTEGER LastWriteTime; 75 BYTE *Hash; 76 DWORD ReparseTag; 77 DWORD ReparseReserved; 78 LARGE_INTEGER HardLink; 79 USHORT Streams; 80 USHORT ShortNameLength; 81 USHORT FileNameLength; 82 USHORT FileNameAsciiLength; 83 CHAR *ShortFileName; 84 CHAR *ShortFileNameAscii; 85 CHAR *FileName; 86 USHORT FileNamePad; 87 CHAR *FileNameAscii; 88 CHAR *fullpath; 89 STREAM_ENTRY *StreamEntries; 90 BYTE *rest; 91 USHORT restsize; 92 void *next; 93 void *kids; 94 void *nextbrother; 95 LARGE_INTEGER DirContentSize; 96 LARGE_INTEGER CurDirSize; 97 } DIRENTRY; 98 99 typedef struct _BOOT_META_DATA 100 { 101 SECURITY_DATA SecurityData; 102 DIRENTRY *DirEntry; 103 } BOOT_META_DATA ; 104 105 #define RESHDR_FLAG_FREE 0x01 106 #define RESHDR_FLAG_METADATA 0x02 107 #define RESHDR_FLAG_COMPRESSED 0x04 108 #define RESHDR_FLAG_SPANNED 0x08 109 110 typedef struct _WIM_HEADER 111 { 112 CHAR ImageTag[8]; 113 DWORD Size; 114 DWORD Version; 115 DWORD Flags; 116 DWORD ChunckSize; 117 CHAR Guid[16]; 118 USHORT PartNumber; 119 USHORT TotalParts; 120 DWORD ImageCount; 121 RESHDR_DISK_SHORT OffsetTable; 122 RESHDR_DISK_SHORT XmlData; 123 RESHDR_DISK_SHORT BootMetaData; 124 DWORD BootIndex; 125 RESHDR_DISK_SHORT Integrity; 126 CHAR Unused[60]; 127 } WIM_HEADER ; 128 129 #define FLAG_HEADER_RESERVED 0x00000001 130 #define FLAG_HEADER_COMPRESSION 0x00000002 131 #define FLAG_HEADER_READONLY 0x00000004 132 #define FLAG_HEADER_SPANNED 0x00000008 133 #define FLAG_HEADER_RESOURCE_ONLY 0x00000010 134 #define FLAG_HEADER_METADATA_ONLY 0x00000020 135 #define FLAG_HEADER_WRITE_IN_PROGRESS 0x00000040 136 #define FLAG_HEADER_RP_FIX 0x00000080 // reparse point fixup 137 #define FLAG_HEADER_COMPRESS_RESERVED 0x00010000 138 #define FLAG_HEADER_COMPRESS_XPRESS 0x00020000 139 #define FLAG_HEADER_COMPRESS_LZX 0x00040000 140 141 #define FILE_ATTRIBUTE_READONLY 0x1 142 #define FILE_ATTRIBUTE_HIDDEN 0x2 143 #define FILE_ATTRIBUTE_SYSTEM 0x4 144 #define FILE_ATTRIBUTE_DIRECTORY 0x10 145 #define FILE_ATTRIBUTE_ARCHIVE 0x20 146 #define FILE_ATTRIBUTE_DEVICE 0x40 147 #define FILE_ATTRIBUTE_NORMAL 0x80 148 #define FILE_ATTRIBUTE_TEMPORARY 0x100 149 #define FILE_ATTRIBUTE_SPARSE_FILE 0x200 150 #define FILE_ATTRIBUTE_REPARSE_POINT 0x400 151 #define FILE_ATTRIBUTE_COMPRESSED 0x800 152 #define FILE_ATTRIBUTE_OFFLINE 0x1000 153 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000 154 #define FILE_ATTRIBUTE_ENCRYPTED 0x4000 155 #define FILE_ATTRIBUTE_VIRTUAL 0x10000 156 157 158 DWORD GetDWord(FILE *fp); 159 USHORT GetUshort(FILE *fp); 160 LARGE_INTEGER GetLargeInteger(FILE *fp); 161 LARGE_INTEGER GetLargeInteger7(FILE *fp); 162 BYTE GetFlags1(FILE *fp); 163 164 static char *w2a(void *string, int len); 165 static char *a2w(void *string, int len, int *out_len); 166 int comparehashes (const void* x, const void *y); 167 int compareoffsets (const void* a, const void *b); 168 169 int ReadWimHeader(FILE *fp,WIM_HEADER *Header); 170 FILE_RESOURCE_HEADER *ReadLookupTable(FILE *fp,LARGE_INTEGER offset,LARGE_INTEGER size,LARGE_INTEGER *numoffsets); 171 SECURITY_DATA ReadSecurityData(FILE *fp,LARGE_INTEGER offset); 172 BOOT_META_DATA ReadBootMetaDataTable(FILE *fp,RESHDR_DISK_SHORT BootMetaData); 173 BYTE *ReadXML(FILE *fp, LARGE_INTEGER offset,LARGE_INTEGER size); 174 int ReadFileResource(FILE *fp,LARGE_INTEGER offset, LARGE_INTEGER size, LARGE_INTEGER unpacksize, char *filename); 175 DIRENTRY *ReadDir(FILE *fp,LARGE_INTEGER *offset,char *path,DIRENTRY *last); 176 177 int PrintHeader (WIM_HEADER Header); 178 int PrintBootMetaData(BOOT_META_DATA bmd); 179 180 int WriteDirEntry(FILE *fp,DIRENTRY *direntry); 181 int WriteSecurityData(FILE *fp,SECURITY_DATA sd); 182 int WriteFile(FILE *fp,FILE_RESOURCE_HEADER *FileResourceHeader, char *filename); 183 DIRENTRY *CreateFile(char *filename, char *destpath, BYTE *filehash); 184 DIRENTRY *CreateDirectory(char *filename, char *destpath, BYTE *filehash); 185 186 int WriteWimHeader(FILE *fp,WIM_HEADER *Header); 187 RESHDR_DISK_SHORT WriteLookupTable(FILE *fp,FILE_RESOURCE_HEADER *frh,LARGE_INTEGER items); 188 RESHDR_DISK_SHORT WriteXML(FILE *fp,BYTE *buf,LARGE_INTEGER size); 189 RESHDR_DISK_SHORT WriteBootMetaData(FILE *fp,BOOT_META_DATA bmd); 190 RESHDR_DISK_SHORT WriteIntegrity(FILE *fp); 191 192 int CopyFileResource(FILE *infile, FILE_RESOURCE_HEADER *frh, FILE *of); 193 int CopyFileResources(FILE *infile,FILE *of,FILE_RESOURCE_HEADER *frh,LARGE_INTEGER numitems); 194 FILE_RESOURCE_HEADER *WriteUnCompressedFileResource(FILE *of,char *srcfilename); 195 FILE_RESOURCE_HEADER *AddFileResource(CHAR *path,FILE *of); 196 DIRENTRY *FindFile2(DIRENTRY *tree, CHAR *path, CHAR *filename); 197 int ExtractFile(DIRENTRY *extractfile,FILE_RESOURCE_HEADER *frh, LARGE_INTEGER numoffsets, FILE *fp, CHAR *filename);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |