elftools 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elftools.rb +2 -0
- data/lib/elftools/constants.rb +3 -1
- data/lib/elftools/dynamic.rb +3 -1
- data/lib/elftools/elf_file.rb +2 -0
- data/lib/elftools/exceptions.rb +2 -0
- data/lib/elftools/lazy_array.rb +3 -1
- data/lib/elftools/note.rb +3 -1
- data/lib/elftools/sections/dynamic_section.rb +2 -0
- data/lib/elftools/sections/note_section.rb +2 -0
- data/lib/elftools/sections/null_section.rb +2 -0
- data/lib/elftools/sections/relocation_section.rb +2 -0
- data/lib/elftools/sections/section.rb +2 -0
- data/lib/elftools/sections/sections.rb +4 -2
- data/lib/elftools/sections/str_tab_section.rb +2 -0
- data/lib/elftools/sections/sym_tab_section.rb +2 -0
- data/lib/elftools/segments/dynamic_segment.rb +2 -0
- data/lib/elftools/segments/interp_segment.rb +2 -0
- data/lib/elftools/segments/load_segment.rb +2 -0
- data/lib/elftools/segments/note_segment.rb +2 -0
- data/lib/elftools/segments/segment.rb +2 -0
- data/lib/elftools/segments/segments.rb +4 -2
- data/lib/elftools/structs.rb +21 -13
- data/lib/elftools/util.rb +2 -0
- data/lib/elftools/version.rb +3 -1
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 604d1720fabed07c8bb37185d09e89ec8962d3a34ad85ec58ffe42a29e02857a
|
4
|
+
data.tar.gz: 5912030d8207a6f46ae3cd3c91e0b6a60b7a2d75f57e79bfd46dc01dfdb3c9d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01466eb4691e615a65a2efda8914e4c7a4ac17f71b2c437e14b088e4962885fd091e0be981ae81deabdf7aa2425b6e9fff8c0e74434aa09fd489a722d7a81c39
|
7
|
+
data.tar.gz: a551049dedca9a3f69cbd1da213b193c8e1f616bf665113d55832b27543bb3e8b02d0f5e9b87ebf64f50d64fb70c15731f8e504e82cc97fb9d6b1251b2cc8d71
|
data/lib/elftools.rb
CHANGED
data/lib/elftools/constants.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ELFTools
|
2
4
|
# Define constants from elf.h.
|
3
5
|
# Mostly refer from https://github.com/torvalds/linux/blob/master/include/uapi/linux/elf.h
|
4
6
|
# and binutils/elfcpp/elfcpp.h.
|
5
7
|
module Constants
|
6
8
|
# ELF magic header
|
7
|
-
ELFMAG = "\x7FELF"
|
9
|
+
ELFMAG = "\x7FELF"
|
8
10
|
|
9
11
|
# Values of `d_un.d_val' in the DT_FLAGS and DT_FLAGS_1 entry.
|
10
12
|
module DF
|
data/lib/elftools/dynamic.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ELFTools
|
2
4
|
# Define common methods for dynamic sections and dynamic segments.
|
3
5
|
#
|
@@ -89,7 +91,7 @@ module ELFTools
|
|
89
91
|
# @param [Integer] n The index.
|
90
92
|
# @return [ELFTools::Dynamic::Tag] The desired tag.
|
91
93
|
def tag_at(n)
|
92
|
-
return if n
|
94
|
+
return if n.negative?
|
93
95
|
|
94
96
|
@tag_at_map ||= {}
|
95
97
|
return @tag_at_map[n] if @tag_at_map[n]
|
data/lib/elftools/elf_file.rb
CHANGED
data/lib/elftools/exceptions.rb
CHANGED
data/lib/elftools/lazy_array.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ELFTools
|
2
4
|
# A helper class for {ELFTools} easy to implement
|
3
5
|
# 'lazy loading' objects.
|
@@ -37,7 +39,7 @@ module ELFTools
|
|
37
39
|
# return type of block given in {#initialize}.
|
38
40
|
def [](i)
|
39
41
|
# XXX: support negative index?
|
40
|
-
return nil
|
42
|
+
return nil unless i.between?(0, @internal.size - 1)
|
41
43
|
|
42
44
|
@internal[i] ||= @block.call(i)
|
43
45
|
end
|
data/lib/elftools/note.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'elftools/structs'
|
2
4
|
require 'elftools/util'
|
3
5
|
|
@@ -101,7 +103,7 @@ module ELFTools
|
|
101
103
|
# Name of this note.
|
102
104
|
# @return [String] The name.
|
103
105
|
def name
|
104
|
-
return @name if @name
|
106
|
+
return @name if defined?(@name)
|
105
107
|
|
106
108
|
stream.pos = @offset + SIZE_OF_NHDR
|
107
109
|
@name = stream.read(header.n_namesz)[0..-2]
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Require this file to load all sections classes.
|
2
4
|
|
3
5
|
require 'elftools/sections/section'
|
@@ -19,7 +21,7 @@ module ELFTools
|
|
19
21
|
# @param [#pos=, #read] stream Streaming object.
|
20
22
|
# @return [ELFTools::Sections::Section]
|
21
23
|
# Return object dependes on +header.sh_type+.
|
22
|
-
def create(header, stream, *args)
|
24
|
+
def create(header, stream, *args, **kwargs)
|
23
25
|
klass = case header.sh_type
|
24
26
|
when Constants::SHT_DYNAMIC then DynamicSection
|
25
27
|
when Constants::SHT_NULL then NullSection
|
@@ -29,7 +31,7 @@ module ELFTools
|
|
29
31
|
when Constants::SHT_SYMTAB, Constants::SHT_DYNSYM then SymTabSection
|
30
32
|
else Section
|
31
33
|
end
|
32
|
-
klass.new(header, stream, *args)
|
34
|
+
klass.new(header, stream, *args, **kwargs)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Require this file to load all segment classes.
|
2
4
|
|
3
5
|
require 'elftools/segments/segment'
|
@@ -17,7 +19,7 @@ module ELFTools
|
|
17
19
|
# @param [#pos=, #read] stream Streaming object.
|
18
20
|
# @return [ELFTools::Segments::Segment]
|
19
21
|
# Return object dependes on +header.p_type+.
|
20
|
-
def create(header, stream, *args)
|
22
|
+
def create(header, stream, *args, **kwargs)
|
21
23
|
klass = case header.p_type
|
22
24
|
when Constants::PT_DYNAMIC then DynamicSegment
|
23
25
|
when Constants::PT_INTERP then InterpSegment
|
@@ -25,7 +27,7 @@ module ELFTools
|
|
25
27
|
when Constants::PT_NOTE then NoteSegment
|
26
28
|
else Segment
|
27
29
|
end
|
28
|
-
klass.new(header, stream, *args)
|
30
|
+
klass.new(header, stream, *args, **kwargs)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
data/lib/elftools/structs.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bindata'
|
4
|
+
|
2
5
|
module ELFTools
|
3
6
|
# Define ELF related structures in this module.
|
4
7
|
#
|
5
8
|
# Structures are fetched from https://github.com/torvalds/linux/blob/master/include/uapi/linux/elf.h.
|
6
|
-
#
|
7
|
-
# little/big endian simultaneously.
|
9
|
+
# Use gem +bindata+ to have these structures support 32/64 bits and little/big endian simultaneously.
|
8
10
|
module Structs
|
9
11
|
# The base structure to define common methods.
|
10
12
|
class ELFStruct < BinData::Record
|
@@ -23,9 +25,13 @@ module ELFTools
|
|
23
25
|
end
|
24
26
|
|
25
27
|
class << self
|
26
|
-
#
|
27
|
-
#
|
28
|
-
|
28
|
+
# Hooks the constructor.
|
29
|
+
#
|
30
|
+
# +BinData::Record+ doesn't allow us to override +#initialize+, so we hack +new+ here.
|
31
|
+
def new(*args)
|
32
|
+
# XXX: The better implementation is +new(*args, **kwargs)+, but we can't do this unless bindata changed
|
33
|
+
# lib/bindata/dsl.rb#override_new_in_class to invoke +new+ with both +args+ and +kwargs+.
|
34
|
+
kwargs = args.last.is_a?(Hash) ? args.last : {}
|
29
35
|
offset = kwargs.delete(:offset)
|
30
36
|
super.tap do |obj|
|
31
37
|
obj.offset = offset
|
@@ -42,13 +48,13 @@ module ELFTools
|
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
45
|
-
#
|
46
|
-
# @return [
|
51
|
+
# Gets the endianness of current class.
|
52
|
+
# @return [:little, :big] The endianness.
|
47
53
|
def self_endian
|
48
54
|
bindata_name[-2..-1] == 'be' ? :big : :little
|
49
55
|
end
|
50
56
|
|
51
|
-
#
|
57
|
+
# Packs an integer to string.
|
52
58
|
# @param [Integer] val
|
53
59
|
# @param [Integer] bytes
|
54
60
|
# @return [String]
|
@@ -110,7 +116,7 @@ module ELFTools
|
|
110
116
|
choice :sh_entsize, **CHOICE_SIZE_T
|
111
117
|
end
|
112
118
|
|
113
|
-
# Program header structure for
|
119
|
+
# Program header structure for 32-bit.
|
114
120
|
class ELF32_Phdr < ELFStruct
|
115
121
|
endian :big_and_little
|
116
122
|
uint32 :p_type
|
@@ -123,7 +129,7 @@ module ELFTools
|
|
123
129
|
uint32 :p_align
|
124
130
|
end
|
125
131
|
|
126
|
-
# Program header structure for
|
132
|
+
# Program header structure for 64-bit.
|
127
133
|
class ELF64_Phdr < ELFStruct
|
128
134
|
endian :big_and_little
|
129
135
|
uint32 :p_type
|
@@ -135,13 +141,14 @@ module ELFTools
|
|
135
141
|
uint64 :p_memsz
|
136
142
|
uint64 :p_align
|
137
143
|
end
|
138
|
-
|
144
|
+
|
145
|
+
# Gets the class of program header according to bits.
|
139
146
|
ELF_Phdr = {
|
140
147
|
32 => ELF32_Phdr,
|
141
148
|
64 => ELF64_Phdr
|
142
149
|
}.freeze
|
143
150
|
|
144
|
-
# Symbol structure for
|
151
|
+
# Symbol structure for 32-bit.
|
145
152
|
class ELF32_sym < ELFStruct
|
146
153
|
endian :big_and_little
|
147
154
|
uint32 :st_name
|
@@ -152,7 +159,7 @@ module ELFTools
|
|
152
159
|
uint16 :st_shndx
|
153
160
|
end
|
154
161
|
|
155
|
-
# Symbol structure for
|
162
|
+
# Symbol structure for 64-bit.
|
156
163
|
class ELF64_sym < ELFStruct
|
157
164
|
endian :big_and_little
|
158
165
|
uint32 :st_name # Symbol name, index in string tbl
|
@@ -162,6 +169,7 @@ module ELFTools
|
|
162
169
|
uint64 :st_value # Value of the symbol
|
163
170
|
uint64 :st_size # Associated symbol size
|
164
171
|
end
|
172
|
+
|
165
173
|
# Get symbol header class according to bits.
|
166
174
|
ELF_sym = {
|
167
175
|
32 => ELF32_sym,
|
data/lib/elftools/util.rb
CHANGED
data/lib/elftools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elftools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- david942j
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: '0.17'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: '0.17'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: yard
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,15 +154,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
154
|
requirements:
|
155
155
|
- - ">="
|
156
156
|
- !ruby/object:Gem::Version
|
157
|
-
version: 2.
|
157
|
+
version: '2.3'
|
158
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
159
|
requirements:
|
160
160
|
- - ">="
|
161
161
|
- !ruby/object:Gem::Version
|
162
162
|
version: '0'
|
163
163
|
requirements: []
|
164
|
-
|
165
|
-
rubygems_version: 2.7.6
|
164
|
+
rubygems_version: 3.0.2
|
166
165
|
signing_key:
|
167
166
|
specification_version: 4
|
168
167
|
summary: ELFTools - Pure ruby library for parsing and patching ELF files
|