Leaked source code of windows server 2003
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.

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