librex 0.0.1
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.
- data/README +4 -0
- data/lib/rex.rb +101 -0
- data/lib/rex.rb.ts.rb +70 -0
- data/lib/rex/LICENSE +29 -0
- data/lib/rex/arch.rb +103 -0
- data/lib/rex/arch/sparc.rb +75 -0
- data/lib/rex/arch/sparc.rb.ut.rb +18 -0
- data/lib/rex/arch/x86.rb +513 -0
- data/lib/rex/arch/x86.rb.ut.rb +93 -0
- data/lib/rex/assembly/nasm.rb +100 -0
- data/lib/rex/assembly/nasm.rb.ut.rb +22 -0
- data/lib/rex/codepage.map +104 -0
- data/lib/rex/compat.rb +281 -0
- data/lib/rex/constants.rb +113 -0
- data/lib/rex/elfparsey.rb +11 -0
- data/lib/rex/elfparsey/elf.rb +123 -0
- data/lib/rex/elfparsey/elfbase.rb +260 -0
- data/lib/rex/elfparsey/exceptions.rb +27 -0
- data/lib/rex/elfscan.rb +12 -0
- data/lib/rex/elfscan/scanner.rb +207 -0
- data/lib/rex/elfscan/search.rb +46 -0
- data/lib/rex/encoder/alpha2.rb +31 -0
- data/lib/rex/encoder/alpha2/alpha_mixed.rb +68 -0
- data/lib/rex/encoder/alpha2/alpha_upper.rb +79 -0
- data/lib/rex/encoder/alpha2/generic.rb +113 -0
- data/lib/rex/encoder/alpha2/unicode_mixed.rb +117 -0
- data/lib/rex/encoder/alpha2/unicode_upper.rb +129 -0
- data/lib/rex/encoder/ndr.rb +89 -0
- data/lib/rex/encoder/ndr.rb.ut.rb +44 -0
- data/lib/rex/encoder/nonalpha.rb +61 -0
- data/lib/rex/encoder/nonupper.rb +64 -0
- data/lib/rex/encoder/xdr.rb +106 -0
- data/lib/rex/encoder/xdr.rb.ut.rb +29 -0
- data/lib/rex/encoder/xor.rb +69 -0
- data/lib/rex/encoder/xor/dword.rb +13 -0
- data/lib/rex/encoder/xor/dword_additive.rb +13 -0
- data/lib/rex/encoders/xor_dword.rb +35 -0
- data/lib/rex/encoders/xor_dword_additive.rb +53 -0
- data/lib/rex/encoders/xor_dword_additive.rb.ut.rb +12 -0
- data/lib/rex/encoding/xor.rb +20 -0
- data/lib/rex/encoding/xor.rb.ts.rb +14 -0
- data/lib/rex/encoding/xor/byte.rb +15 -0
- data/lib/rex/encoding/xor/byte.rb.ut.rb +21 -0
- data/lib/rex/encoding/xor/dword.rb +21 -0
- data/lib/rex/encoding/xor/dword.rb.ut.rb +15 -0
- data/lib/rex/encoding/xor/dword_additive.rb +92 -0
- data/lib/rex/encoding/xor/dword_additive.rb.ut.rb +15 -0
- data/lib/rex/encoding/xor/exceptions.rb +17 -0
- data/lib/rex/encoding/xor/generic.rb +146 -0
- data/lib/rex/encoding/xor/generic.rb.ut.rb +120 -0
- data/lib/rex/encoding/xor/qword.rb +15 -0
- data/lib/rex/encoding/xor/word.rb +21 -0
- data/lib/rex/encoding/xor/word.rb.ut.rb +13 -0
- data/lib/rex/exceptions.rb +275 -0
- data/lib/rex/exceptions.rb.ut.rb +44 -0
- data/lib/rex/exploitation/cmdstager.rb +133 -0
- data/lib/rex/exploitation/egghunter.rb +143 -0
- data/lib/rex/exploitation/egghunter.rb.ut.rb +25 -0
- data/lib/rex/exploitation/encryptjs.rb +77 -0
- data/lib/rex/exploitation/heaplib.js.b64 +331 -0
- data/lib/rex/exploitation/heaplib.rb +94 -0
- data/lib/rex/exploitation/javascriptosdetect.rb +735 -0
- data/lib/rex/exploitation/obfuscatejs.rb +335 -0
- data/lib/rex/exploitation/opcodedb.rb +818 -0
- data/lib/rex/exploitation/opcodedb.rb.ut.rb +279 -0
- data/lib/rex/exploitation/seh.rb +92 -0
- data/lib/rex/exploitation/seh.rb.ut.rb +19 -0
- data/lib/rex/file.rb +84 -0
- data/lib/rex/file.rb.ut.rb +16 -0
- data/lib/rex/image_source.rb +12 -0
- data/lib/rex/image_source/disk.rb +60 -0
- data/lib/rex/image_source/image_source.rb +46 -0
- data/lib/rex/image_source/memory.rb +37 -0
- data/lib/rex/io/bidirectional_pipe.rb +157 -0
- data/lib/rex/io/datagram_abstraction.rb +35 -0
- data/lib/rex/io/stream.rb +313 -0
- data/lib/rex/io/stream_abstraction.rb +186 -0
- data/lib/rex/io/stream_server.rb +211 -0
- data/lib/rex/job_container.rb +202 -0
- data/lib/rex/logging.rb +4 -0
- data/lib/rex/logging/log_dispatcher.rb +179 -0
- data/lib/rex/logging/log_sink.rb +42 -0
- data/lib/rex/logging/sinks/flatfile.rb +55 -0
- data/lib/rex/logging/sinks/stderr.rb +43 -0
- data/lib/rex/machparsey.rb +9 -0
- data/lib/rex/machparsey/exceptions.rb +34 -0
- data/lib/rex/machparsey/mach.rb +209 -0
- data/lib/rex/machparsey/machbase.rb +408 -0
- data/lib/rex/machscan.rb +9 -0
- data/lib/rex/machscan/scanner.rb +217 -0
- data/lib/rex/mime.rb +9 -0
- data/lib/rex/mime/header.rb +75 -0
- data/lib/rex/mime/message.rb +112 -0
- data/lib/rex/mime/part.rb +20 -0
- data/lib/rex/nop/opty2.rb +108 -0
- data/lib/rex/nop/opty2.rb.ut.rb +23 -0
- data/lib/rex/nop/opty2_tables.rb +300 -0
- data/lib/rex/ole.rb +128 -0
- data/lib/rex/ole/clsid.rb +47 -0
- data/lib/rex/ole/difat.rb +141 -0
- data/lib/rex/ole/directory.rb +230 -0
- data/lib/rex/ole/direntry.rb +240 -0
- data/lib/rex/ole/fat.rb +99 -0
- data/lib/rex/ole/header.rb +204 -0
- data/lib/rex/ole/minifat.rb +77 -0
- data/lib/rex/ole/samples/create_ole.rb +27 -0
- data/lib/rex/ole/samples/dir.rb +35 -0
- data/lib/rex/ole/samples/dump_stream.rb +34 -0
- data/lib/rex/ole/samples/ole_info.rb +23 -0
- data/lib/rex/ole/storage.rb +395 -0
- data/lib/rex/ole/stream.rb +53 -0
- data/lib/rex/ole/substorage.rb +49 -0
- data/lib/rex/ole/util.rb +157 -0
- data/lib/rex/parser/arguments.rb +97 -0
- data/lib/rex/parser/arguments.rb.ut.rb +67 -0
- data/lib/rex/parser/ini.rb +185 -0
- data/lib/rex/parser/ini.rb.ut.rb +29 -0
- data/lib/rex/parser/nmap_xml.rb +111 -0
- data/lib/rex/payloads.rb +1 -0
- data/lib/rex/payloads/win32.rb +2 -0
- data/lib/rex/payloads/win32/common.rb +26 -0
- data/lib/rex/payloads/win32/kernel.rb +53 -0
- data/lib/rex/payloads/win32/kernel/common.rb +54 -0
- data/lib/rex/payloads/win32/kernel/migration.rb +12 -0
- data/lib/rex/payloads/win32/kernel/recovery.rb +50 -0
- data/lib/rex/payloads/win32/kernel/stager.rb +171 -0
- data/lib/rex/peparsey.rb +12 -0
- data/lib/rex/peparsey/exceptions.rb +32 -0
- data/lib/rex/peparsey/pe.rb +188 -0
- data/lib/rex/peparsey/pe_memdump.rb +63 -0
- data/lib/rex/peparsey/pebase.rb +1655 -0
- data/lib/rex/peparsey/section.rb +136 -0
- data/lib/rex/pescan.rb +13 -0
- data/lib/rex/pescan/analyze.rb +309 -0
- data/lib/rex/pescan/scanner.rb +206 -0
- data/lib/rex/pescan/search.rb +56 -0
- data/lib/rex/platforms.rb +1 -0
- data/lib/rex/platforms/windows.rb +51 -0
- data/lib/rex/poly.rb +132 -0
- data/lib/rex/poly/block.rb +468 -0
- data/lib/rex/poly/register.rb +100 -0
- data/lib/rex/poly/register/x86.rb +40 -0
- data/lib/rex/post.rb +8 -0
- data/lib/rex/post/dir.rb +51 -0
- data/lib/rex/post/file.rb +172 -0
- data/lib/rex/post/file_stat.rb +220 -0
- data/lib/rex/post/gen.pl +13 -0
- data/lib/rex/post/io.rb +182 -0
- data/lib/rex/post/meterpreter.rb +4 -0
- data/lib/rex/post/meterpreter/channel.rb +438 -0
- data/lib/rex/post/meterpreter/channel_container.rb +54 -0
- data/lib/rex/post/meterpreter/channels/pool.rb +160 -0
- data/lib/rex/post/meterpreter/channels/pools/file.rb +62 -0
- data/lib/rex/post/meterpreter/channels/pools/stream_pool.rb +103 -0
- data/lib/rex/post/meterpreter/channels/stream.rb +87 -0
- data/lib/rex/post/meterpreter/client.rb +335 -0
- data/lib/rex/post/meterpreter/client_core.rb +274 -0
- data/lib/rex/post/meterpreter/dependencies.rb +3 -0
- data/lib/rex/post/meterpreter/extension.rb +32 -0
- data/lib/rex/post/meterpreter/extensions/espia/espia.rb +58 -0
- data/lib/rex/post/meterpreter/extensions/espia/tlv.rb +16 -0
- data/lib/rex/post/meterpreter/extensions/incognito/incognito.rb +94 -0
- data/lib/rex/post/meterpreter/extensions/incognito/tlv.rb +21 -0
- data/lib/rex/post/meterpreter/extensions/priv/fs.rb +118 -0
- data/lib/rex/post/meterpreter/extensions/priv/passwd.rb +61 -0
- data/lib/rex/post/meterpreter/extensions/priv/priv.rb +104 -0
- data/lib/rex/post/meterpreter/extensions/priv/tlv.rb +28 -0
- data/lib/rex/post/meterpreter/extensions/sniffer/sniffer.rb +100 -0
- data/lib/rex/post/meterpreter/extensions/sniffer/tlv.rb +24 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/constants.rb +333 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb +273 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb +235 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/file_stat.rb +103 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/io.rb +48 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/config.rb +144 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb +73 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/route.rb +56 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket.rb +137 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/tcp_client_channel.rb +167 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/tcp_server_channel.rb +167 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/udp_channel.rb +192 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/stdapi.rb +139 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/config.rb +97 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log.rb +184 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log_subsystem/event_record.rb +41 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/power.rb +61 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb +361 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/image.rb +129 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/io.rb +55 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/memory.rb +336 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/thread.rb +141 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry.rb +279 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb +182 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_value.rb +102 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/thread.rb +174 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb +185 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/ui.rb +227 -0
- data/lib/rex/post/meterpreter/inbound_packet_handler.rb +30 -0
- data/lib/rex/post/meterpreter/object_aliases.rb +83 -0
- data/lib/rex/post/meterpreter/packet.rb +596 -0
- data/lib/rex/post/meterpreter/packet_dispatcher.rb +409 -0
- data/lib/rex/post/meterpreter/packet_parser.rb +94 -0
- data/lib/rex/post/meterpreter/packet_response_waiter.rb +83 -0
- data/lib/rex/post/meterpreter/ui/console.rb +135 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher.rb +62 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +595 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/espia.rb +108 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/incognito.rb +241 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv.rb +61 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb +98 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/passwd.rb +51 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/timestomp.rb +132 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/sniffer.rb +187 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi.rb +63 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +376 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb +270 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +484 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb +315 -0
- data/lib/rex/post/meterpreter/ui/console/interactive_channel.rb +95 -0
- data/lib/rex/post/permission.rb +26 -0
- data/lib/rex/post/process.rb +57 -0
- data/lib/rex/post/thread.rb +57 -0
- data/lib/rex/post/ui.rb +52 -0
- data/lib/rex/proto.rb +12 -0
- data/lib/rex/proto.rb.ts.rb +8 -0
- data/lib/rex/proto/dcerpc.rb +6 -0
- data/lib/rex/proto/dcerpc.rb.ts.rb +9 -0
- data/lib/rex/proto/dcerpc/client.rb +358 -0
- data/lib/rex/proto/dcerpc/client.rb.ut.rb +491 -0
- data/lib/rex/proto/dcerpc/exceptions.rb +150 -0
- data/lib/rex/proto/dcerpc/handle.rb +47 -0
- data/lib/rex/proto/dcerpc/handle.rb.ut.rb +85 -0
- data/lib/rex/proto/dcerpc/ndr.rb +72 -0
- data/lib/rex/proto/dcerpc/ndr.rb.ut.rb +41 -0
- data/lib/rex/proto/dcerpc/packet.rb +253 -0
- data/lib/rex/proto/dcerpc/packet.rb.ut.rb +56 -0
- data/lib/rex/proto/dcerpc/response.rb +186 -0
- data/lib/rex/proto/dcerpc/response.rb.ut.rb +15 -0
- data/lib/rex/proto/dcerpc/uuid.rb +84 -0
- data/lib/rex/proto/dcerpc/uuid.rb.ut.rb +46 -0
- data/lib/rex/proto/drda.rb +5 -0
- data/lib/rex/proto/drda.rb.ts.rb +17 -0
- data/lib/rex/proto/drda/constants.rb +49 -0
- data/lib/rex/proto/drda/constants.rb.ut.rb +23 -0
- data/lib/rex/proto/drda/packet.rb +252 -0
- data/lib/rex/proto/drda/packet.rb.ut.rb +109 -0
- data/lib/rex/proto/drda/utils.rb +123 -0
- data/lib/rex/proto/drda/utils.rb.ut.rb +84 -0
- data/lib/rex/proto/http.rb +5 -0
- data/lib/rex/proto/http.rb.ts.rb +12 -0
- data/lib/rex/proto/http/client.rb +817 -0
- data/lib/rex/proto/http/client.rb.ut.rb +93 -0
- data/lib/rex/proto/http/handler.rb +46 -0
- data/lib/rex/proto/http/handler/erb.rb +128 -0
- data/lib/rex/proto/http/handler/erb.rb.ut.rb +21 -0
- data/lib/rex/proto/http/handler/erb.rb.ut.rb.rhtml +1 -0
- data/lib/rex/proto/http/handler/proc.rb +54 -0
- data/lib/rex/proto/http/handler/proc.rb.ut.rb +24 -0
- data/lib/rex/proto/http/header.rb +161 -0
- data/lib/rex/proto/http/header.rb.ut.rb +46 -0
- data/lib/rex/proto/http/packet.rb +394 -0
- data/lib/rex/proto/http/packet.rb.ut.rb +165 -0
- data/lib/rex/proto/http/request.rb +356 -0
- data/lib/rex/proto/http/request.rb.ut.rb +214 -0
- data/lib/rex/proto/http/response.rb +85 -0
- data/lib/rex/proto/http/response.rb.ut.rb +149 -0
- data/lib/rex/proto/http/server.rb +367 -0
- data/lib/rex/proto/http/server.rb.ut.rb +79 -0
- data/lib/rex/proto/smb.rb +7 -0
- data/lib/rex/proto/smb.rb.ts.rb +8 -0
- data/lib/rex/proto/smb/client.rb +1733 -0
- data/lib/rex/proto/smb/client.rb.ut.rb +223 -0
- data/lib/rex/proto/smb/constants.rb +1062 -0
- data/lib/rex/proto/smb/constants.rb.ut.rb +18 -0
- data/lib/rex/proto/smb/crypt.rb +95 -0
- data/lib/rex/proto/smb/crypt.rb.ut.rb +20 -0
- data/lib/rex/proto/smb/evasions.rb +65 -0
- data/lib/rex/proto/smb/exceptions.rb +846 -0
- data/lib/rex/proto/smb/simpleclient.rb +292 -0
- data/lib/rex/proto/smb/simpleclient.rb.ut.rb +128 -0
- data/lib/rex/proto/smb/utils.rb +514 -0
- data/lib/rex/proto/smb/utils.rb.ut.rb +20 -0
- data/lib/rex/proto/sunrpc.rb +1 -0
- data/lib/rex/proto/sunrpc/client.rb +195 -0
- data/lib/rex/script.rb +42 -0
- data/lib/rex/script/base.rb +59 -0
- data/lib/rex/script/meterpreter.rb +9 -0
- data/lib/rex/script/shell.rb +9 -0
- data/lib/rex/service.rb +48 -0
- data/lib/rex/service_manager.rb +141 -0
- data/lib/rex/service_manager.rb.ut.rb +32 -0
- data/lib/rex/services/local_relay.rb +423 -0
- data/lib/rex/socket.rb +586 -0
- data/lib/rex/socket.rb.ut.rb +86 -0
- data/lib/rex/socket/comm.rb +119 -0
- data/lib/rex/socket/comm/local.rb +409 -0
- data/lib/rex/socket/comm/local.rb.ut.rb +75 -0
- data/lib/rex/socket/ip.rb +129 -0
- data/lib/rex/socket/parameters.rb +345 -0
- data/lib/rex/socket/parameters.rb.ut.rb +51 -0
- data/lib/rex/socket/range_walker.rb +295 -0
- data/lib/rex/socket/range_walker.rb.ut.rb +55 -0
- data/lib/rex/socket/ssl_tcp.rb +184 -0
- data/lib/rex/socket/ssl_tcp.rb.ut.rb +39 -0
- data/lib/rex/socket/ssl_tcp_server.rb +122 -0
- data/lib/rex/socket/ssl_tcp_server.rb.ut.rb +51 -0
- data/lib/rex/socket/subnet_walker.rb +75 -0
- data/lib/rex/socket/subnet_walker.rb.ut.rb +28 -0
- data/lib/rex/socket/switch_board.rb +272 -0
- data/lib/rex/socket/switch_board.rb.ut.rb +52 -0
- data/lib/rex/socket/tcp.rb +76 -0
- data/lib/rex/socket/tcp.rb.ut.rb +64 -0
- data/lib/rex/socket/tcp_server.rb +67 -0
- data/lib/rex/socket/tcp_server.rb.ut.rb +44 -0
- data/lib/rex/socket/udp.rb +157 -0
- data/lib/rex/socket/udp.rb.ut.rb +44 -0
- data/lib/rex/struct2.rb +5 -0
- data/lib/rex/struct2/c_struct.rb +181 -0
- data/lib/rex/struct2/c_struct_template.rb +39 -0
- data/lib/rex/struct2/constant.rb +26 -0
- data/lib/rex/struct2/element.rb +44 -0
- data/lib/rex/struct2/generic.rb +73 -0
- data/lib/rex/struct2/restraint.rb +54 -0
- data/lib/rex/struct2/s_string.rb +72 -0
- data/lib/rex/struct2/s_struct.rb +111 -0
- data/lib/rex/sync.rb +6 -0
- data/lib/rex/sync/event.rb +94 -0
- data/lib/rex/sync/read_write_lock.rb +176 -0
- data/lib/rex/sync/ref.rb +57 -0
- data/lib/rex/sync/thread_safe.rb +82 -0
- data/lib/rex/test.rb +35 -0
- data/lib/rex/text.rb +1029 -0
- data/lib/rex/text.rb.ut.rb +168 -0
- data/lib/rex/time.rb +65 -0
- data/lib/rex/transformer.rb +115 -0
- data/lib/rex/transformer.rb.ut.rb +38 -0
- data/lib/rex/ui.rb +21 -0
- data/lib/rex/ui/interactive.rb +252 -0
- data/lib/rex/ui/output.rb +80 -0
- data/lib/rex/ui/output/none.rb +18 -0
- data/lib/rex/ui/progress_tracker.rb +96 -0
- data/lib/rex/ui/subscriber.rb +149 -0
- data/lib/rex/ui/text/color.rb +97 -0
- data/lib/rex/ui/text/color.rb.ut.rb +18 -0
- data/lib/rex/ui/text/dispatcher_shell.rb +382 -0
- data/lib/rex/ui/text/input.rb +117 -0
- data/lib/rex/ui/text/input/buffer.rb +75 -0
- data/lib/rex/ui/text/input/readline.rb +129 -0
- data/lib/rex/ui/text/input/socket.rb +95 -0
- data/lib/rex/ui/text/input/stdio.rb +45 -0
- data/lib/rex/ui/text/irb_shell.rb +55 -0
- data/lib/rex/ui/text/output.rb +80 -0
- data/lib/rex/ui/text/output/buffer.rb +65 -0
- data/lib/rex/ui/text/output/file.rb +37 -0
- data/lib/rex/ui/text/output/socket.rb +43 -0
- data/lib/rex/ui/text/output/stdio.rb +40 -0
- data/lib/rex/ui/text/progress_tracker.rb +56 -0
- data/lib/rex/ui/text/progress_tracker.rb.ut.rb +34 -0
- data/lib/rex/ui/text/shell.rb +321 -0
- data/lib/rex/ui/text/table.rb +254 -0
- data/lib/rex/ui/text/table.rb.ut.rb +55 -0
- data/lib/rex/zip.rb +93 -0
- data/lib/rex/zip/archive.rb +91 -0
- data/lib/rex/zip/blocks.rb +182 -0
- data/lib/rex/zip/entry.rb +95 -0
- data/lib/rex/zip/samples/comment.rb +32 -0
- data/lib/rex/zip/samples/mkwar.rb +138 -0
- data/lib/rex/zip/samples/mkzip.rb +19 -0
- data/lib/rex/zip/samples/recursive.rb +58 -0
- metadata +435 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..'))
|
|
4
|
+
|
|
5
|
+
require 'test/unit'
|
|
6
|
+
require 'rex/file'
|
|
7
|
+
|
|
8
|
+
class Rex::FileUtils::UnitTest < ::Test::Unit::TestCase
|
|
9
|
+
Klass = Rex::FileUtils
|
|
10
|
+
|
|
11
|
+
def test_find_full_path
|
|
12
|
+
assert_not_nil(Klass.find_full_path("ls"))
|
|
13
|
+
assert_nil(Klass.find_full_path("cookie monster cake"))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# $Id: disk.rb 5401 2008-02-09 04:35:21Z ramon $
|
|
4
|
+
|
|
5
|
+
require 'rex/image_source/image_source'
|
|
6
|
+
require 'rex/struct2'
|
|
7
|
+
|
|
8
|
+
module Rex
|
|
9
|
+
module ImageSource
|
|
10
|
+
class Disk < ImageSource
|
|
11
|
+
|
|
12
|
+
attr_accessor :file, :file_offset, :size
|
|
13
|
+
|
|
14
|
+
WINDOW_SIZE = 4096
|
|
15
|
+
WINDOW_OVERLAP = 64
|
|
16
|
+
|
|
17
|
+
def initialize(_file, _offset = 0, _len = nil)
|
|
18
|
+
_len = _file.stat.size if !_len
|
|
19
|
+
|
|
20
|
+
self.file = _file
|
|
21
|
+
self.file_offset = _offset
|
|
22
|
+
self.size = _len
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def read(offset, len)
|
|
26
|
+
if offset < 0 || offset+len > size
|
|
27
|
+
raise RangeError, "Offset #{offset} outside of image source", caller
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
file.seek(file_offset + offset)
|
|
31
|
+
file.read(len)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def index(search, offset = 0)
|
|
35
|
+
# do a sliding window search across the disk
|
|
36
|
+
while offset < size
|
|
37
|
+
|
|
38
|
+
# get a full window size if we can, we
|
|
39
|
+
# don't want to read past our boundaries
|
|
40
|
+
wsize = size - offset
|
|
41
|
+
wsize = WINDOW_SIZE if wsize > WINDOW_SIZE
|
|
42
|
+
|
|
43
|
+
window = self.read(offset, wsize)
|
|
44
|
+
res = window.index(search)
|
|
45
|
+
return res + offset if res
|
|
46
|
+
offset += WINDOW_SIZE - WINDOW_OVERLAP
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def subsource(offset, len)
|
|
51
|
+
self.class.new(file, file_offset+offset, len)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def close
|
|
55
|
+
file.close
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# $Id: image_source.rb 5401 2008-02-09 04:35:21Z ramon $
|
|
4
|
+
|
|
5
|
+
module Rex
|
|
6
|
+
module ImageSource
|
|
7
|
+
class ImageSource
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
# Um, just some abstract class stuff I guess, this is the interface
|
|
11
|
+
# that any image sources should subscribe to...
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
def subsource(offset, len)
|
|
15
|
+
raise "do something"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def size
|
|
19
|
+
raise "do something"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def file_offset
|
|
23
|
+
raise "do something"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def close
|
|
27
|
+
raise "do something"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def read_asciiz(offset)
|
|
31
|
+
# FIXME, make me better
|
|
32
|
+
string = ''
|
|
33
|
+
loop do
|
|
34
|
+
char = read(offset, 1)
|
|
35
|
+
break if char == "\x00"
|
|
36
|
+
offset += 1
|
|
37
|
+
string << char
|
|
38
|
+
end
|
|
39
|
+
return string
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# $Id: memory.rb 5401 2008-02-09 04:35:21Z ramon $
|
|
4
|
+
|
|
5
|
+
require 'rex/image_source/image_source'
|
|
6
|
+
require 'rex/struct2'
|
|
7
|
+
|
|
8
|
+
module Rex
|
|
9
|
+
module ImageSource
|
|
10
|
+
class Memory < ImageSource
|
|
11
|
+
|
|
12
|
+
attr_accessor :rawdata, :size, :file_offset
|
|
13
|
+
|
|
14
|
+
def initialize(_rawdata, _file_offset = 0)
|
|
15
|
+
self.rawdata = _rawdata
|
|
16
|
+
self.size = _rawdata.length
|
|
17
|
+
self.file_offset = _file_offset
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def read(offset, len)
|
|
21
|
+
rawdata[offset, len]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def subsource(offset, len)
|
|
25
|
+
self.class.new(rawdata[offset, len], offset + file_offset)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def close
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def index(*args)
|
|
32
|
+
rawdata.index(*args)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
module Rex
|
|
2
|
+
module IO
|
|
3
|
+
|
|
4
|
+
require 'rex/ui/text/output'
|
|
5
|
+
require 'rex/ui/text/output/buffer'
|
|
6
|
+
require 'rex/ui/text/input/buffer'
|
|
7
|
+
|
|
8
|
+
class BidirectionalPipe < Rex::Ui::Text::Input
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@subscribers_out = {}
|
|
12
|
+
@subscribers_ref = {}
|
|
13
|
+
@subscribers_idx = 0
|
|
14
|
+
@pipe_input = Rex::Ui::Text::Input::Buffer.new
|
|
15
|
+
|
|
16
|
+
# We are the shell, the input, and the output
|
|
17
|
+
self.output = self
|
|
18
|
+
self.input = self
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def pipe_input
|
|
22
|
+
@pipe_input
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def close
|
|
26
|
+
@pipe_input.close
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def has_subscriber?(id)
|
|
30
|
+
@subscribers_out.has_key?(id)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def create_subscriber(id=nil)
|
|
34
|
+
id ||= (@subscribers_idx += 1).to_s
|
|
35
|
+
@subscribers_out[id] = Rex::Ui::Text::Output::Buffer.new
|
|
36
|
+
return id
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def create_subscriber_proc(id=nil, &block)
|
|
40
|
+
id = create_subscriber(id)
|
|
41
|
+
@subscribers_ref[id] = block
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def remove_subscriber(id)
|
|
45
|
+
@subscribers_out.delete(id)
|
|
46
|
+
@subscribers_ref.delete(id)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def write_input(buf)
|
|
50
|
+
@pipe_input.put(buf)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def read_subscriber(id)
|
|
54
|
+
output = @subscribers_out[id]
|
|
55
|
+
|
|
56
|
+
return '' if output.nil?
|
|
57
|
+
|
|
58
|
+
buf = output.buf
|
|
59
|
+
|
|
60
|
+
output.reset
|
|
61
|
+
|
|
62
|
+
buf
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def print(msg='')
|
|
66
|
+
@subscribers_out.each_pair { |id, buf|
|
|
67
|
+
begin
|
|
68
|
+
@subscribers_ref[id] ? @subscribers_ref[id].call(msg) : buf.print(msg)
|
|
69
|
+
rescue ::Exception => e
|
|
70
|
+
# $stderr.puts "Error handling subscriber #{id}: #{e} #{e.backtrace.inspect}"
|
|
71
|
+
raise e
|
|
72
|
+
end
|
|
73
|
+
}
|
|
74
|
+
msg
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def print_error(msg='')
|
|
78
|
+
print_line('[-] ' + msg)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def print_line(msg='')
|
|
82
|
+
print(msg + "\n")
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def print_good(msg='')
|
|
86
|
+
print_line('[+] ' + msg)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def print_debug(msg='')
|
|
90
|
+
print_line('[!] ' + msg)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def flush
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def print_status(msg='')
|
|
97
|
+
print_line('[*] ' + msg)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
#
|
|
101
|
+
# Wrappers for the pipe_input methods
|
|
102
|
+
#
|
|
103
|
+
|
|
104
|
+
def close
|
|
105
|
+
@pipe_input.close
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def sysread(len = 1)
|
|
109
|
+
@pipe_input.sysread(len)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def put(msg)
|
|
113
|
+
@pipe_input.put(msg)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def gets
|
|
117
|
+
@pipe_input.gets
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def eof?
|
|
121
|
+
@pipe_input.eof?
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def fd
|
|
125
|
+
@pipe_input.fd
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
#
|
|
129
|
+
# Wrappers for shell methods
|
|
130
|
+
#
|
|
131
|
+
|
|
132
|
+
attr_accessor :output, :prompt, :input
|
|
133
|
+
|
|
134
|
+
def intrinsic_shell?
|
|
135
|
+
true
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def supports_readline
|
|
139
|
+
false
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def supports_color?
|
|
143
|
+
false
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def pgets
|
|
147
|
+
gets
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
protected
|
|
152
|
+
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'socket'
|
|
4
|
+
|
|
5
|
+
module Rex
|
|
6
|
+
module IO
|
|
7
|
+
|
|
8
|
+
###
|
|
9
|
+
#
|
|
10
|
+
# This class provides an abstraction to a datagram based
|
|
11
|
+
# connection through the use of a datagram socketpair.
|
|
12
|
+
#
|
|
13
|
+
###
|
|
14
|
+
module DatagramAbstraction
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# Creates a streaming socket pair
|
|
18
|
+
#
|
|
19
|
+
def initialize_abstraction
|
|
20
|
+
self.lsock, self.rsock = Rex::Socket.udp_socket_pair()
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# The left side of the stream (local)
|
|
25
|
+
attr_reader :lsock
|
|
26
|
+
# The right side of the stream (remote)
|
|
27
|
+
attr_reader :rsock
|
|
28
|
+
|
|
29
|
+
protected
|
|
30
|
+
attr_writer :lsock
|
|
31
|
+
attr_writer :rsock
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end; end
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
require 'rex/sync/thread_safe'
|
|
2
|
+
|
|
3
|
+
module Rex
|
|
4
|
+
module IO
|
|
5
|
+
|
|
6
|
+
###
|
|
7
|
+
#
|
|
8
|
+
# This mixin is an abstract representation of a streaming connection. Streams
|
|
9
|
+
# extend classes that must implement the following methods:
|
|
10
|
+
#
|
|
11
|
+
# syswrite(buffer)
|
|
12
|
+
# sysread(length)
|
|
13
|
+
# shutdown(how)
|
|
14
|
+
# close
|
|
15
|
+
# peerinfo
|
|
16
|
+
# localinfo
|
|
17
|
+
#
|
|
18
|
+
###
|
|
19
|
+
module Stream
|
|
20
|
+
|
|
21
|
+
##
|
|
22
|
+
#
|
|
23
|
+
# Abstract methods
|
|
24
|
+
#
|
|
25
|
+
##
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
# This method writes the supplied buffer to the stream. This method
|
|
29
|
+
# intelligent reduces the size of supplied buffers so that ruby doesn't get
|
|
30
|
+
# into a potential global thread blocking state when used on blocking
|
|
31
|
+
# sockets. That is, this method will send the supplied buffer in chunks
|
|
32
|
+
# of, at most, 32768 bytes.
|
|
33
|
+
#
|
|
34
|
+
def write(buf, opts = {})
|
|
35
|
+
total_sent = 0
|
|
36
|
+
total_length = buf.length
|
|
37
|
+
begin
|
|
38
|
+
while( total_sent < total_length )
|
|
39
|
+
s = Rex::ThreadSafe.select( nil, [ fd ], nil, 0.2 )
|
|
40
|
+
if( s == nil || s[0] == nil )
|
|
41
|
+
next
|
|
42
|
+
end
|
|
43
|
+
data = buf[0, 32768]
|
|
44
|
+
sent = fd.syswrite( data )
|
|
45
|
+
if sent > 0
|
|
46
|
+
total_sent += sent
|
|
47
|
+
buf[0, sent] = ""
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
rescue ::IOError, ::Errno::EPIPE
|
|
51
|
+
return nil if (fd.abortive_close == true)
|
|
52
|
+
raise $!
|
|
53
|
+
end
|
|
54
|
+
total_sent
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
#
|
|
58
|
+
# This method reads data of the supplied length from the stream.
|
|
59
|
+
#
|
|
60
|
+
def read(length = nil, opts = {})
|
|
61
|
+
# XXX handle length being nil
|
|
62
|
+
begin
|
|
63
|
+
fd.readpartial(length)
|
|
64
|
+
rescue ::IOError, ::EOFError, ::Errno::EPIPE
|
|
65
|
+
return nil if (fd.abortive_close == true)
|
|
66
|
+
raise $!
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
#
|
|
71
|
+
# Polls the stream to see if there is any read data available. Returns
|
|
72
|
+
# true if data is available for reading, otherwise false is returned.
|
|
73
|
+
#
|
|
74
|
+
def has_read_data?(timeout = nil)
|
|
75
|
+
begin
|
|
76
|
+
if RUBY_VERSION =~ /^1\.9\./
|
|
77
|
+
if ((rv = ::Kernel.select([ fd ], nil, nil, timeout)) and
|
|
78
|
+
(rv[0]) and
|
|
79
|
+
(rv[0][0] == fd))
|
|
80
|
+
true
|
|
81
|
+
else
|
|
82
|
+
false
|
|
83
|
+
end
|
|
84
|
+
else
|
|
85
|
+
if ((rv = Rex::ThreadSafe.select([ fd ], nil, nil, timeout)) and
|
|
86
|
+
(rv[0]) and
|
|
87
|
+
(rv[0][0] == fd))
|
|
88
|
+
true
|
|
89
|
+
else
|
|
90
|
+
false
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
rescue StreamClosedError, ::IOError, ::EOFError, ::Errno::EPIPE
|
|
94
|
+
# If the thing that lead to the closure was an abortive close, then
|
|
95
|
+
# don't raise the stream closed error.
|
|
96
|
+
return false if (fd.abortive_close == true)
|
|
97
|
+
|
|
98
|
+
raise $!
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
#
|
|
103
|
+
# This method returns the selectable file descriptor, or self by default.
|
|
104
|
+
#
|
|
105
|
+
def fd
|
|
106
|
+
self
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
##
|
|
110
|
+
#
|
|
111
|
+
# Common methods
|
|
112
|
+
#
|
|
113
|
+
##
|
|
114
|
+
|
|
115
|
+
#
|
|
116
|
+
# This method writes the supplied buffer to the stream by calling the write
|
|
117
|
+
# routine.
|
|
118
|
+
#
|
|
119
|
+
def <<(buf)
|
|
120
|
+
return write(buf.to_s)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
#
|
|
124
|
+
# This method calls get_once() to read pending data from the socket
|
|
125
|
+
#
|
|
126
|
+
def >>
|
|
127
|
+
get_once
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
#
|
|
131
|
+
# This method writes to the stream, optionally timing out after a period of
|
|
132
|
+
# time.
|
|
133
|
+
#
|
|
134
|
+
def timed_write(buf, wait = def_write_timeout, opts = {})
|
|
135
|
+
if (wait and wait > 0)
|
|
136
|
+
Timeout.timeout(wait) {
|
|
137
|
+
return write(buf, opts)
|
|
138
|
+
}
|
|
139
|
+
else
|
|
140
|
+
return write(buf, opts)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
#
|
|
145
|
+
# This method reads from the stream, optionally timing out after a period
|
|
146
|
+
# of time.
|
|
147
|
+
#
|
|
148
|
+
def timed_read(length = nil, wait = def_read_timeout, opts = {})
|
|
149
|
+
if (wait and wait > 0)
|
|
150
|
+
Timeout.timeout(wait) {
|
|
151
|
+
return read(length, opts)
|
|
152
|
+
}
|
|
153
|
+
else
|
|
154
|
+
return read(length, opts)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
#
|
|
159
|
+
# This method writes the full contents of the supplied buffer, optionally
|
|
160
|
+
# with a timeout.
|
|
161
|
+
#
|
|
162
|
+
def put(buf, opts = {})
|
|
163
|
+
return 0 if (buf == nil or buf.length == 0)
|
|
164
|
+
|
|
165
|
+
send_len = buf.length
|
|
166
|
+
send_idx = 0
|
|
167
|
+
wait = opts['Timeout'] || 0
|
|
168
|
+
|
|
169
|
+
# Keep writing until our send length drops to zero
|
|
170
|
+
while (send_idx < send_len)
|
|
171
|
+
curr_len = timed_write(buf[send_idx, buf.length-send_idx], wait, opts)
|
|
172
|
+
|
|
173
|
+
# If the write operation failed due to an IOError, then we fail.
|
|
174
|
+
return buf.length - send_len if (curr_len == nil)
|
|
175
|
+
|
|
176
|
+
send_len -= curr_len
|
|
177
|
+
send_idx += curr_len
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
return buf.length - send_len
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
#
|
|
185
|
+
# This method emulates the behavior of Pex::Socket::Recv in MSF2
|
|
186
|
+
#
|
|
187
|
+
def get_once(length = -1, timeout = def_read_timeout)
|
|
188
|
+
|
|
189
|
+
if (has_read_data?(timeout) == false)
|
|
190
|
+
return nil
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
bsize = (length == -1) ? def_block_size : length
|
|
194
|
+
|
|
195
|
+
begin
|
|
196
|
+
return read(bsize)
|
|
197
|
+
rescue Exception
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
return ''
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
#
|
|
204
|
+
# This method reads as much data as it can from the wire given a maximum
|
|
205
|
+
# timeout.
|
|
206
|
+
#
|
|
207
|
+
def get(timeout = nil, ltimeout = def_read_loop_timeout, opts = {})
|
|
208
|
+
# For those people who are used to being able to use a negative timeout!
|
|
209
|
+
if (timeout and timeout.to_i < 0)
|
|
210
|
+
timeout = nil
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# No data in the first place? bust.
|
|
214
|
+
if (has_read_data?(timeout) == false)
|
|
215
|
+
return nil
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
buf = ""
|
|
219
|
+
lps = 0
|
|
220
|
+
eof = false
|
|
221
|
+
|
|
222
|
+
# Keep looping until there is no more data to be gotten..
|
|
223
|
+
while (has_read_data?(ltimeout) == true)
|
|
224
|
+
# Catch EOF errors so that we can handle them properly.
|
|
225
|
+
begin
|
|
226
|
+
temp = read(def_block_size)
|
|
227
|
+
rescue EOFError
|
|
228
|
+
eof = true
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# If we read zero bytes and we had data, then we've hit EOF
|
|
232
|
+
if (temp and temp.length == 0)
|
|
233
|
+
eof = true
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# If we reached EOF and there are no bytes in the buffer we've been
|
|
237
|
+
# reading into, then throw an EOF error.
|
|
238
|
+
if (eof)
|
|
239
|
+
# If we've already read at least some data, then it's time to
|
|
240
|
+
# break out and let it be processed before throwing an EOFError.
|
|
241
|
+
if (buf.length > 0)
|
|
242
|
+
break
|
|
243
|
+
else
|
|
244
|
+
raise EOFError
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
break if (temp == nil or temp.empty? == true)
|
|
249
|
+
|
|
250
|
+
buf += temp
|
|
251
|
+
lps += 1
|
|
252
|
+
|
|
253
|
+
break if (lps >= def_max_loops)
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# Return the entire buffer we read in
|
|
257
|
+
return buf
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
##
|
|
261
|
+
#
|
|
262
|
+
# Defaults
|
|
263
|
+
#
|
|
264
|
+
##
|
|
265
|
+
|
|
266
|
+
#
|
|
267
|
+
# The default number of seconds to wait for a write operation to timeout.
|
|
268
|
+
#
|
|
269
|
+
def def_write_timeout
|
|
270
|
+
10
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
#
|
|
274
|
+
# The default number of seconds to wait for a read operation to timeout.
|
|
275
|
+
#
|
|
276
|
+
def def_read_timeout
|
|
277
|
+
10
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
#
|
|
281
|
+
# The default number of seconds to wait while in a read loop after read
|
|
282
|
+
# data has been found.
|
|
283
|
+
#
|
|
284
|
+
def def_read_loop_timeout
|
|
285
|
+
0.1
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
#
|
|
289
|
+
# The maximum number of read loops to perform before returning to the
|
|
290
|
+
# caller.
|
|
291
|
+
#
|
|
292
|
+
def def_max_loops
|
|
293
|
+
1024
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
#
|
|
297
|
+
# The default block size to read in chunks from the wire.
|
|
298
|
+
#
|
|
299
|
+
def def_block_size
|
|
300
|
+
16384
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
#
|
|
304
|
+
# This flag indicates whether or not an abortive close has been issued.
|
|
305
|
+
#
|
|
306
|
+
attr_accessor :abortive_close
|
|
307
|
+
|
|
308
|
+
protected
|
|
309
|
+
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
end end
|
|
313
|
+
|