techprotrade commited on
Commit
f36aa21
·
verified ·
1 Parent(s): 5941bce

Add loan-advisor-agent

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +7 -0
  2. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/BackupRead_BackupWrite.py +119 -0
  3. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/BackupSeek_streamheaders.py +137 -0
  4. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/CopyFileEx.py +57 -0
  5. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/CreateFileTransacted_MiniVersion.py +122 -0
  6. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/EvtFormatMessage.py +83 -0
  7. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/EvtSubscribe_pull.py +28 -0
  8. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/EvtSubscribe_push.py +32 -0
  9. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/FileSecurityTest.py +137 -0
  10. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/GetSaveFileName.py +43 -0
  11. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/NetValidatePasswordPolicy.py +127 -0
  12. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/OpenEncryptedFileRaw.py +66 -0
  13. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/RegCreateKeyTransacted.py +60 -0
  14. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/RegRestoreKey.py +71 -0
  15. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/SystemParametersInfo.py +210 -0
  16. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/c_extension/setup.py +26 -0
  17. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/dde/ddeclient.py +18 -0
  18. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/dde/ddeserver.py +42 -0
  19. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/desktopmanager.py +246 -0
  20. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/eventLogDemo.py +138 -0
  21. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/getfilever.py +33 -0
  22. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/images/frowny.bmp +0 -0
  23. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/images/smiley.bmp +0 -0
  24. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/mmapfile_demo.py +101 -0
  25. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/pipes/cat.py +17 -0
  26. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/pipes/runproc.py +114 -0
  27. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/print_desktop.py +113 -0
  28. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/rastest.py +166 -0
  29. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/GetTokenInformation.py +110 -0
  30. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/account_rights.py +49 -0
  31. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/explicit_entries.py +170 -0
  32. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/get_policy_info.py +39 -0
  33. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/list_rights.py +35 -0
  34. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/localized_names.py +70 -0
  35. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/lsaregevent.py +14 -0
  36. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/lsastore.py +12 -0
  37. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/query_information.py +25 -0
  38. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/regsave_sa.py +61 -0
  39. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/regsecurity.py +36 -0
  40. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/sa_inherit.py +8 -0
  41. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/security_enums.py +336 -0
  42. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/set_file_audit.py +106 -0
  43. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/set_file_owner.py +73 -0
  44. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/set_policy_info.py +25 -0
  45. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/setkernelobjectsecurity.py +134 -0
  46. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/setnamedsecurityinfo.py +131 -0
  47. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/setsecurityinfo.py +131 -0
  48. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/setuserobjectsecurity.py +102 -0
  49. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/sspi/fetch_url.py +158 -0
  50. loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/sspi/simple_auth.py +72 -0
.gitattributes CHANGED
@@ -711,3 +711,10 @@ loan-advisor-agent/.venv/Lib/site-packages/sqlalchemy/cyextension/collections.cp
711
  loan-advisor-agent/.venv/Lib/site-packages/tiktoken/_tiktoken.cp312-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
712
  loan-advisor-agent/.venv/Lib/site-packages/tokenizers/tokenizers.pyd filter=lfs diff=lfs merge=lfs -text
713
  loan-advisor-agent/.venv/Lib/site-packages/vertexai/generative_models/__pycache__/_generative_models.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
711
  loan-advisor-agent/.venv/Lib/site-packages/tiktoken/_tiktoken.cp312-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
712
  loan-advisor-agent/.venv/Lib/site-packages/tokenizers/tokenizers.pyd filter=lfs diff=lfs merge=lfs -text
713
  loan-advisor-agent/.venv/Lib/site-packages/vertexai/generative_models/__pycache__/_generative_models.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
714
+ loan-advisor-agent/.venv/Lib/site-packages/win32/lib/__pycache__/win32con.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
715
+ loan-advisor-agent/.venv/Lib/site-packages/win32/libs/pywintypes.lib filter=lfs diff=lfs merge=lfs -text
716
+ loan-advisor-agent/.venv/Lib/site-packages/win32/win32api.pyd filter=lfs diff=lfs merge=lfs -text
717
+ loan-advisor-agent/.venv/Lib/site-packages/win32/win32crypt.pyd filter=lfs diff=lfs merge=lfs -text
718
+ loan-advisor-agent/.venv/Lib/site-packages/win32/win32file.pyd filter=lfs diff=lfs merge=lfs -text
719
+ loan-advisor-agent/.venv/Lib/site-packages/win32/win32gui.pyd filter=lfs diff=lfs merge=lfs -text
720
+ loan-advisor-agent/.venv/Lib/site-packages/win32/win32security.pyd filter=lfs diff=lfs merge=lfs -text
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/BackupRead_BackupWrite.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## demonstrates using BackupRead and BackupWrite to copy all of a file's data streams
2
+
3
+ import ntsecuritycon
4
+ import pythoncom
5
+ import pywintypes
6
+ import win32api
7
+ import win32con
8
+ import win32file
9
+ import win32security
10
+ from win32com import storagecon
11
+
12
+ all_sd_info = (
13
+ win32security.DACL_SECURITY_INFORMATION
14
+ | win32security.DACL_SECURITY_INFORMATION
15
+ | win32security.OWNER_SECURITY_INFORMATION
16
+ | win32security.GROUP_SECURITY_INFORMATION
17
+ )
18
+
19
+ tempdir = win32api.GetTempPath()
20
+ tempfile = win32api.GetTempFileName(tempdir, "bkr")[0]
21
+ outfile = win32api.GetTempFileName(tempdir, "out")[0]
22
+ print("Filename:", tempfile, "Output file:", outfile)
23
+
24
+ f = open(tempfile, "w")
25
+ f.write("some random junk" + "x" * 100)
26
+ f.close()
27
+
28
+ ## add a couple of alternate data streams
29
+ f = open(tempfile + ":streamdata", "w")
30
+ f.write("data written to alternate stream" + "y" * 100)
31
+ f.close()
32
+
33
+ f = open(tempfile + ":anotherstream", "w")
34
+ f.write("z" * 100)
35
+ f.close()
36
+
37
+ ## add Summary Information, which is stored as a separate stream
38
+ m = storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE | storagecon.STGM_DIRECT
39
+ pss = pythoncom.StgOpenStorageEx(
40
+ tempfile, m, storagecon.STGFMT_FILE, 0, pythoncom.IID_IPropertySetStorage, None
41
+ )
42
+ ps = pss.Create(
43
+ pythoncom.FMTID_SummaryInformation,
44
+ pythoncom.IID_IPropertyStorage,
45
+ 0,
46
+ storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE,
47
+ )
48
+ ps.WriteMultiple(
49
+ (storagecon.PIDSI_KEYWORDS, storagecon.PIDSI_COMMENTS), ("keywords", "comments")
50
+ )
51
+ ps = None
52
+ pss = None
53
+
54
+ ## add a custom security descriptor to make sure we don't
55
+ ## get a default that would always be the same for both files in temp dir
56
+ new_sd = pywintypes.SECURITY_DESCRIPTOR()
57
+ sid = win32security.LookupAccountName("", "EveryOne")[0]
58
+ acl = pywintypes.ACL()
59
+ acl.AddAccessAllowedAce(1, win32con.GENERIC_READ, sid)
60
+ acl.AddAccessAllowedAce(1, ntsecuritycon.FILE_APPEND_DATA, sid)
61
+ acl.AddAccessAllowedAce(1, win32con.GENERIC_WRITE, sid)
62
+ acl.AddAccessAllowedAce(1, ntsecuritycon.FILE_ALL_ACCESS, sid)
63
+
64
+ new_sd.SetSecurityDescriptorDacl(True, acl, False)
65
+ win32security.SetFileSecurity(tempfile, win32security.DACL_SECURITY_INFORMATION, new_sd)
66
+
67
+
68
+ sa = pywintypes.SECURITY_ATTRIBUTES()
69
+ sa.bInheritHandle = True
70
+ h = win32file.CreateFile(
71
+ tempfile,
72
+ win32con.GENERIC_ALL,
73
+ win32con.FILE_SHARE_READ,
74
+ sa,
75
+ win32con.OPEN_EXISTING,
76
+ win32file.FILE_FLAG_BACKUP_SEMANTICS,
77
+ None,
78
+ )
79
+
80
+ outh = win32file.CreateFile(
81
+ outfile,
82
+ win32con.GENERIC_ALL,
83
+ win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
84
+ sa,
85
+ win32con.OPEN_EXISTING,
86
+ win32file.FILE_FLAG_BACKUP_SEMANTICS,
87
+ None,
88
+ )
89
+
90
+ ctxt = 0
91
+ outctxt = 0
92
+ buf = None
93
+ readsize = 100
94
+
95
+ while 1:
96
+ bytes_read, buf, ctxt = win32file.BackupRead(h, readsize, buf, False, True, ctxt)
97
+ if bytes_read == 0:
98
+ break
99
+ bytes_written, outctxt = win32file.BackupWrite(
100
+ outh, bytes_read, buf, False, True, outctxt
101
+ )
102
+ print("Written:", bytes_written, "Context:", outctxt)
103
+ win32file.BackupRead(h, 0, buf, True, True, ctxt)
104
+ win32file.BackupWrite(outh, 0, b"", True, True, outctxt)
105
+ win32file.CloseHandle(h)
106
+ win32file.CloseHandle(outh)
107
+
108
+ assert open(tempfile).read() == open(outfile).read(), "File contents differ !"
109
+ assert open(tempfile + ":streamdata").read() == open(outfile + ":streamdata").read(), (
110
+ "streamdata contents differ !"
111
+ )
112
+ assert (
113
+ open(tempfile + ":anotherstream").read() == open(outfile + ":anotherstream").read()
114
+ ), "anotherstream contents differ !"
115
+ assert (
116
+ memoryview(win32security.GetFileSecurity(tempfile, all_sd_info))[:]
117
+ == memoryview(win32security.GetFileSecurity(outfile, all_sd_info))[:]
118
+ ), "Security descriptors are different !"
119
+ ## also should check Summary Info programatically
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/BackupSeek_streamheaders.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## demonstrates using BackupSeek to enumerate data streams for a file
2
+ import struct
3
+
4
+ import pythoncom
5
+ import pywintypes
6
+ import win32api
7
+ import win32con
8
+ import win32file
9
+ from win32com import storagecon
10
+
11
+ stream_types = {
12
+ win32con.BACKUP_DATA: "Standard data",
13
+ win32con.BACKUP_EA_DATA: "Extended attribute data",
14
+ win32con.BACKUP_SECURITY_DATA: "Security descriptor data",
15
+ win32con.BACKUP_ALTERNATE_DATA: "Alternative data streams",
16
+ win32con.BACKUP_LINK: "Hard link information",
17
+ win32con.BACKUP_PROPERTY_DATA: "Property data",
18
+ win32con.BACKUP_OBJECT_ID: "Objects identifiers",
19
+ win32con.BACKUP_REPARSE_DATA: "Reparse points",
20
+ win32con.BACKUP_SPARSE_BLOCK: "Sparse file",
21
+ }
22
+
23
+ tempdir = win32api.GetTempPath()
24
+ tempfile = win32api.GetTempFileName(tempdir, "bkr")[0]
25
+ print("Filename:", tempfile)
26
+
27
+ f = open(tempfile, "w")
28
+ f.write("some random junk" + "x" * 100)
29
+ f.close()
30
+
31
+ f = open(tempfile + ":streamdata", "w")
32
+ f.write("data written to alternate stream" + "y" * 100)
33
+ f.close()
34
+
35
+ f = open(tempfile + ":anotherstream", "w")
36
+ f.write("z" * 200)
37
+ f.close()
38
+
39
+ ## add Summary Information, which is stored as a separate stream
40
+ m = storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE | storagecon.STGM_DIRECT
41
+ pss = pythoncom.StgOpenStorageEx(
42
+ tempfile, m, storagecon.STGFMT_FILE, 0, pythoncom.IID_IPropertySetStorage, None
43
+ )
44
+ ps = pss.Create(
45
+ pythoncom.FMTID_SummaryInformation,
46
+ pythoncom.IID_IPropertyStorage,
47
+ 0,
48
+ storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE,
49
+ )
50
+ ps.WriteMultiple(
51
+ (storagecon.PIDSI_KEYWORDS, storagecon.PIDSI_COMMENTS), ("keywords", "comments")
52
+ )
53
+ ps = None
54
+ pss = None
55
+
56
+ sa = pywintypes.SECURITY_ATTRIBUTES()
57
+ sa.bInheritHandle = False
58
+ h = win32file.CreateFile(
59
+ tempfile,
60
+ win32con.GENERIC_ALL,
61
+ win32con.FILE_SHARE_READ,
62
+ sa,
63
+ win32con.OPEN_EXISTING,
64
+ win32file.FILE_FLAG_BACKUP_SEMANTICS,
65
+ None,
66
+ )
67
+
68
+
69
+ """ stream header:
70
+ typedef struct _WIN32_STREAM_ID {
71
+ DWORD dwStreamId; DWORD dwStreamAttributes; LARGE_INTEGER Size;
72
+ DWORD dwStreamNameSize; WCHAR cStreamName[ANYSIZE_ARRAY];
73
+ }
74
+ """
75
+
76
+ win32_stream_id_format = "LLQL"
77
+ win32_stream_id_size = struct.calcsize(win32_stream_id_format)
78
+
79
+
80
+ def parse_stream_header(h, ctxt, data):
81
+ stream_type, stream_attributes, stream_size, stream_name_size = struct.unpack(
82
+ win32_stream_id_format, data
83
+ )
84
+ print(
85
+ "\nType:",
86
+ stream_type,
87
+ stream_types[stream_type],
88
+ "Attributes:",
89
+ stream_attributes,
90
+ "Size:",
91
+ stream_size,
92
+ "Name len:",
93
+ stream_name_size,
94
+ )
95
+ if stream_name_size > 0:
96
+ ## ??? sdk says this size is in characters, but it appears to be number of bytes ???
97
+ bytes_read, stream_name_buf, ctxt = win32file.BackupRead(
98
+ h, stream_name_size, None, False, True, ctxt
99
+ )
100
+ stream_name = pywintypes.UnicodeFromRaw(stream_name_buf[:])
101
+ else:
102
+ stream_name = "Unnamed"
103
+ print("Name:" + stream_name)
104
+ return (
105
+ ctxt,
106
+ stream_type,
107
+ stream_attributes,
108
+ stream_size,
109
+ stream_name_size,
110
+ stream_name,
111
+ )
112
+
113
+
114
+ ctxt = 0
115
+ win32_stream_id_buf = (
116
+ None ## gets rebound to a writable buffer on first call and reused
117
+ )
118
+ while 1:
119
+ bytes_read, win32_stream_id_buf, ctxt = win32file.BackupRead(
120
+ h, win32_stream_id_size, win32_stream_id_buf, False, True, ctxt
121
+ )
122
+ if bytes_read == 0:
123
+ break
124
+ (
125
+ ctxt,
126
+ stream_type,
127
+ stream_attributes,
128
+ stream_size,
129
+ stream_name_size,
130
+ stream_name,
131
+ ) = parse_stream_header(h, ctxt, win32_stream_id_buf[:])
132
+ if stream_size > 0:
133
+ bytes_moved = win32file.BackupSeek(h, stream_size, ctxt)
134
+ print("Moved: ", bytes_moved)
135
+
136
+ win32file.BackupRead(h, win32_stream_id_size, win32_stream_id_buf, True, True, ctxt)
137
+ win32file.CloseHandle(h)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/CopyFileEx.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32api
2
+ import win32file
3
+
4
+
5
+ def ProgressRoutine(
6
+ TotalFileSize,
7
+ TotalBytesTransferred,
8
+ StreamSize,
9
+ StreamBytesTransferred,
10
+ StreamNumber,
11
+ CallbackReason,
12
+ SourceFile,
13
+ DestinationFile,
14
+ Data,
15
+ ):
16
+ print(Data)
17
+ print(
18
+ TotalFileSize,
19
+ TotalBytesTransferred,
20
+ StreamSize,
21
+ StreamBytesTransferred,
22
+ StreamNumber,
23
+ CallbackReason,
24
+ SourceFile,
25
+ DestinationFile,
26
+ )
27
+ ##if TotalBytesTransferred > 100000:
28
+ ## return win32file.PROGRESS_STOP
29
+ return win32file.PROGRESS_CONTINUE
30
+
31
+
32
+ temp_dir = win32api.GetTempPath()
33
+ fsrc = win32api.GetTempFileName(temp_dir, "cfe")[0]
34
+ fdst = win32api.GetTempFileName(temp_dir, "cfe")[0]
35
+ print(fsrc, fdst)
36
+
37
+ f = open(fsrc, "w")
38
+ f.write("xxxxxxxxxxxxxxxx\n" * 32768)
39
+ f.close()
40
+ ## add a couple of extra data streams
41
+ f = open(fsrc + ":stream_y", "w")
42
+ f.write("yyyyyyyyyyyyyyyy\n" * 32768)
43
+ f.close()
44
+ f = open(fsrc + ":stream_z", "w")
45
+ f.write("zzzzzzzzzzzzzzzz\n" * 32768)
46
+ f.close()
47
+
48
+ operation_desc = "Copying " + fsrc + " to " + fdst
49
+ win32file.CopyFileEx(
50
+ fsrc,
51
+ fdst,
52
+ ProgressRoutine,
53
+ Data=operation_desc,
54
+ Cancel=False,
55
+ CopyFlags=win32file.COPY_FILE_RESTARTABLE,
56
+ Transaction=None,
57
+ )
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/CreateFileTransacted_MiniVersion.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ This demonstrates the creation of miniversions of a file during a transaction.
3
+ The FSCTL_TXFS_CREATE_MINIVERSION control code saves any changes to a new
4
+ miniversion (effectively a savepoint within a transaction).
5
+ """
6
+
7
+ import os
8
+ import struct
9
+
10
+ import win32api
11
+ import win32con
12
+ import win32file
13
+ import win32transaction
14
+ import winerror
15
+ import winioctlcon
16
+
17
+
18
+ def demo():
19
+ """
20
+ Definition of buffer used with FSCTL_TXFS_CREATE_MINIVERSION:
21
+ typedef struct _TXFS_CREATE_MINIVERSION_INFO{
22
+ USHORT StructureVersion;
23
+ USHORT StructureLength;
24
+ ULONG BaseVersion;
25
+ USHORT MiniVersion;}
26
+ """
27
+ buf_fmt = "HHLH0L" ## buffer size must include struct padding
28
+ buf_size = struct.calcsize(buf_fmt)
29
+
30
+ tempdir = win32api.GetTempPath()
31
+ tempfile = win32api.GetTempFileName(tempdir, "cft")[0]
32
+ print("Demonstrating transactions on tempfile", tempfile)
33
+ f = open(tempfile, "w")
34
+ f.write("This is original file.\n")
35
+ f.close()
36
+
37
+ trans = win32transaction.CreateTransaction(
38
+ Description="Test creating miniversions of a file"
39
+ )
40
+ hfile = win32file.CreateFileW(
41
+ tempfile,
42
+ win32con.GENERIC_READ | win32con.GENERIC_WRITE,
43
+ win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
44
+ None,
45
+ win32con.OPEN_EXISTING,
46
+ 0,
47
+ None,
48
+ Transaction=trans,
49
+ )
50
+
51
+ win32file.WriteFile(hfile, b"This is first miniversion.\n")
52
+ buf = win32file.DeviceIoControl(
53
+ hfile, winioctlcon.FSCTL_TXFS_CREATE_MINIVERSION, None, buf_size, None
54
+ )
55
+ struct_ver, struct_len, base_ver, ver_1 = struct.unpack(buf_fmt, buf)
56
+
57
+ win32file.SetFilePointer(hfile, 0, win32con.FILE_BEGIN)
58
+ win32file.WriteFile(hfile, b"This is second miniversion!\n")
59
+ buf = win32file.DeviceIoControl(
60
+ hfile, winioctlcon.FSCTL_TXFS_CREATE_MINIVERSION, None, buf_size, None
61
+ )
62
+ struct_ver, struct_len, base_ver, ver_2 = struct.unpack(buf_fmt, buf)
63
+ hfile.Close()
64
+
65
+ ## miniversions can't be opened with write access
66
+ hfile_0 = win32file.CreateFileW(
67
+ tempfile,
68
+ win32con.GENERIC_READ,
69
+ win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
70
+ None,
71
+ win32con.OPEN_EXISTING,
72
+ 0,
73
+ None,
74
+ Transaction=trans,
75
+ MiniVersion=base_ver,
76
+ )
77
+ print("version:", base_ver, win32file.ReadFile(hfile_0, 100))
78
+ hfile_0.Close()
79
+
80
+ hfile_1 = win32file.CreateFileW(
81
+ tempfile,
82
+ win32con.GENERIC_READ,
83
+ win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
84
+ None,
85
+ win32con.OPEN_EXISTING,
86
+ 0,
87
+ None,
88
+ Transaction=trans,
89
+ MiniVersion=ver_1,
90
+ )
91
+ print("version:", ver_1, win32file.ReadFile(hfile_1, 100))
92
+ hfile_1.Close()
93
+
94
+ hfile_2 = win32file.CreateFileW(
95
+ tempfile,
96
+ win32con.GENERIC_READ,
97
+ win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
98
+ None,
99
+ win32con.OPEN_EXISTING,
100
+ 0,
101
+ None,
102
+ Transaction=trans,
103
+ MiniVersion=ver_2,
104
+ )
105
+ print("version:", ver_2, win32file.ReadFile(hfile_2, 100))
106
+ hfile_2.Close()
107
+
108
+ ## MiniVersions are destroyed when transaction is committed or rolled back
109
+ win32transaction.CommitTransaction(trans)
110
+
111
+ os.unlink(tempfile)
112
+
113
+
114
+ if __name__ == "__main__":
115
+ # When run on CI, this fails with NOT_SUPPORTED, so don't have that cause "failure"
116
+ try:
117
+ demo()
118
+ except win32file.error as e:
119
+ if e.winerror == winerror.ERROR_NOT_SUPPORTED:
120
+ print("These features are not supported by this filesystem.")
121
+ else:
122
+ raise
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/EvtFormatMessage.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+
3
+ import win32evtlog
4
+
5
+
6
+ def main():
7
+ path = "System"
8
+ num_events = 5
9
+ if len(sys.argv) > 2:
10
+ path = sys.argv[1]
11
+ num_events = int(sys.argv[2])
12
+ elif len(sys.argv) > 1:
13
+ path = sys.argv[1]
14
+
15
+ query = win32evtlog.EvtQuery(path, win32evtlog.EvtQueryForwardDirection)
16
+ events = win32evtlog.EvtNext(query, num_events)
17
+ context = win32evtlog.EvtCreateRenderContext(win32evtlog.EvtRenderContextSystem)
18
+
19
+ for i, event in enumerate(events, 1):
20
+ result = win32evtlog.EvtRender(
21
+ event, win32evtlog.EvtRenderEventValues, Context=context
22
+ )
23
+
24
+ print(f"Event {i}")
25
+
26
+ level_value, level_variant = result[win32evtlog.EvtSystemLevel]
27
+ if level_variant != win32evtlog.EvtVarTypeNull:
28
+ if level_value == 1:
29
+ print(" Level: CRITICAL")
30
+ elif level_value == 2:
31
+ print(" Level: ERROR")
32
+ elif level_value == 3:
33
+ print(" Level: WARNING")
34
+ elif level_value == 4:
35
+ print(" Level: INFO")
36
+ elif level_value == 5:
37
+ print(" Level: VERBOSE")
38
+ else:
39
+ print(" Level: UNKNOWN")
40
+
41
+ time_created_value, time_created_variant = result[
42
+ win32evtlog.EvtSystemTimeCreated
43
+ ]
44
+ if time_created_variant != win32evtlog.EvtVarTypeNull:
45
+ print(f" Timestamp: {time_created_value.isoformat()}")
46
+
47
+ computer_value, computer_variant = result[win32evtlog.EvtSystemComputer]
48
+ if computer_variant != win32evtlog.EvtVarTypeNull:
49
+ print(f" FQDN: {computer_value}")
50
+
51
+ provider_name_value, provider_name_variant = result[
52
+ win32evtlog.EvtSystemProviderName
53
+ ]
54
+ if provider_name_variant != win32evtlog.EvtVarTypeNull:
55
+ print(f" Provider: {provider_name_value}")
56
+
57
+ try:
58
+ metadata = win32evtlog.EvtOpenPublisherMetadata(provider_name_value)
59
+ # pywintypes.error: (2, 'EvtOpenPublisherMetadata', 'The system cannot find the file specified.')
60
+ except Exception:
61
+ pass
62
+ else:
63
+ try:
64
+ message = win32evtlog.EvtFormatMessage(
65
+ metadata, event, win32evtlog.EvtFormatMessageEvent
66
+ )
67
+ # pywintypes.error: (15027, 'EvtFormatMessage: allocated 0, need buffer of size 0', 'The message resource is present but the message was not found in the message table.')
68
+ except Exception:
69
+ pass
70
+ else:
71
+ try:
72
+ print(f" Message: {message}")
73
+ except UnicodeEncodeError:
74
+ # Obscure error when run under subprocess.Popen(), presumably due to
75
+ # not knowing the correct encoding for the console.
76
+ # > UnicodeEncodeError: \'charmap\' codec can\'t encode character \'\\u200e\' in position 57: character maps to <undefined>\r\n'
77
+ # Can't reproduce when running manually, so it seems more a subprocess.Popen()
78
+ # than ours:
79
+ print(f" Failed to decode: {message!r}")
80
+
81
+
82
+ if __name__ == "__main__":
83
+ main()
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/EvtSubscribe_pull.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Demonstrates how to create a "pull" subscription
2
+ import win32con
3
+ import win32event
4
+ import win32evtlog
5
+
6
+ query_text = '*[System[Provider[@Name="Microsoft-Windows-Winlogon"]]]'
7
+
8
+ h = win32event.CreateEvent(None, 0, 0, None)
9
+ s = win32evtlog.EvtSubscribe(
10
+ "System",
11
+ win32evtlog.EvtSubscribeStartAtOldestRecord,
12
+ SignalEvent=h,
13
+ Query=query_text,
14
+ )
15
+
16
+ while 1:
17
+ while 1:
18
+ events = win32evtlog.EvtNext(s, 10)
19
+ if len(events) == 0:
20
+ break
21
+ ##for event in events:
22
+ ## print(win32evtlog.EvtRender(event, win32evtlog.EvtRenderEventXml))
23
+ print("retrieved %s events" % len(events))
24
+ while 1:
25
+ print("waiting...")
26
+ w = win32event.WaitForSingleObjectEx(h, 2000, True)
27
+ if w == win32con.WAIT_OBJECT_0:
28
+ break
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/EvtSubscribe_push.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Demonstrates a "push" subscription with a callback function
2
+ from __future__ import annotations
3
+
4
+ from time import sleep
5
+
6
+ import win32evtlog
7
+
8
+ query_text = '*[System[Provider[@Name="Microsoft-Windows-Winlogon"]]]'
9
+
10
+
11
+ def c(reason, context, evt):
12
+ if reason == win32evtlog.EvtSubscribeActionError:
13
+ print("EvtSubscribeActionError")
14
+ elif reason == win32evtlog.EvtSubscribeActionDeliver:
15
+ print("EvtSubscribeActionDeliver")
16
+ else:
17
+ print("??? Unknown action ???", reason)
18
+ context.append(win32evtlog.EvtRender(evt, win32evtlog.EvtRenderEventXml))
19
+ return 0
20
+
21
+
22
+ evttext: list[str] = []
23
+ s = win32evtlog.EvtSubscribe(
24
+ "System",
25
+ win32evtlog.EvtSubscribeStartAtOldestRecord,
26
+ Query="*",
27
+ Callback=c,
28
+ Context=evttext,
29
+ )
30
+
31
+ sleep(0.001)
32
+ print("\n".join(evttext))
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/FileSecurityTest.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Contributed by Kelly Kranabetter.
2
+ import os
3
+ import sys
4
+
5
+ import ntsecuritycon
6
+ import pywintypes
7
+ import win32security
8
+ import winerror
9
+
10
+ # get security information
11
+ # name=r"c:\autoexec.bat"
12
+ # name= r"g:\!workgrp\lim"
13
+ name = sys.argv[0]
14
+
15
+ if not os.path.exists(name):
16
+ print(name, "does not exist!")
17
+ sys.exit()
18
+
19
+ print("On file ", name, "\n")
20
+
21
+ # get owner SID
22
+ print("OWNER")
23
+ try:
24
+ sd = win32security.GetFileSecurity(name, win32security.OWNER_SECURITY_INFORMATION)
25
+ sid = sd.GetSecurityDescriptorOwner()
26
+ print(" ", win32security.LookupAccountSid(None, sid))
27
+ except pywintypes.error as exc:
28
+ # in automation and network shares we see:
29
+ # pywintypes.error: (1332, 'LookupAccountName', 'No mapping between account names and security IDs was done.')
30
+ if exc.winerror != winerror.ERROR_NONE_MAPPED:
31
+ raise
32
+ print("No owner information is available")
33
+
34
+ # get group SID
35
+ try:
36
+ print("GROUP")
37
+ sd = win32security.GetFileSecurity(name, win32security.GROUP_SECURITY_INFORMATION)
38
+ sid = sd.GetSecurityDescriptorGroup()
39
+ print(" ", win32security.LookupAccountSid(None, sid))
40
+ except pywintypes.error as exc:
41
+ if exc.winerror != winerror.ERROR_NONE_MAPPED:
42
+ raise
43
+ print("No group information is available")
44
+
45
+ # get ACEs
46
+ sd = win32security.GetFileSecurity(name, win32security.DACL_SECURITY_INFORMATION)
47
+ dacl = sd.GetSecurityDescriptorDacl()
48
+ if dacl is None:
49
+ print("No Discretionary ACL")
50
+ else:
51
+ for ace_no in range(0, dacl.GetAceCount()):
52
+ ace = dacl.GetAce(ace_no)
53
+ print("ACE", ace_no)
54
+
55
+ print(" -Type")
56
+ for i in (
57
+ "ACCESS_ALLOWED_ACE_TYPE",
58
+ "ACCESS_DENIED_ACE_TYPE",
59
+ "SYSTEM_AUDIT_ACE_TYPE",
60
+ "SYSTEM_ALARM_ACE_TYPE",
61
+ ):
62
+ if getattr(ntsecuritycon, i) == ace[0][0]:
63
+ print(" ", i)
64
+
65
+ print(" -Flags", hex(ace[0][1]))
66
+ for i in (
67
+ "OBJECT_INHERIT_ACE",
68
+ "CONTAINER_INHERIT_ACE",
69
+ "NO_PROPAGATE_INHERIT_ACE",
70
+ "INHERIT_ONLY_ACE",
71
+ "SUCCESSFUL_ACCESS_ACE_FLAG",
72
+ "FAILED_ACCESS_ACE_FLAG",
73
+ ):
74
+ if getattr(ntsecuritycon, i) & ace[0][1] == getattr(ntsecuritycon, i):
75
+ print(" ", i)
76
+
77
+ print(" -mask", hex(ace[1]))
78
+
79
+ # files and directories do permissions differently
80
+ permissions_file = (
81
+ "DELETE",
82
+ "READ_CONTROL",
83
+ "WRITE_DAC",
84
+ "WRITE_OWNER",
85
+ "SYNCHRONIZE",
86
+ "FILE_GENERIC_READ",
87
+ "FILE_GENERIC_WRITE",
88
+ "FILE_GENERIC_EXECUTE",
89
+ "FILE_DELETE_CHILD",
90
+ )
91
+ permissions_dir = (
92
+ "DELETE",
93
+ "READ_CONTROL",
94
+ "WRITE_DAC",
95
+ "WRITE_OWNER",
96
+ "SYNCHRONIZE",
97
+ "FILE_ADD_SUBDIRECTORY",
98
+ "FILE_ADD_FILE",
99
+ "FILE_DELETE_CHILD",
100
+ "FILE_LIST_DIRECTORY",
101
+ "FILE_TRAVERSE",
102
+ "FILE_READ_ATTRIBUTES",
103
+ "FILE_WRITE_ATTRIBUTES",
104
+ "FILE_READ_EA",
105
+ "FILE_WRITE_EA",
106
+ )
107
+ permissions_dir_inherit = (
108
+ "DELETE",
109
+ "READ_CONTROL",
110
+ "WRITE_DAC",
111
+ "WRITE_OWNER",
112
+ "SYNCHRONIZE",
113
+ "GENERIC_READ",
114
+ "GENERIC_WRITE",
115
+ "GENERIC_EXECUTE",
116
+ "GENERIC_ALL",
117
+ )
118
+ if os.path.isfile(name):
119
+ permissions = permissions_file
120
+ else:
121
+ permissions = permissions_dir
122
+ # directories also contain an ACE that is inherited by children (files) within them
123
+ if (
124
+ ace[0][1] & ntsecuritycon.OBJECT_INHERIT_ACE
125
+ == ntsecuritycon.OBJECT_INHERIT_ACE
126
+ and ace[0][1] & ntsecuritycon.INHERIT_ONLY_ACE
127
+ == ntsecuritycon.INHERIT_ONLY_ACE
128
+ ):
129
+ permissions = permissions_dir_inherit
130
+
131
+ calc_mask = 0 # calculate the mask so we can see if we are printing all of the permissions
132
+ for i in permissions:
133
+ if getattr(ntsecuritycon, i) & ace[1] == getattr(ntsecuritycon, i):
134
+ calc_mask |= getattr(ntsecuritycon, i)
135
+ print(" ", i)
136
+ print(" ", "Calculated Check Mask=", hex(calc_mask))
137
+ print(" -SID\n ", win32security.LookupAccountSid(None, ace[2]))
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/GetSaveFileName.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import win32con
4
+ import win32gui
5
+
6
+ filter = "Python Scripts\0*.py;*.pyw;*.pys\0Text files\0*.txt\0"
7
+ customfilter = "Other file types\0*.*\0"
8
+
9
+ fname, customfilter, flags = win32gui.GetSaveFileNameW(
10
+ InitialDir=os.environ["temp"],
11
+ Flags=win32con.OFN_ALLOWMULTISELECT | win32con.OFN_EXPLORER,
12
+ File="somefilename",
13
+ DefExt="py",
14
+ Title="GetSaveFileNameW",
15
+ Filter=filter,
16
+ CustomFilter=customfilter,
17
+ FilterIndex=1,
18
+ )
19
+
20
+ print(f"save file names: {fname!r}")
21
+ print(f"filter used: {customfilter!r}")
22
+ print(f"Flags: {flags}")
23
+ for k, v in win32con.__dict__.items():
24
+ if k.startswith("OFN_") and flags & v:
25
+ print("\t" + k)
26
+
27
+ fname, customfilter, flags = win32gui.GetOpenFileNameW(
28
+ InitialDir=os.environ["temp"],
29
+ Flags=win32con.OFN_ALLOWMULTISELECT | win32con.OFN_EXPLORER,
30
+ File="somefilename",
31
+ DefExt="py",
32
+ Title="GetOpenFileNameW",
33
+ Filter=filter,
34
+ CustomFilter=customfilter,
35
+ FilterIndex=0,
36
+ )
37
+
38
+ print(f"open file names: {fname!r}")
39
+ print(f"filter used: {customfilter!r}")
40
+ print(f"Flags: {flags}")
41
+ for k, v in win32con.__dict__.items():
42
+ if k.startswith("OFN_") and flags & v:
43
+ print("\t" + k)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/NetValidatePasswordPolicy.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """A demo of using win32net.NetValidatePasswordPolicy.
2
+
3
+ Example usage:
4
+
5
+ % NetValidatePasswordPolicy.py --password=foo change
6
+ which might return:
7
+
8
+ > Result of 'change' validation is 0: The operation completed successfully.
9
+
10
+ or depending on the policy:
11
+
12
+ > Result of 'change' validation is 2245: The password does not meet the
13
+ > password policy requirements. Check the minimum password length,
14
+ > password complexity and password history requirements.
15
+
16
+ Adding --user doesn't seem to change the output (even the PasswordLastSet seen
17
+ when '-f' is used doesn't depend on the username), but theoretically it will
18
+ also check the password history for the specified user.
19
+
20
+ % NetValidatePasswordPolicy.py auth
21
+
22
+ which always (with and without '-m') seems to return:
23
+
24
+ > Result of 'auth' validation is 2701: Password must change at next logon
25
+ """
26
+
27
+ import optparse
28
+ import sys
29
+ from pprint import pprint
30
+
31
+ import win32api
32
+ import win32net
33
+ import win32netcon
34
+
35
+
36
+ def main():
37
+ parser = optparse.OptionParser(
38
+ "%prog [options] auth|change ...",
39
+ description="A win32net.NetValidatePasswordPolicy demo.",
40
+ )
41
+
42
+ parser.add_option(
43
+ "-u",
44
+ "--username",
45
+ action="store",
46
+ help="The username to pass to the function (only for the 'change' command)",
47
+ )
48
+
49
+ parser.add_option(
50
+ "-p",
51
+ "--password",
52
+ action="store",
53
+ help="The clear-text password to pass to the function "
54
+ "(only for the 'change' command)",
55
+ )
56
+
57
+ parser.add_option(
58
+ "-m",
59
+ "--password-matched",
60
+ action="store_false",
61
+ default=True,
62
+ help="Used to specify the password does NOT match (ie, "
63
+ "uses False for the PasswordMatch/PasswordMatched "
64
+ "arg, both 'auth' and 'change' commands)",
65
+ )
66
+
67
+ parser.add_option(
68
+ "-s",
69
+ "--server",
70
+ action="store",
71
+ help="The name of the server to execute the command on",
72
+ )
73
+
74
+ parser.add_option(
75
+ "-f",
76
+ "--show_fields",
77
+ action="store_true",
78
+ default=False,
79
+ help="Print the NET_VALIDATE_PERSISTED_FIELDS returned",
80
+ )
81
+
82
+ options, args = parser.parse_args()
83
+
84
+ if not args:
85
+ args = ["auth"]
86
+
87
+ for arg in args:
88
+ if arg == "auth":
89
+ input = {
90
+ "PasswordMatched": options.password_matched,
91
+ }
92
+ val_type = win32netcon.NetValidateAuthentication
93
+ elif arg == "change":
94
+ input = {
95
+ "ClearPassword": options.password,
96
+ "PasswordMatch": options.password_matched,
97
+ "UserAccountName": options.username,
98
+ }
99
+ val_type = win32netcon.NetValidatePasswordChange
100
+ else:
101
+ parser.error("Invalid arg - must be 'auth' or 'change'")
102
+
103
+ try:
104
+ fields, status = win32net.NetValidatePasswordPolicy(
105
+ options.server, None, val_type, input
106
+ )
107
+ except NotImplementedError:
108
+ print("NetValidatePasswordPolicy not implemented on this platform.")
109
+ return 1
110
+ except win32net.error as exc:
111
+ print("NetValidatePasswordPolicy failed: ", exc)
112
+ return 1
113
+
114
+ if options.show_fields:
115
+ print("NET_VALIDATE_PERSISTED_FIELDS fields:")
116
+ pprint(fields)
117
+
118
+ print(
119
+ "Result of %r validation is %d: %s"
120
+ % (arg, status, win32api.FormatMessage(status).strip())
121
+ )
122
+
123
+ return 0
124
+
125
+
126
+ if __name__ == "__main__":
127
+ sys.exit(main())
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/OpenEncryptedFileRaw.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import win32api
4
+ import win32file
5
+ import winerror
6
+
7
+
8
+ def ReadCallback(input_buffer, data, buflen):
9
+ fnamein, fnameout, f = data
10
+ # print(fnamein, fnameout, buflen)
11
+ f.write(input_buffer)
12
+ return winerror.ERROR_SUCCESS
13
+
14
+
15
+ def WriteCallback(output_buffer, data, buflen):
16
+ fnamebackup, fnameout, f = data
17
+ file_data = f.read(buflen)
18
+ ## returning 0 as len terminates WriteEncryptedFileRaw
19
+ output_len = len(file_data)
20
+ output_buffer[:output_len] = file_data
21
+ return winerror.ERROR_SUCCESS, output_len
22
+
23
+
24
+ tmp_dir = win32api.GetTempPath()
25
+ dst_dir = win32api.GetTempFileName(tmp_dir, "oef")[0]
26
+ os.remove(dst_dir)
27
+ os.mkdir(dst_dir)
28
+ print("Destination dir:", dst_dir)
29
+
30
+ ## create an encrypted file
31
+ fname = win32api.GetTempFileName(dst_dir, "ref")[0]
32
+ print("orig file:", fname)
33
+ f = open(fname, "w")
34
+ f.write("xxxxxxxxxxxxxxxx\n" * 32768)
35
+ f.close()
36
+ ## add a couple of extra data streams
37
+ f = open(fname + ":stream_y", "w")
38
+ f.write("yyyyyyyyyyyyyyyy\n" * 32768)
39
+ f.close()
40
+ f = open(fname + ":stream_z", "w")
41
+ f.write("zzzzzzzzzzzzzzzz\n" * 32768)
42
+ f.close()
43
+ win32file.EncryptFile(fname)
44
+
45
+ ## backup raw data of encrypted file
46
+ bkup_fname = win32api.GetTempFileName(dst_dir, "bef")[0]
47
+ print("backup file:", bkup_fname)
48
+ f = open(bkup_fname, "wb")
49
+ ctxt = win32file.OpenEncryptedFileRaw(fname, 0)
50
+ try:
51
+ win32file.ReadEncryptedFileRaw(ReadCallback, (fname, bkup_fname, f), ctxt)
52
+ finally:
53
+ ## if context is not closed, file remains locked even if calling process is killed
54
+ win32file.CloseEncryptedFileRaw(ctxt)
55
+ f.close()
56
+
57
+ ## restore data from backup to new encrypted file
58
+ dst_fname = win32api.GetTempFileName(dst_dir, "wef")[0]
59
+ print("restored file:", dst_fname)
60
+ f = open(bkup_fname, "rb")
61
+ ctxtout = win32file.OpenEncryptedFileRaw(dst_fname, win32file.CREATE_FOR_IMPORT)
62
+ try:
63
+ win32file.WriteEncryptedFileRaw(WriteCallback, (bkup_fname, dst_fname, f), ctxtout)
64
+ finally:
65
+ win32file.CloseEncryptedFileRaw(ctxtout)
66
+ f.close()
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/RegCreateKeyTransacted.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32api
2
+ import win32con
3
+ import win32transaction
4
+
5
+ keyname = "Pywin32 test transacted registry functions"
6
+ subkeyname = "test transacted subkey"
7
+ classname = "Transacted Class"
8
+
9
+ trans = win32transaction.CreateTransaction(Description="test RegCreateKeyTransacted")
10
+ key, disp = win32api.RegCreateKeyEx(
11
+ win32con.HKEY_CURRENT_USER,
12
+ keyname,
13
+ samDesired=win32con.KEY_ALL_ACCESS,
14
+ Class=classname,
15
+ )
16
+ ## clean up any existing keys
17
+ for subk in win32api.RegEnumKeyExW(key):
18
+ win32api.RegDeleteKey(key, subk[0])
19
+
20
+ ## reopen key in transacted mode
21
+ transacted_key = win32api.RegOpenKeyTransacted(
22
+ Key=win32con.HKEY_CURRENT_USER,
23
+ SubKey=keyname,
24
+ Transaction=trans,
25
+ samDesired=win32con.KEY_ALL_ACCESS,
26
+ )
27
+ subkey, disp = win32api.RegCreateKeyEx(
28
+ transacted_key,
29
+ subkeyname,
30
+ Transaction=trans,
31
+ samDesired=win32con.KEY_ALL_ACCESS,
32
+ Class=classname,
33
+ )
34
+
35
+ ## Newly created key should not be visible from non-transacted handle
36
+ subkeys = [s[0] for s in win32api.RegEnumKeyExW(key)]
37
+ assert subkeyname not in subkeys
38
+
39
+ transacted_subkeys = [s[0] for s in win32api.RegEnumKeyExW(transacted_key)]
40
+ assert subkeyname in transacted_subkeys
41
+
42
+ ## Key should be visible to non-transacted handle after commit
43
+ win32transaction.CommitTransaction(trans)
44
+ subkeys = [s[0] for s in win32api.RegEnumKeyExW(key)]
45
+ assert subkeyname in subkeys
46
+
47
+ ## test transacted delete
48
+ del_trans = win32transaction.CreateTransaction(
49
+ Description="test RegDeleteKeyTransacted"
50
+ )
51
+ win32api.RegDeleteKeyEx(key, subkeyname, Transaction=del_trans)
52
+ ## subkey should still show up for non-transacted handle
53
+ subkeys = [s[0] for s in win32api.RegEnumKeyExW(key)]
54
+ assert subkeyname in subkeys
55
+ ## ... and should be gone after commit
56
+ win32transaction.CommitTransaction(del_trans)
57
+ subkeys = [s[0] for s in win32api.RegEnumKeyExW(key)]
58
+ assert subkeyname not in subkeys
59
+
60
+ win32api.RegDeleteKey(win32con.HKEY_CURRENT_USER, keyname)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/RegRestoreKey.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import ntsecuritycon
4
+ import win32api
5
+ import win32con
6
+ import win32security
7
+ import winnt
8
+
9
+ temp_dir = win32api.GetTempPath()
10
+ fname = win32api.GetTempFileName(temp_dir, "rsk")[0]
11
+ print(fname)
12
+ ## file can't exist
13
+ os.remove(fname)
14
+
15
+ ## enable backup and restore privs
16
+ required_privs = (
17
+ (
18
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_BACKUP_NAME),
19
+ win32con.SE_PRIVILEGE_ENABLED,
20
+ ),
21
+ (
22
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_RESTORE_NAME),
23
+ win32con.SE_PRIVILEGE_ENABLED,
24
+ ),
25
+ )
26
+ ph = win32api.GetCurrentProcess()
27
+ th = win32security.OpenProcessToken(
28
+ ph, win32con.TOKEN_READ | win32con.TOKEN_ADJUST_PRIVILEGES
29
+ )
30
+ adjusted_privs = win32security.AdjustTokenPrivileges(th, 0, required_privs)
31
+
32
+ try:
33
+ sa = win32security.SECURITY_ATTRIBUTES()
34
+ my_sid = win32security.GetTokenInformation(th, ntsecuritycon.TokenUser)[0]
35
+ sa.SECURITY_DESCRIPTOR.SetSecurityDescriptorOwner(my_sid, 0)
36
+
37
+ k, disp = win32api.RegCreateKeyEx(
38
+ win32con.HKEY_CURRENT_USER,
39
+ "Python test key",
40
+ SecurityAttributes=sa,
41
+ samDesired=win32con.KEY_ALL_ACCESS,
42
+ Class="some class",
43
+ Options=0,
44
+ )
45
+ win32api.RegSetValue(k, None, win32con.REG_SZ, "Default value for python test key")
46
+
47
+ subk, disp = win32api.RegCreateKeyEx(
48
+ k,
49
+ "python test subkey",
50
+ SecurityAttributes=sa,
51
+ samDesired=win32con.KEY_ALL_ACCESS,
52
+ Class="some other class",
53
+ Options=0,
54
+ )
55
+ win32api.RegSetValue(subk, None, win32con.REG_SZ, "Default value for subkey")
56
+
57
+ win32api.RegSaveKeyEx(
58
+ k, fname, Flags=winnt.REG_STANDARD_FORMAT, SecurityAttributes=sa
59
+ )
60
+
61
+ restored_key, disp = win32api.RegCreateKeyEx(
62
+ win32con.HKEY_CURRENT_USER,
63
+ "Python test key(restored)",
64
+ SecurityAttributes=sa,
65
+ samDesired=win32con.KEY_ALL_ACCESS,
66
+ Class="restored class",
67
+ Options=0,
68
+ )
69
+ win32api.RegRestoreKey(restored_key, fname)
70
+ finally:
71
+ win32security.AdjustTokenPrivileges(th, 0, adjusted_privs)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/SystemParametersInfo.py ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import glob
2
+ import os
3
+ import time
4
+
5
+ import win32api
6
+ import win32con
7
+ import win32gui
8
+
9
+ ## some of these tests will fail for systems prior to XP
10
+
11
+ for pname in (
12
+ ## Set actions all take an unsigned int in pvParam
13
+ "SPI_GETMOUSESPEED",
14
+ "SPI_GETACTIVEWNDTRKTIMEOUT",
15
+ "SPI_GETCARETWIDTH",
16
+ "SPI_GETFOREGROUNDFLASHCOUNT",
17
+ "SPI_GETFOREGROUNDLOCKTIMEOUT",
18
+ ## Set actions all take an unsigned int in uiParam
19
+ "SPI_GETWHEELSCROLLLINES",
20
+ "SPI_GETKEYBOARDDELAY",
21
+ "SPI_GETKEYBOARDSPEED",
22
+ "SPI_GETMOUSEHOVERHEIGHT",
23
+ "SPI_GETMOUSEHOVERWIDTH",
24
+ "SPI_GETMOUSEHOVERTIME",
25
+ "SPI_GETSCREENSAVETIMEOUT",
26
+ "SPI_GETMENUSHOWDELAY",
27
+ "SPI_GETLOWPOWERTIMEOUT",
28
+ "SPI_GETPOWEROFFTIMEOUT",
29
+ "SPI_GETBORDER",
30
+ ## below are winxp only:
31
+ "SPI_GETFONTSMOOTHINGCONTRAST",
32
+ "SPI_GETFONTSMOOTHINGTYPE",
33
+ "SPI_GETFOCUSBORDERHEIGHT",
34
+ "SPI_GETFOCUSBORDERWIDTH",
35
+ "SPI_GETMOUSECLICKLOCKTIME",
36
+ ):
37
+ print(pname)
38
+ cget = getattr(win32con, pname)
39
+ cset = getattr(win32con, pname.replace("_GET", "_SET"))
40
+ orig_value = win32gui.SystemParametersInfo(cget)
41
+ print("\toriginal setting:", orig_value)
42
+ win32gui.SystemParametersInfo(cset, orig_value + 1)
43
+ new_value = win32gui.SystemParametersInfo(cget)
44
+ print("\tnew value:", new_value)
45
+ # On Vista, some of these values seem to be ignored. So only "fail" if
46
+ # the new value isn't what we set or the original
47
+ if new_value != orig_value + 1:
48
+ assert new_value == orig_value
49
+ print(f"Strange - setting {pname} seems to have been ignored")
50
+ win32gui.SystemParametersInfo(cset, orig_value)
51
+ assert win32gui.SystemParametersInfo(cget) == orig_value
52
+
53
+
54
+ # these take a boolean value in pvParam
55
+ # change to opposite, check that it was changed and change back
56
+ for pname in (
57
+ "SPI_GETFLATMENU",
58
+ "SPI_GETDROPSHADOW",
59
+ "SPI_GETKEYBOARDCUES",
60
+ "SPI_GETMENUFADE",
61
+ "SPI_GETCOMBOBOXANIMATION",
62
+ "SPI_GETCURSORSHADOW",
63
+ "SPI_GETGRADIENTCAPTIONS",
64
+ "SPI_GETHOTTRACKING",
65
+ "SPI_GETLISTBOXSMOOTHSCROLLING",
66
+ "SPI_GETMENUANIMATION",
67
+ "SPI_GETSELECTIONFADE",
68
+ "SPI_GETTOOLTIPANIMATION",
69
+ "SPI_GETTOOLTIPFADE",
70
+ "SPI_GETUIEFFECTS",
71
+ "SPI_GETACTIVEWINDOWTRACKING",
72
+ "SPI_GETACTIVEWNDTRKZORDER",
73
+ ):
74
+ print(pname)
75
+ cget = getattr(win32con, pname)
76
+ cset = getattr(win32con, pname.replace("_GET", "_SET"))
77
+ orig_value = win32gui.SystemParametersInfo(cget)
78
+ print(orig_value)
79
+ win32gui.SystemParametersInfo(cset, not orig_value)
80
+ new_value = win32gui.SystemParametersInfo(cget)
81
+ print(new_value)
82
+ assert orig_value != new_value
83
+ win32gui.SystemParametersInfo(cset, orig_value)
84
+ assert win32gui.SystemParametersInfo(cget) == orig_value
85
+
86
+
87
+ # these take a boolean in uiParam
88
+ # could combine with above section now that SystemParametersInfo only takes a single parameter
89
+ for pname in (
90
+ "SPI_GETFONTSMOOTHING",
91
+ "SPI_GETICONTITLEWRAP",
92
+ "SPI_GETBEEP",
93
+ "SPI_GETBLOCKSENDINPUTRESETS",
94
+ "SPI_GETKEYBOARDPREF",
95
+ "SPI_GETSCREENSAVEACTIVE",
96
+ "SPI_GETMENUDROPALIGNMENT",
97
+ "SPI_GETDRAGFULLWINDOWS",
98
+ "SPI_GETSHOWIMEUI",
99
+ ):
100
+ cget = getattr(win32con, pname)
101
+ cset = getattr(win32con, pname.replace("_GET", "_SET"))
102
+ orig_value = win32gui.SystemParametersInfo(cget)
103
+ win32gui.SystemParametersInfo(cset, not orig_value)
104
+ new_value = win32gui.SystemParametersInfo(cget)
105
+ # Some of these also can't be changed (eg, SPI_GETSCREENSAVEACTIVE) so
106
+ # don't actually get upset.
107
+ if orig_value != new_value:
108
+ print("successfully toggled", pname, "from", orig_value, "to", new_value)
109
+ else:
110
+ print("couldn't toggle", pname, "from", orig_value)
111
+ win32gui.SystemParametersInfo(cset, orig_value)
112
+ assert win32gui.SystemParametersInfo(cget) == orig_value
113
+
114
+
115
+ print("SPI_GETICONTITLELOGFONT")
116
+ lf = win32gui.SystemParametersInfo(win32con.SPI_GETICONTITLELOGFONT)
117
+ orig_height = lf.lfHeight
118
+ orig_italic = lf.lfItalic
119
+ print("Height:", orig_height, "Italic:", orig_italic)
120
+ lf.lfHeight += 2
121
+ lf.lfItalic = not lf.lfItalic
122
+ win32gui.SystemParametersInfo(win32con.SPI_SETICONTITLELOGFONT, lf)
123
+ new_lf = win32gui.SystemParametersInfo(win32con.SPI_GETICONTITLELOGFONT)
124
+ print("New Height:", new_lf.lfHeight, "New Italic:", new_lf.lfItalic)
125
+ assert new_lf.lfHeight == orig_height + 2
126
+ assert new_lf.lfItalic != orig_italic
127
+
128
+ lf.lfHeight = orig_height
129
+ lf.lfItalic = orig_italic
130
+ win32gui.SystemParametersInfo(win32con.SPI_SETICONTITLELOGFONT, lf)
131
+ new_lf = win32gui.SystemParametersInfo(win32con.SPI_GETICONTITLELOGFONT)
132
+ assert new_lf.lfHeight == orig_height
133
+ assert new_lf.lfItalic == orig_italic
134
+
135
+
136
+ print("SPI_GETMOUSEHOVERWIDTH, SPI_GETMOUSEHOVERHEIGHT, SPI_GETMOUSEHOVERTIME")
137
+ w = win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERWIDTH)
138
+ h = win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERHEIGHT)
139
+ t = win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERTIME)
140
+ print("w,h,t:", w, h, t)
141
+
142
+ win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERWIDTH, w + 1)
143
+ win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERHEIGHT, h + 2)
144
+ win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERTIME, t + 3)
145
+ new_w = win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERWIDTH)
146
+ new_h = win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERHEIGHT)
147
+ new_t = win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERTIME)
148
+ print("new w,h,t:", new_w, new_h, new_t)
149
+ assert new_w == w + 1
150
+ assert new_h == h + 2
151
+ assert new_t == t + 3
152
+
153
+ win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERWIDTH, w)
154
+ win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERHEIGHT, h)
155
+ win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERTIME, t)
156
+ new_w = win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERWIDTH)
157
+ new_h = win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERHEIGHT)
158
+ new_t = win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERTIME)
159
+ assert new_w == w
160
+ assert new_h == h
161
+ assert new_t == t
162
+
163
+
164
+ print("SPI_SETDOUBLECLKWIDTH, SPI_SETDOUBLECLKHEIGHT")
165
+ x = win32api.GetSystemMetrics(win32con.SM_CXDOUBLECLK)
166
+ y = win32api.GetSystemMetrics(win32con.SM_CYDOUBLECLK)
167
+ print("x,y:", x, y)
168
+ win32gui.SystemParametersInfo(win32con.SPI_SETDOUBLECLKWIDTH, x + 1)
169
+ win32gui.SystemParametersInfo(win32con.SPI_SETDOUBLECLKHEIGHT, y + 2)
170
+ new_x = win32api.GetSystemMetrics(win32con.SM_CXDOUBLECLK)
171
+ new_y = win32api.GetSystemMetrics(win32con.SM_CYDOUBLECLK)
172
+ print("new x,y:", new_x, new_y)
173
+ assert new_x == x + 1
174
+ assert new_y == y + 2
175
+ win32gui.SystemParametersInfo(win32con.SPI_SETDOUBLECLKWIDTH, x)
176
+ win32gui.SystemParametersInfo(win32con.SPI_SETDOUBLECLKHEIGHT, y)
177
+ new_x = win32api.GetSystemMetrics(win32con.SM_CXDOUBLECLK)
178
+ new_y = win32api.GetSystemMetrics(win32con.SM_CYDOUBLECLK)
179
+ assert new_x == x
180
+ assert new_y == y
181
+
182
+
183
+ print("SPI_SETDRAGWIDTH, SPI_SETDRAGHEIGHT")
184
+ dw = win32api.GetSystemMetrics(win32con.SM_CXDRAG)
185
+ dh = win32api.GetSystemMetrics(win32con.SM_CYDRAG)
186
+ print("dw,dh:", dw, dh)
187
+ win32gui.SystemParametersInfo(win32con.SPI_SETDRAGWIDTH, dw + 1)
188
+ win32gui.SystemParametersInfo(win32con.SPI_SETDRAGHEIGHT, dh + 2)
189
+ new_dw = win32api.GetSystemMetrics(win32con.SM_CXDRAG)
190
+ new_dh = win32api.GetSystemMetrics(win32con.SM_CYDRAG)
191
+ print("new dw,dh:", new_dw, new_dh)
192
+ assert new_dw == dw + 1
193
+ assert new_dh == dh + 2
194
+ win32gui.SystemParametersInfo(win32con.SPI_SETDRAGWIDTH, dw)
195
+ win32gui.SystemParametersInfo(win32con.SPI_SETDRAGHEIGHT, dh)
196
+ new_dw = win32api.GetSystemMetrics(win32con.SM_CXDRAG)
197
+ new_dh = win32api.GetSystemMetrics(win32con.SM_CYDRAG)
198
+ assert new_dw == dw
199
+ assert new_dh == dh
200
+
201
+
202
+ orig_wallpaper = win32gui.SystemParametersInfo(Action=win32con.SPI_GETDESKWALLPAPER)
203
+ print("Original: ", orig_wallpaper)
204
+ for bmp in glob.glob(os.path.join(os.environ["windir"], "*.bmp")):
205
+ print(bmp)
206
+ win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, Param=bmp)
207
+ print(win32gui.SystemParametersInfo(Action=win32con.SPI_GETDESKWALLPAPER))
208
+ time.sleep(1)
209
+
210
+ win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, Param=orig_wallpaper)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/c_extension/setup.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # A sample distutils script to show to build your own
2
+ # extension module which extends pywintypes or pythoncom.
3
+ #
4
+ # Use 'python -m build' to build this extension.
5
+ import os
6
+ from setuptools import Extension, setup
7
+ from sysconfig import get_paths
8
+
9
+ sources = ["win32_extension.cpp"]
10
+ lib_dir = get_paths()["platlib"]
11
+
12
+ # Specify the directory where the PyWin32 .h and .lib files are installed.
13
+ # If you are doing a win32com extension, you will also need to add
14
+ # win32com\Include and win32com\Libs.
15
+ ext = Extension(
16
+ "win32_extension",
17
+ sources,
18
+ include_dirs=[os.path.join(lib_dir, "win32", "include")],
19
+ library_dirs=[os.path.join(lib_dir, "win32", "libs")],
20
+ )
21
+
22
+ setup(
23
+ name="win32 extension sample",
24
+ version="0.1",
25
+ ext_modules=[ext],
26
+ )
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/dde/ddeclient.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 'Request' example added jjk 11/20/98
2
+
3
+ import win32ui # isort: skip # Must be imported before dde !
4
+ import dde
5
+
6
+ server = dde.CreateServer()
7
+ server.Create("TestClient")
8
+
9
+ conversation = dde.CreateConversation(server)
10
+
11
+ conversation.ConnectTo("RunAny", "RunAnyCommand")
12
+ conversation.Exec("DoSomething")
13
+ conversation.Exec("DoSomethingElse")
14
+
15
+ conversation.ConnectTo("RunAny", "ComputeStringLength")
16
+ s = "abcdefghi"
17
+ sl = conversation.Request(s)
18
+ print(f'length of "{s}" is {sl}')
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/dde/ddeserver.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 'Request' example added jjk 11/20/98
2
+
3
+ import win32ui # isort: skip # Must be imported before dde !
4
+ import dde
5
+ from pywin.mfc import object
6
+
7
+
8
+ class MySystemTopic(object.Object):
9
+ def __init__(self):
10
+ object.Object.__init__(self, dde.CreateServerSystemTopic())
11
+
12
+ def Exec(self, cmd):
13
+ print("System Topic asked to exec", cmd)
14
+
15
+
16
+ class MyOtherTopic(object.Object):
17
+ def __init__(self, topicName):
18
+ object.Object.__init__(self, dde.CreateTopic(topicName))
19
+
20
+ def Exec(self, cmd):
21
+ print("Other Topic asked to exec", cmd)
22
+
23
+
24
+ class MyRequestTopic(object.Object):
25
+ def __init__(self, topicName):
26
+ topic = dde.CreateTopic(topicName)
27
+ topic.AddItem(dde.CreateStringItem(""))
28
+ object.Object.__init__(self, topic)
29
+
30
+ def Request(self, aString):
31
+ print("Request Topic asked to compute length of:", aString)
32
+ return str(len(aString))
33
+
34
+
35
+ server = dde.CreateServer()
36
+ server.AddTopic(MySystemTopic())
37
+ server.AddTopic(MyOtherTopic("RunAnyCommand"))
38
+ server.AddTopic(MyRequestTopic("ComputeStringLength"))
39
+ server.Create("RunAny")
40
+
41
+ while 1:
42
+ win32ui.PumpWaitingMessages(0, -1)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/desktopmanager.py ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Demonstrates using a taskbar icon to create and navigate between desktops
2
+
3
+ import _thread
4
+ import io
5
+ import time
6
+ import traceback
7
+
8
+ import pywintypes
9
+ import win32api
10
+ import win32con
11
+ import win32gui
12
+ import win32process
13
+ import win32service
14
+
15
+ ## "Shell_TrayWnd" is class of system tray window, broadcasts "TaskbarCreated" when initialized
16
+
17
+
18
+ def desktop_name_dlgproc(hwnd, msg, wparam, lparam):
19
+ """Handles messages from the desktop name dialog box"""
20
+ if msg in (win32con.WM_CLOSE, win32con.WM_DESTROY):
21
+ win32gui.DestroyWindow(hwnd)
22
+ elif msg == win32con.WM_COMMAND:
23
+ if wparam == win32con.IDOK:
24
+ desktop_name = win32gui.GetDlgItemText(hwnd, 72)
25
+ print("new desktop name: ", desktop_name)
26
+ win32gui.DestroyWindow(hwnd)
27
+ create_desktop(desktop_name)
28
+
29
+ elif wparam == win32con.IDCANCEL:
30
+ win32gui.DestroyWindow(hwnd)
31
+
32
+
33
+ def get_new_desktop_name(parent_hwnd):
34
+ """Create a dialog box to ask the user for name of desktop to be created"""
35
+ msgs = {
36
+ win32con.WM_COMMAND: desktop_name_dlgproc,
37
+ win32con.WM_CLOSE: desktop_name_dlgproc,
38
+ win32con.WM_DESTROY: desktop_name_dlgproc,
39
+ }
40
+ # dlg item [type, caption, id, (x,y,cx,cy), style, ex style
41
+ style = (
42
+ win32con.WS_BORDER
43
+ | win32con.WS_VISIBLE
44
+ | win32con.WS_CAPTION
45
+ | win32con.WS_SYSMENU
46
+ ) ## |win32con.DS_SYSMODAL
47
+ h = win32gui.CreateDialogIndirect(
48
+ win32api.GetModuleHandle(None),
49
+ [
50
+ ["One ugly dialog box !", (100, 100, 200, 100), style, 0],
51
+ [
52
+ "Button",
53
+ "Create",
54
+ win32con.IDOK,
55
+ (10, 10, 30, 20),
56
+ win32con.WS_VISIBLE
57
+ | win32con.WS_TABSTOP
58
+ | win32con.BS_HOLLOW
59
+ | win32con.BS_DEFPUSHBUTTON,
60
+ ],
61
+ [
62
+ "Button",
63
+ "Never mind",
64
+ win32con.IDCANCEL,
65
+ (45, 10, 50, 20),
66
+ win32con.WS_VISIBLE | win32con.WS_TABSTOP | win32con.BS_HOLLOW,
67
+ ],
68
+ ["Static", "Desktop name:", 71, (10, 40, 70, 10), win32con.WS_VISIBLE],
69
+ ["Edit", "", 72, (75, 40, 90, 10), win32con.WS_VISIBLE],
70
+ ],
71
+ parent_hwnd,
72
+ msgs,
73
+ ) ## parent_hwnd, msgs)
74
+
75
+ win32gui.EnableWindow(h, True)
76
+ hcontrol = win32gui.GetDlgItem(h, 72)
77
+ win32gui.EnableWindow(hcontrol, True)
78
+ win32gui.SetFocus(hcontrol)
79
+
80
+
81
+ def new_icon(hdesk, desktop_name):
82
+ """Runs as a thread on each desktop to create a new tray icon and handle its messages"""
83
+ global id
84
+ id += 1
85
+ hdesk.SetThreadDesktop()
86
+ ## apparently the threads can't use same hinst, so each needs its own window class
87
+ windowclassname = "PythonDesktopManager" + desktop_name
88
+ wc = win32gui.WNDCLASS()
89
+ wc.hInstance = win32api.GetModuleHandle(None)
90
+ wc.lpszClassName = windowclassname
91
+ wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW | win32con.CS_GLOBALCLASS
92
+ wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
93
+ wc.hbrBackground = win32con.COLOR_WINDOW
94
+ wc.lpfnWndProc = icon_wndproc
95
+ windowclass = win32gui.RegisterClass(wc)
96
+ style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
97
+ hwnd = win32gui.CreateWindow(
98
+ windowclass,
99
+ "dm_" + desktop_name,
100
+ win32con.WS_SYSMENU,
101
+ 0,
102
+ 0,
103
+ win32con.CW_USEDEFAULT,
104
+ win32con.CW_USEDEFAULT,
105
+ 0,
106
+ 0,
107
+ wc.hInstance,
108
+ None,
109
+ )
110
+ win32gui.UpdateWindow(hwnd)
111
+ flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
112
+ notify_info = (
113
+ hwnd,
114
+ id,
115
+ flags,
116
+ win32con.WM_USER + 20,
117
+ hicon,
118
+ "Desktop Manager (%s)" % desktop_name,
119
+ )
120
+ window_info[hwnd] = notify_info
121
+ ## wait for explorer to initialize system tray for new desktop
122
+ tray_found = 0
123
+ while not tray_found:
124
+ try:
125
+ tray_found = win32gui.FindWindow("Shell_TrayWnd", None)
126
+ except win32gui.error:
127
+ traceback.print_exc
128
+ time.sleep(0.5)
129
+ win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, notify_info)
130
+ win32gui.PumpMessages()
131
+
132
+
133
+ def create_desktop(desktop_name, start_explorer=1):
134
+ """Creates a new desktop and spawns a thread running on it
135
+ Will also start a new icon thread on an existing desktop
136
+ """
137
+ sa = pywintypes.SECURITY_ATTRIBUTES()
138
+ sa.bInheritHandle = 1
139
+
140
+ try:
141
+ hdesk = win32service.CreateDesktop(
142
+ desktop_name, 0, win32con.MAXIMUM_ALLOWED, sa
143
+ )
144
+ except win32service.error:
145
+ traceback.print_exc()
146
+ errbuf = io.StringIO()
147
+ traceback.print_exc(None, errbuf)
148
+ win32api.MessageBox(0, errbuf.getvalue(), "Desktop creation failed")
149
+ return
150
+ if start_explorer:
151
+ s = win32process.STARTUPINFO()
152
+ s.lpDesktop = desktop_name
153
+ prc_info = win32process.CreateProcess(
154
+ None,
155
+ "Explorer.exe",
156
+ None,
157
+ None,
158
+ True,
159
+ win32con.CREATE_NEW_CONSOLE,
160
+ None,
161
+ "c:\\",
162
+ s,
163
+ )
164
+
165
+ th = _thread.start_new_thread(new_icon, (hdesk, desktop_name))
166
+ hdesk.SwitchDesktop()
167
+
168
+
169
+ def icon_wndproc(hwnd, msg, wp, lp):
170
+ """Window proc for the tray icons"""
171
+ if lp == win32con.WM_LBUTTONDOWN:
172
+ ## popup menu won't disappear if you don't do this
173
+ win32gui.SetForegroundWindow(hwnd)
174
+
175
+ curr_desktop = win32service.OpenInputDesktop(0, True, win32con.MAXIMUM_ALLOWED)
176
+ curr_desktop_name = win32service.GetUserObjectInformation(
177
+ curr_desktop, win32con.UOI_NAME
178
+ )
179
+ winsta = win32service.GetProcessWindowStation()
180
+ desktops = winsta.EnumDesktops()
181
+ m = win32gui.CreatePopupMenu()
182
+ desktop_cnt = len(desktops)
183
+ ## *don't* create an item 0
184
+ for d in range(1, desktop_cnt + 1):
185
+ mf_flags = win32con.MF_STRING
186
+ ## if you switch to winlogon yourself, there's nothing there and you're stuck
187
+ if desktops[d - 1].lower() in ("winlogon", "disconnect"):
188
+ mf_flags |= win32con.MF_GRAYED | win32con.MF_DISABLED
189
+ if desktops[d - 1] == curr_desktop_name:
190
+ mf_flags |= win32con.MF_CHECKED
191
+ win32gui.AppendMenu(m, mf_flags, d, desktops[d - 1])
192
+ win32gui.AppendMenu(m, win32con.MF_STRING, desktop_cnt + 1, "Create new ...")
193
+ win32gui.AppendMenu(m, win32con.MF_STRING, desktop_cnt + 2, "Exit")
194
+
195
+ x, y = win32gui.GetCursorPos()
196
+ d = win32gui.TrackPopupMenu(
197
+ m,
198
+ win32con.TPM_LEFTBUTTON | win32con.TPM_RETURNCMD | win32con.TPM_NONOTIFY,
199
+ x,
200
+ y,
201
+ 0,
202
+ hwnd,
203
+ None,
204
+ )
205
+ win32gui.PumpWaitingMessages()
206
+ win32gui.DestroyMenu(m)
207
+ if d == desktop_cnt + 1: ## Create new
208
+ get_new_desktop_name(hwnd)
209
+ elif d == desktop_cnt + 2: ## Exit
210
+ win32gui.PostQuitMessage(0)
211
+ win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, window_info[hwnd])
212
+ del window_info[hwnd]
213
+ origin_desktop.SwitchDesktop()
214
+ elif d > 0:
215
+ hdesk = win32service.OpenDesktop(
216
+ desktops[d - 1], 0, 0, win32con.MAXIMUM_ALLOWED
217
+ )
218
+ hdesk.SwitchDesktop()
219
+ return 0
220
+ else:
221
+ return win32gui.DefWindowProc(hwnd, msg, wp, lp)
222
+
223
+
224
+ window_info = {}
225
+ origin_desktop = win32service.OpenInputDesktop(0, True, win32con.MAXIMUM_ALLOWED)
226
+ origin_desktop_name = win32service.GetUserObjectInformation(
227
+ origin_desktop, win32service.UOI_NAME
228
+ )
229
+
230
+ hinst = win32api.GetModuleHandle(None)
231
+ try:
232
+ hicon = win32gui.LoadIcon(hinst, 1) ## python.exe and pythonw.exe
233
+ except win32gui.error:
234
+ hicon = win32gui.LoadIcon(hinst, 135) ## pythonwin's icon
235
+ id = 0
236
+
237
+ create_desktop(str(origin_desktop_name), 0)
238
+
239
+ ## wait for first thread to initialize its icon
240
+ while not window_info:
241
+ time.sleep(1)
242
+
243
+ ## exit when last tray icon goes away
244
+ while window_info:
245
+ win32gui.PumpWaitingMessages()
246
+ time.sleep(3)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/eventLogDemo.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32api # To translate NT Sids to account names.
2
+ import win32con
3
+ import win32evtlog
4
+ import win32evtlogutil
5
+ import win32security
6
+
7
+
8
+ def ReadLog(computer, logType="Application", dumpEachRecord=0):
9
+ # read the entire log back.
10
+ h = win32evtlog.OpenEventLog(computer, logType)
11
+ numRecords = win32evtlog.GetNumberOfEventLogRecords(h)
12
+ # print(f"There are {numRecords} records")
13
+
14
+ num = 0
15
+ while 1:
16
+ objects = win32evtlog.ReadEventLog(
17
+ h,
18
+ win32evtlog.EVENTLOG_BACKWARDS_READ | win32evtlog.EVENTLOG_SEQUENTIAL_READ,
19
+ 0,
20
+ )
21
+ if not objects:
22
+ break
23
+ for object in objects:
24
+ # get it for testing purposes, but don't print it.
25
+ msg = win32evtlogutil.SafeFormatMessage(object, logType)
26
+ if object.Sid is not None:
27
+ try:
28
+ domain, user, typ = win32security.LookupAccountSid(
29
+ computer, object.Sid
30
+ )
31
+ sidDesc = f"{domain}/{user}"
32
+ except win32security.error:
33
+ sidDesc = str(object.Sid)
34
+ user_desc = f"Event associated with user {sidDesc}"
35
+ else:
36
+ user_desc = None
37
+ if dumpEachRecord:
38
+ print(
39
+ "Event record from {!r} generated at {}".format(
40
+ object.SourceName, object.TimeGenerated.Format()
41
+ )
42
+ )
43
+ if user_desc:
44
+ print(user_desc)
45
+ try:
46
+ print(msg)
47
+ except UnicodeError:
48
+ print("(unicode error printing message: repr() follows...)")
49
+ print(repr(msg))
50
+
51
+ num += len(objects)
52
+
53
+ if numRecords == num:
54
+ print("Successfully read all", numRecords, "records")
55
+ else:
56
+ print(
57
+ "Couldn't get all records - reported %d, but found %d" % (numRecords, num)
58
+ )
59
+ print(
60
+ "(Note that some other app may have written records while we were running!)"
61
+ )
62
+ win32evtlog.CloseEventLog(h)
63
+
64
+
65
+ def usage():
66
+ print("Writes an event to the event log.")
67
+ print("-w : Don't write any test records.")
68
+ print("-r : Don't read the event log")
69
+ print("-c : computerName : Process the log on the specified computer")
70
+ print("-v : Verbose")
71
+ print("-t : LogType - Use the specified log - default = 'Application'")
72
+
73
+
74
+ def test():
75
+ import getopt
76
+ import sys
77
+
78
+ opts, args = getopt.getopt(sys.argv[1:], "rwh?c:t:v")
79
+ computer = None
80
+ do_read = do_write = 1
81
+
82
+ logType = "Application"
83
+ verbose = 0
84
+
85
+ if len(args) > 0:
86
+ print("Invalid args")
87
+ usage()
88
+ return 1
89
+ for opt, val in opts:
90
+ if opt == "-t":
91
+ logType = val
92
+ if opt == "-c":
93
+ computer = val
94
+ if opt in ["-h", "-?"]:
95
+ usage()
96
+ return
97
+ if opt == "-r":
98
+ do_read = 0
99
+ if opt == "-w":
100
+ do_write = 0
101
+ if opt == "-v":
102
+ verbose += 1
103
+ if do_write:
104
+ ph = win32api.GetCurrentProcess()
105
+ th = win32security.OpenProcessToken(ph, win32con.TOKEN_READ)
106
+ my_sid = win32security.GetTokenInformation(th, win32security.TokenUser)[0]
107
+
108
+ win32evtlogutil.ReportEvent(
109
+ logType,
110
+ 2,
111
+ strings=["The message text for event 2", "Another insert"],
112
+ data=b"Raw\0Data",
113
+ sid=my_sid,
114
+ )
115
+ win32evtlogutil.ReportEvent(
116
+ logType,
117
+ 1,
118
+ eventType=win32evtlog.EVENTLOG_WARNING_TYPE,
119
+ strings=["A warning", "An even more dire warning"],
120
+ data=b"Raw\0Data",
121
+ sid=my_sid,
122
+ )
123
+ win32evtlogutil.ReportEvent(
124
+ logType,
125
+ 1,
126
+ eventType=win32evtlog.EVENTLOG_INFORMATION_TYPE,
127
+ strings=["An info", "Too much info"],
128
+ data=b"Raw\0Data",
129
+ sid=my_sid,
130
+ )
131
+ print("Successfully wrote 3 records to the log")
132
+
133
+ if do_read:
134
+ ReadLog(computer, logType, verbose > 0)
135
+
136
+
137
+ if __name__ == "__main__":
138
+ test()
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/getfilever.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import win32api
4
+
5
+ ver_strings = (
6
+ "Comments",
7
+ "InternalName",
8
+ "ProductName",
9
+ "CompanyName",
10
+ "LegalCopyright",
11
+ "ProductVersion",
12
+ "FileDescription",
13
+ "LegalTrademarks",
14
+ "PrivateBuild",
15
+ "FileVersion",
16
+ "OriginalFilename",
17
+ "SpecialBuild",
18
+ )
19
+ fname = os.environ["comspec"]
20
+ d = win32api.GetFileVersionInfo(fname, "\\")
21
+ ## backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc
22
+ for n, v in d.items():
23
+ print(n, v)
24
+
25
+ pairs = win32api.GetFileVersionInfo(fname, "\\VarFileInfo\\Translation")
26
+ ## \VarFileInfo\Translation returns list of available (language, codepage) pairs that can be used to retreive string info
27
+ ## any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle two are language/codepage pair returned from above
28
+ for lang, codepage in pairs:
29
+ print("lang:", lang, "codepage:", codepage)
30
+ for ver_string in ver_strings:
31
+ str_info = f"\\StringFileInfo\\{lang:04X}{codepage:04X}\\{ver_string}"
32
+ # print(str_inf)
33
+ print(ver_string, repr(win32api.GetFileVersionInfo(fname, str_info)))
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/images/frowny.bmp ADDED
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/images/smiley.bmp ADDED
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/mmapfile_demo.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import tempfile
3
+
4
+ import mmapfile
5
+ import win32api
6
+ import winerror
7
+
8
+ system_info = win32api.GetSystemInfo()
9
+ page_size = system_info[1]
10
+ alloc_size = system_info[7]
11
+
12
+ fname = tempfile.mktemp()
13
+ mapping_name = os.path.split(fname)[1]
14
+ fsize = 8 * page_size
15
+ print(fname, fsize, mapping_name)
16
+
17
+ m1 = mmapfile.mmapfile(File=fname, Name=mapping_name, MaximumSize=fsize)
18
+ m1.seek(100)
19
+ m1.write_byte(b"?")
20
+ m1.seek(-1, 1)
21
+ assert m1.read_byte() == b"?"
22
+
23
+ ## A reopened named mapping should have exact same size as original mapping
24
+ m2 = mmapfile.mmapfile(Name=mapping_name, File=None, MaximumSize=fsize * 2)
25
+ assert m2.size() == m1.size()
26
+ m1.seek(0, 0)
27
+ m1.write(fsize * b"s")
28
+ assert m2.read(fsize) == fsize * b"s"
29
+
30
+ move_src = 100
31
+ move_dest = 500
32
+ move_size = 150
33
+
34
+ m2.seek(move_src, 0)
35
+ assert m2.tell() == move_src
36
+ m2.write(b"m" * move_size)
37
+ m2.move(move_dest, move_src, move_size)
38
+ m2.seek(move_dest, 0)
39
+ assert m2.read(move_size) == b"m" * move_size
40
+ ## m2.write('x'* (fsize+1))
41
+
42
+ m2.close()
43
+ m1.resize(fsize * 2)
44
+ assert m1.size() == fsize * 2
45
+ m1.seek(fsize)
46
+ m1.write(b"w" * fsize)
47
+ m1.flush()
48
+ m1.close()
49
+ os.remove(fname)
50
+
51
+
52
+ ## Test a file with size larger than 32 bits
53
+ ## need 10 GB free on drive where your temp folder lives
54
+ fname_large = tempfile.mktemp()
55
+ mapping_name = "Pywin32_large_mmap"
56
+ offsetdata = b"This is start of offset"
57
+
58
+ ## Deliberately use odd numbers to test rounding logic
59
+ fsize = (1024 * 1024 * 1024 * 10) + 333
60
+ offset = (1024 * 1024 * 32) + 42
61
+ view_size = (1024 * 1024 * 16) + 111
62
+
63
+ ## round mapping size and view size up to multiple of system page size
64
+ if fsize % page_size:
65
+ fsize += page_size - (fsize % page_size)
66
+ if view_size % page_size:
67
+ view_size += page_size - (view_size % page_size)
68
+ ## round offset down to multiple of allocation granularity
69
+ offset -= offset % alloc_size
70
+
71
+ m1 = None
72
+ m2 = None
73
+ try:
74
+ try:
75
+ m1 = mmapfile.mmapfile(fname_large, mapping_name, fsize, 0, offset * 2)
76
+ except mmapfile.error as exc:
77
+ # if we don't have enough disk-space, that's OK.
78
+ if exc.winerror != winerror.ERROR_DISK_FULL:
79
+ raise
80
+ print("skipping large file test - need", fsize, "available bytes.")
81
+ else:
82
+ m1.seek(offset)
83
+ m1.write(offsetdata)
84
+
85
+ ## When reopening an existing mapping without passing a file handle, you have
86
+ ## to specify a positive size even though it's ignored
87
+ m2 = mmapfile.mmapfile(
88
+ File=None,
89
+ Name=mapping_name,
90
+ MaximumSize=1,
91
+ FileOffset=offset,
92
+ NumberOfBytesToMap=view_size,
93
+ )
94
+ assert m2.read(len(offsetdata)) == offsetdata
95
+ finally:
96
+ if m1 is not None:
97
+ m1.close()
98
+ if m2 is not None:
99
+ m2.close()
100
+ if os.path.exists(fname_large):
101
+ os.remove(fname_large)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/pipes/cat.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """cat.py
2
+ a version of unix cat, tweaked to show off runproc.py
3
+ """
4
+
5
+ import sys
6
+
7
+ data = sys.stdin.read(1)
8
+ sys.stdout.write(data)
9
+ sys.stdout.flush()
10
+ while data:
11
+ data = sys.stdin.read(1)
12
+ sys.stdout.write(data)
13
+ sys.stdout.flush()
14
+ # Just here to have something to read from stderr.
15
+ sys.stderr.write("Blah...")
16
+
17
+ # end of cat.py
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/pipes/runproc.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """runproc.py
2
+
3
+ start a process with three inherited pipes.
4
+ Try to write to and read from those.
5
+ """
6
+
7
+ import msvcrt
8
+ import os
9
+
10
+ import win32api
11
+ import win32con
12
+ import win32file
13
+ import win32pipe
14
+ import win32process
15
+ import win32security
16
+
17
+
18
+ class Process:
19
+ def run(self, cmdline):
20
+ # security attributes for pipes
21
+ sAttrs = win32security.SECURITY_ATTRIBUTES()
22
+ sAttrs.bInheritHandle = 1
23
+
24
+ # create pipes
25
+ hStdin_r, self.hStdin_w = win32pipe.CreatePipe(sAttrs, 0)
26
+ self.hStdout_r, hStdout_w = win32pipe.CreatePipe(sAttrs, 0)
27
+ self.hStderr_r, hStderr_w = win32pipe.CreatePipe(sAttrs, 0)
28
+
29
+ # set the info structure for the new process.
30
+ StartupInfo = win32process.STARTUPINFO()
31
+ StartupInfo.hStdInput = hStdin_r
32
+ StartupInfo.hStdOutput = hStdout_w
33
+ StartupInfo.hStdError = hStderr_w
34
+ StartupInfo.dwFlags = win32process.STARTF_USESTDHANDLES
35
+ # Mark doesn't support wShowWindow yet.
36
+ # StartupInfo.dwFlags = StartupInfo.dwFlags | win32process.STARTF_USESHOWWINDOW
37
+ # StartupInfo.wShowWindow = win32con.SW_HIDE
38
+
39
+ # Create new output read handles and the input write handle. Set
40
+ # the inheritance properties to FALSE. Otherwise, the child inherits
41
+ # the these handles; resulting in non-closeable handles to the pipes
42
+ # being created.
43
+ pid = win32api.GetCurrentProcess()
44
+
45
+ tmp = win32api.DuplicateHandle(
46
+ pid,
47
+ self.hStdin_w,
48
+ pid,
49
+ 0,
50
+ 0, # non-inheritable!!
51
+ win32con.DUPLICATE_SAME_ACCESS,
52
+ )
53
+ # Close the inhertible version of the handle
54
+ win32file.CloseHandle(self.hStdin_w)
55
+ self.hStdin_w = tmp
56
+ tmp = win32api.DuplicateHandle(
57
+ pid,
58
+ self.hStdout_r,
59
+ pid,
60
+ 0,
61
+ 0, # non-inheritable!
62
+ win32con.DUPLICATE_SAME_ACCESS,
63
+ )
64
+ # Close the inhertible version of the handle
65
+ win32file.CloseHandle(self.hStdout_r)
66
+ self.hStdout_r = tmp
67
+
68
+ # start the process.
69
+ hProcess, hThread, dwPid, dwTid = win32process.CreateProcess(
70
+ None, # program
71
+ cmdline, # command line
72
+ None, # process security attributes
73
+ None, # thread attributes
74
+ 1, # inherit handles, or USESTDHANDLES won't work.
75
+ # creation flags. Don't access the console.
76
+ 0, # Don't need anything here.
77
+ # If you're in a GUI app, you should use
78
+ # CREATE_NEW_CONSOLE here, or any subprocesses
79
+ # might fall victim to the problem described in:
80
+ # KB article: Q156755, cmd.exe requires
81
+ # an NT console in order to perform redirection..
82
+ None, # no new environment
83
+ None, # current directory (stay where we are)
84
+ StartupInfo,
85
+ )
86
+ # normally, we would save the pid etc. here...
87
+
88
+ # Child is launched. Close the parents copy of those pipe handles
89
+ # that only the child should have open.
90
+ # You need to make sure that no handles to the write end of the
91
+ # output pipe are maintained in this process or else the pipe will
92
+ # not close when the child process exits and the ReadFile will hang.
93
+ win32file.CloseHandle(hStderr_w)
94
+ win32file.CloseHandle(hStdout_w)
95
+ win32file.CloseHandle(hStdin_r)
96
+
97
+ self.stdin = os.fdopen(msvcrt.open_osfhandle(self.hStdin_w, 0), "wb")
98
+ self.stdin.write("hmmmmm\r\n")
99
+ self.stdin.flush()
100
+ self.stdin.close()
101
+
102
+ self.stdout = os.fdopen(msvcrt.open_osfhandle(self.hStdout_r, 0), "rb")
103
+ print(f"Read on stdout: {self.stdout.read()!r}")
104
+
105
+ self.stderr = os.fdopen(msvcrt.open_osfhandle(self.hStderr_r, 0), "rb")
106
+ print(f"Read on stderr: {self.stderr.read()!r}")
107
+
108
+
109
+ if __name__ == "__main__":
110
+ p = Process()
111
+ exe = win32api.GetModuleFileName(0)
112
+ p.run(exe + " cat.py")
113
+
114
+ # end of runproc.py
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/print_desktop.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pywintypes
2
+ import win32api
3
+ import win32con
4
+ import win32gui
5
+ import win32print
6
+
7
+ pname = win32print.GetDefaultPrinter()
8
+ print(pname)
9
+ p = win32print.OpenPrinter(pname)
10
+ print("Printer handle: ", p)
11
+ print_processor = win32print.GetPrinter(p, 2)["pPrintProcessor"]
12
+ ## call with last parm set to 0 to get total size needed for printer's DEVMODE
13
+ dmsize = win32print.DocumentProperties(0, p, pname, None, None, 0)
14
+ ## dmDriverExtra should be total size - fixed size
15
+ driverextra = (
16
+ dmsize - pywintypes.DEVMODEType().Size
17
+ ) ## need a better way to get DEVMODE.dmSize
18
+ dm = pywintypes.DEVMODEType(driverextra)
19
+ dm.Fields = dm.Fields | win32con.DM_ORIENTATION | win32con.DM_COPIES
20
+ dm.Orientation = win32con.DMORIENT_LANDSCAPE
21
+ dm.Copies = 2
22
+ win32print.DocumentProperties(
23
+ 0, p, pname, dm, dm, win32con.DM_IN_BUFFER | win32con.DM_OUT_BUFFER
24
+ )
25
+
26
+ pDC = win32gui.CreateDC(print_processor, pname, dm)
27
+ printerwidth = win32print.GetDeviceCaps(pDC, win32con.PHYSICALWIDTH)
28
+ printerheight = win32print.GetDeviceCaps(pDC, win32con.PHYSICALHEIGHT)
29
+
30
+ hwnd = win32gui.GetDesktopWindow()
31
+ l, t, r, b = win32gui.GetWindowRect(hwnd)
32
+ desktopheight = b - t
33
+ desktopwidth = r - l
34
+ dDC = win32gui.GetWindowDC(hwnd)
35
+
36
+ dcDC = win32gui.CreateCompatibleDC(dDC)
37
+ dcBM = win32gui.CreateCompatibleBitmap(dDC, desktopwidth, desktopheight)
38
+ win32gui.SelectObject(dcDC, dcBM)
39
+ win32gui.StretchBlt(
40
+ dcDC,
41
+ 0,
42
+ 0,
43
+ desktopwidth,
44
+ desktopheight,
45
+ dDC,
46
+ 0,
47
+ 0,
48
+ desktopwidth,
49
+ desktopheight,
50
+ win32con.SRCCOPY,
51
+ )
52
+
53
+ pcDC = win32gui.CreateCompatibleDC(pDC)
54
+ pcBM = win32gui.CreateCompatibleBitmap(pDC, printerwidth, printerheight)
55
+ win32gui.SelectObject(pcDC, pcBM)
56
+ win32gui.StretchBlt(
57
+ pcDC,
58
+ 0,
59
+ 0,
60
+ printerwidth,
61
+ printerheight,
62
+ dcDC,
63
+ 0,
64
+ 0,
65
+ desktopwidth,
66
+ desktopheight,
67
+ win32con.SRCCOPY,
68
+ )
69
+
70
+ win32print.StartDoc(pDC, ("desktop.bmp", None, None, 0))
71
+ win32print.StartPage(pDC)
72
+ win32gui.StretchBlt(
73
+ pDC,
74
+ 0,
75
+ 0,
76
+ int(printerwidth * 0.9),
77
+ int(printerheight * 0.9),
78
+ pcDC,
79
+ 0,
80
+ 0,
81
+ printerwidth,
82
+ printerheight,
83
+ win32con.SRCCOPY,
84
+ )
85
+
86
+ font = win32gui.LOGFONT()
87
+ font.lfHeight = int(printerheight / 20)
88
+ font.lfWidth = font.lfHeight
89
+ font.lfWeight = 150
90
+ font.lfItalic = 1
91
+ font.lfUnderline = 1
92
+ hf = win32gui.CreateFontIndirect(font)
93
+ win32gui.SelectObject(pDC, hf)
94
+ win32gui.SetBkMode(pDC, win32con.TRANSPARENT)
95
+ win32gui.SetTextColor(pDC, win32api.RGB(0, 255, 0))
96
+ win32gui.DrawText(
97
+ pDC,
98
+ "Printed by Python!",
99
+ -1,
100
+ (0, 0, int(printerwidth * 0.9), int(printerheight * 0.9)),
101
+ win32con.DT_RIGHT | win32con.DT_BOTTOM | win32con.DT_SINGLELINE,
102
+ )
103
+ win32print.EndPage(pDC)
104
+ win32print.EndDoc(pDC)
105
+
106
+ win32print.ClosePrinter(p)
107
+ win32gui.DeleteObject(dcBM)
108
+ win32gui.DeleteObject(pcBM)
109
+ win32gui.DeleteObject(hf)
110
+ win32gui.DeleteDC(dDC)
111
+ win32gui.DeleteDC(dcDC)
112
+ win32gui.DeleteDC(pDC)
113
+ win32gui.DeleteDC(pcDC)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/rastest.py ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # rastest.py - test/demonstrate the win32ras module.
2
+ # Much of the code here contributed by Jethro Wright.
3
+
4
+ import os
5
+ import sys
6
+
7
+ import win32event
8
+ import win32ras
9
+
10
+ # Build a little dictionary of RAS states to decent strings.
11
+ # eg win32ras.RASCS_OpenPort -> "OpenPort"
12
+ stateMap = {
13
+ val: name[6:] for name, val in win32ras.__dict__.items() if name[:6] == "RASCS_"
14
+ }
15
+
16
+ # Use a lock so the callback can tell the main thread when it is finished.
17
+ callbackEvent = win32event.CreateEvent(None, 0, 0, None)
18
+
19
+
20
+ def Callback(hras, msg, state, error, exterror):
21
+ # print("Callback called with ", hras, msg, state, error, exterror)
22
+ stateName = stateMap.get(state, "Unknown state?")
23
+ print("Status is %s (%04lx), error code is %d" % (stateName, state, error))
24
+ finished = state in [win32ras.RASCS_Connected]
25
+ if finished:
26
+ win32event.SetEvent(callbackEvent)
27
+ if error != 0 or int(state) == win32ras.RASCS_Disconnected:
28
+ # we know for sure this is a good place to hangup....
29
+ print("Detected call failure: %s" % win32ras.GetErrorString(error))
30
+ HangUp(hras)
31
+ win32event.SetEvent(callbackEvent)
32
+
33
+
34
+ def ShowConnections():
35
+ print("All phone-book entries:")
36
+ for (name,) in win32ras.EnumEntries():
37
+ print(" ", name)
38
+ print("Current Connections:")
39
+ for con in win32ras.EnumConnections():
40
+ print(" ", con)
41
+
42
+
43
+ def EditEntry(entryName):
44
+ try:
45
+ win32ras.EditPhonebookEntry(0, None, entryName)
46
+ except win32ras.error as xxx_todo_changeme:
47
+ (rc, function, msg) = xxx_todo_changeme.args
48
+ print("Can not edit/find the RAS entry -", msg)
49
+
50
+
51
+ def HangUp(hras):
52
+ # trap potential, irrelevant errors from win32ras....
53
+ try:
54
+ win32ras.HangUp(hras)
55
+ except:
56
+ print("Tried to hang up gracefully on error, but didn't work....")
57
+ return None
58
+
59
+
60
+ def Connect(entryName, bUseCallback):
61
+ if bUseCallback:
62
+ theCallback = Callback
63
+ win32event.ResetEvent(callbackEvent)
64
+ else:
65
+ theCallback = None
66
+ # in order to *use* the username/password of a particular dun entry, one must
67
+ # explicitly get those params under win95....
68
+ try:
69
+ dp, b = win32ras.GetEntryDialParams(None, entryName)
70
+ except:
71
+ print("Couldn't find DUN entry: %s" % entryName)
72
+ else:
73
+ hras, rc = win32ras.Dial(
74
+ None, None, (entryName, "", "", dp[3], dp[4], ""), theCallback
75
+ )
76
+ # hras, rc = win32ras.Dial(None, None, (entryName, ),theCallback)
77
+ # print(hras, rc)
78
+ if not bUseCallback and rc != 0:
79
+ print("Could not dial the RAS connection:", win32ras.GetErrorString(rc))
80
+ hras = HangUp(hras)
81
+ # don't wait here if there's no need to....
82
+ elif (
83
+ bUseCallback
84
+ and win32event.WaitForSingleObject(callbackEvent, 60000)
85
+ != win32event.WAIT_OBJECT_0
86
+ ):
87
+ print("Gave up waiting for the process to complete!")
88
+ # sdk docs state one must explcitly hangup, even if there's an error....
89
+ try:
90
+ cs = win32ras.GetConnectStatus(hras)
91
+ except:
92
+ # on error, attempt a hang up anyway....
93
+ hras = HangUp(hras)
94
+ else:
95
+ if int(cs[0]) == win32ras.RASCS_Disconnected:
96
+ hras = HangUp(hras)
97
+ return hras, rc
98
+
99
+
100
+ def Disconnect(rasEntry):
101
+ # Need to find the entry
102
+ name = rasEntry.lower()
103
+ for hcon, entryName, devName, devType in win32ras.EnumConnections():
104
+ if entryName.lower() == name:
105
+ win32ras.HangUp(hcon)
106
+ print("Disconnected from", rasEntry)
107
+ break
108
+ else:
109
+ print("Could not find an open connection to", entryName)
110
+
111
+
112
+ usage = """
113
+ Usage: %s [-s] [-l] [-c connection] [-d connection]
114
+ -l : List phone-book entries and current connections.
115
+ -s : Show status while connecting/disconnecting (uses callbacks)
116
+ -c : Connect to the specified phonebook name.
117
+ -d : Disconnect from the specified phonebook name.
118
+ -e : Edit the specified phonebook entry.
119
+ """
120
+
121
+
122
+ def main():
123
+ import getopt
124
+
125
+ try:
126
+ opts, args = getopt.getopt(sys.argv[1:], "slc:d:e:")
127
+ except getopt.error as why:
128
+ print(why)
129
+ print(
130
+ usage
131
+ % (
132
+ os.path.basename(
133
+ sys.argv[0],
134
+ )
135
+ )
136
+ )
137
+ return
138
+
139
+ bCallback = 0
140
+ if args or not opts:
141
+ print(
142
+ usage
143
+ % (
144
+ os.path.basename(
145
+ sys.argv[0],
146
+ )
147
+ )
148
+ )
149
+ return
150
+ for opt, val in opts:
151
+ if opt == "-s":
152
+ bCallback = 1
153
+ if opt == "-l":
154
+ ShowConnections()
155
+ if opt == "-c":
156
+ hras, rc = Connect(val, bCallback)
157
+ if hras is not None:
158
+ print(f"hras: 0x{hras:8x}, rc: 0x{rc:04x}")
159
+ if opt == "-d":
160
+ Disconnect(val)
161
+ if opt == "-e":
162
+ EditEntry(val)
163
+
164
+
165
+ if __name__ == "__main__":
166
+ main()
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/GetTokenInformation.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Lists various types of information about current user's access token,
2
+ including UAC status on Vista
3
+ """
4
+
5
+ import pywintypes
6
+ import win32api
7
+ import win32con
8
+ import win32security
9
+ import winerror
10
+ from security_enums import (
11
+ SECURITY_IMPERSONATION_LEVEL,
12
+ TOKEN_ELEVATION_TYPE,
13
+ TOKEN_GROUP_ATTRIBUTES,
14
+ TOKEN_PRIVILEGE_ATTRIBUTES,
15
+ TOKEN_TYPE,
16
+ )
17
+
18
+
19
+ def dump_token(th):
20
+ token_type = win32security.GetTokenInformation(th, win32security.TokenType)
21
+ print("TokenType:", token_type, TOKEN_TYPE.lookup_name(token_type))
22
+ if token_type == win32security.TokenImpersonation:
23
+ imp_lvl = win32security.GetTokenInformation(
24
+ th, win32security.TokenImpersonationLevel
25
+ )
26
+ print(
27
+ "TokenImpersonationLevel:",
28
+ imp_lvl,
29
+ SECURITY_IMPERSONATION_LEVEL.lookup_name(imp_lvl),
30
+ )
31
+
32
+ print(
33
+ "TokenSessionId:",
34
+ win32security.GetTokenInformation(th, win32security.TokenSessionId),
35
+ )
36
+
37
+ privs = win32security.GetTokenInformation(th, win32security.TokenPrivileges)
38
+ print("TokenPrivileges:")
39
+ for priv_luid, priv_flags in privs:
40
+ flag_names, unk = TOKEN_PRIVILEGE_ATTRIBUTES.lookup_flags(priv_flags)
41
+ flag_desc = " ".join(flag_names)
42
+ if unk:
43
+ flag_desc += f"({unk})"
44
+
45
+ priv_name = win32security.LookupPrivilegeName("", priv_luid)
46
+ priv_desc = win32security.LookupPrivilegeDisplayName("", priv_name)
47
+ print("\t", priv_name, priv_desc, priv_flags, flag_desc)
48
+
49
+ print("TokenGroups:")
50
+ groups = win32security.GetTokenInformation(th, win32security.TokenGroups)
51
+ for group_sid, group_attr in groups:
52
+ flag_names, unk = TOKEN_GROUP_ATTRIBUTES.lookup_flags(group_attr)
53
+ flag_desc = " ".join(flag_names)
54
+ if unk:
55
+ flag_desc += f"({unk})"
56
+ if group_attr & TOKEN_GROUP_ATTRIBUTES.SE_GROUP_LOGON_ID:
57
+ sid_desc = "Logon sid"
58
+ else:
59
+ sid_desc = win32security.LookupAccountSid("", group_sid)
60
+ print("\t", group_sid, sid_desc, group_attr, flag_desc)
61
+
62
+ ## Vista token information types, will throw (87, 'GetTokenInformation', 'The parameter is incorrect.') on earier OS
63
+ try:
64
+ is_elevated = win32security.GetTokenInformation(
65
+ th, win32security.TokenElevation
66
+ )
67
+ print("TokenElevation:", is_elevated)
68
+ except pywintypes.error as details:
69
+ if details.winerror != winerror.ERROR_INVALID_PARAMETER:
70
+ raise
71
+ return None
72
+ print(
73
+ "TokenHasRestrictions:",
74
+ win32security.GetTokenInformation(th, win32security.TokenHasRestrictions),
75
+ )
76
+ print(
77
+ "TokenMandatoryPolicy",
78
+ win32security.GetTokenInformation(th, win32security.TokenMandatoryPolicy),
79
+ )
80
+ print(
81
+ "TokenVirtualizationAllowed:",
82
+ win32security.GetTokenInformation(th, win32security.TokenVirtualizationAllowed),
83
+ )
84
+ print(
85
+ "TokenVirtualizationEnabled:",
86
+ win32security.GetTokenInformation(th, win32security.TokenVirtualizationEnabled),
87
+ )
88
+
89
+ elevation_type = win32security.GetTokenInformation(
90
+ th, win32security.TokenElevationType
91
+ )
92
+ print(
93
+ "TokenElevationType:",
94
+ elevation_type,
95
+ TOKEN_ELEVATION_TYPE.lookup_name(elevation_type),
96
+ )
97
+ if elevation_type != win32security.TokenElevationTypeDefault:
98
+ lt = win32security.GetTokenInformation(th, win32security.TokenLinkedToken)
99
+ print("TokenLinkedToken:", lt)
100
+ else:
101
+ lt = None
102
+ return lt
103
+
104
+
105
+ ph = win32api.GetCurrentProcess()
106
+ th = win32security.OpenProcessToken(ph, win32con.MAXIMUM_ALLOWED)
107
+ lt = dump_token(th)
108
+ if lt:
109
+ print("\n\nlinked token info:")
110
+ dump_token(lt)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/account_rights.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ntsecuritycon
2
+ import win32api
3
+ import win32con
4
+ import win32security
5
+
6
+ new_privs = (
7
+ (
8
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_SECURITY_NAME),
9
+ win32con.SE_PRIVILEGE_ENABLED,
10
+ ),
11
+ (
12
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_CREATE_PERMANENT_NAME),
13
+ win32con.SE_PRIVILEGE_ENABLED,
14
+ ),
15
+ (
16
+ win32security.LookupPrivilegeValue("", "SeEnableDelegationPrivilege"),
17
+ win32con.SE_PRIVILEGE_ENABLED,
18
+ ), ##doesn't seem to be in ntsecuritycon.py ?
19
+ )
20
+
21
+ ph = win32api.GetCurrentProcess()
22
+ th = win32security.OpenProcessToken(
23
+ ph, win32security.TOKEN_ALL_ACCESS
24
+ ) ##win32con.TOKEN_ADJUST_PRIVILEGES)
25
+ win32security.AdjustTokenPrivileges(th, 0, new_privs)
26
+
27
+ policy_handle = win32security.GetPolicyHandle("", win32security.POLICY_ALL_ACCESS)
28
+ tmp_sid = win32security.LookupAccountName("", "tmp")[0]
29
+
30
+ privs = [
31
+ ntsecuritycon.SE_DEBUG_NAME,
32
+ ntsecuritycon.SE_TCB_NAME,
33
+ ntsecuritycon.SE_RESTORE_NAME,
34
+ ntsecuritycon.SE_REMOTE_SHUTDOWN_NAME,
35
+ ]
36
+ win32security.LsaAddAccountRights(policy_handle, tmp_sid, privs)
37
+
38
+ privlist = win32security.LsaEnumerateAccountRights(policy_handle, tmp_sid)
39
+ for priv in privlist:
40
+ print(priv)
41
+
42
+ privs = [ntsecuritycon.SE_DEBUG_NAME, ntsecuritycon.SE_TCB_NAME]
43
+ win32security.LsaRemoveAccountRights(policy_handle, tmp_sid, 0, privs)
44
+
45
+ privlist = win32security.LsaEnumerateAccountRights(policy_handle, tmp_sid)
46
+ for priv in privlist:
47
+ print(priv)
48
+
49
+ win32security.LsaClose(policy_handle)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/explicit_entries.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import ntsecuritycon
4
+ import win32api
5
+ import win32con
6
+ import win32security
7
+ from security_enums import ACCESS_MODE, ACE_FLAGS, TRUSTEE_FORM, TRUSTEE_TYPE
8
+
9
+ fname = os.path.join(win32api.GetTempPath(), "win32security_test.txt")
10
+ f = open(fname, "w")
11
+ f.write("Hello from Python\n")
12
+ f.close()
13
+ print("Testing on file", fname)
14
+
15
+ new_privs = (
16
+ (
17
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_SECURITY_NAME),
18
+ win32con.SE_PRIVILEGE_ENABLED,
19
+ ),
20
+ (
21
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_SHUTDOWN_NAME),
22
+ win32con.SE_PRIVILEGE_ENABLED,
23
+ ),
24
+ (
25
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_RESTORE_NAME),
26
+ win32con.SE_PRIVILEGE_ENABLED,
27
+ ),
28
+ (
29
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_TAKE_OWNERSHIP_NAME),
30
+ win32con.SE_PRIVILEGE_ENABLED,
31
+ ),
32
+ (
33
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_CREATE_PERMANENT_NAME),
34
+ win32con.SE_PRIVILEGE_ENABLED,
35
+ ),
36
+ (
37
+ win32security.LookupPrivilegeValue("", "SeEnableDelegationPrivilege"),
38
+ win32con.SE_PRIVILEGE_ENABLED,
39
+ ), ##doesn't seem to be in ntsecuritycon.py ?
40
+ )
41
+
42
+ ph = win32api.GetCurrentProcess()
43
+ th = win32security.OpenProcessToken(
44
+ ph, win32security.TOKEN_ALL_ACCESS
45
+ ) ##win32con.TOKEN_ADJUST_PRIVILEGES)
46
+ win32security.AdjustTokenPrivileges(th, 0, new_privs)
47
+
48
+ all_security_info = (
49
+ win32security.OWNER_SECURITY_INFORMATION
50
+ | win32security.GROUP_SECURITY_INFORMATION
51
+ | win32security.DACL_SECURITY_INFORMATION
52
+ | win32security.SACL_SECURITY_INFORMATION
53
+ )
54
+
55
+ sd = win32security.GetFileSecurity(fname, all_security_info)
56
+
57
+ old_sacl = sd.GetSecurityDescriptorSacl()
58
+ if old_sacl is None:
59
+ old_sacl = win32security.ACL()
60
+ old_dacl = sd.GetSecurityDescriptorDacl()
61
+ if old_dacl is None:
62
+ old_dacl = win32security.ACL()
63
+
64
+ my_sid = win32security.GetTokenInformation(th, ntsecuritycon.TokenUser)[0]
65
+ tmp_sid = win32security.LookupAccountName("", "tmp")[0]
66
+ pwr_sid = win32security.LookupAccountName("", "Power Users")[0]
67
+
68
+
69
+ ## MultipleTrustee,MultipleTrusteeOperation,TrusteeForm,TrusteeType,Identifier
70
+ ## first two are ignored
71
+ my_trustee = {}
72
+ my_trustee["MultipleTrustee"] = None
73
+ my_trustee["MultipleTrusteeOperation"] = 0
74
+ my_trustee["TrusteeForm"] = TRUSTEE_FORM.TRUSTEE_IS_SID
75
+ my_trustee["TrusteeType"] = TRUSTEE_TYPE.TRUSTEE_IS_USER
76
+ my_trustee["Identifier"] = my_sid
77
+
78
+ tmp_trustee = {}
79
+ tmp_trustee["MultipleTrustee"] = None
80
+ tmp_trustee["MultipleTrusteeOperation"] = 0
81
+ tmp_trustee["TrusteeForm"] = TRUSTEE_FORM.TRUSTEE_IS_NAME
82
+ tmp_trustee["TrusteeType"] = TRUSTEE_TYPE.TRUSTEE_IS_USER
83
+ tmp_trustee["Identifier"] = "rupole\\tmp"
84
+
85
+ pwr_trustee = {}
86
+ pwr_trustee["MultipleTrustee"] = None
87
+ pwr_trustee["MultipleTrusteeOperation"] = 0
88
+ pwr_trustee["TrusteeForm"] = TRUSTEE_FORM.TRUSTEE_IS_SID
89
+ pwr_trustee["TrusteeType"] = TRUSTEE_TYPE.TRUSTEE_IS_USER
90
+ pwr_trustee["Identifier"] = pwr_sid
91
+
92
+ expl_list = []
93
+ expl_list.append(
94
+ {
95
+ "Trustee": my_trustee,
96
+ "Inheritance": ACE_FLAGS.NO_INHERITANCE,
97
+ "AccessMode": ACCESS_MODE.SET_AUDIT_SUCCESS, ##|ACCESS_MODE.SET_AUDIT_FAILURE,
98
+ "AccessPermissions": win32con.GENERIC_ALL,
99
+ }
100
+ )
101
+
102
+ expl_list.append(
103
+ {
104
+ "Trustee": my_trustee,
105
+ "Inheritance": ACE_FLAGS.NO_INHERITANCE,
106
+ "AccessMode": ACCESS_MODE.SET_AUDIT_FAILURE,
107
+ "AccessPermissions": win32con.GENERIC_ALL,
108
+ }
109
+ )
110
+
111
+ expl_list.append(
112
+ {
113
+ "Trustee": tmp_trustee,
114
+ "Inheritance": ACE_FLAGS.NO_INHERITANCE,
115
+ "AccessMode": ACCESS_MODE.SET_AUDIT_SUCCESS,
116
+ "AccessPermissions": win32con.GENERIC_ALL,
117
+ }
118
+ )
119
+
120
+ expl_list.append(
121
+ {
122
+ "Trustee": tmp_trustee,
123
+ "Inheritance": ACE_FLAGS.NO_INHERITANCE,
124
+ "AccessMode": ACCESS_MODE.SET_AUDIT_FAILURE,
125
+ "AccessPermissions": win32con.GENERIC_ALL,
126
+ }
127
+ )
128
+ old_sacl.SetEntriesInAcl(expl_list)
129
+
130
+ expl_list = []
131
+ expl_list.append(
132
+ {
133
+ "Trustee": tmp_trustee,
134
+ "Inheritance": ACE_FLAGS.NO_INHERITANCE,
135
+ "AccessMode": ACCESS_MODE.DENY_ACCESS,
136
+ "AccessPermissions": win32con.DELETE,
137
+ }
138
+ )
139
+
140
+ expl_list.append(
141
+ {
142
+ "Trustee": tmp_trustee,
143
+ "Inheritance": ACE_FLAGS.NO_INHERITANCE,
144
+ "AccessMode": ACCESS_MODE.GRANT_ACCESS,
145
+ "AccessPermissions": win32con.WRITE_OWNER,
146
+ }
147
+ )
148
+ expl_list.append(
149
+ {
150
+ "Trustee": pwr_trustee,
151
+ "Inheritance": ACE_FLAGS.NO_INHERITANCE,
152
+ "AccessMode": ACCESS_MODE.GRANT_ACCESS,
153
+ "AccessPermissions": win32con.GENERIC_READ,
154
+ }
155
+ )
156
+ expl_list.append(
157
+ {
158
+ "Trustee": my_trustee,
159
+ "Inheritance": ACE_FLAGS.NO_INHERITANCE,
160
+ "AccessMode": ACCESS_MODE.GRANT_ACCESS,
161
+ "AccessPermissions": win32con.GENERIC_ALL,
162
+ }
163
+ )
164
+
165
+ old_dacl.SetEntriesInAcl(expl_list)
166
+ sd.SetSecurityDescriptorSacl(1, old_sacl, 1)
167
+ sd.SetSecurityDescriptorDacl(1, old_dacl, 1)
168
+ sd.SetSecurityDescriptorOwner(pwr_sid, 1)
169
+
170
+ win32security.SetFileSecurity(fname, all_security_info, sd)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/get_policy_info.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32security
2
+
3
+ policy_handle = win32security.GetPolicyHandle("rupole", win32security.POLICY_ALL_ACCESS)
4
+
5
+ # mod_nbr, mod_time = win32security.LsaQueryInformationPolicy(policy_handle,win32security.PolicyModificationInformation)
6
+ # print(mod_nbr, mod_time)
7
+
8
+ (
9
+ domain_name,
10
+ dns_domain_name,
11
+ dns_forest_name,
12
+ domain_guid,
13
+ domain_sid,
14
+ ) = win32security.LsaQueryInformationPolicy(
15
+ policy_handle, win32security.PolicyDnsDomainInformation
16
+ )
17
+ print(domain_name, dns_domain_name, dns_forest_name, domain_guid, domain_sid)
18
+
19
+ event_audit_info = win32security.LsaQueryInformationPolicy(
20
+ policy_handle, win32security.PolicyAuditEventsInformation
21
+ )
22
+ print(event_audit_info)
23
+
24
+ domain_name, sid = win32security.LsaQueryInformationPolicy(
25
+ policy_handle, win32security.PolicyPrimaryDomainInformation
26
+ )
27
+ print(domain_name, sid)
28
+
29
+ domain_name, sid = win32security.LsaQueryInformationPolicy(
30
+ policy_handle, win32security.PolicyAccountDomainInformation
31
+ )
32
+ print(domain_name, sid)
33
+
34
+ server_role = win32security.LsaQueryInformationPolicy(
35
+ policy_handle, win32security.PolicyLsaServerRoleInformation
36
+ )
37
+ print("server role: ", server_role)
38
+
39
+ win32security.LsaClose(policy_handle)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/list_rights.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ntsecuritycon
2
+ import win32api
3
+ import win32con
4
+ import win32security
5
+
6
+ new_privs = (
7
+ (
8
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_SECURITY_NAME),
9
+ win32con.SE_PRIVILEGE_ENABLED,
10
+ ),
11
+ (
12
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_CREATE_PERMANENT_NAME),
13
+ win32con.SE_PRIVILEGE_ENABLED,
14
+ ),
15
+ (
16
+ win32security.LookupPrivilegeValue("", "SeEnableDelegationPrivilege"),
17
+ win32con.SE_PRIVILEGE_ENABLED,
18
+ ), ##doesn't seem to be in ntsecuritycon.py ?
19
+ )
20
+
21
+ ph = win32api.GetCurrentProcess()
22
+ th = win32security.OpenProcessToken(
23
+ ph, win32security.TOKEN_ALL_ACCESS
24
+ ) ##win32con.TOKEN_ADJUST_PRIVILEGES)
25
+ win32security.AdjustTokenPrivileges(th, 0, new_privs)
26
+
27
+ policy_handle = win32security.GetPolicyHandle("", win32security.POLICY_ALL_ACCESS)
28
+
29
+ sidlist = win32security.LsaEnumerateAccountsWithUserRight(
30
+ policy_handle, ntsecuritycon.SE_RESTORE_NAME
31
+ )
32
+ for sid in sidlist:
33
+ print(win32security.LookupAccountSid("", sid))
34
+
35
+ win32security.LsaClose(policy_handle)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/localized_names.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # A Python port of the MS knowledge base article Q157234
2
+ # "How to deal with localized and renamed user and group names"
3
+ # https://www.betaarchive.com/wiki/index.php?title=Microsoft_KB_Archive/157234
4
+
5
+ import sys
6
+
7
+ import pywintypes
8
+ from ntsecuritycon import (
9
+ DOMAIN_ALIAS_RID_ADMINS,
10
+ DOMAIN_USER_RID_ADMIN,
11
+ SECURITY_BUILTIN_DOMAIN_RID,
12
+ SECURITY_NT_AUTHORITY,
13
+ )
14
+ from win32net import NetUserModalsGet
15
+ from win32security import LookupAccountSid
16
+
17
+
18
+ def LookupAliasFromRid(TargetComputer, Rid):
19
+ # Sid is the same regardless of machine, since the well-known
20
+ # BUILTIN domain is referenced.
21
+ sid = pywintypes.SID()
22
+ sid.Initialize(SECURITY_NT_AUTHORITY, 2)
23
+
24
+ for i, r in enumerate((SECURITY_BUILTIN_DOMAIN_RID, Rid)):
25
+ sid.SetSubAuthority(i, r)
26
+
27
+ name, domain, typ = LookupAccountSid(TargetComputer, sid)
28
+ return name
29
+
30
+
31
+ def LookupUserGroupFromRid(TargetComputer, Rid):
32
+ # get the account domain Sid on the target machine
33
+ # note: if you were looking up multiple sids based on the same
34
+ # account domain, only need to call this once.
35
+ umi2 = NetUserModalsGet(TargetComputer, 2)
36
+ domain_sid = umi2["domain_id"]
37
+
38
+ SubAuthorityCount = domain_sid.GetSubAuthorityCount()
39
+
40
+ # create and init new sid with acct domain Sid + acct Rid
41
+ sid = pywintypes.SID()
42
+ sid.Initialize(domain_sid.GetSidIdentifierAuthority(), SubAuthorityCount + 1)
43
+
44
+ # copy existing subauthorities from account domain Sid into
45
+ # new Sid
46
+ for i in range(SubAuthorityCount):
47
+ sid.SetSubAuthority(i, domain_sid.GetSubAuthority(i))
48
+
49
+ # append Rid to new Sid
50
+ sid.SetSubAuthority(SubAuthorityCount, Rid)
51
+
52
+ name, domain, typ = LookupAccountSid(TargetComputer, sid)
53
+ return name
54
+
55
+
56
+ def main():
57
+ if len(sys.argv) == 2:
58
+ targetComputer = sys.argv[1]
59
+ else:
60
+ targetComputer = None
61
+
62
+ name = LookupUserGroupFromRid(targetComputer, DOMAIN_USER_RID_ADMIN)
63
+ print(f"'Administrator' user name = {name}")
64
+
65
+ name = LookupAliasFromRid(targetComputer, DOMAIN_ALIAS_RID_ADMINS)
66
+ print(f"'Administrators' local group/alias name = {name}")
67
+
68
+
69
+ if __name__ == "__main__":
70
+ main()
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/lsaregevent.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32event
2
+ import win32security
3
+
4
+ evt = win32event.CreateEvent(None, 0, 0, None)
5
+ win32security.LsaRegisterPolicyChangeNotification(
6
+ win32security.PolicyNotifyAuditEventsInformation, evt
7
+ )
8
+ print("Waiting for you change Audit policy in Management console ...")
9
+ ret_code = win32event.WaitForSingleObject(evt, 1000000000)
10
+ ## should come back when you change Audit policy in Management console ...
11
+ print(ret_code)
12
+ win32security.LsaUnregisterPolicyChangeNotification(
13
+ win32security.PolicyNotifyAuditEventsInformation, evt
14
+ )
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/lsastore.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32security
2
+
3
+ policy_handle = win32security.GetPolicyHandle("", win32security.POLICY_ALL_ACCESS)
4
+ privatedata = "some sensitive data"
5
+ keyname = "tmp"
6
+ win32security.LsaStorePrivateData(policy_handle, keyname, privatedata)
7
+ retrieveddata = win32security.LsaRetrievePrivateData(policy_handle, keyname)
8
+ assert retrieveddata == privatedata
9
+
10
+ ## passing None deletes key
11
+ win32security.LsaStorePrivateData(policy_handle, keyname, None)
12
+ win32security.LsaClose(policy_handle)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/query_information.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32api
2
+ import win32security
3
+ import winerror
4
+ from ntsecuritycon import TOKEN_QUERY, TokenUser
5
+
6
+
7
+ # This is a Python implementation of win32api.GetDomainName()
8
+ def GetDomainName():
9
+ try:
10
+ tok = win32security.OpenThreadToken(win32api.GetCurrentThread(), TOKEN_QUERY, 1)
11
+ except win32api.error as details:
12
+ if details[0] != winerror.ERROR_NO_TOKEN:
13
+ raise
14
+ # attempt to open the process token, since no thread token
15
+ # exists
16
+ tok = win32security.OpenProcessToken(win32api.GetCurrentProcess(), TOKEN_QUERY)
17
+ sid, attr = win32security.GetTokenInformation(tok, TokenUser)
18
+ win32api.CloseHandle(tok)
19
+
20
+ name, dom, typ = win32security.LookupAccountSid(None, sid)
21
+ return dom
22
+
23
+
24
+ if __name__ == "__main__":
25
+ print("Domain name is", GetDomainName())
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/regsave_sa.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ fname = "h:\\tmp.reg"
2
+
3
+ import os
4
+
5
+ import ntsecuritycon
6
+ import pywintypes
7
+ import win32api
8
+ import win32con
9
+ import win32security
10
+
11
+ ## regsave will not overwrite a file
12
+ if os.path.isfile(fname):
13
+ os.remove(fname)
14
+
15
+ new_privs = (
16
+ (
17
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_SECURITY_NAME),
18
+ win32con.SE_PRIVILEGE_ENABLED,
19
+ ),
20
+ (
21
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_TCB_NAME),
22
+ win32con.SE_PRIVILEGE_ENABLED,
23
+ ),
24
+ (
25
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_BACKUP_NAME),
26
+ win32con.SE_PRIVILEGE_ENABLED,
27
+ ),
28
+ (
29
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_RESTORE_NAME),
30
+ win32con.SE_PRIVILEGE_ENABLED,
31
+ ),
32
+ )
33
+ ph = win32api.GetCurrentProcess()
34
+ th = win32security.OpenProcessToken(
35
+ ph, win32security.TOKEN_ALL_ACCESS | win32con.TOKEN_ADJUST_PRIVILEGES
36
+ )
37
+ win32security.AdjustTokenPrivileges(th, 0, new_privs)
38
+ my_sid = win32security.GetTokenInformation(th, ntsecuritycon.TokenUser)[0]
39
+
40
+ hklm = win32api.RegOpenKey(
41
+ win32con.HKEY_LOCAL_MACHINE, None, 0, win32con.KEY_ALL_ACCESS
42
+ )
43
+ skey = win32api.RegOpenKey(hklm, "SYSTEM", 0, win32con.KEY_ALL_ACCESS)
44
+
45
+ sa = pywintypes.SECURITY_ATTRIBUTES()
46
+ sd = pywintypes.SECURITY_DESCRIPTOR()
47
+ sa.SECURITY_DESCRIPTOR = sd
48
+ acl = pywintypes.ACL()
49
+
50
+ pwr_sid = win32security.LookupAccountName("", "Power Users")[0]
51
+ acl.AddAccessAllowedAce(
52
+ win32con.ACL_REVISION,
53
+ win32con.GENERIC_READ | win32con.ACCESS_SYSTEM_SECURITY,
54
+ my_sid,
55
+ )
56
+ sd.SetSecurityDescriptorDacl(1, acl, 0)
57
+ sd.SetSecurityDescriptorOwner(pwr_sid, 0)
58
+ sa.bInheritHandle = 1
59
+ assert sa.SECURITY_DESCRIPTOR is sd
60
+
61
+ win32api.RegSaveKey(skey, fname, sa)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/regsecurity.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ntsecuritycon
2
+ import win32api
3
+ import win32con
4
+ import win32security
5
+
6
+ new_privs = (
7
+ (
8
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_SECURITY_NAME),
9
+ win32con.SE_PRIVILEGE_ENABLED,
10
+ ),
11
+ (
12
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_TCB_NAME),
13
+ win32con.SE_PRIVILEGE_ENABLED,
14
+ ),
15
+ )
16
+ ph = win32api.GetCurrentProcess()
17
+ th = win32security.OpenProcessToken(
18
+ ph, win32security.TOKEN_ALL_ACCESS | win32con.TOKEN_ADJUST_PRIVILEGES
19
+ )
20
+
21
+ win32security.AdjustTokenPrivileges(th, 0, new_privs)
22
+ hkey = win32api.RegOpenKey(
23
+ win32con.HKEY_LOCAL_MACHINE, None, 0, win32con.KEY_ALL_ACCESS
24
+ )
25
+ win32api.RegCreateKey(hkey, "SYSTEM\\NOTMP")
26
+ notmpkey = win32api.RegOpenKey(
27
+ hkey, "SYSTEM\\notmp", 0, win32con.ACCESS_SYSTEM_SECURITY
28
+ )
29
+
30
+ tmp_sid = win32security.LookupAccountName("", "tmp")[0]
31
+ sacl = win32security.ACL()
32
+ sacl.AddAuditAccessAce(win32security.ACL_REVISION, win32con.GENERIC_ALL, tmp_sid, 1, 1)
33
+
34
+ sd = win32security.SECURITY_DESCRIPTOR()
35
+ sd.SetSecurityDescriptorSacl(1, sacl, 1)
36
+ win32api.RegSetKeySecurity(notmpkey, win32con.SACL_SECURITY_INFORMATION, sd)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/sa_inherit.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ import pywintypes
2
+ import win32security
3
+
4
+ sa = pywintypes.SECURITY_ATTRIBUTES()
5
+ tmp_sid = win32security.LookupAccountName("", "tmp")[0]
6
+ sa.SetSecurityDescriptorOwner(tmp_sid, 0)
7
+ sid = sa.SECURITY_DESCRIPTOR.GetSecurityDescriptorOwner()
8
+ print(win32security.LookupAccountSid("", sid))
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/security_enums.py ADDED
@@ -0,0 +1,336 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ntsecuritycon
2
+ import win32security
3
+ import winnt
4
+
5
+
6
+ class Enum:
7
+ def __init__(self, *const_names):
8
+ """Accepts variable number of constant names that can be found in either
9
+ win32security, ntsecuritycon, or winnt."""
10
+ for const_name in const_names:
11
+ try:
12
+ const_val = getattr(win32security, const_name)
13
+ except AttributeError:
14
+ try:
15
+ const_val = getattr(ntsecuritycon, const_name)
16
+ except AttributeError:
17
+ try:
18
+ const_val = getattr(winnt, const_name)
19
+ except AttributeError:
20
+ raise AttributeError(
21
+ 'Constant "%s" not found in win32security, ntsecuritycon, or winnt.'
22
+ % const_name
23
+ )
24
+ setattr(self, const_name, const_val)
25
+
26
+ def lookup_name(self, const_val):
27
+ """Looks up the name of a particular value."""
28
+ for k, v in self.__dict__.items():
29
+ if v == const_val:
30
+ return k
31
+ raise AttributeError("Value %s not found in enum" % const_val)
32
+
33
+ def lookup_flags(self, flags):
34
+ """Returns the names of all recognized flags in input, and any flags not found in the enum."""
35
+ flag_names = []
36
+ unknown_flags = flags
37
+ for k, v in self.__dict__.items():
38
+ if flags & v == v:
39
+ flag_names.append(k)
40
+ unknown_flags &= ~v
41
+ return flag_names, unknown_flags
42
+
43
+
44
+ TOKEN_INFORMATION_CLASS = Enum(
45
+ "TokenUser",
46
+ "TokenGroups",
47
+ "TokenPrivileges",
48
+ "TokenOwner",
49
+ "TokenPrimaryGroup",
50
+ "TokenDefaultDacl",
51
+ "TokenSource",
52
+ "TokenType",
53
+ "TokenImpersonationLevel",
54
+ "TokenStatistics",
55
+ "TokenRestrictedSids",
56
+ "TokenSessionId",
57
+ "TokenGroupsAndPrivileges",
58
+ "TokenSessionReference",
59
+ "TokenSandBoxInert",
60
+ "TokenAuditPolicy",
61
+ "TokenOrigin",
62
+ "TokenElevationType",
63
+ "TokenLinkedToken",
64
+ "TokenElevation",
65
+ "TokenHasRestrictions",
66
+ "TokenAccessInformation",
67
+ "TokenVirtualizationAllowed",
68
+ "TokenVirtualizationEnabled",
69
+ "TokenIntegrityLevel",
70
+ "TokenUIAccess",
71
+ "TokenMandatoryPolicy",
72
+ "TokenLogonSid",
73
+ )
74
+
75
+ TOKEN_TYPE = Enum("TokenPrimary", "TokenImpersonation")
76
+
77
+ TOKEN_ELEVATION_TYPE = Enum(
78
+ "TokenElevationTypeDefault", "TokenElevationTypeFull", "TokenElevationTypeLimited"
79
+ )
80
+
81
+ POLICY_AUDIT_EVENT_TYPE = Enum(
82
+ "AuditCategorySystem",
83
+ "AuditCategoryLogon",
84
+ "AuditCategoryObjectAccess",
85
+ "AuditCategoryPrivilegeUse",
86
+ "AuditCategoryDetailedTracking",
87
+ "AuditCategoryPolicyChange",
88
+ "AuditCategoryAccountManagement",
89
+ "AuditCategoryDirectoryServiceAccess",
90
+ "AuditCategoryAccountLogon",
91
+ )
92
+
93
+ POLICY_INFORMATION_CLASS = Enum(
94
+ "PolicyAuditLogInformation",
95
+ "PolicyAuditEventsInformation",
96
+ "PolicyPrimaryDomainInformation",
97
+ "PolicyPdAccountInformation",
98
+ "PolicyAccountDomainInformation",
99
+ "PolicyLsaServerRoleInformation",
100
+ "PolicyReplicaSourceInformation",
101
+ "PolicyDefaultQuotaInformation",
102
+ "PolicyModificationInformation",
103
+ "PolicyAuditFullSetInformation",
104
+ "PolicyAuditFullQueryInformation",
105
+ "PolicyDnsDomainInformation",
106
+ )
107
+
108
+ POLICY_LSA_SERVER_ROLE = Enum("PolicyServerRoleBackup", "PolicyServerRolePrimary")
109
+
110
+ ## access modes for opening a policy handle - this is not a real enum
111
+ POLICY_ACCESS_MODES = Enum(
112
+ "POLICY_VIEW_LOCAL_INFORMATION",
113
+ "POLICY_VIEW_AUDIT_INFORMATION",
114
+ "POLICY_GET_PRIVATE_INFORMATION",
115
+ "POLICY_TRUST_ADMIN",
116
+ "POLICY_CREATE_ACCOUNT",
117
+ "POLICY_CREATE_SECRET",
118
+ "POLICY_CREATE_PRIVILEGE",
119
+ "POLICY_SET_DEFAULT_QUOTA_LIMITS",
120
+ "POLICY_SET_AUDIT_REQUIREMENTS",
121
+ "POLICY_AUDIT_LOG_ADMIN",
122
+ "POLICY_SERVER_ADMIN",
123
+ "POLICY_LOOKUP_NAMES",
124
+ "POLICY_NOTIFICATION",
125
+ "POLICY_ALL_ACCESS",
126
+ "POLICY_READ",
127
+ "POLICY_WRITE",
128
+ "POLICY_EXECUTE",
129
+ )
130
+
131
+ ## EventAuditingOptions flags - not a real enum
132
+ POLICY_AUDIT_EVENT_OPTIONS_FLAGS = Enum(
133
+ "POLICY_AUDIT_EVENT_UNCHANGED",
134
+ "POLICY_AUDIT_EVENT_SUCCESS",
135
+ "POLICY_AUDIT_EVENT_FAILURE",
136
+ "POLICY_AUDIT_EVENT_NONE",
137
+ )
138
+
139
+ # AceType in ACE_HEADER - not a real enum
140
+ ACE_TYPE = Enum(
141
+ "ACCESS_MIN_MS_ACE_TYPE",
142
+ "ACCESS_ALLOWED_ACE_TYPE",
143
+ "ACCESS_DENIED_ACE_TYPE",
144
+ "SYSTEM_AUDIT_ACE_TYPE",
145
+ "SYSTEM_ALARM_ACE_TYPE",
146
+ "ACCESS_MAX_MS_V2_ACE_TYPE",
147
+ "ACCESS_ALLOWED_COMPOUND_ACE_TYPE",
148
+ "ACCESS_MAX_MS_V3_ACE_TYPE",
149
+ "ACCESS_MIN_MS_OBJECT_ACE_TYPE",
150
+ "ACCESS_ALLOWED_OBJECT_ACE_TYPE",
151
+ "ACCESS_DENIED_OBJECT_ACE_TYPE",
152
+ "SYSTEM_AUDIT_OBJECT_ACE_TYPE",
153
+ "SYSTEM_ALARM_OBJECT_ACE_TYPE",
154
+ "ACCESS_MAX_MS_OBJECT_ACE_TYPE",
155
+ "ACCESS_MAX_MS_V4_ACE_TYPE",
156
+ "ACCESS_MAX_MS_ACE_TYPE",
157
+ "ACCESS_ALLOWED_CALLBACK_ACE_TYPE",
158
+ "ACCESS_DENIED_CALLBACK_ACE_TYPE",
159
+ "ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE",
160
+ "ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE",
161
+ "SYSTEM_AUDIT_CALLBACK_ACE_TYPE",
162
+ "SYSTEM_ALARM_CALLBACK_ACE_TYPE",
163
+ "SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE",
164
+ "SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE",
165
+ "SYSTEM_MANDATORY_LABEL_ACE_TYPE",
166
+ "ACCESS_MAX_MS_V5_ACE_TYPE",
167
+ )
168
+
169
+ # bit flags for AceFlags - not a real enum
170
+ ACE_FLAGS = Enum(
171
+ "CONTAINER_INHERIT_ACE",
172
+ "FAILED_ACCESS_ACE_FLAG",
173
+ "INHERIT_ONLY_ACE",
174
+ "INHERITED_ACE",
175
+ "NO_PROPAGATE_INHERIT_ACE",
176
+ "OBJECT_INHERIT_ACE",
177
+ "SUCCESSFUL_ACCESS_ACE_FLAG",
178
+ "NO_INHERITANCE",
179
+ "SUB_CONTAINERS_AND_OBJECTS_INHERIT",
180
+ "SUB_CONTAINERS_ONLY_INHERIT",
181
+ "SUB_OBJECTS_ONLY_INHERIT",
182
+ )
183
+
184
+ # used in SetEntriesInAcl - very similar to ACE_TYPE
185
+ ACCESS_MODE = Enum(
186
+ "NOT_USED_ACCESS",
187
+ "GRANT_ACCESS",
188
+ "SET_ACCESS",
189
+ "DENY_ACCESS",
190
+ "REVOKE_ACCESS",
191
+ "SET_AUDIT_SUCCESS",
192
+ "SET_AUDIT_FAILURE",
193
+ )
194
+
195
+ # Bit flags in PSECURITY_DESCRIPTOR->Control - not a real enum
196
+ SECURITY_DESCRIPTOR_CONTROL_FLAGS = Enum(
197
+ "SE_DACL_AUTO_INHERITED", ## win2k and up
198
+ "SE_SACL_AUTO_INHERITED", ## win2k and up
199
+ "SE_DACL_PROTECTED", ## win2k and up
200
+ "SE_SACL_PROTECTED", ## win2k and up
201
+ "SE_DACL_DEFAULTED",
202
+ "SE_DACL_PRESENT",
203
+ "SE_GROUP_DEFAULTED",
204
+ "SE_OWNER_DEFAULTED",
205
+ "SE_SACL_PRESENT",
206
+ "SE_SELF_RELATIVE",
207
+ "SE_SACL_DEFAULTED",
208
+ )
209
+
210
+ # types of SID
211
+ SID_NAME_USE = Enum(
212
+ "SidTypeUser",
213
+ "SidTypeGroup",
214
+ "SidTypeDomain",
215
+ "SidTypeAlias",
216
+ "SidTypeWellKnownGroup",
217
+ "SidTypeDeletedAccount",
218
+ "SidTypeInvalid",
219
+ "SidTypeUnknown",
220
+ "SidTypeComputer",
221
+ "SidTypeLabel",
222
+ )
223
+
224
+ ## bit flags, not a real enum
225
+ TOKEN_ACCESS_PRIVILEGES = Enum(
226
+ "TOKEN_ADJUST_DEFAULT",
227
+ "TOKEN_ADJUST_GROUPS",
228
+ "TOKEN_ADJUST_PRIVILEGES",
229
+ "TOKEN_ALL_ACCESS",
230
+ "TOKEN_ASSIGN_PRIMARY",
231
+ "TOKEN_DUPLICATE",
232
+ "TOKEN_EXECUTE",
233
+ "TOKEN_IMPERSONATE",
234
+ "TOKEN_QUERY",
235
+ "TOKEN_QUERY_SOURCE",
236
+ "TOKEN_READ",
237
+ "TOKEN_WRITE",
238
+ )
239
+
240
+ SECURITY_IMPERSONATION_LEVEL = Enum(
241
+ "SecurityAnonymous",
242
+ "SecurityIdentification",
243
+ "SecurityImpersonation",
244
+ "SecurityDelegation",
245
+ )
246
+
247
+ POLICY_SERVER_ENABLE_STATE = Enum("PolicyServerEnabled", "PolicyServerDisabled")
248
+
249
+ POLICY_NOTIFICATION_INFORMATION_CLASS = Enum(
250
+ "PolicyNotifyAuditEventsInformation",
251
+ "PolicyNotifyAccountDomainInformation",
252
+ "PolicyNotifyServerRoleInformation",
253
+ "PolicyNotifyDnsDomainInformation",
254
+ "PolicyNotifyDomainEfsInformation",
255
+ "PolicyNotifyDomainKerberosTicketInformation",
256
+ "PolicyNotifyMachineAccountPasswordInformation",
257
+ )
258
+
259
+ TRUSTED_INFORMATION_CLASS = Enum(
260
+ "TrustedDomainNameInformation",
261
+ "TrustedControllersInformation",
262
+ "TrustedPosixOffsetInformation",
263
+ "TrustedPasswordInformation",
264
+ "TrustedDomainInformationBasic",
265
+ "TrustedDomainInformationEx",
266
+ "TrustedDomainAuthInformation",
267
+ "TrustedDomainFullInformation",
268
+ "TrustedDomainAuthInformationInternal",
269
+ "TrustedDomainFullInformationInternal",
270
+ "TrustedDomainInformationEx2Internal",
271
+ "TrustedDomainFullInformation2Internal",
272
+ )
273
+
274
+ TRUSTEE_FORM = Enum(
275
+ "TRUSTEE_IS_SID",
276
+ "TRUSTEE_IS_NAME",
277
+ "TRUSTEE_BAD_FORM",
278
+ "TRUSTEE_IS_OBJECTS_AND_SID",
279
+ "TRUSTEE_IS_OBJECTS_AND_NAME",
280
+ )
281
+
282
+ TRUSTEE_TYPE = Enum(
283
+ "TRUSTEE_IS_UNKNOWN",
284
+ "TRUSTEE_IS_USER",
285
+ "TRUSTEE_IS_GROUP",
286
+ "TRUSTEE_IS_DOMAIN",
287
+ "TRUSTEE_IS_ALIAS",
288
+ "TRUSTEE_IS_WELL_KNOWN_GROUP",
289
+ "TRUSTEE_IS_DELETED",
290
+ "TRUSTEE_IS_INVALID",
291
+ "TRUSTEE_IS_COMPUTER",
292
+ )
293
+
294
+ ## SE_OBJECT_TYPE - securable objects
295
+ SE_OBJECT_TYPE = Enum(
296
+ "SE_UNKNOWN_OBJECT_TYPE",
297
+ "SE_FILE_OBJECT",
298
+ "SE_SERVICE",
299
+ "SE_PRINTER",
300
+ "SE_REGISTRY_KEY",
301
+ "SE_LMSHARE",
302
+ "SE_KERNEL_OBJECT",
303
+ "SE_WINDOW_OBJECT",
304
+ "SE_DS_OBJECT",
305
+ "SE_DS_OBJECT_ALL",
306
+ "SE_PROVIDER_DEFINED_OBJECT",
307
+ "SE_WMIGUID_OBJECT",
308
+ "SE_REGISTRY_WOW64_32KEY",
309
+ )
310
+
311
+ PRIVILEGE_FLAGS = Enum(
312
+ "SE_PRIVILEGE_ENABLED_BY_DEFAULT",
313
+ "SE_PRIVILEGE_ENABLED",
314
+ "SE_PRIVILEGE_USED_FOR_ACCESS",
315
+ )
316
+
317
+ # Group flags used with TokenGroups
318
+ TOKEN_GROUP_ATTRIBUTES = Enum(
319
+ "SE_GROUP_MANDATORY",
320
+ "SE_GROUP_ENABLED_BY_DEFAULT",
321
+ "SE_GROUP_ENABLED",
322
+ "SE_GROUP_OWNER",
323
+ "SE_GROUP_USE_FOR_DENY_ONLY",
324
+ "SE_GROUP_INTEGRITY",
325
+ "SE_GROUP_INTEGRITY_ENABLED",
326
+ "SE_GROUP_LOGON_ID",
327
+ "SE_GROUP_RESOURCE",
328
+ )
329
+
330
+ # Privilege flags returned by TokenPrivileges
331
+ TOKEN_PRIVILEGE_ATTRIBUTES = Enum(
332
+ "SE_PRIVILEGE_ENABLED_BY_DEFAULT",
333
+ "SE_PRIVILEGE_ENABLED",
334
+ "SE_PRIVILEGE_REMOVED",
335
+ "SE_PRIVILEGE_USED_FOR_ACCESS",
336
+ )
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/set_file_audit.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import ntsecuritycon
4
+ import win32api
5
+ import win32con
6
+ import win32security
7
+ from win32security import (
8
+ ACL_REVISION_DS,
9
+ CONTAINER_INHERIT_ACE,
10
+ DACL_SECURITY_INFORMATION,
11
+ GROUP_SECURITY_INFORMATION,
12
+ OBJECT_INHERIT_ACE,
13
+ OWNER_SECURITY_INFORMATION,
14
+ PROTECTED_DACL_SECURITY_INFORMATION,
15
+ SACL_SECURITY_INFORMATION,
16
+ SE_FILE_OBJECT,
17
+ )
18
+
19
+ ## SE_SECURITY_NAME needed to access SACL, SE_RESTORE_NAME needed to change owner to someone other than yourself
20
+ new_privs = (
21
+ (
22
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_SECURITY_NAME),
23
+ win32con.SE_PRIVILEGE_ENABLED,
24
+ ),
25
+ (
26
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_RESTORE_NAME),
27
+ win32con.SE_PRIVILEGE_ENABLED,
28
+ ),
29
+ )
30
+ ph = win32api.GetCurrentProcess()
31
+ th = win32security.OpenProcessToken(
32
+ ph, win32security.TOKEN_ALL_ACCESS | win32con.TOKEN_ADJUST_PRIVILEGES
33
+ )
34
+ modified_privs = win32security.AdjustTokenPrivileges(th, 0, new_privs)
35
+
36
+ ## look up a few sids that should be available on most systems
37
+ my_sid = win32security.GetTokenInformation(th, ntsecuritycon.TokenUser)[0]
38
+ pwr_sid = win32security.LookupAccountName("", "Power Users")[0]
39
+ admin_sid = win32security.LookupAccountName("", "Administrators")[0]
40
+ everyone_sid = win32security.LookupAccountName("", "EveryOne")[0]
41
+
42
+ ## create a dir and set security so Everyone has read permissions, and all files and subdirs inherit its ACLs
43
+ temp_dir = win32api.GetTempPath()
44
+ dir_name = win32api.GetTempFileName(temp_dir, "sfa")[0]
45
+ os.remove(dir_name)
46
+ os.mkdir(dir_name)
47
+ dir_dacl = win32security.ACL()
48
+ dir_dacl.AddAccessAllowedAceEx(
49
+ ACL_REVISION_DS,
50
+ CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE,
51
+ win32con.GENERIC_READ,
52
+ everyone_sid,
53
+ )
54
+ ## make sure current user has permissions on dir
55
+ dir_dacl.AddAccessAllowedAceEx(
56
+ ACL_REVISION_DS,
57
+ CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE,
58
+ win32con.GENERIC_ALL,
59
+ my_sid,
60
+ )
61
+ ## keep dir from inheriting any permissions so it only has ACEs explicitly set here
62
+ win32security.SetNamedSecurityInfo(
63
+ dir_name,
64
+ SE_FILE_OBJECT,
65
+ OWNER_SECURITY_INFORMATION
66
+ | GROUP_SECURITY_INFORMATION
67
+ | DACL_SECURITY_INFORMATION
68
+ | PROTECTED_DACL_SECURITY_INFORMATION,
69
+ pwr_sid,
70
+ pwr_sid,
71
+ dir_dacl,
72
+ None,
73
+ )
74
+
75
+ ## Create a file in the dir and add some specific permissions to it
76
+ fname = win32api.GetTempFileName(dir_name, "sfa")[0]
77
+ print(fname)
78
+ file_sd = win32security.GetNamedSecurityInfo(
79
+ fname, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION
80
+ )
81
+ file_dacl = file_sd.GetSecurityDescriptorDacl()
82
+ file_sacl = file_sd.GetSecurityDescriptorSacl()
83
+
84
+ if file_dacl is None:
85
+ file_dacl = win32security.ACL()
86
+ if file_sacl is None:
87
+ file_sacl = win32security.ACL()
88
+
89
+ file_dacl.AddAccessDeniedAce(file_dacl.GetAclRevision(), win32con.DELETE, admin_sid)
90
+ file_dacl.AddAccessDeniedAce(file_dacl.GetAclRevision(), win32con.DELETE, my_sid)
91
+ file_dacl.AddAccessAllowedAce(file_dacl.GetAclRevision(), win32con.GENERIC_ALL, pwr_sid)
92
+ file_sacl.AddAuditAccessAce(
93
+ file_dacl.GetAclRevision(), win32con.GENERIC_ALL, my_sid, True, True
94
+ )
95
+
96
+ win32security.SetNamedSecurityInfo(
97
+ fname,
98
+ SE_FILE_OBJECT,
99
+ DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION,
100
+ None,
101
+ None,
102
+ file_dacl,
103
+ file_sacl,
104
+ )
105
+
106
+ win32security.AdjustTokenPrivileges(th, 0, modified_privs)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/set_file_owner.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ fname = r"h:\tmp.txt"
2
+
3
+ import ntsecuritycon
4
+ import win32api
5
+ import win32con
6
+ import win32security
7
+
8
+ new_privs = (
9
+ (
10
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_SECURITY_NAME),
11
+ win32con.SE_PRIVILEGE_ENABLED,
12
+ ),
13
+ (
14
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_SHUTDOWN_NAME),
15
+ win32con.SE_PRIVILEGE_ENABLED,
16
+ ),
17
+ (
18
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_TCB_NAME),
19
+ win32con.SE_PRIVILEGE_ENABLED,
20
+ ),
21
+ (
22
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_RESTORE_NAME),
23
+ win32con.SE_PRIVILEGE_ENABLED,
24
+ ),
25
+ (
26
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_TAKE_OWNERSHIP_NAME),
27
+ win32con.SE_PRIVILEGE_ENABLED,
28
+ ),
29
+ (
30
+ win32security.LookupPrivilegeValue("", ntsecuritycon.SE_CREATE_PERMANENT_NAME),
31
+ win32con.SE_PRIVILEGE_ENABLED,
32
+ ),
33
+ (
34
+ win32security.LookupPrivilegeValue("", "SeEnableDelegationPrivilege"),
35
+ win32con.SE_PRIVILEGE_ENABLED,
36
+ ), ##doesn't seem to be in ntsecuritycon.py ?
37
+ )
38
+
39
+ ph = win32api.GetCurrentProcess()
40
+ th = win32security.OpenProcessToken(
41
+ ph, win32security.TOKEN_ALL_ACCESS | win32con.TOKEN_ADJUST_PRIVILEGES
42
+ )
43
+ win32security.AdjustTokenPrivileges(th, 0, new_privs)
44
+
45
+ all_security_info = (
46
+ win32security.OWNER_SECURITY_INFORMATION
47
+ | win32security.GROUP_SECURITY_INFORMATION
48
+ | win32security.DACL_SECURITY_INFORMATION
49
+ | win32security.SACL_SECURITY_INFORMATION
50
+ )
51
+
52
+ sd = win32security.GetFileSecurity(fname, all_security_info)
53
+ old_dacl = sd.GetSecurityDescriptorDacl()
54
+ old_sacl = sd.GetSecurityDescriptorSacl()
55
+ old_group = sd.GetSecurityDescriptorGroup()
56
+
57
+ new_sd = win32security.SECURITY_DESCRIPTOR()
58
+ print(
59
+ "relative, valid, size: ",
60
+ new_sd.IsSelfRelative(),
61
+ new_sd.IsValid(),
62
+ new_sd.GetLength(),
63
+ )
64
+
65
+ my_sid = win32security.GetTokenInformation(th, ntsecuritycon.TokenUser)[0]
66
+ tmp_sid = win32security.LookupAccountName("", "tmp")[0]
67
+
68
+ new_sd.SetSecurityDescriptorSacl(1, old_sacl, 1)
69
+ new_sd.SetSecurityDescriptorDacl(1, old_dacl, 1)
70
+ new_sd.SetSecurityDescriptorOwner(tmp_sid, 0)
71
+ new_sd.SetSecurityDescriptorGroup(old_group, 0)
72
+
73
+ win32security.SetFileSecurity(fname, all_security_info, new_sd)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/set_policy_info.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32security
2
+
3
+ policy_handle = win32security.GetPolicyHandle("rupole", win32security.POLICY_ALL_ACCESS)
4
+
5
+ event_audit_info = win32security.LsaQueryInformationPolicy(
6
+ policy_handle, win32security.PolicyAuditEventsInformation
7
+ )
8
+ print(event_audit_info)
9
+
10
+ new_audit_info = list(event_audit_info[1])
11
+ new_audit_info[win32security.AuditCategoryPolicyChange] = (
12
+ win32security.POLICY_AUDIT_EVENT_SUCCESS | win32security.POLICY_AUDIT_EVENT_FAILURE
13
+ )
14
+ new_audit_info[win32security.AuditCategoryAccountLogon] = (
15
+ win32security.POLICY_AUDIT_EVENT_SUCCESS | win32security.POLICY_AUDIT_EVENT_FAILURE
16
+ )
17
+ new_audit_info[win32security.AuditCategoryLogon] = (
18
+ win32security.POLICY_AUDIT_EVENT_SUCCESS | win32security.POLICY_AUDIT_EVENT_FAILURE
19
+ )
20
+
21
+ win32security.LsaSetInformationPolicy(
22
+ policy_handle, win32security.PolicyAuditEventsInformation, (1, new_audit_info)
23
+ )
24
+
25
+ win32security.LsaClose(policy_handle)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/setkernelobjectsecurity.py ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32api
2
+ import win32con
3
+ import win32security
4
+
5
+ ## You need SE_RESTORE_NAME to be able to set the owner of a security descriptor to anybody
6
+ ## other than yourself or your primary group. Most admin logins don't have it by default, so
7
+ ## enabling it may fail
8
+ new_privs = (
9
+ (
10
+ win32security.LookupPrivilegeValue("", win32security.SE_SECURITY_NAME),
11
+ win32con.SE_PRIVILEGE_ENABLED,
12
+ ),
13
+ (
14
+ win32security.LookupPrivilegeValue("", win32security.SE_TCB_NAME),
15
+ win32con.SE_PRIVILEGE_ENABLED,
16
+ ),
17
+ (
18
+ win32security.LookupPrivilegeValue("", win32security.SE_SHUTDOWN_NAME),
19
+ win32con.SE_PRIVILEGE_ENABLED,
20
+ ),
21
+ (
22
+ win32security.LookupPrivilegeValue("", win32security.SE_RESTORE_NAME),
23
+ win32con.SE_PRIVILEGE_ENABLED,
24
+ ),
25
+ (
26
+ win32security.LookupPrivilegeValue("", win32security.SE_TAKE_OWNERSHIP_NAME),
27
+ win32con.SE_PRIVILEGE_ENABLED,
28
+ ),
29
+ (
30
+ win32security.LookupPrivilegeValue("", win32security.SE_CREATE_PERMANENT_NAME),
31
+ win32con.SE_PRIVILEGE_ENABLED,
32
+ ),
33
+ (
34
+ win32security.LookupPrivilegeValue("", win32security.SE_ENABLE_DELEGATION_NAME),
35
+ win32con.SE_PRIVILEGE_ENABLED,
36
+ ),
37
+ (
38
+ win32security.LookupPrivilegeValue("", win32security.SE_CHANGE_NOTIFY_NAME),
39
+ win32con.SE_PRIVILEGE_ENABLED,
40
+ ),
41
+ (
42
+ win32security.LookupPrivilegeValue("", win32security.SE_DEBUG_NAME),
43
+ win32con.SE_PRIVILEGE_ENABLED,
44
+ ),
45
+ (
46
+ win32security.LookupPrivilegeValue(
47
+ "", win32security.SE_PROF_SINGLE_PROCESS_NAME
48
+ ),
49
+ win32con.SE_PRIVILEGE_ENABLED,
50
+ ),
51
+ (
52
+ win32security.LookupPrivilegeValue("", win32security.SE_SYSTEM_PROFILE_NAME),
53
+ win32con.SE_PRIVILEGE_ENABLED,
54
+ ),
55
+ (
56
+ win32security.LookupPrivilegeValue("", win32security.SE_LOCK_MEMORY_NAME),
57
+ win32con.SE_PRIVILEGE_ENABLED,
58
+ ),
59
+ )
60
+
61
+ all_info = (
62
+ win32security.OWNER_SECURITY_INFORMATION
63
+ | win32security.GROUP_SECURITY_INFORMATION
64
+ | win32security.DACL_SECURITY_INFORMATION
65
+ | win32security.SACL_SECURITY_INFORMATION
66
+ )
67
+
68
+ pid = win32api.GetCurrentProcessId()
69
+ ph = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, 0, pid)
70
+ ## PROCESS_ALL_ACCESS does not contain ACCESS_SYSTEM_SECURITY (neccessy to do SACLs)
71
+ th = win32security.OpenProcessToken(
72
+ ph, win32security.TOKEN_ALL_ACCESS
73
+ ) ##win32con.TOKEN_ADJUST_PRIVILEGES)
74
+ old_privs = win32security.GetTokenInformation(th, win32security.TokenPrivileges)
75
+ desired_privs = tuple((e[0], win32con.SE_PRIVILEGE_ENABLED) for e in old_privs)
76
+ modified_privs = win32security.AdjustTokenPrivileges(
77
+ th, 0, desired_privs
78
+ ) # Will (partially) fail for new_privs (unless they are a subset of current ones)
79
+ gle = win32api.GetLastError()
80
+ if gle != 0:
81
+ print("AdjustTokenPrivileges error:", gle)
82
+ # print(modified_privs)
83
+ my_sid = win32security.GetTokenInformation(th, win32security.TokenUser)[0]
84
+ pwr_sid = win32security.LookupAccountName("", "Power Users")[0]
85
+ ## reopen process with ACCESS_SYSTEM_SECURITY now that sufficent privs are enabled
86
+ ph = win32api.OpenProcess(
87
+ win32con.PROCESS_ALL_ACCESS | win32con.ACCESS_SYSTEM_SECURITY, 0, pid
88
+ )
89
+
90
+ sd = win32security.GetKernelObjectSecurity(ph, all_info)
91
+ dacl = sd.GetSecurityDescriptorDacl()
92
+ if dacl is None:
93
+ dacl = win32security.ACL()
94
+ sacl = sd.GetSecurityDescriptorSacl()
95
+ if sacl is None:
96
+ sacl = win32security.ACL()
97
+
98
+ dacl_ace_cnt = dacl.GetAceCount()
99
+ sacl_ace_cnt = sacl.GetAceCount()
100
+
101
+ dacl.AddAccessAllowedAce(
102
+ dacl.GetAclRevision(), win32con.ACCESS_SYSTEM_SECURITY | win32con.WRITE_DAC, my_sid
103
+ )
104
+ sacl.AddAuditAccessAce(sacl.GetAclRevision(), win32con.GENERIC_ALL, my_sid, 1, 1)
105
+ sd.SetSecurityDescriptorDacl(1, dacl, 0)
106
+ sd.SetSecurityDescriptorSacl(1, sacl, 0)
107
+ sd.SetSecurityDescriptorGroup(pwr_sid, 0)
108
+ sd.SetSecurityDescriptorOwner(pwr_sid, 0)
109
+
110
+ win32security.SetKernelObjectSecurity(ph, all_info, sd)
111
+ new_sd = win32security.GetKernelObjectSecurity(ph, all_info)
112
+
113
+ if new_sd.GetSecurityDescriptorDacl().GetAceCount() != dacl_ace_cnt + 1:
114
+ print("New dacl doesn't contain extra ace ????")
115
+ if new_sd.GetSecurityDescriptorSacl().GetAceCount() != sacl_ace_cnt + 1:
116
+ print("New Sacl doesn't contain extra ace ????")
117
+ if (
118
+ win32security.LookupAccountSid("", new_sd.GetSecurityDescriptorOwner())[0]
119
+ != "Power Users"
120
+ ):
121
+ print("Owner not successfully set to Power Users !!!!!")
122
+ if (
123
+ win32security.LookupAccountSid("", new_sd.GetSecurityDescriptorGroup())[0]
124
+ != "Power Users"
125
+ ):
126
+ print("Group not successfully set to Power Users !!!!!")
127
+
128
+ sd.SetSecurityDescriptorSacl(0, None, 0)
129
+ win32security.SetKernelObjectSecurity(ph, win32security.SACL_SECURITY_INFORMATION, sd)
130
+ new_sd_1 = win32security.GetKernelObjectSecurity(
131
+ ph, win32security.SACL_SECURITY_INFORMATION
132
+ )
133
+ if new_sd_1.GetSecurityDescriptorSacl() is not None:
134
+ print("Unable to set Sacl to NULL !!!!!!!!")
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/setnamedsecurityinfo.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32api
2
+ import win32con
3
+ import win32process
4
+ import win32security
5
+
6
+ fname, tmp = win32api.GetTempFileName(win32api.GetTempPath(), "tmp")
7
+ print(fname)
8
+ ## You need SE_RESTORE_NAME to be able to set the owner of a security descriptor to anybody
9
+ ## other than yourself or your primary group. Most admin logins don't have it by default, so
10
+ ## enabling it may fail
11
+ new_privs = (
12
+ (
13
+ win32security.LookupPrivilegeValue("", win32security.SE_SECURITY_NAME),
14
+ win32con.SE_PRIVILEGE_ENABLED,
15
+ ),
16
+ (
17
+ win32security.LookupPrivilegeValue("", win32security.SE_TCB_NAME),
18
+ win32con.SE_PRIVILEGE_ENABLED,
19
+ ),
20
+ (
21
+ win32security.LookupPrivilegeValue("", win32security.SE_SHUTDOWN_NAME),
22
+ win32con.SE_PRIVILEGE_ENABLED,
23
+ ),
24
+ (
25
+ win32security.LookupPrivilegeValue("", win32security.SE_RESTORE_NAME),
26
+ win32con.SE_PRIVILEGE_ENABLED,
27
+ ),
28
+ (
29
+ win32security.LookupPrivilegeValue("", win32security.SE_TAKE_OWNERSHIP_NAME),
30
+ win32con.SE_PRIVILEGE_ENABLED,
31
+ ),
32
+ (
33
+ win32security.LookupPrivilegeValue("", win32security.SE_CREATE_PERMANENT_NAME),
34
+ win32con.SE_PRIVILEGE_ENABLED,
35
+ ),
36
+ (
37
+ win32security.LookupPrivilegeValue("", win32security.SE_ENABLE_DELEGATION_NAME),
38
+ win32con.SE_PRIVILEGE_ENABLED,
39
+ ),
40
+ (
41
+ win32security.LookupPrivilegeValue("", win32security.SE_CHANGE_NOTIFY_NAME),
42
+ win32con.SE_PRIVILEGE_ENABLED,
43
+ ),
44
+ (
45
+ win32security.LookupPrivilegeValue("", win32security.SE_DEBUG_NAME),
46
+ win32con.SE_PRIVILEGE_ENABLED,
47
+ ),
48
+ (
49
+ win32security.LookupPrivilegeValue(
50
+ "", win32security.SE_PROF_SINGLE_PROCESS_NAME
51
+ ),
52
+ win32con.SE_PRIVILEGE_ENABLED,
53
+ ),
54
+ (
55
+ win32security.LookupPrivilegeValue("", win32security.SE_SYSTEM_PROFILE_NAME),
56
+ win32con.SE_PRIVILEGE_ENABLED,
57
+ ),
58
+ (
59
+ win32security.LookupPrivilegeValue("", win32security.SE_LOCK_MEMORY_NAME),
60
+ win32con.SE_PRIVILEGE_ENABLED,
61
+ ),
62
+ )
63
+
64
+ all_info = (
65
+ win32security.OWNER_SECURITY_INFORMATION
66
+ | win32security.GROUP_SECURITY_INFORMATION
67
+ | win32security.DACL_SECURITY_INFORMATION
68
+ | win32security.SACL_SECURITY_INFORMATION
69
+ )
70
+
71
+ ph = win32process.GetCurrentProcess()
72
+ th = win32security.OpenProcessToken(
73
+ ph, win32security.TOKEN_ALL_ACCESS
74
+ ) ##win32con.TOKEN_ADJUST_PRIVILEGES)
75
+ win32security.AdjustTokenPrivileges(th, 0, new_privs)
76
+ my_sid = win32security.GetTokenInformation(th, win32security.TokenUser)[0]
77
+ pwr_sid = win32security.LookupAccountName("", "Power Users")[0]
78
+
79
+ sd = win32security.GetNamedSecurityInfo(fname, win32security.SE_FILE_OBJECT, all_info)
80
+ dacl = sd.GetSecurityDescriptorDacl()
81
+ if dacl is None:
82
+ dacl = win32security.ACL()
83
+ sacl = sd.GetSecurityDescriptorSacl()
84
+ if sacl is None:
85
+ sacl = win32security.ACL()
86
+
87
+ dacl_ace_cnt = dacl.GetAceCount()
88
+ sacl_ace_cnt = sacl.GetAceCount()
89
+
90
+ dacl.AddAccessAllowedAce(
91
+ dacl.GetAclRevision(), win32con.ACCESS_SYSTEM_SECURITY | win32con.WRITE_DAC, my_sid
92
+ )
93
+ sacl.AddAuditAccessAce(sacl.GetAclRevision(), win32con.GENERIC_ALL, my_sid, 1, 1)
94
+
95
+ win32security.SetNamedSecurityInfo(
96
+ fname, win32security.SE_FILE_OBJECT, all_info, pwr_sid, pwr_sid, dacl, sacl
97
+ )
98
+ new_sd = win32security.GetNamedSecurityInfo(
99
+ fname, win32security.SE_FILE_OBJECT, all_info
100
+ )
101
+
102
+ ## could do additional checking to make sure added ACE contains expected info
103
+ if new_sd.GetSecurityDescriptorDacl().GetAceCount() != dacl_ace_cnt + 1:
104
+ print("New dacl doesn't contain extra ace ????")
105
+ if new_sd.GetSecurityDescriptorSacl().GetAceCount() != sacl_ace_cnt + 1:
106
+ print("New Sacl doesn't contain extra ace ????")
107
+ if (
108
+ win32security.LookupAccountSid("", new_sd.GetSecurityDescriptorOwner())[0]
109
+ != "Power Users"
110
+ ):
111
+ print("Owner not successfully set to Power Users !!!!!")
112
+ if (
113
+ win32security.LookupAccountSid("", new_sd.GetSecurityDescriptorGroup())[0]
114
+ != "Power Users"
115
+ ):
116
+ print("Group not successfully set to Power Users !!!!!")
117
+
118
+ win32security.SetNamedSecurityInfo(
119
+ fname,
120
+ win32security.SE_FILE_OBJECT,
121
+ win32security.SACL_SECURITY_INFORMATION,
122
+ None,
123
+ None,
124
+ None,
125
+ None,
126
+ )
127
+ new_sd_1 = win32security.GetNamedSecurityInfo(
128
+ fname, win32security.SE_FILE_OBJECT, win32security.SACL_SECURITY_INFORMATION
129
+ )
130
+ if new_sd_1.GetSecurityDescriptorSacl() is not None:
131
+ print("Unable to set Sacl to NULL !!!!!!!!")
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/setsecurityinfo.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32api
2
+ import win32con
3
+ import win32security
4
+
5
+ ## You need SE_RESTORE_NAME to be able to set the owner of a security descriptor to anybody
6
+ ## other than yourself or your primary group. Most admin logins don't have it by default, so
7
+ ## enabling it may fail
8
+ new_privs = (
9
+ (
10
+ win32security.LookupPrivilegeValue("", win32security.SE_SECURITY_NAME),
11
+ win32con.SE_PRIVILEGE_ENABLED,
12
+ ),
13
+ (
14
+ win32security.LookupPrivilegeValue("", win32security.SE_TCB_NAME),
15
+ win32con.SE_PRIVILEGE_ENABLED,
16
+ ),
17
+ (
18
+ win32security.LookupPrivilegeValue("", win32security.SE_SHUTDOWN_NAME),
19
+ win32con.SE_PRIVILEGE_ENABLED,
20
+ ),
21
+ (
22
+ win32security.LookupPrivilegeValue("", win32security.SE_RESTORE_NAME),
23
+ win32con.SE_PRIVILEGE_ENABLED,
24
+ ),
25
+ (
26
+ win32security.LookupPrivilegeValue("", win32security.SE_TAKE_OWNERSHIP_NAME),
27
+ win32con.SE_PRIVILEGE_ENABLED,
28
+ ),
29
+ (
30
+ win32security.LookupPrivilegeValue("", win32security.SE_CREATE_PERMANENT_NAME),
31
+ win32con.SE_PRIVILEGE_ENABLED,
32
+ ),
33
+ (
34
+ win32security.LookupPrivilegeValue("", win32security.SE_ENABLE_DELEGATION_NAME),
35
+ win32con.SE_PRIVILEGE_ENABLED,
36
+ ),
37
+ (
38
+ win32security.LookupPrivilegeValue("", win32security.SE_CHANGE_NOTIFY_NAME),
39
+ win32con.SE_PRIVILEGE_ENABLED,
40
+ ),
41
+ (
42
+ win32security.LookupPrivilegeValue("", win32security.SE_DEBUG_NAME),
43
+ win32con.SE_PRIVILEGE_ENABLED,
44
+ ),
45
+ (
46
+ win32security.LookupPrivilegeValue(
47
+ "", win32security.SE_PROF_SINGLE_PROCESS_NAME
48
+ ),
49
+ win32con.SE_PRIVILEGE_ENABLED,
50
+ ),
51
+ (
52
+ win32security.LookupPrivilegeValue("", win32security.SE_SYSTEM_PROFILE_NAME),
53
+ win32con.SE_PRIVILEGE_ENABLED,
54
+ ),
55
+ (
56
+ win32security.LookupPrivilegeValue("", win32security.SE_LOCK_MEMORY_NAME),
57
+ win32con.SE_PRIVILEGE_ENABLED,
58
+ ),
59
+ )
60
+
61
+ all_info = (
62
+ win32security.OWNER_SECURITY_INFORMATION
63
+ | win32security.GROUP_SECURITY_INFORMATION
64
+ | win32security.DACL_SECURITY_INFORMATION
65
+ | win32security.SACL_SECURITY_INFORMATION
66
+ )
67
+
68
+ pid = win32api.GetCurrentProcessId()
69
+ ph = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, 0, pid)
70
+ ## PROCESS_ALL_ACCESS does not contain ACCESS_SYSTEM_SECURITY (neccessy to do SACLs)
71
+ th = win32security.OpenProcessToken(
72
+ ph, win32security.TOKEN_ALL_ACCESS
73
+ ) ##win32con.TOKEN_ADJUST_PRIVILEGES)
74
+ old_privs = win32security.AdjustTokenPrivileges(th, 0, new_privs)
75
+ my_sid = win32security.GetTokenInformation(th, win32security.TokenUser)[0]
76
+ pwr_sid = win32security.LookupAccountName("", "Power Users")[0]
77
+ ## reopen process with ACCESS_SYSTEM_SECURITY now that sufficent privs are enabled
78
+ ph = win32api.OpenProcess(
79
+ win32con.PROCESS_ALL_ACCESS | win32con.ACCESS_SYSTEM_SECURITY, 0, pid
80
+ )
81
+
82
+ sd = win32security.GetSecurityInfo(ph, win32security.SE_KERNEL_OBJECT, all_info)
83
+ dacl = sd.GetSecurityDescriptorDacl()
84
+ if dacl is None:
85
+ dacl = win32security.ACL()
86
+ sacl = sd.GetSecurityDescriptorSacl()
87
+ if sacl is None:
88
+ sacl = win32security.ACL()
89
+
90
+ dacl_ace_cnt = dacl.GetAceCount()
91
+ sacl_ace_cnt = sacl.GetAceCount()
92
+
93
+ dacl.AddAccessAllowedAce(
94
+ dacl.GetAclRevision(), win32con.ACCESS_SYSTEM_SECURITY | win32con.WRITE_DAC, my_sid
95
+ )
96
+ sacl.AddAuditAccessAce(sacl.GetAclRevision(), win32con.GENERIC_ALL, my_sid, 1, 1)
97
+
98
+ win32security.SetSecurityInfo(
99
+ ph, win32security.SE_KERNEL_OBJECT, all_info, pwr_sid, pwr_sid, dacl, sacl
100
+ )
101
+ new_sd = win32security.GetSecurityInfo(ph, win32security.SE_KERNEL_OBJECT, all_info)
102
+
103
+ if new_sd.GetSecurityDescriptorDacl().GetAceCount() != dacl_ace_cnt + 1:
104
+ print("New dacl doesn't contain extra ace ????")
105
+ if new_sd.GetSecurityDescriptorSacl().GetAceCount() != sacl_ace_cnt + 1:
106
+ print("New Sacl doesn't contain extra ace ????")
107
+ if (
108
+ win32security.LookupAccountSid("", new_sd.GetSecurityDescriptorOwner())[0]
109
+ != "Power Users"
110
+ ):
111
+ print("Owner not successfully set to Power Users !!!!!")
112
+ if (
113
+ win32security.LookupAccountSid("", new_sd.GetSecurityDescriptorGroup())[0]
114
+ != "Power Users"
115
+ ):
116
+ print("Group not successfully set to Power Users !!!!!")
117
+
118
+ win32security.SetSecurityInfo(
119
+ ph,
120
+ win32security.SE_KERNEL_OBJECT,
121
+ win32security.SACL_SECURITY_INFORMATION,
122
+ None,
123
+ None,
124
+ None,
125
+ None,
126
+ )
127
+ new_sd_1 = win32security.GetSecurityInfo(
128
+ ph, win32security.SE_KERNEL_OBJECT, win32security.SACL_SECURITY_INFORMATION
129
+ )
130
+ if new_sd_1.GetSecurityDescriptorSacl() is not None:
131
+ print("Unable to set Sacl to NULL !!!!!!!!")
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/setuserobjectsecurity.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import win32con
2
+ import win32process
3
+ import win32security
4
+
5
+ new_privs = (
6
+ (
7
+ win32security.LookupPrivilegeValue("", win32security.SE_SECURITY_NAME),
8
+ win32con.SE_PRIVILEGE_ENABLED,
9
+ ),
10
+ (
11
+ win32security.LookupPrivilegeValue("", win32security.SE_TCB_NAME),
12
+ win32con.SE_PRIVILEGE_ENABLED,
13
+ ),
14
+ (
15
+ win32security.LookupPrivilegeValue("", win32security.SE_SHUTDOWN_NAME),
16
+ win32con.SE_PRIVILEGE_ENABLED,
17
+ ),
18
+ (
19
+ win32security.LookupPrivilegeValue("", win32security.SE_RESTORE_NAME),
20
+ win32con.SE_PRIVILEGE_ENABLED,
21
+ ),
22
+ (
23
+ win32security.LookupPrivilegeValue("", win32security.SE_TAKE_OWNERSHIP_NAME),
24
+ win32con.SE_PRIVILEGE_ENABLED,
25
+ ),
26
+ (
27
+ win32security.LookupPrivilegeValue("", win32security.SE_CREATE_PERMANENT_NAME),
28
+ win32con.SE_PRIVILEGE_ENABLED,
29
+ ),
30
+ (
31
+ win32security.LookupPrivilegeValue("", win32security.SE_ENABLE_DELEGATION_NAME),
32
+ win32con.SE_PRIVILEGE_ENABLED,
33
+ ),
34
+ (
35
+ win32security.LookupPrivilegeValue("", win32security.SE_CHANGE_NOTIFY_NAME),
36
+ win32con.SE_PRIVILEGE_ENABLED,
37
+ ),
38
+ (
39
+ win32security.LookupPrivilegeValue("", win32security.SE_DEBUG_NAME),
40
+ win32con.SE_PRIVILEGE_ENABLED,
41
+ ),
42
+ (
43
+ win32security.LookupPrivilegeValue(
44
+ "", win32security.SE_PROF_SINGLE_PROCESS_NAME
45
+ ),
46
+ win32con.SE_PRIVILEGE_ENABLED,
47
+ ),
48
+ (
49
+ win32security.LookupPrivilegeValue("", win32security.SE_SYSTEM_PROFILE_NAME),
50
+ win32con.SE_PRIVILEGE_ENABLED,
51
+ ),
52
+ (
53
+ win32security.LookupPrivilegeValue("", win32security.SE_LOCK_MEMORY_NAME),
54
+ win32con.SE_PRIVILEGE_ENABLED,
55
+ ),
56
+ )
57
+
58
+ all_info = (
59
+ win32security.OWNER_SECURITY_INFORMATION
60
+ | win32security.GROUP_SECURITY_INFORMATION
61
+ | win32security.DACL_SECURITY_INFORMATION
62
+ | win32security.SACL_SECURITY_INFORMATION
63
+ )
64
+ info = (
65
+ win32security.OWNER_SECURITY_INFORMATION
66
+ | win32security.GROUP_SECURITY_INFORMATION
67
+ | win32security.DACL_SECURITY_INFORMATION
68
+ )
69
+
70
+ ph = win32process.GetCurrentProcess()
71
+ th = win32security.OpenProcessToken(
72
+ ph, win32security.TOKEN_ALL_ACCESS
73
+ ) ##win32con.TOKEN_ADJUST_PRIVILEGES)
74
+ win32security.AdjustTokenPrivileges(th, 0, new_privs)
75
+ my_sid = win32security.GetTokenInformation(th, win32security.TokenUser)[0]
76
+ pwr_sid = win32security.LookupAccountName("", "Power Users")[0]
77
+
78
+ h = win32process.GetProcessWindowStation()
79
+ sd = win32security.GetUserObjectSecurity(h, info)
80
+ dacl = sd.GetSecurityDescriptorDacl()
81
+ ace_cnt = dacl.GetAceCount()
82
+
83
+ dacl.AddAccessAllowedAce(
84
+ dacl.GetAclRevision(), win32con.ACCESS_SYSTEM_SECURITY | win32con.WRITE_DAC, my_sid
85
+ )
86
+ sd.SetSecurityDescriptorDacl(1, dacl, 0)
87
+ sd.SetSecurityDescriptorGroup(pwr_sid, 0)
88
+ sd.SetSecurityDescriptorOwner(pwr_sid, 0)
89
+
90
+ win32security.SetUserObjectSecurity(h, info, sd)
91
+ new_sd = win32security.GetUserObjectSecurity(h, info)
92
+ assert new_sd.GetSecurityDescriptorDacl().GetAceCount() == ace_cnt + 1, (
93
+ "Did not add an ace to the Dacl !!!!!!"
94
+ )
95
+ assert (
96
+ win32security.LookupAccountSid("", new_sd.GetSecurityDescriptorOwner())[0]
97
+ == "Power Users"
98
+ ), "Owner not successfully set to Power Users !!!!!"
99
+ assert (
100
+ win32security.LookupAccountSid("", new_sd.GetSecurityDescriptorGroup())[0]
101
+ == "Power Users"
102
+ ), "Group not successfully set to Power Users !!!!!"
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/sspi/fetch_url.py ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Fetches a URL from a web-server supporting NTLM authentication
3
+ eg, IIS.
4
+
5
+ If no arguments are specified, a default of http://localhost/localstart.asp
6
+ is used. This script does follow simple 302 redirections, so pointing at the
7
+ root of an IIS server is should work.
8
+ """
9
+
10
+ import http.client # sorry, this demo needs 2.3+
11
+ import optparse
12
+ import urllib.error
13
+ import urllib.parse
14
+ import urllib.request
15
+ from base64 import decodestring, encodestring
16
+
17
+ from sspi import ClientAuth
18
+
19
+ options = None # set to optparse options object
20
+
21
+
22
+ def open_url(host, url):
23
+ h = http.client.HTTPConnection(host)
24
+ # h.set_debuglevel(9)
25
+ h.putrequest("GET", url)
26
+ h.endheaders()
27
+ resp = h.getresponse()
28
+ print("Initial response is", resp.status, resp.reason)
29
+ body = resp.read()
30
+ if resp.status == 302: # object moved
31
+ url = "/" + resp.msg["location"]
32
+ resp.close()
33
+ h.putrequest("GET", url)
34
+ h.endheaders()
35
+ resp = h.getresponse()
36
+ print("After redirect response is", resp.status, resp.reason)
37
+ if options.show_headers:
38
+ print("Initial response headers:")
39
+ for name, val in resp.msg.items():
40
+ print(f" {name}: {val}")
41
+ if options.show_body:
42
+ print(body)
43
+ if resp.status == 401:
44
+ # 401: Unauthorized - here is where the real work starts
45
+ auth_info = None
46
+ if options.user or options.domain or options.password:
47
+ auth_info = options.user, options.domain, options.password
48
+ ca = ClientAuth("NTLM", auth_info=auth_info)
49
+ auth_scheme = ca.pkg_info["Name"]
50
+ data = None
51
+ while 1:
52
+ err, out_buf = ca.authorize(data)
53
+ data = out_buf[0].Buffer
54
+ # Encode it as base64 as required by HTTP
55
+ auth = encodestring(data).replace("\012", "")
56
+ h.putrequest("GET", url)
57
+ h.putheader("Authorization", auth_scheme + " " + auth)
58
+ h.putheader("Content-Length", "0")
59
+ h.endheaders()
60
+ resp = h.getresponse()
61
+ if options.show_headers:
62
+ print("Token dance headers:")
63
+ for name, val in resp.msg.items():
64
+ print(f" {name}: {val}")
65
+
66
+ if err == 0:
67
+ break
68
+ else:
69
+ if resp.status != 401:
70
+ print("Eeek - got response", resp.status)
71
+ cl = resp.msg.get("content-length")
72
+ if cl:
73
+ print(repr(resp.read(int(cl))))
74
+ else:
75
+ print("no content!")
76
+
77
+ assert resp.status == 401, resp.status
78
+
79
+ assert not resp.will_close, "NTLM is per-connection - must not close"
80
+ schemes = [
81
+ s.strip() for s in resp.msg.get("WWW-Authenticate", "").split(",")
82
+ ]
83
+ for scheme in schemes:
84
+ if scheme.startswith(auth_scheme):
85
+ data = decodestring(scheme[len(auth_scheme) + 1 :])
86
+ break
87
+ else:
88
+ print(f"Could not find scheme '{auth_scheme}' in schemes {schemes!r}")
89
+ break
90
+
91
+ resp.read()
92
+ print("Final response status is", resp.status, resp.reason)
93
+ if resp.status == 200:
94
+ # Worked!
95
+ # Check we can read it again without re-authenticating.
96
+ if resp.will_close:
97
+ print(
98
+ "EEEK - response will close, but NTLM is per connection - it must stay open"
99
+ )
100
+ body = resp.read()
101
+ if options.show_body:
102
+ print("Final response body:")
103
+ print(body)
104
+ h.putrequest("GET", url)
105
+ h.endheaders()
106
+ resp = h.getresponse()
107
+ print("Second fetch response is", resp.status, resp.reason)
108
+ if options.show_headers:
109
+ print("Second response headers:")
110
+ for name, val in resp.msg.items():
111
+ print(f" {name}: {val}")
112
+
113
+ resp.read(int(resp.msg.get("content-length", 0)))
114
+ elif resp.status == 500:
115
+ print("Error text")
116
+ print(resp.read())
117
+ else:
118
+ if options.show_body:
119
+ cl = resp.msg.get("content-length")
120
+ print(resp.read(int(cl)))
121
+
122
+
123
+ if __name__ == "__main__":
124
+ parser = optparse.OptionParser(description=__doc__)
125
+
126
+ parser.add_option(
127
+ "",
128
+ "--show-body",
129
+ action="store_true",
130
+ help="print the body of each response as it is received",
131
+ )
132
+
133
+ parser.add_option(
134
+ "",
135
+ "--show-headers",
136
+ action="store_true",
137
+ help="print the headers of each response as it is received",
138
+ )
139
+
140
+ parser.add_option("", "--user", action="store", help="The username to login with")
141
+
142
+ parser.add_option(
143
+ "", "--password", action="store", help="The password to login with"
144
+ )
145
+
146
+ parser.add_option("", "--domain", action="store", help="The domain to login to")
147
+
148
+ options, args = parser.parse_args()
149
+ if not args:
150
+ print("Run with --help for usage details")
151
+ args = ["http://localhost/localstart.asp"]
152
+ for url in args:
153
+ scheme, netloc, path, params, query, fragment = urllib.parse.urlparse(url)
154
+ if (scheme != "http") or params or query or fragment:
155
+ parser.error("Scheme must be http, URL must be simple")
156
+
157
+ print(f"Opening '{path}' from '{netloc}'")
158
+ r = open_url(netloc, path)
loan-advisor-agent/.venv/Lib/site-packages/win32/Demos/security/sspi/simple_auth.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # A demo of basic SSPI authentication.
2
+ # There is a 'client' context and a 'server' context - typically these will
3
+ # be on different machines (here they are in the same process, but the same
4
+ # concepts apply)
5
+ import sspi
6
+ import sspicon
7
+ import win32api
8
+ import win32security
9
+
10
+
11
+ def lookup_ret_code(err):
12
+ for k, v in sspicon.__dict__.items():
13
+ if k[0:6] in ("SEC_I_", "SEC_E_") and v == err:
14
+ return k
15
+
16
+
17
+ """
18
+ pkg_name='Kerberos'
19
+ sspiclient=SSPIClient(pkg_name, win32api.GetUserName(), ## target spn is ourself
20
+ None, None, ## use none for client name and authentication information for current context
21
+ ## 'username', ('username','domain.com','passwd'),
22
+ sspicon.ISC_REQ_INTEGRITY|sspicon.ISC_REQ_SEQUENCE_DETECT|sspicon.ISC_REQ_REPLAY_DETECT| \
23
+ sspicon.ISC_REQ_DELEGATE|sspicon.ISC_REQ_CONFIDENTIALITY|sspicon.ISC_REQ_USE_SESSION_KEY)
24
+ sspiserver=SSPIServer(pkg_name, None,
25
+ sspicon.ASC_REQ_INTEGRITY|sspicon.ASC_REQ_SEQUENCE_DETECT|sspicon.ASC_REQ_REPLAY_DETECT| \
26
+ sspicon.ASC_REQ_DELEGATE|sspicon.ASC_REQ_CONFIDENTIALITY|sspicon.ASC_REQ_STREAM|sspicon.ASC_REQ_USE_SESSION_KEY)
27
+ """
28
+
29
+ pkg_name = "NTLM"
30
+
31
+ # Setup the 2 contexts.
32
+ sspiclient = sspi.ClientAuth(pkg_name)
33
+ sspiserver = sspi.ServerAuth(pkg_name)
34
+
35
+ # Perform the authentication dance, each loop exchanging more information
36
+ # on the way to completing authentication.
37
+ sec_buffer = None
38
+ while 1:
39
+ err, sec_buffer = sspiclient.authorize(sec_buffer)
40
+ err, sec_buffer = sspiserver.authorize(sec_buffer)
41
+ if err == 0:
42
+ break
43
+
44
+ # The server can now impersonate the client. In this demo the 2 users will
45
+ # always be the same.
46
+ sspiserver.ctxt.ImpersonateSecurityContext()
47
+ print("Impersonated user: ", win32api.GetUserNameEx(win32api.NameSamCompatible))
48
+ sspiserver.ctxt.RevertSecurityContext()
49
+ print("Reverted to self: ", win32api.GetUserName())
50
+
51
+ pkg_size_info = sspiclient.ctxt.QueryContextAttributes(sspicon.SECPKG_ATTR_SIZES)
52
+ # Now sign some data
53
+ msg = "some data to be encrypted ......"
54
+
55
+ sigsize = pkg_size_info["MaxSignature"]
56
+ sigbuf = win32security.PySecBufferDescType()
57
+ sigbuf.append(win32security.PySecBufferType(len(msg), sspicon.SECBUFFER_DATA))
58
+ sigbuf.append(win32security.PySecBufferType(sigsize, sspicon.SECBUFFER_TOKEN))
59
+ sigbuf[0].Buffer = msg
60
+ sspiclient.ctxt.MakeSignature(0, sigbuf, 1)
61
+ sspiserver.ctxt.VerifySignature(sigbuf, 1)
62
+
63
+ # And finally encrypt some.
64
+ trailersize = pkg_size_info["SecurityTrailer"]
65
+ encbuf = win32security.PySecBufferDescType()
66
+ encbuf.append(win32security.PySecBufferType(len(msg), sspicon.SECBUFFER_DATA))
67
+ encbuf.append(win32security.PySecBufferType(trailersize, sspicon.SECBUFFER_TOKEN))
68
+ encbuf[0].Buffer = msg
69
+ sspiclient.ctxt.EncryptMessage(0, encbuf, 1)
70
+ print(f"Encrypted data: {encbuf[0].Buffer!r}")
71
+ sspiserver.ctxt.DecryptMessage(encbuf, 1)
72
+ print(f"Encrypted data: {encbuf[0].Buffer}")