Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1251 lines
30 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. file.h
  5. Abstract:
  6. Declares interfaces for routines that simplify access to the
  7. file system. These include:
  8. - Dealing with short/long file names on both Win9x and NT in a
  9. single binary
  10. - Checking for file existance
  11. - Forcing creation of a path
  12. - Packing files on a floppy (for research and data gathering purposes)
  13. - WriteFileString wrapper to simplify WriteFile of a string
  14. Author:
  15. Jim Schmidt (jimschm) 13-Feb-1997
  16. Revision History:
  17. jimschm 21-Jan-1999 Centralized cmd line parser
  18. marcw 15-May-1998 Packed file enum
  19. --*/
  20. #pragma once
  21. #define INVALID_ATTRIBUTES 0xffffffff
  22. BOOL
  23. IsPathLengthOkA (
  24. IN PCSTR FileSpec
  25. );
  26. BOOL
  27. IsPathLengthOkW (
  28. IN PCWSTR FileSpec
  29. );
  30. BOOL
  31. OurGetLongPathNameA (
  32. IN PCSTR ShortPath,
  33. OUT PSTR Buffer,
  34. IN INT BufferSizeInBytes
  35. );
  36. BOOL
  37. OurGetLongPathNameW (
  38. IN PCWSTR ShortPath,
  39. OUT PWSTR Buffer,
  40. IN INT BufferSizeInChars
  41. );
  42. DWORD
  43. OurGetShortPathNameW (
  44. PCWSTR LongPath,
  45. PWSTR ShortPath,
  46. DWORD Size
  47. );
  48. #define OurGetShortPathNameA GetShortPathNameA
  49. DWORD
  50. OurGetFullPathNameW (
  51. PCWSTR FileName,
  52. DWORD Size,
  53. PWSTR FullPath,
  54. PWSTR *FilePtr
  55. );
  56. #define OurGetFullPathNameA GetFullPathNameA
  57. BOOL
  58. CopyFileSpecToLongA(
  59. IN PCSTR FullFileSpecIn,
  60. OUT PSTR OutPath
  61. );
  62. BOOL
  63. CopyFileSpecToLongW(
  64. IN PCWSTR FullFileSpecIn,
  65. OUT PWSTR OutPath
  66. );
  67. BOOL
  68. DoesFileExistExA(
  69. IN PCSTR Path,
  70. OUT PWIN32_FIND_DATAA FindData OPTIONAL
  71. );
  72. #define DoesFileExistA(x) DoesFileExistExA (x, NULL)
  73. BOOL
  74. DoesFileExistExW(
  75. IN PCWSTR Path,
  76. OUT PWIN32_FIND_DATAW FindData OPTIONAL
  77. );
  78. #define DoesFileExistW(x) DoesFileExistExW (x, NULL)
  79. DWORD
  80. MakeSurePathExistsA(
  81. IN LPCSTR szPath,
  82. IN BOOL PathOnly
  83. );
  84. DWORD
  85. MakeSurePathExistsW(
  86. IN LPCWSTR szPath,
  87. IN BOOL PathOnly
  88. );
  89. typedef struct tagPACKFILEENUMA {
  90. CHAR Identifier[MAX_MBCHAR_PATH];
  91. DWORD SizeLow;
  92. DWORD SizeHigh;
  93. HANDLE Handle;
  94. } PACKFILEENUMA, *PPACKFILEENUMA, PACKFILEENUMW, *PPACKFILEENUMW;
  95. BOOL
  96. PackedFile_AddFileA (
  97. IN PCSTR PackFile,
  98. IN PCSTR NewFile,
  99. IN PCSTR Identifier OPTIONAL
  100. );
  101. BOOL
  102. PackedFile_ExtractFileA (
  103. IN PCSTR PackFile,
  104. IN PCSTR FileIdentifier,
  105. IN PCSTR FileName OPTIONAL
  106. );
  107. BOOL
  108. PackedFile_EnumFirstA (
  109. IN PCSTR PackFile,
  110. OUT PPACKFILEENUMA Enum
  111. );
  112. BOOL
  113. PackedFile_EnumNextA (
  114. IN PPACKFILEENUMA Enum
  115. );
  116. VOID
  117. PackedFile_AbortEnum (
  118. IN OUT PPACKFILEENUMA Enum
  119. );
  120. BOOL
  121. PackedFile_ExtractFileUsingEnumA (
  122. IN PPACKFILEENUMA Enum,
  123. IN PCSTR FileName OPTIONAL
  124. );
  125. //
  126. // The W versions of these functions are not functional...unimplemented.
  127. //
  128. BOOL
  129. PackedFile_AddFileW (
  130. IN PCSTR PackFile,
  131. IN PCSTR NewFile,
  132. IN PCSTR Identifier OPTIONAL
  133. );
  134. BOOL
  135. PackedFile_ExtractFileW (
  136. IN PCSTR PackFile,
  137. IN PCSTR FileIdentifier,
  138. IN PCSTR FileName OPTIONAL
  139. );
  140. BOOL
  141. PackedFile_EnumFirstW (
  142. IN PCSTR PackFile,
  143. OUT PPACKFILEENUMA Enum
  144. );
  145. BOOL
  146. PackedFile_EnumNextW (
  147. IN PPACKFILEENUMA Enum
  148. );
  149. BOOL
  150. PackedFile_ExtractFileUsingEnumW (
  151. IN PPACKFILEENUMA Enum,
  152. IN PCSTR FileName OPTIONAL
  153. );
  154. BOOL
  155. WriteFileStringA (
  156. IN HANDLE File,
  157. IN PCSTR String
  158. );
  159. BOOL
  160. WriteFileStringW (
  161. IN HANDLE File,
  162. IN PCWSTR String
  163. );
  164. typedef struct {
  165. HANDLE FindHandle;
  166. WIN32_FIND_DATAA FindData;
  167. PSTR SavedEndOfFileBuffer;
  168. PSTR SavedEndOfPattern;
  169. } FIND_DATAA, *PFIND_DATAA;
  170. typedef struct {
  171. HANDLE FindHandle;
  172. WIN32_FIND_DATAW FindData;
  173. PWSTR SavedEndOfFileBuffer;
  174. PWSTR SavedEndOfPattern;
  175. } FIND_DATAW, *PFIND_DATAW;
  176. #define FILE_ENUM_ALL_LEVELS 0
  177. #define FILE_ENUM_THIS_LEVEL 1
  178. typedef enum {
  179. TREE_ENUM_INIT,
  180. TREE_ENUM_BEGIN,
  181. TREE_ENUM_FILES_BEGIN,
  182. TREE_ENUM_RETURN_ITEM,
  183. TREE_ENUM_FILES_NEXT,
  184. TREE_ENUM_DIRS_BEGIN,
  185. TREE_ENUM_DIRS_NEXT,
  186. TREE_ENUM_DIRS_FILTER,
  187. TREE_ENUM_PUSH,
  188. TREE_ENUM_POP,
  189. TREE_ENUM_DONE,
  190. TREE_ENUM_FAILED,
  191. TREE_ENUM_CLEANED_UP
  192. } TREE_ENUM_STATE;
  193. typedef struct {
  194. //
  195. // Enumerated items
  196. //
  197. PCSTR Name;
  198. PCSTR SubPath;
  199. PCSTR FullPath;
  200. PWIN32_FIND_DATAA FindData;
  201. BOOL Directory;
  202. UINT Level;
  203. UINT MaxLevel;
  204. //
  205. // Enumeration state -- private
  206. //
  207. BOOL EnumDirsFirst;
  208. BOOL EnumDepthFirst;
  209. CHAR RootPath[MAX_MBCHAR_PATH];
  210. UINT RootPathSize;
  211. CHAR Pattern[MAX_MBCHAR_PATH];
  212. PSTR EndOfPattern;
  213. CHAR FilePattern[MAX_MBCHAR_PATH];
  214. UINT FilePatternSize;
  215. CHAR FileBuffer[MAX_MBCHAR_PATH];
  216. PSTR EndOfFileBuffer;
  217. TREE_ENUM_STATE State;
  218. GROWBUFFER FindDataArray;
  219. PFIND_DATAA Current;
  220. } TREE_ENUMA, *PTREE_ENUMA;
  221. typedef struct {
  222. //
  223. // Enumerated items
  224. //
  225. PCWSTR Name;
  226. PCWSTR SubPath;
  227. PCWSTR FullPath;
  228. PWIN32_FIND_DATAW FindData;
  229. BOOL Directory;
  230. UINT Level;
  231. UINT MaxLevel;
  232. //
  233. // Enumeration state -- private
  234. //
  235. BOOL EnumDirsFirst;
  236. BOOL EnumDepthFirst;
  237. WCHAR RootPath[MAX_PATH * 2];
  238. UINT RootPathSize;
  239. WCHAR Pattern[MAX_PATH * 2];
  240. PWSTR EndOfPattern;
  241. WCHAR FilePattern[MAX_PATH * 2];
  242. UINT FilePatternSize;
  243. WCHAR FileBuffer[MAX_PATH * 2];
  244. PWSTR EndOfFileBuffer;
  245. TREE_ENUM_STATE State;
  246. GROWBUFFER FindDataArray;
  247. PFIND_DATAW Current;
  248. } TREE_ENUMW, *PTREE_ENUMW;
  249. BOOL
  250. EnumFirstFileInTreeExA (
  251. OUT PTREE_ENUMA EnumPtr,
  252. IN PCSTR RootPath,
  253. IN PCSTR FilePattern, OPTIONAL
  254. IN BOOL EnumDirsFirst,
  255. IN BOOL EnumDepthFirst,
  256. IN INT MaxLevel
  257. );
  258. BOOL
  259. EnumNextFileInTreeA (
  260. IN OUT PTREE_ENUMA EnumPtr
  261. );
  262. VOID
  263. AbortEnumFileInTreeA (
  264. IN OUT PTREE_ENUMA EnumPtr
  265. );
  266. #define EnumFirstFileInTreeA(ptr, path, pattern, dirfirst) EnumFirstFileInTreeExA((ptr), (path), (pattern), (dirfirst), FALSE, FILE_ENUM_ALL_LEVELS)
  267. BOOL
  268. EnumFirstFileInTreeExW (
  269. OUT PTREE_ENUMW EnumPtr,
  270. IN PCWSTR RootPath,
  271. IN PCWSTR FilePattern, OPTIONAL
  272. IN BOOL EnumDirsFirst,
  273. IN BOOL EnumDepthFirst,
  274. IN INT MaxLevel
  275. );
  276. BOOL
  277. EnumNextFileInTreeW (
  278. IN OUT PTREE_ENUMW EnumPtr
  279. );
  280. VOID
  281. AbortEnumFileInTreeW (
  282. IN OUT PTREE_ENUMW EnumPtr
  283. );
  284. #define EnumFirstFileInTreeW(ptr, path, pattern, dirfirst) EnumFirstFileInTreeExW((ptr), (path), (pattern), (dirfirst), FALSE, FILE_ENUM_ALL_LEVELS)
  285. VOID
  286. AbortEnumCurrentDirA (
  287. IN OUT PTREE_ENUMA EnumPtr
  288. );
  289. VOID
  290. AbortEnumCurrentDirW (
  291. IN OUT PTREE_ENUMW EnumPtr
  292. );
  293. typedef struct {
  294. PCSTR FileName;
  295. PCSTR FullPath;
  296. BOOL Directory;
  297. HANDLE Handle;
  298. CHAR RootPath[MAX_MBCHAR_PATH];
  299. PSTR EndOfRoot;
  300. HANDLE Enum;
  301. WIN32_FIND_DATAA fd;
  302. } FILE_ENUMA, *PFILE_ENUMA;
  303. typedef struct {
  304. PCWSTR FileName;
  305. PCWSTR FullPath;
  306. BOOL Directory;
  307. HANDLE Handle;
  308. WCHAR RootPath[MAX_WCHAR_PATH];
  309. PWSTR EndOfRoot;
  310. HANDLE Enum;
  311. WIN32_FIND_DATAW fd;
  312. } FILE_ENUMW, *PFILE_ENUMW;
  313. BOOL
  314. EnumFirstFileA (
  315. OUT PFILE_ENUMA EnumPtr,
  316. IN PCSTR RootPath,
  317. IN PCSTR FilePattern OPTIONAL
  318. );
  319. BOOL
  320. EnumFirstFileW (
  321. OUT PFILE_ENUMW EnumPtr,
  322. IN PCWSTR RootPath,
  323. IN PCWSTR FilePattern OPTIONAL
  324. );
  325. BOOL
  326. EnumNextFileA (
  327. IN OUT PFILE_ENUMA EnumPtr
  328. );
  329. BOOL
  330. EnumNextFileW (
  331. IN OUT PFILE_ENUMW EnumPtr
  332. );
  333. VOID
  334. AbortFileEnumA (
  335. IN OUT PFILE_ENUMA EnumPtr
  336. );
  337. VOID
  338. AbortFileEnumW (
  339. IN OUT PFILE_ENUMW EnumPtr
  340. );
  341. BOOL
  342. ExtractIconImageFromFileA (
  343. IN PCSTR ModuleContainingIcon,
  344. IN PCSTR GroupIconId, // OPTIONAL if file is an ICO file
  345. IN OUT PGROWBUFFER Buffer
  346. );
  347. BOOL
  348. ExtractIconImageFromFileW (
  349. IN PCWSTR ModuleContainingIcon,
  350. IN PCWSTR GroupIconId, // OPTIONAL if file is an ICO file
  351. IN OUT PGROWBUFFER Buffer
  352. );
  353. BOOL
  354. ExtractIconImageFromFileExA (
  355. IN PCSTR ModuleContainingIcon,
  356. IN PCSTR GroupIconId,
  357. IN OUT PGROWBUFFER Buffer,
  358. IN HANDLE IcoFileHandle, OPTIONAL
  359. IN HANDLE PeModuleHandle, OPTIONAL
  360. IN HANDLE NeModuleHandle OPTIONAL
  361. );
  362. BOOL
  363. ExtractIconImageFromFileExW (
  364. IN PCWSTR ModuleContainingIcon,
  365. IN PCWSTR GroupIconId,
  366. IN OUT PGROWBUFFER Buffer,
  367. IN HANDLE IcoFileHandle, OPTIONAL
  368. IN HANDLE PeModuleHandle, OPTIONAL
  369. IN HANDLE NeModuleHandle OPTIONAL
  370. );
  371. BOOL
  372. WriteIconImageArrayToIcoFileA (
  373. IN PCSTR DestinationFile,
  374. IN PGROWBUFFER Buffer
  375. );
  376. BOOL
  377. WriteIconImageArrayToIcoFileW (
  378. IN PCWSTR DestinationFile,
  379. IN PGROWBUFFER Buffer
  380. );
  381. BOOL
  382. WriteIconImageArrayToPeFileA (
  383. IN PCSTR DestinationFile,
  384. IN PGROWBUFFER Buffer,
  385. IN PCSTR GroupIconId
  386. );
  387. BOOL
  388. WriteIconImageArrayToPeFileW (
  389. IN PCWSTR DestinationFile,
  390. IN PGROWBUFFER Buffer,
  391. IN PCWSTR GroupIconId
  392. );
  393. BOOL
  394. WriteIconImageArrayToPeFileExA (
  395. IN PCSTR DestinationFile,
  396. IN PGROWBUFFER IconImageArray,
  397. IN PCSTR GroupIconId,
  398. IN PWORD NextIconId, OPTIONAL
  399. IN HANDLE UpdateHandle
  400. );
  401. BOOL
  402. WriteIconImageArrayToPeFileExW (
  403. IN PCWSTR DestinationFile,
  404. IN PGROWBUFFER IconImageArray,
  405. IN PCWSTR GroupIconId,
  406. IN PWORD NextIconId, OPTIONAL
  407. IN HANDLE UpdateHandle
  408. );
  409. BOOL
  410. WriteIconImageArrayToIcoFileEx (
  411. IN PGROWBUFFER Buffer,
  412. IN HANDLE File
  413. );
  414. PCSTR
  415. ExtractIconNamesFromFileA (
  416. IN PCSTR ModuleContainingIcons,
  417. IN OUT PGROWBUFFER NameBuf
  418. );
  419. PCWSTR
  420. ExtractIconNamesFromFileW (
  421. IN PCWSTR ModuleContainingIcons,
  422. IN OUT PGROWBUFFER NameBuf
  423. );
  424. PCSTR
  425. ExtractIconNamesFromFileExA (
  426. IN PCSTR ModuleContainingIcons,
  427. IN OUT PGROWBUFFER NameBuf,
  428. IN HANDLE Module,
  429. IN HANDLE Module16
  430. );
  431. PCWSTR
  432. ExtractIconNamesFromFileExW (
  433. IN PCWSTR ModuleContainingIcons,
  434. IN OUT PGROWBUFFER NameBuf,
  435. IN HANDLE Module,
  436. IN HANDLE Module16
  437. );
  438. BOOL
  439. IsFileAnIcoA (
  440. IN PCSTR FileInQuestion
  441. );
  442. BOOL
  443. IsFileAnIcoW (
  444. IN PCWSTR FileInQuestion
  445. );
  446. typedef struct {
  447. WORD GroupId;
  448. WORD IconId;
  449. GROWBUFFER IconImages;
  450. GROWBUFFER IconList;
  451. CHAR DestFile[MAX_MBCHAR_PATH];
  452. HANDLE Module;
  453. HANDLE Module16;
  454. CHAR ModuleName[MAX_MBCHAR_PATH];
  455. HANDLE IcoFile;
  456. CHAR IcoFileName[MAX_MBCHAR_PATH];
  457. HANDLE Update;
  458. CHAR IconImageFileName[MAX_MBCHAR_PATH];
  459. HANDLE IconImageFile;
  460. BOOL SaveMode;
  461. BOOL Error;
  462. } ICON_EXTRACT_CONTEXTA, *PICON_EXTRACT_CONTEXTA;
  463. typedef struct {
  464. WORD GroupId;
  465. WORD IconId;
  466. GROWBUFFER IconImages;
  467. GROWBUFFER IconList;
  468. WCHAR DestFile[MAX_WCHAR_PATH];
  469. HANDLE Module;
  470. HANDLE Module16;
  471. WCHAR ModuleName[MAX_WCHAR_PATH];
  472. HANDLE IcoFile;
  473. WCHAR IcoFileName[MAX_WCHAR_PATH];
  474. HANDLE Update;
  475. WCHAR IconImageFileName[MAX_WCHAR_PATH];
  476. HANDLE IconImageFile;
  477. BOOL SaveMode;
  478. BOOL Error;
  479. } ICON_EXTRACT_CONTEXTW, *PICON_EXTRACT_CONTEXTW;
  480. BOOL
  481. BeginIconExtractionA (
  482. OUT PICON_EXTRACT_CONTEXTA Context,
  483. IN PCSTR DestFile OPTIONAL
  484. );
  485. BOOL
  486. BeginIconExtractionW (
  487. OUT PICON_EXTRACT_CONTEXTW Context,
  488. IN PCWSTR DestFile OPTIONAL
  489. );
  490. BOOL
  491. OpenIconImageFileA (
  492. IN OUT PICON_EXTRACT_CONTEXTA Context,
  493. IN PCSTR FileName,
  494. IN BOOL SaveMode
  495. );
  496. BOOL
  497. OpenIconImageFileW (
  498. IN OUT PICON_EXTRACT_CONTEXTW Context,
  499. IN PCWSTR FileName,
  500. IN BOOL SaveMode
  501. );
  502. BOOL
  503. CopyIconA (
  504. IN OUT PICON_EXTRACT_CONTEXTA Context,
  505. IN PCSTR FileContainingIcon, OPTIONAL
  506. IN PCSTR IconId, OPTIONAL
  507. IN INT IconIndex OPTIONAL
  508. );
  509. BOOL
  510. CopyIconW (
  511. IN OUT PICON_EXTRACT_CONTEXTW Context,
  512. IN PCWSTR FileContainingIcon, OPTIONAL
  513. IN PCWSTR IconId, OPTIONAL
  514. IN INT IconIndex OPTIONAL
  515. );
  516. BOOL
  517. CopyAllIconsA (
  518. IN OUT PICON_EXTRACT_CONTEXTA Context,
  519. IN PCSTR FileContainingIcons
  520. );
  521. BOOL
  522. CopyAllIconsW (
  523. IN OUT PICON_EXTRACT_CONTEXTW Context,
  524. IN PCWSTR FileContainingIcons
  525. );
  526. BOOL
  527. EndIconExtractionA (
  528. IN OUT PICON_EXTRACT_CONTEXTA Context
  529. );
  530. BOOL
  531. EndIconExtractionW (
  532. IN OUT PICON_EXTRACT_CONTEXTW Context
  533. );
  534. //
  535. // New Executable resource access
  536. //
  537. HANDLE
  538. OpenNeFileA (
  539. PCSTR FileName
  540. );
  541. HANDLE
  542. OpenNeFileW (
  543. PCWSTR FileName
  544. );
  545. VOID
  546. CloseNeFile (
  547. HANDLE Handle
  548. );
  549. //
  550. // Once upon a time ENUMRESTYPEPROC was defined as a TCHAR prototype,
  551. // which was broken. If ENUMRESTYPEPROCA isn't defined, we'll define
  552. // it. (NOTE: The current winbase.h has these typedefs.)
  553. //
  554. #ifndef ENUMRESTYPEPROCA
  555. #if 0
  556. typedef BOOL (CALLBACK* ENUMRESTYPEPROCA)(HMODULE hModule, PCSTR lpType, LONG_PTR lParam);
  557. typedef BOOL (CALLBACK* ENUMRESTYPEPROCW)(HMODULE hModule, PCWSTR lpType, LONG_PTR lParam);
  558. #endif
  559. //
  560. // to be consistent with winbase.h, the second arg is non-const. But that's
  561. // actually a bug in winbase.h.
  562. //
  563. typedef BOOL (CALLBACK* ENUMRESTYPEPROCA)(HMODULE hModule, PSTR lpType, LONG_PTR lParam);
  564. typedef BOOL (CALLBACK* ENUMRESTYPEPROCW)(HMODULE hModule, PWSTR lpType, LONG_PTR lParam);
  565. //
  566. // These two prototypes are OK
  567. //
  568. typedef BOOL (CALLBACK* ENUMRESNAMEPROCA)(HMODULE hModule, PCSTR lpType,
  569. PSTR lpName, LONG_PTR lParam);
  570. typedef BOOL (CALLBACK* ENUMRESNAMEPROCW)(HMODULE hModule, PCWSTR lpType,
  571. PWSTR lpName, LONG_PTR lParam);
  572. #endif
  573. BOOL
  574. EnumNeResourceTypesA (
  575. IN HANDLE Handle,
  576. IN ENUMRESTYPEPROCA EnumFunc,
  577. IN LONG lParam
  578. );
  579. BOOL
  580. EnumNeResourceTypesW (
  581. IN HANDLE Handle,
  582. IN ENUMRESTYPEPROCW EnumFunc,
  583. IN LONG lParam
  584. );
  585. BOOL
  586. EnumNeResourceNamesA (
  587. IN HANDLE Handle,
  588. IN PCSTR Type,
  589. IN ENUMRESNAMEPROCA EnumFunc,
  590. IN LONG lParam
  591. );
  592. BOOL
  593. EnumNeResourceNamesW (
  594. IN HANDLE Handle,
  595. IN PCWSTR Type,
  596. IN ENUMRESNAMEPROCW EnumFunc,
  597. IN LONG lParam
  598. );
  599. DWORD
  600. SizeofNeResourceA (
  601. IN HANDLE Handle,
  602. IN PCSTR Type,
  603. IN PCSTR Name
  604. );
  605. DWORD
  606. SizeofNeResourceW (
  607. IN HANDLE Handle,
  608. IN PCWSTR Type,
  609. IN PCWSTR Name
  610. );
  611. PBYTE
  612. FindNeResourceExA (
  613. IN HANDLE Handle,
  614. IN PCSTR Type,
  615. IN PCSTR Name
  616. );
  617. PBYTE
  618. FindNeResourceExW (
  619. IN HANDLE Handle,
  620. IN PCWSTR Type,
  621. IN PCWSTR Name
  622. );
  623. #define FindNeResourceA(h,n,t) FindNeResourceExA(h,t,n)
  624. #define FindNeResourceW(h,n,t) FindNeResourceExW(h,t,n)
  625. #pragma pack(push, 1)
  626. #define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
  627. #define IMAGE_NE_SIGNATURE 0x454E // NE
  628. #define IMAGE_PE_SIGNATURE 0x00004550l // PE00
  629. typedef struct _DOS_HEADER { // DOS .EXE header
  630. WORD e_magic; // Magic number
  631. WORD e_cblp; // Bytes on last page of file
  632. WORD e_cp; // Pages in file
  633. WORD e_crlc; // Relocations
  634. WORD e_cparhdr; // Size of header in paragraphs
  635. WORD e_minalloc; // Minimum extra paragraphs needed
  636. WORD e_maxalloc; // Maximum extra paragraphs needed
  637. WORD e_ss; // Initial (relative) SS value
  638. WORD e_sp; // Initial SP value
  639. WORD e_csum; // Checksum
  640. WORD e_ip; // Initial IP value
  641. WORD e_cs; // Initial (relative) CS value
  642. WORD e_lfarlc; // File address of relocation table
  643. WORD e_ovno; // Overlay number
  644. WORD e_res[4]; // Reserved words
  645. WORD e_oemid; // OEM identifier (for e_oeminfo)
  646. WORD e_oeminfo; // OEM information; e_oemid specific
  647. WORD e_res2[10]; // Reserved words
  648. LONG e_lfanew; // File address of new exe header
  649. } DOS_HEADER, *PDOS_HEADER;
  650. typedef struct {
  651. WORD Signature; // 00h
  652. BYTE LinkerVersion; // 02h
  653. BYTE LinkerRevision; // 03h
  654. WORD OffsetToEntryTable; // 04h
  655. WORD LengthOfEntryTable; // 06h
  656. DWORD Reserved; // 08h
  657. WORD Flags; // 0ch
  658. WORD AutoDataSegment; // 0eh
  659. WORD LocalHeapSize; // 10h
  660. WORD StackSize; // 12h
  661. DWORD EntryAddress; // 14h
  662. DWORD StackAddress; // 18h
  663. WORD SegmentTableEntries; // 1ch
  664. WORD ModuleReferenceTableEntries; // 1eh
  665. WORD NonResidentTableSize; // 20h
  666. WORD OffsetToSegmentTable; // 22h
  667. WORD OffsetToResourceTable; // 24h
  668. WORD OffsetToResidentNameTable; // 26h
  669. WORD OffsetToModuleReferenceTable; // 28h
  670. WORD OffsetToImportedNameTable; // 2ah
  671. WORD OffsetToNonResidentNameTable; // 2ch
  672. WORD Unused; // 2eh
  673. WORD MovableEntryPoints; // 30h
  674. WORD LogicalSectorShiftCount; // 32h
  675. WORD ResourceSegments; // 34h
  676. BYTE TargetOS; // 36h
  677. BYTE AdditionalFlags; // 37h
  678. WORD FastLoadOffset; // 38h
  679. WORD SectorsInFastLoad; // 3ah
  680. WORD Reserved2; // 3ch
  681. WORD WindowsVersion; // 3eh
  682. } NE_INFO_BLOCK, *PNE_INFO_BLOCK;
  683. typedef struct {
  684. WORD Offset;
  685. WORD Length;
  686. WORD Flags;
  687. WORD Id;
  688. WORD Handle;
  689. WORD Usage;
  690. } NE_RES_NAMEINFO, *PNE_RES_NAMEINFO;
  691. typedef struct {
  692. WORD TypeId;
  693. WORD ResourceCount;
  694. DWORD Reserved;
  695. NE_RES_NAMEINFO NameInfo[];
  696. } NE_RES_TYPEINFO, *PNE_RES_TYPEINFO;
  697. #pragma pack(pop)
  698. typedef struct {
  699. WORD AlignShift;
  700. GROWLIST TypeInfoArray;
  701. GROWLIST ResourceNames;
  702. } NE_RESOURCES, *PNE_RESOURCES;
  703. BOOL
  704. LoadNeHeader (
  705. IN HANDLE File,
  706. OUT PNE_INFO_BLOCK Header
  707. );
  708. BOOL
  709. LoadNeResources (
  710. IN HANDLE File,
  711. OUT PNE_RESOURCES Resources
  712. );
  713. VOID
  714. FreeNeResources (
  715. PNE_RESOURCES Resources
  716. );
  717. BOOL
  718. LoadNeIconFromFileA (
  719. PCSTR FileName,
  720. INT IconIndex
  721. );
  722. PVOID
  723. MapFileIntoMemoryExA (
  724. IN PCSTR FileName,
  725. OUT PHANDLE FileHandle,
  726. OUT PHANDLE MapHandle,
  727. IN BOOL WriteAccess
  728. );
  729. PVOID
  730. MapFileIntoMemoryExW (
  731. IN PCWSTR FileName,
  732. OUT PHANDLE FileHandle,
  733. OUT PHANDLE MapHandle,
  734. IN BOOL WriteAccess
  735. );
  736. #define MapFileIntoMemoryA(FileName,FileHandle,MapHandle) MapFileIntoMemoryExA(FileName,FileHandle,MapHandle,FALSE)
  737. #define MapFileIntoMemoryW(FileName,FileHandle,MapHandle) MapFileIntoMemoryExW(FileName,FileHandle,MapHandle,FALSE)
  738. BOOL
  739. UnmapFile (
  740. IN PVOID FileImage,
  741. IN HANDLE MapHandle,
  742. IN HANDLE FileHandle
  743. );
  744. BOOL
  745. RemoveCompleteDirectoryA (
  746. IN PCSTR Dir
  747. );
  748. BOOL
  749. RemoveCompleteDirectoryW (
  750. IN PCWSTR Dir
  751. );
  752. typedef struct {
  753. PCSTR OriginalArg;
  754. PCSTR CleanedUpArg;
  755. DWORD Attributes;
  756. BOOL Quoted;
  757. } CMDLINEARGA, *PCMDLINEARGA;
  758. typedef struct {
  759. PCSTR CmdLine;
  760. UINT ArgCount;
  761. CMDLINEARGA Args[];
  762. } CMDLINEA, *PCMDLINEA;
  763. typedef struct {
  764. PCWSTR OriginalArg;
  765. PCWSTR CleanedUpArg;
  766. DWORD Attributes;
  767. BOOL Quoted;
  768. } CMDLINEARGW, *PCMDLINEARGW;
  769. typedef struct {
  770. PCWSTR CmdLine;
  771. UINT ArgCount;
  772. CMDLINEARGW Args[];
  773. } CMDLINEW, *PCMDLINEW;
  774. PCMDLINEA
  775. ParseCmdLineA (
  776. IN PCSTR CmdLine,
  777. IN OUT PGROWBUFFER Buffer
  778. );
  779. PCMDLINEW
  780. ParseCmdLineW (
  781. IN PCWSTR CmdLine,
  782. IN OUT PGROWBUFFER Buffer
  783. );
  784. BOOL GetFileSizeFromFilePathA(
  785. IN PCSTR FilePath,
  786. OUT ULARGE_INTEGER * FileSize
  787. );
  788. BOOL GetFileSizeFromFilePathW(
  789. IN PCWSTR FilePath,
  790. OUT ULARGE_INTEGER * FileSize
  791. );
  792. #define NUMDRIVELETTERS 26
  793. #define UNKNOWN_DRIVE '?'
  794. typedef struct {
  795. CHAR Letter[NUMDRIVELETTERS];
  796. BOOL ExistsOnSystem[NUMDRIVELETTERS];
  797. DWORD Type[NUMDRIVELETTERS]; // Returned from GetDriveType:
  798. // DRIVE_FIXED, DRIVE_CDROM or DRIVE_REMOVABLE
  799. CHAR IdentifierString[NUMDRIVELETTERS][MAX_PATH]; // For caller use
  800. } DRIVELETTERSA, *PDRIVELETTERSA;
  801. typedef struct {
  802. WCHAR Letter[NUMDRIVELETTERS];
  803. BOOL ExistsOnSystem[NUMDRIVELETTERS];
  804. DWORD Type[NUMDRIVELETTERS]; // Returned from GetDriveType:
  805. // DRIVE_FIXED, DRIVE_CDROM or DRIVE_REMOVABLE
  806. WCHAR IdentifierString[NUMDRIVELETTERS][MAX_PATH]; // For caller use
  807. } DRIVELETTERSW, *PDRIVELETTERSW;
  808. VOID
  809. InitializeDriveLetterStructureA (
  810. OUT PDRIVELETTERSA DriveLetters
  811. );
  812. VOID
  813. InitializeDriveLetterStructureW (
  814. OUT PDRIVELETTERSW DriveLetters
  815. );
  816. BOOL
  817. GetDiskFreeSpaceNewA(
  818. IN PCSTR DriveName,
  819. OUT DWORD * OutSectorsPerCluster,
  820. OUT DWORD * OutBytesPerSector,
  821. OUT ULARGE_INTEGER * OutNumberOfFreeClusters,
  822. OUT ULARGE_INTEGER * OutTotalNumberOfClusters
  823. );
  824. BOOL
  825. GetDiskFreeSpaceNewW(
  826. IN PCWSTR DriveName,
  827. OUT DWORD * OutSectorsPerCluster,
  828. OUT DWORD * OutBytesPerSector,
  829. OUT ULARGE_INTEGER * OutNumberOfFreeClusters,
  830. OUT ULARGE_INTEGER * OutTotalNumberOfClusters
  831. );
  832. DWORD
  833. QuietGetFileAttributesA (
  834. IN PCSTR FilePath
  835. );
  836. DWORD
  837. QuietGetFileAttributesW (
  838. IN PCWSTR FilePath
  839. );
  840. BOOL
  841. IsPathOnFixedDriveA (
  842. IN PCSTR FileSpec OPTIONAL
  843. );
  844. BOOL
  845. IsPathOnFixedDriveW (
  846. IN PCWSTR FileSpec OPTIONAL
  847. );
  848. DWORD
  849. MakeSureLongPathExistsW (
  850. IN PCWSTR Path,
  851. IN BOOL PathOnly
  852. );
  853. DWORD
  854. SetLongPathAttributesW (
  855. IN PCWSTR Path,
  856. IN DWORD Attributes
  857. );
  858. DWORD
  859. GetLongPathAttributesW (
  860. IN PCWSTR Path
  861. );
  862. BOOL
  863. DeleteLongPathW (
  864. IN PCWSTR Path
  865. );
  866. BOOL
  867. RemoveLongDirectoryPathW (
  868. IN PCWSTR Path
  869. );
  870. #ifdef UNICODE
  871. #define MakeSureLongPathExists MakeSureLongPathExistsW
  872. #define SetLongPathAttributes SetLongPathAttributesW
  873. #define GetLongPathAttributes GetLongPathAttributesW
  874. #define DeleteLongPath DeleteLongPathW
  875. #define RemoveLongDirectoryPath RemoveLongDirectoryPathW
  876. #define IsPathLengthOk IsPathLengthOkW
  877. #define IsPathLengthOkT IsPathLengthOkW
  878. #define OurGetLongPathName OurGetLongPathNameW
  879. #define OurGetShortPathName OurGetShortPathNameW
  880. #define OurGetFullPathName OurGetFullPathNameW
  881. #define CopyFileSpecToLong CopyFileSpecToLongW
  882. #define DoesFileExist DoesFileExistW
  883. #define DoesFileExistEx DoesFileExistExW
  884. #define MakeSurePathExists MakeSurePathExistsW
  885. #define PACKFILEENUM PACKFILEENUMW
  886. #define PackedFile_ExtractFileUsingEnum PackedFile_ExtractFileUsingEnumW
  887. #define PackedFile_AddFile PackedFile_AddFileW
  888. #define PackedFile_ExtractFile PackedFile_ExtractFileW
  889. #define PackedFile_EnumFirst PackedFile_EnumFirstW
  890. #define PackedFile_EnumNext PackedFile_EnumNextW
  891. #define WriteFileString WriteFileStringW
  892. #define TREE_ENUM TREE_ENUMW
  893. #define PTREE_ENUM PTREE_ENUMW
  894. #define FILE_ENUM FILE_ENUMW
  895. #define PFILE_ENUM PFILE_ENUMW
  896. #define EnumFirstFileInTreeEx EnumFirstFileInTreeExW
  897. #define EnumFirstFileInTree EnumFirstFileInTreeW
  898. #define EnumNextFileInTree EnumNextFileInTreeW
  899. #define AbortEnumFileInTree AbortEnumFileInTreeW
  900. #define AbortEnumCurrentDir AbortEnumCurrentDirW
  901. #define EnumFirstFile EnumFirstFileW
  902. #define EnumNextFile EnumNextFileW
  903. #define AbortFileEnum AbortFileEnumW
  904. #define ExtractIconImageFromFile ExtractIconImageFromFileW
  905. #define ExtractIconImageFromFileEx ExtractIconImageFromFileExW
  906. #define WriteIconImageArrayToIcoFile WriteIconImageArrayToIcoFileW
  907. #define WriteIconImageArrayToIcoFileEx WriteIconImageArrayToIcoFileExW
  908. #define WriteIconImageArrayToPeFile WriteIconImageArrayToPeFileW
  909. #define WriteIconImageArrayToPeFileEx WriteIconImageArrayToPeFileExW
  910. #define ExtractIconNamesFromFile ExtractIconNamesFromFileW
  911. #define ExtractIconNamesFromFileEx ExtractIconNamesFromFileExW
  912. #define IsFileAnIco IsFileAnIcoW
  913. #define ICON_EXTRACT_CONTEXT ICON_EXTRACT_CONTEXTW
  914. #define PICON_EXTRACT_CONTEXT PICON_EXTRACT_CONTEXTW
  915. #define BeginIconExtraction BeginIconExtractionW
  916. #define OpenIconImageFile OpenIconImageFileW
  917. #define CopyIcon CopyIconW
  918. #define CopyAllIcons CopyAllIconsW
  919. #define EndIconExtraction EndIconExtractionW
  920. #define OpenNeFile OpenNeFileW
  921. #define EnumNeResourceTypes EnumNeResourceTypesW
  922. #define EnumNeResourceNames EnumNeResourceNamesW
  923. #define SizeofNeResource SizeofNeResourceW
  924. #define FindNeResource FindNeResourceW
  925. #define FindNeResourceEx FindNeResourceExW
  926. #define MapFileIntoMemory MapFileIntoMemoryW
  927. #define MapFileIntoMemoryEx MapFileIntoMemoryExW
  928. #define RemoveCompleteDirectory RemoveCompleteDirectoryW
  929. #define CMDLINE CMDLINEW
  930. #define CMDLINEARG CMDLINEARGW
  931. #define PCMDLINE PCMDLINEW
  932. #define PCMDLINEARG PCMDLINEARGW
  933. #define ParseCmdLine ParseCmdLineW
  934. #define GetFileSizeFromFilePath GetFileSizeFromFilePathW
  935. #define GetDiskInfo GetDiskInfoW
  936. #define GetIntegrityInfo GetIntegrityInfoW
  937. #define DRIVELETTERS DRIVELETTERSW
  938. #define PDRIVELETTERS PDRIVELETTERSW
  939. #define InitializeDriveLetterStructure InitializeDriveLetterStructureW
  940. #define GetDiskFreeSpaceNew GetDiskFreeSpaceNewW
  941. #define QuietGetFileAttributes QuietGetFileAttributesW
  942. #define IsPathOnFixedDrive IsPathOnFixedDriveW
  943. #else
  944. #define IsPathLengthOk IsPathLengthOkA
  945. #define IsPathLengthOkT IsPathLengthOkA
  946. #define OurGetLongPathName OurGetLongPathNameA
  947. #define OurGetShortPathName OurGetShortPathNameA
  948. #define OurGetFullPathName OurGetFullPathNameA
  949. #define MakeSurePathExists MakeSurePathExistsA
  950. #define DoesFileExist DoesFileExistA
  951. #define DoesFileExistEx DoesFileExistExA
  952. #define CopyFileSpecToLong CopyFileSpecToLongA
  953. #define PACKFILEENUM PACKFILEENUMA
  954. #define PackedFile_ExtractFileUsingEnum PackedFile_ExtractFileUsingEnumA
  955. #define PackedFile_AddFile PackedFile_AddFileA
  956. #define PackedFile_ExtractFile PackedFile_ExtractFileA
  957. #define PackedFile_EnumFirst PackedFile_EnumFirstA
  958. #define PackedFile_EnumNext PackedFile_EnumNextA
  959. #define WriteFileString WriteFileStringA
  960. #define TREE_ENUM TREE_ENUMA
  961. #define PTREE_ENUM PTREE_ENUMA
  962. #define FILE_ENUM FILE_ENUMA
  963. #define PFILE_ENUM PFILE_ENUMA
  964. #define EnumFirstFileInTreeEx EnumFirstFileInTreeExA
  965. #define EnumFirstFileInTree EnumFirstFileInTreeA
  966. #define EnumNextFileInTree EnumNextFileInTreeA
  967. #define AbortEnumFileInTree AbortEnumFileInTreeA
  968. #define AbortEnumCurrentDir AbortEnumCurrentDirA
  969. #define EnumFirstFile EnumFirstFileA
  970. #define EnumNextFile EnumNextFileA
  971. #define AbortFileEnum AbortFileEnumA
  972. #define ExtractIconImageFromFile ExtractIconImageFromFileA
  973. #define ExtractIconImageFromFileEx ExtractIconImageFromFileExA
  974. #define WriteIconImageArrayToIcoFile WriteIconImageArrayToIcoFileA
  975. #define WriteIconImageArrayToIcoFileEx WriteIconImageArrayToIcoFileExA
  976. #define WriteIconImageArrayToPeFile WriteIconImageArrayToPeFileA
  977. #define WriteIconImageArrayToPeFileEx WriteIconImageArrayToPeFileExA
  978. #define ExtractIconNamesFromFile ExtractIconNamesFromFileA
  979. #define ExtractIconNamesFromFileEx ExtractIconNamesFromFileExA
  980. #define IsFileAnIco IsFileAnIcoA
  981. #define ICON_EXTRACT_CONTEXT ICON_EXTRACT_CONTEXTA
  982. #define PICON_EXTRACT_CONTEXT PICON_EXTRACT_CONTEXTA
  983. #define BeginIconExtraction BeginIconExtractionA
  984. #define OpenIconImageFile OpenIconImageFileA
  985. #define CopyIcon CopyIconA
  986. #define CopyAllIcons CopyAllIconsA
  987. #define EndIconExtraction EndIconExtractionA
  988. #define OpenNeFile OpenNeFileA
  989. #define EnumNeResourceTypes EnumNeResourceTypesA
  990. #define EnumNeResourceNames EnumNeResourceNamesA
  991. #define SizeofNeResource SizeofNeResourceA
  992. #define FindNeResource FindNeResourceA
  993. #define FindNeResourceEx FindNeResourceExA
  994. #define MapFileIntoMemory MapFileIntoMemoryA
  995. #define MapFileIntoMemoryEx MapFileIntoMemoryExA
  996. #define RemoveCompleteDirectory RemoveCompleteDirectoryA
  997. #define CMDLINE CMDLINEA
  998. #define CMDLINEARG CMDLINEARGA
  999. #define PCMDLINE PCMDLINEA
  1000. #define PCMDLINEARG PCMDLINEARGA
  1001. #define ParseCmdLine ParseCmdLineA
  1002. #define GetFileSizeFromFilePath GetFileSizeFromFilePathA
  1003. #define DRIVELETTERS DRIVELETTERSA
  1004. #define PDRIVELETTERS PDRIVELETTERSA
  1005. #define InitializeDriveLetterStructure InitializeDriveLetterStructureA
  1006. #define GetDiskFreeSpaceNew GetDiskFreeSpaceNewA
  1007. #define QuietGetFileAttributes QuietGetFileAttributesA
  1008. #define IsPathOnFixedDrive IsPathOnFixedDriveA
  1009. #endif