mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-25 05:32:14 +00:00
GP-3543 corrected ELF Android packed reloc bug and sleb128 datatype
value
This commit is contained in:
parent
d40c5165f5
commit
bcfc7c84d8
@ -197,11 +197,11 @@ public class ElfRelocationTable implements ElfFileSection {
|
||||
int relocationIndex = 0;
|
||||
long remainingRelocations = reader.readNext(LEB128::signed); // reloc_count
|
||||
long offset = reader.readNext(LEB128::signed); // reloc_baseOffset
|
||||
long addend = 0;
|
||||
|
||||
while (remainingRelocations > 0) {
|
||||
|
||||
// start new group
|
||||
long addend = 0;
|
||||
// start new group - read group header (size and flags)
|
||||
|
||||
// group_size
|
||||
long groupSize = reader.readNext(LEB128::signed);
|
||||
@ -228,10 +228,13 @@ public class ElfRelocationTable implements ElfFileSection {
|
||||
// group_info (optional)
|
||||
long groupRInfo = groupedByInfo ? reader.readNext(LEB128::signed) : 0;
|
||||
|
||||
if (groupedByAddend && groupHasAddend) {
|
||||
if (groupHasAddend && groupedByAddend) {
|
||||
// group_addend (optional)
|
||||
addend += reader.readNext(LEB128::signed);
|
||||
}
|
||||
else if (!groupHasAddend) {
|
||||
addend = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < groupSize; i++) {
|
||||
// reloc_offset (optional)
|
||||
|
@ -21,7 +21,6 @@ import java.io.InputStream;
|
||||
import ghidra.docking.settings.*;
|
||||
import ghidra.program.model.mem.MemBuffer;
|
||||
import ghidra.program.model.scalar.Scalar;
|
||||
import ghidra.util.classfinder.ClassTranslator;
|
||||
|
||||
/**
|
||||
* An abstract base class for a LEB128 variable length integer data type.
|
||||
@ -82,13 +81,27 @@ public abstract class AbstractLeb128DataType extends BuiltIn implements Dynamic
|
||||
maxLength = LEB128.MAX_SUPPORTED_LENGTH;
|
||||
}
|
||||
|
||||
int len = getLength(buf, maxLength);
|
||||
if (len < 1) {
|
||||
return null; // error, or more than 10 bytes long
|
||||
}
|
||||
|
||||
long val;
|
||||
try (InputStream is = buf.getInputStream(0, maxLength)) {
|
||||
long val = LEB128.read(is, signed);
|
||||
return new Scalar(64 - Long.numberOfLeadingZeros(val), val, signed);
|
||||
val = LEB128.read(is, signed);
|
||||
}
|
||||
catch (IOException e) {
|
||||
return null; // memory error, or more than 10 bytes long
|
||||
return null; // error, or more than 10 bytes long
|
||||
}
|
||||
|
||||
// approximate bitLength from storage byte length
|
||||
int bitLength = Math.max(64, len * 7);
|
||||
int mod = bitLength % 8;
|
||||
if (mod != 0) {
|
||||
bitLength += (8 - mod);
|
||||
}
|
||||
|
||||
return new Scalar(bitLength, val, signed);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user