Module: Guid_Win32_
- Included in:
- Guid
- Defined in:
- lib/wwmd/guid.rb
Overview
:nodoc:
Constant Summary collapse
- PROV_RSA_FULL =
1
- CRYPT_VERIFYCONTEXT =
0xF0000000
- FORMAT_MESSAGE_IGNORE_INSERTS =
0x00000200
- FORMAT_MESSAGE_FROM_SYSTEM =
0x00001000
- CryptAcquireContext =
Win32API.new("advapi32", "CryptAcquireContext", 'PPPII', 'L')
- CryptGenRandom =
Win32API.new("advapi32", "CryptGenRandom", 'LIP', 'L')
- CryptReleaseContext =
Win32API.new("advapi32", "CryptReleaseContext", 'LI', 'L')
- GetLastError =
Win32API.new("kernel32", "GetLastError", '', 'L')
- FormatMessageA =
Win32API.new("kernel32", "FormatMessageA", 'LPLLPLPPPPPPPP', 'L')
Instance Method Summary collapse
Instance Method Details
#initialize ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/wwmd/guid.rb', line 41 def initialize hProvStr = " " * 4 if CryptAcquireContext.call(hProvStr, nil, nil, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) == 0 raise SystemCallError, "CryptAcquireContext failed: #{lastErrorMessage}" end hProv, = hProvStr.unpack('L') @bytes = " " * 16 if CryptGenRandom.call(hProv, 16, @bytes) == 0 raise SystemCallError, "CryptGenRandom failed: #{lastErrorMessage}" end if CryptReleaseContext.call(hProv, 0) == 0 raise SystemCallError, "CryptReleaseContext failed: #{lastErrorMessage}" end end |
#lastErrorMessage ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/wwmd/guid.rb', line 31 def lastErrorMessage code = GetLastError.call msg = "\0" * 1024 len = FormatMessageA.call(FORMAT_MESSAGE_IGNORE_INSERTS + FORMAT_MESSAGE_FROM_SYSTEM, 0, code, 0, msg, 1024, nil, nil, nil, nil, nil, nil, nil, nil) msg[0, len].tr("\r", '').chomp end |