Package ghidra.test

Class ToyProgramBuilder


public class ToyProgramBuilder extends ProgramBuilder
  • Constructor Details

    • ToyProgramBuilder

      public ToyProgramBuilder(String name, String languageName, Object consumer) throws Exception
      Construct toy program builder using specified toy language
      Parameters:
      name - program name
      languageName - toy language ID (note: only builder variant supports all instructions)
      consumer - program consumer (if null this builder will be used as consumer and must be disposed to release program)
      Throws:
      Exception
    • ToyProgramBuilder

      public ToyProgramBuilder(String name, boolean bigEndian) throws Exception
      Construct toy program builder using toy language "builder" variant. This builder will be the program consumer and must be disposed
      Parameters:
      name - program name
      bigEndian - language endianness
      Throws:
      Exception
    • ToyProgramBuilder

      public ToyProgramBuilder(String name, boolean bigEndian, Object consumer) throws Exception
      Construct toy program builder using toy language "builder" variant. This builder will be the program consumer and must be disposed
      Parameters:
      name - program name
      bigEndian - language endianness
      consumer - program consumer (if null this builder will be used as consumer and must be disposed to release program)
      Throws:
      Exception
    • ToyProgramBuilder

      public ToyProgramBuilder(String name, boolean bigEndian, boolean wordAligned, Object consumer) throws Exception
      Construct toy program builder using toy language "builder" variant. This builder will be the program consumer and must be disposed
      Parameters:
      name - program name
      bigEndian - language endianness
      consumer - program consumer (if null this builder will be used as consumer and must be disposed to release program)
      Throws:
      Exception
  • Method Details

    • getAddress

      public Address getAddress(long offset)
      Get address in default ram space
      Parameters:
      offset - address offset
      Returns:
      the address
    • getDefinedInstructionAddress

      public List<Address> getDefinedInstructionAddress()
      Get locations where instruction bytes have been added
      Returns:
      instruction start locations
    • resetDefinedInstructionAddresses

      public void resetDefinedInstructionAddresses()
      Reset/clear the list of defined instruction addresses
    • addBytesNOP

      public void addBytesNOP(long offset, int length) throws MemoryAccessException
      Add NOP instruction bytes of specified byte length
      Parameters:
      offset - instruction address offset
      length - length of NOP instruction in bytes
      Throws:
      MemoryAccessException
    • addBytesNOP

      public void addBytesNOP(String addr, int length) throws MemoryAccessException
      Add NOP instruction bytes of specified byte length
      Parameters:
      addr - instruction address
      length - length of NOP instruction in bytes
      Throws:
      MemoryAccessException
    • addBytesFallthrough

      public void addBytesFallthrough(long offset) throws MemoryAccessException
      Add simple fall-through (consumes 2-bytes)
      Parameters:
      offset - instruction address offset
      Throws:
      MemoryAccessException
    • addBytesFallthrough

      public void addBytesFallthrough(String addr) throws MemoryAccessException
      Add simple fall-through (consumes 2-bytes)
      Parameters:
      addr - instruction address
      Throws:
      MemoryAccessException
    • addBytesStore

      public void addBytesStore(long offset, int srcRegIndex, int destRegIndex) throws MemoryAccessException
      Add store indirect (consumes 2-bytes)
      Parameters:
      offset - instruction address offset
      srcRegIndex - source register index (0..15)
      destRegIndex - destination register index (contained indirect memory address) (0..15)
      Throws:
      MemoryAccessException
    • addBytesStore

      public void addBytesStore(String addr, int srcRegIndex, int destRegIndex) throws MemoryAccessException
      Add store indirect (consumes 2-bytes)
      Parameters:
      addr - instruction address
      srcRegIndex - source register index (0..15)
      destRegIndex - destination register index (contained indirect memory address) (0..15)
      Throws:
      MemoryAccessException
    • addBytesLoad

      public void addBytesLoad(long offset, int srcRegIndex, int destRegIndex) throws MemoryAccessException
      Add load indirect (consumes 2-bytes)
      Parameters:
      offset - instruction address offset
      srcRegIndex - source register index (contained indirect memory address) (0..15)
      destRegIndex - destination register index (0..15)
      Throws:
      MemoryAccessException
    • addBytesLoad

      public void addBytesLoad(String addr, int srcRegIndex, int destRegIndex) throws MemoryAccessException
      Add load indirect (consumes 2-bytes)
      Parameters:
      addr - instruction address
      srcRegIndex - source register index (contained indirect memory address) (0..15)
      destRegIndex - destination register index (0..15)
      Throws:
      MemoryAccessException
    • addBytesMoveImmediate

      public void addBytesMoveImmediate(long offset, short imm) throws MemoryAccessException
      Add move immediate instruction (consumes 2-bytes)
      Parameters:
      offset - instruction offset
      imm - immediate byte value
      Throws:
      MemoryAccessException
    • addBytesMoveImmediate

      public void addBytesMoveImmediate(String addr, short imm) throws MemoryAccessException
      Add move immediate instruction (consumes 2-bytes)
      Parameters:
      addr - instruction address
      imm - immediate byte value
      Throws:
      MemoryAccessException
    • addBytesFallthroughSetNoFlowContext

      public void addBytesFallthroughSetNoFlowContext(long offset, int ctxVal) throws MemoryAccessException
      Add simple fall-through which sets noflow context value on next instruction (consumes 2-bytes)
      Parameters:
      offset - instruction address offset
      ctxVal - context value (0-15)
      Throws:
      MemoryAccessException
    • addBytesFallthroughSetNoFlowContext

      public void addBytesFallthroughSetNoFlowContext(String addr, int ctxVal) throws MemoryAccessException
      Add simple fall-through which sets noflow context value on next instruction (consumes 2-bytes)
      Parameters:
      addr - instruction address
      ctxVal - context value (0-15)
      Throws:
      MemoryAccessException
    • addBytesFallthroughSetNoFlowContext

      public void addBytesFallthroughSetNoFlowContext(long offset, int ctxVal, long target) throws MemoryAccessException
      Add simple fall-through which sets noflow context value on target address (consumes 2-bytes)
      Parameters:
      offset - instruction address offset
      ctxVal - context value (0-15)
      target - context target address offset
      Throws:
      MemoryAccessException
    • addBytesFallthroughSetNoFlowContext

      public void addBytesFallthroughSetNoFlowContext(String addr, int ctxVal, String targetAddr) throws MemoryAccessException
      Add simple fall-through which sets noflow context value on target address (consumes 2-bytes)
      Parameters:
      addr - instruction address
      ctxVal - context value (0-15)
      targetAddr - context target address
      Throws:
      MemoryAccessException
    • addBytesFallthroughSetFlowContext

      public void addBytesFallthroughSetFlowContext(long offset, int ctxVal) throws MemoryAccessException
      Add simple fall-through which sets flowing context value on next instruction (consumes 2-bytes)
      Parameters:
      offset - instruction address offset
      ctxVal - context value (0-15)
      Throws:
      MemoryAccessException
    • addBytesFallthroughSetFlowContext

      public void addBytesFallthroughSetFlowContext(String addr, int ctxVal) throws MemoryAccessException
      Add simple fall-through which sets flowing context value on next instruction (consumes 2-bytes)
      Parameters:
      addr - instruction address
      ctxVal - context value (0-15)
      Throws:
      MemoryAccessException
    • addBytesCall

      public void addBytesCall(long offset, long dest) throws MemoryAccessException
      Add call (consumes 2-bytes)
      Parameters:
      offset - instruction address offset
      dest - call destination offset
      Throws:
      MemoryAccessException
    • addBytesCall

      public void addBytesCall(String offset, long dest) throws MemoryAccessException
      Add call (consumes 2-bytes)
      Parameters:
      offset - instruction address offset
      dest - call destination offset
      Throws:
      MemoryAccessException
    • addBytesCall

      public void addBytesCall(String addr, String destAddr) throws MemoryAccessException
      Add call (consumes 2-bytes)
      Parameters:
      addr - instruction address
      destAddr - call destination address
      Throws:
      MemoryAccessException
    • addBytesCallWithDelaySlot

      public void addBytesCallWithDelaySlot(long offset, long dest) throws MemoryAccessException
      Add call w/ delayslot (consumes 4-bytes)
      Parameters:
      offset - instruction address offset
      dest - call destination offset
      Throws:
      MemoryAccessException
    • addBytesCallWithDelaySlot

      public void addBytesCallWithDelaySlot(String addr, String destAddr) throws MemoryAccessException
      Add call w/ delayslot (consumes 4-bytes)
      Parameters:
      addr - instruction address
      destAddr - call destination address
      Throws:
      MemoryAccessException
    • addBytesReturn

      public void addBytesReturn(long offset) throws MemoryAccessException
      Add terminal/return (consumes 2-bytes)
      Parameters:
      offset - instruction address offset
      Throws:
      MemoryAccessException
    • addBytesReturn

      public void addBytesReturn(String addr) throws MemoryAccessException
      Add terminal/return (consumes 2-bytes)
      Parameters:
      addr - instruction address
      Throws:
      MemoryAccessException
    • addBytesBranch

      public void addBytesBranch(long offset, long dest) throws MemoryAccessException
      Add branch (consumes 2-bytes)
      Parameters:
      offset - address offset
      dest - call destination offset
      Throws:
      MemoryAccessException
    • addBytesBranch

      public void addBytesBranch(String addr, String destAddr) throws MemoryAccessException
      Add branch (consumes 2-bytes)
      Parameters:
      addr - instruction address offset
      destAddr - call destination address
      Throws:
      MemoryAccessException
    • addBytesBranchConditional

      public void addBytesBranchConditional(long offset, long dest) throws MemoryAccessException
      Add branch (consumes 2-bytes)
      Parameters:
      offset - instruction address offset
      dest - call destination offset
      Throws:
      MemoryAccessException
    • addBytesBranchConditional

      public void addBytesBranchConditional(String addr, String destAddr) throws MemoryAccessException
      Add branch (consumes 2-bytes)
      Parameters:
      addr - instruction address
      destAddr - call destination address
      Throws:
      MemoryAccessException
    • addBytesSkipConditional

      public void addBytesSkipConditional(long offset) throws MemoryAccessException
      Add conditional skip (consumes 2-bytes)
      Parameters:
      offset - instruction address offset
      Throws:
      MemoryAccessException
    • addBytesSkipConditional

      public void addBytesSkipConditional(String addr) throws MemoryAccessException
      Add conditional skip (consumes 2-bytes)
      Parameters:
      addr - instruction address
      Throws:
      MemoryAccessException
    • addBytesBranchWithDelaySlot

      public void addBytesBranchWithDelaySlot(long offset, long dest) throws MemoryAccessException
      Add branch w/ delay slot (consumes 4-bytes)
      Parameters:
      offset - instruction address offset
      dest - call destination offset
      Throws:
      MemoryAccessException
    • addBytesBranchWithDelaySlot

      public void addBytesBranchWithDelaySlot(String addr, String destAddr) throws MemoryAccessException
      Add branch w/ delay slot (consumes 4-bytes)
      Parameters:
      addr - instruction address
      destAddr - call destination address
      Throws:
      MemoryAccessException
    • addBytesCopInstruction

      public void addBytesCopInstruction(long offset) throws MemoryAccessException
      Add COP instruction for exercising nfctx context (consumes 2-bytes). Location will not be added to defined instruction address list.
      Parameters:
      offset - instruction address offset
      Throws:
      MemoryAccessException
    • addBytesCopInstruction

      public void addBytesCopInstruction(String addr) throws MemoryAccessException
      Add COP instruction for exercising nfctx context (consumes 2-bytes). Location will not be added to defined instruction address list.
      Parameters:
      addr - instruction address
      Throws:
      MemoryAccessException
    • addBytesBadInstruction

      public void addBytesBadInstruction(long offset) throws MemoryAccessException
      Add BAD instruction (consumes 2-bytes). Location will not be added to defined instruction address list.
      Parameters:
      offset - bad instruction address offset
      Throws:
      MemoryAccessException
    • addBytesBadInstruction

      public void addBytesBadInstruction(String addr) throws MemoryAccessException
      Add BAD instruction (consumes 2-bytes). Location will not be added to defined instruction address list.
      Parameters:
      addr - bad instruction address
      Throws:
      MemoryAccessException
    • createNOPInstruction

      public void createNOPInstruction(String address, int size) throws Exception
      Throws:
      Exception
    • createCallInstruction

      public void createCallInstruction(String address, String callAddress) throws Exception
      Throws:
      Exception
    • createReturnInstruction

      public void createReturnInstruction(String address) throws Exception
      Throws:
      Exception
    • createJmpInstruction

      public void createJmpInstruction(String address, String destAddress) throws Exception
      Throws:
      Exception
    • createConditionalJmpInstruction

      public void createConditionalJmpInstruction(String address, String destAddress) throws Exception
      Throws:
      Exception
    • createJmpWithDelaySlot

      public void createJmpWithDelaySlot(String address, String destAddress) throws Exception
      Throws:
      Exception