elfcat 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 276bf0fda31cc2596108a360c7d483a99988c715
4
+ data.tar.gz: 2465da17762b16996a40e4ada39d36f6f2b5694f
5
+ SHA512:
6
+ metadata.gz: c11781b78a9749023ab7bc203b3a3a0680dc3ca969be8140317ecf3fff81360ee79f26cb6d5e4b9990438c18f7c2650a0a75035f622a7a40c6ae57edf99fc7dc
7
+ data.tar.gz: b5ac3b81824aad30faad99f5ab1e94333ce6125dc905f4624a05fcff6f516650254782e4259c9de1862845d379754b9125c3eb91b037630086ba8d68cc64147a
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in elfcat.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 gbudiman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Gloria Budiman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ # elfcat
2
+ Executable-and-Linkable Format (ELF) Parser
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "elfcat"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'elfcat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "elfcat"
8
+ spec.version = Elfcat::VERSION
9
+ spec.authors = ["Gloria Budiman"]
10
+ spec.email = ["wahyu.g@gmail.com"]
11
+
12
+ spec.summary = %q{Executable-and-Linkable Format (ELF) Parser}
13
+ spec.description = %q{Parses ELF file into workable ruby data structures}
14
+ spec.homepage = "https://github.com/gbudiman/elfcat"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency "cute-hex", "> 0"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.10"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec"
35
+ end
@@ -0,0 +1,7 @@
1
+ require "cute-hex"
2
+ require "elfcat/version"
3
+ require "elfcat/util"
4
+ require "elfcat/fileheader"
5
+
6
+ module Elfcat
7
+ end
@@ -0,0 +1,17 @@
1
+ class Elf
2
+ attr_reader :resource
3
+
4
+ def initialize _filepath
5
+ @resource = File.binread _filepath
6
+
7
+ return self
8
+ end
9
+
10
+ def file_header
11
+ @file_header ||= FileHeader.new(@resource.slice_with_index(0, 64))
12
+
13
+ # ap @file_header.ei_magic_number
14
+ # ap @file_header[:ei_magic_number]
15
+ # @file_header.debug
16
+ end
17
+ end
@@ -0,0 +1,50 @@
1
+ class FileHeader
2
+ attr_reader :file_header
3
+
4
+ FH = {
5
+ ei_magic_number: [0x00,4],
6
+ ei_class: [0x04],
7
+ ei_data: [0x05],
8
+ ei_version: [0x06],
9
+ ei_osabi: [0x07],
10
+ ei_abiversion: [0x08],
11
+ e_type: [0x10,2],
12
+ e_machine: [0x12,2],
13
+ e_version: [0x14,4],
14
+ e_entry: [0x18,4],
15
+ e_phoff: [0x1C,4],
16
+ e_shoff: [0x20,4],
17
+ e_flags: [0x24,4],
18
+ e_ehsize: [0x28,2],
19
+ e_phentsize: [0x2A,2],
20
+ e_phnum: [0x2C,2],
21
+ e_shentsize: [0x2E,2],
22
+ e_shnum: [0x30,2],
23
+ e_shstrndx: [0x32,2]
24
+ }
25
+
26
+ def initialize _x
27
+ @data = Hash.new
28
+ @debug = Proc.new{self.debug}
29
+
30
+ FH.each do |k, v|
31
+ @data[k] = Util.concatenate(_x, v[0], v[1] || 1)
32
+ end
33
+ end
34
+
35
+ def method_missing _method
36
+ puts "i'm called"
37
+ return @data[_method][:data]
38
+ end
39
+
40
+ def [](_name)
41
+ return @data[_name]
42
+ end
43
+
44
+ def debug
45
+ @data.each do |k, d|
46
+ k_s = sprintf("%32s", k)
47
+ puts "#{k_s} #{CuteHex.x d.data}"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,37 @@
1
+ class String
2
+ def slice_with_index _start, _end
3
+ index = 0
4
+ result = []
5
+
6
+ self.slice(_start, _end).each_byte do |b|
7
+ result[index] = b
8
+ index += 1
9
+ end
10
+
11
+ return result
12
+ end
13
+ end
14
+
15
+ class Hash
16
+ def method_missing _method
17
+ return self[_method]
18
+ end
19
+ end
20
+
21
+ module Util
22
+ def self.concatenate _h, _start, _length = 1
23
+ start = _start
24
+ length = _length
25
+ result = 0
26
+
27
+ loop do
28
+ result |= (_h[start] << ((length - 1) * 8))
29
+
30
+ length -= 1
31
+ break if length == 0
32
+ start += 1
33
+ end
34
+
35
+ return {address: _start, length: _length, data: result}
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Elfcat
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elfcat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gloria Budiman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cute-hex
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>'
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>'
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Parses ELF file into workable ruby data structures
70
+ email:
71
+ - wahyu.g@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .travis.yml
79
+ - Gemfile
80
+ - LICENSE
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - elfcat.gemspec
87
+ - lib/elfcat.rb
88
+ - lib/elfcat/elf.rb
89
+ - lib/elfcat/fileheader.rb
90
+ - lib/elfcat/util.rb
91
+ - lib/elfcat/version.rb
92
+ homepage: https://github.com/gbudiman/elfcat
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.7
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Executable-and-Linkable Format (ELF) Parser
116
+ test_files: []