Lines 17-26
Link Here
|
17 |
import java.util.Arrays; |
17 |
import java.util.Arrays; |
18 |
import java.util.Comparator; |
18 |
import java.util.Comparator; |
19 |
|
19 |
|
|
|
20 |
import org.eclipse.cdt.core.Addr32; |
21 |
import org.eclipse.cdt.core.Addr32Factory; |
22 |
import org.eclipse.cdt.core.Addr64; |
23 |
import org.eclipse.cdt.core.Addr64Factory; |
20 |
import org.eclipse.cdt.core.CCorePlugin; |
24 |
import org.eclipse.cdt.core.CCorePlugin; |
|
|
25 |
import org.eclipse.cdt.core.IAddress; |
26 |
import org.eclipse.cdt.core.IAddressFactory; |
21 |
|
27 |
|
22 |
// test checkin |
28 |
// test checkin |
23 |
public class Elf { |
29 |
public class Elf { |
|
|
30 |
public final static int ELF32_ADDR_SIZE = 4; |
31 |
public final static int ELF32_OFF_SIZE = 4; |
32 |
public final static int ELF64_ADDR_SIZE = 8; |
33 |
public final static int ELF64_OFF_SIZE = 8; |
34 |
|
24 |
protected ERandomAccessFile efile; |
35 |
protected ERandomAccessFile efile; |
25 |
|
36 |
|
26 |
protected ELFhdr ehdr; |
37 |
protected ELFhdr ehdr; |
Lines 52-58
Link Here
|
52 |
|
63 |
|
53 |
/* e_ident[EI_CLASS] */ |
64 |
/* e_ident[EI_CLASS] */ |
54 |
public final static int ELFCLASSNONE = 0; |
65 |
public final static int ELFCLASSNONE = 0; |
55 |
public final static int ELCLASS32 = 1; |
66 |
public final static int ELFCLASS32 = 1; |
56 |
public final static int ELFCLASS64 = 2; |
67 |
public final static int ELFCLASS64 = 2; |
57 |
|
68 |
|
58 |
/* e_ident[EI_DATA] */ |
69 |
/* e_ident[EI_DATA] */ |
Lines 117-123
Link Here
|
117 |
public int e_type; /* file type (Elf32_Half) */ |
128 |
public int e_type; /* file type (Elf32_Half) */ |
118 |
public int e_machine; /* machine type (Elf32_Half) */ |
129 |
public int e_machine; /* machine type (Elf32_Half) */ |
119 |
public long e_version; /* version number (Elf32_Word) */ |
130 |
public long e_version; /* version number (Elf32_Word) */ |
120 |
public long e_entry; /* entry point (Elf32_Addr)*/ |
131 |
public IAddress e_entry; /* entry point (Elf32_Addr)*/ |
121 |
public long e_phoff; /* Program hdr offset (Elf32_Off)*/ |
132 |
public long e_phoff; /* Program hdr offset (Elf32_Off)*/ |
122 |
public long e_shoff; /* Section hdr offset (Elf32_Off)*/ |
133 |
public long e_shoff; /* Section hdr offset (Elf32_Off)*/ |
123 |
public long e_flags; /* Processor flags (Elf32_Word)*/ |
134 |
public long e_flags; /* Processor flags (Elf32_Word)*/ |
Lines 138-146
Link Here
|
138 |
e_type = efile.readShortE(); |
149 |
e_type = efile.readShortE(); |
139 |
e_machine = efile.readShortE(); |
150 |
e_machine = efile.readShortE(); |
140 |
e_version = efile.readIntE(); |
151 |
e_version = efile.readIntE(); |
141 |
e_entry = efile.readIntE(); |
152 |
switch (e_ident[ELFhdr.EI_CLASS]) |
|
|
153 |
{ |
154 |
case ELFhdr.ELFCLASS32: |
155 |
{ |
156 |
byte[] addrArray = new byte[ELF32_ADDR_SIZE]; |
157 |
efile.readFullyE(addrArray); |
158 |
e_entry = new Addr32(addrArray); |
142 |
e_phoff = efile.readIntE(); |
159 |
e_phoff = efile.readIntE(); |
143 |
e_shoff = efile.readIntE(); |
160 |
e_shoff = efile.readIntE(); |
|
|
161 |
} |
162 |
break; |
163 |
case ELFhdr.ELFCLASS64: |
164 |
{ |
165 |
byte[] addrArray = new byte[ELF64_ADDR_SIZE]; |
166 |
efile.readFullyE(addrArray); |
167 |
e_entry = new Addr64(addrArray); |
168 |
e_phoff = readUnsignedLong(efile); |
169 |
e_shoff = readUnsignedLong(efile); |
170 |
} |
171 |
break; |
172 |
case ELFhdr.ELFCLASSNONE: |
173 |
default: |
174 |
throw new IOException("Unknown ELF class " + e_ident[ELFhdr.EI_CLASS]); |
175 |
} |
144 |
e_flags = efile.readIntE(); |
176 |
e_flags = efile.readIntE(); |
145 |
e_ehsize = efile.readShortE(); |
177 |
e_ehsize = efile.readShortE(); |
146 |
e_phentsize = efile.readShortE(); |
178 |
e_phentsize = efile.readShortE(); |
Lines 163-171
Link Here
|
163 |
e_type = makeShort(bytes, offset, isle); offset += 2; |
195 |
e_type = makeShort(bytes, offset, isle); offset += 2; |
164 |
e_machine = makeShort(bytes, offset, isle); offset += 2; |
196 |
e_machine = makeShort(bytes, offset, isle); offset += 2; |
165 |
e_version = makeInt(bytes, offset, isle); offset += 4; |
197 |
e_version = makeInt(bytes, offset, isle); offset += 4; |
166 |
e_entry = makeInt(bytes, offset, isle); offset += 4; |
198 |
switch (e_ident[ELFhdr.EI_CLASS]) |
167 |
e_phoff = makeInt(bytes, offset, isle); offset += 4; |
199 |
{ |
168 |
e_shoff = makeInt(bytes, offset, isle); offset += 4; |
200 |
case ELFhdr.ELFCLASS32: |
|
|
201 |
{ |
202 |
byte[] addrArray = new byte[ELF32_ADDR_SIZE]; |
203 |
System.arraycopy(bytes, offset, addrArray, 0, ELF32_ADDR_SIZE); offset += ELF32_ADDR_SIZE; |
204 |
e_entry = new Addr32(addrArray); |
205 |
e_phoff = makeInt(bytes, offset, isle); offset += ELF32_OFF_SIZE; |
206 |
e_shoff = makeInt(bytes, offset, isle); offset += ELF32_OFF_SIZE; |
207 |
} |
208 |
break; |
209 |
case ELFhdr.ELFCLASS64: |
210 |
{ |
211 |
byte[] addrArray = new byte[ELF64_ADDR_SIZE]; |
212 |
System.arraycopy(bytes, offset, addrArray, 0, ELF64_ADDR_SIZE); offset += ELF64_ADDR_SIZE; |
213 |
e_entry = new Addr64(addrArray); |
214 |
e_phoff = makeUnsignedLong(bytes, offset, isle); offset += ELF64_OFF_SIZE; |
215 |
e_shoff = makeUnsignedLong(bytes, offset, isle); offset += ELF64_OFF_SIZE; |
216 |
} |
217 |
break; |
218 |
case ELFhdr.ELFCLASSNONE: |
219 |
default: |
220 |
throw new IOException("Unknown ELF class " + e_ident[ELFhdr.EI_CLASS]); |
221 |
} |
169 |
e_flags = makeInt(bytes, offset, isle); offset += 4; |
222 |
e_flags = makeInt(bytes, offset, isle); offset += 4; |
170 |
e_ehsize = makeShort(bytes, offset, isle); offset += 2; |
223 |
e_ehsize = makeShort(bytes, offset, isle); offset += 2; |
171 |
e_phentsize = makeShort(bytes, offset, isle); offset += 2; |
224 |
e_phentsize = makeShort(bytes, offset, isle); offset += 2; |
Lines 194-199
Link Here
|
194 |
return ((val[offset + 0] << 24) + (val[offset + 1] << 16) + (val[offset + 2] << 8) + val[offset + 3]); |
247 |
return ((val[offset + 0] << 24) + (val[offset + 1] << 16) + (val[offset + 2] << 8) + val[offset + 3]); |
195 |
} |
248 |
} |
196 |
|
249 |
|
|
|
250 |
private final long makeLong(byte [] val, int offset, boolean isle) throws IOException |
251 |
{ |
252 |
long result = 0; |
253 |
int shift = 0; |
254 |
if ( isle ) |
255 |
for(int i=7; i >= 0; i-- ) |
256 |
{ |
257 |
shift = i*8; |
258 |
result += ( ((long)val[offset + i]) << shift ) & ( 0xffL << shift ); |
259 |
} |
260 |
else |
261 |
for(int i=0; i <= 7; i++ ) |
262 |
{ |
263 |
shift = (7-i)*8; |
264 |
result += ( ((long)val[offset + i]) << shift ) & ( 0xffL << shift ); |
265 |
} |
266 |
return result; |
267 |
} |
268 |
|
269 |
private final long makeUnsignedLong(byte [] val, int offset, boolean isle) throws IOException |
270 |
{ |
271 |
long result = makeLong(val,offset,isle); |
272 |
if(result < 0) |
273 |
{ |
274 |
throw new IOException( "Maximal file offset is " + Long.toHexString(Long.MAX_VALUE) + |
275 |
" given offset is " + Long.toHexString(result)); |
276 |
} |
277 |
return result; |
278 |
|
279 |
} |
280 |
|
281 |
|
197 |
|
282 |
|
198 |
} |
283 |
} |
199 |
|
284 |
|
Lines 222-228
Link Here
|
222 |
public long sh_name; |
307 |
public long sh_name; |
223 |
public long sh_type; |
308 |
public long sh_type; |
224 |
public long sh_flags; |
309 |
public long sh_flags; |
225 |
public long sh_addr; |
310 |
public IAddress sh_addr; |
226 |
public long sh_offset; |
311 |
public long sh_offset; |
227 |
public long sh_size; |
312 |
public long sh_size; |
228 |
public long sh_link; |
313 |
public long sh_link; |
Lines 301-309
Link Here
|
301 |
public final static int SHN_XINDEX = 0xffffffff; |
386 |
public final static int SHN_XINDEX = 0xffffffff; |
302 |
public final static int SHN_HIRESERVE = 0xffffffff; |
387 |
public final static int SHN_HIRESERVE = 0xffffffff; |
303 |
|
388 |
|
304 |
|
389 |
/*NOTE: 64 bit and 32 bit ELF sections has different order*/ |
305 |
public long st_name; |
390 |
public long st_name; |
306 |
public long st_value; |
391 |
public IAddress st_value; |
307 |
public long st_size; |
392 |
public long st_size; |
308 |
public short st_info; |
393 |
public short st_info; |
309 |
public short st_other; |
394 |
public short st_other; |
Lines 326-331
Link Here
|
326 |
} |
411 |
} |
327 |
|
412 |
|
328 |
public int compareTo(Object obj) { |
413 |
public int compareTo(Object obj) { |
|
|
414 |
/* |
329 |
long thisVal = 0; |
415 |
long thisVal = 0; |
330 |
long anotherVal = 0; |
416 |
long anotherVal = 0; |
331 |
if ( obj instanceof Symbol ) { |
417 |
if ( obj instanceof Symbol ) { |
Lines 338-343
Link Here
|
338 |
thisVal = this.st_value; |
424 |
thisVal = this.st_value; |
339 |
} |
425 |
} |
340 |
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1)); |
426 |
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1)); |
|
|
427 |
*/ |
428 |
return this.st_value.compareTo(((Symbol)obj).st_value); |
341 |
} |
429 |
} |
342 |
|
430 |
|
343 |
public String toString() { |
431 |
public String toString() { |
Lines 362-388
Link Here
|
362 |
* and the Long doesn't know how to compare against a Symbol so if |
450 |
* and the Long doesn't know how to compare against a Symbol so if |
363 |
* we compare Symbol vs Long it is ok, but not if we do Long vs Symbol. |
451 |
* we compare Symbol vs Long it is ok, but not if we do Long vs Symbol. |
364 |
*/ |
452 |
*/ |
|
|
453 |
|
365 |
class SymbolComparator implements Comparator { |
454 |
class SymbolComparator implements Comparator { |
366 |
long val1, val2; |
455 |
IAddress val1, val2; |
367 |
public int compare(Object o1, Object o2) { |
456 |
public int compare(Object o1, Object o2) { |
368 |
|
457 |
|
369 |
if(o1 instanceof Long) { |
458 |
if(o1 instanceof IAddress) { |
370 |
val1 = ((Long)o1).longValue(); |
459 |
val1 = (IAddress)o1; |
371 |
} else if(o1 instanceof Symbol) { |
460 |
} else if(o1 instanceof Symbol) { |
372 |
val1 = ((Symbol)o1).st_value; |
461 |
val1 = ((Symbol)o1).st_value; |
373 |
} else { |
462 |
} else { |
374 |
return -1; |
463 |
return -1; |
375 |
} |
464 |
} |
376 |
|
465 |
|
377 |
if(o2 instanceof Long) { |
466 |
if(o2 instanceof IAddress) { |
378 |
val2 = ((Long)o2).longValue(); |
467 |
val2 = (IAddress)o2; |
379 |
} else if(o2 instanceof Symbol) { |
468 |
} else if(o2 instanceof Symbol) { |
380 |
val2 = ((Symbol)o2).st_value; |
469 |
val2 = ((Symbol)o2).st_value; |
381 |
} else { |
470 |
} else { |
382 |
return -1; |
471 |
return -1; |
383 |
} |
472 |
} |
384 |
return (val1 == val2) ? 0 |
473 |
return val1.compareTo(val2); |
385 |
: ((val1 < val2) ? -1 : 1); |
|
|
386 |
} |
474 |
} |
387 |
} |
475 |
} |
388 |
|
476 |
|
Lines 399-409
Link Here
|
399 |
public final static int PF_X = 1; |
487 |
public final static int PF_X = 1; |
400 |
public final static int PF_W = 2; |
488 |
public final static int PF_W = 2; |
401 |
public final static int PF_R = 4; |
489 |
public final static int PF_R = 4; |
402 |
|
490 |
/*NOTE: 64 bit and 32 bit ELF have different order and size of elements */ |
403 |
public long p_type; |
491 |
public long p_type; |
404 |
public long p_offset; |
492 |
public long p_offset; |
405 |
public long p_vaddr; |
493 |
public IAddress p_vaddr; |
406 |
public long p_paddr; |
494 |
public IAddress p_paddr; |
407 |
public long p_filesz; |
495 |
public long p_filesz; |
408 |
public long p_memsz; |
496 |
public long p_memsz; |
409 |
public long p_flags; |
497 |
public long p_flags; |
Lines 418-437
Link Here
|
418 |
PHdr phdrs[] = new PHdr[ehdr.e_phnum]; |
506 |
PHdr phdrs[] = new PHdr[ehdr.e_phnum]; |
419 |
for( int i = 0; i < ehdr.e_phnum; i++ ) { |
507 |
for( int i = 0; i < ehdr.e_phnum; i++ ) { |
420 |
phdrs[i] = new PHdr(); |
508 |
phdrs[i] = new PHdr(); |
|
|
509 |
switch (ehdr.e_ident[ELFhdr.EI_CLASS]) |
510 |
{ |
511 |
case ELFhdr.ELFCLASS32: |
512 |
{ |
513 |
byte[] addrArray = new byte[ELF32_ADDR_SIZE]; |
514 |
|
421 |
phdrs[i].p_type = efile.readIntE(); |
515 |
phdrs[i].p_type = efile.readIntE(); |
422 |
phdrs[i].p_offset = efile.readIntE(); |
516 |
phdrs[i].p_offset = efile.readIntE(); |
423 |
phdrs[i].p_vaddr = efile.readIntE(); |
517 |
efile.readFullyE(addrArray); |
424 |
phdrs[i].p_paddr = efile.readIntE(); |
518 |
phdrs[i].p_vaddr = new Addr32(addrArray); |
|
|
519 |
efile.readFullyE(addrArray); |
520 |
phdrs[i].p_paddr = new Addr32(addrArray); |
425 |
phdrs[i].p_filesz = efile.readIntE(); |
521 |
phdrs[i].p_filesz = efile.readIntE(); |
426 |
phdrs[i].p_memsz = efile.readIntE(); |
522 |
phdrs[i].p_memsz = efile.readIntE(); |
427 |
phdrs[i].p_flags = efile.readIntE(); |
523 |
phdrs[i].p_flags = efile.readIntE(); |
428 |
phdrs[i].p_align = efile.readIntE(); |
524 |
phdrs[i].p_align = efile.readIntE(); |
429 |
} |
525 |
} |
|
|
526 |
break; |
527 |
case ELFhdr.ELFCLASS64: |
528 |
{ |
529 |
byte[] addrArray = new byte[ELF64_ADDR_SIZE]; |
530 |
|
531 |
phdrs[i].p_type = efile.readIntE(); |
532 |
phdrs[i].p_flags = efile.readIntE(); |
533 |
phdrs[i].p_offset = readUnsignedLong(efile); |
534 |
efile.readFullyE(addrArray); |
535 |
phdrs[i].p_vaddr = new Addr64(addrArray); |
536 |
efile.readFullyE(addrArray); |
537 |
phdrs[i].p_paddr = new Addr64(addrArray); |
538 |
phdrs[i].p_filesz = readUnsignedLong(efile); |
539 |
phdrs[i].p_memsz = readUnsignedLong(efile); |
540 |
phdrs[i].p_align = readUnsignedLong(efile); |
541 |
} |
542 |
break; |
543 |
case ELFhdr.ELFCLASSNONE: |
544 |
default: |
545 |
throw new IOException("Unknown ELF class " + ehdr.e_ident[ELFhdr.EI_CLASS]); |
546 |
} |
547 |
|
548 |
} |
430 |
return phdrs; |
549 |
return phdrs; |
431 |
} |
550 |
} |
432 |
|
551 |
|
433 |
public class Dynamic { |
552 |
public class Dynamic { |
434 |
public final static int DYN_ENT_SIZE = 8; |
553 |
public final static int DYN_ENT_SIZE_32 = 8; |
|
|
554 |
public final static int DYN_ENT_SIZE_64 = 16; |
435 |
|
555 |
|
436 |
public final static int DT_NULL = 0; |
556 |
public final static int DT_NULL = 0; |
437 |
public final static int DT_NEEDED = 1; |
557 |
public final static int DT_NEEDED = 1; |
Lines 454-463
Link Here
|
454 |
private Section section; |
574 |
private Section section; |
455 |
private String name; |
575 |
private String name; |
456 |
|
576 |
|
457 |
protected Dynamic(Section section, long tag, long val) { |
577 |
protected Dynamic(Section section) { |
458 |
this.section = section; |
578 |
this.section = section; |
459 |
d_tag = tag; |
|
|
460 |
d_val = val; |
461 |
} |
579 |
} |
462 |
|
580 |
|
463 |
public String toString() { |
581 |
public String toString() { |
Lines 491-501
Link Here
|
491 |
// We must assume the section is a table ignoring the sh_entsize as it is not |
609 |
// We must assume the section is a table ignoring the sh_entsize as it is not |
492 |
// set for MIPS. |
610 |
// set for MIPS. |
493 |
while( off < section.sh_size ) { |
611 |
while( off < section.sh_size ) { |
494 |
Dynamic dynEnt = new Dynamic(section, efile.readIntE(), efile.readIntE()); |
612 |
Dynamic dynEnt = new Dynamic(section); |
495 |
if ( dynEnt.d_tag == Dynamic.DT_NULL ) |
613 |
switch (ehdr.e_ident[ELFhdr.EI_CLASS]) |
|
|
614 |
{ |
615 |
case ELFhdr.ELFCLASS32: |
616 |
{ |
617 |
dynEnt.d_tag = efile.readIntE(); |
618 |
dynEnt.d_val = efile.readIntE(); |
619 |
off+= Dynamic.DYN_ENT_SIZE_32; |
620 |
} |
496 |
break; |
621 |
break; |
|
|
622 |
case ELFhdr.ELFCLASS64: |
623 |
{ |
624 |
dynEnt.d_tag = efile.readLongE(); |
625 |
dynEnt.d_val = efile.readLongE(); |
626 |
off+= Dynamic.DYN_ENT_SIZE_64; |
627 |
} |
628 |
break; |
629 |
case ELFhdr.ELFCLASSNONE: |
630 |
default: |
631 |
throw new IOException("Unknown ELF class " + ehdr.e_ident[ELFhdr.EI_CLASS]); |
632 |
} |
633 |
|
634 |
if ( dynEnt.d_tag != Dynamic.DT_NULL ) |
497 |
dynList.add(dynEnt); |
635 |
dynList.add(dynEnt); |
498 |
off+= Dynamic.DYN_ENT_SIZE; |
|
|
499 |
} |
636 |
} |
500 |
return (Dynamic[])dynList.toArray(new Dynamic[0]); |
637 |
return (Dynamic[])dynList.toArray(new Dynamic[0]); |
501 |
} |
638 |
} |
Lines 546-551
Link Here
|
546 |
int debugType; |
683 |
int debugType; |
547 |
boolean bDebug; |
684 |
boolean bDebug; |
548 |
boolean isle; |
685 |
boolean isle; |
|
|
686 |
IAddressFactory addressFactory; |
549 |
|
687 |
|
550 |
public String getCPU() { |
688 |
public String getCPU() { |
551 |
return cpu; |
689 |
return cpu; |
Lines 566-571
Link Here
|
566 |
public boolean isLittleEndian() { |
704 |
public boolean isLittleEndian() { |
567 |
return isle; |
705 |
return isle; |
568 |
} |
706 |
} |
|
|
707 |
|
708 |
public IAddressFactory getAddressFactory() { |
709 |
return addressFactory; |
710 |
} |
569 |
} |
711 |
} |
570 |
|
712 |
|
571 |
public Attribute getAttributes() throws IOException { |
713 |
public Attribute getAttributes() throws IOException { |
Lines 679-684
Link Here
|
679 |
attrib.isle = false; |
821 |
attrib.isle = false; |
680 |
break; |
822 |
break; |
681 |
} |
823 |
} |
|
|
824 |
switch (ehdr.e_ident[ELFhdr.EI_CLASS]) |
825 |
{ |
826 |
case ELFhdr.ELFCLASS32: |
827 |
attrib.addressFactory = new Addr32Factory(); |
828 |
break; |
829 |
case ELFhdr.ELFCLASS64: |
830 |
attrib.addressFactory = new Addr64Factory(); |
831 |
break; |
832 |
case ELFhdr.ELFCLASSNONE: |
833 |
default: |
834 |
attrib.addressFactory = null; |
835 |
} |
682 |
// getSections |
836 |
// getSections |
683 |
// find .debug using toString |
837 |
// find .debug using toString |
684 |
Section [] sec = getSections(); |
838 |
Section [] sec = getSections(); |
Lines 777-790
Link Here
|
777 |
sections[i] = new Section(); |
931 |
sections[i] = new Section(); |
778 |
sections[i].sh_name = efile.readIntE(); |
932 |
sections[i].sh_name = efile.readIntE(); |
779 |
sections[i].sh_type = efile.readIntE(); |
933 |
sections[i].sh_type = efile.readIntE(); |
|
|
934 |
switch (ehdr.e_ident[ELFhdr.EI_CLASS]) |
935 |
{ |
936 |
case ELFhdr.ELFCLASS32: |
937 |
{ |
938 |
byte[] addrArray = new byte[ELF32_ADDR_SIZE]; |
780 |
sections[i].sh_flags = efile.readIntE(); |
939 |
sections[i].sh_flags = efile.readIntE(); |
781 |
sections[i].sh_addr = efile.readIntE(); |
940 |
efile.readFullyE(addrArray); |
|
|
941 |
sections[i].sh_addr = new Addr32(addrArray); |
782 |
sections[i].sh_offset = efile.readIntE(); |
942 |
sections[i].sh_offset = efile.readIntE(); |
783 |
sections[i].sh_size = efile.readIntE(); |
943 |
sections[i].sh_size = efile.readIntE(); |
|
|
944 |
} |
945 |
break; |
946 |
case ELFhdr.ELFCLASS64: |
947 |
{ |
948 |
byte[] addrArray = new byte[ELF64_ADDR_SIZE]; |
949 |
sections[i].sh_flags = efile.readLongE(); |
950 |
efile.readFullyE(addrArray); |
951 |
sections[i].sh_addr = new Addr64(addrArray); |
952 |
sections[i].sh_offset = readUnsignedLong(efile); |
953 |
sections[i].sh_size = readUnsignedLong(efile); |
954 |
} |
955 |
break; |
956 |
case ELFhdr.ELFCLASSNONE: |
957 |
default: |
958 |
throw new IOException("Unknown ELF class " + ehdr.e_ident[ELFhdr.EI_CLASS]); |
959 |
} |
960 |
|
784 |
sections[i].sh_link = efile.readIntE(); |
961 |
sections[i].sh_link = efile.readIntE(); |
785 |
sections[i].sh_info = efile.readIntE(); |
962 |
sections[i].sh_info = efile.readIntE(); |
|
|
963 |
switch (ehdr.e_ident[ELFhdr.EI_CLASS]) |
964 |
{ |
965 |
case ELFhdr.ELFCLASS32: |
966 |
{ |
786 |
sections[i].sh_addralign = efile.readIntE(); |
967 |
sections[i].sh_addralign = efile.readIntE(); |
787 |
sections[i].sh_entsize = efile.readIntE(); |
968 |
sections[i].sh_entsize = efile.readIntE(); |
|
|
969 |
} |
970 |
break; |
971 |
case ELFhdr.ELFCLASS64: |
972 |
{ |
973 |
sections[i].sh_addralign = efile.readLongE(); |
974 |
sections[i].sh_entsize = readUnsignedLong(efile); |
975 |
} |
976 |
break; |
977 |
case ELFhdr.ELFCLASSNONE: |
978 |
default: |
979 |
throw new IOException("Unknown ELF class " + ehdr.e_ident[ELFhdr.EI_CLASS]); |
980 |
} |
788 |
if ( sections[i].sh_type == Section.SHT_SYMTAB ) |
981 |
if ( sections[i].sh_type == Section.SHT_SYMTAB ) |
789 |
syms = i; |
982 |
syms = i; |
790 |
if ( syms == 0 && sections[i].sh_type == Section.SHT_DYNSYM ) |
983 |
if ( syms == 0 && sections[i].sh_type == Section.SHT_DYNSYM ) |
Lines 804-815
Link Here
|
804 |
for( int c = 0; c < numSyms; c++) { |
997 |
for( int c = 0; c < numSyms; c++) { |
805 |
efile.seek(section.sh_offset + (section.sh_entsize * c)); |
998 |
efile.seek(section.sh_offset + (section.sh_entsize * c)); |
806 |
Symbol symbol = new Symbol( section ); |
999 |
Symbol symbol = new Symbol( section ); |
|
|
1000 |
switch (ehdr.e_ident[ELFhdr.EI_CLASS]) |
1001 |
{ |
1002 |
case ELFhdr.ELFCLASS32: |
1003 |
{ |
1004 |
byte[] addrArray = new byte[ELF32_ADDR_SIZE]; |
1005 |
|
807 |
symbol.st_name = efile.readIntE(); |
1006 |
symbol.st_name = efile.readIntE(); |
808 |
symbol.st_value = efile.readIntE(); |
1007 |
efile.readFullyE(addrArray); |
|
|
1008 |
symbol.st_value = new Addr32(addrArray); |
809 |
symbol.st_size = efile.readIntE(); |
1009 |
symbol.st_size = efile.readIntE(); |
810 |
symbol.st_info = efile.readByte(); |
1010 |
symbol.st_info = efile.readByte(); |
811 |
symbol.st_other = efile.readByte(); |
1011 |
symbol.st_other = efile.readByte(); |
812 |
symbol.st_shndx = efile.readShortE(); |
1012 |
symbol.st_shndx = efile.readShortE(); |
|
|
1013 |
} |
1014 |
break; |
1015 |
case ELFhdr.ELFCLASS64: |
1016 |
{ |
1017 |
byte[] addrArray = new byte[ELF64_ADDR_SIZE]; |
1018 |
|
1019 |
symbol.st_name = efile.readIntE(); |
1020 |
symbol.st_info = efile.readByte(); |
1021 |
symbol.st_other = efile.readByte(); |
1022 |
symbol.st_shndx = efile.readShortE(); |
1023 |
efile.readFullyE(addrArray); |
1024 |
symbol.st_value = new Addr64(addrArray); |
1025 |
symbol.st_size = readUnsignedLong(efile); |
1026 |
} |
1027 |
break; |
1028 |
case ELFhdr.ELFCLASSNONE: |
1029 |
default: |
1030 |
throw new IOException("Unknown ELF class " + ehdr.e_ident[ELFhdr.EI_CLASS]); |
1031 |
} |
813 |
if ( symbol.st_info == 0 ) |
1032 |
if ( symbol.st_info == 0 ) |
814 |
continue; |
1033 |
continue; |
815 |
symList.add(symbol); |
1034 |
symList.add(symbol); |
Lines 865-871
Link Here
|
865 |
|
1084 |
|
866 |
|
1085 |
|
867 |
/* return the address of the function that address is in */ |
1086 |
/* return the address of the function that address is in */ |
868 |
public Symbol getSymbol( long vma ) { |
1087 |
public Symbol getSymbol( IAddress vma ) { |
869 |
if ( symbols == null ) { |
1088 |
if ( symbols == null ) { |
870 |
return null; |
1089 |
return null; |
871 |
} |
1090 |
} |
Lines 873-879
Link Here
|
873 |
//@@@ If this works, move it to a single instance in this class. |
1092 |
//@@@ If this works, move it to a single instance in this class. |
874 |
SymbolComparator symbol_comparator = new SymbolComparator(); |
1093 |
SymbolComparator symbol_comparator = new SymbolComparator(); |
875 |
|
1094 |
|
876 |
int ndx = Arrays.binarySearch(symbols, new Long(vma), symbol_comparator); |
1095 |
int ndx = Arrays.binarySearch(symbols, vma, symbol_comparator); |
877 |
if ( ndx > 0 ) |
1096 |
if ( ndx > 0 ) |
878 |
return symbols[ndx]; |
1097 |
return symbols[ndx]; |
879 |
if ( ndx == -1 ) { |
1098 |
if ( ndx == -1 ) { |
Lines 882-888
Link Here
|
882 |
ndx = -ndx - 1; |
1101 |
ndx = -ndx - 1; |
883 |
return symbols[ndx-1]; |
1102 |
return symbols[ndx-1]; |
884 |
} |
1103 |
} |
885 |
|
1104 |
/* |
886 |
public long swapInt( long val ) { |
1105 |
public long swapInt( long val ) { |
887 |
if ( ehdr.e_ident[ELFhdr.EI_DATA] == ELFhdr.ELFDATA2LSB ) { |
1106 |
if ( ehdr.e_ident[ELFhdr.EI_DATA] == ELFhdr.ELFDATA2LSB ) { |
888 |
short tmp[] = new short[4]; |
1107 |
short tmp[] = new short[4]; |
Lines 904-911
Link Here
|
904 |
} |
1123 |
} |
905 |
return val; |
1124 |
return val; |
906 |
} |
1125 |
} |
907 |
|
1126 |
*/ |
908 |
public String getFilename() { |
1127 |
public String getFilename() { |
909 |
return file; |
1128 |
return file; |
910 |
} |
1129 |
} |
|
|
1130 |
|
1131 |
private final long readUnsignedLong(ERandomAccessFile file) throws IOException |
1132 |
{ |
1133 |
long result = file.readLongE(); |
1134 |
if(result < 0) |
1135 |
{ |
1136 |
throw new IOException( "Maximal file offset is " + Long.toHexString(Long.MAX_VALUE) + |
1137 |
" given offset is " + Long.toHexString(result)); |
1138 |
} |
1139 |
return result; |
1140 |
} |
911 |
} |
1141 |
} |