diff options
Diffstat (limited to 'ruby')
-rw-r--r-- | ruby/Makefile.am | 58 | ||||
-rw-r--r-- | ruby/README.rdoc | 4 | ||||
-rw-r--r-- | ruby/Rakefile.in | 114 | ||||
-rw-r--r-- | ruby/doc/site/index.html | 8 | ||||
-rw-r--r-- | ruby/ext/hivex/extconf.rb | 33 | ||||
-rw-r--r-- | ruby/lib/hivex.rb | 18 | ||||
-rwxr-xr-x | ruby/run-ruby-tests | 27 | ||||
-rw-r--r-- | ruby/tests/tc_010_load.rb | 28 | ||||
-rw-r--r-- | ruby/tests/tc_021_close.rb | 29 | ||||
-rw-r--r-- | ruby/tests/tc_200_write.rb | 46 | ||||
-rw-r--r-- | ruby/tests/tc_210_setvalue.rb | 68 |
11 files changed, 433 insertions, 0 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am new file mode 100644 index 0000000..b323d7e --- /dev/null +++ b/ruby/Makefile.am @@ -0,0 +1,58 @@ +# hivex Ruby bindings +# Copyright (C) 2009-2011 Red Hat Inc. +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +EXTRA_DIST = \ + Rakefile.in \ + README.rdoc \ + doc/site/index.html \ + ext/hivex/extconf.rb \ + ext/hivex/_hivex.c \ + lib/hivex.rb \ + run-ruby-tests \ + tests/tc_*.rb + +CLEANFILES = \ + lib/*~ \ + tests/*~ \ + ext/hivex/*~ \ + ext/hivex/extconf.h \ + ext/hivex/_hivex.o \ + ext/hivex/_hivex.so \ + ext/hivex/mkmf.log \ + ext/hivex/Makefile + +if HAVE_RUBY + +TESTS = run-ruby-tests + +TESTS_ENVIRONMENT = \ + LD_LIBRARY_PATH=$(top_builddir)/src/.libs + +all: + rake build + rake rdoc + +RUBY_SITELIB := $(shell ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']") +RUBY_SITEARCH := $(shell ruby -rrbconfig -e "puts Config::CONFIG['sitearchdir']") + +install: + $(MKDIR_P) $(DESTDIR)$(RUBY_SITELIB) + $(MKDIR_P) $(DESTDIR)$(RUBY_SITEARCH) + $(INSTALL) -p -m 0644 lib/hivex.rb $(DESTDIR)$(RUBY_SITELIB) + $(INSTALL) -p -m 0755 ext/hivex/_hivex.so $(DESTDIR)$(RUBY_SITEARCH) + +endif diff --git a/ruby/README.rdoc b/ruby/README.rdoc new file mode 100644 index 0000000..7965650 --- /dev/null +++ b/ruby/README.rdoc @@ -0,0 +1,4 @@ += Ruby bindings for hivex + +The module Hivex provides Ruby bindings for +{the hivex API}[http://libguestfs.org/hivex.3.html]. diff --git a/ruby/Rakefile.in b/ruby/Rakefile.in new file mode 100644 index 0000000..da9f3f1 --- /dev/null +++ b/ruby/Rakefile.in @@ -0,0 +1,114 @@ +# hivex Ruby bindings -*- ruby -*- +# @configure_input@ +# Copyright (C) 2009-2011 Red Hat Inc. +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +require 'rake/clean' +require 'rake/rdoctask' +require 'rake/testtask' +require 'rake/gempackagetask' + +PKG_NAME='@PACKAGE_NAME@' +PKG_VERSION='@PACKAGE_VERSION@' + +EXT_CONF='@srcdir@/ext/hivex/extconf.rb' +MAKEFILE='@builddir@/ext/hivex/Makefile' +HIVEX_MODULE='@builddir@/ext/hivex/_hivex.so' +HIVEX_SRC='@srcdir@/ext/hivex/_hivex.c' + +CLEAN.include [ "@builddir@/ext/**/*.o", HIVEX_MODULE, + "@builddir@/ext/**/depend" ] + +CLOBBER.include [ "@builddir@/config.save", "@builddir@/ext/**/mkmf.log", + MAKEFILE ] + +# Build locally + +file MAKEFILE => EXT_CONF do |t| + unless sh "top_srcdir=$(pwd)/@top_srcdir@; top_builddir=$(pwd)/@top_builddir@; export ARCHFLAGS=\"-arch $(uname -m)\"; cd #{File::dirname(EXT_CONF)}; ruby #{File::basename(EXT_CONF)} --with-_hivex-include=$top_srcdir/lib --with-_hivex-lib=$top_builddir/lib/.libs" + $stderr.puts "Failed to run extconf" + break + end +end +file HIVEX_MODULE => [ MAKEFILE, HIVEX_SRC ] do |t| + Dir::chdir(File::dirname(EXT_CONF)) do + unless sh "make" + $stderr.puts "make failed" + break + end + end +end +desc "Build the native library" +task :build => HIVEX_MODULE + +Rake::TestTask.new(:test) do |t| + t.test_files = FileList['tests/tc_*.rb'] + t.libs = [ 'lib', 'ext/hivex' ] +end +task :test => :build + +RDOC_FILES = FileList[ + "README.rdoc", + "lib/**/*.rb", + "ext/**/*.[ch]" +] + +Rake::RDocTask.new do |rd| + rd.main = "README.rdoc" + rd.rdoc_dir = "doc/site/api" + rd.rdoc_files.include(RDOC_FILES) +end + +Rake::RDocTask.new(:ri) do |rd| + rd.main = "README.rdoc" + rd.rdoc_dir = "doc/ri" + rd.options << "--ri-system" + rd.rdoc_files.include(RDOC_FILES) +end + +# Package tasks + +PKG_FILES = FileList[ + "Rakefile", "COPYING", "README", "NEWS", "README.rdoc", + "lib/**/*.rb", + "ext/**/*.[ch]", "ext/**/MANIFEST", "ext/**/extconf.rb", + "tests/**/*", + "spec/**/*" +] + +DIST_FILES = FileList[ + "pkg/*.src.rpm", "pkg/*.gem", "pkg/*.zip", "pkg/*.tgz" +] + +SPEC = Gem::Specification.new do |s| + s.name = PKG_NAME + s.version = PKG_VERSION + s.email = "rjones@redhat.com" + s.homepage = "http://libguestfs.org/" + s.summary = "Ruby bindings for hivex" + s.files = PKG_FILES + s.autorequire = "hivex" + s.required_ruby_version = '>= 1.8.1' + s.extensions = "ext/hivex/extconf.rb" + s.description = <<EOF +Ruby bindings for hivex. +EOF +end + +Rake::GemPackageTask.new(SPEC) do |pkg| + pkg.need_tar = true + pkg.need_zip = true +end diff --git a/ruby/doc/site/index.html b/ruby/doc/site/index.html new file mode 100644 index 0000000..c97f0e0 --- /dev/null +++ b/ruby/doc/site/index.html @@ -0,0 +1,8 @@ +<html> +<head><title>Ruby documentation for hivex</title></head> +<body> +<p> + <a href="api/index.html">Ruby API documentation for hivex</a> +</p> +</body> +</html> diff --git a/ruby/ext/hivex/extconf.rb b/ruby/ext/hivex/extconf.rb new file mode 100644 index 0000000..c144c4b --- /dev/null +++ b/ruby/ext/hivex/extconf.rb @@ -0,0 +1,33 @@ +# hivex Ruby bindings -*- ruby -*- +# @configure_input@ +# Copyright (C) 2009-2011 Red Hat Inc. +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +require 'mkmf' + +extension_name = '_hivex' + +dir_config(extension_name) + +unless have_header("hivex.h") + raise "<hivex.h> not found" +end +unless have_library("hivex", "hivex_open", "hivex.h") + raise "hivex library not found" +end + +create_header +create_makefile(extension_name) diff --git a/ruby/lib/hivex.rb b/ruby/lib/hivex.rb new file mode 100644 index 0000000..a142db1 --- /dev/null +++ b/ruby/lib/hivex.rb @@ -0,0 +1,18 @@ +# hivex Ruby bindings +# Copyright (C) 2009-2011 Red Hat Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +require '_hivex' diff --git a/ruby/run-ruby-tests b/ruby/run-ruby-tests new file mode 100755 index 0000000..1ef116c --- /dev/null +++ b/ruby/run-ruby-tests @@ -0,0 +1,27 @@ +#!/bin/sh - +# hivex Ruby bindings +# Copyright (C) 2009-2011 Red Hat Inc. +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +set -e + +# Run them one at a time, otherwise rake runs them in parallel (which +# is bound to fail because they all use a single test image file). + +for f in tests/tc_*.rb; do + echo rake test "$@" TEST="$f" + rake test "$@" TEST="$f" +done diff --git a/ruby/tests/tc_010_load.rb b/ruby/tests/tc_010_load.rb new file mode 100644 index 0000000..113ab69 --- /dev/null +++ b/ruby/tests/tc_010_load.rb @@ -0,0 +1,28 @@ +# hivex Ruby bindings -*- ruby -*- +# Copyright (C) 2009-2011 Red Hat Inc. +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +require 'test/unit' +$:.unshift(File::join(File::dirname(__FILE__), "..", "lib")) +$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "hivex")) +require 'hivex' + +class TestLoad < Test::Unit::TestCase + def test_load + h = Hivex::open("../images/minimal", {}) + assert_not_nil (h) + end +end diff --git a/ruby/tests/tc_021_close.rb b/ruby/tests/tc_021_close.rb new file mode 100644 index 0000000..a089cf3 --- /dev/null +++ b/ruby/tests/tc_021_close.rb @@ -0,0 +1,29 @@ +# hivex Ruby bindings -*- ruby -*- +# Copyright (C) 2009-2011 Red Hat Inc. +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +require 'test/unit' +$:.unshift(File::join(File::dirname(__FILE__), "..", "lib")) +$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "hivex")) +require 'hivex' + +class TestClose < Test::Unit::TestCase + def test_close + h = Hivex::open("../images/minimal", {}) + assert_not_nil (h) + h.close() + end +end diff --git a/ruby/tests/tc_200_write.rb b/ruby/tests/tc_200_write.rb new file mode 100644 index 0000000..b46dc7b --- /dev/null +++ b/ruby/tests/tc_200_write.rb @@ -0,0 +1,46 @@ +# hivex Ruby bindings -*- ruby -*- +# Copyright (C) 2009-2011 Red Hat Inc. +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +require 'test/unit' +$:.unshift(File::join(File::dirname(__FILE__), "..", "lib")) +$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "hivex")) +require 'hivex' + +class TestWrite < Test::Unit::TestCase + def test_write + h = Hivex::open("../images/minimal", {:write => 1}) + assert_not_nil (h) + + root = h.root() + assert (root) + + h.node_add_child(root, "A") + h.node_add_child(root, "B") + b = h.node_get_child(root, "B") + assert (b) + + values = [ + { :key => "Key1", :type => 3, :value => "ABC" }, + { :key => "Key2", :type => 3, :value => "DEF" } + ] + h.node_set_values(b, values) + + # Don't actually commit here because that would overwrite + # the original file. + # h.commit() + end +end diff --git a/ruby/tests/tc_210_setvalue.rb b/ruby/tests/tc_210_setvalue.rb new file mode 100644 index 0000000..e55e5fe --- /dev/null +++ b/ruby/tests/tc_210_setvalue.rb @@ -0,0 +1,68 @@ +# hivex Ruby bindings -*- ruby -*- +# Copyright (C) 2009-2011 Red Hat Inc. +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +require 'test/unit' +$:.unshift(File::join(File::dirname(__FILE__), "..", "lib")) +$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "hivex")) +require 'hivex' + +class TestSetValue < Test::Unit::TestCase + def test_set_value + h = Hivex::open("../images/minimal", {:write => 1}) + assert_not_nil (h) + + root = h.root() + assert (root) + + h.node_add_child(root, "B") + b = h.node_get_child(root, "B") + + values = [ + { :key => "Key1", :type => 3, :value => "ABC" }, + { :key => "Key2", :type => 2, :value => "DEF" } + ] + h.node_set_values(b, values) + + value1 = { :key => "Key3", :type => 3, :value => "GHI" } + h.node_set_value(b, value1) + + value2 = { :key => "Key1", :type => 3, :value => "JKL" } + h.node_set_value(b, value2) + + val = h.node_get_value(b, "Key1") + hash = h.value_value(val) + assert (hash[:type] == 3) + assert (hash[:value] == "JKL") + assert (hash[:len] == 3) + + val = h.node_get_value(b, "Key2") + hash = h.value_value(val) + assert (hash[:type] == 2) + assert (hash[:value] == "DEF") + assert (hash[:len] == 3) + + val = h.node_get_value(b, "Key3") + hash = h.value_value(val) + assert (hash[:type] == 3) + assert (hash[:value] == "GHI") + assert (hash[:len] == 3) + + # Don't actually commit here because that would overwrite + # the original file. + # h.commit() + end +end |