jwawinsafer.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. {******************************************************************************}
  2. { }
  3. { Windows Safer API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: winsafer.h, released Nov 2001. The original Pascal }
  9. { code is: WinSafer.pas, released Februari 2002. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  16. { }
  17. { You may retrieve the latest version of this file at the Project JEDI }
  18. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  19. { }
  20. { The contents of this file are used with permission, subject to the Mozilla }
  21. { Public License Version 1.1 (the "License"); you may not use this file except }
  22. { in compliance with the License. You may obtain a copy of the License at }
  23. { http://www.mozilla.org/MPL/MPL-1.1.html }
  24. { }
  25. { Software distributed under the License is distributed on an "AS IS" basis, }
  26. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  27. { the specific language governing rights and limitations under the License. }
  28. { }
  29. { Alternatively, the contents of this file may be used under the terms of the }
  30. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  31. { provisions of the LGPL License are applicable instead of those above. }
  32. { If you wish to allow use of your version of this file only under the terms }
  33. { of the LGPL License and not to allow others to use your version of this file }
  34. { under the MPL, indicate your decision by deleting the provisions above and }
  35. { replace them with the notice and other provisions required by the LGPL }
  36. { License. If you do not delete the provisions above, a recipient may use }
  37. { your version of this file under either the MPL or the LGPL License. }
  38. { }
  39. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  40. { }
  41. {******************************************************************************}
  42. unit JwaWinSafer;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "winsafer.h"'}
  46. {$HPPEMIT ''}
  47. {$I jediapilib.inc}
  48. interface
  49. uses
  50. JwaWinCrypt, JwaWinType;
  51. //
  52. // Opaque datatype for representing handles to Safer objects.
  53. //
  54. type
  55. SAFER_LEVEL_HANDLE = HANDLE;
  56. {$EXTERNALSYM SAFER_LEVEL_HANDLE}
  57. PSAFER_LEVEL_HANDLE = ^SAFER_LEVEL_HANDLE;
  58. {$EXTERNALSYM PSAFER_LEVEL_HANDLE}
  59. TSaferLevelHandle = SAFER_LEVEL_HANDLE;
  60. PSaferLevelHandle = PSAFER_LEVEL_HANDLE;
  61. //
  62. // Constants to represent scope with SaferCreateLevel and others.
  63. //
  64. const
  65. SAFER_SCOPEID_MACHINE = 1;
  66. {$EXTERNALSYM SAFER_SCOPEID_MACHINE}
  67. SAFER_SCOPEID_USER = 2;
  68. {$EXTERNALSYM SAFER_SCOPEID_USER}
  69. //
  70. // Pre-defined levels that can be used with SaferCreateLevel
  71. //
  72. SAFER_LEVELID_FULLYTRUSTED = $40000;
  73. {$EXTERNALSYM SAFER_LEVELID_FULLYTRUSTED}
  74. SAFER_LEVELID_NORMALUSER = $20000;
  75. {$EXTERNALSYM SAFER_LEVELID_NORMALUSER}
  76. SAFER_LEVELID_CONSTRAINED = $10000;
  77. {$EXTERNALSYM SAFER_LEVELID_CONSTRAINED}
  78. SAFER_LEVELID_UNTRUSTED = $01000;
  79. {$EXTERNALSYM SAFER_LEVELID_UNTRUSTED}
  80. SAFER_LEVELID_DISALLOWED = $00000;
  81. {$EXTERNALSYM SAFER_LEVELID_DISALLOWED}
  82. //
  83. // Flags to use when creating/opening a Level with SaferCreateLevel
  84. //
  85. SAFER_LEVEL_OPEN = 1;
  86. {$EXTERNALSYM SAFER_LEVEL_OPEN}
  87. //
  88. // Maximum string size.
  89. //
  90. SAFER_MAX_FRIENDLYNAME_SIZE = 256;
  91. {$EXTERNALSYM SAFER_MAX_FRIENDLYNAME_SIZE}
  92. SAFER_MAX_DESCRIPTION_SIZE = 256;
  93. {$EXTERNALSYM SAFER_MAX_DESCRIPTION_SIZE}
  94. SAFER_MAX_HASH_SIZE = 64;
  95. {$EXTERNALSYM SAFER_MAX_HASH_SIZE}
  96. //
  97. // Flags to use with SaferComputeTokenFromLevel.
  98. //
  99. SAFER_TOKEN_NULL_IF_EQUAL = $00000001;
  100. {$EXTERNALSYM SAFER_TOKEN_NULL_IF_EQUAL}
  101. SAFER_TOKEN_COMPARE_ONLY = $00000002;
  102. {$EXTERNALSYM SAFER_TOKEN_COMPARE_ONLY}
  103. SAFER_TOKEN_MAKE_INERT = $00000004;
  104. {$EXTERNALSYM SAFER_TOKEN_MAKE_INERT}
  105. SAFER_TOKEN_WANT_FLAGS = $00000008;
  106. {$EXTERNALSYM SAFER_TOKEN_WANT_FLAGS}
  107. //
  108. // Flags for specifying what criteria within SAFER_CODE_PROPERTIES to evaluate
  109. // when finding code identity with SaferIdentifyLevel.
  110. //
  111. SAFER_CRITERIA_IMAGEPATH = $00001;
  112. {$EXTERNALSYM SAFER_CRITERIA_IMAGEPATH}
  113. SAFER_CRITERIA_NOSIGNEDHASH = $00002;
  114. {$EXTERNALSYM SAFER_CRITERIA_NOSIGNEDHASH}
  115. SAFER_CRITERIA_IMAGEHASH = $00004;
  116. {$EXTERNALSYM SAFER_CRITERIA_IMAGEHASH}
  117. SAFER_CRITERIA_AUTHENTICODE = $00008;
  118. {$EXTERNALSYM SAFER_CRITERIA_AUTHENTICODE}
  119. SAFER_CRITERIA_URLZONE = $00010;
  120. {$EXTERNALSYM SAFER_CRITERIA_URLZONE}
  121. SAFER_CRITERIA_IMAGEPATH_NT = $01000;
  122. {$EXTERNALSYM SAFER_CRITERIA_IMAGEPATH_NT}
  123. //
  124. // Code image information structure passed to SaferIdentifyLevel.
  125. //
  126. // #include <pshpack8.h> todo
  127. type
  128. _SAFER_CODE_PROPERTIES = record
  129. //
  130. // Must be initialized to be the size of this structure,
  131. // for the purposes of future/backwards compatibility.
  132. //
  133. cbSize: DWORD;
  134. //
  135. // Must be initialized to the types of criteria that should
  136. // be considered when evaluating this structure. This can be
  137. // a combination of the SAFER_CRITERIA_xxxx flags. If not enough
  138. // of the structure elements needed to evaluate the criteria
  139. // types indicated were supplied, then some of those criteria
  140. // flags may be silently ignored. Specifying 0 for this value
  141. // will cause the entire structure's contents to be ignored.
  142. //
  143. dwCheckFlags: DWORD;
  144. //
  145. // Optionally specifies the fully-qualified path and filename
  146. // to be used for discrimination checks based on the path.
  147. // The ImagePath will additionally be used to open and read the
  148. // file to identify any other discrimination criteria that was
  149. // unsupplied in this structure.
  150. //
  151. ImagePath: LPCWSTR;
  152. //
  153. // Optionally specifies a file handle that has been opened to
  154. // code image with at least GENERIC_READ access. The handle will
  155. // be used instead of explicitly opening the file again to compute
  156. // other discrimination criteria that was unsupplied in this structure.
  157. //
  158. hImageFileHandle: HANDLE;
  159. //
  160. // Optionally specifies the pre-determined Internet Explorer
  161. // security zone. These enums are defined within urlmon.h
  162. // For example: URLZONE_LOCAL_MACHINE, URLZONE_INTRANET,
  163. // URLZONE_TRUSTED, URLZONE_INTERNET, or URLZONE_UNTRUSTED.
  164. //
  165. UrlZoneId: DWORD;
  166. //
  167. // Optionally specifies the pre-computed hash of the image.
  168. // The supplied hash is interpreted as being valid if ImageSize
  169. // is non-zero and dwImageHashSize is non-zero and HashAlgorithm
  170. // represents a valid hashing algorithm from wincrypt.h
  171. //
  172. // If the supplied hash fails to meet the conditions above, then
  173. // the hash will be automatically computed against:
  174. // 1) by using ImageSize and pByteBlock if both are non-zero.
  175. // 2) by using hImageFileHandle if it is non-null.
  176. // 3) by attempting to open ImagePath if it is non-null.
  177. //
  178. ImageHash: array [0..SAFER_MAX_HASH_SIZE - 1] of BYTE;
  179. dwImageHashSize: DWORD;
  180. ImageSize: LARGE_INTEGER;
  181. HashAlgorithm: ALG_ID;
  182. //
  183. // Optionally specifies a memory block of memory representing
  184. // the image for which the trust is being requested for. When
  185. // this member is specified, ImageSize must also be supplied.
  186. //
  187. pByteBlock: LPBYTE;
  188. //
  189. // Optionally gives the arguments used for Authenticode signer
  190. // certificate verification. These arguments are supplied to the
  191. // WinVerifyTrust() API and control the user-interface prompting
  192. // to accept untrusted certificates.
  193. //
  194. hWndParent: HWND;
  195. dwWVTUIChoice: DWORD;
  196. end;
  197. {$EXTERNALSYM _SAFER_CODE_PROPERTIES}
  198. SAFER_CODE_PROPERTIES = _SAFER_CODE_PROPERTIES;
  199. {$EXTERNALSYM SAFER_CODE_PROPERTIES}
  200. PSAFER_CODE_PROPERTIES = ^SAFER_CODE_PROPERTIES;
  201. {$EXTERNALSYM PSAFER_CODE_PROPERTIES}
  202. TSaferCodeProperties = SAFER_CODE_PROPERTIES;
  203. PSaferCodeProperties = PSAFER_CODE_PROPERTIES;
  204. // #include <poppack.h>
  205. //
  206. // Masks for the per-identity WinSafer flags
  207. //
  208. const
  209. SAFER_POLICY_JOBID_MASK = DWORD($FF000000);
  210. {$EXTERNALSYM SAFER_POLICY_JOBID_MASK}
  211. SAFER_POLICY_JOBID_CONSTRAINED = $04000000;
  212. {$EXTERNALSYM SAFER_POLICY_JOBID_CONSTRAINED}
  213. SAFER_POLICY_JOBID_UNTRUSTED = $03000000;
  214. {$EXTERNALSYM SAFER_POLICY_JOBID_UNTRUSTED}
  215. SAFER_POLICY_ONLY_EXES = $00010000;
  216. {$EXTERNALSYM SAFER_POLICY_ONLY_EXES}
  217. SAFER_POLICY_SANDBOX_INERT = $00020000;
  218. {$EXTERNALSYM SAFER_POLICY_SANDBOX_INERT}
  219. SAFER_POLICY_UIFLAGS_MASK = $000000FF;
  220. {$EXTERNALSYM SAFER_POLICY_UIFLAGS_MASK}
  221. SAFER_POLICY_UIFLAGS_INFORMATION_PROMPT = $00000001;
  222. {$EXTERNALSYM SAFER_POLICY_UIFLAGS_INFORMATION_PROMPT}
  223. SAFER_POLICY_UIFLAGS_OPTION_PROMPT = $00000002;
  224. {$EXTERNALSYM SAFER_POLICY_UIFLAGS_OPTION_PROMPT}
  225. //
  226. // Information classes on the overall policy that can be queried
  227. // with SaferSet/GetPolicyInformation and set at different
  228. // policy scopes based on access of the caller.
  229. //
  230. type
  231. _SAFER_POLICY_INFO_CLASS = (
  232. spicFiller0,
  233. //
  234. // Accesses the list of all Levels defined in a policy.
  235. // The corresponding data element is a buffer that is filled
  236. // with multiple DWORDs, each representing the LevelIds that
  237. // are defined within this scope.
  238. //
  239. SaferPolicyLevelList,
  240. //
  241. // for transparent enforcement of policy in the execution
  242. // framework -- will be used by native code execution but can
  243. // be used by any policy enforcement environment.
  244. // Corresponding data element is a DWORD holding a Boolean value.
  245. //
  246. SaferPolicyEnableTransparentEnforcement,
  247. //
  248. // Returns the name of the Level that has been designed
  249. // as the default level within the specified scope.
  250. // The corresponding data element is a single DWORD buffer
  251. // representing the LevelId of the default Level. If no
  252. // level has been configured to be the default, then the
  253. // GetInfo API will return FALSE and GetLastError will
  254. // return ERROR_NOT_FOUND.
  255. //
  256. SaferPolicyDefaultLevel,
  257. //
  258. // Returns whether Code Identities or Default Level within the
  259. // user scope can be considered during identification.
  260. //
  261. SaferPolicyEvaluateUserScope,
  262. //
  263. // Control Flags for for safer policy scope.
  264. //
  265. SaferPolicyScopeFlags);
  266. {$EXTERNALSYM _SAFER_POLICY_INFO_CLASS}
  267. SAFER_POLICY_INFO_CLASS = _SAFER_POLICY_INFO_CLASS;
  268. {$EXTERNALSYM SAFER_POLICY_INFO_CLASS}
  269. TSaferPolicyInfoClass = SAFER_POLICY_INFO_CLASS;
  270. //
  271. // Enumerations used for retrieving specific information about a
  272. // single authorization Level via SaferGet/SetInformationFromLevel.
  273. //
  274. _SAFER_OBJECT_INFO_CLASS = (
  275. soicFillter0,
  276. SaferObjectLevelId, // get: DWORD
  277. SaferObjectScopeId, // get: DWORD
  278. SaferObjectFriendlyName, // get/set: LPCWSTR
  279. SaferObjectDescription, // get/set: LPCWSTR
  280. SaferObjectBuiltin, // get: DWORD boolean
  281. SaferObjectDisallowed, // get: DWORD boolean
  282. SaferObjectDisableMaxPrivilege, // get: DWORD boolean
  283. SaferObjectInvertDeletedPrivileges, // get: DWORD boolean
  284. SaferObjectDeletedPrivileges, // get: TOKEN_PRIVILEGES
  285. SaferObjectDefaultOwner, // get: TOKEN_OWNER
  286. SaferObjectSidsToDisable, // get: TOKEN_GROUPS
  287. SaferObjectRestrictedSidsInverted, // get: TOKEN_GROUPS
  288. SaferObjectRestrictedSidsAdded, // get: TOKEN_GROUPS
  289. //
  290. // To enumerate all identities, call GetInfo with
  291. // SaferObjectAllIdentificationGuids.
  292. //
  293. SaferObjectAllIdentificationGuids, // get: SAFER_IDENTIFICATION_GUIDS
  294. //
  295. // To create a new identity, call SetInfo with
  296. // SaferObjectSingleIdentification with a new
  297. // unique GUID that you have generated.
  298. // To get details on a single identity, call GetInfo with
  299. // SaferObjectSingleIdentification with desired GUID.
  300. // To modify details of a single identity, call SetInfo with
  301. // SaferObjectSingleIdentification with desired info and GUID.
  302. // To delete an identity, call SetInfo with
  303. // SaferObjectSingleIdentification with the
  304. // header.dwIdentificationType set to 0.
  305. //
  306. SaferObjectSingleIdentification, // get/set: SAFER_IDENTIFICATION_*
  307. SaferObjectExtendedError); // get: DWORD dwError
  308. {$EXTERNALSYM _SAFER_OBJECT_INFO_CLASS}
  309. SAFER_OBJECT_INFO_CLASS = _SAFER_OBJECT_INFO_CLASS;
  310. {$EXTERNALSYM SAFER_OBJECT_INFO_CLASS}
  311. TSaferObjectInfoClass = SAFER_OBJECT_INFO_CLASS;
  312. //
  313. // Structures and enums used by the SaferGet/SetLevelInformation APIs.
  314. //
  315. // #include <pshpack8.h> todo
  316. _SAFER_IDENTIFICATION_TYPES = (
  317. SaferIdentityDefault,
  318. SaferIdentityTypeImageName,
  319. SaferIdentityTypeImageHash,
  320. SaferIdentityTypeUrlZone,
  321. SaferIdentityTypeCertificate);
  322. {$EXTERNALSYM _SAFER_IDENTIFICATION_TYPES}
  323. SAFER_IDENTIFICATION_TYPES = _SAFER_IDENTIFICATION_TYPES;
  324. {$EXTERNALSYM SAFER_IDENTIFICATION_TYPES}
  325. TSaferIdentificationTypes = SAFER_IDENTIFICATION_TYPES;
  326. _SAFER_IDENTIFICATION_HEADER = record
  327. //
  328. // indicates the type of the structure, one of SaferIdentityType*
  329. //
  330. dwIdentificationType: SAFER_IDENTIFICATION_TYPES;
  331. //
  332. // size of the whole structure, not just the common header.
  333. //
  334. cbStructSize: DWORD;
  335. //
  336. // the unique GUID of the Identity in question.
  337. //
  338. IdentificationGuid: GUID;
  339. //
  340. // last change of this identification.
  341. //
  342. lastModified: FILETIME;
  343. end;
  344. {$EXTERNALSYM _SAFER_IDENTIFICATION_HEADER}
  345. SAFER_IDENTIFICATION_HEADER = _SAFER_IDENTIFICATION_HEADER;
  346. {$EXTERNALSYM SAFER_IDENTIFICATION_HEADER}
  347. PSAFER_IDENTIFICATION_HEADER = ^SAFER_IDENTIFICATION_HEADER;
  348. {$EXTERNALSYM PSAFER_IDENTIFICATION_HEADER}
  349. TSaferIdentificationHeader = SAFER_IDENTIFICATION_HEADER;
  350. PSaferIdentificationHeader = PSAFER_IDENTIFICATION_HEADER;
  351. _SAFER_PATHNAME_IDENTIFICATION = record
  352. //
  353. // header.dwIdentificationType must be SaferIdentityTypeImageName
  354. // header.cbStructSize must be sizeof(SAFER_PATHNAME_IDENTIFICATION)
  355. //
  356. header: SAFER_IDENTIFICATION_HEADER;
  357. //
  358. // user-entered description
  359. //
  360. Description: array [0..SAFER_MAX_DESCRIPTION_SIZE - 1] of WCHAR;
  361. //
  362. // filepath or name, possibly with vars
  363. //
  364. ImageName: PWCHAR;
  365. //
  366. // any combo of SAFER_POL_SAFERFLAGS_*
  367. //
  368. dwSaferFlags: DWORD;
  369. end;
  370. {$EXTERNALSYM _SAFER_PATHNAME_IDENTIFICATION}
  371. SAFER_PATHNAME_IDENTIFICATION = _SAFER_PATHNAME_IDENTIFICATION;
  372. {$EXTERNALSYM SAFER_PATHNAME_IDENTIFICATION}
  373. PSAFER_PATHNAME_IDENTIFICATION = ^SAFER_PATHNAME_IDENTIFICATION;
  374. {$EXTERNALSYM PSAFER_PATHNAME_IDENTIFICATION}
  375. TSaferPathNameIdentification = SAFER_PATHNAME_IDENTIFICATION;
  376. PSaferPathNameIdentification = PSAFER_PATHNAME_IDENTIFICATION;
  377. _SAFER_HASH_IDENTIFICATION = record
  378. //
  379. // header.dwIdentificationType must be SaferIdentityTypeImageHash
  380. // header.cbStructSize must be sizeof(SAFER_HASH_IDENTIFICATION)
  381. //
  382. header: SAFER_IDENTIFICATION_HEADER;
  383. //
  384. // user-entered friendly name, initially from file's resources.
  385. //
  386. Description: array [0..SAFER_MAX_DESCRIPTION_SIZE - 1] of WCHAR;
  387. //
  388. // user-entered description.
  389. //
  390. FriendlyName: array [0..SAFER_MAX_FRIENDLYNAME_SIZE - 1] of WCHAR;
  391. //
  392. // amount of ImageHash actually used, in bytes (MD5 is 16 bytes).
  393. //
  394. HashSize: DWORD;
  395. //
  396. // computed hash data itself.
  397. //
  398. ImageHash: array [0..SAFER_MAX_HASH_SIZE - 1] of BYTE;
  399. //
  400. // algorithm in which the hash was computed (CALG_MD5, etc).
  401. //
  402. HashAlgorithm: ALG_ID;
  403. //
  404. // size of the original file in bytes.
  405. //
  406. ImageSize: LARGE_INTEGER;
  407. //
  408. // any combo of SAFER_POL_SAFERFLAGS_*
  409. //
  410. dwSaferFlags: DWORD;
  411. end;
  412. {$EXTERNALSYM _SAFER_HASH_IDENTIFICATION}
  413. SAFER_HASH_IDENTIFICATION = _SAFER_HASH_IDENTIFICATION;
  414. {$EXTERNALSYM SAFER_HASH_IDENTIFICATION}
  415. PSAFER_HASH_IDENTIFICATION = ^SAFER_HASH_IDENTIFICATION;
  416. {$EXTERNALSYM PSAFER_HASH_IDENTIFICATION}
  417. TSaferHashIdentification = SAFER_HASH_IDENTIFICATION;
  418. PSaferHashIdentification = PSAFER_HASH_IDENTIFICATION;
  419. _SAFER_URLZONE_IDENTIFICATION = record
  420. //
  421. // header.dwIdentificationType must be SaferIdentityTypeUrlZone
  422. // header.cbStructSize must be sizeof(SAFER_URLZONE_IDENTIFICATION)
  423. //
  424. header: SAFER_IDENTIFICATION_HEADER;
  425. //
  426. // any single URLZONE_* from urlmon.h
  427. //
  428. UrlZoneId: DWORD;
  429. //
  430. // any combo of SAFER_POLICY_*
  431. //
  432. dwSaferFlags: DWORD;
  433. end;
  434. {$EXTERNALSYM _SAFER_URLZONE_IDENTIFICATION}
  435. SAFER_URLZONE_IDENTIFICATION = _SAFER_URLZONE_IDENTIFICATION;
  436. {$EXTERNALSYM SAFER_URLZONE_IDENTIFICATION}
  437. PSAFER_URLZONE_IDENTIFICATION = ^SAFER_URLZONE_IDENTIFICATION;
  438. {$EXTERNALSYM PSAFER_URLZONE_IDENTIFICATION}
  439. TSaferUrlZoneIdentification = SAFER_URLZONE_IDENTIFICATION;
  440. PSaferUrlZoneIdentification = PSAFER_URLZONE_IDENTIFICATION;
  441. // #include <poppack.h>
  442. //
  443. // Functions related to querying and setting the global policy
  444. // controls to disable transparent enforcement, and perform level
  445. // enumeration operations.
  446. //
  447. function SaferGetPolicyInformation(dwScopeId: DWORD; SaferPolicyInfoClass: SAFER_POLICY_INFO_CLASS;
  448. InfoBufferSize: DWORD; InfoBuffer: PVOID; var InfoBufferRetSize: DWORD; lpReserved: LPVOID): BOOL; stdcall;
  449. {$EXTERNALSYM SaferGetPolicyInformation}
  450. function SaferSetPolicyInformation(dwScopeId: DWORD; SaferPolicyInfoClass: SAFER_POLICY_INFO_CLASS;
  451. InfoBufferSize: DWORD; InfoBuffer: PVOID; lpReserved: LPVOID): BOOL; stdcall;
  452. {$EXTERNALSYM SaferSetPolicyInformation}
  453. //
  454. // Functions to open or close a handle to a Safer Level.
  455. //
  456. function SaferCreateLevel(dwScopeId, dwLevelId, OpenFlags: DWORD; pLevelHandle: PSAFER_LEVEL_HANDLE; lpReserved: LPVOID): BOOL; stdcall;
  457. {$EXTERNALSYM SaferCreateLevel}
  458. function SaferCloseLevel(hLevelHandle: SAFER_LEVEL_HANDLE): BOOL; stdcall;
  459. {$EXTERNALSYM SaferCloseLevel}
  460. function SaferIdentifyLevel(dwNumProperties: DWORD; pCodeProperties: PSAFER_CODE_PROPERTIES;
  461. var pLevelHandle: SAFER_LEVEL_HANDLE; lpReserved: LPVOID): BOOL; stdcall;
  462. {$EXTERNALSYM SaferIdentifyLevel}
  463. function SaferComputeTokenFromLevel(LevelHandle: SAFER_LEVEL_HANDLE; InAccessToken: HANDLE; OutAccessToken: PHANDLE;
  464. dwFlags: DWORD; lpReserved: LPVOID): BOOL; stdcall;
  465. {$EXTERNALSYM SaferComputeTokenFromLevel}
  466. function SaferGetLevelInformation(LevelHandle: SAFER_LEVEL_HANDLE; dwInfoType: SAFER_OBJECT_INFO_CLASS;
  467. lpQueryBuffer: LPVOID; dwInBufferSize: DWORD; var lpdwOutBufferSize: DWORD): BOOL; stdcall;
  468. {$EXTERNALSYM SaferGetLevelInformation}
  469. function SaferSetLevelInformation(LevelHandle: SAFER_LEVEL_HANDLE; dwInfoType: SAFER_OBJECT_INFO_CLASS;
  470. lpQueryBuffer: LPVOID; dwInBufferSize: DWORD): BOOL; stdcall;
  471. {$EXTERNALSYM SaferSetLevelInformation}
  472. //
  473. // This function performs logging of messages to the Application
  474. // event log. This is called by the hooks within CreateProcess,
  475. // ShellExecute and cmd when a lower trust evaluation result occurs.
  476. //
  477. function SaferRecordEventLogEntry(hLevel: SAFER_LEVEL_HANDLE; szTargetPath: LPCWSTR; lpReserved: LPVOID): BOOL; stdcall;
  478. {$EXTERNALSYM SaferRecordEventLogEntry}
  479. function SaferiIsExecutableFileType(szFullPathname: LPCWSTR; bFromShellExecute: BOOL): BOOL; stdcall;
  480. {$EXTERNALSYM SaferiIsExecutableFileType}
  481. implementation
  482. const
  483. advapi32 = 'advapi32.dll';
  484. {$IFDEF DYNAMIC_LINK}
  485. var
  486. _SaferGetPolicyInformation: Pointer;
  487. function SaferGetPolicyInformation;
  488. begin
  489. GetProcedureAddress(_SaferGetPolicyInformation, advapi32, 'SaferGetPolicyInformation');
  490. asm
  491. MOV ESP, EBP
  492. POP EBP
  493. JMP [_SaferGetPolicyInformation]
  494. end;
  495. end;
  496. var
  497. _SaferSetPolicyInformation: Pointer;
  498. function SaferSetPolicyInformation;
  499. begin
  500. GetProcedureAddress(_SaferSetPolicyInformation, advapi32, 'SaferSetPolicyInformation');
  501. asm
  502. MOV ESP, EBP
  503. POP EBP
  504. JMP [_SaferSetPolicyInformation]
  505. end;
  506. end;
  507. var
  508. _SaferCreateLevel: Pointer;
  509. function SaferCreateLevel;
  510. begin
  511. GetProcedureAddress(_SaferCreateLevel, advapi32, 'SaferCreateLevel');
  512. asm
  513. MOV ESP, EBP
  514. POP EBP
  515. JMP [_SaferCreateLevel]
  516. end;
  517. end;
  518. var
  519. _SaferCloseLevel: Pointer;
  520. function SaferCloseLevel;
  521. begin
  522. GetProcedureAddress(_SaferCloseLevel, advapi32, 'SaferCloseLevel');
  523. asm
  524. MOV ESP, EBP
  525. POP EBP
  526. JMP [_SaferCloseLevel]
  527. end;
  528. end;
  529. var
  530. _SaferIdentifyLevel: Pointer;
  531. function SaferIdentifyLevel;
  532. begin
  533. GetProcedureAddress(_SaferIdentifyLevel, advapi32, 'SaferIdentifyLevel');
  534. asm
  535. MOV ESP, EBP
  536. POP EBP
  537. JMP [_SaferIdentifyLevel]
  538. end;
  539. end;
  540. var
  541. _SaferComputeTokenFromLevel: Pointer;
  542. function SaferComputeTokenFromLevel;
  543. begin
  544. GetProcedureAddress(_SaferComputeTokenFromLevel, advapi32, 'SaferComputeTokenFromLevel');
  545. asm
  546. MOV ESP, EBP
  547. POP EBP
  548. JMP [_SaferComputeTokenFromLevel]
  549. end;
  550. end;
  551. var
  552. _SaferGetLevelInformation: Pointer;
  553. function SaferGetLevelInformation;
  554. begin
  555. GetProcedureAddress(_SaferGetLevelInformation, advapi32, 'SaferGetLevelInformation');
  556. asm
  557. MOV ESP, EBP
  558. POP EBP
  559. JMP [_SaferGetLevelInformation]
  560. end;
  561. end;
  562. var
  563. _SaferSetLevelInformation: Pointer;
  564. function SaferSetLevelInformation;
  565. begin
  566. GetProcedureAddress(_SaferSetLevelInformation, advapi32, 'SaferSetLevelInformation');
  567. asm
  568. MOV ESP, EBP
  569. POP EBP
  570. JMP [_SaferSetLevelInformation]
  571. end;
  572. end;
  573. var
  574. _SaferRecordEventLogEntry: Pointer;
  575. function SaferRecordEventLogEntry;
  576. begin
  577. GetProcedureAddress(_SaferRecordEventLogEntry, advapi32, 'SaferRecordEventLogEntry');
  578. asm
  579. MOV ESP, EBP
  580. POP EBP
  581. JMP [_SaferRecordEventLogEntry]
  582. end;
  583. end;
  584. var
  585. _SaferiIsExecutableFileType: Pointer;
  586. function SaferiIsExecutableFileType;
  587. begin
  588. GetProcedureAddress(_SaferiIsExecutableFileType, advapi32, 'SaferiIsExecutableFileType');
  589. asm
  590. MOV ESP, EBP
  591. POP EBP
  592. JMP [_SaferiIsExecutableFileType]
  593. end;
  594. end;
  595. {$ELSE}
  596. function SaferGetPolicyInformation; external advapi32 name 'SaferGetPolicyInformation';
  597. function SaferSetPolicyInformation; external advapi32 name 'SaferSetPolicyInformation';
  598. function SaferCreateLevel; external advapi32 name 'SaferCreateLevel';
  599. function SaferCloseLevel; external advapi32 name 'SaferCloseLevel';
  600. function SaferIdentifyLevel; external advapi32 name 'SaferIdentifyLevel';
  601. function SaferComputeTokenFromLevel; external advapi32 name 'SaferComputeTokenFromLevel';
  602. function SaferGetLevelInformation; external advapi32 name 'SaferGetLevelInformation';
  603. function SaferSetLevelInformation; external advapi32 name 'SaferSetLevelInformation';
  604. function SaferRecordEventLogEntry; external advapi32 name 'SaferRecordEventLogEntry';
  605. function SaferiIsExecutableFileType; external advapi32 name 'SaferiIsExecutableFileType';
  606. {$ENDIF DYNAMIC_LINK}
  607. end.