分享
 
 
 

Microsoft公司 .CAB文件格式

王朝other·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

Microsoft公司 .CAB文件格式

_Inside Windows Cabinet Files_

Listing One

// =================================================================

// CAB FILE LAYOUT

// =================================================================

/*

(1) CAB_HEADER structure

(2) Reserved area, if CAB_HEADER.flags & CAB_FLAG_RESERVE

(3) Previous cabinet name, if CAB_HEADER.flags & CAB_FLAG_HASPREV

(4) Previous disk name, if CAB_HEADER.flags & CAB_FLAG_HASPREV

(5) Next cabinet name, if CAB_HEADER.flags & CAB_FLAG_HASNEXT

(6) Next disk name, if CAB_HEADER.flags & CAB_FLAG_HASNEXT

(7) CAB_FOLDER structures (n = CAB_HEADER.cFolders)

(8) CAB_ENTRY structures / file names (n = CAB_HEADER.cFiles)

(9) File data (offset = CAB_FOLDER.coffCabStart)

*/

// =================================================================

// MACROS

// =================================================================

#define SWAPWORD(x) ((WORD) (((x) << 8) | ((x) >> 8)))

#define SWAPDWORD(x) ((SWAPWORD ((WORD) (x)) << 16) | (SWAPWORD ((WORD) ((x) >> 16))))

// =================================================================

// CONSTANTS

// =================================================================

#define CAB_SIGNATURE SWAPDWORD ('MSCF')

#define CAB_VERSION 0x0103

#define CAB_FLAG_HASPREV 0x0001

#define CAB_FLAG_HASNEXT 0x0002

#define CAB_FLAG_RESERVE 0x0004

#define CAB_ATTRIB_READONLY 0x0001

#define CAB_ATTRIB_HIDDEN 0x0002

#define CAB_ATTRIB_SYSTEM 0x0004

#define CAB_ATTRIB_VOLUME 0x0008

#define CAB_ATTRIB_DIRECTORY 0x0010

#define CAB_ATTRIB_ARCHIVE 0x0020

#define CAB_FILE_FIRST 0x0000

#define CAB_FILE_NEXT 0x0001

#define CAB_FILE_SPLIT 0xFFFE

#define CAB_FILE_CONTINUED 0xFFFD

#define CAB_NOTIFY_OK 1

#define CAB_NOTIFY_ERROR 0

#define CAB_NOTIFY_SKIP 0

#define CAB_NOTIFY_ABORT (-1)

// =================================================================

// CABINET STRUCTURES

// =================================================================

typedef struct _CAB_HEADER

{

DWORD sig; // file signature 'MSCF' (CAB_SIGNATURE)

DWORD csumHeader; // header checksum (0 if not used)

DWORD cbCabinet; // cabinet file size

DWORD csumFolders; // folders checksum (0 if not used)

DWORD coffFiles; // offset of first CAB_ENTRY

DWORD csumFiles; // files checksum (0 if not used)

WORD version; // cabinet version (CAB_VERSION)

WORD cFolders; // number of folders

WORD cFiles; // number of files

WORD flags; // cabinet flags (CAB_FLAG_*)

WORD setID; // cabinet set id

WORD iCabinet; // zero-based cabinet number

}

CAB_HEADER, *PCAB_HEADER;

#define CAB_HEADER_ sizeof (CAB_HEADER)

// -----------------------------------------------------------------

typedef struct _CAB_FOLDER

{

DWORD coffCabStart; // offset of folder data

WORD cCFData; // ???

WORD typeCompress; // compression type (tcomp* in FDI.h)

}

CAB_FOLDER, *PCAB_FOLDER;

#define CAB_FOLDER_ sizeof (CAB_FOLDER)

// -----------------------------------------------------------------

typedef struct _CAB_ENTRY

{

DWORD cbFile; // uncompressed file size

DWORD uoffFolderStart; // file offset after decompression

WORD iFolder; // file control id (CAB_FILE_*)

WORD date; // file date stamp, as used by DOS

WORD time; // file time stamp, as used by DOS

WORD attribs; // file attributes (CAB_ATTRIB_*)

}

CAB_ENTRY, *PCAB_ENTRY;

#define CAB_ENTRY_ sizeof (CAB_ENTRY)

Listing Two

// =================================================================

// FILE EXTRACTION CALLBACK

// =================================================================

int DIAMONDAPI FDIExtract (FDINOTIFICATIONTYPE fdint,

PFDINOTIFICATION pfdin)

{

FILETIME ft, lft;

BYTE abFile [MAX_PATH];

int hf, iResult;

switch (fdint)

{

case fdintCOPY_FILE:

if (lstrcmpi (pfdin->psz1,

((PEXTRACT_FILE) pfdin->pv)->pbEntry))

{

iResult = CAB_NOTIFY_SKIP;

}

else

{

hf = FDIOpen (((PEXTRACT_FILE) pfdin->pv)->pbFile,

_O_RDWR | _O_CREAT | _O_TRUNC,

_S_IREAD | _S_IWRITE);

if (hf != -1)

{

iResult = hf;

}

else

{

printfMessage

(((PEXTRACT_FILE) pfdin->pv)->hWnd,

MB_ICONERROR | MB_OK,

"CabLib Error",

"Unable to create file \"%s\"",

((PEXTRACT_FILE) pfdin->pv)->pbFile);

iResult = CAB_NOTIFY_ABORT;

}

}

break;

case fdintNEXT_CABINET:

if (lstrlen (pfdin->psz3) + lstrlen (pfdin->psz1)

< MAX_PATH)

{

lstrcpy (abFile, pfdin->psz3);

lstrcat (abFile, pfdin->psz1);

hf = FDIOpen (abFile, _O_RDONLY, 0);

}

else

{

hf = -1;

}

if (hf != -1)

{

FDIClose (hf);

iResult = CAB_NOTIFY_OK;

}

else

{

printfMessage (((PEXTRACT_FILE) pfdin->pv)->hWnd,

MB_ICONERROR | MB_OK,

"CabLib Error",

"Unable to open file \"%s%s\"",

pfdin->psz3,

pfdin->psz1);

iResult = CAB_NOTIFY_ABORT;

}

break;

case fdintCLOSE_FILE_INFO:

DosDateTimeToFileTime (pfdin->date, pfdin->time, &lft);

LocalFileTimeToFileTime (&lft, &ft);

SetFileTime ((HANDLE) pfdin->hf, &ft, &ft, &ft);

if (FDIClose (pfdin->hf) == -1)

{

printfMessage (((PEXTRACT_FILE) pfdin->pv)->hWnd,

MB_ICONERROR | MB_OK,

"CabLib Error",

"Unable to close file \"%s\"",

((PEXTRACT_FILE) pfdin->pv)->pbFile);

}

iResult = CAB_NOTIFY_OK;

break;

default:

iResult = CAB_NOTIFY_OK;

break;

}

return iResult;

}

Example 1:

HFDI FAR DIAMONDAPI FDICreate (PFNALLOC pfnalloc,

PFNFREE pfnfree,

PFNOPEN pfnopen,

PFNREAD pfnread,

PFNWRITE pfnwrite,

PFNCLOSE pfnclose,

PFNSEEK pfnseek,

int cpuType,

PERF perf);

Example 2:

BOOL FAR DIAMONDAPI FDICopy (HFDI hfdi,

char FAR *pszCabinet,

char FAR *pszCabPath,

int flags,

PFNFDINOTIFY pfnfdin,

PFNFDIDECRYPT pfnfdid,

void FAR *pvUser);

4

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有