]>
git.saurik.com Git - apple/ld64.git/blob - unit-tests/test-cases/efi-basic/mtoctest.py
7 print "Unkown command line args"
12 opts
, args
= getopt
.getopt(sys
.argv
[1:],"hav:",["help","arch=","verbose"])
13 except getopt
.GetoptError
:
14 print "Unkown command line args"
19 if o
in ("-h", "--help"):
22 elif o
in ("-a", "--arch"):
30 print "\nmach-o load commands:"
31 otoolload
= open("otool-load.log", "r")
32 data
= otoolload
.read()
36 # extract extry point from ' ss 0x00000000 eflags 0x00000000 eip 0x00000259 cs 0x00000000'
38 eip
= data
.find("eip")
40 EntryPoint
= int (data
[eip
+ 4:eip
+ 4 + 10], 16)
43 r15
= data
.find("r15")
45 EntryPoint
= int (data
[r15
+ 4:r15
+ 4 + 10], 16)
47 # extract entry point from ' r15 0x0000000000000000 rip 0x0000000000000253'
49 rip
= data
.find("rip")
51 EntryPoint
= int (data
[rip
+ 4:rip
+ 4 + 18], 16)
54 print "FAIL - no entry point for PE/COFF image"
58 print "Entry Point = 0x%08x" % EntryPoint
62 print "\nPE/COFF dump:"
63 objdump
= open("objdump-raw.log", "r")
67 # Extract 'SizeOfImage 00000360'
68 Index
= data
.find("SizeOfImage")
69 End
= data
[Index
:].find("\n")
70 SizeOfImage
= int (data
[Index
+11:Index
+ End
], 16);
72 print "SizeOfImage = 0x%08x" % SizeOfImage
74 #Parse ' 0 .text 00000080 00000240 00000240 00000240 2**2'
75 # ' CONTENTS, ALLOC, LOAD, READONLY, CODE '
76 EndOfTable
= data
.find("SYMBOL TABLE:")
77 Index
= data
.find("Idx Name")
78 End
= data
[Index
:].find("\n")
79 Index
= Index
+ End
+ 1
82 while Index
< EndOfTable
:
83 End
= data
[Index
:].find("\n")
84 Split
= data
[Index
:Index
+End
].split()
86 # Split[1] Name i.e. .text
92 if int(Split
[3],16) != int(Split
[5],16):
93 print "FAIL - %s VMA %08x not equal File off %08x XIP will not work" % (Split
[1], int(Split
[3],16), int(Split
[5],16))
96 if int(Split
[3],16) + int(Split
[2],16) > PeCoffEnd
:
97 PeCoffEnd
= int(Split
[3],16) + int(Split
[2],16)
99 if Split
[1] == ".text":
100 SecStart
= int(Split
[3],16)
101 SecEnd
= int(Split
[3],16) + int(Split
[2],16)
102 if (EntryPoint
< SecStart
) or (EntryPoint
> SecEnd
):
103 print "FAIL - Entry point (0x%x) not in .text section (0x%x - 0x%x)" % (EntryPoint
, SecStart
, SecEnd
)
107 print "%10s" % Split
[1] + ' ' + Split
[2] + ' ' + Split
[3] + ' ' + Split
[4] + ' ' + Split
[5] + " End = %x" % PeCoffEnd
108 Index
+= data
[Index
:].find("\n") + 1
109 Index
+= data
[Index
:].find("\n") + 1
111 if SizeOfImage
< PeCoffEnd
:
112 print "FAIL - PE/COFF Header SizeOfImage (0x%x) is not correct. Image larger than size (0x%x)." % (SizeOfImage
, PeCoffEnd
)
116 print "\nmach-o relocations:"
117 otoolreloc
= open("otool-reloc.log", "r")
118 lines
= otoolreloc
.readlines()
127 if line
.find ("address") > -1:
134 if __name__
== "__main__":