elf-mithril 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+ define_enum() {
3
+ echo "class $2 < Enum # $1"
4
+ grep "[[:space:]]$1" elf.h | awk '{print $2, " = ", $3}'
5
+ echo "end"
6
+ }
7
+
8
+ define_enum EV_ Version
9
+ define_enum ELFCLASS IdentClass
10
+ define_enum ELFDATA IdentData
11
+ define_enum ELFOSABI OsAbi
12
+ define_enum ET_ Type
13
+ define_enum EM_ Machine
14
+ define_enum SHN_ SpecialSection
15
+ define_enum SHT_ SectionType
16
+ define_enum SHF_ SectionFlags
17
+ define_enum PT_ PhdrType
18
+ define_enum PF_ PhdrFlags
19
+ define_enum DT_ DynamicType
20
+ define_enum DF_ DynamicFlags
21
+ define_enum NT_ CoreNType
22
+ define_enum STB_ SymbolBinding
23
+ define_enum STT_ SymbolType
24
+ define_enum STV_ SymbolVisibility
25
+ define_enum STN_ SymbolName
26
+ define_enum R_ Relocation
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ # One time use more less - quick editor script to parse elf.h (from
3
+ # FreeBSD or go) into ruby-esque DSL
4
+ sed -e 's/\_/ /' -e 's/\;//g' | awk '{printf "%s :%s #", tolower($2) ,$3; for(i=5;i<NF;i++) printf "%s ", $i; printf "\n"}'
5
+
@@ -0,0 +1 @@
1
+ #!/bin/bash
Binary file
@@ -0,0 +1,22 @@
1
+ #include <stdio.h>
2
+ #include <stdint.h>
3
+ uint32_t
4
+ dl_new_hash (const char *s)
5
+ {
6
+ uint32_t h = 5381;
7
+
8
+ for (unsigned char c = *s; c != '\0'; c = *++s)
9
+ h = h * 33 + c;
10
+
11
+ return h;
12
+ }
13
+
14
+ int main(){
15
+ while(!feof(stdin)){
16
+ char buf[1024];
17
+ scanf("%1024s",buf);
18
+ unsigned long ehash1 = dl_new_hash(buf);
19
+ printf("%lu \n",ehash1);
20
+ }
21
+ }
22
+
Binary file
@@ -0,0 +1,70 @@
1
+ #include <stdio.h>
2
+ unsigned long
3
+ elf_hash(const unsigned char *name)
4
+ {
5
+ unsigned long h = 0, g;
6
+ while (*name)
7
+ {
8
+ h = (h << 4) + *name++;
9
+ if (g = h & 0xf0000000)
10
+ h ^= g >> 24;
11
+ h &= ~g;
12
+ }
13
+ return h;
14
+ }
15
+ static unsigned int
16
+ _dl_elf_hash (const char *name_arg)
17
+ {
18
+ const unsigned char *name = (const unsigned char *) name_arg;
19
+ unsigned long int hash = *name;
20
+ if (hash != 0 && name[1] != '\0')
21
+ {
22
+ hash = (hash << 4) + name[1];
23
+ if (name[2] != '\0')
24
+ {
25
+ hash = (hash << 4) + name[2];
26
+ if (name[3] != '\0')
27
+ {
28
+ hash = (hash << 4) + name[3];
29
+ if (name[4] != '\0')
30
+ {
31
+ hash = (hash << 4) + name[4];
32
+ name += 5;
33
+ while (*name != '\0')
34
+ {
35
+ unsigned long int hi;
36
+ hash = (hash << 4) + *name++;
37
+ hi = hash & 0xf0000000;
38
+
39
+ /* The algorithm specified in the ELF ABI is as
40
+ follows:
41
+
42
+ if (hi != 0)
43
+ hash ^= hi >> 24;
44
+
45
+ hash &= ~hi;
46
+
47
+ But the following is equivalent and a lot
48
+ faster, especially on modern processors. */
49
+
50
+ hash ^= hi >> 24;
51
+ }
52
+
53
+ /* Second part of the modified formula. This
54
+ operation can be lifted outside the loop. */
55
+ hash &= 0x0fffffff;
56
+ }
57
+ }
58
+ }
59
+ }
60
+ return hash;
61
+ }
62
+ int main(){
63
+ while(!feof(stdin)){
64
+ char buf[1024];
65
+ scanf("%1024s",buf);
66
+ unsigned long ehash1 = elf_hash(buf);
67
+ unsigned long ehash2 = _dl_elf_hash(buf);
68
+ printf("%lu\t %lu \n",ehash1,ehash2);
69
+ }
70
+ }
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elf-mithril
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Julian Bangert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bindata
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.5.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: renum
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.4.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.4.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: andand
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: segment_tree
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rbtree-pure
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: In Soviet Russia, Mithril forges Elf
127
+ email:
128
+ - jbangert@acm.org
129
+ executables:
130
+ - mithril-ld
131
+ - mithril-rewrite
132
+ - mithril-section-symbols
133
+ extensions: []
134
+ extra_rdoc_files: []
135
+ files:
136
+ - .gitignore
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/mithril-ld
142
+ - bin/mithril-rewrite
143
+ - bin/mithril-section-symbols
144
+ - lib/mithril.rb
145
+ - lib/mithril/elf.rb
146
+ - lib/mithril/elf_enums.rb
147
+ - lib/mithril/elf_generative.rb
148
+ - lib/mithril/elf_structs.rb
149
+ - lib/mithril/inject_symbols.rb
150
+ - lib/mithril/parser.rb
151
+ - lib/mithril/policy.rb
152
+ - lib/mithril/version.rb
153
+ - lib/mithril/writer.rb
154
+ - lib/mithril/writer2.rb
155
+ - mithril.gemspec
156
+ - test/hash_test.rb
157
+ - tools/#elf_enums.sh#
158
+ - tools/elf.h
159
+ - tools/elf_enums.sh
160
+ - tools/elf_h_processor.sh
161
+ - tools/elf_structs.sh
162
+ - tools/gnu_elf_hash_test
163
+ - tools/gnu_elf_hash_test.cxx
164
+ - tools/hash_test
165
+ - tools/hash_test.c
166
+ homepage: ''
167
+ licenses:
168
+ - MIT
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ none: false
175
+ requirements:
176
+ - - ! '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ requirements: []
186
+ rubyforge_project:
187
+ rubygems_version: 1.8.23
188
+ signing_key:
189
+ specification_version: 3
190
+ summary: The Mithril toolkit for canonical elf manipulation
191
+ test_files:
192
+ - test/hash_test.rb