]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - offlineasm/offsets.rb
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / offlineasm / offsets.rb
index 63af014bbccae59b126996d030167a7e904896e5..50b963b72c572ab23ac80b0a9b786ab23c1a6fc7 100644 (file)
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 # THE POSSIBILITY OF SUCH DAMAGE.
 
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 # THE POSSIBILITY OF SUCH DAMAGE.
 
+require "config"
 require "ast"
 
 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.
 
 #
 # MissingMagicValuesException
 #
 # Thrown when magic values are missing from the binary.
-# This is usually an indication that the classic interpreter is enabled.
 #
 
 class MissingMagicValuesException < Exception
 #
 
 class MissingMagicValuesException < Exception
@@ -61,7 +68,7 @@ end
 
 def offsetsAndConfigurationIndex(file)
     endiannessMarkerBytes = nil
 
 def offsetsAndConfigurationIndex(file)
     endiannessMarkerBytes = nil
-    result = []
+    result = {}
     
     def readInt(endianness, bytes)
         if endianness == :little
     
     def readInt(endianness, bytes)
         if endianness == :little
@@ -98,7 +105,7 @@ def offsetsAndConfigurationIndex(file)
     
     fileBytes = []
     
     
     fileBytes = []
     
-    File.open(file, "r") {
+    File.open(file, "rb") {
         | inp |
         loop {
             byte = inp.getbyte
         | inp |
         loop {
             byte = inp.getbyte
@@ -147,15 +154,19 @@ def offsetsAndConfigurationIndex(file)
                     | data |
                     offsets << readInt(endianness, data)
                 }
                     | data |
                     offsets << readInt(endianness, data)
                 }
-                result << [offsets, index]
+                result[index] = offsets
             }
         end
     }
     
     raise MissingMagicValuesException unless result.length >= 1
             }
         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
 
 #
 end
 
 #