From fda362e85d3525d7a1b7723b7e783c01f501eff7 Mon Sep 17 00:00:00 2001 From: Huzaif Mushtaq Mir Date: Tue, 23 Dec 2025 12:17:49 +0530 Subject: [PATCH 1/2] handle buffer size for wchars --- examples/LexActivator.rb | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/examples/LexActivator.rb b/examples/LexActivator.rb index 01282bd..46627b4 100644 --- a/examples/LexActivator.rb +++ b/examples/LexActivator.rb @@ -22,7 +22,7 @@ def self.encode_utf16(input) def self.decode_utf16(input) if FFI::Platform::IS_WINDOWS - "#{input}\0".force_encoding("UTF-16LE").encode("UTF-8", :invalid => :replace, :undef => :replace) + input.force_encoding("UTF-16LE").encode("UTF-8", :invalid => :replace, :undef => :replace) else input end @@ -36,34 +36,42 @@ module PermissionFlags end BUFFER_SIZE_256 = 256 + BUFFER_SIZE_4096 = 4096 MAX_METADATA_SIZE = 100 + # Helper to select correct type for wide strings + if FFI::Platform::IS_WINDOWS + CHAR = :ushort # wchar_t is 2 bytes (UTF-16LE) on Windows + else + CHAR = :char # char for non-Windows + end + class OrganizationAddress < FFI::Struct - layout :addressLine1, [:char, BUFFER_SIZE_256], - :addressLine2, [:char, BUFFER_SIZE_256], - :city, [:char, BUFFER_SIZE_256], - :state, [:char, BUFFER_SIZE_256], - :country, [:char, BUFFER_SIZE_256], - :postalCode, [:char, BUFFER_SIZE_256] + layout :addressLine1, [CHAR, BUFFER_SIZE_256], + :addressLine2, [CHAR, BUFFER_SIZE_256], + :city, [CHAR, BUFFER_SIZE_256], + :state, [CHAR, BUFFER_SIZE_256], + :country, [CHAR, BUFFER_SIZE_256], + :postalCode, [CHAR, BUFFER_SIZE_256] end class Metadata < FFI::Struct - layout :key, [:char, BUFFER_SIZE_256], - :value, [:char, BUFFER_SIZE_256] + layout :key, [CHAR, BUFFER_SIZE_256], + :value, [CHAR, BUFFER_SIZE_4096] end class UserLicense < FFI::Struct layout :allowedActivations, :int64, :allowedDeactivations, :int64, - :key, [:char, BUFFER_SIZE_256], - :type, [:char, BUFFER_SIZE_256], - :metadata, [Metadata, MAX_METADATA_SIZE] + :key, [CHAR, BUFFER_SIZE_256], + :type, [CHAR, BUFFER_SIZE_256], + :metadata, [Metadata, MAX_METADATA_SIZE] end class FeatureEntitlement < FFI::Struct - layout :featureName, [:char, BUFFER_SIZE_256], - :featureDisplayName, [:char, BUFFER_SIZE_256], - :value, [:char, BUFFER_SIZE_256] + layout :featureName, [CHAR, BUFFER_SIZE_256], + :featureDisplayName, [CHAR, BUFFER_SIZE_256], + :value, [CHAR, BUFFER_SIZE_256] end # @method SetProductFile(file_path) From 43cea8166a9ee5c00a8ac109251eb256f4a3f428 Mon Sep 17 00:00:00 2001 From: Huzaif Mushtaq Mir Date: Tue, 23 Dec 2025 17:06:38 +0530 Subject: [PATCH 2/2] fix: revert \0 changes --- examples/LexActivator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/LexActivator.rb b/examples/LexActivator.rb index 46627b4..4e27416 100644 --- a/examples/LexActivator.rb +++ b/examples/LexActivator.rb @@ -22,7 +22,7 @@ def self.encode_utf16(input) def self.decode_utf16(input) if FFI::Platform::IS_WINDOWS - input.force_encoding("UTF-16LE").encode("UTF-8", :invalid => :replace, :undef => :replace) + "#{input}\0".force_encoding("UTF-16LE").encode("UTF-8", :invalid => :replace, :undef => :replace) else input end