packetgen 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/packetgen/header/asn1_base.rb +1 -57
- data/lib/packetgen/header/base.rb +2 -58
- data/lib/packetgen/header/dhcp/options.rb +1 -1
- data/lib/packetgen/header/dns/question.rb +1 -1
- data/lib/packetgen/header/tcp/options.rb +1 -1
- data/lib/packetgen/headerable.rb +93 -0
- data/lib/packetgen/packet.rb +1 -0
- data/lib/packetgen/types/array.rb +9 -5
- data/lib/packetgen/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be94839db4cb9f9a818fdf5b948f34185198d7f8445545d13763cf57f313eb3a
|
4
|
+
data.tar.gz: 0cf02398bb76d3bb9083f6bbcb1e873b81c686e822ac3e63790a0b5f5d5155b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c72f91e241484140503a997aca5aa930cb8d3e357103b0af617231d7c49fa791b49537916fd68bb5c8d77b901c203500babf18cfe5c2df40900bfc2a30feb90b
|
7
|
+
data.tar.gz: d76180f3c3089218d67a0840d4f94c802c94bd8990cc45b91062414bba175973cc6f97287c1be99ccd87c063d7ebb17f210f15cc49fdd9eb649ec3465b29ea8e
|
@@ -17,23 +17,7 @@ module PacketGen
|
|
17
17
|
# @author Sylvain Daubert
|
18
18
|
# @since 2.0.0
|
19
19
|
class ASN1Base < RASN1::Model
|
20
|
-
|
21
|
-
# @return [Packet,nil]
|
22
|
-
attr_reader :packet
|
23
|
-
|
24
|
-
# Give protocol name for this class
|
25
|
-
# @return [String]
|
26
|
-
# @since 2.0.0
|
27
|
-
def self.protocol_name
|
28
|
-
return @protocol_name if defined? @protocol_name
|
29
|
-
|
30
|
-
classname = to_s
|
31
|
-
@protocol_name = if classname.start_with?('PacketGen::Header')
|
32
|
-
classname.sub(/.*Header::/, '')
|
33
|
-
else
|
34
|
-
classname.sub(/.*::/, '')
|
35
|
-
end
|
36
|
-
end
|
20
|
+
include Headerable
|
37
21
|
|
38
22
|
# Define some methods from given ASN.1 fields to mimic {Base} attributes
|
39
23
|
# @param [Array<Symbol>] attributes
|
@@ -46,46 +30,6 @@ module PacketGen
|
|
46
30
|
end
|
47
31
|
end
|
48
32
|
|
49
|
-
# Return header protocol name
|
50
|
-
# @return [String]
|
51
|
-
def protocol_name
|
52
|
-
self.class.protocol_name
|
53
|
-
end
|
54
|
-
|
55
|
-
# return header method name
|
56
|
-
# @return [String]
|
57
|
-
# @since 2.0.0
|
58
|
-
def method_name
|
59
|
-
return @method_name if defined? @method_name
|
60
|
-
|
61
|
-
@method_name = protocol_name.downcase.sub(/::/, '_')
|
62
|
-
end
|
63
|
-
|
64
|
-
# Called by {Packet#parse} when guessing first header to check if header
|
65
|
-
# is correct
|
66
|
-
# @return [true]
|
67
|
-
def parse?
|
68
|
-
true
|
69
|
-
end
|
70
|
-
|
71
|
-
# @api private
|
72
|
-
# @since 2.1.4
|
73
|
-
# Set packet to which this header belongs
|
74
|
-
# @param [Packet] packet
|
75
|
-
# @return [Packet] packet
|
76
|
-
def packet=(packet)
|
77
|
-
@packet = packet
|
78
|
-
added_to_packet(packet)
|
79
|
-
@packet
|
80
|
-
end
|
81
|
-
|
82
|
-
# @abstract This method is called when a header is added to a packet.
|
83
|
-
# This base method does nothing but may be overriden by subclasses.
|
84
|
-
# @param [Packet] packet packet to which self is added
|
85
|
-
# @return [void]
|
86
|
-
# @since 2.1.4
|
87
|
-
def added_to_packet(packet) end
|
88
|
-
|
89
33
|
alias parse parse!
|
90
34
|
alias to_s to_der
|
91
35
|
|
@@ -15,6 +15,8 @@ module PacketGen
|
|
15
15
|
# * +#reply!+, which inverts needed fields to forge a response.
|
16
16
|
# @author Sylvain Daubert
|
17
17
|
class Base < Types::Fields
|
18
|
+
include Headerable
|
19
|
+
|
18
20
|
# @api private
|
19
21
|
# Simple class to handle a header association
|
20
22
|
class Binding < Struct.new(:key, :value)
|
@@ -133,10 +135,6 @@ module PacketGen
|
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
136
|
-
# Reference on packet which owns this header
|
137
|
-
# @return [Packet,nil]
|
138
|
-
attr_reader :packet
|
139
|
-
|
140
138
|
# @private
|
141
139
|
# On inheritage, create +@known_header+ class variable
|
142
140
|
# @param [Class] klass
|
@@ -195,19 +193,6 @@ module PacketGen
|
|
195
193
|
end
|
196
194
|
end
|
197
195
|
|
198
|
-
# Give protocol name for this class
|
199
|
-
# @return [String]
|
200
|
-
# @since 2.0.0
|
201
|
-
def self.protocol_name
|
202
|
-
return @protocol_name if defined? @protocol_name
|
203
|
-
|
204
|
-
classname = to_s
|
205
|
-
@protocol_name = if classname.start_with?('PacketGen::Header')
|
206
|
-
classname.sub(/.*Header::/, '')
|
207
|
-
else
|
208
|
-
classname.sub(/.*::/, '')
|
209
|
-
end
|
210
|
-
end
|
211
196
|
|
212
197
|
# Helper method to calculate length of +hdr+ and set its +length+ field.
|
213
198
|
# To be used by +#calc_length+ in Base subclasses.
|
@@ -236,47 +221,6 @@ module PacketGen
|
|
236
221
|
super
|
237
222
|
end
|
238
223
|
|
239
|
-
# Return header protocol name
|
240
|
-
# @return [String]
|
241
|
-
def protocol_name
|
242
|
-
self.class.protocol_name
|
243
|
-
end
|
244
|
-
|
245
|
-
# return header method name
|
246
|
-
# @return [String]
|
247
|
-
# @since 2.0.0
|
248
|
-
# @since 2.8.6 permit multiple nesting levels
|
249
|
-
def method_name
|
250
|
-
return @method_name if defined? @method_name
|
251
|
-
|
252
|
-
@method_name = protocol_name.downcase.gsub(/::/, '_')
|
253
|
-
end
|
254
|
-
|
255
|
-
# @abstract Should be redefined by subclasses. This method should check invariant
|
256
|
-
# fields from header.
|
257
|
-
# Call by {Packet#parse} when guessing first header to check if header is correct
|
258
|
-
# @return [Boolean]
|
259
|
-
def parse?
|
260
|
-
true
|
261
|
-
end
|
262
|
-
|
263
|
-
# @api private
|
264
|
-
# Set packet to which this header belongs
|
265
|
-
# @param [Packet] packet
|
266
|
-
# @return [Packet] packet
|
267
|
-
# @since 2.1.4
|
268
|
-
def packet=(packet)
|
269
|
-
@packet = packet
|
270
|
-
added_to_packet(packet)
|
271
|
-
@packet
|
272
|
-
end
|
273
|
-
|
274
|
-
# @abstract This method is called when a header is added to a packet.
|
275
|
-
# This base method does nothing but may be overriden by subclasses.
|
276
|
-
# @param [Packet] packet packet to which self is added
|
277
|
-
# @return [void]
|
278
|
-
# @since 2.1.4
|
279
|
-
def added_to_packet(packet) end
|
280
224
|
|
281
225
|
# @api private
|
282
226
|
# Get +header+ id in {Packet#headers} array
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# This file is part of PacketGen
|
2
|
+
# See https://github.com/sdaubert/packetgen for more informations
|
3
|
+
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
|
+
# This program is published under MIT license.
|
5
|
+
|
6
|
+
# frozen_string_literal: true
|
7
|
+
|
8
|
+
module PacketGen
|
9
|
+
# This mixin module defines minimal API for a class to act as a header
|
10
|
+
# in {Packet}.
|
11
|
+
# @author Sylvain Daubert
|
12
|
+
# @since 3.0.2
|
13
|
+
module Headerable
|
14
|
+
# This modules handles class methods for {Headerable headerable classes}.
|
15
|
+
module ClassMethods
|
16
|
+
# Give protocol name for this class
|
17
|
+
# @return [String]
|
18
|
+
def protocol_name
|
19
|
+
return @protocol_name if defined? @protocol_name
|
20
|
+
|
21
|
+
classname = to_s
|
22
|
+
@protocol_name = if classname.start_with?('PacketGen::Header')
|
23
|
+
classname.sub(/.*Header::/, '')
|
24
|
+
else
|
25
|
+
classname.sub(/.*::/, '')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @api private
|
31
|
+
# Extend +klass+ with {ClassMethods}.
|
32
|
+
# @param [Class] klass
|
33
|
+
# @return [void]
|
34
|
+
def self.included(klass)
|
35
|
+
klass.extend ClassMethods
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return header protocol name
|
39
|
+
# @return [String]
|
40
|
+
def protocol_name
|
41
|
+
self.class.protocol_name
|
42
|
+
end
|
43
|
+
|
44
|
+
# return header method name
|
45
|
+
# @return [String]
|
46
|
+
def method_name
|
47
|
+
return @method_name if defined? @method_name
|
48
|
+
|
49
|
+
@method_name = protocol_name.downcase.gsub(/::/, '_')
|
50
|
+
end
|
51
|
+
|
52
|
+
# @abstract Should be redefined by subclasses. This method should check invariant
|
53
|
+
# fields from header.
|
54
|
+
# Called by {Packet#parse} when guessing first header to check if header is correct
|
55
|
+
# @return [Boolean]
|
56
|
+
def parse?
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
# Reference on packet which owns this header
|
61
|
+
# @return [Packet,nil]
|
62
|
+
def packet
|
63
|
+
@packet ||= nil
|
64
|
+
end
|
65
|
+
|
66
|
+
# @api private
|
67
|
+
# Set packet to which this header belongs
|
68
|
+
# @param [Packet] packet
|
69
|
+
# @return [Packet] packet
|
70
|
+
def packet=(packet)
|
71
|
+
@packet = packet
|
72
|
+
added_to_packet(packet)
|
73
|
+
@packet
|
74
|
+
end
|
75
|
+
|
76
|
+
# @abstract This method is called when a header is added to a packet.
|
77
|
+
# This base method does nothing but may be overriden by subclasses.
|
78
|
+
# @param [Packet] packet packet to which self is added
|
79
|
+
# @return [void]
|
80
|
+
def added_to_packet(packet) end
|
81
|
+
|
82
|
+
# @abstract This method MUST be redefined by subclasses.
|
83
|
+
# Populate headerable object from a binary string.
|
84
|
+
# @param [String] str
|
85
|
+
# @return [self]
|
86
|
+
# @raise [NotImplementedError]
|
87
|
+
def read(str)
|
88
|
+
super
|
89
|
+
rescue NoMethodError
|
90
|
+
raise NotImplementedError, "#{self.class} should implement #read"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/packetgen/packet.rb
CHANGED
@@ -18,11 +18,11 @@ module PacketGen
|
|
18
18
|
# by {.set_of}.
|
19
19
|
#
|
20
20
|
# == #real_type
|
21
|
-
# Subclasses should define private method +#real_type+
|
21
|
+
# Subclasses should define private method +#real_type+ if {.set_of} type
|
22
22
|
# may be subclassed. This method should return real class to use. It
|
23
23
|
# takes an only argument, which is of type given by {.set_of}.
|
24
24
|
#
|
25
|
-
# Default behaviour of this method is to argument's class.
|
25
|
+
# Default behaviour of this method is to return argument's class.
|
26
26
|
#
|
27
27
|
# @author Sylvain Daubert
|
28
28
|
class Array
|
@@ -201,11 +201,15 @@ module PacketGen
|
|
201
201
|
|
202
202
|
private
|
203
203
|
|
204
|
-
def record_from_hash(
|
204
|
+
def record_from_hash(hsh)
|
205
205
|
obj_klass = self.class.set_of_klass
|
206
|
-
|
206
|
+
unless obj_klass
|
207
|
+
raise NotImplementedError, 'class should define #record_from_hash or declare type of elements in set with .set_of'
|
208
|
+
end
|
207
209
|
|
208
|
-
|
210
|
+
obj = obj_klass.new(hsh) if obj_klass
|
211
|
+
klass = real_type(obj)
|
212
|
+
klass == obj_klass ? obj : klass.new(hsh)
|
209
213
|
end
|
210
214
|
|
211
215
|
def real_type(obj)
|
data/lib/packetgen/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: packetgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvain Daubert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: interfacez
|
@@ -234,6 +234,7 @@ files:
|
|
234
234
|
- lib/packetgen/header/tcp/options.rb
|
235
235
|
- lib/packetgen/header/tftp.rb
|
236
236
|
- lib/packetgen/header/udp.rb
|
237
|
+
- lib/packetgen/headerable.rb
|
237
238
|
- lib/packetgen/inspect.rb
|
238
239
|
- lib/packetgen/packet.rb
|
239
240
|
- lib/packetgen/pcapng.rb
|