emonti-hexwrench 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,7 @@
1
+ == 0.2.0 / 2009-06-17
2
+ * release version
3
+
4
+ == 0.1.0 / 2009-03-20
5
+
6
+ * enhancements
7
+ * Started using bones to help manage this mess. History.txt is born!
data/README.rdoc ADDED
@@ -0,0 +1,69 @@
1
+
2
+ = hexwrench
3
+
4
+ * http://www.github.com/emonti/hexwrench
5
+
6
+ == DESCRIPTION:
7
+
8
+ Hexwrench is a gui-based hex editor written in ruby based using wxruby.
9
+
10
+
11
+ == REQUIREMENTS:
12
+
13
+ * wxruby >= 0.2.0
14
+ * optional: wxirb (http://www.github.com/emonti/wxirb)
15
+
16
+
17
+ == INSTALL:
18
+
19
+ === Gem Installation
20
+
21
+ gem sources -a http://gems.github.com #(you only have to do this once)
22
+ gem install emonti-hexwrench
23
+
24
+ === Manual installation:
25
+
26
+ You can access the latest hexwrench branches at github with git:
27
+
28
+ git clone git://github.com/emonti/hexwrench.git
29
+
30
+ To generate the gem locally do:
31
+
32
+ cd hexwrench
33
+ rake gem:install
34
+
35
+ or ... you can install manually without rubygems.
36
+
37
+ cd hexwrench
38
+ cp -r hexwrench/lib/* /usr/lib/ruby/1.8/site_ruby/1.8 # or another ruby libdir
39
+ cp bin/* ~/bin # or wherever else in your PATH
40
+
41
+ Run this to generate docs with rdoc the same way the gem would have:
42
+
43
+ rdoc --main README.rdoc README.rdoc lib
44
+
45
+ == LICENSE:
46
+
47
+ (The MIT License)
48
+
49
+ Copyright (c) 2009 Eric Monti, Matasano Security
50
+
51
+ Permission is hereby granted, free of charge, to any person obtaining
52
+ a copy of this software and associated documentation files (the
53
+ 'Software'), to deal in the Software without restriction, including
54
+ without limitation the rights to use, copy, modify, merge, publish,
55
+ distribute, sublicense, and/or sell copies of the Software, and to
56
+ permit persons to whom the Software is furnished to do so, subject to
57
+ the following conditions:
58
+
59
+ The above copyright notice and this permission notice shall be
60
+ included in all copies or substantial portions of the Software.
61
+
62
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
63
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
64
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
65
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
66
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
67
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
68
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
69
+
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ begin
6
+ require 'bones'
7
+ Bones.setup
8
+ rescue LoadError
9
+ begin
10
+ load 'tasks/setup.rb'
11
+ rescue LoadError
12
+ raise RuntimeError, '### please install the "bones" gem ###'
13
+ end
14
+ end
15
+
16
+ ensure_in_path 'lib'
17
+ require 'hexwrench'
18
+
19
+ task :default => 'test:run'
20
+
21
+ PROJ.name = 'hexwrench'
22
+ PROJ.authors = 'Eric Monti'
23
+ PROJ.email = 'emonti@matasano.com'
24
+ PROJ.description = 'A wxwidgets-based hex editor written in ruby'
25
+ PROJ.url = 'http://emonti.github.com/hexwrench'
26
+ PROJ.version = Hexwrench::VERSION
27
+ PROJ.rubyforge.name = 'hexwrench'
28
+ PROJ.readme_file = 'README.rdoc'
29
+
30
+ PROJ.spec.opts << '--color'
31
+
32
+ PROJ.rdoc.opts << '--line-numbers'
33
+
34
+ #PROJ.rdoc.opts << '--diagram'
35
+ PROJ.notes.tags << "X"+"XX" # muhah! so we don't note our-self
36
+
37
+ # exclude rcov.rb from rcov report
38
+ PROJ.rcov.opts += ["--exclude", "rcov.rb", "--exclude", "eventmachine"]
39
+
40
+ depend_on 'wxruby', '>= 2.0.0'
41
+
42
+ # EOF
data/bin/hexwrench ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ end
8
+ require 'wx'
9
+ require 'hexwrench'
10
+
11
+
12
+ Wx::App.run do
13
+ Hexwrench::EditorFrame.new( nil, :filename => ARGV[0]).show
14
+ end
data/hexwrench.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{hexwrench}
5
+ s.version = "0.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Eric Monti"]
9
+ s.date = %q{2009-06-17}
10
+ s.default_executable = %q{hexwrench}
11
+ s.description = %q{A wxwidgets-based hex editor written in ruby}
12
+ s.email = %q{emonti@matasano.com}
13
+ s.executables = ["hexwrench"]
14
+ s.extra_rdoc_files = ["History.txt", "README.rdoc", "bin/hexwrench", "lib/hexwrench/build_xrc.sh", "lib/hexwrench/ui/gui.xrc"]
15
+ s.files = ["History.txt", "README.rdoc", "Rakefile", "bin/hexwrench", "hexwrench.gemspec", "lib/hexwrench.rb", "lib/hexwrench/build_xrc.sh", "lib/hexwrench/data_inspector.rb", "lib/hexwrench/edit_frame.rb", "lib/hexwrench/edit_window.rb", "lib/hexwrench/gui.rb", "lib/hexwrench/stringsgrid.rb", "lib/hexwrench/stringslist.rb", "lib/hexwrench/stringsvlist.rb", "lib/hexwrench/ui/gui.xrc", "samples/ascii_heat_map.rb", "tasks/ann.rake", "tasks/bones.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/notes.rake", "tasks/post_load.rake", "tasks/rdoc.rake", "tasks/rubyforge.rake", "tasks/setup.rb", "tasks/spec.rake", "tasks/svn.rake", "tasks/test.rake"]
16
+ s.homepage = %q{http://emonti.github.com/hexwrench}
17
+ s.rdoc_options = ["--line-numbers", "--main", "README.rdoc"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{hexwrench}
20
+ s.rubygems_version = %q{1.3.4}
21
+ s.summary = %q{A wxwidgets-based hex editor written in ruby}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<wxruby>, [">= 2.0.0"])
29
+ s.add_development_dependency(%q<bones>, [">= 2.5.1"])
30
+ else
31
+ s.add_dependency(%q<wxruby>, [">= 2.0.0"])
32
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
33
+ end
34
+ else
35
+ s.add_dependency(%q<wxruby>, [">= 2.0.0"])
36
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
37
+ end
38
+ end
@@ -0,0 +1 @@
1
+ xrcise -o gui.rb -n Hexwrench ui/gui.xrc
@@ -0,0 +1,138 @@
1
+ require 'rbkb/extends'
2
+
3
+ module Hexwrench
4
+ DEFAULT_DATA_INSPECTORS = [
5
+ { :label => "8 bit",
6
+ :enabled => true,
7
+ :proc => lambda {|buf, idx, parent| buf[idx].to_s} },
8
+
9
+ { :label => "16 bit",
10
+ :enabled => true,
11
+ :proc => lambda do |buf, idx, parent|
12
+ if d=buf[idx,2] and d.size == 2
13
+ d.dat_to_num(parent.endianness)
14
+ end
15
+ end
16
+ },
17
+
18
+ { :label => "32 bit",
19
+ :enabled => true,
20
+ :proc => lambda do |buf, idx, parent|
21
+ if d=buf[idx,4] and d.size == 4
22
+ d.dat_to_num(parent.endianness)
23
+ end
24
+ end
25
+ },
26
+
27
+ { :label => "64 bit",
28
+ :enabled => true,
29
+ :proc => lambda do |buf, idx, parent|
30
+ if d=buf[idx,8] and d.size == 8
31
+ d.dat_to_num(parent.endianness)
32
+ end
33
+ end
34
+ },
35
+
36
+ { :label => "128 bit",
37
+ :enabled => false,
38
+ :proc => lambda do |buf, idx, parent|
39
+ if d=buf[idx,16] and d.size == 16
40
+ d.dat_to_num(parent.endianness)
41
+ end
42
+ end
43
+ },
44
+
45
+ { :label => "IPv4",
46
+ :enabled => true,
47
+ :proc => lambda do |buf, idx, parent|
48
+ if d=buf[idx,4] and d.size == 4
49
+ "#{d[0]}.#{d[1]}.#{d[2]}.#{d[3]}"
50
+ end
51
+ end
52
+ }
53
+ ]
54
+
55
+ DATA_INS_BYTE_ORDER={:big => 0, :little => 1}
56
+
57
+ class DataInspector < Wx::Frame
58
+ attr_accessor :endian, :inspectors, :font
59
+
60
+ def initialize(parent, opts={})
61
+ unless @editor=opts[:editor]
62
+ raise "#{self.class}.new() requires an :editor parameter"
63
+ end
64
+
65
+ super(parent, :title => "Data Inspector")
66
+ @inspectors =(opts[:inspectors] || DEFAULT_DATA_INSPECTORS)
67
+ @endian =(opts[:endian]|| :big)
68
+ @font = (opts[:font] || Wx::Font.new(10, Wx::MODERN, Wx::NORMAL, Wx::NORMAL))
69
+ set_font(@font)
70
+
71
+ @order_sel = Wx::RadioBox.new(self ,
72
+ :choices => ["MSB", "LSB"], :label => "Byte Order")
73
+
74
+ @order_sel.selection = DATA_INS_BYTE_ORDER[@endian]
75
+
76
+ evt_radiobox(@order_sel) {|evt| do_inspectors() }
77
+
78
+ @grid = Wx::Grid.new(self)
79
+ make_grid()
80
+
81
+ @main_sizer = Wx::BoxSizer.new(Wx::VERTICAL)
82
+ @main_sizer.add(@order_sel)
83
+ @main_sizer.add(@grid, Wx::EXPAND|Wx::ALL)
84
+ self.sizer = @main_sizer
85
+ end
86
+
87
+ def endianness
88
+ DATA_INS_BYTE_ORDER.invert[@order_sel.selection]
89
+ end
90
+
91
+ def make_grid()
92
+ @grid.create_grid(@inspectors.select {|x| x[:enabled]}.size, 1)
93
+ @grid.set_row_label_alignment(Wx::ALIGN_RIGHT, Wx::ALIGN_CENTRE)
94
+ @grid.set_default_cell_background_colour(Wx::LIGHT_GREY)
95
+ @grid.set_col_label_size(0)
96
+ @grid.set_col_minimal_acceptable_width(0)
97
+ @grid.enable_grid_lines(false)
98
+ @grid.disable_drag_row_size()
99
+ @grid.disable_drag_grid_size()
100
+ @grid.set_label_font(@font)
101
+ @grid.set_selection_mode(Wx::Grid::GridSelectRows)
102
+
103
+ @grid.begin_batch
104
+ idx=0
105
+ @inspectors.each do |inspector|
106
+ next unless inspector[:enabled]
107
+ label = inspector[:label]
108
+ @grid.set_row_label_value(idx, label.to_s)
109
+ @grid.set_read_only(idx,0) # XXX
110
+ idx+=1
111
+ end
112
+ @grid.end_batch
113
+ end
114
+
115
+ def do_inspectors
116
+ if @editor.selection
117
+ pos = 0
118
+ buf = @editor.data[@editor.selection]
119
+ else
120
+ pos = @editor.cur_pos
121
+ buf = @editor.data
122
+ end
123
+
124
+ @grid.begin_batch
125
+ idx=0
126
+ @inspectors.each do |inspector|
127
+ next unless inspector[:enabled]
128
+ inspector_proc = inspector[:proc]
129
+ val=inspector_proc.call(buf, pos, self)
130
+ @grid.set_cell_value(idx, 0, val.to_s)
131
+ idx+=1
132
+ end
133
+ @grid.auto_size_column(0, true)
134
+ @grid.end_batch
135
+ end
136
+
137
+ end
138
+ end