# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
+require "config"
require "ast"
-OFFSET_HEADER_MAGIC_NUMBERS = [ 0x9e43fd66, 0x4379bfba ]
-OFFSET_MAGIC_NUMBERS = [ 0xec577ac7, 0x0ff5e755 ]
+def to32Bit(value)
+ if value > 0x7fffffff
+ value -= 1 << 32
+ end
+ value
+end
+
+OFFSET_HEADER_MAGIC_NUMBERS = [ to32Bit(0x9e43fd66), to32Bit(0x4379bfba) ]
+OFFSET_MAGIC_NUMBERS = [ to32Bit(0xec577ac7), to32Bit(0x0ff5e755) ]
#
# MissingMagicValuesException
#
# Thrown when magic values are missing from the binary.
-# This is usually an indication that the classic interpreter is enabled.
#
class MissingMagicValuesException < Exception
def offsetsAndConfigurationIndex(file)
endiannessMarkerBytes = nil
- result = []
+ result = {}
def readInt(endianness, bytes)
if endianness == :little
fileBytes = []
- File.open(file, "r") {
+ File.open(file, "rb") {
| inp |
loop {
byte = inp.getbyte
| data |
offsets << readInt(endianness, data)
}
- result << [offsets, index]
+ result[index] = offsets
}
end
}
raise MissingMagicValuesException unless result.length >= 1
- raise if result.map{|v| v[1]}.uniq.size < result.map{|v| v[1]}.size
- result
+ # result is {index1=>offsets1, index2=>offsets2} but we want to return
+ # [[offsets1, index1], [offsets2, index2]].
+ return result.map {
+ | pair |
+ pair.reverse
+ }
end
#