jwawinsafer.pas 24 KB

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