mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
fixed elf parsing of 2G+ files
32 bit elf parser of 2G+ elf files does not read some field properties because it does signed extension when reading unsigned integer Change-Id: I64b47cc0849d4fb41daec258b2a595003b9de734
This commit is contained in:
parent
3f660b725b
commit
b08253b70a
2 changed files with 25 additions and 16 deletions
|
@ -23,7 +23,7 @@ public class ERandomAccessFile extends RandomAccessFile {
|
||||||
private boolean isle;
|
private boolean isle;
|
||||||
private long ptr_offset;
|
private long ptr_offset;
|
||||||
int val[] = new int[4];
|
int val[] = new int[4];
|
||||||
|
|
||||||
public ERandomAccessFile(String file, String mode) throws IOException {
|
public ERandomAccessFile(String file, String mode) throws IOException {
|
||||||
super(file, mode);
|
super(file, mode);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class ERandomAccessFile extends RandomAccessFile {
|
||||||
{
|
{
|
||||||
isle = le;
|
isle = le;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final short readShortE() throws IOException {
|
public final short readShortE() throws IOException {
|
||||||
val[0] = read();
|
val[0] = read();
|
||||||
val[1] = read();
|
val[1] = read();
|
||||||
|
@ -47,7 +47,7 @@ public class ERandomAccessFile extends RandomAccessFile {
|
||||||
}
|
}
|
||||||
return (short)((val[0] << 8) + val[1]);
|
return (short)((val[0] << 8) + val[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final long readIntE() throws IOException
|
public final long readIntE() throws IOException
|
||||||
{
|
{
|
||||||
val[0] = read();
|
val[0] = read();
|
||||||
|
@ -56,10 +56,14 @@ public class ERandomAccessFile extends RandomAccessFile {
|
||||||
val[3] = read();
|
val[3] = read();
|
||||||
if ((val[0] | val[1] | val[2] | val[3]) < 0)
|
if ((val[0] | val[1] | val[2] | val[3]) < 0)
|
||||||
throw new EOFException();
|
throw new EOFException();
|
||||||
|
long value;
|
||||||
if ( isle ) {
|
if ( isle ) {
|
||||||
return ((val[3] << 24) + (val[2] << 16) + (val[1] << 8) + val[0]);
|
value= ((val[3] << 24) + (val[2] << 16) + (val[1] << 8) + val[0]) ;
|
||||||
|
} else{
|
||||||
|
value= ((val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3]);
|
||||||
}
|
}
|
||||||
return ((val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3]);
|
return value & 0x00000000ffffffffL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final long readLongE() throws IOException
|
public final long readLongE() throws IOException
|
||||||
|
@ -67,8 +71,8 @@ public class ERandomAccessFile extends RandomAccessFile {
|
||||||
byte [] bytes = new byte[8];
|
byte [] bytes = new byte[8];
|
||||||
long result = 0;
|
long result = 0;
|
||||||
super.readFully(bytes);
|
super.readFully(bytes);
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
if ( isle )
|
if ( isle )
|
||||||
for(int i=7; i >= 0; i-- )
|
for(int i=7; i >= 0; i-- )
|
||||||
{
|
{
|
||||||
shift = i*8;
|
shift = i*8;
|
||||||
|
@ -82,7 +86,7 @@ public class ERandomAccessFile extends RandomAccessFile {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void readFullyE(byte [] bytes) throws IOException
|
public final void readFullyE(byte [] bytes) throws IOException
|
||||||
{
|
{
|
||||||
super.readFully(bytes);
|
super.readFully(bytes);
|
||||||
|
@ -92,7 +96,7 @@ public class ERandomAccessFile extends RandomAccessFile {
|
||||||
{
|
{
|
||||||
tmp = bytes[i];
|
tmp = bytes[i];
|
||||||
bytes[i] = bytes[bytes.length - i -1];
|
bytes[i] = bytes[bytes.length - i -1];
|
||||||
bytes[bytes.length - i -1] = tmp;
|
bytes[bytes.length - i -1] = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
* Anton Leherbauer (Wind River Systems)
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.utils.elf.parser;
|
package org.eclipse.cdt.utils.elf.parser;
|
||||||
|
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -54,26 +54,26 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser {
|
||||||
// continue, the array was to small.
|
// continue, the array was to small.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Take a second run at it if the data array failed.
|
//Take a second run at it if the data array failed.
|
||||||
if(attribute == null) {
|
if(attribute == null) {
|
||||||
attribute = Elf.getAttributes(path.toOSString());
|
attribute = Elf.getAttributes(path.toOSString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attribute != null) {
|
if (attribute != null) {
|
||||||
switch (attribute.getType()) {
|
switch (attribute.getType()) {
|
||||||
case Attribute.ELF_TYPE_EXE :
|
case Attribute.ELF_TYPE_EXE :
|
||||||
binary = createBinaryExecutable(path);
|
binary = createBinaryExecutable(path);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Attribute.ELF_TYPE_SHLIB :
|
case Attribute.ELF_TYPE_SHLIB :
|
||||||
binary = createBinaryShared(path);
|
binary = createBinaryShared(path);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Attribute.ELF_TYPE_OBJ :
|
case Attribute.ELF_TYPE_OBJ :
|
||||||
binary = createBinaryObject(path);
|
binary = createBinaryObject(path);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Attribute.ELF_TYPE_CORE :
|
case Attribute.ELF_TYPE_CORE :
|
||||||
binary = createBinaryCore(path);
|
binary = createBinaryCore(path);
|
||||||
break;
|
break;
|
||||||
|
@ -84,7 +84,12 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser {
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (hints == null) {
|
if (hints == null) {
|
||||||
binary = createBinaryArchive(path);
|
try {
|
||||||
|
binary = createBinaryArchive(path);
|
||||||
|
} catch (IOException e2) {
|
||||||
|
CCorePlugin.log(e); // log original exception
|
||||||
|
throw e2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue