openc3 5.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +18 -0
- data/Guardfile +35 -0
- data/LICENSE.txt +727 -0
- data/README.md +37 -0
- data/Rakefile +131 -0
- data/bin/cstol_converter +1178 -0
- data/bin/openc3cli +531 -0
- data/bin/rubysloc +139 -0
- data/data/config/_array_params.yaml +23 -0
- data/data/config/_id_items.yaml +24 -0
- data/data/config/_id_params.yaml +58 -0
- data/data/config/_interfaces.yaml +214 -0
- data/data/config/_interfaces.yaml.err +1017 -0
- data/data/config/_items.yaml +20 -0
- data/data/config/_params.yaml +60 -0
- data/data/config/cmd_tlm_server.yaml +136 -0
- data/data/config/command.yaml +44 -0
- data/data/config/command_modifiers.yaml +160 -0
- data/data/config/command_telemetry.yaml +3 -0
- data/data/config/interface_modifiers.yaml +104 -0
- data/data/config/item_modifiers.yaml +221 -0
- data/data/config/microservice.yaml +78 -0
- data/data/config/param_item_modifiers.yaml +52 -0
- data/data/config/parameter_modifiers.yaml +200 -0
- data/data/config/plugins.yaml +80 -0
- data/data/config/protocols.yaml +290 -0
- data/data/config/screen.yaml +147 -0
- data/data/config/table_manager.yaml +89 -0
- data/data/config/table_parameter_modifiers.yaml +9 -0
- data/data/config/target.yaml +142 -0
- data/data/config/target_config.yaml +94 -0
- data/data/config/telemetry.yaml +87 -0
- data/data/config/telemetry_modifiers.yaml +159 -0
- data/data/config/tool.yaml +63 -0
- data/data/config/unknown.yaml +3 -0
- data/data/config/widgets.yaml +1505 -0
- data/ext/mkrf_conf.rb +49 -0
- data/ext/openc3/ext/array/array.c +122 -0
- data/ext/openc3/ext/array/extconf.rb +13 -0
- data/ext/openc3/ext/buffered_file/buffered_file.c +198 -0
- data/ext/openc3/ext/buffered_file/extconf.rb +13 -0
- data/ext/openc3/ext/config_parser/config_parser.c +280 -0
- data/ext/openc3/ext/config_parser/extconf.rb +13 -0
- data/ext/openc3/ext/crc/crc.c +351 -0
- data/ext/openc3/ext/crc/extconf.rb +13 -0
- data/ext/openc3/ext/openc3_io/extconf.rb +13 -0
- data/ext/openc3/ext/openc3_io/openc3_io.c +158 -0
- data/ext/openc3/ext/packet/extconf.rb +13 -0
- data/ext/openc3/ext/packet/packet.c +318 -0
- data/ext/openc3/ext/platform/extconf.rb +13 -0
- data/ext/openc3/ext/platform/platform.c +134 -0
- data/ext/openc3/ext/polynomial_conversion/extconf.rb +13 -0
- data/ext/openc3/ext/polynomial_conversion/polynomial_conversion.c +79 -0
- data/ext/openc3/ext/string/extconf.rb +13 -0
- data/ext/openc3/ext/string/string.c +63 -0
- data/ext/openc3/ext/structure/structure.c +1719 -0
- data/ext/openc3/ext/tabbed_plots_config/extconf.rb +13 -0
- data/ext/openc3/ext/tabbed_plots_config/tabbed_plots_config.c +62 -0
- data/ext/openc3/ext/telemetry/extconf.rb +13 -0
- data/ext/openc3/ext/telemetry/telemetry.c +336 -0
- data/lib/cosmos.rb +20 -0
- data/lib/cosmosc2.rb +20 -0
- data/lib/openc3/api/api.rb +39 -0
- data/lib/openc3/api/authorized_api.rb +30 -0
- data/lib/openc3/api/cmd_api.rb +451 -0
- data/lib/openc3/api/config_api.rb +58 -0
- data/lib/openc3/api/interface_api.rb +117 -0
- data/lib/openc3/api/limits_api.rb +375 -0
- data/lib/openc3/api/router_api.rb +117 -0
- data/lib/openc3/api/settings_api.rb +70 -0
- data/lib/openc3/api/target_api.rb +78 -0
- data/lib/openc3/api/tlm_api.rb +455 -0
- data/lib/openc3/bridge/bridge.rb +54 -0
- data/lib/openc3/bridge/bridge_config.rb +167 -0
- data/lib/openc3/bridge/bridge_interface_thread.rb +42 -0
- data/lib/openc3/bridge/bridge_router_thread.rb +42 -0
- data/lib/openc3/ccsds/ccsds_packet.rb +68 -0
- data/lib/openc3/ccsds/ccsds_parser.rb +148 -0
- data/lib/openc3/config/config_parser.rb +549 -0
- data/lib/openc3/config/meta_config_parser.rb +74 -0
- data/lib/openc3/conversions/conversion.rb +70 -0
- data/lib/openc3/conversions/generic_conversion.rb +83 -0
- data/lib/openc3/conversions/packet_time_formatted_conversion.rb +43 -0
- data/lib/openc3/conversions/packet_time_seconds_conversion.rb +43 -0
- data/lib/openc3/conversions/polynomial_conversion.rb +87 -0
- data/lib/openc3/conversions/processor_conversion.rb +70 -0
- data/lib/openc3/conversions/received_count_conversion.rb +38 -0
- data/lib/openc3/conversions/received_time_formatted_conversion.rb +42 -0
- data/lib/openc3/conversions/received_time_seconds_conversion.rb +42 -0
- data/lib/openc3/conversions/segmented_polynomial_conversion.rb +171 -0
- data/lib/openc3/conversions/unix_time_conversion.rb +68 -0
- data/lib/openc3/conversions/unix_time_formatted_conversion.rb +49 -0
- data/lib/openc3/conversions/unix_time_seconds_conversion.rb +49 -0
- data/lib/openc3/conversions.rb +34 -0
- data/lib/openc3/core_ext/array.rb +416 -0
- data/lib/openc3/core_ext/binding.rb +29 -0
- data/lib/openc3/core_ext/class.rb +72 -0
- data/lib/openc3/core_ext/exception.rb +61 -0
- data/lib/openc3/core_ext/file.rb +83 -0
- data/lib/openc3/core_ext/hash.rb +37 -0
- data/lib/openc3/core_ext/io.rb +134 -0
- data/lib/openc3/core_ext/kernel.rb +42 -0
- data/lib/openc3/core_ext/math.rb +128 -0
- data/lib/openc3/core_ext/matrix.rb +156 -0
- data/lib/openc3/core_ext/objectspace.rb +36 -0
- data/lib/openc3/core_ext/openc3_io.rb +57 -0
- data/lib/openc3/core_ext/range.rb +27 -0
- data/lib/openc3/core_ext/socket.rb +38 -0
- data/lib/openc3/core_ext/string.rb +389 -0
- data/lib/openc3/core_ext/stringio.rb +33 -0
- data/lib/openc3/core_ext/time.rb +508 -0
- data/lib/openc3/core_ext.rb +36 -0
- data/lib/openc3/interfaces/interface.rb +498 -0
- data/lib/openc3/interfaces/linc_interface.rb +475 -0
- data/lib/openc3/interfaces/protocols/burst_protocol.rb +192 -0
- data/lib/openc3/interfaces/protocols/crc_protocol.rb +193 -0
- data/lib/openc3/interfaces/protocols/fixed_protocol.rb +155 -0
- data/lib/openc3/interfaces/protocols/ignore_packet_protocol.rb +56 -0
- data/lib/openc3/interfaces/protocols/length_protocol.rb +165 -0
- data/lib/openc3/interfaces/protocols/override_protocol.rb +60 -0
- data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +206 -0
- data/lib/openc3/interfaces/protocols/protocol.rb +82 -0
- data/lib/openc3/interfaces/protocols/template_protocol.rb +261 -0
- data/lib/openc3/interfaces/protocols/terminated_protocol.rb +93 -0
- data/lib/openc3/interfaces/serial_interface.rb +94 -0
- data/lib/openc3/interfaces/simulated_target_interface.rb +168 -0
- data/lib/openc3/interfaces/stream_interface.rb +81 -0
- data/lib/openc3/interfaces/tcpip_client_interface.rb +69 -0
- data/lib/openc3/interfaces/tcpip_server_interface.rb +629 -0
- data/lib/openc3/interfaces/udp_interface.rb +169 -0
- data/lib/openc3/interfaces.rb +44 -0
- data/lib/openc3/io/buffered_file.rb +109 -0
- data/lib/openc3/io/io_multiplexer.rb +80 -0
- data/lib/openc3/io/json_api_object.rb +208 -0
- data/lib/openc3/io/json_drb.rb +335 -0
- data/lib/openc3/io/json_drb_object.rb +114 -0
- data/lib/openc3/io/json_drb_rack.rb +84 -0
- data/lib/openc3/io/json_rpc.rb +420 -0
- data/lib/openc3/io/openc3_snmp.rb +58 -0
- data/lib/openc3/io/posix_serial_driver.rb +156 -0
- data/lib/openc3/io/raw_logger.rb +167 -0
- data/lib/openc3/io/raw_logger_pair.rb +77 -0
- data/lib/openc3/io/serial_driver.rb +105 -0
- data/lib/openc3/io/stderr.rb +43 -0
- data/lib/openc3/io/stdout.rb +43 -0
- data/lib/openc3/io/udp_sockets.rb +194 -0
- data/lib/openc3/io/win32_serial_driver.rb +196 -0
- data/lib/openc3/logs/log_writer.rb +302 -0
- data/lib/openc3/logs/packet_log_constants.rb +62 -0
- data/lib/openc3/logs/packet_log_reader.rb +345 -0
- data/lib/openc3/logs/packet_log_writer.rb +299 -0
- data/lib/openc3/logs/text_log_writer.rb +68 -0
- data/lib/openc3/logs.rb +25 -0
- data/lib/openc3/microservices/cleanup_microservice.rb +68 -0
- data/lib/openc3/microservices/decom_microservice.rb +136 -0
- data/lib/openc3/microservices/interface_microservice.rb +532 -0
- data/lib/openc3/microservices/log_microservice.rb +108 -0
- data/lib/openc3/microservices/microservice.rb +204 -0
- data/lib/openc3/microservices/plugin_microservice.rb +43 -0
- data/lib/openc3/microservices/reaction_microservice.rb +541 -0
- data/lib/openc3/microservices/reducer_microservice.rb +313 -0
- data/lib/openc3/microservices/router_microservice.rb +44 -0
- data/lib/openc3/microservices/text_log_microservice.rb +84 -0
- data/lib/openc3/microservices/timeline_microservice.rb +363 -0
- data/lib/openc3/microservices/trigger_group_microservice.rb +638 -0
- data/lib/openc3/models/activity_model.rb +319 -0
- data/lib/openc3/models/auth_model.rb +65 -0
- data/lib/openc3/models/cvt_model.rb +185 -0
- data/lib/openc3/models/environment_model.rb +58 -0
- data/lib/openc3/models/gem_model.rb +137 -0
- data/lib/openc3/models/info_model.rb +31 -0
- data/lib/openc3/models/interface_model.rb +281 -0
- data/lib/openc3/models/interface_status_model.rb +117 -0
- data/lib/openc3/models/metadata_model.rb +139 -0
- data/lib/openc3/models/metric_model.rb +59 -0
- data/lib/openc3/models/microservice_model.rb +206 -0
- data/lib/openc3/models/microservice_status_model.rb +74 -0
- data/lib/openc3/models/model.rb +204 -0
- data/lib/openc3/models/note_model.rb +122 -0
- data/lib/openc3/models/notification_model.rb +40 -0
- data/lib/openc3/models/ping_model.rb +35 -0
- data/lib/openc3/models/plugin_model.rb +292 -0
- data/lib/openc3/models/process_status_model.rb +76 -0
- data/lib/openc3/models/reaction_model.rb +322 -0
- data/lib/openc3/models/reducer_model.rb +65 -0
- data/lib/openc3/models/router_model.rb +35 -0
- data/lib/openc3/models/router_status_model.rb +27 -0
- data/lib/openc3/models/scope_model.rb +153 -0
- data/lib/openc3/models/settings_model.rb +55 -0
- data/lib/openc3/models/sorted_model.rb +167 -0
- data/lib/openc3/models/target_model.rb +759 -0
- data/lib/openc3/models/timeline_model.rb +154 -0
- data/lib/openc3/models/tool_config_model.rb +38 -0
- data/lib/openc3/models/tool_model.rb +262 -0
- data/lib/openc3/models/trigger_group_model.rb +186 -0
- data/lib/openc3/models/trigger_model.rb +330 -0
- data/lib/openc3/models/widget_model.rb +138 -0
- data/lib/openc3/operators/microservice_operator.rb +128 -0
- data/lib/openc3/operators/operator.rb +277 -0
- data/lib/openc3/packets/binary_accessor.rb +1207 -0
- data/lib/openc3/packets/commands.rb +373 -0
- data/lib/openc3/packets/json_packet.rb +134 -0
- data/lib/openc3/packets/limits.rb +271 -0
- data/lib/openc3/packets/limits_response.rb +53 -0
- data/lib/openc3/packets/packet.rb +1168 -0
- data/lib/openc3/packets/packet_config.rb +625 -0
- data/lib/openc3/packets/packet_item.rb +586 -0
- data/lib/openc3/packets/packet_item_limits.rb +162 -0
- data/lib/openc3/packets/parsers/format_string_parser.rb +65 -0
- data/lib/openc3/packets/parsers/limits_parser.rb +159 -0
- data/lib/openc3/packets/parsers/limits_response_parser.rb +61 -0
- data/lib/openc3/packets/parsers/packet_item_parser.rb +272 -0
- data/lib/openc3/packets/parsers/packet_parser.rb +134 -0
- data/lib/openc3/packets/parsers/processor_parser.rb +73 -0
- data/lib/openc3/packets/parsers/state_parser.rb +127 -0
- data/lib/openc3/packets/parsers/xtce_converter.rb +442 -0
- data/lib/openc3/packets/parsers/xtce_parser.rb +722 -0
- data/lib/openc3/packets/structure.rb +553 -0
- data/lib/openc3/packets/structure_item.rb +365 -0
- data/lib/openc3/packets/telemetry.rb +487 -0
- data/lib/openc3/processors/processor.rb +86 -0
- data/lib/openc3/processors/statistics_processor.rb +82 -0
- data/lib/openc3/processors/watermark_processor.rb +58 -0
- data/lib/openc3/processors.rb +24 -0
- data/lib/openc3/script/api_shared.rb +828 -0
- data/lib/openc3/script/calendar.rb +89 -0
- data/lib/openc3/script/commands.rb +227 -0
- data/lib/openc3/script/exceptions.rb +29 -0
- data/lib/openc3/script/extract.rb +161 -0
- data/lib/openc3/script/limits.rb +60 -0
- data/lib/openc3/script/script.rb +299 -0
- data/lib/openc3/script/script_runner.rb +238 -0
- data/lib/openc3/script/storage.rb +146 -0
- data/lib/openc3/script/suite.rb +542 -0
- data/lib/openc3/script/suite_results.rb +196 -0
- data/lib/openc3/script/suite_runner.rb +217 -0
- data/lib/openc3/script.rb +21 -0
- data/lib/openc3/streams/serial_stream.rb +167 -0
- data/lib/openc3/streams/stream.rb +63 -0
- data/lib/openc3/streams/tcpip_client_stream.rb +116 -0
- data/lib/openc3/streams/tcpip_socket_stream.rb +195 -0
- data/lib/openc3/system/system.rb +127 -0
- data/lib/openc3/system/system_config.rb +411 -0
- data/lib/openc3/system/target.rb +269 -0
- data/lib/openc3/system.rb +24 -0
- data/lib/openc3/tools/cmd_tlm_server/api.rb +20 -0
- data/lib/openc3/tools/cmd_tlm_server/cmd_tlm_server_config.rb +320 -0
- data/lib/openc3/tools/cmd_tlm_server/interface_thread.rb +294 -0
- data/lib/openc3/tools/table_manager/table.rb +77 -0
- data/lib/openc3/tools/table_manager/table_config.rb +273 -0
- data/lib/openc3/tools/table_manager/table_item.rb +90 -0
- data/lib/openc3/tools/table_manager/table_item_parser.rb +66 -0
- data/lib/openc3/tools/table_manager/table_manager_core.rb +333 -0
- data/lib/openc3/tools/table_manager/table_parser.rb +93 -0
- data/lib/openc3/tools/test_runner/test.rb +67 -0
- data/lib/openc3/top_level.rb +595 -0
- data/lib/openc3/topics/autonomic_topic.rb +52 -0
- data/lib/openc3/topics/calendar_topic.rb +44 -0
- data/lib/openc3/topics/command_decom_topic.rb +76 -0
- data/lib/openc3/topics/command_topic.rb +83 -0
- data/lib/openc3/topics/config_topic.rb +68 -0
- data/lib/openc3/topics/interface_topic.rb +73 -0
- data/lib/openc3/topics/limits_event_topic.rb +109 -0
- data/lib/openc3/topics/notifications_topic.rb +28 -0
- data/lib/openc3/topics/router_topic.rb +85 -0
- data/lib/openc3/topics/telemetry_decom_topic.rb +54 -0
- data/lib/openc3/topics/telemetry_topic.rb +36 -0
- data/lib/openc3/topics/timeline_topic.rb +45 -0
- data/lib/openc3/topics/topic.rb +53 -0
- data/lib/openc3/utilities/authentication.rb +141 -0
- data/lib/openc3/utilities/authorization.rb +51 -0
- data/lib/openc3/utilities/crc.rb +278 -0
- data/lib/openc3/utilities/csv.rb +153 -0
- data/lib/openc3/utilities/logger.rb +187 -0
- data/lib/openc3/utilities/message_log.rb +91 -0
- data/lib/openc3/utilities/metric.rb +141 -0
- data/lib/openc3/utilities/process_manager.rb +139 -0
- data/lib/openc3/utilities/quaternion.rb +257 -0
- data/lib/openc3/utilities/ruby_lex_utils.rb +568 -0
- data/lib/openc3/utilities/s3.rb +202 -0
- data/lib/openc3/utilities/s3_autoload.rb +9 -0
- data/lib/openc3/utilities/s3_file_cache.rb +274 -0
- data/lib/openc3/utilities/simulated_target.rb +117 -0
- data/lib/openc3/utilities/sleeper.rb +51 -0
- data/lib/openc3/utilities/store.rb +23 -0
- data/lib/openc3/utilities/store_autoload.rb +237 -0
- data/lib/openc3/utilities/zip.rb +21 -0
- data/lib/openc3/utilities.rb +35 -0
- data/lib/openc3/version.rb +14 -0
- data/lib/openc3/win32/excel.rb +132 -0
- data/lib/openc3/win32/win32.rb +402 -0
- data/lib/openc3/win32/win32_main.rb +333 -0
- data/lib/openc3.rb +49 -0
- data/tasks/gemfile_stats.rake +113 -0
- data/tasks/spec.rake +30 -0
- data/templates/plugin-template/README.md +15 -0
- data/templates/plugin-template/Rakefile +12 -0
- data/templates/plugin-template/plugin.gemspec +23 -0
- data/templates/plugin-template/plugin.txt +9 -0
- data/templates/plugin-template/targets/TARGET/cmd_tlm/cmd.txt +8 -0
- data/templates/plugin-template/targets/TARGET/cmd_tlm/tlm.txt +8 -0
- data/templates/plugin-template/targets/TARGET/lib/target.rb +10 -0
- data/templates/plugin-template/targets/TARGET/procedures/procedure.rb +3 -0
- data/templates/plugin-template/targets/TARGET/screens/status.txt +9 -0
- data/templates/plugin-template/targets/TARGET/target.txt +5 -0
- metadata +849 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
# encoding: ascii-8bit
|
|
2
|
+
|
|
3
|
+
# Copyright 2022 Ball Aerospace & Technologies Corp.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This program is free software; you can modify and/or redistribute it
|
|
7
|
+
# under the terms of the GNU Affero General Public License
|
|
8
|
+
# as published by the Free Software Foundation; version 3 with
|
|
9
|
+
# attribution addendums as found in the LICENSE.txt
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
# GNU Affero General Public License for more details.
|
|
15
|
+
|
|
16
|
+
# Modified by OpenC3, Inc.
|
|
17
|
+
# All changes Copyright 2022, OpenC3, Inc.
|
|
18
|
+
# All Rights Reserved
|
|
19
|
+
|
|
20
|
+
require 'openc3/win32/win32_main'
|
|
21
|
+
require 'openc3/packets/structure'
|
|
22
|
+
|
|
23
|
+
module OpenC3
|
|
24
|
+
# Uses the Win32API to implement methods useful on Windows.
|
|
25
|
+
class Win32
|
|
26
|
+
# Create a file
|
|
27
|
+
def self.create_file(filename, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, template_file = NULL)
|
|
28
|
+
api = Win32API.new('Kernel32', 'CreateFile', [LP, DWORD, DWORD, LP, DWORD, DWORD, HANDLE], HANDLE)
|
|
29
|
+
|
|
30
|
+
handle = api.call(filename, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, template_file)
|
|
31
|
+
raise "Error during CreateFile: #{get_last_error_message()}" if handle == INVALID_HANDLE_VALUE
|
|
32
|
+
|
|
33
|
+
handle
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Close a file
|
|
37
|
+
def self.close_handle(handle)
|
|
38
|
+
api = Win32API.new('Kernel32', 'CloseHandle', [HANDLE], BOOL)
|
|
39
|
+
result = api.call(handle)
|
|
40
|
+
raise "Error closing handle: #{get_last_error_message()}" if result == 0
|
|
41
|
+
|
|
42
|
+
result
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Get Comm State
|
|
46
|
+
def self.get_comm_state(handle)
|
|
47
|
+
dcb = build_dcb()
|
|
48
|
+
api = Win32API.new('Kernel32', 'GetCommState', [HANDLE, LP], BOOL)
|
|
49
|
+
result = api.call(handle, dcb.buffer)
|
|
50
|
+
raise "GetCommState Error: #{get_last_error_message()}" if result == 0
|
|
51
|
+
|
|
52
|
+
dcb
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Set Comm State
|
|
56
|
+
def self.set_comm_state(handle, dcb)
|
|
57
|
+
api = Win32API.new('Kernel32', 'SetCommState', [HANDLE, LP], BOOL)
|
|
58
|
+
result = api.call(handle, dcb.buffer)
|
|
59
|
+
raise "SetCommState Error: #{get_last_error_message()}" if result == 0
|
|
60
|
+
|
|
61
|
+
result
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Set Comm Timeouts - Values in Ms
|
|
65
|
+
def self.set_comm_timeouts(handle, read_interval_timeout = 4294967295, read_total_timeout_multiplier = 0, read_total_timeout_constant = 0, write_total_timeout_multiplier = 0, write_total_timeout_constant = 0)
|
|
66
|
+
comm_timeouts = build_comm_timeouts(read_interval_timeout, read_total_timeout_multiplier, read_total_timeout_constant, write_total_timeout_multiplier, write_total_timeout_constant)
|
|
67
|
+
api = Win32API.new('Kernel32', 'SetCommTimeouts', [HANDLE, LP], BOOL)
|
|
68
|
+
result = api.call(handle, comm_timeouts.buffer)
|
|
69
|
+
raise "SetCommTimeouts Error: #{get_last_error_message()}" if result == 0
|
|
70
|
+
|
|
71
|
+
result
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Read File
|
|
75
|
+
def self.read_file(handle, bytes_to_read, overlapped = NULL)
|
|
76
|
+
buffer = ' ' * (bytes_to_read + 1)
|
|
77
|
+
bytes_read = ' ' * 8
|
|
78
|
+
api = Win32API.new('Kernel32', 'ReadFile', [HANDLE, LP, DWORD, LP, LP], BOOL)
|
|
79
|
+
api.call(handle, buffer, bytes_to_read, bytes_read, overlapped)
|
|
80
|
+
bytes_read = bytes_read.unpack(DWORD)[0]
|
|
81
|
+
if bytes_read > 0
|
|
82
|
+
buffer[0..(bytes_read - 1)]
|
|
83
|
+
else
|
|
84
|
+
''
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Write File
|
|
89
|
+
def self.write_file(handle, buffer, bytes_to_write, overlapped = NULL)
|
|
90
|
+
bytes_written = ' ' * 8
|
|
91
|
+
api = Win32API.new('Kernel32', 'WriteFile', [HANDLE, LP, DWORD, LP, LP], BOOL)
|
|
92
|
+
api.call(handle, buffer, bytes_to_write, bytes_written, overlapped)
|
|
93
|
+
bytes_written.unpack(DWORD)[0]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
protected
|
|
97
|
+
|
|
98
|
+
def self.build_dcb
|
|
99
|
+
dcb = Structure.new(:LITTLE_ENDIAN)
|
|
100
|
+
dcb.define_item('DCBlength', 0, 32, :UINT)
|
|
101
|
+
dcb.define_item('BaudRate', 32, 32, :UINT)
|
|
102
|
+
dcb.define_item('fBinary', 71, 1, :UINT)
|
|
103
|
+
dcb.define_item('fParity', 70, 1, :UINT)
|
|
104
|
+
dcb.define_item('fOutxCtsFlow', 69, 1, :UINT)
|
|
105
|
+
dcb.define_item('fOutxDsrFlow', 68, 1, :UINT)
|
|
106
|
+
dcb.define_item('fDtrControl', 66, 2, :UINT)
|
|
107
|
+
dcb.define_item('fDsrSensitivity', 65, 1, :UINT)
|
|
108
|
+
dcb.define_item('fTXContinueOnXoff', 64, 1, :UINT)
|
|
109
|
+
dcb.define_item('fOutX', 79, 1, :UINT)
|
|
110
|
+
dcb.define_item('fInX', 78, 1, :UINT)
|
|
111
|
+
dcb.define_item('fErrorChar', 77, 1, :UINT)
|
|
112
|
+
dcb.define_item('fNull', 76, 1, :UINT)
|
|
113
|
+
dcb.define_item('fRtsControl', 74, 2, :UINT)
|
|
114
|
+
dcb.define_item('fAbortOnError', 73, 1, :UINT)
|
|
115
|
+
dcb.define_item('fDummy2', 88, 17, :UINT)
|
|
116
|
+
dcb.define_item('wReserved', 96, 16, :UINT)
|
|
117
|
+
dcb.define_item('XonLim', 112, 16, :UINT)
|
|
118
|
+
dcb.define_item('XoffLim', 128, 16, :UINT)
|
|
119
|
+
dcb.define_item('ByteSize', 144, 8, :UINT)
|
|
120
|
+
dcb.define_item('Parity', 152, 8, :UINT)
|
|
121
|
+
dcb.define_item('StopBits', 160, 8, :UINT)
|
|
122
|
+
dcb.define_item('XonChar', 168, 8, :INT)
|
|
123
|
+
dcb.define_item('XoffChar', 176, 8, :INT)
|
|
124
|
+
dcb.define_item('ErrorChar', 184, 8, :INT)
|
|
125
|
+
dcb.define_item('EofChar', 192, 8, :INT)
|
|
126
|
+
dcb.define_item('EvtChar', 200, 8, :INT)
|
|
127
|
+
dcb.define_item('wReserved1', 208, 16, :UINT)
|
|
128
|
+
dcb.write('DCBlength', 28)
|
|
129
|
+
dcb
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def self.build_comm_timeouts(read_interval_timeout = 4294967295, read_total_timeout_multiplier = 0, read_total_timeout_constant = 0, write_total_timeout_multiplier = 0, write_total_timeout_constant = 0)
|
|
133
|
+
comm_timeouts = Structure.new(:LITTLE_ENDIAN)
|
|
134
|
+
comm_timeouts.append_item('ReadIntervalTimeout', 32, :UINT)
|
|
135
|
+
comm_timeouts.append_item('ReadTotalTimeoutMultiplier', 32, :UINT)
|
|
136
|
+
comm_timeouts.append_item('ReadTotalTimeoutConstant', 32, :UINT)
|
|
137
|
+
comm_timeouts.append_item('WriteTotalTimeoutMultiplier', 32, :UINT)
|
|
138
|
+
comm_timeouts.append_item('WriteTotalTimeoutConstant', 32, :UINT)
|
|
139
|
+
comm_timeouts.write('ReadIntervalTimeout', read_interval_timeout)
|
|
140
|
+
comm_timeouts.write('ReadTotalTimeoutMultiplier', read_total_timeout_multiplier)
|
|
141
|
+
comm_timeouts.write('ReadTotalTimeoutConstant', read_total_timeout_constant)
|
|
142
|
+
comm_timeouts.write('WriteTotalTimeoutMultiplier', write_total_timeout_multiplier)
|
|
143
|
+
comm_timeouts.write('WriteTotalTimeoutConstant', write_total_timeout_constant)
|
|
144
|
+
comm_timeouts
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
module QDA
|
|
150
|
+
module Filters
|
|
151
|
+
# Used only on windows to enable calling other executables without the
|
|
152
|
+
# annoying command-prompt box that pops up when using Ruby backticks in
|
|
153
|
+
# a script running under rubyw.
|
|
154
|
+
#
|
|
155
|
+
# Usage:
|
|
156
|
+
# output, errors = QDA::Filters::Win32Process::backtick('dir')
|
|
157
|
+
#
|
|
158
|
+
# Note - most of this code written by S Kroeger, see
|
|
159
|
+
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/155684
|
|
160
|
+
module Win32Process
|
|
161
|
+
NORMAL_PRIORITY_CLASS = 0x00000020
|
|
162
|
+
STARTUP_INFO_SIZE = 68
|
|
163
|
+
PROCESS_INFO_SIZE = 16
|
|
164
|
+
SECURITY_ATTRIBUTES_SIZE = 12
|
|
165
|
+
|
|
166
|
+
ERROR_SUCCESS = 0x00
|
|
167
|
+
FORMAT_MESSAGE_FROM_SYSTEM = 0x1000
|
|
168
|
+
FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x2000
|
|
169
|
+
|
|
170
|
+
HANDLE_FLAG_INHERIT = 1
|
|
171
|
+
HANDLE_FLAG_PROTECT_FROM_CLOSE = 2
|
|
172
|
+
|
|
173
|
+
STARTF_USESHOWWINDOW = 0x00000001
|
|
174
|
+
STARTF_USESTDHANDLES = 0x00000100
|
|
175
|
+
|
|
176
|
+
class << self
|
|
177
|
+
def raise_last_win_32_error
|
|
178
|
+
errorCode = OpenC3::Win32API.new("kernel32", "GetLastError", [], 'L').call
|
|
179
|
+
if errorCode != ERROR_SUCCESS
|
|
180
|
+
params = [
|
|
181
|
+
'L', # IN DWORD dwFlags,
|
|
182
|
+
'P', # IN LPCVOID lpSource,
|
|
183
|
+
'L', # IN DWORD dwMessageId,
|
|
184
|
+
'L', # IN DWORD dwLanguageId,
|
|
185
|
+
'P', # OUT LPSTR lpBuffer,
|
|
186
|
+
'L', # IN DWORD nSize,
|
|
187
|
+
'P', # IN va_list *Arguments
|
|
188
|
+
]
|
|
189
|
+
|
|
190
|
+
formatMessage = OpenC3::Win32API.new("kernel32", "FormatMessage", params, 'L')
|
|
191
|
+
msg = ' ' * 255
|
|
192
|
+
formatMessage.call(FORMAT_MESSAGE_FROM_SYSTEM +
|
|
193
|
+
FORMAT_MESSAGE_ARGUMENT_ARRAY, '', errorCode, 0, msg, 255, '')
|
|
194
|
+
|
|
195
|
+
msg.gsub!(/\000/, '')
|
|
196
|
+
msg.strip!
|
|
197
|
+
raise msg
|
|
198
|
+
else
|
|
199
|
+
raise 'GetLastError returned ERROR_SUCCESS'
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def create_pipe # returns read and write handle
|
|
204
|
+
params = [
|
|
205
|
+
'P', # pointer to read handle
|
|
206
|
+
'P', # pointer to write handle
|
|
207
|
+
'P', # pointer to security attributes
|
|
208
|
+
'L'
|
|
209
|
+
] # pipe size
|
|
210
|
+
|
|
211
|
+
createPipe = OpenC3::Win32API.new("kernel32", "CreatePipe", params, 'I')
|
|
212
|
+
|
|
213
|
+
read_handle, write_handle = [0].pack('I'), [0].pack('I')
|
|
214
|
+
sec_attrs = [SECURITY_ATTRIBUTES_SIZE, 0, 1].pack('III')
|
|
215
|
+
|
|
216
|
+
raise_last_win_32_error if createPipe.Call(read_handle,
|
|
217
|
+
write_handle, sec_attrs, 0).zero?
|
|
218
|
+
|
|
219
|
+
[read_handle.unpack('I')[0], write_handle.unpack('I')[0]]
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def set_handle_information(handle, flags, value)
|
|
223
|
+
params = [
|
|
224
|
+
'L', # handle to an object
|
|
225
|
+
'L', # specifies flags to change
|
|
226
|
+
'L'
|
|
227
|
+
] # specifies new values for flags
|
|
228
|
+
|
|
229
|
+
setHandleInformation = OpenC3::Win32API.new("kernel32",
|
|
230
|
+
"SetHandleInformation", params, 'I')
|
|
231
|
+
raise_last_win_32_error if setHandleInformation.Call(handle,
|
|
232
|
+
flags, value).zero?
|
|
233
|
+
nil
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def close_handle(handle)
|
|
237
|
+
closeHandle = OpenC3::Win32API.new("kernel32", "CloseHandle", ['L'], 'I')
|
|
238
|
+
raise_last_win_32_error if closeHandle.call(handle).zero?
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def create_process(command, stdin, stdout, stderror)
|
|
242
|
+
params = [
|
|
243
|
+
'L', # IN LPCSTR lpApplicationName
|
|
244
|
+
'P', # IN LPSTR lpCommandLine
|
|
245
|
+
'L', # IN LPSECURITY_ATTRIBUTES lpProcessAttributes
|
|
246
|
+
'L', # IN LPSECURITY_ATTRIBUTES lpThreadAttributes
|
|
247
|
+
'L', # IN BOOL bInheritHandles
|
|
248
|
+
'L', # IN DWORD dwCreationFlags
|
|
249
|
+
'L', # IN LPVOID lpEnvironment
|
|
250
|
+
'L', # IN LPCSTR lpCurrentDirectory
|
|
251
|
+
'P', # IN LPSTARTUPINFOA lpStartupInfo
|
|
252
|
+
'P'
|
|
253
|
+
] # OUT LPPROCESS_INFORMATION lpProcessInformation
|
|
254
|
+
|
|
255
|
+
startupInfo = [STARTUP_INFO_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
256
|
+
STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW, 0,
|
|
257
|
+
0, 0, stdin, stdout, stderror].pack('IIIIIIIIIIIISSIIII')
|
|
258
|
+
|
|
259
|
+
processInfo = [0, 0, 0, 0].pack('IIII')
|
|
260
|
+
command << 0
|
|
261
|
+
|
|
262
|
+
createProcess = OpenC3::Win32API.new("kernel32", "CreateProcess", params, 'I')
|
|
263
|
+
cp_args = [0, command, 0, 0, 1, 0, 0, 0, startupInfo, processInfo]
|
|
264
|
+
raise_last_win_32_error if createProcess.call(*cp_args).zero?
|
|
265
|
+
|
|
266
|
+
hProcess, hThread,
|
|
267
|
+
dwProcessId, dwThreadId = processInfo.unpack('LLLL')
|
|
268
|
+
|
|
269
|
+
close_handle(hProcess)
|
|
270
|
+
close_handle(hThread)
|
|
271
|
+
|
|
272
|
+
[dwProcessId, dwThreadId]
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def write_file(hFile, buffer)
|
|
276
|
+
params = [
|
|
277
|
+
'L', # handle to file to write to
|
|
278
|
+
'P', # pointer to data to write to file
|
|
279
|
+
'L', # number of bytes to write
|
|
280
|
+
'P', # pointer to number of bytes written
|
|
281
|
+
'L'
|
|
282
|
+
] # pointer to structure for overlapped I/O
|
|
283
|
+
|
|
284
|
+
written = [0].pack('I')
|
|
285
|
+
writeFile = OpenC3::Win32API.new("kernel32", "WriteFile", params, 'I')
|
|
286
|
+
|
|
287
|
+
raise_last_win_32_error if writeFile.call(hFile, buffer, buffer.size,
|
|
288
|
+
written, 0).zero?
|
|
289
|
+
|
|
290
|
+
written.unpack('I')[0]
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
def read_file(hFile)
|
|
294
|
+
params = [
|
|
295
|
+
'L', # handle of file to read
|
|
296
|
+
'P', # pointer to buffer that receives data
|
|
297
|
+
'L', # number of bytes to read
|
|
298
|
+
'P', # pointer to number of bytes read
|
|
299
|
+
'L'
|
|
300
|
+
] # pointer to structure for data
|
|
301
|
+
|
|
302
|
+
number = [0].pack('I')
|
|
303
|
+
buffer = ' ' * 255
|
|
304
|
+
|
|
305
|
+
readFile = OpenC3::Win32API.new("kernel32", "ReadFile", params, 'I')
|
|
306
|
+
return '' if readFile.call(hFile, buffer, 255, number, 0).zero?
|
|
307
|
+
|
|
308
|
+
buffer[0...number.unpack('I')[0]]
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def peek_named_pipe(hFile)
|
|
312
|
+
params = [
|
|
313
|
+
'L', # handle to pipe to copy from
|
|
314
|
+
'L', # pointer to data buffer
|
|
315
|
+
'L', # size, in bytes, of data buffer
|
|
316
|
+
'L', # pointer to number of bytes read
|
|
317
|
+
'P', # pointer to total number of bytes available
|
|
318
|
+
'L'
|
|
319
|
+
] # pointer to unread bytes in this message
|
|
320
|
+
|
|
321
|
+
available = [0].pack('I')
|
|
322
|
+
peekNamedPipe = OpenC3::Win32API.new("kernel32", "PeekNamedPipe", params, 'I')
|
|
323
|
+
|
|
324
|
+
return -1 if peekNamedPipe.Call(hFile, 0, 0, 0, available, 0).zero?
|
|
325
|
+
|
|
326
|
+
available.unpack('I')[0]
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
class Win32popenIO
|
|
331
|
+
def initialize(hRead, hWrite, hError)
|
|
332
|
+
@hRead = hRead
|
|
333
|
+
@hWrite = hWrite
|
|
334
|
+
@hError = hError
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
def write(data)
|
|
338
|
+
Win32Process.write_file(@hWrite, data.to_s)
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
def read
|
|
342
|
+
sleep(0.01) while Win32Process.peek_named_pipe(@hRead).zero?
|
|
343
|
+
Win32Process.read_file(@hRead)
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
def read_all
|
|
347
|
+
all = ''
|
|
348
|
+
until (buffer = read).empty?
|
|
349
|
+
all << buffer
|
|
350
|
+
end
|
|
351
|
+
all
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
def read_err
|
|
355
|
+
sleep(0.01) while Win32Process.peek_named_pipe(@hError).zero?
|
|
356
|
+
Win32Process.read_file(@hError)
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
def read_all_err
|
|
360
|
+
all = ''
|
|
361
|
+
until (buffer = read_err).empty?
|
|
362
|
+
all << buffer
|
|
363
|
+
end
|
|
364
|
+
all
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
# The only useful public method in this class - receives a command line,
|
|
369
|
+
# and returns the output content and error content as a pair of strings.
|
|
370
|
+
# No shell expansion is carried out on the command line string.
|
|
371
|
+
#
|
|
372
|
+
# Usage:
|
|
373
|
+
# output, errors = QDA::Filters::Win32Process::backtick('dir')
|
|
374
|
+
def self.backtick(command)
|
|
375
|
+
# create 3 pipes
|
|
376
|
+
child_in_r, child_in_w = create_pipe
|
|
377
|
+
child_out_r, child_out_w = create_pipe
|
|
378
|
+
child_error_r, child_error_w = create_pipe
|
|
379
|
+
|
|
380
|
+
# Ensure the write handle to the pipe for STDIN is not inherited.
|
|
381
|
+
set_handle_information(child_in_w, HANDLE_FLAG_INHERIT, 0)
|
|
382
|
+
set_handle_information(child_out_r, HANDLE_FLAG_INHERIT, 0)
|
|
383
|
+
set_handle_information(child_error_r, HANDLE_FLAG_INHERIT, 0)
|
|
384
|
+
|
|
385
|
+
create_process(command,
|
|
386
|
+
child_in_r,
|
|
387
|
+
child_out_w,
|
|
388
|
+
child_error_w)
|
|
389
|
+
# we have to close the handles, so the pipes terminate with the process
|
|
390
|
+
close_handle(child_in_r)
|
|
391
|
+
close_handle(child_out_w)
|
|
392
|
+
close_handle(child_error_w)
|
|
393
|
+
close_handle(child_in_w)
|
|
394
|
+
io = Win32popenIO.new(child_out_r, child_in_w, child_error_r)
|
|
395
|
+
|
|
396
|
+
out = io.read_all().gsub(/\r/, '')
|
|
397
|
+
err = io.read_all_err().gsub(/\r/, '')
|
|
398
|
+
return out, err
|
|
399
|
+
end
|
|
400
|
+
end # module Win32Process
|
|
401
|
+
end # module Filters
|
|
402
|
+
end # module QDA
|