Skip to content

Commit

Permalink
Code cleanup + comments + file headers
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-javierf committed Jun 12, 2022
1 parent 8aceb0a commit e53bd74
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 20 deletions.
17 changes: 12 additions & 5 deletions src/main/java/ntrghidra/ARM9.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* ARM9.java
* This class contains code to locate in memory and
* work with the ARM9 part of a game's binary.
*
* Pedro Javier Fernández
* 12/06/2022 (DD/MM/YYYY)
*
* See project license file for license information.
*/

package ntrghidra;

import java.util.ArrayList;
Expand All @@ -9,13 +20,10 @@
public class ARM9
{
private int RamAddress;

private byte[] StaticData;

private int _start_ModuleParamsOffset;
private CRT0.ModuleParams _start_ModuleParams;

private List<CRT0.AutoLoadEntry> AutoLoadList;
private List<CRT0.AutoLoadEntry> AutoLoadList; // AutoLoad is a TODO feature still.

public ARM9(byte[] Data, int RamAddress)
{
Expand Down Expand Up @@ -72,7 +80,6 @@ public ARM9(byte[] Data, int RamAddress, int _start_ModuleParamsOffset)
}
}


public void AddAutoLoadEntry(int Address, byte[] Data)
{
CRT0 a = new CRT0();
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/ntrghidra/CRT0.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* CRT0.java
* CRT0 is one of the first initialization routines/code
* that is present in NDS games. This class contains method
* to work with game information that is compressed and
* decompress it.
*
* Pedro Javier Fernández
* 12/06/2022 (DD/MM/YYYY)
*
* See project license file for license information.
*/

package ntrghidra;

import java.io.DataOutputStream;
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/ntrghidra/DSILabelList.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
/*
* DSILabelList.java
* Definition of DSILabel class which represents registers
* and other important addresses in memory exclusive to the
* DSi console. Also includes a list of these memory regions.
*
* Pedro Javier Fernández
* 12/06/2022 (DD/MM/YYYY)
*
* See project license file for license information.
*/

package ntrghidra;

import java.util.ArrayList;
import java.util.List;


public class DSILabelList {

//This internal class represents a location of interest (registers, i/o, etc)
public class DSILabel {
String name;
Expand Down Expand Up @@ -117,7 +128,7 @@ private DSILabelList()





/*ARM7*/

Expand Down Expand Up @@ -162,7 +173,6 @@ private DSILabelList()
_ARM7labels.add(new DSILabel("REG_POWCNT2", 0x4000304));
_ARM7labels.add(new DSILabel("REG_BIOSPROT", 0x4000308));


//ARM7 Sound Registers (NOTE: sound channle specific registers missing)
_ARM7labels.add(new DSILabel("Sound_Channels_0_to_15", 0x4000400));
//...
Expand All @@ -175,7 +185,6 @@ private DSILabelList()
_ARM7labels.add(new DSILabel("REG_SNDCAP1DAD", 0x4000518));
_ARM7labels.add(new DSILabel("REG_SNDCAP1LEN", 0x400051C));


//ARM7 DSi Extra Registers
//not included

Expand All @@ -190,7 +199,6 @@ private DSILabelList()
_ARM7labels.add(new DSILabel("Wifi_WS0_Region", 0x4800000));
_ARM7labels.add(new DSILabel("Wifi_WS1_Region", 0x4808000));


//ARM7 Hardcoded RAM Addresses for Exception Handling
_ARM7labels.add(new DSILabel("DSi7_IRQ_IF2_Check_Bits_DSi_only)", 0x380FFC0));
_ARM7labels.add(new DSILabel("NDS7_Debug_Stacktop_Debug_Vector", 0x380FFDC));
Expand All @@ -199,6 +207,7 @@ private DSILabelList()

}

// Singleton pattern
public static DSILabelList getInstance()
{
if(_instance==null)
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/ntrghidra/DSIMemRegionList.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* NDSIMemRegionList.java
* Definition of DSIMemRegionList class and
* list of these memory regions. These are
* DSi only memory regions !!!
*
* Pedro Javier Fernández
* 12/06/2022 (DD/MM/YYYY)
*
* See project license file for license information.
*/

package ntrghidra;

import java.util.ArrayList;
Expand Down Expand Up @@ -28,7 +40,6 @@ public DSIMemRegion(String name, int addr, int size, boolean read, boolean write
public boolean write() {return write;}
public boolean execute() {return execute;}
}


//This class uses a singleton pattern
private static DSIMemRegionList _instance = null;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/ntrghidra/IOUtil.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* IOUtil.java
* Helper methods to manipulate bytes
*
* Pedro Javier Fernández
* 12/06/2022 (DD/MM/YYYY)
*
* See project license file for license information.
*/

package ntrghidra;

import java.nio.ByteBuffer;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/ntrghidra/NDS.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* NDS.java
* Definition of the NDS binary format
*
* Pedro Javier Fernández
* 12/06/2022 (DD/MM/YYYY)
*
* See project license file for license information.
*/

package ntrghidra;

import java.io.IOException;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/ntrghidra/NDSLabelList.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* NDSLabelList.java
* Definition of NDSLabel class which represents registers
* and other important addresses in memory. Also includes
* a list of these memory regions.
*
* Pedro Javier Fernández
* 12/06/2022 (DD/MM/YYYY)
*
* See project license file for license information.
*/

package ntrghidra;

import java.util.ArrayList;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/ntrghidra/NDSMemRegionList.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* NDSMemRegionList.java
* Definition of NDSMemRegionList class and
* list of these memory regions.
*
* Pedro Javier Fernández
* 12/06/2022 (DD/MM/YYYY)
*
* See project license file for license information.
*/

package ntrghidra;

import java.util.ArrayList;
Expand Down
25 changes: 16 additions & 9 deletions src/main/java/ntrghidra/NTRGhidraLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* NTRGhidraLoader.java
* Main plugin file and entrypoint code.
*
* Pedro Javier Fernández
* 12/06/2022 (DD/MM/YYYY)
*
* See project license file for license information.
*/

package ntrghidra;

// Java standard utilities
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

// Ghidra Imports: IMPORTANT, these may change with Ghidra updates
import docking.widgets.OptionDialog;
import ghidra.app.util.Option;
import ghidra.app.util.bin.BinaryReader;
Expand All @@ -43,7 +56,7 @@
import static ghidra.app.util.MemoryBlockUtils.createInitializedBlock;

/**
* TODO: Provide class-level documentation that describes what this loader does.
* Main entrypoint class
*/
public class NTRGhidraLoader extends AbstractLibrarySupportLoader {

Expand All @@ -53,9 +66,6 @@ public class NTRGhidraLoader extends AbstractLibrarySupportLoader {

@Override
public String getName() {

// TODO: Name the loader. This name must match the name of the loader in the .opinion
// files.
return "Nintendo DS (NTR) and DSi (TWL)";
}

Expand Down Expand Up @@ -103,7 +113,8 @@ protected boolean promptToAskSDK() {

@Override
public Collection<LoadSpec> findSupportedLoadSpecs(ByteProvider provider) throws IOException {
// In this callback loader should decide whether it able to process the file and return instance of the class LoadSpec, telling user how file can be processed*/
// In this callback loader should decide whether it able to process the file and return instance of the class LoadSpec,
// telling user how file can be processed

BinaryReader reader = new BinaryReader(provider, true);

Expand Down Expand Up @@ -162,7 +173,6 @@ void loadARM9Overlays(ByteProvider provider, Program program, NDS romparser, Mes
}
}


//ARM7 has support for overlays as well, even compressed, but they have never been used in comercial games.
void loadARM7Overlays(ByteProvider provider, Program program, NDS romparser, MessageLog log, FlatProgramAPI fpa, TaskMonitor monitor) throws IOException, AddressOverflowException{
BinaryReader reader = new BinaryReader(provider, true);
Expand All @@ -179,7 +189,6 @@ void loadARM7Overlays(ByteProvider provider, Program program, NDS romparser, Mes
}
}


@Override
protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,Program program, TaskMonitor monitor, MessageLog log) throws CancelledException, IOException
{
Expand All @@ -203,7 +212,6 @@ protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> optio
int arm9_ram_base = romParser.Header.MainRamAddress;
int arm9_size = romParser.Header.MainSize;


if(usesNintendoSDK) //try to apply decompression
{
//Get decompressed blob
Expand Down Expand Up @@ -258,7 +266,6 @@ protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> optio
api.addEntryPoint(api.toAddr(arm9_entrypoint));
api.disassemble(api.toAddr(arm9_entrypoint));
api.createFunction(api.toAddr(arm9_entrypoint), "_entry_arm9");

}
else //ARM7
{
Expand Down

0 comments on commit e53bd74

Please sign in to comment.