128 if ((Char ==
'\\') || (Char ==
'/'))
145 for (
size_t i = 0;
i <
Path.size(); ++
i)
169 j =
i = (
Path[0] ? (
Path[1] ==
':' ? 2 : 0) : 0);
175 return Path.c_str() +
j;
186 if (
Path.length() > 0)
250 Criteria->
Search = SearchCriteria;
281 if (!
Node->TargetFolder.empty())
283 fname =
Node->TargetFolder + fname;
301 printf(
"ERROR: Invalid codec specified!\n");
328 std::string ConvertedFileName;
587 DPRINT(
MAX_TRACE, (
"Skipping file (%s) FileOffset (0x%X) LastFileOffset (0x%X).\n",
664 ULONG TotalBytesRead;
702 DPRINT(
MAX_TRACE, (
"Extracting file at uncompressed offset (0x%X) Size (%u bytes) AO (0x%X) UO (0x%X).\n",
705 (
UINT)
File->DataBlock->AbsoluteOffset,
706 (
UINT)
File->DataBlock->UncompOffset));
712 DestFile =
fopen(DestName,
"rb");
713 if (DestFile !=
NULL)
719 DestFile =
fopen(DestName,
"w+b");
720 if (DestFile ==
NULL)
728 DestFile =
fopen(DestName,
"w+b");
729 if (DestFile ==
NULL)
770 CurrentOffset =
File->DataBlock->UncompOffset;
779 DPRINT(
MAX_TRACE, (
"CO (0x%X) ReuseBlock (%u) Offset (0x%X) Size (%d) BytesLeftInBlock (%d)\n",
802 DPRINT(
MAX_TRACE, (
"Data block: Checksum (0x%X) CompSize (%u bytes) UncompSize (%u bytes)\n",
893 DPRINT(
MAX_TRACE, (
"Continuing extraction of file at uncompressed offset (0x%X) Size (%u bytes) AO (0x%X) UO (0x%X).\n",
896 (
UINT)
File->DataBlock->AbsoluteOffset,
897 (
UINT)
File->DataBlock->UncompOffset));
965 BytesSkipped = (
Offset - CurrentOffset);
969 BytesToWrite -= BytesSkipped;
971 if (
Size < BytesToWrite)
974 DPRINT(
MAX_TRACE, (
"Offset (0x%X) CurrentOffset (0x%X) ToWrite (%u) Skipped (%u)(%u) Size (%u).\n",
983 BytesToWrite, 1, DestFile) < 1)
992 Size -= BytesToWrite;
994 CurrentOffset += BytesToWrite;
1053#ifndef CAB_READ_ONLY
1217 DPRINT(
MID_TRACE, (
"File not found (%s).\n", FileNode->FileNameOnDisk.c_str()));
1261 DPRINT(
MIN_TRACE, (
"Cannot read from file. BytesToRead (%u) BytesRead (%u) CurrentIBufferSize (%u).\n",
1343 DPRINT(
MAX_TRACE, (
"First on new disk. CurrentIBufferSize (%u) CurrentOBufferSize (%u).\n",
1441 if (FolderNode->Commit)
1526 std::string NewFileName;
1532 SrcFile =
fopen(NewFileName.c_str(),
"rb");
1533 if (SrcFile ==
NULL)
1610 std::string szSearchPath = Criteria->Search;
1614 std::string pszFile;
1616 if (sep != std::string::npos)
1618 pszFile = szSearchPath.substr(sep + 1);
1620 szFilePath = szSearchPath.substr(0, sep + 1);
1624 pszFile = Criteria->Search;
1634 hFind =
FindFirstFile(Criteria->Search.c_str(), &FindFileData);
1648 szFile += FindFileData.cFileName;
1674 if(
stat(szFile.c_str(), &stbuf) == 0)
1763 const char* DiskLabel)
1778#ifndef CAB_READ_ONLY
1858 DPRINT(
MAX_TRACE, (
"FileName '%s' FileOffset (0x%X) FileSize (%u).\n",
1859 File->FileName.c_str(),
1865 DPRINT(
MAX_TRACE, (
"GetAbsoluteOffset(): Comparing (0x%X, 0x%X) (%u).\n",
1872 if ((
Node->Data.UncompSize == 0) ||
1875 Node->Data.UncompSize)))
1911 Node->File.FileControlID));
2027 File->FileName = Buf;
2029 DPRINT(
MAX_TRACE, (
"Found file '%s' at uncompressed offset (0x%X). Size (%u bytes) ControlId (0x%X).\n",
2030 File->FileName.c_str(),
2049 ULONG AbsoluteOffset;
2056 DPRINT(
MAX_TRACE, (
"Reading data blocks for folder (%u) at absolute offset (0x%X).\n",
2085 DPRINT(
MAX_TRACE, (
"AbsOffset (0x%X) UncompOffset (0x%X) Checksum (0x%X) CompSize (%u) UncompSize (%u).\n",
2086 (
UINT)AbsoluteOffset,
2089 Node->Data.CompSize,
2090 Node->Data.UncompSize));
2092 Node->AbsoluteOffset = AbsoluteOffset;
2093 Node->UncompOffset = UncompOffset;
2095 AbsoluteOffset +=
sizeof(
CFDATA) +
Node->Data.CompSize;
2096 UncompOffset +=
Node->Data.UncompSize;
2286 UlongCount =
Size / 4;
2288 pb = (
unsigned char*)
Buffer;
2291 while (UlongCount-- > 0)
2295 ul |= (((
ULONG)(*pb++)) << 8);
2296 ul |= (((
ULONG)(*pb++)) << 16);
2297 ul |= (((
ULONG)(*pb++)) << 24);
2307 ul |= (((
ULONG)(*pb++)) << 16);
2309 ul |= (((
ULONG)(*pb++)) << 8);
2357 const char* retryPattern =
NULL;
2358 const char* retryFileName =
NULL;
2368 retryPattern = Pattern;
2388 Pattern = retryPattern;
2403#ifndef CAB_READ_ONLY
2473 TotalSize +=
sizeof(
ULONG);
2527 if (FileNode->Commit)
2546 ReservedSize |= (0 << 16);
2547 ReservedSize |= (0 << 24);
2629 if (FolderNode->Commit)
2631 DPRINT(
MAX_TRACE, (
"Writing folder entry. CompressionType (0x%X) DataBlockCount (%d) DataOffset (0x%X).\n",
2632 FolderNode->Folder.CompressionType, FolderNode->Folder.DataBlockCount, (
UINT)FolderNode->Folder.DataOffset));
2653 bool SetCont =
false;
2663 File->Delete =
true;
2672 File->Delete =
false;
2676 DPRINT(
MAX_TRACE, (
"Writing file entry. FileControlID (0x%X) FileOffset (0x%X) FileSize (%u) FileName (%s).\n",
2720 DPRINT(
MAX_TRACE, (
"Reading block at (0x%X) CompSize (%u) UncompSize (%u).\n",
2769 DPRINT(
MAX_TRACE, (
"Block compressed. CurrentIBufferSize (%u) TotalCompSize(%u).\n",
2809 DPRINT(
MAX_TRACE, (
"Writing block. Checksum (0x%X) CompSize (%u) UncompSize (%u).\n",
2856 DPRINT(
MAX_TRACE, (
"day: %d, mon: %d, year:%d, hour: %d, min: %d, sec: %d\n",
2860 *DosDate = ((timedef->
tm_mday + 1) << 0)
2861 | ((timedef->
tm_mon + 1) << 5)
2862 | (((timedef->
tm_year + 1900) - 1980) << 9);
2864 *DosTime = (timedef->
tm_sec << 0)
static ACPI_BUFFER CurrentBuffer
vector< FileInfo > FileList
PRTL_UNICODE_STRING_BUFFER Path
char * strcat(char *DstString, const char *SrcString)
ACPI_SIZE strlen(const char *String)
char * strcpy(char *DstString, const char *SrcString)
#define UlongToHandle(ul)
virtual ULONG Compress(void *OutputBuffer, void *InputBuffer, ULONG InputLength, PULONG OutputLength)=0
virtual ULONG Uncompress(void *OutputBuffer, void *InputBuffer, ULONG InputLength, PULONG OutputLength)=0
ULONG ReadBlock(PCFDATA Data, void *Buffer, PULONG BytesRead)
ULONG Seek(LONG Position)
ULONG WriteBlock(PCFDATA Data, void *Buffer, PULONG BytesWritten)
void SetMaxDiskSize(ULONG Size)
ULONG GetAttributesOnFile(PCFFILE_NODE File)
ULONG AddFile(const std::string &FileName, const std::string &TargetFolder)
void NormalizePath(std::string &Path)
void DestroySearchCriteria()
void SetDestinationPath(const char *DestinationPath)
PCFFOLDER_NODE CurrentFolderNode
std::string GetFileName(const std::string &Path)
ULONG ComputeChecksum(void *Buffer, ULONG Size, ULONG Seed)
void DestroyDeletedFileNodes()
ULONG ExtractFile(const char *FileName)
bool SetCabinetReservedFile(const char *FileName)
void DestroyFolderNodes()
ULONG FindFirst(PCAB_SEARCH Search)
ULONG CommitDataBlocks(PCFFOLDER_NODE FolderNode)
virtual void OnDiskChange(const char *CabinetName, const char *DiskLabel)
void SetCabinetName(const char *FileName)
PCFFILE_NODE NewFileNode()
PCFFOLDER_NODE NewFolderNode()
class CCFDATAStorage * ScratchFile
ULONG InitCabinetHeader()
virtual void OnVerboseMessage(const char *Message)
void DestroyDeletedFolderNodes()
PCFDATA_NODE CurrentDataNode
bool SetCompressionCodec(const char *CodecName)
bool MatchFileNamePattern(const char *FileName, const char *Pattern)
ULONG GetFileTimes(FILE *FileHandle, PCFFILE_NODE File)
virtual bool OnOverwrite(PCFFILE Entry, const char *FileName)
virtual void OnExtract(PCFFILE Entry, const char *FileName)
void ConvertDateAndTime(time_t *Time, PUSHORT DosDate, PUSHORT DosTime)
ULONG GetAbsoluteOffset(PCFFILE_NODE File)
PCFFOLDER_NODE LocateFolderNode(ULONG Index)
void DestroyDataNodes(PCFFOLDER_NODE FolderNode)
void SelectCodec(LONG Id)
ULONG ReadBlock(void *Buffer, ULONG Size, PULONG BytesRead)
virtual void OnAdd(PCFFILE Entry, const char *FileName)
ULONG WriteCabinetHeader(bool MoreDisks)
void * CabinetReservedFileBuffer
const char * GetDestinationPath()
ULONG FindNext(PCAB_SEARCH Search)
std::string CreateCabFilename(PCFFILE_NODE Node)
ULONG CabinetReservedFileSize
void ConvertPath(std::string &Path)
std::list< PSEARCH_CRITERIA > CriteriaList
bool IsSeparator(char Char)
ULONG CommitDisk(ULONG MoreDisks)
ULONG GetCurrentDiskNumber()
std::string CabinetReservedFile
ULONG ReadDataBlocks(PCFFOLDER_NODE FolderNode)
ULONG WriteDisk(ULONG MoreDisks)
ULONG WriteFileToScratchStorage(PCFFILE_NODE FileNode)
ULONG ReadString(char *String, LONG MaxLength)
PCFDATA_NODE NewDataNode(PCFFOLDER_NODE FolderNode)
ULONG SetAttributesOnFile(char *FileName, USHORT FileAttributes)
ULONG AddSearchCriteria(const std::string &SearchCriteria, const std::string &TargetFolder)
virtual bool OnDiskLabel(ULONG Number, char *Label)
ULONG LocateFile(const char *FileName, PCFFILE_NODE *File)
bool CreateSimpleCabinet()
virtual bool OnCabinetName(ULONG Number, char *Name)
ULONG WriteFolderEntries()
_Check_return_ _Ret_opt_z_ _CRTIMP char *__cdecl getcwd(_Out_writes_opt_(_SizeInBytes) char *_DstBuf, _In_ int _SizeInBytes)
#define INVALID_HANDLE_VALUE
#define FILE_ATTRIBUTE_NORMAL
static void cleanup(void)
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
BOOL WINAPI FindClose(HANDLE hFindFile)
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
BOOL WINAPI DosDateTimeToFileTime(IN WORD wFatDate, IN WORD wFatTime, OUT LPFILETIME lpFileTime)
BOOL WINAPI FileTimeToDosDateTime(IN CONST FILETIME *lpFileTime, OUT LPWORD lpFatDate, OUT LPWORD lpFatTime)
static const WCHAR Message[]
struct _FileName FileName
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG FileAttributes
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
int __cdecl closedir(DIR *)
DIR *__cdecl opendir(const char *)
struct dirent *__cdecl readdir(DIR *)
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define ERROR_FILE_NOT_FOUND
static PLARGE_INTEGER Time
#define FILE_ATTRIBUTE_DIRECTORY
_In_ ULONG _In_ ULONG Offset
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
static WCHAR szFilePath[]
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
std::list< PCFFILE_NODE >::iterator Next
ULONG ScratchFilePosition
PCFFOLDER_NODE FolderNode
std::list< PCFDATA_NODE > DataList
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
DWORD WINAPI GetLastError(void)
#define GetFileAttributes
#define SetFileAttributes