Check-in [0eb27ae57e]
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | - reading max-rpm internals shows more than the code review does. Win. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
0eb27ae57efe1b935161e635fbf2be13 |
User & Date: | jls@semicomplete.com 2011-05-14 00:11:47 |
Context
2011-05-14
| ||
07:49 | - factor out the rpm bits into separate class files - include all known rpm 'tag' types check-in: 35f668b84f user: jls@semicomplete.com tags: trunk | |
00:11 | - reading max-rpm internals shows more than the code review does. Win. check-in: 0eb27ae57e user: jls@semicomplete.com tags: trunk | |
2011-05-13
| ||
10:41 | - more futile attempts at reverse-engineering the rpm format. check-in: 6804f3caac user: jls@semicomplete.com tags: trunk | |
Changes
Added experimental/LEARN.
> | 1 | http://www.rpm.org/max-rpm/s1-rpm-file-format-rpm-file-format.html |
Changes to experimental/rpmlib.rb.
1 2 3 4 5 6 7 8 9 | require "ap" class RPMFile attr_reader :file def initialize(file) if file.is_a?(String) file = File.new(file, "r") end | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 | require "ap" # Much of the code here is derived from knowledge gained by reading the rpm # source code and this site: # http://www.rpm.org/max-rpm/s1-rpm-file-format-rpm-file-format.html class RPMFile attr_reader :file def initialize(file) if file.is_a?(String) file = File.new(file, "r") end |
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | attr_accessor :name #char name[66]; attr_accessor :osnum #short osnum; attr_accessor :signature_type #short signature_type; attr_accessor :reserved #char reserved[16]; #} # attr_accessor :length def read(file) # Use 'A' here instead of 'a' to trim nulls. @length = 96 data = file.read(@length).unpack("A4CCnnA66nnA16") @magic, @major, @minor, @type, @archnum, @name, \ @osnum, @signature_type, @reserved = data | > > > > > > > > > > > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | attr_accessor :name #char name[66]; attr_accessor :osnum #short osnum; attr_accessor :signature_type #short signature_type; attr_accessor :reserved #char reserved[16]; #} # attr_accessor :length def type case @type when 0 return :binary when 1 return :source else raise "Unknown package 'type' value #{@type}" end end # def type def read(file) # Use 'A' here instead of 'a' to trim nulls. @length = 96 data = file.read(@length).unpack("A4CCnnA66nnA16") @magic, @major, @minor, @type, @archnum, @name, \ @osnum, @signature_type, @reserved = data |
︙ | ︙ | |||
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | end # def validate end # class ::RPMFile::Signature class Header attr_reader :tags attr_reader :length def initialize(rpm) @rpm = rpm @tags = [] end def read # At this point assume we've read and consumed the lead and signature. #len = @rpm.signature.index_length + @rpm.signature # # header size is # ( @rpm.signature.index_length * size of a header entry ) # + @rpm.signature.data_length # # header 'entries' are an # int32 (tag id), int32 (tag type), int32 (offset), uint32 (count) # # See rpm's header.c, the headerLoad method function for reference. | > > > > > > > > > > > > > > | | < | | | | > | | | > | | | | | | | | | | < | > > > > > > > > > > > > > > > > | 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | end # def validate end # class ::RPMFile::Signature class Header attr_reader :tags attr_reader :length attr_accessor :magic # 8-byte string magic attr_accessor :index_length # rpmlib calls this field 'il' unhelpfully attr_accessor :data_length # rpmlib calls this field 'dl' unhelpfully HEADER_MAGIC = "\x8e\xad\xe8\x01\x00\x00\x00\x00" def initialize(rpm) @rpm = rpm @tags = [] end def read # At this point assume we've read and consumed the lead and signature. #len = @rpm.signature.index_length + @rpm.signature # # header size is # ( @rpm.signature.index_length * size of a header entry ) # + @rpm.signature.data_length # # header 'entries' are an # int32 (tag id), int32 (tag type), int32 (offset), uint32 (count) # # See rpm's header.c, the headerLoad method function for reference. # Header always starts with HEADER_MAGIC + index_length(2bytes) + # data_length(2bytes) @length = 16 data = @rpm.file.read(@length).unpack("a8NN") # TODO(sissel): @index_length is really a count, rename? @magic, @index_length, @data_length = data validate entry_size = 16 # tag id, type, offset, count == 16 bytes index_size = @index_length * entry_size tag_data = @rpm.file.read(index_size) data = @rpm.file.read(@data_length) (0 ... @index_length).each do |i| offset = i * entry_size entry_data = tag_data[i * entry_size, entry_size] entry = entry_data.unpack("NNNN") entry << entry_data tag = Tag.new(*entry) @tags << tag # TODO(sissel): This section is pretty F'd up. # Maybe I should just support RPM 3 (centos5 and fedora14 do it) if i == 0 # first tag # First tag must be <100 (if not, it is an 'old' package and # therefore we fabricate a 'region' tag that goes in first. if tag.tag_as_int >= 100 # I don't really feel like supporting this. If you need it, please let me know. raise "Unsupported RPM (Legacy RPM?)" # 7 == :binary (region tag type), 61 = :header_image #legacy_tag = Tag.new(7, 61, entry_size, 0 - @rpm.signature.data_length, data) #@tags.unshift(legacy_tag) end rdl = ril = nil if tag.offset > 0 rdl = -(data[offset,1].unpack("C")).first ril = rdl / entry_size else ril = @rpm.signature.index_length rdl = ril * entry_size tag.tag = 61 # :header_image end tag.offset = -rdl end # first tag handling #ap tag.tag => { #:type => tag.type, #:offset => tag.offset, #:count => tag.count, #:value => tag.value, #} end # each index #@length = (@rpm.signature.index_length * entry_size) + @rpm.signature.data_length end # def read def write end # def write def validate # TODO(sissel): raise real exceptions if @magic != ::RPMFile::Signature::HEADER_MAGIC raise "Signature magic did not match; got #{@magic.inspect}, " \ "expected #{::RPMFile::Signature::HEADER_MAGIC.inspect}" end if !(0..32).include?(@index_length) raise "Invalid 'index_length' value #{@index_length}, expected to be in range [0..32]" end if !(0..8192).include?(@data_length) raise "Invalid 'data_length' value #{@data_length}, expected to be in range [0..8192]" end end # def validate end # class ::RPMFile::Header class Tag attr_accessor :tag attr_accessor :type attr_accessor :offset attr_accessor :count |
︙ | ︙ | |||
259 260 261 262 263 264 265 | end return @signature end # def signature public def header | | > | 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | end return @signature end # def signature public def header #signature lead if @header.nil? @header = ::RPMFile::Header.new(self) @header.read end return @header # http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch15s03s03.html end |
︙ | ︙ |