fxos: analyze pcrel in cfg (for future call analysis)

This will not cover advanced stuff that relies on static analysis, but
we don't care at the moment.
This commit is contained in:
Lephenixnoir 2023-08-20 19:42:06 +02:00
parent 12e6cd45a4
commit df4bba2c1a
Signed by untrusted user: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
4 changed files with 10 additions and 19 deletions

View File

@ -45,6 +45,7 @@
#define FXOS_PASSES_CFG_H
#include <fxos/disassembly.h>
#include <fxos/passes/pcrel.h>
#include <set>
namespace FxOS {
@ -69,6 +70,8 @@ private:
uint32_t m_lastFunction;
/* Set of instructions in a function, used to generate new claims */
std::set<uint32_t> m_claimedInstructions;
/* pcrel pass used to find call to other functions */
PcrelPass m_pcrel;
};
} /* namespace FxOS */

View File

@ -13,7 +13,7 @@
namespace FxOS {
CfgPass::CfgPass(Disassembly &disasm):
InstructionPass(disasm), m_claimedInstructions {}
InstructionPass(disasm), m_claimedInstructions {}, m_pcrel {disasm}
{
this->setAllowDiscovery(true);
}
@ -94,6 +94,7 @@ bool CfgPass::analyzeInstruction(uint32_t pc, Instruction &i)
i.jmptarget = jmptarget;
}
m_pcrel.analyzeInstruction(pc, i);
return true;
}

View File

@ -50,20 +50,6 @@ static void ad_disassemble_all(
printf("\n");
FxOS_log(LOG, "Finished pass <cfg> in %s", timer.format_time());
/* Annotate all decoded instructions with pcrel/syscall
TODO: analyze only the functions, if possible */
printr("[pcrel] Resolving PC-relative addressing modes...");
timer.restart();
PcrelPass pcrel_pass(space.disasm);
if(!pcrel_pass.analyzeAllInstructions()) {
errors++;
if(!force)
return;
}
timer.stop();
printf("\n");
FxOS_log(LOG, "Finished pass <pcrel> in %s", timer.format_time());
printr("[syscall] Finding syscall references...");
timer.restart();
OS *os = space.os_analysis();
@ -207,7 +193,7 @@ static void _am_cg_main_menu_function(VirtualSpace &vspace)
continue;
/* Return the target of the bsr instruction */
uint32_t fun_addr = sc_addr + 2*(i+2) + 4 + disp * 2;
uint32_t fun_addr = sc_addr + 2 * (i + 2) + 4 + disp * 2;
fmt::print("found widget at 0x{:08x}\n", sc_addr + 2 * i);
fmt::print("rX = r{}, rY = r{}, disp = {}\n", rX, rY, disp);
@ -278,8 +264,8 @@ static ShellCommand _am_cmd(
auto name = parse_am(s, p);
_am(s, name);
},
[](Session &s, Parser &p) { parse_am(s, p); },
"Analysis: Misc functions", R"(
[](Session &s, Parser &p) { parse_am(s, p); }, "Analysis: Misc functions",
R"(
am <name>
Runs miscellaneous analysis functions; commonly used for prototyping.

View File

@ -128,8 +128,9 @@ void _d(Session &session, std::variant<long, Range> location)
address++;
}
/* cfg implicitly does pcrel */
disassemble(session, disasm,
{"cfg", "pcrel", /*"constprop",*/ "syscall", "print"}, address);
{"cfg", /*"constprop",*/ "syscall", "print"}, address);
}
}