Class ProgramBuilder

    • Constructor Detail

      • ProgramBuilder

        public ProgramBuilder()
                       throws java.lang.Exception
        Construct program builder using the big-endian Toy language and default compiler spec. This builder object will be the program consumer and must be disposed to properly release the program.
        Throws:
        java.lang.Exception - if there is an exception creating the program
      • ProgramBuilder

        public ProgramBuilder​(java.lang.String name,
                              java.lang.String languageName)
                       throws java.lang.Exception
        Construct program builder using specified language and default compiler spec. This builder object will be the program consumer and must be disposed to properly release the program.
        Parameters:
        name - program name
        languageName - supported language ID (includes all Toy language IDs)
        Throws:
        java.lang.Exception - if there is an exception creating the program
      • ProgramBuilder

        public ProgramBuilder​(java.lang.String name,
                              java.lang.String languageName,
                              java.lang.Object consumer)
                       throws java.lang.Exception
        Construct program builder using specified language and default compiler spec
        Parameters:
        name - program name
        languageName - supported language ID (includes all Toy language IDs)
        consumer - program consumer (if null this builder will be used as consumer and must be disposed to release program)
        Throws:
        java.lang.Exception - if there is an exception creating the program
      • ProgramBuilder

        public ProgramBuilder​(java.lang.String name,
                              java.lang.String languageName,
                              java.lang.String compilerSpecID,
                              java.lang.Object consumer)
                       throws java.lang.Exception
        Construct program builder using specified language
        Parameters:
        name - program name
        languageName - supported language ID (includes all Toy language IDs)
        compilerSpecID - compiler specification ID (if null default spec will be used)
        consumer - program consumer (if null this builder will be used as consumer and must be disposed to release program)
        Throws:
        java.lang.Exception - if there is an exception creating the program
    • Method Detail

      • analyze

        public void analyze()
        Perform complete analysis on the built program. Limited analysis may already have been performed during disassembly - so it may not be necessary to do complete analysis
      • getProgram

        public ProgramDB getProgram()
        Get the constructed program. If this builder was not constructed with a consumer, the caller should dispose the builder after either the program is no longer in use, or a new consumer has been added to the program (e.g., program opened in a tool or another consumer explicitly added).
        Returns:
        constructed program
      • getLanguage

        public Language getLanguage()
      • getRegister

        public Register getRegister​(java.lang.String regName)
      • addr

        public Address addr​(long offset)
      • addr

        public Address addr​(java.lang.String addressString)
      • dispose

        public void dispose()
      • setName

        public void setName​(java.lang.String name)
      • withTransaction

        public void withTransaction​(java.lang.Runnable r)
      • startTransaction

        protected void startTransaction()
      • endTransaction

        protected void endTransaction()
      • endTransaction

        protected void endTransaction​(boolean commit)
      • setRecordChanges

        public void setRecordChanges​(boolean enabled)
      • setAnalyzed

        public void setAnalyzed​(boolean analyzed)
        This prevents the 'ask to analyze' dialog from showing when called with true
        Parameters:
        analyzed - true to mark the program as analyzed
      • createMemory

        public MemoryBlock createMemory​(java.lang.String name,
                                        java.lang.String address,
                                        int size)
      • createMemory

        public MemoryBlock createMemory​(java.lang.String name,
                                        java.lang.String address,
                                        int size,
                                        java.lang.String comment)
      • createMemory

        public MemoryBlock createMemory​(java.lang.String name,
                                        java.lang.String address,
                                        int size,
                                        java.lang.String comment,
                                        byte initialValue)
      • createUninitializedMemory

        public MemoryBlock createUninitializedMemory​(java.lang.String name,
                                                     java.lang.String address,
                                                     int size)
      • createOverlayMemory

        public MemoryBlock createOverlayMemory​(java.lang.String name,
                                               java.lang.String address,
                                               int size)
      • setBytes

        public void setBytes​(java.lang.String address,
                             java.lang.String byteString)
                      throws java.lang.Exception
        Sets the bytes starting at address to the values encoded in byteString.

        See setBytes(String, byte[], boolean).

        Parameters:
        address - String containing numeric value, preferably hex encoded: "0x1004000"
        byteString - String containing 2 digit hex values, separated by ' ' space chars or by comma ',' chars: "12 05 ff". See NumericUtilities.parseHexLong(String).
        Throws:
        java.lang.Exception - if there is an exception applying the bytes
      • setBytes

        public void setBytes​(java.lang.String address,
                             java.lang.String byteString,
                             boolean disassemble)
                      throws java.lang.Exception
        Sets the bytes starting at address to the values encoded in byteString and then optionally disassembling.

        See setBytes(String, byte[], boolean).

        Parameters:
        address - String containing numeric value, preferably hex encoded: "0x1004000"
        byteString - String containing 2 digit hex values, separated by ' ' space chars or by comma ',' chars: "12 05 ff". See NumericUtilities.parseHexLong(String).
        disassemble - boolean flag.
        Throws:
        java.lang.Exception - if there is an exception applying the bytes
      • setBytes

        public void setBytes​(java.lang.String stringAddress,
                             byte[] bytes)
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setBytes

        public void setBytes​(java.lang.String stringAddress,
                             byte[] bytes,
                             boolean disassemble)
                      throws java.lang.Exception
        Sets the bytes starting at stringAddress to the byte values in bytes and then optionally disassembling.

        Parameters:
        stringAddress - String containing numeric value, preferably hex encoded: "0x1004000"
        bytes - array of bytes to copy into the memory buffer at the addresss.
        disassemble - boolean flag. See disassemble(String, int)
        Throws:
        java.lang.Exception - if there is an exception applying the bytes
      • setRead

        public void setRead​(MemoryBlock block,
                            boolean r)
      • setWrite

        public void setWrite​(MemoryBlock block,
                             boolean w)
      • setExecute

        public void setExecute​(MemoryBlock block,
                               boolean e)
      • disassemble

        public void disassemble​(java.lang.String addressString,
                                int length)
      • disassemble

        public void disassemble​(java.lang.String addressString,
                                int length,
                                boolean followFlows)
      • disassemble

        public void disassemble​(AddressSetView set,
                                boolean followFlows)
      • disassembleArm

        public void disassembleArm​(java.lang.String addressString,
                                   int length,
                                   boolean thumb)
      • clearCodeUnits

        public void clearCodeUnits​(java.lang.String startAddressString,
                                   java.lang.String endAddressString,
                                   boolean clearContext)
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createLabel

        public Symbol createLabel​(java.lang.String addressString,
                                  java.lang.String name)
      • createLabel

        public Symbol createLabel​(java.lang.String addressString,
                                  java.lang.String name,
                                  java.lang.String namespace)
      • createFunction

        public Function createFunction​(java.lang.String addressString)
        Creates a function by examining the instructions to find the body.
        Parameters:
        addressString - the address
        Returns:
        the function
      • addFunctionVariable

        public void addFunctionVariable​(Function f,
                                        Variable v)
                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createEmptyFunction

        public Function createEmptyFunction​(java.lang.String name,
                                            java.lang.String address,
                                            int size,
                                            DataType returnType,
                                            boolean varargs,
                                            boolean inline,
                                            boolean noReturn,
                                            Parameter... params)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createEmptyFunction

        public Function createEmptyFunction​(java.lang.String name,
                                            java.lang.String namespace,
                                            java.lang.String address,
                                            int bodySize,
                                            DataType returnType,
                                            Parameter... params)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createEmptyFunction

        public Function createEmptyFunction​(java.lang.String name,
                                            java.lang.String namespace,
                                            java.lang.String callingConventionName,
                                            boolean customStorage,
                                            java.lang.String address,
                                            int bodySize,
                                            DataType returnType,
                                            Parameter... params)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createEmptyFunction

        public Function createEmptyFunction​(java.lang.String name,
                                            java.lang.String namespace,
                                            java.lang.String callingConventionName,
                                            java.lang.String address,
                                            int size,
                                            DataType returnType,
                                            DataType... paramTypes)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createNamespace

        public Namespace createNamespace​(java.lang.String namespace)
      • getNamespace

        public Namespace getNamespace​(java.lang.String namespace)
      • getNamespace

        public Namespace getNamespace​(java.lang.String namespace,
                                      Address address)
      • createNamespace

        public Namespace createNamespace​(java.lang.String namespace,
                                         SourceType type)
      • createNamespace

        public Namespace createNamespace​(java.lang.String namespace,
                                         java.lang.String parentNamespace,
                                         SourceType type)
      • createClassNamespace

        public Namespace createClassNamespace​(java.lang.String name,
                                              java.lang.String parentNamespace,
                                              SourceType type)
                                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • applyFixedLengthDataType

        public void applyFixedLengthDataType​(java.lang.String addressString,
                                             DataType dt,
                                             int length)
      • applyDataType

        public void applyDataType​(java.lang.String addressString,
                                  DataType dt)
      • applyDataType

        public void applyDataType​(java.lang.String addressString,
                                  DataType dt,
                                  int n)
        Creates a data instance at the specified address, repeated N times.
        Parameters:
        addressString - address.
        dt - DataType to place at address, Dynamic length datatype not supported.
        n - repeat count.
      • applyStringDataType

        public void applyStringDataType​(java.lang.String addressString,
                                        AbstractStringDataType dt,
                                        int n)
        Creates a sting data type instance at the specified address, repeated N times.
        Parameters:
        addressString - address.
        dt - AbstractStringDataType string type to place at address.
        n - repeat count.
      • deleteReference

        public void deleteReference​(Reference reference)
      • createMemoryReadReference

        public Reference createMemoryReadReference​(java.lang.String fromAddress,
                                                   java.lang.String toAddress)
      • createMemoryCallReference

        public Reference createMemoryCallReference​(java.lang.String fromAddress,
                                                   java.lang.String toAddress)
      • createMemoryJumpReference

        public Reference createMemoryJumpReference​(java.lang.String fromAddress,
                                                   java.lang.String toAddress)
      • createMemoryReference

        public Reference createMemoryReference​(java.lang.String fromAddress,
                                               java.lang.String toAddress,
                                               RefType refType,
                                               SourceType sourceType)
      • createMemoryReference

        public Reference createMemoryReference​(java.lang.String fromAddress,
                                               java.lang.String toAddress,
                                               RefType refType,
                                               SourceType sourceType,
                                               int opIndex)
      • createOffsetMemReference

        public Reference createOffsetMemReference​(java.lang.String fromAddress,
                                                  java.lang.String toAddress,
                                                  int offset,
                                                  RefType refType,
                                                  SourceType sourceType,
                                                  int opIndex)
      • createStackReference

        public Reference createStackReference​(java.lang.String fromAddress,
                                              RefType refType,
                                              int stackOffset,
                                              SourceType sourceType,
                                              int opIndex)
      • createRegisterReference

        public Reference createRegisterReference​(java.lang.String fromAddress,
                                                 java.lang.String registerName,
                                                 int opIndex)
      • createRegisterReference

        public Reference createRegisterReference​(java.lang.String fromAddress,
                                                 RefType refType,
                                                 java.lang.String registerName,
                                                 SourceType sourceType,
                                                 int opIndex)
      • createEntryPoint

        public Symbol createEntryPoint​(java.lang.String addressString,
                                       java.lang.String name)
      • createBookmark

        public Bookmark createBookmark​(java.lang.String address,
                                       java.lang.String bookmarkType,
                                       java.lang.String category,
                                       java.lang.String comment)
      • createEncodedString

        public void createEncodedString​(java.lang.String address,
                                        java.lang.String string,
                                        java.nio.charset.Charset encoding,
                                        boolean nullTerminate)
                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createString

        public Data createString​(java.lang.String address,
                                 java.lang.String string,
                                 java.nio.charset.Charset charset,
                                 boolean nullTerminate,
                                 DataType dataType)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createString

        public Data createString​(java.lang.String address,
                                 byte[] stringBytes,
                                 java.nio.charset.Charset charset,
                                 DataType dataType)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setProperty

        public void setProperty​(java.lang.String name,
                                java.lang.Object value)
      • setAnalysisEnabled

        public void setAnalysisEnabled​(java.lang.String name,
                                       boolean enabled)
      • addDataType

        public void addDataType​(DataType dt)
      • addCategory

        public void addCategory​(CategoryPath path)
      • createProgramTree

        public void createProgramTree​(java.lang.String treeName)
                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createFragment

        public void createFragment​(java.lang.String treeName,
                                   java.lang.String modulePath,
                                   java.lang.String fragmentName,
                                   java.lang.String startAddr,
                                   java.lang.String endAddr)
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getOrCreateModule

        public ProgramModule getOrCreateModule​(java.lang.String treeName,
                                               java.lang.String modulePath)
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createEquate

        public Equate createEquate​(java.lang.String address,
                                   java.lang.String name,
                                   long value,
                                   int opIndex)
      • createComment

        public void createComment​(java.lang.String address,
                                  java.lang.String comment,
                                  int commentType)
      • createFunctionComment

        public void createFunctionComment​(java.lang.String entryPointAddress,
                                          java.lang.String comment)
      • setFallthrough

        public void setFallthrough​(java.lang.String from,
                                   java.lang.String to)
      • createExternalLibraries

        public void createExternalLibraries​(java.lang.String... libraryNames)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • bindExternalLibrary

        public void bindExternalLibrary​(java.lang.String libraryName,
                                        java.lang.String pathname)
                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createExternalReference

        public void createExternalReference​(java.lang.String fromAddress,
                                            java.lang.String libraryName,
                                            java.lang.String externalLabel,
                                            int opIndex)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createExternalReference

        public void createExternalReference​(java.lang.String fromAddress,
                                            java.lang.String libraryName,
                                            java.lang.String externalLabel,
                                            java.lang.String extAddress,
                                            int opIndex)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createExternalReference

        public void createExternalReference​(java.lang.String fromAddress,
                                            java.lang.String libraryName,
                                            java.lang.String externalLabel,
                                            java.lang.String extAddress,
                                            int opIndex,
                                            RefType refType,
                                            SourceType sourceType)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createExternalFunction

        public ExternalLocation createExternalFunction​(java.lang.String extAddress,
                                                       java.lang.String libName,
                                                       java.lang.String functionName)
                                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createExternalFunction

        public ExternalLocation createExternalFunction​(java.lang.String extAddress,
                                                       java.lang.String libName,
                                                       java.lang.String functionName,
                                                       java.lang.String originalName)
                                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createLocalVariable

        public void createLocalVariable​(Function function,
                                        java.lang.String name,
                                        DataType dt,
                                        int stackOffset)
                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setRegisterValue

        public void setRegisterValue​(java.lang.String registerName,
                                     java.lang.String startAddress,
                                     java.lang.String endAddress,
                                     long value)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setIntProperty

        public void setIntProperty​(java.lang.String address,
                                   java.lang.String propertyName,
                                   int value)
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setStringProperty

        public void setStringProperty​(java.lang.String address,
                                      java.lang.String propertyName,
                                      java.lang.String value)
                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setObjectProperty

        public void setObjectProperty​(java.lang.String address,
                                      java.lang.String propertyName,
                                      Saveable value)
                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setChanged

        public void setChanged​(boolean changed)