jwawinsafer.pas 24 KB

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