-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7da8b70
commit 57a9f87
Showing
5 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# frozen_string_literal: true | ||
# | ||
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com) | ||
# | ||
# Ronin is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Ronin is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Ronin. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
|
||
require 'ronin/cli/file_processor_command' | ||
require 'ronin/support/archive' | ||
|
||
module Ronin | ||
class CLI | ||
module Commands | ||
# | ||
# Unarchive the files. | ||
# | ||
# ## Usage | ||
# | ||
# ronin unarchive [options] FILE ... | ||
# | ||
## Options | ||
# | ||
# -f, --format tar|zip Explicit archive format | ||
# | ||
# ## Arguments | ||
# | ||
# FILE ... File(s) to unarchive | ||
# | ||
class Unarchive < FileProcessorCommand | ||
|
||
ALLOWED_EXTENSIONS = ['.tar', '.zip'] | ||
|
||
usage '[options] FILE ...' | ||
|
||
argument :file, required: true, | ||
repeats: true, | ||
desc: 'Archive files to unarchive' | ||
|
||
option :format, short: '-f', | ||
value: { | ||
type: [:tar, :zip] | ||
}, | ||
desc: 'Archive type' | ||
|
||
description 'Unarchive the data' | ||
|
||
man_page 'ronin-unarchive.1' | ||
|
||
# | ||
# Runs the `unarchive` sub-command. | ||
# | ||
# @param [Array<String>] files | ||
# File arguments. | ||
# | ||
def run(*files) | ||
files.each do |file| | ||
extension = File.extname(file) | ||
|
||
unless ALLOWED_EXTENSIONS.include?(extension) | ||
print_error("invalid file: #{file.inspect}") | ||
next | ||
end | ||
|
||
open_archive(file) do |archived_files| | ||
archived_files.each do |archived_file| | ||
File.binwrite(archived_file.name, archived_file.read) | ||
end | ||
end | ||
end | ||
end | ||
|
||
# | ||
# Opens archive for read. | ||
# | ||
# @param [String] file | ||
# File to open. | ||
# | ||
# @yield [archived_file] | ||
# Yielded archived file. | ||
# | ||
# @yieldparam [Zip::Reader, Tar::Reader] reader | ||
# Zip or tar reader object. | ||
# | ||
def open_archive(file,&block) | ||
case options[:format] | ||
when :tar | ||
Support::Archive.untar(file,&block) | ||
when :zip | ||
Support::Archive.unzip(file,&block) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# ronin-unarchive 1 "2024-01-18" Ronin "User Manuals" | ||
|
||
## NAME | ||
|
||
ronin-unarchive - Unarchive the files. | ||
|
||
## SYNOPSIS | ||
|
||
`ronin unarchive` [*options*] *FILE* ... | ||
|
||
## DESCRIPTION | ||
|
||
Unarchive the files. | ||
|
||
## ARGUMENTS | ||
|
||
*FILE* | ||
: Files to unarchive. | ||
|
||
## OPTIONS | ||
|
||
`-f`, `--format` `tar`\|`zip` | ||
: Explicit archive format | ||
|
||
## EXAMPLES | ||
|
||
Archive the file using tar: | ||
|
||
$ ronin unarchive foo.tar | ||
|
||
Archive the file using explicit format: | ||
|
||
$ ronin unarchive -f tar foo.bar | ||
|
||
## AUTHOR | ||
|
||
Postmodern <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,4 +177,4 @@ Postmodern <[email protected]> | |
|
||
## SEE ALSO | ||
|
||
[ronin-help](ronin-help.1.md) [ronin-archive](ronin-archive.1.md) [ronin-asn](ronin-asn.1.md) [ronin-banner-grab](ronin-banner-grab.1.md) [ronin-bitflip](ronin-bitflip.1.md) [ronin-bitsquat](ronin-bitsquat.1.md) [ronin-cert-dump](ronin-cert-dump.1.md) [ronin-cert-gen](ronin-cert-gen.1.md) [ronin-cert-grab](ronin-cert-grab.1.md) [ronin-completion](ronin-completion.1.md) [ronin-decode](ronin-decode.1.md) [ronin-decrypt](ronin-decrypt.1.md) [ronin-dns](ronin-dns.1.md) [ronin-email-addr](ronin-email-addr.1.md) [ronin-encode](ronin-encode.1.md) [ronin-encrypt](ronin-encrypt.1.md) [ronin-entropy](ronin-entropy.1.md) [ronin-escape](ronin-escape.1.md) [ronin-extract](ronin-extract.1.md) [ronin-grep](ronin-grep.1.md) [ronin-hexdump](ronin-hexdump.1.md) [ronin-highlight](ronin-highlight.1.md) [ronin-hmac](ronin-hmac.1.md) [ronin-homoglyph](ronin-homoglyph.1.md) [ronin-host](ronin-host.1.md) [ronin-http](ronin-http.1.md) [ronin-ip](ronin-ip.1.md) [ronin-iprange](ronin-iprange.1.md) [ronin-irb](ronin-irb.1.md) [ronin-md5](ronin-md5.1.md) [ronin-netcat](ronin-netcat.1.md) [ronin-new](ronin-new.1.md) [ronin-pack](ronin-pack.1.md) [ronin-proxy](ronin-proxy.1.md) [ronin-public-suffix-list](ronin-public-suffix-list.1.md) [ronin-quote](ronin-quote.1.md) [ronin-rot](ronin-rot.1.md) [ronin-sha1](ronin-sha1.1.md) [ronin-sha256](ronin-sha256.1.md) [ronin-sha512](ronin-sha512.1.md) [ronin-strings](ronin-strings.1.md) [ronin-tips](ronin-tips.1.md) [ronin-tld-list](ronin-tld-list.1.md) [ronin-typo](ronin-typo.1.md) [ronin-typosquat](ronin-typosquat.1.md) [ronin-unescape](ronin-unescape.1.md) [ronin-unhexdump](ronin-unhexdump.1.md) [ronin-unpack](ronin-unpack.1.md) [ronin-unquote](ronin-unquote.1.md) [ronin-url](ronin-url.1.md) [ronin-xor](ronin-xor.1.md) | ||
[ronin-help](ronin-help.1.md) [ronin-archive](ronin-archive.1.md) [ronin-asn](ronin-asn.1.md) [ronin-banner-grab](ronin-banner-grab.1.md) [ronin-bitflip](ronin-bitflip.1.md) [ronin-bitsquat](ronin-bitsquat.1.md) [ronin-cert-dump](ronin-cert-dump.1.md) [ronin-cert-gen](ronin-cert-gen.1.md) [ronin-cert-grab](ronin-cert-grab.1.md) [ronin-completion](ronin-completion.1.md) [ronin-decode](ronin-decode.1.md) [ronin-decrypt](ronin-decrypt.1.md) [ronin-dns](ronin-dns.1.md) [ronin-email-addr](ronin-email-addr.1.md) [ronin-encode](ronin-encode.1.md) [ronin-encrypt](ronin-encrypt.1.md) [ronin-entropy](ronin-entropy.1.md) [ronin-escape](ronin-escape.1.md) [ronin-extract](ronin-extract.1.md) [ronin-grep](ronin-grep.1.md) [ronin-hexdump](ronin-hexdump.1.md) [ronin-highlight](ronin-highlight.1.md) [ronin-hmac](ronin-hmac.1.md) [ronin-homoglyph](ronin-homoglyph.1.md) [ronin-host](ronin-host.1.md) [ronin-http](ronin-http.1.md) [ronin-ip](ronin-ip.1.md) [ronin-iprange](ronin-iprange.1.md) [ronin-irb](ronin-irb.1.md) [ronin-md5](ronin-md5.1.md) [ronin-netcat](ronin-netcat.1.md) [ronin-new](ronin-new.1.md) [ronin-pack](ronin-pack.1.md) [ronin-proxy](ronin-proxy.1.md) [ronin-public-suffix-list](ronin-public-suffix-list.1.md) [ronin-quote](ronin-quote.1.md) [ronin-rot](ronin-rot.1.md) [ronin-sha1](ronin-sha1.1.md) [ronin-sha256](ronin-sha256.1.md) [ronin-sha512](ronin-sha512.1.md) [ronin-strings](ronin-strings.1.md) [ronin-tips](ronin-tips.1.md) [ronin-tld-list](ronin-tld-list.1.md) [ronin-typo](ronin-typo.1.md) [ronin-typosquat](ronin-typosquat.1.md) [ronin-unarchive](ronin-unarchive.1.md) [ronin-unescape](ronin-unescape.1.md) [ronin-unhexdump](ronin-unhexdump.1.md) [ronin-unpack](ronin-unpack.1.md) [ronin-unquote](ronin-unquote.1.md) [ronin-url](ronin-url.1.md) [ronin-xor](ronin-xor.1.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'spec_helper' | ||
require 'ronin/cli/commands/unarchive' | ||
require_relative 'man_page_example' | ||
|
||
describe Ronin::CLI::Commands::Unarchive do | ||
include_examples "man_page" | ||
end |