mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
* feat(ghidra): admit plain MIPS32 PIC shared images Add an elf32-dyn-o32-arch32r2-standard-v1 lane for ET_DYN images without an ASE flag (shared libraries and ET_DYN executables), beside the MIPS16 lane. It reuses the complete dynamic-relocation inspection and admits R_MIPS_NONE, symbol-bearing R_MIPS_REL32 and the TLS loader slots DTPMOD32/DTPREL32/TPREL32, which stay unapplied with a limitation. Ghidra's default moves an image linked at 0 to 0x10000 and then shifts only nonzero local GOT entries, so page-zero GOT entries (how GNU-ld libraries call static functions) keep unshifted values and calls through them decompile to wrong addresses. The lane imports at the image's own ELF image base instead (lowest PT_LOAD in the first 20 headers, as Ghidra computes it), commits it in the analysis profile and requires the bridge handshake to report it. Images with a prelink trailer are refused. verify:ghidra:mips32-shared checks LE, BE and soft-float LLD fixtures laid out like GNU ld output against an independent readelf oracle: every REL32, local GOT entry (including a zero page entry), global GOT entry (EXTERNAL or lazy-binding stub) and unapplied TLS slot, plus named calls in the decompilation, snapshot round trip and CLI evidence. Refs #2338 * style(ghidra): format link-base regression scenarios * test(ghidra): require zero-valued local GOT coverage * test(ghidra): cover TPREL32 in the shared lane and drop duplicated session suites Add an initial-exec TLS variable so the MIPS32 shared fixture declares R_MIPS_TLS_TPREL32 beside DTPMOD32/DTPREL32, and require all three slots to stay UNSUPPORTED with unchanged bytes. Remove the soft-float and mutation handshake suites that the main reconciliation duplicated in GhidraSessionValues.test.ts. * test(ghidra): read the section table in the MIPS32 shared-library oracle parseMipsReadelf now confirms the fixture's section types from readelf -S (main added -S to the executable, relocatable and PSP oracles). Request it in the shared-library oracle too. * test(ghidra): follow main's verifier contracts in the MIPS32 shared lane Main made the Ghidra installation probe asynchronous behind the shared inspectVerifierGhidraInstallation helper, and analyze_function now returns a summary unless detail "complete" is requested. Use both, as the other MIPS lanes do. * refactor(ghidra): keep Ghidra's image-base rule out of shared ELF parsing The shared MIPS ELF reader computed Ghidra's ElfHeader.getImageBase rule (lowest PT_LOAD address among the first 20 program headers) and the domain type described it as Ghidra's base. Record source facts instead: every PT_LOAD virtual address with its program-header index, plus the Android prelink trailer. ghidraMipsElfImageBase in GhidraMipsProfile now applies Ghidra's rule to those facts. The committed elf_image_base is unchanged. --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
42 lines
1.5 KiB
C
42 lines
1.5 KiB
C
/* Position-independent shared-library (ET_DYN) static-analysis fixture, built
|
|
* with -fPIC -shared and never executed or loaded by REA. It exercises what
|
|
* MIPS32 o32 libraries rely on: calls and data accesses through local and
|
|
* global GOT entries, R_MIPS_REL32 pointers to a local function (symbol index
|
|
* zero), to a preemptible exported function and to an undefined import, a
|
|
* general-dynamic TLS variable whose DTPMOD32/DTPREL32 slots and an
|
|
* initial-exec one whose TPREL32 slot only the dynamic loader can fill. The
|
|
* direct call to the static function goes through a local GOT page entry;
|
|
* .text lies in page zero, so that entry is zero in the file and must still be
|
|
* rebased with the image.
|
|
*/
|
|
extern int rea_mips_so_external(int value);
|
|
extern int rea_mips_so_external_data;
|
|
|
|
__thread int rea_mips_so_tls = 5;
|
|
__attribute__((tls_model("initial-exec"))) __thread int rea_mips_so_tls_ie = 9;
|
|
|
|
__attribute__((noinline)) static int rea_mips_so_local(int value)
|
|
{
|
|
return value * 3 + 1;
|
|
}
|
|
|
|
__attribute__((noinline)) int rea_mips_so_exported(int value)
|
|
{
|
|
return value + 7;
|
|
}
|
|
|
|
int (*const rea_mips_so_table[])(int) = {
|
|
rea_mips_so_local,
|
|
rea_mips_so_exported,
|
|
};
|
|
|
|
int (*const rea_mips_so_external_pointer)(int) = rea_mips_so_external;
|
|
|
|
int rea_mips_so_entry(int value)
|
|
{
|
|
return rea_mips_so_external(value) + rea_mips_so_external_data +
|
|
rea_mips_so_table[value & 1](value) + rea_mips_so_local(value) +
|
|
rea_mips_so_external_pointer(value) + rea_mips_so_tls +
|
|
rea_mips_so_tls_ie;
|
|
}
|