Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
This is a drop-in replacement for the Win32API library currently part of Ruby's standard library.
require 'win32/api'
include Win32
# Typical example - Get user name
buf = 0.chr * 260
len = [buf.length].pack('L')
GetUserName = API.new('GetUserName', 'PP', 'I', 'advapi32')
GetUserName.call(buf, len)
puts buf.strip
# Callback example - Enumerate windows
EnumWindows = API.new('EnumWindows', 'KP', 'L', 'user32')
GetWindowText = API.new('GetWindowText', 'LPI', 'I', 'user32')
EnumWindowsProc = API::Callback.new('LP', 'I'){ |handle, param|
buf = "\0" * 200
GetWindowText.call(handle, buf, 200);
puts buf.strip unless buf.strip.empty?
buf.index(param).nil? ? true : false
}
EnumWindows.call(EnumWindowsProc, 'UEDIT32')
# Raw function pointer example - System beep
LoadLibrary = API.new('LoadLibrary', 'P', 'L')
GetProcAddress = API.new('GetProcAddress', 'LP', 'L')
hlib = LoadLibrary.call('user32')
addr = GetProcAddress.call(hlib, 'MessageBeep')
func = Win32::API::Function.new(addr, 'L', 'L')
func.call(0)
NOTE: Some of the information below is now out of date, but explains my motivation at the time the project was originally created.
The current Win32API library that ships with the standard library has been slated for removal from Ruby 2.0 and it will not receive any updates in the Ruby 1.8.x branch. I have far too many libraries invested in it to let it die at this point.
In addition, the current Win32API library was written in the bad old Ruby 1.6.x days, which means it doesn't use the newer allocation framework. There were several other refactorings that I felt it needed to more closely match how it was actually being used in practice.
The first order of business was changing the order of the arguments. By moving the DLL name from first to last, I was able to provide reasonable default arguments for the prototype, return type and the DLL. Only the function name is required now.
There was a laundry list of other refactorings that were needed: sensical instance variable names with proper accessors, removing support for lower case prototype and return value characters that no one used in practice, better naming conventions, the addition of RDoc ready comments and, especially, callback and raw function pointer support.
Most importantly, we can now add, modify and fix any features that we feel best benefit our end users.
As of win32-api 1.4.8 a binary gem is shipped that contains binaries for both Ruby 1.8, Ruby 1.9, and 2.x. For Ruby 2.x, both 32 and 64 bit binaries are included as of release 1.5.0.
The file under lib/win32 dynamically requires the correct binary based on your version of Ruby.
The source file contains inline RDoc documentation. If you installed this file as a gem, then you have the docs. Run "gem server" and point your browser at http://localhost:8808 to see them.
This package is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
Possible callback issues when dealing with multi-threaded applications.
Please submit any bug reports to the project page at https://github.com/cosmo0920/win32-api
Although this library is free, please consider having your company setup a gittip if used by your company professionally.
http://www.gittip.com/djberg96/
I really don't have future plans for this library since you should use FFI as your preferred C interface going forward. All of my own projects have since been converted to either use FFI or an analogous OLE interface.
I will continue to maintain this library as long as there are folks out there who are still using it, but I strongly encourage you to convert your projects to FFI when possible.
(C) 2003-2015 Daniel J. Berger
(C) 2016-2020 Hiroshi Hatake
All Rights Reserved
Artistic 2.0
Daniel J. Berger
Park Heesob
Hiroshi Hatake
FAQs
Unknown package
We found that win32-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.