33package crypto
44
55import (
6- "fmt"
7- "syscall"
8- "unsafe"
6+ "github.com/moond4rk/hackbrowserdata/utils/winapi"
97)
108
119// gcmNonceSize is defined in crypto.go (cross-platform).
@@ -32,47 +30,10 @@ func DecryptYandex(key, ciphertext []byte) ([]byte, error) {
3230 return AESGCMDecrypt (key , nonce , payload )
3331}
3432
35- type dataBlob struct {
36- cbData uint32
37- pbData * byte
38- }
39-
40- func newBlob (d []byte ) * dataBlob {
41- if len (d ) == 0 {
42- return & dataBlob {}
43- }
44- return & dataBlob {
45- pbData : & d [0 ],
46- cbData : uint32 (len (d )),
47- }
48- }
49-
50- func (b * dataBlob ) bytes () []byte {
51- d := make ([]byte , b .cbData )
52- copy (d , (* [1 << 30 ]byte )(unsafe .Pointer (b .pbData ))[:])
53- return d
54- }
55-
56- // DecryptDPAPI (Data Protection Application Programming Interface)
57- // is a simple cryptographic application programming interface
58- // available as a built-in component in Windows 2000 and
59- // later versions of Microsoft Windows operating systems
33+ // DecryptDPAPI decrypts a DPAPI-protected blob using the current user's
34+ // master key. The actual Win32 call (and its DATA_BLOB / LocalFree dance)
35+ // lives in utils/winapi so every package that needs a syscall handle
36+ // shares a single declaration instead of re-opening Crypt32.dll per call.
6037func DecryptDPAPI (ciphertext []byte ) ([]byte , error ) {
61- crypt32 := syscall .NewLazyDLL ("Crypt32.dll" )
62- kernel32 := syscall .NewLazyDLL ("Kernel32.dll" )
63- unprotectDataProc := crypt32 .NewProc ("CryptUnprotectData" )
64- localFreeProc := kernel32 .NewProc ("LocalFree" )
65-
66- var outBlob dataBlob
67- r , _ , err := unprotectDataProc .Call (
68- uintptr (unsafe .Pointer (newBlob (ciphertext ))),
69- 0 , 0 , 0 , 0 , 0 ,
70- uintptr (unsafe .Pointer (& outBlob )),
71- )
72- if r == 0 {
73- return nil , fmt .Errorf ("CryptUnprotectData failed with error %w" , err )
74- }
75-
76- defer localFreeProc .Call (uintptr (unsafe .Pointer (outBlob .pbData )))
77- return outBlob .bytes (), nil
38+ return winapi .DecryptDPAPI (ciphertext )
7839}
0 commit comments