Skip to content

Commit

Permalink
Added goto main at the plugin start.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Kononovich committed Jan 4, 2020
1 parent 15f3d17 commit 0926199
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
44 changes: 41 additions & 3 deletions src/main/java/psx/PsxPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package psx;

import java.util.List;

import docking.ActionContext;
import docking.DialogComponentProvider;
import docking.action.DockingAction;
Expand All @@ -26,7 +28,12 @@
import ghidra.app.util.importer.MessageLog;
import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.util.PluginStatus;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressFactory;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.Symbol;
import ghidra.program.model.symbol.SymbolTable;
import ghidra.util.task.TaskMonitor;
import psx.debug.DebuggerProvider;
import ghidra.MiscellaneousPluginPackage;
Expand Down Expand Up @@ -58,9 +65,8 @@ public void programActivated(Program program) {
createOmAction();
createDbgAction();

String gdtName = String.format("psyq%s", PsxLoader.getProgramPsyqVersion(program));
PsxLoader.closePsyqDataTypeArchives(program, gdtName);
PsxLoader.loadPsyqArchive(program, gdtName, null, TaskMonitor.DUMMY, new MessageLog());
loadPsyqGdt(program);
gotoMain(this.getTool(), program);
}
}

Expand All @@ -72,6 +78,38 @@ protected void dispose() {

dbgProvider.close();
}

private static void loadPsyqGdt(Program program) {
String gdtName = String.format("psyq%s", PsxLoader.getProgramPsyqVersion(program));
PsxLoader.closePsyqDataTypeArchives(program, gdtName);
PsxLoader.loadPsyqArchive(program, gdtName, null, TaskMonitor.DUMMY, new MessageLog());
}

private static void gotoMain(PluginTool tool, Program program) {
SymbolTable st = program.getSymbolTable();
List<Symbol> mainSym = st.getGlobalSymbols("main");

if (mainSym.size() > 0) {
gotoPc(tool, program, "default", mainSym.get(0).getAddress().getOffset());
}
}

public static void gotoPc(PluginTool tool, Program program, String addrSpace, long pcAddr) {
GoToService gotoService = tool.getService(GoToService.class);

AddressFactory af = program.getAddressFactory();
AddressSpace as = af.getAddressSpace(addrSpace);

if (as == null) {
as = af.getDefaultAddressSpace();
}

if (gotoService != null) {
Address addr = as.getAddress(pcAddr);
gotoService.goTo(addr);
}
}

private void createOmAction() {
DockingAction openOverlayManagerAction = new DockingAction("PsxOverlayManager", getName()) {

Expand Down
19 changes: 2 additions & 17 deletions src/main/java/psx/debug/DebuggerProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
import javax.swing.JComponent;

import docking.WindowPosition;
import ghidra.app.services.GoToService;
import ghidra.framework.plugintool.ComponentProviderAdapter;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressFactory;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.MemoryBlock;
import ghidra.program.model.mem.MemoryBlockType;
import ghidra.util.Msg;
import psx.PsxPlugin;
import resources.ResourceManager;

public class DebuggerProvider extends ComponentProviderAdapter {
Expand Down Expand Up @@ -82,19 +79,7 @@ private void showPcReg() {
return;
}

GoToService gotoService = tool.getService(GoToService.class);

AddressFactory af = program.getAddressFactory();
AddressSpace as = af.getAddressSpace(gui.getAddressSpace());

if (as == null) {
as = af.getDefaultAddressSpace();
}

if (gotoService != null) {
Address addr = as.getAddress(pc);
gotoService.goTo(addr);
}
PsxPlugin.gotoPc(tool, program, gui.getAddressSpace(), pc);
}

private void showGprRegs() {
Expand Down

0 comments on commit 0926199

Please sign in to comment.