X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..refs/heads/master:/offlineasm/offsets.rb?ds=inline diff --git a/offlineasm/offsets.rb b/offlineasm/offsets.rb index 63af014..50b963b 100644 --- a/offlineasm/offsets.rb +++ b/offlineasm/offsets.rb @@ -21,16 +21,23 @@ # 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 @@ -61,7 +68,7 @@ end def offsetsAndConfigurationIndex(file) endiannessMarkerBytes = nil - result = [] + result = {} def readInt(endianness, bytes) if endianness == :little @@ -98,7 +105,7 @@ def offsetsAndConfigurationIndex(file) fileBytes = [] - File.open(file, "r") { + File.open(file, "rb") { | inp | loop { byte = inp.getbyte @@ -147,15 +154,19 @@ def offsetsAndConfigurationIndex(file) | 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 #