Skip to content

Commit

Permalink
Add bin2hex lib
Browse files Browse the repository at this point in the history
  • Loading branch information
KINGSABRI committed Jan 31, 2013
1 parent 2121476 commit f9902e4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
13 changes: 9 additions & 4 deletions bofk-cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require 'pattern'
require 'hex2lendian'
require 'hex2bin'
require 'bin2hex'
require 'optparse'
require 'pp'

Expand All @@ -42,7 +43,7 @@
options[:hex2bin] = h2b
end
#--> bin to Hex
opts.on('-x', '--bin2hex', "Convert binary shellcode to Hex string.") do |bin2hex|
opts.on('-x', '--bin2hex BINARY_FILE', "Convert binary shellcode to Hex string.") do |bin2hex|
options[:bin2hex] = bin2hex
end
#--> Display the help screen
Expand All @@ -65,18 +66,19 @@

@pattern = Pattern.new
@hex2bin = Hex2Bin.new()
@bin2hex = Bin2Hex.new

case

#--> Pattern create
when options[:create]
then
puts @pattern.create(options[:create])
puts @pattern.create(options[:create])

#--> Pattern offset
when options[:offset]
then
puts @pattern.offset(options[:offset]) # TODO: make offset can take 2 ARGS
puts @pattern.offset(options[:offset]) # TODO: make offset can take 2 ARGS

#--> Hex to little endian characters converter
when options[:hex2endl]
Expand All @@ -94,7 +96,10 @@
#--> bin to Hex
when options[:bin2hex]
then
puts "bin2hex : to be solved"
puts "\n\n"
@bin2hex.read(options[:bin2hex])
puts @bin2hex.to_hex
puts "\n\n"
else
puts "WTF!!!"
end
Expand Down
45 changes: 45 additions & 0 deletions lib/bin2hex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@


class Bin2Hex

def initialize
@file2read = ""
@hex = ""
end

def read(file)
reader = File.open("#{file}" , 'rb')
@file2read = reader.read.each_byte.map { |b| "%02x" % b } # b.to_s(16).rjust(2, '0')

return @file2read
end

def to_hex
hex_ary = @file2read.join.scan(/.{2}/)
hex_ary.map do |byte|
@hex << '\x' + byte
end

return @hex
end

end


# TODO add file checker
















0 comments on commit f9902e4

Please sign in to comment.