mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
remote debug console
This commit is contained in:
parent
0f0a82b8b1
commit
36c5a5c62b
9 changed files with 201 additions and 47 deletions
|
@ -17,44 +17,46 @@
|
|||
#include "flow.hh"
|
||||
#include "blockaction.hh"
|
||||
|
||||
#ifdef OPACTION_DEBUG
|
||||
#ifdef __REMOTE_SOCKET__
|
||||
|
||||
#include "ifacedecomp.hh"
|
||||
|
||||
static IfaceStatus *ghidra_dcp = (IfaceStatus *)0;
|
||||
static RemoteSocket *remote = (RemoteSocket *)0;
|
||||
|
||||
void turn_on_debugging(Funcdata *fd)
|
||||
/// \brief Establish a debug console for decompilation of the given function
|
||||
///
|
||||
/// Attempt to connect to a UNIX domain socket and direct the i/o streams to
|
||||
/// the decompiler console interface. The socket must have been previously established
|
||||
/// by another process.
|
||||
/// From the command-line, `nc -l -U /tmp/ghidrasocket` for example.
|
||||
void connect_to_console(Funcdata *fd)
|
||||
|
||||
{
|
||||
if (ghidra_dcp == (IfaceStatus *)0) {
|
||||
ghidra_dcp = new IfaceStatus("[ghidradbg]> ",cin,cout);
|
||||
ghidra_dcp->optr = (ostream *)0;
|
||||
ghidra_dcp->fileoptr = (ostream *)0;
|
||||
IfaceCapability::registerAllCommands(ghidra_dcp);
|
||||
if (remote == (RemoteSocket *)0) {
|
||||
remote = new RemoteSocket();
|
||||
if (remote->open("/tmp/ghidrasocket")) {
|
||||
ghidra_dcp = new IfaceStatus("[ghidradbg]> ",*remote->getInputStream(),*remote->getOutputStream());
|
||||
IfaceCapability::registerAllCommands(ghidra_dcp);
|
||||
}
|
||||
}
|
||||
// Check if debug script exists
|
||||
ifstream is("ghidracom.txt");
|
||||
if (!is) return;
|
||||
is.close();
|
||||
|
||||
if (!remote->isSocketOpen())
|
||||
return;
|
||||
|
||||
IfaceDecompData *decomp_data = (IfaceDecompData *)ghidra_dcp->getData("decompile");
|
||||
decomp_data->fd = fd;
|
||||
decomp_data->conf = fd->getArch();
|
||||
ghidra_dcp->pushScript("ghidracom.txt","ghidradbg> ");
|
||||
ghidra_dcp->optr = new ofstream("ghidrares.txt");
|
||||
ghidra_dcp->fileoptr = ghidra_dcp->optr;
|
||||
decomp_data->conf->setDebugStream(ghidra_dcp->optr);
|
||||
ostream *oldPrintStream = decomp_data->conf->print->getOutputStream();
|
||||
bool emitXml = decomp_data->conf->print->emitsXml();
|
||||
decomp_data->conf->print->setOutputStream(remote->getOutputStream());
|
||||
decomp_data->conf->print->setXML(false);
|
||||
ghidra_dcp->reset();
|
||||
mainloop(ghidra_dcp);
|
||||
ghidra_dcp->popScript();
|
||||
}
|
||||
|
||||
void turn_off_debugging(Funcdata *fd)
|
||||
|
||||
{
|
||||
if (ghidra_dcp->optr != (ostream *)0) {
|
||||
delete ghidra_dcp->optr;
|
||||
ghidra_dcp->optr = (ostream *)0;
|
||||
}
|
||||
decomp_data->conf->clearAnalysis(fd);
|
||||
decomp_data->conf->print->setOutputStream(oldPrintStream);
|
||||
decomp_data->conf->print->setXML(emitXml);
|
||||
fd->debugDisable();
|
||||
decomp_data->conf->allacts.getCurrent()->clearBreakPoints();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -213,9 +215,13 @@ void DeregisterProgram::loadParameters(void)
|
|||
void DeregisterProgram::rawAction(void)
|
||||
|
||||
{
|
||||
#ifdef OPACTION_DEBUG
|
||||
#ifdef __REMOTE_SOCKET__
|
||||
if (ghidra_dcp != (IfaceStatus *)0)
|
||||
delete ghidra_dcp;
|
||||
if (remote != (RemoteSocket *)0)
|
||||
delete remote;
|
||||
ghidra_dcp = (IfaceStatus *)0;
|
||||
remote = (RemoteSocket *)0;
|
||||
#endif
|
||||
if (ghidra != (ArchitectureGhidra *)0) {
|
||||
res = 1;
|
||||
|
@ -284,14 +290,11 @@ void DecompileAt::rawAction(void)
|
|||
throw LowlevelError(s.str());
|
||||
}
|
||||
if (!fd->isProcStarted()) {
|
||||
#ifdef OPACTION_DEBUG
|
||||
turn_on_debugging(fd);
|
||||
#ifdef __REMOTE_SOCKET__
|
||||
connect_to_console(fd);
|
||||
#endif
|
||||
ghidra->allacts.getCurrent()->reset( *fd );
|
||||
ghidra->allacts.getCurrent()->perform( *fd );
|
||||
#ifdef OPACTION_DEBUG
|
||||
turn_off_debugging(fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
sout.write("\000\000\001\016",4);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue