mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GP-3543 corrected ELF Android packed reloc bug and sleb128 datatype
value
This commit is contained in:
parent
d40c5165f5
commit
bcfc7c84d8
2 changed files with 23 additions and 7 deletions
|
@ -197,11 +197,11 @@ public class ElfRelocationTable implements ElfFileSection {
|
||||||
int relocationIndex = 0;
|
int relocationIndex = 0;
|
||||||
long remainingRelocations = reader.readNext(LEB128::signed); // reloc_count
|
long remainingRelocations = reader.readNext(LEB128::signed); // reloc_count
|
||||||
long offset = reader.readNext(LEB128::signed); // reloc_baseOffset
|
long offset = reader.readNext(LEB128::signed); // reloc_baseOffset
|
||||||
|
long addend = 0;
|
||||||
|
|
||||||
while (remainingRelocations > 0) {
|
while (remainingRelocations > 0) {
|
||||||
|
|
||||||
// start new group
|
// start new group - read group header (size and flags)
|
||||||
long addend = 0;
|
|
||||||
|
|
||||||
// group_size
|
// group_size
|
||||||
long groupSize = reader.readNext(LEB128::signed);
|
long groupSize = reader.readNext(LEB128::signed);
|
||||||
|
@ -228,10 +228,13 @@ public class ElfRelocationTable implements ElfFileSection {
|
||||||
// group_info (optional)
|
// group_info (optional)
|
||||||
long groupRInfo = groupedByInfo ? reader.readNext(LEB128::signed) : 0;
|
long groupRInfo = groupedByInfo ? reader.readNext(LEB128::signed) : 0;
|
||||||
|
|
||||||
if (groupedByAddend && groupHasAddend) {
|
if (groupHasAddend && groupedByAddend) {
|
||||||
// group_addend (optional)
|
// group_addend (optional)
|
||||||
addend += reader.readNext(LEB128::signed);
|
addend += reader.readNext(LEB128::signed);
|
||||||
}
|
}
|
||||||
|
else if (!groupHasAddend) {
|
||||||
|
addend = 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < groupSize; i++) {
|
for (int i = 0; i < groupSize; i++) {
|
||||||
// reloc_offset (optional)
|
// reloc_offset (optional)
|
||||||
|
|
|
@ -21,7 +21,6 @@ import java.io.InputStream;
|
||||||
import ghidra.docking.settings.*;
|
import ghidra.docking.settings.*;
|
||||||
import ghidra.program.model.mem.MemBuffer;
|
import ghidra.program.model.mem.MemBuffer;
|
||||||
import ghidra.program.model.scalar.Scalar;
|
import ghidra.program.model.scalar.Scalar;
|
||||||
import ghidra.util.classfinder.ClassTranslator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract base class for a LEB128 variable length integer data type.
|
* 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;
|
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)) {
|
try (InputStream is = buf.getInputStream(0, maxLength)) {
|
||||||
long val = LEB128.read(is, signed);
|
val = LEB128.read(is, signed);
|
||||||
return new Scalar(64 - Long.numberOfLeadingZeros(val), val, signed);
|
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
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
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue