forks
int64
homepage
string
issues
string
languages
sequence
last_commit_datetime
timestamp[us]
license
string
repo
string
ssh_address
string
stars
int64
stars_cat
string
topics
sequence
url
string
content_list
sequence
37
5
[ "Java", "C", "Shell" ]
2021-01-02T10:40:01
0ffffffffh/dragondance
git@github.com:0ffffffffh/dragondance.git
273
100-1000
[]
https://github.com/0ffffffffh/dragondance
[ "Java<=+-sep-+=><repo_name>0ffffffffh/dragondance\n<file_path>coveragetools/README.md\n## DDPH (Dragon Dance Pin Helper)\n\n**ddph** is a module for Intel Pin that can collect and supply coverage data to the Dragon Dance plugin. You can find usage of this module on the Dragon Dance's readme section.\n\ndpph comes with its build shell script for macOS, Linux. And comes with a Visual C++ project file for Windows to build with msbuild tool or directly from the Visual Studio.\n\nIf you don't want to waste your time with building it from the source, you can find the binaries for Windows, Linux and macOS.\n\n### Building from the source\n\n##### For Windows:\n\nddph comes with Visual C++ Project file and two props file which are contained macro variable definition for the project. That means you can build with Visual Studio or msbuild command line tool.\n\n*Preparation:*\n\nBefore building the source you have to set **PIN_ROOT** environment variable with the Intel Pin dev kit's root directory. Otherwise compiler could not locate the required headers and the libraries.\n\nThen you can load into Visual Studio via click the vcxproj file and build within GUI, or you can use msbuild.\n\nBuilding the ddph with the msbuild is not complicated. Open a command prompt. Set current directory to the ddph's source folder.\n\nThen type following command\n\n`msbuild ddph.vcxproj /p:Configuration=[BUILD_TYPE] /p:Platform=[ARCHITECTURE]`\n\n*BUILD_TYPE* can be \"Debug\" or \"Release\"\n*ARCHITECTURE* can be \"x64\" for 64 bit compilation, \"Win32\" for 32 bit compilation. That's all. \n\n\n\n<superlink>\n\n\n\n##### For Linux and macOS\n\nddph also comes with a build shell script (**build.sh**) for Linux and macOS. You can execute the script thats all.\n\n*Preparation:*\n\nBefore execute the build script you have to set script variable with pin kit directory. Open build.sh and change PIN_ROOT variable with your valid intel pin dev kit root path.\n\nAlso you make sure that it has proper permission to execute. (chmod +x build.sh)\n\nIf everything is ok, simply execute the build.sh. build script can take arguments for build operation.\n\n`./build.sh [ARCHITECTURE] [OPTIONAL_FLAGS]`\n\n*ARCHITECTURE* can be \"x32\" for 32 bit or \"x64\" for 64 bit compilation. If you are running on 64 bit os but want to 32 bit compilation you have to aware to cross compilation thing. Build script checks system's arch and sets -m32 flag if OS arch is 64 bit and compilation arch is x32.\n\n*OPTIONAL_FLAGS* this flag can be only **-oldabi**. If your C++ compiler does not met Pin dev kit's ABI , you may get in trouble with the compilation. The C++11 ABI changes breaks the ABI compatibility of the binary. If you are in such a situation, your compilation will be broken with an error that is says there is an ABI problem. To handle that problem, build script has a flag to force the compiler to use older ABI. To get more information about the ABI changes you can follow this link<superlink>\n\n<superlink>\n\n<superlink>\n\nYou can get some warnings during the compilation but that's ok, these are noisy and ignorable.\n\n\n<file_path>README.md\n# Dragon Dance\n\n## What is that?\n\nDragon Dance is a plugin for Ghidra<superlink>. If you are lazy to compile for your own, you can use the compiled binaries I provided for Windows, macOS and Linux.\n\n<superlink>\n\nDragon Dance can import and use multiple coverage data in the same session. (Also it supports multi-session but for now that's not usable by the GUI). And you can switch between them or apply intersection, difference, distinct or sum operation with each other quickly.\n\nDragon Dance lets you to view intensity of the executed instructions. So you can get hint on which instructions how often executed. Also you can view the coverage visualization on the function graph window.\n\n<superlink> \n\n## Scripting\n\nDragon Dance also supports its own scripting system. \n\n<superlink>\n\nIt lets you flexible way to play with the coverage data. You can load, delete, show, intersect, diff, distinct, sum operation on them. Following section will be contained the scripting system and api. Press Alt + Enter keys to execute the script.\n\n#### Built-in Functions\n\nBuilt-in functions are implementation of the internal coverage operations to supply an interface to the scripting system. Built-in function can be return coverage object variable or nothing. Built-ins may have aliases.\n\nThey are accepts Built-in Arg as a parameter. Parameters can be variable length.\n\n###### Built-in Arg\n\nBuilt-in Arg is a reference to hold different type of the value. Built-in Args passed left to right order. Built-in Arg can hold following value types:\n\n- Coverage Data Object (which is returned by Built-ins)\n- String\n- Integer (Can be decimal, hexadecimal or octal forms)\n\n#### Variables\n\nVariables are responsible to hold the coverage object only. They can be loaded by built-in functions. They can be passed as an parameter (**Built-in Arg**) to the Built-in Functions.\n\nThere is two types of the coverage object. \n\n*Physical Coverage Object* and *Logical Coverage Object*\n\n**Physical Coverage Object** points a coverage object that it loaded directly from the coverage file. They are visible on the coverage table which is on the GUI. So you can interact them via the GUI operations.\n\n**Logical Coverage Object** points a coverage object that has processed in a built-in function and returned from it as a result. They are not visible on the GUI but they can lives in a Variable until they are destroyed. \n\nCoverage object maintained by the Variable object automatically for both of type of the coverage object. For example;\n\n```\ncov1 = load(\"firstcoverage.out\")\ncov2 = load(\"secondcov.out\")\n\ncov1 = diff(cov1,cov2)\n```\n\nIn this example cov1 and cov2 are variable. And both variables has physical coverage object. diff built-in takes both variables and sets the return value to the cov1 variable. That overwrite operation will set the result coverage object to the variable but does not delete the coverage object because that is a physical coverage object. That coverage data will remain in the session and also GUI table.\n\nLet's think previous example like this;\n\n```\ncov1 = load(\"first.out\")\ncov2 = load(\"second.out\")\ncov3 = load(\"third.out\")\nrvar = sum(cov1,cov2,cov3)\nrvar = diff(rvar, cov2)\n```\n\nIn this example three physical coverage variable goes into sum operation and the sum operation returns logical result coverage object. Then the diff operation takes a logical and a physical variable in it and overwrites the variable named rvar.\n\nIn this case, the result will be set to the rvar and it's previous coverage value destroyed immediately. Because this was a logical object and should be deleted to prevent object leakage. If you want to destroy a variable that it contained a physical coverage object, you have to call `discard` built-in to do. All built-ins will be detailed below.\n\nYou can write complex scripts using nested built-in calls, you can write something like so:\n\n`cres = diff(intersect(a, load(\"another.log\"), c, d), sum(e,f) )`\n\nyou don't have to write the logic line by line.\n\n### Built-in References\n\nThe following API documentations and their behaviors may change until reached final version. \n\n**clear()**\n\n| Property | Description |\n| ----------------------- | ------------------------------------------------------------ |\n| Return Value | None |\n| Minimum Parameter Count | 0 |\n| Maximum Parameter Count | 0 |\n| Description | This built-in clears the being visualized coverage and sets the active coverage to null. |\n| Aliases | None |\n\n\n\n**cwd(** *String* : workingDirectory **)**\n\n| Property | Description |\n| ----------------------- | ------------------------------------------------------------ |\n| Return Value | None |\n| Minimum Parameter Count | 1 |\n| Maximum Parameter Count | 1 |\n| Description | Sets the current working directory with the given path. All import calls without absolute path after the **cwd** the coverage files will be searched in the active working directory. |\n| Aliases | None |\n\n\n\n**diff(** *Variable* : var1, var2, ..... var*N* **)**\n\n| Property | Description |\n| ----------------------- | ------------------------------------------------------------ |\n| Return Value | Variable |\n| Minimum Parameter Count | 2 |\n| Maximum Parameter Count | Unlimited |\n| Description | Applies difference operation to given variable length Variables. And returns the result coverage variable. |\n| Aliases | None |\n\n\n\n**discard(** *Variable* : var1, var2, ..... var*N* **)**\n\n| Property | Description |\n| ----------------------- | ------------------------------------------------------------ |\n| Return Value | None |\n| Minimum Parameter Count | 1 |\n| Maximum Parameter Count | Unlimited |\n| Description | Destroys variables whatever physical or logical. It will destroy the coverage object first and then unregisters the variable name from the variable list. After this call whole given variables becomes undefined. |\n| Aliases | del |\n\n\n\n**distinct(** Variable : var1, var2, ..... var*N* **)**\n\n| Property | Description |\n| ----------------------- | ------------------------------------------------------------ |\n| Return Value | Variable |\n| Minimum Parameter Count | 2 |\n| Maximum Parameter Count | Unlimited |\n| Description | Applies distinct (xor) operation to given variable length variables. And returns the result coverage variable |\n| Aliases | xor |\n\n\n\n**goto(** *Integer* : offset **)**\n\n| Property | Description |\n| ----------------------- | ------------------------------------------------------------ |\n| Return Value | None |\n| Minimum Parameter Count | 1 |\n| Maximum Parameter Count | 1 |\n| Description | Locates the current address selection by given offset. Real address value calculated by adding the offset value to the image base value. |\n| Aliases | None |\n\n\n\n**import(** *String* : filePathOrCoverageName **)**\n\n| Property | Description |\n| ----------------------- | ------------------------------------------------------------ |\n| Return Value | Variable |\n| Minimum Parameter Count | 1 |\n| Maximum Parameter Count | 1 |\n| Description | Imports coverage data from the physical coverage file. Takes relative or absolute path. Or coverage name that it loaded physically earlier. If given path is an absolute path, import loads directly from the path. Otherwise it looks under the current working directory to load. In both cases, import will check that the coverage data already loaded or not using its path. If loaded already it returns cached coverage variable. Or if given value is a name of a physical coverage, it lookups the coverage map from its session and returns coverage object if exists. |\n| Aliases | get, load |\n\n\n\n**intersect(** *Variable* : var1, var2, ..... var*N* **)**\n\n| Property | Description |\n| ----------------------- | ------------------------------------------------------------ |\n| Return Value | Variable |\n| Minimum Parameter Count | 2 |\n| Maximum Parameter Count | Unlimited |\n| Description | Applies intersection operation to the given variable length variables. And returns the result coverage variable |\n| Aliases | and |\n\n\n\n**show(** *Variable* : var **)**\n\n| Property | Description |\n| ----------------------- | ------------------------------------------------------------ |\n| Return Value | None |\n| Minimum Parameter Count | 1 |\n| Maximum Parameter Count | 1 |\n| Description | Visualizes given coverage variable. If there is an actively visualized coverage object and that is a logical, the function destroys previously coverage object immediately and shows given one. |\n| Aliases | None |\n\n\n\n**sum(** *Variable* : var1, var2, ..... var*N* **)**\n\n| Property | Description |\n| ----------------------- | ------------------------------------------------------------ |\n| Return Value | Variable |\n| Minimum Parameter Count | 1 |\n| Maximum Parameter Count | Unlimited |\n| Description | Applies sum operation to the given variable length variables. And returns the result coverage variable. |\n| Aliases | or, union |\n\n**Fix Ups**\n\nDragon Dance can try to fix a misanalysed situation in ghidra during import the coverage data file. On some binaries, the ghidra does not decompile instructions of a function due to unexpected code generation by the compiler. Dragon Dance checks loaded image and the coverage data integrity. if they are valid for each other and the address is belongs to a executable section but there is lack of instruction decompilation, The plugin asks to fix. Then it tries to fix via decompiling the raw section.\n\n<superlink>\n\nIn the future versions of the plugin, it may contains more fixups or workarounds for the image.\n\n### Installation\n\nInstallation is quite easy.\n\nStart Ghidra.\n\nClick \"File\" menu and then select \"Install Extensions..\"\n\nClick the Green Plus icon from the Top-Right of the window\n\nSelect plugin zip package and select Ok.\n\nSelect dragondance from the list\n\nClick Ok and restart the ghidra\n\n### Launching DragonDance\n\nDuring the first loading of a binary to the Ghidra after the plugin installation, Ghidra should ask you whether you want to configure the newly installed plugin or not.\n\nIf you click the Yes button, DragonDance plugin should appear immediately. \n\nIf you click the No button you have to activate manually yourself.\n\nIn order to active manually,\n\n\nClick \"File\" menu and then select Configure from the Disassembly Window (CodeBrowser)\n\nClick the little plug icon from the top right corner of the Configure Tool window.\n\nFind the DragonDance item from the plugin list and enable it's checkbox then click Ok\n\nDragon Dance window should be appeared.\n\nAfter the activation you should able to see Dragon Dance item in the Window menu.\n\n\n### Collecting Coverage Data\n\nAs I described before, Dragon Dance can import coverage data from Dynamorio and the Intel Pin. (For now). Actually these are generic binary instrumentation tools. You have to use proper module with them to collect coverage data. Dynamorio has it's own coverage module called drcov. You can use that built-in module to collect coverage.\n\n**Using Dynamorio**\n\nYou can collect coverage data from the Dynamorio using following command:\n\n`drrun -t drcov -logdir [COVERAGE_OUTPUT_DIRECTORY_PATH] -- [EXECUTABLE_PATH_TO_EXAMINE] [EXECUTABLE_ARGUMENTS]`\n\nThe output will be placed into given directory as *drcov.[EXECUTABLE_NAME].[ID].proc.log* format. \n\n**Using Intel Pin**\n\nAs I mention before, Intel Pin does not provide any built-in coverage collector module. You have to use a custom pin module. Fortunally I crafted my own to collect coverage from the Pin. So that brings a few advantage to us. I can extend it when needed or add extra features, options in it. \n\nWhile later versions may work, only Intel PIN 3.7 is supported. These are not immediately offered on the Intel PIN page, so here are direct download links:\n\nhttps://software.intel.com/sites/landingpage/pintool/downloads/pin-3.7-97619-g0d0c92f4f-gcc-linux.tar.gz\n\nhttps://software.intel.com/sites/landingpage/pintool/downloads/pin-3.7-97619-g0d0c92f4f-msvc-windows.zip\n\nhttps://software.intel.com/sites/landingpage/pintool/downloads/pin-3.7-97619-g0d0c92f4f-clang-mac.tar.gz\n\n\nYou can access **ddph**'s source here<superlink>. I will share binaries for Windows, macOS and Linux. Or you can build your very own binary using it's build shell script.\n\nTo be collect coverage data from Intel Pin use following command:\n\n`pin -t ddph.[so,dylib,dll] [ddph options] -- [EXECUTABLE_PATH_TO_EXAMINE] [EXECUTABLE_ARGUMENTS]`\n\nddph has some options for collection.\n\n-o: with this option you can specify coverage output filename. (*default:* **ddph.out**)\n\n-l: you can specify operation log filename. if you pass \"no\" to this option, ddph will not perform logging operation. (*default:* **ddph.log**)\n\n-p: capture detail level. this option can be **reduced** or **high**. high level captures whole instructions one by one and builds pre-process execution blocks. This will gives you more intensive coverage output but that's slower than reduced. reduced level uses pin's trace blocks so that is way more faster than high level. But that will not cause huge differences on the different level of coverage output. If you don't want to do specific things, consider using reduced level. (*default:* **reduced**) \n\n**For macOs users:** <u>Starting with macOS 10.11 (OS X El Capitan), the os comes with a security layer named **System Integrity Protection** *SIP*. That prevents the user mode processes that are tries to do injection or modification upon another process even if you are running under root privileges.</u>\n\nTo overcome this prevention, you have to disable it. To do that follow these steps below.\n\nRestart macOS\n\nDuring the boot process, press Command + R keys and keep pressed.\n\nThe OS eventually enters into the Recovery Mode\n\nOpen a terminal from the Utilities section\n\ntype `csrutil status` and enter. You must see that the SIP enabled.\n\ntype `csrutil disable` and press enter. \n\ntype `csrutil status` again to make sure it is disabled or not. Then restart the OS and let it boot as normal. Now you are ready to use binary instrumentation tools.\n\n\n\n<superlink>\n\n<superlink>\n\n<superlink>\n\n#### Build instructions\n\nFirst, download ghidra (latest version, currently 9.1.2) and dragondance\n```\n$ wget https://ghidra-sre.org/ghidra_9.1.2_PUBLIC_20200212.zip\n$ wget https://github.com/0ffffffffh/dragondance/archive/master.zip\n$ unzip ghidra_9.1.2_PUBLIC_20200212.zip\n$ unzip master.zip\n```\n Next install gradle and jdk\n```\n$ sudo apt install openjdk-11-jdk\n$ wget https://services.gradle.org/distributions/gradle-5.2.1-bin.zip\n$ sudo unzip -d /opt/gradle gradle-5.2.1-bin.zip\n```\ncreate new profile file\n```\n$ sudo vi /etc/profile.d/gradle.sh\n```\nand add the following to add gradle to the PATH in every subsequent login.\n```\nexport GRADLE_HOME=/opt/gradle/gradle-5.2.1\nexport PATH=${GRADLE_HOME}/bin:${PATH}\n```\nto do it immediately, without having to logout\n```\n$ source /etc/profile.d/gradle.sh\n```\nwe can now proceed to build dragondance\n```\n$ cd dragondance-master/\n$ gradle -PGHIDRA_INSTALL_DIR=/home/ubuntu/ghidra_9.1.2_PUBLIC\n> Task :buildExtension\n\nCreated ghidra_9.1.2_PUBLIC_20200506_dragondance-master.zip in /home/ubuntu/dragondance-master/dist\n\nBUILD SUCCESSFUL in 29s\n5 actionable tasks: 5 executed\nubuntu@ubuntu:~/dragondance-master$ \n```\nwhere you may have to adjust the path to where you downloaded ghidra to. You can now find the built extension in `dragondance-master/dist`\n\n#### The Features that I want to bring on it\n\nCommand prompt style line by line script execution.\n\nContext change awareness\n\nFunction (Routine) based coverage visualization\n\nExecution flow awareness\n\nMore built-ins to the scripting\n\nIts own coverage database format to save and load faster and keep latest changes on the session.\n\nPseudo code painting. (Ghidra does not provide an API for this. So I have to study on the Ghidra's source code to find out a way or workaround to achieve it. ) \n\nUI enhancements \n\n##### Project Author\n\nOğuz Kartal (@0ffffffffh<superlink>\n\n\n<file_path>src/main/java/dragondance/eng/session/SessionManager.java\npackage dragondance.eng.session;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class SessionManager {\n\tprivate static List<Session> sessions;\n\tprivate static Session activeSession;\n\t\n\tstatic {\n\t\tSessionManager.sessions = new ArrayList<Session>();\n\t}\n\t\n\tpublic static void registerSession(Session session) {\n\t\tsessions.add(session);\n\t\t\n\t\tif (sessions.size()==1) {\n\t\t\tactiveSession=session;\n\t\t}\n\t}\n\t\n\tpublic static void deregisterSession(Session session) {\n\t\t\n\t\tif (session == null)\n\t\t\treturn;\n\t\t\n\t\tsessions.remove(session);\n\t}\n\t\n\tpublic static Session getActiveSession() {\n\t\treturn activeSession;\n\t}\n\t\n\tpublic static boolean switchSession(String name) {\n\t\treturn false;\n\t}\n}\n\n<file_path>src/main/java/dragondance/eng/InstructionInfo.java\npackage dragondance.eng;\n\npublic class InstructionInfo {\n\t\n\tprivate long addr;\n\tprivate int size;\n\tprivate int density;\n\tprivate CodeRange container;\n\t\n\tpublic static InstructionInfo cloneFor(InstructionInfo inst, CodeRange containerRange) {\n\t\tInstructionInfo cloneInst = new InstructionInfo(containerRange,inst.addr,inst.size, inst.density);\n\t\treturn cloneInst;\n\t}\n\t\n\tpublic InstructionInfo(CodeRange containerRange, long a, int s, int d) {\n\t\tthis.container = containerRange;\n\t\tthis.addr=a;\n\t\tthis.size=s;\n\t\tthis.setDensity(d);\n\t}\n\t\n\tpublic long getAddr() {\n\t\treturn this.addr;\n\t}\n\t\n\tpublic int getSize() {\n\t\treturn this.size;\n\t}\n\t\n\tpublic int getDensity() {\n\t\treturn this.density;\n\t}\n\t\n\tprivate void onDensityChanged() {\n\t\t\n\t\tif (this.container != null)\n\t\t\tthis.container.getContainerCoverage().setMaxDensity(this.density);\n\t\t\n\t}\n\t\n\tpublic void setDensity(int value) {\n\t\tthis.density=value;\n\t\tonDensityChanged();\n\t}\n\t\n\tpublic void incrementDensityBy(int amount) {\n\t\tthis.density += amount;\n\t\tonDensityChanged();\n\t}\n\t\n\tpublic void incrementDensity() {\n\t\tthis.density++;\n\t\tonDensityChanged();\n\t}\n\t\n\tpublic final boolean hasOwnerRange() {\n\t\treturn this.container != null;\n\t}\n\t\n\tpublic CodeRange getOwnerCodeRange() {\n\t\treturn this.container;\n\t}\n\t\n\t@Override\n\tpublic String toString() {\n\t\treturn String.format(\"(%x, %d [%x])\",this.addr, this.size,this.addr + this.size);\n\t}\n}\n<file_path>src/main/java/dragondance/exceptions/DragonDanceScriptRuntimeException.java\npackage dragondance.exceptions;\n\npublic class DragonDanceScriptRuntimeException extends RuntimeException {\n\tpublic DragonDanceScriptRuntimeException(String message) {\n\t\tsuper(\"Dragon Dance script runtime error: \" + message);\n\t}\n}\n\n<file_path>src/main/java/dragondance/exceptions/InvalidInstructionAddress.java\npackage dragondance.exceptions;\n\npublic class InvalidInstructionAddress extends Exception {\n\n\tpublic InvalidInstructionAddress(long addr) {\n\t\tsuper(String.format(\"Invalid instruction address (%x)\",addr));\n\t}\n\t\n}\n\n<file_path>src/main/java/dragondance/exceptions/OperationAbortedException.java\npackage dragondance.exceptions;\n\npublic class OperationAbortedException extends Exception {\n\n\tpublic OperationAbortedException() {\n\t\tthis(\"Operation aborted\");\n\t}\n\t\n\tpublic OperationAbortedException(String message) {\n\t\tsuper(message);\n\t}\n\t\n\t\n}\n\n<file_path>src/main/java/dragondance/exceptions/ScriptParserException.java\npackage dragondance.exceptions;\n\npublic class ScriptParserException extends Exception {\n\t\t\n\tpublic ScriptParserException(String msg, Object ...args) {\n\t\tsuper(String.format(msg, args));\n\t}\n\t\n\t\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/BuiltinAlias.java\npackage dragondance.scripting.functions;\n\nimport static java.lang.annotation.RetentionPolicy.RUNTIME;\n\nimport java.lang.annotation.Retention;\n\n@Retention(RUNTIME)\npublic @interface BuiltinAlias {\n\tString[] aliases();\n}\n\n<file_path>src/main/java/dragondance/util/TextGraphic.java\npackage dragondance.util;\n\nimport java.awt.Color;\nimport java.awt.Font;\nimport java.awt.FontMetrics;\nimport java.awt.Graphics;\nimport java.awt.Point;\nimport java.awt.geom.Rectangle2D;\nimport java.awt.image.BufferedImage;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Stack;\n\n\npublic class TextGraphic {\n\t\n\tclass RenderItem {\n\t\tpublic static final int RI_TEXTOUT=0;\n\t\tpublic static final int RI_INCRPOS=1;\n\t\tpublic static final int RI_PUSHPOPFONT=2;\n\t\tpublic static final int RI_PUSHPOPCOLOR=3;\n\t\tpublic static final int RI_NEWLINE=4;\n\t\tpublic static final int RI_FLOATTEXTBLOCK=5;\n\t\t\n\t\tprivate int type;\n\t\tprivate Object[] v;\n\t\t\n\t\tpublic RenderItem(int t, Object...args) {\n\t\t\tthis.type=t;\n\t\t\tthis.v = args;\n\t\t}\n\t}\n\t\n\tprivate int w,h;\n\tprivate BufferedImage img;\n\tprivate Graphics gph;\n\t\n\tprivate Point pos;\n\tprivate int lastStringHeight=0;\n\tprivate List<RenderItem> items;\n\tprivate Stack<Font> fontStack;\n\tprivate Stack<Color> colorStack;\n\tprivate int textMaxWidth=0,textMaxHeight=0;\n\tprivate Font currFont;\n\tprivate Color currColor;\n\tprivate Color backgroundColor;\n\tprivate Point virtCoord;\n\t\n\tpublic TextGraphic(int width, int height, Color bgColor) {\n\t\tthis.w = width;\n\t\tthis.h = height;\n\t\t\n\t\tthis.backgroundColor = bgColor;\n\t\t\n\t\tthis.img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);\n\t\tthis.gph = this.img.getGraphics();\n\t\t\n\t\tthis.items = new ArrayList<RenderItem>();\n\t\tthis.fontStack = new Stack<Font>();\n\t\tthis.colorStack = new Stack<Color>();\n\t\t\n\t\tthis.pos = new Point(0,0);\n\t\t\n\t\tthis.virtCoord = new Point(0,this.gph.getFontMetrics().getAscent());\n\t\t\n\t\tthis.currColor = this.gph.getColor();\n\t\tthis.currFont = this.gph.getFont();\n\t\t\n\t\tclearScene();\n\t}\n\t\n\tprivate Point logicalToPhysical(Point p) {\n\t\tPoint np = new Point();\n\t\t\n\t\tnp.x = this.virtCoord.x + p.x;\n\t\tnp.y = this.virtCoord.y + p.y;\n\t\t\n\t\treturn np;\n\t}\n\t\n\tprivate TextGraphic newRender(int type, Object...args) {\n\t\titems.add(new RenderItem(type,args));\n\t\treturn this;\n\t}\n\t\n\tpublic TextGraphic textOut(String format, Color color, Object ...args) {\n\t\treturn textOut(String.format(format, args),color);\n\t}\n\t\n\tpublic TextGraphic textOut(String s, Color color) {\n\t\treturn newRender(RenderItem.RI_TEXTOUT,s,color);\n\t}\n\t\n\tpublic TextGraphic incrementPos(int x, int y) {\n\t\treturn newRender(RenderItem.RI_INCRPOS,x,y);\n\t}\n\t\n\tpublic TextGraphic decrementPos(int x, int y) {\n\t\treturn incrementPos(-x,-y);\n\t}\n\t\n\tpublic TextGraphic pushFont(String fontName, int size, int style) {\n\t\treturn newRender(RenderItem.RI_PUSHPOPFONT,fontName,size,style);\n\t}\n\t\n\tpublic TextGraphic popFont() {\n\t\treturn newRender(RenderItem.RI_PUSHPOPFONT);\n\t}\n\t\n\tpublic TextGraphic pushColor(Color color) {\n\t\treturn newRender(RenderItem.RI_PUSHPOPCOLOR,color);\n\t}\n\t\n\tpublic TextGraphic popColor() {\n\t\treturn newRender(RenderItem.RI_PUSHPOPCOLOR);\n\t}\n\t\n\tpublic TextGraphic newLine() {\n\t\treturn newRender(RenderItem.RI_NEWLINE);\n\t}\n\t\n\tpublic TextGraphic floatTextBlock() {\n\t\treturn newRender(RenderItem.RI_FLOATTEXTBLOCK);\n\t}\n\t\n\t\n\tprivate void clearScene() {\n\t\tColor prev = this.gph.getColor();\n\t\tthis.gph.setColor(this.backgroundColor);\n\t\tthis.gph.fillRect(0, 0, this.w,this.h);\n\t\t\n\t\t/*\n\t\tthis.gph.setColor(Color.BLACK);\n\t\t\n\t\t\n\t\tthis.gph.drawLine(0, 0, this.w, 0); //top line\n\t\tthis.gph.drawLine(0, 0, 0, this.h); //left line\n\t\tthis.gph.drawLine(0, this.h-1, this.w-1, this.h-1); //bottom line\n\t\tthis.gph.drawLine(this.w-1, 0, this.w-1,this.h-1); //right line\n\t\t*/\n\t\t\n\t\tthis.gph.setColor(prev);\n\t\t\n\t\t\n\t}\n\t\n\tprivate void renderText(RenderItem r) {\n\t\tString s;\n\t\tColor prev,color;\n\t\t\n\t\ts = (String)r.v[0];\n\t\tcolor = (Color)r.v[1];\n\t\t\n\t\tprev = this.gph.getColor();\n\t\t\n\t\tFontMetrics fm = this.gph.getFontMetrics();\n\t\tRectangle2D rect = fm.getStringBounds(s, this.gph);\n\t\t\n\t\tthis.gph.setColor(color);\n\t\t\n\t\tPoint rpos = logicalToPhysical(this.pos);\n\t\t\n\t\t\n\t\tthis.gph.drawString(s, rpos.x, rpos.y);\n\t\tthis.gph.setColor(prev);\n\t\t\n\t\t\n\t\tthis.lastStringHeight = (int)rect.getHeight();\n\t\t\n\t\tif (this.pos.x + rect.getWidth() > this.textMaxWidth)\n\t\t\tthis.textMaxWidth += this.pos.x + (int)rect.getWidth();\n\t\t\n\t\tif (this.pos.y + rect.getHeight() > this.textMaxHeight)\n\t\t\tthis.textMaxHeight += this.pos.y + (int)rect.getHeight();\n\t\t\n\t\tthis.pos.x += (int)rect.getWidth();\n\t}\n\t\n\tprivate void incrPos(RenderItem r) {\n\t\tint x,y;\n\t\t\n\t\tx = ((Integer)r.v[0]).intValue();\n\t\ty = ((Integer)r.v[1]).intValue();\n\t\t\n\t\tthis.pos.x += x;\n\t\tthis.pos.y += y;\n\t}\n\t\n\tprivate void pushPopFont(RenderItem r) {\n\t\tString fontName;\n\t\tint fontSize,style;\n\t\t\n\t\tif (r.v.length > 0) {\n\t\t\tfontName = (String)r.v[0];\n\t\t\tfontSize = ((Integer)r.v[1]).intValue();\n\t\t\tstyle = ((Integer)r.v[2]).intValue();\n\t\t\t\n\t\t\tFont f = new Font(fontName,style,fontSize);\n\t\t\tfontStack.push(currFont);\n\t\t\tthis.currFont = f;\n\t\t}\n\t\telse {\n\t\t\tif (!fontStack.empty())\n\t\t\t\tthis.currFont = fontStack.pop();\n\t\t}\n\t\t\n\t\tthis.gph.setFont(this.currFont);\n\t}\n\t\n\tprivate void pushPopColor(RenderItem r) {\n\t\tColor color;\n\t\t\n\t\tif (r.v.length > 0) {\n\t\t\tcolor = (Color)r.v[0];\n\t\t\tcolorStack.push(this.currColor);\n\t\t\tthis.currColor=color;\n\t\t}\n\t\telse {\n\t\t\tif (!colorStack.empty())\n\t\t\t\tthis.currColor = colorStack.pop();\n\t\t}\n\t\t\n\t\tthis.gph.setColor(this.currColor);\n\t}\n\t\n\tprivate void doNewLine() {\n\t\tthis.pos.x=0;\n\t\tthis.pos.y += this.lastStringHeight;\n\t}\n\t\n\tprivate void doFloatBlock() {\n\t\tif (this.pos.x + this.textMaxWidth > this.w - 10) {\n\t\t\t//float down the block\n\t\t\tthis.virtCoord.x = 0;\n\t\t\tthis.virtCoord.y = this.textMaxHeight;\n\t\t\t\n\t\t}\n\t\telse {\n\t\t\tthis.virtCoord.x = this.textMaxWidth;\n\t\t\tthis.virtCoord.y = this.gph.getFontMetrics().getAscent();\n\t\t}\n\t\t\n\t\tthis.pos.x=0;\n\t\tthis.pos.y=0;\n\t}\n\t\n\tpublic void clear() {\n\t\tfontStack.clear();\n\t\tcolorStack.clear();\n\t\titems.clear();\n\t\t\n\t\tthis.pos.setLocation(0, 0);\n\t\tthis.virtCoord.setLocation(0, this.gph.getFontMetrics().getAscent());\n\t\t\n\t\tthis.textMaxHeight=0;\n\t\tthis.textMaxWidth=0;\n\t\t\n\t}\n\t\n\tpublic void render(boolean clearAfter) {\n\t\t\n\t\tclearScene();\n\t\t\n\t\tfor (RenderItem r : this.items) {\n\t\t\tswitch (r.type) {\n\t\t\tcase RenderItem.RI_TEXTOUT:\n\t\t\t\trenderText(r);\n\t\t\t\tbreak;\n\t\t\tcase RenderItem.RI_INCRPOS:\n\t\t\t\tincrPos(r);\n\t\t\t\tbreak;\n\t\t\tcase RenderItem.RI_PUSHPOPFONT:\n\t\t\t\tpushPopFont(r);\n\t\t\t\tbreak;\n\t\t\tcase RenderItem.RI_PUSHPOPCOLOR:\n\t\t\t\tpushPopColor(r);\n\t\t\t\tbreak;\n\t\t\tcase RenderItem.RI_NEWLINE:\n\t\t\t\tdoNewLine();\n\t\t\t\tbreak;\n\t\t\tcase RenderItem.RI_FLOATTEXTBLOCK:\n\t\t\t\tdoFloatBlock();\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (clearAfter)\n\t\t\tclear();\n\t}\n\t\n\tpublic void dispatch(Graphics g) {\n\t\tg.drawImage(this.img,0,0,this.w,this.h,null);\n\t}\n}\n\n<file_path>src/main/java/dragondance/Globals.java\npackage dragondance;\n\npublic class Globals {\n\tpublic static boolean WithoutGhidra=false;\n\tpublic static boolean DebugMode=false;\n\t\n\tpublic static boolean EnableLogging=true;\n\tpublic static boolean EnableGhidraConsoleOutput=false;\n\tpublic static boolean EnableLoggingFileOutput=true;\n\tpublic static boolean EnableStdoutLog=false;\n\tpublic static boolean DumpInstructions=false;\n\t\n\tpublic static String LastFileDialogPath=\"\";\n\t\n\tpublic static final float MIN_HUE = 190.0f;\n\tpublic static final float MAX_HUE = 360.0f;\n\t\n\tpublic static final String version = \"0.2.2\";\n\tpublic static final String verPhase = \"beta\";\n\t\n}\n\n<file_path>src/main/java/dragondance/eng/Painter.java\npackage dragondance.eng;\n\nimport java.awt.Color;\nimport java.io.FileNotFoundException;\n\nimport dragondance.Globals;\nimport dragondance.eng.session.SessionManager;\n\npublic class Painter {\n\t\n\tprivate static final float BRIGHTNESS = 1.0f;\n\tprivate static final float SATURATION = 0.2f;\n\t\n\tpublic static final int CP_USE_MAX_DENSITY = 0;\n\tpublic static final int CP_USE_THRESHOLD_VALUE = 1;\n\t\n\tpublic static final int PAINT_MODE_DEFAULT=0;\n\tpublic static final int PAINT_MODE_INTERSECTION=1;\n\tpublic static final int PAINT_MODE_MAX=PAINT_MODE_INTERSECTION;\n\t\n\t\n\tprivate int colorPolicy;\n\tprivate boolean testSampleGen=false;\n\tprivate int testMaxDensity=0;\n\tprivate int mode=PAINT_MODE_DEFAULT;\n\t\n\tpublic Painter() {\n\t\tthis(false);\n\t}\n\t\n\tpublic Painter(boolean testSampleMode) {\n\t\tthis.testSampleGen=testSampleMode;\n\t\tthis.colorPolicy = CP_USE_THRESHOLD_VALUE;\n\t}\n\t\n\t//Hsb to Rgb conversion algorithm\n\t//#https://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV\n\tprivate Color hsbToRgb(float hue, float sat, float brig) {\n\t\tfloat c = sat * brig;\n\t\tfloat m = brig-c;\n\t\t\n\t\tfloat r,g,b;\n\t\t\n\t\thue /= 60.0;\n\t\t\n\t\tint i = ((Double)Math.floor(hue)).intValue();\n\t\t\n\t\tfloat x = c * (1-Math.abs(hue % 2 - 1));\n\t\t\n\t\tswitch (i) {\n\t\tcase 0:\n\t\t\tr=c;\n\t\t\tg=x;\n\t\t\tb=0;\n\t\t\tbreak;\n\t\tcase 1:\n\t\t\tr = x;\n\t\t\tg = c;\n\t\t\tb = 0;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tr = 0;\n\t\t\tg = c;\n\t\t\tb = x;\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\tr = 0;\n\t\t\tg = x;\n\t\t\tb = c;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tr = x;\n\t\t\tg = 0;\n\t\t\tb = c;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tr = c;\n\t\t\tg = 0;\n\t\t\tb = x;\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tr = (r + m) * 255.0f;\n\t\tg = (g + m) * 255.0f;\n\t\tb = (b + m) * 255.0f;\n\t\t\n\t\treturn new Color((int)r,(int)g,(int)b);\n\t}\n\t\n\tprivate int getMaxDensity() {\n\t\tif (this.testSampleGen)\n\t\t\treturn this.testMaxDensity;\n\t\t\n\t\treturn SessionManager.\n\t\t\t\tgetActiveSession().\n\t\t\t\tgetActiveCoverage().getMaxDensity();\n\t}\n\t\n\tprivate Color getHeatColorThreshold(int density) {\n\t\tint maxDensity;\n\t\tfloat heatHue,factor;\n\t\t\n\t\tmaxDensity = getMaxDensity();\n\t\t\n\t\tfactor = (Globals.MAX_HUE / maxDensity) / 2;\n\t\t\n\t\tif (factor < 1.0f)\n\t\t\tfactor = 1.0f;\n\t\t\n\t\theatHue = Globals.MIN_HUE + (density * factor);\n\t\t\n\t\tif (heatHue > Globals.MAX_HUE)\n\t\t\theatHue = Globals.MAX_HUE;\n\t\t\n\t\treturn hsbToRgb(heatHue,SATURATION,BRIGHTNESS);\n\t}\n\t\n\tprivate Color getHeatColorMaxDensity(int density) {\n\t\tfloat heatHue, dp,hp,hdiff;\n\t\t\n\t\thdiff = Globals.MAX_HUE - Globals.MIN_HUE;\n\t\t\n\t\tdp = (density / (float)getMaxDensity()) * 100.0f;\n\t\thp = (dp * hdiff) / 100.0f;\n\t\theatHue = Globals.MIN_HUE + hp;\n\t\t\n\t\treturn hsbToRgb(heatHue,SATURATION,BRIGHTNESS);\n\t}\n\t\n\tprivate Color getHeatColor(int density) {\n\t\t\n\t\tswitch (this.colorPolicy) {\n\t\tcase Painter.CP_USE_MAX_DENSITY:\n\t\t\treturn getHeatColorMaxDensity(density);\n\t\tcase Painter.CP_USE_THRESHOLD_VALUE:\n\t\t\treturn getHeatColorThreshold(density);\n\t\t}\n\t\t\n\t\treturn Color.WHITE;\n\t}\n\t\n\tpublic boolean paint(InstructionInfo inst) {\n\t\tColor color;\n\t\t\n\t\tif (this.mode == PAINT_MODE_DEFAULT) {\n\t\t\tcolor = getHeatColor(inst.getDensity());\n\t\t}\n\t\telse {\n\t\t\tcolor = hsbToRgb(360.0f,0.72f,0.60f);\n\t\t}\n\t\t\n\t\treturn DragonHelper.setInstructionBackgroundColor(inst.getAddr(), color);\n\t}\n\t\n\tpublic int setMode(int newMode) {\n\t\t\n\t\tint oldMode = this.mode;\n\t\t\n\t\tif (newMode < 0 || newMode > PAINT_MODE_MAX)\n\t\t\treturn -1;\n\t\t\n\t\tthis.mode = newMode;\n\t\treturn oldMode;\n\t}\n\t\n\t//Dont use this method. \n\tpublic void generateTestSample(int maxDensity, String file) {\n\t\tthis.testMaxDensity=maxDensity;\n\t\t\n\t\tjava.io.File ff = new java.io.File(file);\n\t\tjava.io.FileOutputStream fos = null;\n\t\t\n\t\ttry {\n\t\t\tfos = new java.io.FileOutputStream(ff,true);\n\t\t} catch (FileNotFoundException e) {\n\t\t\t// TODO Auto-generated catch block\n\t\t\te.printStackTrace();\n\t\t}\n\t\t\n\t\tjava.io.PrintWriter pw = new java.io.PrintWriter(fos);\n\t\t\n\t\tfor (int i=1;i<this.testMaxDensity+1;i++) {\n\t\t\tpw.write(\"<div style=\\\"background-color: \");\n\t\t\tColor c = getHeatColor(i);\n\t\t\tString hex = String.format(\"#%02x%02x%02x\", c.getRed(), c.getGreen(), c.getBlue());\n\t\t\tpw.write(hex + \"; width: 50px; height: 50px;\\\" />\");\n\t\t\tpw.write(String.valueOf(i));\n\t\t\tpw.write(\"<br /><br /><br />\");\n\t\t\t\n\t\t}\n\t\t\n\t\tpw.close();\n\t\t\n\t}\n}\n\n<file_path>src/main/java/dragondance/StringResources.java\npackage dragondance;\n\npublic final class StringResources {\n\tprivate static final String nl = System.lineSeparator();\n\t\n\tpublic static final String INVALID_CODE_ADDRESS_FIX_MESSAGE = \"%x is valid executable code address but \" +\n\t\t\t\t\t\"ghidra can't recognize it as an address of an instruction. probably due to incorrectly analyze\" +\n\t\t\t\t\tnl + nl + \n\t\t\t\t\t\"but it can be fixed with disassembling this section. you can choose yes to fix, \" +\n\t\t\t\t\t\"or choose no to review yourself. (the address located)\";\n\t\n\tpublic static final String MISMATCHED_EXECUTABLE = \"possible reasons:\" + nl + nl +\n\t\t\t\t\t\"1) the binary could be different version of the program\" + nl + \n\t\t\t\t\t\"the MD5 hash of the currently loaded image is \\\"%s\\\"\" + nl + nl + \n\t\t\t\t\t\"2) you forgot to reload the updated binary into ghidra.\" + nl + nl +\n\t\t\t\t\t\"3) you tried to load a coverage data to the mismatched program\";\n\t\n\t\n\tpublic static final String ABOUT = \"Dragon Dance (\" + Globals.version + \")\" + nl + nl +\n\t\t\t\t\t\"by oguz kartal\" + nl + \n\t\t\t\t\t\"http://oguzkartal.net/\";\n\t\n\tpublic static final String NEW_VERSION = \"There is new version of the dragondance.\" + nl + \n\t\t\t\t\t\"You can get the latest version from the github repo's release section\";\n\t\n\tpublic static final String UP_TO_DATE = \"It's up to date. cool!\";\n\t\n\tpublic static final String ATLEAST_2_COVERAGES = \"You have to select at least 2 coverages to do this operation\";\n\t\n\tpublic static final String COVERAGE_IMPORTED_HINT = \"Coverage data imported\" + nl +\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"You can select list item\" + nl +\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"to see coverage details\";\n}\n\n<file_path>src/main/java/dragondance/components/GuiAffectedOpInterface.java\npackage dragondance.components;\n\nimport java.io.FileNotFoundException;\n\nimport dragondance.datasource.CoverageData;\n\npublic interface GuiAffectedOpInterface {\n\tpublic CoverageData loadCoverage(String coverageDataFile) throws FileNotFoundException;\n\tpublic boolean removeCoverage(int id);\n\tpublic boolean visualizeCoverage(CoverageData coverage);\n\tpublic boolean goTo(long offset);\n}\n\n<file_path>src/main/java/dragondance/datasource/DynamorioDataSource.java\npackage dragondance.datasource;\n\nimport java.io.FileNotFoundException;\nimport java.util.Arrays;\nimport java.util.HashMap;\n\nimport dragondance.Log;\n\npublic class DynamorioDataSource extends CoverageDataSource {\n\n\tprivate int drCovVersion;\n\tprivate int moduleDefVersion;\n\tprivate String[] moduleInfoColumns;\n\t\n\tpublic DynamorioDataSource(String sourceFile, String mainModule) throws FileNotFoundException {\n\t\tsuper(sourceFile, mainModule,CoverageDataSource.SOURCE_TYPE_DYNA);\n\t\t\n\t}\n\t\n\tprivate void parseInformation() {\n\t\tString line;\n\t\tString[] parts;\n\t\t\n\t\twhile ((line = readLine()) != null) {\n\t\t\tif (line.startsWith(\"DRCOV VERSION:\")) {\n\t\t\t\tparts = splitMultiDelim(line,\": \",false);\n\t\t\t\tthis.drCovVersion = Integer.parseInt(parts[2]);\n\t\t\t}\n\t\t\telse if (line.startsWith(\"Module Table:\")) {\n\t\t\t\tparts = splitMultiDelim(line,\": ,\",false);\n\t\t\t\tthis.moduleDefVersion = Integer.parseInt(parts[3]);\n\t\t\t\tthis.moduleCount = Integer.parseInt(parts[5]);\n\t\t\t}\n\t\t\telse if (line.startsWith(\"Columns:\")) {\n\t\t\t\tparts = splitMultiDelim(line,\": ,\",false);\n\t\t\t\tthis.moduleInfoColumns = Arrays.copyOfRange(parts, 1, parts.length);\n\t\t\t\treadModules();\n\t\t\t}\n\t\t\telse if (line.startsWith(\"BB Table:\")) {\n\t\t\t\tparts = splitMultiDelim(line,\" \",false);\n\t\t\t\tthis.entryTableSize = Integer.parseInt(parts[2]);\n\t\t\t\treadEntries();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprivate void readModules() {\n\t\t\n\t\tHashMap<String,Integer> map =\n\t\t\t\tnew HashMap<String,Integer>();\n\t\t\n\t\t//Map columns name into the index.\n\t\t//So drcov file version may vary on different format version.\n\t\t//That is generic solution for all\n\t\tfor (int i=0;i<this.moduleInfoColumns.length;i++) {\n\t\t\t\n\t\t\tswitch (this.moduleInfoColumns[i]) {\n\t\t\tcase \"id\":\n\t\t\t\tmap.put(\"id\",i);\n\t\t\t\tbreak;\n\t\t\tcase \"containing_id\":\n\t\t\t\tmap.put(\"containing_id\",i);\n\t\t\t\tbreak;\n\t\t\tcase \"base\":\n\t\t\tcase \"start\":\n\t\t\t\tmap.put(\"base\", i);\n\t\t\t\tbreak;\n\t\t\tcase \"end\":\n\t\t\t\tmap.put(\"end\",i);\n\t\t\t\tbreak;\n\t\t\tcase \"path\":\n\t\t\t\tmap.put(\"path\", i);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tfinal boolean hasCid = map.containsKey(\"containing_id\");\n\t\tString line;\n\t\tint readModuleCount=0;\n\t\tModuleInfo mod=null;\n\t\t\n\t\twhile ((line = readLine()) != null) {\n\t\t\tString[] parts = splitMultiDelim(line,\",\",true);\n\t\t\t\n\t\t\tif (hasCid) {\n\t\t\t\tmod = ModuleInfo.make(\n\t\t\t\t\t\tparts[map.get(\"id\")],\n\t\t\t\t\t\tparts[map.get(\"containing_id\")],\n\t\t\t\t\t\tparts[map.get(\"base\")], \n\t\t\t\t\t\tparts[map.get(\"end\")], \n\t\t\t\t\t\tparts[map.get(\"path\")]\n\t\t\t\t\t\t\t\t);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmod = ModuleInfo.make(\n\t\t\t\t\t\tparts[map.get(\"id\")],\n\t\t\t\t\t\tparts[map.get(\"base\")], \n\t\t\t\t\t\tparts[map.get(\"end\")], \n\t\t\t\t\t\tparts[map.get(\"path\")]\n\t\t\t\t\t\t\t\t);\n\t\t\t}\n\t\t\t\n\t\t\tif (mod == null) {\n\t\t\t\tLog.warning(\"module not parsed for: %s\", line);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tthis.pushModule(mod);\n\t\t\t\n\t\t\tif (++readModuleCount == this.moduleCount)\n\t\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tprivate void readEntries() {\n\t\tBlockEntry entry;\n\t\t\n\t\twhile ((entry = this.readEntry()) != null) {\n\t\t\tthis.pushEntry(entry);\n\t\t}\n\t}\n\t\n\t@Override\n\tpublic boolean process() {\n\t\tparseInformation();\n\t\tthis.processed=true;\n\t\t\n\t\treturn super.process();\n\t}\n\t\n\tpublic int getDrcovVersion() {\n\t\treturn this.drCovVersion;\n\t}\n\t\n\tpublic int getFileDefinitionVersion() {\n\t\treturn this.moduleDefVersion;\n\t}\n\n}\n\n<file_path>src/main/java/dragondance/datasource/PintoolDataSource.java\npackage dragondance.datasource;\n\nimport java.io.FileNotFoundException;\n\nimport dragondance.Log;\n\npublic class PintoolDataSource extends CoverageDataSource {\n\n\tpublic PintoolDataSource(String sourceFile, String mainModule) throws FileNotFoundException {\n\t\tsuper(sourceFile, mainModule,CoverageDataSource.SOURCE_TYPE_PINTOOL);\n\t}\n\n\tprivate void parseInformation() {\n\t\tString line;\n\t\tString[] parts;\n\t\t\n\t\twhile ((line = readLine()) != null) {\n\t\t\tif (line.startsWith(\"EntryCount:\")) {\n\t\t\t\tparts = splitMultiDelim(line,\":, \",false);\n\t\t\t\tthis.entryTableSize = Integer.parseInt(parts[1]);\n\t\t\t\tthis.moduleCount = Integer.parseInt(parts[3]);\n\t\t\t}\n\t\t\telse if (line.startsWith(\"MODULE_TABLE\")) {\n\t\t\t\treadModules();\n\t\t\t}\n\t\t\telse if (line.startsWith(\"ENTRY_TABLE\")) {\n\t\t\t\treadEntries();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprivate void readModules() {\t\t\n\t\tString line;\n\t\tint readModuleCount=0;\n\t\t\n\t\twhile ((line = readLine()) != null) {\n\t\t\tString[] parts = splitMultiDelim(line,\",\", true);\n\t\t\t\n\t\t\tModuleInfo mod = ModuleInfo.make(\n\t\t\t\t\tparts[0], \n\t\t\t\t\tparts[1], \n\t\t\t\t\tparts[2], \n\t\t\t\t\tparts[3] );\n\t\n\t\t\tif (mod == null) {\n\t\t\t\tLog.warning(\"Module not parsed for: %s\", line);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tthis.pushModule(mod);\n\t\t\t\n\t\t\tif (++readModuleCount == this.moduleCount)\n\t\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tprivate void readEntries() {\n\t\tBlockEntry entry;\n\t\t\n\t\twhile ((entry = this.readEntryExtended()) != null) {\n\t\t\tthis.pushEntry(entry);\n\t\t}\n\t}\n\t\n\t@Override\n\tpublic boolean process() {\n\t\tparseInformation();\n\t\tthis.processed=true;\n\t\t\n\t\treturn super.process();\n\t}\n\t\n}\n\n<file_path>src/main/java/dragondance/eng/DragonHelper.java\npackage dragondance.eng;\n\nimport java.awt.Color;\nimport java.awt.Component;\nimport java.awt.EventQueue;\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StringWriter;\nimport java.lang.reflect.InvocationTargetException;\nimport java.net.URL;\nimport java.nio.file.Path;\nimport java.nio.file.Paths;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.concurrent.atomic.AtomicBoolean;\n\nimport javax.swing.SwingUtilities;\n\nimport docking.widgets.OptionDialog;\nimport docking.widgets.filechooser.GhidraFileChooser;\nimport docking.widgets.filechooser.GhidraFileChooserMode;\nimport dragondance.Globals;\nimport dragondance.StringResources;\nimport dragondance.exceptions.InvalidInstructionAddress;\nimport dragondance.util.Util;\nimport generic.concurrent.GThreadPool;\nimport generic.jar.ResourceFile;\nimport generic.json.JSONError;\nimport generic.json.JSONParser;\nimport generic.json.JSONToken;\nimport ghidra.app.plugin.core.colorizer.ColorizingService;\nimport ghidra.app.script.GhidraScript;\nimport ghidra.app.script.GhidraScriptProvider;\nimport ghidra.app.script.GhidraScriptUtil;\nimport ghidra.app.script.GhidraState;\nimport ghidra.app.services.ConsoleService;\nimport ghidra.app.services.GoToService;\nimport ghidra.framework.plugintool.PluginTool;\nimport ghidra.program.flatapi.FlatProgramAPI;\nimport ghidra.program.model.address.Address;\nimport ghidra.program.model.address.AddressSet;\nimport ghidra.program.model.listing.CodeUnit;\nimport ghidra.program.model.listing.Instruction;\nimport ghidra.program.model.mem.MemoryBlock;\nimport ghidra.util.Msg;\nimport ghidra.util.SystemUtilities;\nimport ghidra.util.task.DummyCancellableTaskMonitor;\nimport ghidra.util.task.TaskMonitor;\n\n\npublic class DragonHelper {\n\tprivate static PluginTool tool = null;\n\tprivate static FlatProgramAPI fapi = null;\n\tprivate static GThreadPool tpool = null;\n\t\n\t\n\tpublic static void init(PluginTool pluginTool, FlatProgramAPI api) {\n\t\tDragonHelper.tool = pluginTool;\n\t\tDragonHelper.fapi = api;\n\t}\n\t\n\tpublic static int startTransaction(String name) {\n\t\treturn fapi.getCurrentProgram().startTransaction(name);\n\t}\n\t\n\tpublic static void finishTransaction(int id, boolean commit) {\n\t\tfapi.getCurrentProgram().endTransaction(id, commit);\n\t}\n\t\n\t\n\tpublic static boolean runScript(String scriptName, String[] scriptArguments, GhidraState scriptState)\n\t\t\tthrows Exception {\n\t\t\n\t\t//set dummy printwriter to satisfy ghidra scripting api\n\t\t\n\t\tStringWriter sw = new StringWriter();\n\t\tPrintWriter writer = new PrintWriter(sw);\n\t\t\n\t\tTaskMonitor monitor = new DummyCancellableTaskMonitor();\n\t\t\n\t\tPath p = Paths.get(\n\t\t\t\tSystem.getProperty(\"user.dir\"),\n\t\t\t\t\"Ghidra\",\n\t\t\t\t\"Extensions\",\n\t\t\t\t\"dragondance\",\n\t\t\t\t\"ghidra_scripts\",\n\t\t\t\tscriptName\n\t\t\t\t);\n\t\t\n\t\t\n\t\t//List<ResourceFile> dirs = GhidraScriptUtil.getScriptSourceDirectories();\n\t\t\n\t\tResourceFile scriptSource = new ResourceFile(p.toAbsolutePath().toString());\n\t\t\n\t\t\n\t\tif (scriptSource.exists()) {\n\t\t\tGhidraScriptProvider gsp = GhidraScriptUtil.getProvider(scriptSource);\n\n\t\t\tif (gsp == null) {\n\t\t\t\twriter.close();\n\t\t\t\tthrow new IOException(\"Attempting to run subscript '\" + scriptName +\n\t\t\t\t\t\"': unable to run this script type.\");\n\t\t\t}\n\t\t\t\n\t\t\tGhidraScript script = gsp.getScriptInstance(scriptSource, writer);\n\t\t\tscript.setScriptArgs(scriptArguments);\n\t\t\t\n\t\t\tscript.execute(scriptState, monitor, writer);\n\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic static String getProgramName() {\n\t\treturn fapi.getCurrentProgram().getDomainFile().getName();\n\t}\n\t\n\t\n\tpublic static GThreadPool getTPool() {\n\t\tif (tpool == null) {\n\t\t\ttpool = GThreadPool.getPrivateThreadPool(\"DragonDance\");\n\t\t\ttpool.setMaxThreadCount(4);\n\t\t}\n\t\t\n\t\treturn tpool;\n\t}\n\t\n\tpublic static void queuePoolWorkItem(Runnable r) {\n\t\tgetTPool().submit(r);\n\t}\n\t\n\tpublic static boolean runOnSwingThread(Runnable r, boolean waitExecution) {\n\t\tif (waitExecution) {\n\t\t\ttry {\n\t\t\t\tSwingUtilities.invokeAndWait(r);\n\t\t\t} catch (InvocationTargetException | InterruptedException e) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tSystemUtilities.runIfSwingOrPostSwingLater(r);\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic static void showMessage(String message, Object...args) {\n\t\tif (isUiDispatchThread())\n\t\t\tMsg.showInfo(DragonHelper.class, null, \"Dragon Dance\", String.format(message, args));\n\t\telse\n\t\t\tshowMessageOnSwingThread(message,args);\n\t}\n\t\n\tpublic static void showWarning(String message, Object...args) {\n\t\tif (isUiDispatchThread())\n\t\t\tMsg.showWarn(DragonHelper.class, null, \"Dragon Dance\", String.format(message, args));\n\t\telse\n\t\t\tshowWarningOnSwingThread(message,args);\n\t}\n\t\n\tpublic static void showMessageOnSwingThread(String message, Object ...args) {\n\t\t\n\t\ttry {\n\t\t\tSwingUtilities.invokeAndWait(() -> {\n\t\t\t\tshowMessage(message, args);\n\t\t\t});\n\t\t} catch (InvocationTargetException | InterruptedException e) {\n\t\t\t\n\t\t}\n\t}\n\t\n\tpublic static void showWarningOnSwingThread(String message, Object ...args) {\n\t\t\n\t\ttry {\n\t\t\tSwingUtilities.invokeAndWait(() -> {\n\t\t\t\tshowWarning(message, args);\n\t\t\t});\n\t\t} catch (InvocationTargetException | InterruptedException e) {\n\t\t\t\n\t\t}\n\t}\n\t\n\tpublic static boolean showYesNoMessage(String title, String messageFormat, Object...args) {\n\t\t\n\t\tString message;\n\t\t\n\t\tmessage = String.format(messageFormat, args);\n\t\t\n\t\tAtomicBoolean yesno = new AtomicBoolean();\n\n\t\tRunnable r = () -> {\n\t\t\tint choice = OptionDialog.showYesNoDialog(null, title, message);\n\t\t\tyesno.set(choice == OptionDialog.OPTION_ONE);\n\t\t};\n\n\t\tSystemUtilities.runSwingNow(r);\n\t\t\n\t\treturn yesno.get();\n\t}\n\t\n\tpublic static void printConsole(String format, Object... args) {\n\t\t\n\t\tString message = String.format(format, args);\n\t\t\n\t\tif (tool == null) {\n\t\t\treturn;\n\t\t}\n\n\t\tConsoleService console = tool.getService(ConsoleService.class);\n\t\t\n\t\tif (console == null) {\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tconsole.print(message);\n\t\t\n\t}\n\t\n\tpublic static boolean isValidExecutableSectionAddress(long addr) {\n\t\tif (addr < getImageBase().getOffset())\n\t\t\treturn false;\n\t\t\n\t\tif (addr >= getImageEnd().getOffset())\n\t\t\treturn false;\n\t\t\n\t\treturn isCodeSectionAddress(addr);\n\t}\n\t\n\t\n\tpublic static boolean goToAddress(long addr) {\n\t\tGoToService gotoService = tool.getService(GoToService.class);\n\t\t\n\t\tif (gotoService==null) \n\t\t\treturn false;\n\t\t\n\t\tif (!isValidExecutableSectionAddress(addr)) {\n\t\t\tshowWarning(\"%x is not valid offset.\",addr);\n\t\t\treturn false;\n\t\t}\n\t\t\n\n\t\tif (getInstructionNoThrow(getAddress(addr),true) == null) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\treturn gotoService.goTo(getAddress(addr));\n\t}\n\t\n\tpublic static Address getAddress(long addrValue) {\n\t\treturn fapi.toAddr(addrValue);\n\t}\n\t\n\tpublic static String askFile(Component parent, String title, String okButtonText) {\n\t\t\n\t\tGhidraFileChooser gfc = new GhidraFileChooser(parent);\n\t\t\n\t\tif (!Globals.LastFileDialogPath.isEmpty()) {\n\t\t\tFile def = new File(Globals.LastFileDialogPath);\n\t\t\tgfc.setSelectedFile(def);\n\t\t}\n\t\t\n\t\tgfc.setTitle(title);\n\t\tgfc.setApproveButtonText(okButtonText);\n\t\tgfc.setFileSelectionMode(GhidraFileChooserMode.FILES_ONLY);\n\t\t\n\t\tFile file = gfc.getSelectedFile();\n\t\t\n\t\tif (file == null) {\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\tif (!file.exists())\n\t\t\treturn null;\n\t\t\n\t\tGlobals.LastFileDialogPath = Util.getDirectoryOfFile(file.getAbsolutePath());\n\t\t\n\t\tif (Globals.LastFileDialogPath == null)\n\t\t\tGlobals.LastFileDialogPath = System.getProperty(\"user.dir\");\n\t\t\n\t\treturn file.getAbsolutePath();\n\t}\n\t\n\tpublic static AddressSet makeAddressSet(long addr, int size) {\n\t\tAddress bAddr, eAddr;\n\t\t\n\t\tbAddr = fapi.toAddr(addr);\n\t\teAddr = bAddr.add(size);\n\t\t\n\t\tAddressSet addrSet = new AddressSet();\n\t\taddrSet.add(bAddr, eAddr);\n\t\t\n\t\treturn addrSet;\n\t}\n\t\n\tpublic static String getExecutableMD5Hash() {\n\t\treturn fapi.getCurrentProgram().getExecutableMD5();\n\t}\n\t\n\tpublic static Address getImageBase() {\n\t\tif (Globals.WithoutGhidra)\n\t\t\treturn getAddress(0x10000000);\n\t\t\n\t\treturn fapi.getCurrentProgram().getImageBase();\n\t}\n\t\n\tpublic static Address getImageEnd() {\n\t\treturn fapi.getCurrentProgram().getMaxAddress();\n\t}\n\t\n\tpublic static InstructionContext getInstruction(long addr, boolean throwEx) throws InvalidInstructionAddress {\n\t\treturn getInstruction(fapi.toAddr(addr),throwEx);\n\t}\n\t\n\tpublic static InstructionContext getInstruction(Address addr, boolean throwEx) throws InvalidInstructionAddress {\n\t\treturn getInstruction(addr,throwEx,false);\n\t}\n\t\n\tprivate static InstructionContext getInstructionNoThrow(Address addr, boolean icall) {\n\t\tInstructionContext inst = null;\n\t\t\n\t\ttry {\n\t\t\tinst = getInstruction(addr,false,icall);\n\t\t}\n\t\tcatch (Exception e) {}\n\t\t\n\t\treturn inst;\n\t}\n\t\n\tprivate static InstructionContext getInstruction(Address addr, boolean throwEx, boolean icall) throws InvalidInstructionAddress {\n\t\tInstructionContext ictx;\n\t\t\n\t\tif (addr == null) \n\t\t\treturn null;\n\t\t\n\t\tlong naddr=addr.getOffset();\n\t\t\n\t\tInstruction inst = fapi.getInstructionAt(addr);\n\t\tCodeUnit cu;\n\t\t\n\t\tif (inst == null) {\n\t\t\t\n\t\t\tif (icall) {\n\t\t\t\t\n\t\t\t\tif (throwEx)\n\t\t\t\t\tthrow new InvalidInstructionAddress(naddr);\n\t\t\t\t\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\t\n\t\t\tif (!isCodeSectionAddress(naddr)) {\n\t\t\t\t\n\t\t\t\tif (throwEx)\n\t\t\t\t\tthrow new InvalidInstructionAddress(naddr);\n\t\t\t\t\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\telse if (isInDisassembledRange(naddr)) {\n\t\t\t\t//invalid instruction\n\t\t\t\tif (throwEx)\n\t\t\t\t\tthrow new InvalidInstructionAddress(naddr);\n\t\t\t\t\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\t\n\t\t\tDragonHelper.goToAddress(naddr);\n\t\t\t\n\t\t\tboolean choice = DragonHelper.showYesNoMessage(\"Warning\", \n\t\t\t\t\tStringResources.INVALID_CODE_ADDRESS_FIX_MESSAGE,\n\t\t\t\t\tnaddr);\n\t\t\t\n\t\t\tif (choice) {\n\t\t\t\t\n\t\t\t\tif (!disassemble(naddr)) {\n\t\t\t\t\t\n\t\t\t\t\tif (throwEx)\n\t\t\t\t\t\tthrow new InvalidInstructionAddress(naddr);\n\t\t\t\t\t\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\n\t\t\t\treturn getInstruction(addr,throwEx,true);\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\tcu = fapi.getCurrentProgram().getListing().getCodeUnitAt(addr);\n\t\t\n\t\tictx = new InstructionContext(inst,cu);\n\t\t\n\t\treturn ictx;\n\t}\n\t\n\tpublic static boolean isUiDispatchThread() {\n\t\treturn EventQueue.isDispatchThread();\n\t}\n\t\n\tpublic static boolean disassemble(long addr) {\n\t\t\n\t\tboolean result;\n\t\tAtomicBoolean ret = new AtomicBoolean();\n\t\t\n\t\tint transId = startTransaction(\"DgDisasm\");\n\t\t\n\t\tif (EventQueue.isDispatchThread()) {\n\t\t\tresult = fapi.disassemble(getAddress(addr));\n\t\t}\n\t\telse {\n\t\t\t\n\t\t\tRunnable r = () -> {\n\n\t\t\t\t\tret.set(fapi.disassemble(getAddress(addr)));\n\n\t\t\t};\n\t\t\t\n\t\t\trunOnSwingThread(r, true);\n\t\t\t\n\t\t\tresult = ret.get();\n\t\t}\n\t\t\n\t\t\n\t\tfinishTransaction(transId,result);\n\t\t\n\t\treturn result;\n\t}\n\t\n\tpublic static List<MemoryBlock> getExecutableMemoryBlocks() {\n\t\tMemoryBlock[] blocks = fapi.getCurrentProgram().getMemory().getBlocks();\n\t\tList<MemoryBlock> memList = new ArrayList<MemoryBlock>();\n\t\t\n\t\tfor (MemoryBlock block : blocks) {\n\t\t\tif (block.isExecute()) {\n\t\t\t\tmemList.add(block);\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn memList;\n\t}\n\t\n\tpublic static boolean isCodeSectionAddress(long addr) {\n\t\t//.text, .init .fini __text\n\t\tboolean status=false;\n\t\t\n\t\tList<MemoryBlock> execBlocks = getExecutableMemoryBlocks();\n\t\t\n\t\tfor (MemoryBlock mb : execBlocks) {\n\t\t\tif (addr >= mb.getStart().getOffset() && addr < mb.getEnd().getOffset()) {\n\t\t\t\tstatus=true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\texecBlocks.clear();\n\t\t\n\t\treturn status;\n\t}\n\t\n\tpublic static boolean isInDisassembledRange(long addr) {\n\t\tint iMax=15;\n\t\t\n\t\tAddress gaddr;\n\t\tInstructionContext inst;\n\t\t\n\t\tgaddr = getAddress(addr);\n\t\t\n\t\tinst = getInstructionNoThrow(gaddr,true);\n\t\t\n\t\tif (inst != null)\n\t\t\treturn true;\n\t\t\n\t\twhile (iMax-- > 0) {\n\t\t\tgaddr = gaddr.subtract(1);\n\t\t\tinst = getInstructionNoThrow(gaddr,true);\n\t\t\t\n\t\t\tif (inst != null)\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (inst == null)\n\t\t\treturn false;\n\t\t\n\t\tgaddr = gaddr.add(inst.getSize());\n\t\t\n\t\tinst = getInstructionNoThrow(gaddr,true);\n\t\t\n\t\tif (inst == null)\n\t\t\treturn false;\n\t\t\n\t\tif (addr <= inst.getAddress()) {\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\tiMax = 15;\n\t\t\n\t\twhile (iMax-- > 0) {\n\t\t\tgaddr = gaddr.add(inst.getSize());\n\t\t\t\n\t\t\tinst = getInstructionNoThrow(gaddr,true);\n\t\t\t\n\t\t\tif (inst != null) {\n\t\t\t\tif (inst.getAddress() <= addr) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\t\n\t\treturn false;\n\t}\n\t\n\tpublic static boolean setInstructionBackgroundColor(long addr, Color color) {\n\t\t\n\t\tAddress ba;\n\t\t\n\t\tColorizingService colorService = tool.getService(ColorizingService.class);\n\t\t\n\t\tif (colorService == null) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tba = getAddress(addr);\n\t\t\n\t\tcolorService.setBackgroundColor(ba, ba, color);\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic static boolean clearInstructionBackgroundColor(long addr) {\n\t\t\n\t\tAddress ba;\n\t\t\n\t\tColorizingService colorService = tool.getService(ColorizingService.class);\n\t\t\n\t\tif (colorService == null) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tba = getAddress(addr);\n\t\t\n\t\tcolorService.clearBackgroundColor(ba, ba);\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic static String getStringFromURL(String url) {\n\t\ttry {\n\t\t\tURL u = new URL(url);\n\t\t\t\n\t StringBuilder sb = new StringBuilder();\n\t BufferedReader reader = new BufferedReader(new InputStreamReader(u.openStream()));\n\t \n\t String nextLine = \"\";\n\t \n\t while ((nextLine = reader.readLine()) != null) {\n\t \tsb.append(nextLine + \"\\n\");\n\t }\n\n\t return sb.toString();\n\t\t\t\n\t\t} catch (IOException e) {\n\t\t\t\n\t\t} \n\t\t\n\t\treturn null;\n\t}\n\t\n\tpublic static Object parseJson(String jsonData) {\n\t\tchar[] cbuf = new char[jsonData.length()];\n\t\tObject obj = null;\n\t\tJSONParser parser = new JSONParser();\n\t\tList<JSONToken> tokens = new ArrayList<JSONToken>();\n\t\tjsonData.getChars(0, jsonData.length(), cbuf, 0);\n\t\t\n\t\tif (parser.parse(cbuf, tokens) != JSONError.JSMN_SUCCESS) {\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\ttry {\n\t\t\tobj = parser.convert(cbuf, tokens);\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\ttokens.clear();\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\ttokens.clear();\n\t\treturn obj;\n\t}\n}\n\n<file_path>src/main/java/dragondance/util/Util.java\npackage dragondance.util;\n\nimport java.io.File;\nimport java.security.MessageDigest;\nimport java.security.NoSuchAlgorithmException;\n\nimport dragondance.Globals;\nimport dragondance.eng.DragonHelper;\n\npublic final class Util {\n\tpublic static String getObjectNameFromPath(String path) {\n\t\tint p1,p2;\n\t\t\n\t\tp1 = path.lastIndexOf(File.separator);\n\t\tp2 = path.lastIndexOf(\".\");\n\t\t\n\t\tif (p1 < 0) {\n\t\t\tp1 = 0;\n\t\t}\n\t\t\n\t\tif (p2 < 0) {\n\t\t\tp2 = path.length();\n\t\t}\n\t\t\n\t\treturn path.substring(p1+1, p2);\n\t}\n\t\n\tpublic static String getDirectoryOfFile(String path) {\n\t\tFile file = new File(path);\n\t\t\n\t\tif (file.isDirectory())\n\t\t\treturn file.getAbsolutePath();\n\t\t\n\t\treturn file.getParent();\n\t}\n\t\n\tprivate static int parseVersion(String ver) {\n\t\t\n\t\tif (ver == null)\n\t\t\treturn 0;\n\t\t\n\t\tString[] parts = ver.trim().split(\"\\\\.\");\n\t\t\n\t\tif (parts.length==0)\n\t\t\treturn 0;\n\t\t\n\t\tint nver=0;\n\t\t\n\t\ttry {\n\t\t\tnver = Integer.parseInt(parts[0]) << 16;\n\t\t\t\n\t\t\tif (parts.length>1)\n\t\t\t\tnver |= Integer.parseInt(parts[1]) << 8;\n\t\t\t\n\t\t\tif (parts.length>2)\n\t\t\t\tnver |= Integer.parseInt(parts[2]);\n\t\t}\n\t\tcatch (NumberFormatException e) {\n\t\t\treturn 0;\n\t\t}\n\t\t\n\t\treturn nver;\n\t}\n\t\n\tpublic static boolean checkForNewVersion() {\n\t\tString content = \n\t\t\t\tDragonHelper.getStringFromURL(\"https://raw.githubusercontent.com/0ffffffffh/dragondance/master/.version\");\n\t\t\n\t\tif (content == null)\n\t\t\treturn false;\n\t\t\n\t\tint lver,pver;\n\t\t\n\t\tlver = parseVersion(content);\n\t\tpver = parseVersion(Globals.version);\n\t\t\n\t\tif (lver <= pver)\n\t\t\treturn false;\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic static String md5(String sval) {\n\t\treturn md5(sval.getBytes());\n\t}\n\t\n\tpublic static String md5(byte[] value) {\n\t\tMessageDigest md = null;\n\t\tStringBuffer sb = new StringBuffer();\n\t\t\n\t\ttry {\n\t\t\tmd = MessageDigest.getInstance(\"MD5\");\n\t\t} catch (NoSuchAlgorithmException e) {\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\tmd.update(value);\n\t\tbyte[] digest = md.digest();\n\t\t\n\t\tfor (byte b : digest) {\n\t\t\tsb.append(String.format(\"%02x\", b));\n\t\t}\n\t\t\n\t\treturn sb.toString();\n\t}\n}\n\n<file_path>src/main/java/dragondance/Log.java\npackage dragondance;\n\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.PrintWriter;\nimport java.time.LocalDateTime;\n\nimport dragondance.eng.DragonHelper;\n\npublic class Log {\n\tfinal static int LOGGER_ENABLED = \t\t\t\t1 << 0;\n\t\n\tfinal static int LOGGER_LOG_GHIDRA_CONSOLE = \t1 << 8;\n\tfinal static int LOGGER_LOG_FILE =\t\t\t\t1 << 9;\n\tfinal static int LOGGER_LOG_STDOUT=\t\t\t\t1 << 10;\n\t\n\tfinal static int LOGGER_ERROR = \t\t\t\t1 << 22;\n\tfinal static int LOGGER_WARNING = \t\t\t\t1 << 23;\n\tfinal static int LOGGER_INFO = \t\t\t\t\t1 << 24;\n\tfinal static int LOGGER_DEBUG = \t\t\t\t1 << 25;\n\tfinal static int LOGGER_VERBOSE = \t\t\t\t1 << 26;\n\t\n\tprivate static int logFlag=0;\n\tprivate static String logFile = \"dragondance.log\";\n\t\n\tprivate static FileOutputStream fos;\n\tprivate static PrintWriter pw;\n\t\n\tprivate static boolean createLogFile() {\n\t\t\n\t\tif (fos != null)\n\t\t\treturn true;\n\t\t\n\t\ttry {\n\t\t\tfos = new FileOutputStream(logFile,true);\n\t\t} catch (FileNotFoundException | SecurityException e) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tpw = new PrintWriter(fos,true);\n\t\t\n\t\tpw.println(\"Logging started at \" + LocalDateTime.now().toString());\n\t\t\n\t\treturn true;\n\t}\n\t\n\tprivate static void closeLogFile() {\n\t\t\n\t\tif (pw != null)\n\t\t{\n\t\t\tpw.close();\n\t\t\tpw=null;\n\t\t\tfos=null;\n\t\t}\n\t}\n\t\n\t\n\tprivate static boolean flagSetReset(final int v, boolean enabled) {\n\t\tboolean previous = (logFlag & v) == v;\n\t\t\n\t\tif (enabled)\n\t\t\tlogFlag |= v;\n\t\telse\n\t\t\tlogFlag &= ~v;\n\t\t\n\t\treturn previous;\n\t}\n\t\n\tprivate static final boolean hasFlag(final int flag) {\n\t\treturn (logFlag & flag) == flag;\n\t}\n\t\n\tpublic static void setEnable(boolean enabled) {\n\t\t\n\t\tflagSetReset(LOGGER_ENABLED,enabled);\n\t\t\n\t\tif (!enabled && hasFlag(LOGGER_LOG_FILE))\n\t\t\tenableFileLogging(false);\n\t}\n\t\n\tpublic static void enableGhidraConsoleLogging(boolean enabled) {\n\t\tflagSetReset(LOGGER_LOG_GHIDRA_CONSOLE,enabled);\n\t}\n\t\n\tpublic static void enableFileLogging(boolean enabled) {\n\t\t\n\t\tif (enabled) {\n\t\t\tif (!createLogFile())\n\t\t\t\treturn;\n\t\t}\n\t\telse\n\t\t\tcloseLogFile();\n\t\t\n\t\tflagSetReset(LOGGER_LOG_FILE,enabled);\n\t}\n\t\n\tpublic static boolean enableStdoutLogging(boolean enabled) {\n\t\treturn flagSetReset(LOGGER_LOG_STDOUT,enabled);\n\t}\n\t\n\tpublic static boolean enableError(boolean enable) {\n\t\treturn flagSetReset(LOGGER_ERROR,enable);\n\t}\n\t\n\tpublic static boolean enableWarning(boolean enable) {\n\t\treturn flagSetReset(LOGGER_WARNING,enable);\n\t}\n\t\n\tpublic static boolean enableInfo(boolean enable) {\n\t\treturn flagSetReset(LOGGER_INFO,enable);\n\t}\n\t\n\tpublic static boolean enableVerbose(boolean enable) {\n\t\treturn flagSetReset(LOGGER_VERBOSE,enable);\n\t}\n\t\n\tpublic static boolean enableDebug(boolean enable) {\n\t\treturn flagSetReset(LOGGER_DEBUG,enable);\n\t}\n\t\n\tprivate static void print(String logType, String format, Object... args) {\n\t\tString slog = \"\";\n\t\t\n\t\t\n\t\tif (!hasFlag(LOGGER_ENABLED))\n\t\t\treturn;\n\t\t\n\t\t//emulate %p formatter in java.\n\t\tString pRepl = System.getProperty(\"os.arch\").\n\t\t\t\tcontains(\"64\") ? \"0x%016x\" : \"0x%08x\";\n\t\tformat = format.replace(\"%p\", pRepl);\n\t\t\n\t\tif (logType != null && !logType.isEmpty()) {\n\t\t\tslog = \"(\" + logType + \"): \";\n\t\t}\n\t\t\n\t\tslog += String.format(format, args);\n\t\t\n\t\t\n\t\tif (hasFlag(LOGGER_LOG_GHIDRA_CONSOLE))\n\t\t\tDragonHelper.printConsole(slog);\n\t\t\n\t\tif (hasFlag(LOGGER_LOG_FILE)) {\n\t\t\tpw.print(slog);\n\t\t\tpw.flush();\n\t\t}\n\t\t\n\t\t//Put the stdout (in debug mode this content printed into eclipse console)\n\t\t\n\t\tif (hasFlag(LOGGER_LOG_STDOUT))\n\t\t\tSystem.out.print(slog);\n\t\t\n\t}\n\t\n\tpublic static void plain(String format, Object...args) {\n\t\tprint(\"\",format,args);\n\t}\n\t\n\tpublic static void println(String format, Object... args) {\n\t\tprint(\"\",format + \"\\n\",args);\n\t}\n\t\n\tpublic static void println(String logType, String format, Object...args) {\n\t\tprint(logType,format + \"\\n\",args);\n\t}\n\t\n\tpublic static void error(String format, Object... args) {\n\t\t\n\t\tif (!hasFlag(LOGGER_ERROR))\n\t\t\treturn;\n\t\t\n\t\tprintln(\"Error\",format,args);\n\t}\n\t\n\n\tpublic static void warning(String format, Object... args) {\n\t\t\n\t\tif (!hasFlag(LOGGER_WARNING))\n\t\t\treturn;\n\t\t\n\t\tprintln(\"Warning\",format,args);\n\t}\n\t\n\n\tpublic static void info(String format, Object... args) {\n\t\t\n\t\tif (!hasFlag(LOGGER_INFO))\n\t\t\treturn;\n\t\t\n\t\tprintln(\"Info\",format,args);\n\t}\n\t\n\tpublic static void verbose(String format, Object... args) {\n\t\t\n\t\tif (!hasFlag(LOGGER_VERBOSE))\n\t\t\treturn;\n\t\t\n\t\tprintln(\"Verbose\",format,args);\n\t}\n\t\n\tpublic static void debug(String format, Object... args) {\n\t\t\n\t\tif (!hasFlag(LOGGER_DEBUG))\n\t\t\treturn;\n\t\t\n\t\tprintln(\"Dbg\",format,args);\n\t}\n\t\n\tpublic static boolean isEnabled() {\n\t\treturn hasFlag(LOGGER_ENABLED);\n\t}\n\t\n\tpublic static void done() {\n\t\tlogFlag = 0;\n\t\t\n\t\tcloseLogFile();\n\t}\n\t\n}\n\n<file_path>src/main/java/dragondance/datasource/CoverageDataSource.java\npackage dragondance.datasource;\n\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.nio.ByteBuffer;\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport dragondance.Log;\nimport dragondance.util.Util;\n\nenum ByteMapTypes\n{\n\tUint32,\n\tUShort\n}\n\npublic class CoverageDataSource implements AutoCloseable{\n\t\n\tpublic static final int SOURCE_TYPE_DYNA = 0;\n\tpublic static final int SOURCE_TYPE_PINTOOL = 1;\n\t\n\t\n\tprotected int moduleCount=0;\n\tprotected int entryTableSize=0;\n\t\n\tprotected List<ModuleInfo> modules;\n\tprotected List<BlockEntry> entries;\n\t\n\tprotected String mainModuleName = null;\n\tprotected ModuleInfo mainModule = null;\n\t\n\tprotected boolean isEof = false;\n\tprotected boolean processed = false;\n\tprivate FileInputStream fis = null;\n\tprivate ByteBuffer buf = null;\n\tprivate String filePath;\n\tprivate int id = 0;\n\tprivate int type=-1;\n\tprivate String name;\n\t\n\tpublic CoverageDataSource(String sourceFile, String mainModule,int type) throws FileNotFoundException {\n\t\tthis.mainModuleName=mainModule;\n\t\tthis.type=type;\n\t\t\n\t\tFile file = new File(sourceFile);\n\t\t\n\t\tif (!file.exists())\n\t\t\tthrow new FileNotFoundException(sourceFile);\n\t\t\n\t\tthis.filePath = sourceFile;\n\t\tthis.name = Util.getObjectNameFromPath(sourceFile);\n\t\t\n\t\tthis.fis = new FileInputStream(file);\n\t\tthis.buf = ByteBuffer.allocate(1 * 1024 * 1024);\n\t\t\n\t\tthis.modules = new ArrayList<ModuleInfo>();\n\t\tthis.entries = new ArrayList<BlockEntry>();\n\t\t\n\t\treadIntoBuffer();\n\t\t\n\t}\n\t\n\tpublic static int detectCoverageDataFileType(String file) throws FileNotFoundException {\n\t\tCoverageDataSource cds;\n\t\tint type = -1;\n\t\t\n\t\tcds = new CoverageDataSource(file,null,-1);\n\t\t\n\t\tString s = cds.readLine();\n\t\t\n\t\tif (s.startsWith(\"DDPH-PINTOOL\"))\n\t\t\ttype = SOURCE_TYPE_PINTOOL;\n\t\telse if (s.startsWith(\"DRCOV VERSION:\"))\n\t\t\ttype = SOURCE_TYPE_DYNA;\n\t\t\n\t\t\n\t\ttry {\n\t\t\tcds.close();\n\t\t} catch (Exception e) { } \n\t\t\n\t\treturn type;\n\t}\n\t\n\tprivate boolean readIntoBuffer() {\n\t\t\n\t\tthis.buf.clear();\n\t\tint readLen=0;\n\t\t\n\t\tif (this.isEof)\n\t\t\treturn false;\n\t\t\n\t\ttry {\n\t\t\treadLen = this.fis.read(this.buf.array(), 0, this.buf.capacity());\n\t\t\t\n\t\t\tif (readLen == -1) {\n\t\t\t\tthis.isEof=true;\n\t\t\t\tthis.fis.close();\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tthis.buf.limit(readLen);\n\t\t\t\n\t\t} catch (IOException e) {\n\t\t\tLog.println(e.getMessage());\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tprivate byte readByte() {\n\t\tbyte b;\n\t\t\n\t\tif (this.buf.hasRemaining())\n\t\t\tb = this.buf.get();\n\t\telse {\n\t\t\t\n\t\t\tif (!readIntoBuffer())\n\t\t\t\treturn -1;\n\t\t\t\n\t\t\tb = this.buf.get();\n\t\t}\n\t\t\n\t\treturn b;\n\t}\n\t\n\tprivate int readBytes(byte[] rbuf, int bufOffset, int len) {\n\t\t\n\t\tint readLen=0;\n\t\t\n\t\tif (!this.buf.hasRemaining()) {\n\t\t\tif (!readIntoBuffer())\n\t\t\t\treturn -1;\n\t\t}\n\t\t\n\t\tif (this.buf.remaining() < len) {\n\t\t\tint rem=this.buf.remaining();\n\t\t\tthis.buf.get(rbuf, bufOffset, rem);\n\t\t\t\n\t\t\treadLen = rem;\n\t\t\t\n\t\t\tif (!readIntoBuffer()) {\n\t\t\t\treturn readLen;\n\t\t\t}\n\t\t\t\n\t\t\treadLen += readBytes(rbuf,readLen,len-rem);\n\t\t\t\n\t\t}\n\t\telse {\n\t\t\tthis.buf.get(rbuf,bufOffset,len);\n\t\t\treadLen = len;\n\t\t}\n\t\t\n\t\t\n\t\treturn readLen;\n\t}\n\t\n\tprotected String[] splitMultiDelim(String str, String delims, boolean trimItem) {\n\t\tint p=0,slen=str.length();\n\t\tString s;\n\t\t\n\t\tif (slen == 0)\n\t\t\treturn null;\n\t\t\n\t\tArrayList<String> parts = new ArrayList<String>();\n\t\t\n\t\tfor (int i=0;i<slen;i++) {\n\t\t\tif (delims.indexOf(str.charAt(i)) != -1) {\n\t\t\t\t\n\t\t\t\tif (p != i) {\n\t\t\t\t\ts = str.substring(p,i);\n\t\t\t\t\t\n\t\t\t\t\tif (trimItem)\n\t\t\t\t\t\ts = s.trim();\n\t\t\t\t\t\n\t\t\t\t\tparts.add(s);\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\tp = i + 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (p != slen) {\n\t\t\ts = str.substring(p,slen);\n\t\t\t\n\t\t\tif (trimItem)\n\t\t\t\ts = s.trim();\n\t\t\t\n\t\t\tparts.add(s);\n\t\t}\n\t\t\n\t\treturn parts.toArray(new String[parts.size()]);\n\t}\n\t\n\tprotected String readLine() {\n\t\tboolean gotLine=false;\n\t\tString s = null;\n\t\tStringBuilder sb = new StringBuilder();\n\t\tbyte b = 0;\n\t\t\n\t\twhile (!gotLine) {\n\t\t\t\n\t\t\tb = readByte();\n\t\t\t\n\t\t\tif (b == -1 && this.isEof)\n\t\t\t\treturn null;\n\t\t\t\n\t\t\tif (b == '\\n') {\n\t\t\t\t\n\t\t\t\tif (sb.length() == 0)\n\t\t\t\t\treturn \"\";\n\t\t\t\t\n\t\t\t\tif (sb.charAt(sb.length()-1) == '\\r') {\n\t\t\t\t\tsb.deleteCharAt(sb.length()-1);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\ts = sb.toString();\n\t\t\t\tsb.setLength(0);\n\t\t\t\t\n\t\t\t\tgotLine=true;\n\t\t\t}\n\t\t\telse\n\t\t\t\tsb.append((char)b);\n\t\t\t\n\t\t}\n\t\t\n\t\treturn s;\n\t}\n\t\n\t//gosh java!, why you have not unsigned types?\n\tprivate int b2uint(byte b) {\n\t\treturn (b) & 0xFF;\n\t}\n\t\n\tprivate Number[] mapBytesToValues(byte[] bytes, ByteMapTypes... types) {\n\t\tNumber[] values = new Number[types.length];\n\t\t\n\t\tint index=0,pos=0;\n\t\t\n\t\tfor (ByteMapTypes bmt : types) {\n\t\t\tswitch (bmt) {\n\t\t\tcase Uint32:\n\t\t\t\tint ival = b2uint(bytes[index]) | b2uint(bytes[index+1]) << 8 | b2uint(bytes[index+2]) << 16 | b2uint(bytes[index+3]) << 24;\n\t\t\t\tvalues[pos++] = ival;\n\t\t\t\tindex += 4;\n\t\t\t\tbreak;\n\t\t\tcase UShort:\n\t\t\t\tshort sval = (short) (b2uint(bytes[index]) | b2uint(bytes[index+1]) << 8);\n\t\t\t\tvalues[pos++] = sval;\n\t\t\t\tindex += 2;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn values;\n\t}\n\t\n\tprivate Number[] readBlockEntryNative(int readSize, ByteMapTypes... mapTypes) {\n\t\tint readLen=0;\n\t\tbyte[] entryBuf = new byte[readSize];\n\t\t\n\t\treadLen = readBytes(entryBuf,0,readSize);\n\t\t\n\t\tif (readLen == -1) {\n\t\t\tthis.isEof=true;\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\tNumber[] mapValues = mapBytesToValues(\n\t\t\t\tentryBuf,\n\t\t\t\tmapTypes);\n\t\t\n\t\treturn mapValues;\n\t}\n\t\n\tprotected BlockEntry readEntry() {\n\n\t\tNumber[] mapValues = readBlockEntryNative(8,\n\t\t\t\tByteMapTypes.Uint32,ByteMapTypes.UShort, ByteMapTypes.UShort);\n\t\t\n\t\tif (mapValues == null)\n\t\t\treturn null;\n\t\t\n\t\t\n\t\tBlockEntry be = new BlockEntry(\n\t\t\t\tmapValues[0].intValue(),\n\t\t\t\tmapValues[1].intValue(),\n\t\t\t\tmapValues[2].intValue(),\n\t\t\t\t0);\n\t\t\n\t\treturn be;\n\t}\n\t\n\tprotected BlockEntry readEntryExtended() {\n\t\tNumber[] mapValues = readBlockEntryNative(12,\n\t\t\t\tByteMapTypes.Uint32,ByteMapTypes.UShort, ByteMapTypes.UShort, ByteMapTypes.Uint32);\n\t\t\n\t\tif (mapValues == null) \n\t\t\treturn null;\n\t\t\n\t\tBlockEntry be = new BlockEntry(\n\t\t\t\tmapValues[0].intValue(),\n\t\t\t\tmapValues[1].intValue(),\n\t\t\t\tmapValues[2].intValue(),\n\t\t\t\tmapValues[3].intValue());\n\t\t\n\t\treturn be;\n\t}\n\t\n\tprotected void pushModule(ModuleInfo mod) {\n\t\tif (this.mainModuleName != null && \n\t\t\t\tthis.mainModule == null && \n\t\t\t\tmod.getPath().toLowerCase().endsWith(this.mainModuleName.toLowerCase())\n\t\t\t\t) \n\t\t{\n\t\t\tthis.mainModule = mod;\n\t\t\t\n\t\t\tLog.info(\"Main module id: %d\",this.mainModule.getId());\n\t\t}\n\t\t\n\t\tthis.modules.add(mod);\n\t}\n\t\n\tprivate boolean isMainModuleEntry(BlockEntry entry) {\n\t\tfinal boolean hasCid = this.mainModule.hasContainingId();\n\t\t\n\t\tif (!hasCid)\n\t\t\treturn this.mainModule.getId() == entry.getModuleId();\n\t\t\n\t\treturn this.mainModule.getContainingId() == entry.getModuleId();\n\t}\n\t\n\tprotected void pushEntry(BlockEntry entry) {\n\t\tif (this.mainModule == null || (this.mainModule != null && isMainModuleEntry(entry))) {\n\t\t\tthis.entries.add(entry);\n\t\t}\n\t}\n\t\n\tpublic boolean process() {\n\t\t\n\t\tif (this.processed) {\n\t\t\tLog.info(\"%s processed.\",this.getClass().getName().replace(\"DataSource\", \"\"));\n\t\t\tLog.info(\"Module count: %d, Entry count: %d\",this.moduleCount,this.entryTableSize);\n\t\t\t\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n\t\n\tpublic final boolean isProcessed() {\n\t\treturn this.processed;\n\t}\n\t\n\tpublic int getType() {\n\t\treturn this.type;\n\t}\n\t\n\tpublic int getId() {\n\t\treturn this.id;\n\t}\n\t\n\tpublic void setId(int cid) {\n\t\tif (this.id == 0)\n\t\t\tthis.id = cid;\n\t}\n\t\n\t\n\t@Override\n\tpublic void close() throws Exception {\n\t\tthis.modules.clear();\n\t\tthis.entries.clear();\n\t\tthis.fis.close();\n\t}\n\t\n\tpublic final int getModuleCount() {\n\t\treturn this.moduleCount;\n\t}\n\t\n\tpublic final int getReadedModuleCount() {\n\t\treturn this.modules.size();\n\t}\n\t\n\tpublic final int getEntryCount() {\n\t\treturn this.entryTableSize;\n\t}\n\t\n\tpublic final int getReadedEntryCount() {\n\t\treturn this.entries.size();\n\t}\n\t\n\tpublic final int getMainModuleId() {\n\t\tif (this.mainModule == null)\n\t\t\treturn -1;\n\t\t\n\t\treturn this.mainModule.getId();\n\t}\n\t\n\tpublic final String getName() {\n\t\treturn this.name;\n\t}\n\t\n\tpublic final String getFilePath() {\n\t\treturn this.filePath;\n\t}\n}\n\n<file_path>src/main/java/dragondance/eng/session/Session.java\npackage dragondance.eng.session;\n\nimport java.io.FileNotFoundException;\nimport java.lang.reflect.InvocationTargetException;\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport dragondance.Log;\nimport dragondance.datasource.CoverageData;\nimport dragondance.datasource.CoverageDataSource;\nimport dragondance.datasource.DynamorioDataSource;\nimport dragondance.datasource.PintoolDataSource;\nimport dragondance.eng.Painter;\n\n\npublic class Session {\n\t\t\n\tprivate String sessionName;\n\tprivate String imageName;\n\tprivate int coverageIndex=1;\n\t\n\tprivate List<CoverageData> coverageSources;\n\t\n\tprivate CoverageData activeCoverage=null;\n\t\n\tprivate Painter painter=null;\n\t\n\tpublic static Session createNew(String name, String imageName) {\n\t\tSession sess = new Session();\n\t\t\n\t\tsess.imageName = imageName;\n\t\tsess.sessionName = name;\n\t\tsess.coverageSources = new ArrayList<CoverageData>();\n\t\t\n\t\tSessionManager.registerSession(sess);\n\t\t\n\t\treturn sess;\n\t}\n\t\n\tprivate Class<?> getDatasourceAdapter(int type) {\n\t\tswitch (type)\n\t\t{\n\t\tcase CoverageDataSource.SOURCE_TYPE_DYNA:\n\t\t\treturn DynamorioDataSource.class;\n\t\tcase CoverageDataSource.SOURCE_TYPE_PINTOOL:\n\t\t\treturn PintoolDataSource.class;\n\t\t}\n\t\t\n\t\treturn null;\n\t}\n\t\n\tpublic static String getCoverageTypeString(int typeValue) {\n\t\tswitch (typeValue) {\n\t\tcase CoverageDataSource.SOURCE_TYPE_DYNA:\n\t\t\treturn \"Dynamorio\";\n\t\tcase CoverageDataSource.SOURCE_TYPE_PINTOOL:\n\t\t\treturn \"Pintool\";\n\t\t}\n\t\t\n\t\treturn \"Unknown\";\n\t}\n\t\n\tpublic static Session open(String sessionDatabase) throws Exception {\n\t\tthrow new Exception(\"Session.open not implemented yet.\");\n\t}\n\t\n\t\n\tpublic CoverageData addCoverageData(String fileName) throws FileNotFoundException {\n\t\tint sourceType = CoverageDataSource.detectCoverageDataFileType(fileName);\n\t\t\n\t\tif (sourceType == -1)\n\t\t\treturn null;\n\t\t\n\t\tClass<?> clazz = getDatasourceAdapter(sourceType);\n\t\tCoverageDataSource dataSource;\n\t\tCoverageData coverage;\n\t\t\n\t\tif (clazz == null)\n\t\t\treturn null;\n\t\t\n\t\t\n\t\ttry {\n\t\t\tdataSource = (CoverageDataSource)clazz.getDeclaredConstructor(String.class, String.class).newInstance(fileName, this.imageName);\n\t\t} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException\n\t\t\t\t| NoSuchMethodException | SecurityException e) {\n\n\t\t\tLog.println(e.getMessage());\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\tdataSource.setId(coverageIndex++);\n\t\t\n\t\tcoverage = new CoverageData(dataSource);\n\t\t\n\t\tthis.coverageSources.add(coverage);\n\t\t\n\t\tif (this.activeCoverage == null) {\n\t\t\tthis.activeCoverage = coverage;\n\t\t}\n\t\t\n\t\treturn coverage;\n\t}\n\t\n\tpublic CoverageData getCoverage(int id) {\n\t\tCoverageData covData;\n\t\t\n\t\tfor (int i=0;i<this.coverageSources.size();i++) {\n\t\t\tcovData = this.coverageSources.get(i);\n\t\t\t\n\t\t\tif (covData.getSourceId() == id) {\n\t\t\t\treturn covData;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn null;\n\t}\n\t\n\tpublic boolean removeCoverageData(int id) {\n\t\tint index=-1;\n\t\tCoverageData covData;\n\t\t\n\t\tfor (int i=0;i<this.coverageSources.size();i++) {\n\t\t\tif (this.coverageSources.get(i).getSourceId() == id) {\n\t\t\t\tindex=i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (index < 0) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tcovData = this.coverageSources.remove(index);\n\t\t\n\t\tif (this.activeCoverage == covData) {\n\t\t\tthis.activeCoverage.clearPaint();\n\t\t\tthis.activeCoverage=null;\n\t\t}\n\t\t\n\t\tcovData.closeNothrow();\n\t\t\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic CoverageData getActiveCoverage() {\n\t\treturn this.activeCoverage;\n\t}\n\t\n\tpublic String getActiveCoverageName() {\n\t\treturn \"\";\n\t}\n\t\n\tpublic boolean setActiveCoverage(int id) {\n\t\tCoverageData cov = getCoverage(id);\n\t\t\n\t\treturn setActiveCoverage(cov);\n\t}\n\t\n\tpublic boolean setActiveCoverage(CoverageData coverage) {\n\t\tint oldMode=-1;\n\t\t\n\t\tif (this.activeCoverage != null) {\n\t\t\tthis.activeCoverage.clearPaint();\n\t\t\t\n\t\t\tif (this.activeCoverage.isLogicalCoverageData())\n\t\t\t\tthis.activeCoverage.closeNothrow();\n\t\t}\n\t\t\n\t\tthis.activeCoverage = coverage;\n\t\t\n\t\tif (coverage != null) {\n\t\t\tif (this.activeCoverage.isLogicalCoverageData())\n\t\t\t\toldMode = this.painter.setMode(Painter.PAINT_MODE_INTERSECTION);\n\t\t\t\n\t\t\tthis.activeCoverage.paint(this.painter);\n\t\t\t\n\t\t\tif (oldMode > -1)\n\t\t\t\tthis.painter.setMode(oldMode);\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic boolean isActiveCoverage(CoverageData coverage) {\n\t\treturn this.activeCoverage == coverage;\n\t}\n\t\n\tpublic void setPainter(Painter painter) {\n\t\tthis.painter = painter;\n\t}\n\t\n\tpublic String getName() {\n\t\treturn this.sessionName;\n\t}\n\t\n\tpublic CoverageData tryGetPreviouslyLoadedCoverage(String fileName) {\n\t\tfor (CoverageData cov : this.coverageSources) {\n\t\t\tif (!cov.isLogicalCoverageData() && cov.getSourceFilePath().equals(fileName))\n\t\t\t\treturn cov;\n\t\t}\n\t\t\n\t\treturn null;\n\t}\n\t\n\tpublic CoverageData getCoverageByName(String name) {\n\t\tfor (CoverageData cov : this.coverageSources) {\n\t\t\tif (cov.getName().equals(name)) {\n\t\t\t\treturn cov;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn null;\n\t}\n\t\n\tpublic void close() throws Exception {\n\t\t\n\t\tSessionManager.deregisterSession(this);\n\t\t\n\t\tfor (CoverageData cd : this.coverageSources) {\n\t\t\tcd.close();\n\t\t}\n\t\t\n\t\tthis.coverageSources.clear();\n\t}\n}\n\n<file_path>src/main/java/dragondance/datasource/CoverageData.java\npackage dragondance.datasource;\n\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.List;\n\nimport dragondance.Globals;\nimport dragondance.Log;\nimport dragondance.eng.CodeRange;\nimport dragondance.eng.DragonHelper;\nimport dragondance.eng.InstructionInfo;\nimport dragondance.eng.Painter;\nimport dragondance.eng.session.Session;\nimport dragondance.eng.session.SessionManager;\nimport dragondance.exceptions.InvalidInstructionAddress;\nimport dragondance.exceptions.OperationAbortedException;\n\nclass CodeRangeComparator implements Comparator<CodeRange> {\n\n\t@Override\n\tpublic int compare(CodeRange o1, CodeRange o2) {\n\t\treturn (int)(o1.getRangeStart() - o2.getRangeStart());\n\t}\n\t\n}\n\npublic class CoverageData implements AutoCloseable {\n\tprivate static CodeRangeComparator rangeListComparator = new CodeRangeComparator();\n\t\n\tprivate List<CodeRange> rangeList = null;\n\tprivate HashMap<Long,List<InstructionInfo>> addressMap = null;\n\t\n\tprivate CoverageDataSource source = null;\n\tprivate int maxDensity=0;\n\t\n\tprivate int initialRangeCount=0;\n\tprivate int mergedRangeCount=0;\n\t\n\tprivate boolean visualized=false;\n\tprivate boolean sorted=false;\n\tprivate boolean inClose=false;\n\t\n\tprivate Session ownerSession=null;\n\t\n\tpublic CoverageData(CoverageDataSource source) {\n\t\tthis.source = source;\n\t\tthis.addressMap = new HashMap<Long,List<InstructionInfo>>();\n\t\t\n\t\tthis.ownerSession = SessionManager.getActiveSession();\n\t}\n\t\n\tprivate static CoverageData newLogical() {\n\t\tCoverageData cov = new CoverageData(null);\n\t\tcov.rangeList = new ArrayList<CodeRange>();\n\t\t\n\t\treturn cov;\n\t}\n\t\n\tpublic static CoverageData intersect(CoverageData covData1, CoverageData covData2) {\n\t\t\n\t\tCodeRange lastRange = null;\n\t\tCoverageData isectResult = CoverageData.newLogical();\n\t\t\n\t\tfor (Long key : covData1.addressMap.keySet()) {\n\t\t\tif (covData2.addressMap.containsKey(key)) {\n\t\t\t\tInstructionInfo inst = covData1.lookupAddressMapSingle(key);\n\t\t\t\t\n\t\t\t\tlastRange = isectResult.pushRangeListNoThrow(lastRange,inst.getAddr(),inst.getSize(),false);\n\t\t\t\n\t\t\t}\n\t\t}\n\t\t\n\t\tisectResult.merge();\n\t\t\n\t\treturn isectResult;\n\t}\n\t\n\tpublic static CoverageData difference(CoverageData covData1, CoverageData covData2) {\n\t\tCodeRange lastRange = null;\n\t\tCoverageData diffResult;\n\t\tInstructionInfo inst;\n\t\t\n\t\tHashSet<Long> rightKeyset = new HashSet<Long>();\n\t\t\n\t\trightKeyset.addAll(covData2.addressMap.keySet());\n\t\t\n\t\tdiffResult = CoverageData.newLogical();\n\t\t\n\t\tfor (Long key : covData1.addressMap.keySet()) {\n\t\t\tif (!covData2.addressMap.containsKey(key)) {\n\t\t\t\tinst = covData1.lookupAddressMapSingle(key);\n\t\t\t\t\n\t\t\t\tlastRange = diffResult.pushRangeListNoThrow(lastRange, inst.getAddr(), inst.getSize(), false);\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tdiffResult.merge();\n\t\t\n\t\treturn diffResult;\n\t}\n\t\n\tpublic static CoverageData distinct(CoverageData covData1, CoverageData covData2) {\n\t\tCodeRange lastRange = null;\n\t\tCoverageData distinctResult;\n\t\tInstructionInfo inst;\n\t\t\n\t\tHashSet<Long> rightKeyset = new HashSet<Long>();\n\t\t\n\t\trightKeyset.addAll(covData2.addressMap.keySet());\n\t\t\n\t\tdistinctResult = CoverageData.newLogical();\n\t\t\n\t\tfor (Long key : covData1.addressMap.keySet()) {\n\t\t\t\n\t\t\tif (!covData2.addressMap.containsKey(key)) {\n\t\t\t\t\n\t\t\t\tinst = covData1.lookupAddressMapSingle(key);\n\t\t\t\t\n\t\t\t\tlastRange = distinctResult.pushRangeListNoThrow(lastRange, inst.getAddr(), inst.getSize(), false);\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t\trightKeyset.remove(key);\n\t\t\t\n\t\t}\n\t\t\n\t\tfor (Long key : rightKeyset) {\n\t\t\tinst = covData2.lookupAddressMapSingle(key);\n\t\t\tlastRange = distinctResult.pushRangeListNoThrow(lastRange, inst.getAddr(), inst.getSize(), false);\n\t\t}\n\t\t\n\t\tdistinctResult.merge();\n\t\t\n\t\treturn distinctResult;\n\t}\n\t\n\tpublic static CoverageData sum(CoverageData covData1, CoverageData covData2) {\n\t\tCoverageData sumResult = CoverageData.newLogical();\n\t\tCodeRange lastRange=null;\n\t\tInstructionInfo inst=null;\n\t\t\n\t\t\n\t\t\n\t\tfor (List<InstructionInfo> list : covData1.addressMap.values()) {\n\t\t\tinst = list.get(0);\n\t\t\t\n\t\t\tif (inst != null)\n\t\t\t\tlastRange = sumResult.pushRangeListNoThrow(lastRange, inst.getAddr(), inst.getSize(), false);\n\t\t}\n\t\t\n\t\t\n\t\tfor (List<InstructionInfo> list : covData2.addressMap.values()) {\n\t\t\tinst = list.get(0);\n\t\t\t\n\t\t\tif (inst != null)\n\t\t\t\tlastRange = sumResult.pushRangeListNoThrow(lastRange, inst.getAddr(), inst.getSize(), false);\n\t\t\t\n\t\t}\n\t\t\n\t\tsumResult.merge();\n\t\t\n\t\treturn sumResult;\n\t}\n\t\n\tpublic static CoverageData and(CoverageData ...covDataList) {\n\t\treturn intersect(covDataList);\n\t}\n\n\tpublic static CoverageData or(CoverageData ...covDataList) {\n\t\treturn sum(covDataList);\n\t}\n\t\n\tpublic static CoverageData xor(CoverageData ...covDataList) {\n\t\treturn distinct(covDataList);\n\t}\n\t\n\t\n\tpublic static CoverageData intersect(CoverageData ...covDataList) {\n\t\tCoverageData result;\n\t\t\n\t\tif (covDataList.length < 2)\n\t\t\treturn null;\n\t\t\n\t\tresult = intersect(covDataList[0],covDataList[1]);\n\t\t\n\t\tfor (int i=2;i<covDataList.length;i++) {\n\t\t\tresult = intersect(result,covDataList[i]);\n\t\t}\n\t\t\n\t\t\n\t\treturn result;\n\t}\n\t\n\tpublic static CoverageData difference(CoverageData ...covDataList) {\n\t\tCoverageData result;\n\t\t\n\t\tif (covDataList.length < 2)\n\t\t\treturn null;\n\t\t\n\t\tresult = difference(covDataList[0],covDataList[1]);\n\t\t\n\t\tfor (int i=2;i<covDataList.length;i++) {\n\t\t\tresult = difference(result,covDataList[i]);\n\t\t}\n\t\t\n\t\t\n\t\treturn result;\n\t}\n\t\n\tpublic static CoverageData sum(CoverageData ...covDataList) {\n\t\tCoverageData result;\n\t\t\n\t\tif (covDataList.length < 2)\n\t\t\treturn null;\n\t\t\n\t\tresult = sum(covDataList[0],covDataList[1]);\n\t\t\n\t\tfor (int i=2;i<covDataList.length;i++) {\n\t\t\tresult = sum(result,covDataList[i]);\n\t\t}\n\t\t\n\t\t\n\t\treturn result;\n\t}\n\t\n\tpublic static CoverageData distinct(CoverageData ...covDataList) {\n\t\tCoverageData result;\n\t\t\n\t\tif (covDataList.length < 2)\n\t\t\treturn null;\n\t\t\n\t\tresult = distinct(covDataList[0],covDataList[1]);\n\t\t\n\t\tfor (int i=2;i<covDataList.length;i++) {\n\t\t\tresult = distinct(result,covDataList[i]);\n\t\t}\n\t\t\n\t\t\n\t\treturn result;\n\t}\n\t\n\tprivate void merge() {\n\t\tCodeRange range;\n\t\t\n\t\tif (this.isLogicalCoverageData()) {\n\t\t\t//Merging operation only needed after raw coverage data read from the coverage file.\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tLog.info(\"rangeList: %d\", this.rangeList.size());\n\t\t\n\t\tfor (int i=0;i<this.rangeList.size();i++) {\n\t\t\tfor (int j=0;j<this.rangeList.size();j++) {\n\t\t\t\tif (i != j) {\n\t\t\t\t\tif (this.rangeList.get(i).mergeFrom(\n\t\t\t\t\t\t\tthis.rangeList.get(j) )) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tthis.mergedRangeCount++;\n\t\t\t\t\t\t\n\t\t\t\t\t\trange = this.rangeList.remove(j);\n\t\t\t\t\t\trange.unmapFromAddressMap();\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (i >= j)\n\t\t\t\t\t\t\ti--;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (j > 0)\n\t\t\t\t\t\t\tj--;\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprivate InstructionInfo lookupAddressMapSingle(long addrKey) {\n\t\t\n\t\tList<InstructionInfo> list = null;\n\t\t\n\t\tif (!this.addressMap.containsKey(addrKey))\n\t\t\treturn null;\n\t\t\n\t\tlist = this.addressMap.get(addrKey);\n\t\t\n\t\tif (list.size()>0)\n\t\t\treturn list.get(0);\n\t\t\n\t\treturn null;\n\t}\n\t\n\tprivate CodeRange pushRangeListNoThrow(CodeRange codeRange, long addr, int size, boolean isSequence) {\n\t\ttry {\n\t\t\treturn pushRangeList(codeRange, addr, size,isSequence);\n\t\t} catch (InvalidInstructionAddress | OperationAbortedException e) {\n\t\t\tLog.println(\"pushRangeList (%s)\", e.getMessage());\n\t\t}\n\t\t\n\t\treturn null;\n\t}\n\t\n\tprivate CodeRange pushRangeList(CodeRange codeRange, long addr, int size, boolean isSequence) throws InvalidInstructionAddress, OperationAbortedException {\n\t\tfinal boolean singleInstruction = !isSequence;\n\t\t\n\t\tif (this.rangeList.isEmpty()) {\n\t\t\tcodeRange = new CodeRange(this,addr,size,this.addressMap,singleInstruction);\n\t\t\tthis.rangeList.add(codeRange);\n\t\t}\n\t\telse {\n\t\t\tif (!codeRange.tryApply(addr, size,singleInstruction)) {\n\t\t\t\tcodeRange = new CodeRange(this, addr, size,this.addressMap, singleInstruction);\n\t\t\t\tthis.rangeList.add(codeRange);\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn codeRange;\n\t}\n\t\n\tprivate void buildRanges() throws InvalidInstructionAddress, OperationAbortedException {\n\t\tlong imgBase,addr;\n\t\tCodeRange codeRange = null;\n\t\t\n\t\tthis.rangeList = new ArrayList<CodeRange>();\n\t\t\n\t\timgBase = DragonHelper.getImageBase().getOffset();\n\t\t\n\t\tLog.info(\"Generating initial code ranges. Total block entry: %d\",source.entries.size());\n\t\t\n\t\tfor (BlockEntry be : source.entries) {\n\t\t\t\n\t\t\taddr = imgBase + be.getOffset();\n\t\t\tcodeRange = pushRangeList(codeRange, addr,be.getSize(),true);\n\t\t}\n\t\t\n\t\tthis.initialRangeCount = this.rangeList.size();\n\t\t\n\t\tLog.info(\"%d ranges generated.\", this.rangeList.size());\n\t\tLog.info(\"trying to merge ranges\");\n\t\t\n\t\tmerge();\n\t\t\n\t\tLog.info(\"final code range size: %d, %d range merged\", this.rangeList.size(),this.mergedRangeCount);\n\t\t\n\t}\n\t\n\tpublic boolean build() throws InvalidInstructionAddress, OperationAbortedException {\n\t\t\n\t\tif (this.rangeList != null)\n\t\t\treturn true;\n\t\t\n\t\tif (this.source == null)\n\t\t\treturn false;\n\t\t\n\t\tif (!this.source.isProcessed())\n\t\t\treturn false;\n\t\t\n\t\tthis.buildRanges();\n\t\t\n\t\tif (Globals.DumpInstructions) {\n\t\t\tboolean pv,pd;\n\t\t\tpv = Log.enableVerbose(true);\n\t\t\tpd = Log.enableDebug(true);\n\t\t\tthis.dump();\n\t\t\tthis.dumpHashMap();\n\t\t\tLog.enableVerbose(pv);\n\t\t\tLog.enableDebug(pd);\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic void dump() {\n\t\tfor (CodeRange range : this.rangeList) {\n\t\t\trange.dumpInstructionDensityList();\n\t\t}\n\t}\n\t\n\tpublic void dumpHashMap() {\n\t\tList<InstructionInfo> listValue;\n\t\t\n\t\tfor (Long key : this.addressMap.keySet())\n\t\t{\n\t\t\tlistValue = this.addressMap.get(key);\n\t\t\t\n\t\t\tLog.debug(\"Key: %x | \",key);\n\t\t\tLog.debug(\"Value(s): \");\n\t\t\t\n\t\t\tfor (InstructionInfo ii : listValue) {\n\t\t\t\tif (ii.getOwnerCodeRange().getContainerCoverage() == this) {\n\t\t\t\t\tLog.debug(\"%x (density: %d),\" , ii.hashCode(), ii.getDensity());\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tLog.println(\"\");\n\t\t}\n\t}\n\t\n\tpublic void paint(Painter painter) {\n\t\t\n\t\tif (this.visualized)\n\t\t\treturn;\n\t\t\n\t\tboolean failed=false;\n\t\t\n\t\tint transId = DragonHelper.startTransaction(\"BgPaint\");\n\t\t\n\t\tfor (CodeRange range : this.rangeList) {\n\t\t\tif (!range.paintRange(painter)) {\n\t\t\t\tfailed=true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tDragonHelper.finishTransaction(transId,!failed);\n\t\t\n\t\tif (!failed)\n\t\t\tthis.visualized=true;\n\t}\n\t\n\tpublic void clearPaint() {\n\t\t\n\t\tif (!this.visualized)\n\t\t\treturn;\n\t\t\n\t\tint transId = DragonHelper.startTransaction(\"ClearBgPaint\");\n\t\t\n\t\tfor (CodeRange range : this.rangeList) {\n\t\t\trange.clearPaint();\n\t\t}\n\t\t\n\t\tDragonHelper.finishTransaction(transId, true);\n\t\t\n\t\tthis.visualized=false;\n\t}\n\t\n\tpublic CoverageDataSource getSource() {\n\t\treturn this.source;\n\t}\n\t\n\tpublic int getSourceId() {\n\t\t\n\t\tif (this.source==null)\n\t\t\treturn 0;\n\t\t\n\t\treturn this.source.getId();\n\t}\n\t\n\tpublic void setMaxDensity(int density) {\n\t\tif (density > this.maxDensity) {\n\t\t\tLog.debug(\"new max density: %d\", density);\n\t\t\tthis.maxDensity = density;\n\t\t}\n\t}\n\t\n\tpublic final int getMaxDensity() {\n\t\treturn this.maxDensity;\n\t}\n\n\t@Override\n\tpublic void close() throws Exception {\n\t\t\n\t\tif (this.inClose)\n\t\t\treturn;\n\t\t\n\t\tthis.inClose = true;\n\t\t\n\t\tif (this.ownerSession.isActiveCoverage(this)) {\n\t\t\tthis.ownerSession.setActiveCoverage(null);\n\t\t}\n\t\t\n\t\tthis.clearPaint();\n\t\t\n\t\tif (this.rangeList != null)\n\t\t\tthis.rangeList.clear();\n\t\t\n\t\tif (this.addressMap != null)\n\t\t\tthis.addressMap.clear();\n\t\t\n\t\tif (!isLogicalCoverageData())\n\t\t\tthis.source.close();\n\t\t\n\t\tthis.ownerSession=null;\n\t\t\n\t\tthis.inClose = false;\n\t\t\n\t}\n\t\n\tpublic void closeNothrow() {\n\t\ttry {\n\t\t\tclose();\n\t\t} catch (Exception e) {\n\t\t}\n\t}\n\t\n\tpublic final int getRangeCount() {\n\t\t\n\t\tif (this.rangeList==null)\n\t\t\treturn 0;\n\t\t\n\t\treturn this.rangeList.size();\n\t}\n\t\n\tpublic final int getInitialRangeCount() {\n\t\treturn this.initialRangeCount;\n\t}\n\t\n\tpublic final int getMergedRangeCount() {\n\t\treturn this.mergedRangeCount;\n\t}\n\t\n\tpublic void sort() {\n\t\tif (!this.sorted) {\n\t\t\tthis.rangeList.sort(rangeListComparator);\n\t\t\tthis.sorted=true;\n\t\t}\n\t}\n\t\n\tpublic final String getName() {\n\t\tif (this.source == null) {\n\t\t\treturn \"\";\n\t\t}\n\t\t\n\t\treturn this.source.getName();\n\t}\n\t\n\tpublic final String getSourceFilePath() {\n\t\tif (this.source == null) {\n\t\t\treturn \"\";\n\t\t}\n\t\t\n\t\treturn this.source.getFilePath();\n\t}\n\t\n\tpublic final boolean isLogicalCoverageData() {\n\t\treturn this.source == null;\n\t}\n}\n\n<file_path>src/main/java/dragondance/eng/CodeRange.java\npackage dragondance.eng;\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\n\nimport dragondance.Globals;\nimport dragondance.Log;\nimport dragondance.datasource.CoverageData;\nimport dragondance.exceptions.InvalidInstructionAddress;\nimport dragondance.exceptions.OperationAbortedException;\n\npublic class CodeRange implements AutoCloseable {\n\t\n\tprivate static int gs_RangeIndex=1;\n\t\n\tprivate long rangeStart,rangeEnd,rangeSize;\n\t\n\tprivate long avgInstSize=0;\n\tprivate long totalInstSize=0;\n\tprivate List<InstructionInfo> densityList;\n\tprivate HashMap<Long, List<InstructionInfo>> map;\n\t\n\tprivate String name;\n\tprivate CoverageData container;\n\t\n\tprivate class IntersectionBound\n\t{\n\t\tpublic long begin,end;\n\t\t\n\t\tpublic final boolean areEqual() {\n\t\t\treturn begin==end;\n\t\t}\n\t}\n\t\n\tpublic CodeRange(CoverageData container, long start, int size, HashMap<Long, List<InstructionInfo>> addressMap, boolean singleInstruction) throws InvalidInstructionAddress, OperationAbortedException {\n\t\tthis.rangeStart = start;\n\t\tthis.rangeEnd = start + size;\n\t\tthis.rangeSize = size;\n\t\tthis.container = container;\n\t\tthis.map = addressMap;\n\t\t\n\t\tthis.densityList = new ArrayList<InstructionInfo>();\n\t\t\n\t\tthis.name = \"Range \" + String.valueOf(gs_RangeIndex);\n\t\t\n\t\tCodeRange.gs_RangeIndex++;\n\t\t\n\t\tthis.add(start, size,singleInstruction);\n\t}\n\t\n\tpublic CodeRange(CoverageData container, long start, int size, boolean singleInstruction) throws InvalidInstructionAddress, OperationAbortedException {\n\t\tthis(container,start,size,null,singleInstruction);\n\t}\n\t\n\tpublic CodeRange(CoverageData container, long start, int size) throws InvalidInstructionAddress, OperationAbortedException {\n\t\tthis(container,start,size,false);\n\t}\n\t\n\tprivate void printRangeInfo() {\n\t\tLog.debug(\"Range start: %p, Range end: %p, size: %d\",\n\t\t\t\tthis.rangeStart,this.rangeEnd,this.rangeSize);\n\t\t\n\t}\n\t\n\tpublic void dumpInstructionDensityList() {\n\t\tfor (InstructionInfo ii : this.densityList)\n\t\t{\n\t\t\tLog.verbose(\"addr: %p, size: %d, density: %d\", ii.getAddr(),ii.getSize(),ii.getDensity());\n\t\t}\n\t}\n\t\n\tprivate boolean copyList(List<InstructionInfo> dest, CodeRange destRange, List<InstructionInfo> src, int destCopyIndex, int srcCopyIndex, int size) {\n\t\t\n\t\tint dindex = destCopyIndex < 0 ? dest.size() : destCopyIndex;\n\t\tint sindex = srcCopyIndex < 0 ? src.size() : srcCopyIndex;\n\t\t\n\t\tif (dindex > dest.size())\n\t\t\tdindex = dest.size();\n\t\t\n\t\tif (sindex + size > src.size())\n\t\t\treturn false;\n\t\t\n\t\t\n\t\twhile (size-- > 0)\n\t\t{\n\t\t\tInstructionInfo inst = InstructionInfo.cloneFor(src.get(sindex), destRange);\n\t\t\t\n\t\t\tdest.add(dindex, inst);\n\t\t\tthis.putMapIfAvailable(inst);\n\t\t\t\n\t\t\tdindex++;\n\t\t\tsindex++;\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tprivate final boolean isInRange(long addr) {\n\t\treturn addr >= this.rangeStart && addr <= this.rangeEnd;\n\t}\n\t\n\tprivate IntersectionBound getIntersectionBound(CodeRange source) {\n\t\t\n\t\tIntersectionBound isectBound=new IntersectionBound();\n\t\t\n\t\tisectBound.begin = source.rangeStart > this.rangeStart ? \n\t\t\t\tsource.rangeStart : this.rangeStart;\n\t\t\n\t\tisectBound.end = source.rangeEnd < this.rangeEnd ?\n\t\t\t\tsource.rangeEnd : this.rangeEnd;\n\t\t\n\t\treturn isectBound;\n\t}\n\t\n\tprivate void updateAvgInstSize(int size) {\n\t\tthis.totalInstSize += size;\n\t\tthis.avgInstSize = this.totalInstSize / this.densityList.size();\n\t}\n\t\n\tprivate int getInstructionSize(long addr) throws InvalidInstructionAddress, OperationAbortedException {\n\t\tInstructionContext ictx = null;\n\t\t\n\t\tif (Globals.WithoutGhidra)\n\t\t\treturn 4;\n\t\t\n\t\tictx = DragonHelper.getInstruction(addr,true);\n\t\t\n\t\tif (ictx == null) {\n\t\t\tthrow new OperationAbortedException(String.format(\"There is no valid instruction at %x\",addr));\n\t\t}\n\t\t\n\t\treturn ictx.getSize();\n\t}\n\t\n\tprivate int getIndexFromAddr(long addr) {\n\t\t\n\t\tInstructionInfo instInfo;\n\t\t\n\t\tint stepLimit=15,ri;\n\t\t\n\t\tif (!isInRange(addr))\n\t\t\treturn -1;\n\t\t\n\t\tif (this.densityList.isEmpty())\n\t\t\treturn -1;\n\t\t\n\t\tassert(this.avgInstSize != 0);\n\t\t\n\t\t//guess the index. most of the time our guess will hit for first time\n\t\tri = (int)((addr - this.rangeStart) / this.avgInstSize);\n\t\t\n\t\t//reduce the guess if its out of the list\n\t\tif (ri >= this.densityList.size())\n\t\t\tri = this.densityList.size()/2;\n\t\t\n\t\tinstInfo = this.densityList.get(ri);\n\t\t\n\t\t//test addresses \n\t\tif (instInfo.getAddr() == addr)\n\t\t\treturn ri;\n\t\t\n\t\tif (instInfo.getAddr() > addr)\n\t\t{\n\t\t\t/*\n\t\t\t * Guessed address of the index greater than we looking for\n\t\t\t * So we have step back few times.\n\t\t\t * (That would not be nothing more than 15 times. \n\t\t\t * cuz of the x86's maximum instruction size)\n\t\t\t * \n\t\t\t * That would not be issue on the RISC instruction sets.\n\t\t\t */\n\t\t\t\n\t\t\twhile (ri > 0 && stepLimit > 0)\n\t\t\t{\n\t\t\t\tri--;\n\t\t\t\t\n\t\t\t\tinstInfo = this.densityList.get(ri);\n\t\t\t\t\n\t\t\t\tif (instInfo.getAddr() == addr)\n\t\t\t\t\treturn ri;\n\t\t\t\t\n\t\t\t\tstepLimit--;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t//in this case we have step forward\n\t\t\t\n\t\t\twhile (ri != this.densityList.size()-1 && stepLimit > 0)\n\t\t\t{\n\t\t\t\tri++;\n\t\t\t\t\n\t\t\t\tinstInfo = this.densityList.get(ri);\n\t\t\t\t\n\t\t\t\tif (instInfo.getAddr() == addr)\n\t\t\t\t\treturn ri;\n\t\t\t\t\n\t\t\t\tstepLimit--;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn -1;\n\t}\n\t\n\tprivate boolean incrementRangeDensity(long addr, int size) {\n\t\tint ri = getIndexFromAddr(addr);\n\t\t\n\t\tif (ri == -1)\n\t\t\treturn false;\n\t\t\n\t\twhile (size > 0)\n\t\t{\n\t\t\tInstructionInfo ictx = this.densityList.get(ri);\n\t\t\t\n\t\t\tictx.incrementDensity();\n\t\t\tsize -= ictx.getSize();\n\t\t\t\n\t\t\tri++;\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tprivate boolean mergeFromInternal(CodeRange source) {\n\t\t\n\t\tint ri,sri,tmp;\n\t\t\n\t\tIntersectionBound ibound = getIntersectionBound(source);\n\t\t\n\t\tLog.debug(\"--------src range--------\");\n\t\tsource.printRangeInfo();\n\t\tLog.debug(\"--------self range--------\");\n\t\tthis.printRangeInfo();\n\t\t\n\t\tLog.debug(\"intersection start: %p, end: %p\",ibound.begin,ibound.end);\n\t\t\n\t\tif (ibound.areEqual())\n\t\t{\n\t\t\tLog.verbose(\"intersection points are same\");\n\t\t}\n\t\t\n\t\t//make sure the intersection start point is valid for the source range\n\t\tri = source.getIndexFromAddr(ibound.begin);\n\t\t\n\t\tif (ri == -1)\n\t\t{\n\t\t\tif (ibound.areEqual())\n\t\t\t\tri = source.densityList.size();\n\t\t\telse\n\t\t\t\treturn false; //no they are not really intersected.\n\t\t}\n\t\t\n\t\ttmp = ri;\n\t\t\n\t\tsri = this.getIndexFromAddr(ibound.begin);\n\t\t\n\t\tif (sri == -1)\n\t\t{\n\t\t\tif (!ibound.areEqual())\n\t\t\t\treturn false; // they are not really intersected either.\n\t\t}\n\t\t\n\t\tif (!ibound.areEqual())\n\t\t{\n\t\t\t//merge intersected range densities first.\n\t\t\t\n\t\t\tassert(this.densityList.get(sri).getAddr() == ibound.begin);\n\t\t\t\n\t\t\twhile (sri != this.densityList.size() &&\n\t\t\t\t\tthis.densityList.get(sri).getAddr() < ibound.end)\n\t\t\t{\n\t\t\t\tthis.densityList.get(sri).incrementDensityBy(\n\t\t\t\t\t\tsource.densityList.get(ri).getDensity());\n\t\t\t\t\n\t\t\t\tsri++;\n\t\t\t\tri++;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t//intersection areas are same. there is no item to merge\n\t\t}\n\t\t\n\t\t//prepend lower address range part if exists\n\t\tif (source.rangeStart < this.rangeStart)\n\t\t{\n\t\t\tri = tmp;\n\t\t\tcopyList(this.densityList,this, source.densityList,0,0,ri);\n\t\t\t\n\t\t\ttmp = (int)this.rangeSize;\n\t\t\t\n\t\t\tthis.rangeStart = source.rangeStart;\n\t\t\tthis.rangeSize = this.rangeEnd - this.rangeStart;\n\t\t\t\n\t\t\ttmp = (int)this.rangeSize - tmp;\n\t\t\t\n\t\t\tupdateAvgInstSize(tmp);\n\t\t\t\n\t\t}\n\t\t\n\t\t//append higher address range part if exists\n\t\tif (source.rangeEnd > this.rangeEnd)\n\t\t{\n\t\t\tsri = source.getIndexFromAddr(ibound.end);\n\t\t\tcopyList(this.densityList,this, source.densityList,-1,sri,source.densityList.size()-sri);\n\t\t\ttmp = (int)this.rangeSize;\n\t\t\t\n\t\t\tthis.rangeEnd = source.rangeEnd;\n\t\t\tthis.rangeSize = this.rangeEnd - this.rangeStart;\n\t\t\t\n\t\t\ttmp = (int)this.rangeSize - tmp;\n\t\t\tupdateAvgInstSize(tmp);\n\t\t}\n\t\t\n\t\tLog.debug(\"new range info\");\n\t\tthis.printRangeInfo();\n\t\t\n\t\treturn true;\n\t}\n\t\n\tprivate void putMapIfAvailable(InstructionInfo inst) {\n\t\tList<InstructionInfo> instList;\n\t\t\n\t\tif (this.map == null)\n\t\t\treturn;\n\t\t\n\t\tif (this.map.containsKey(inst.getAddr())) {\n\t\t\tinstList = this.map.get(inst.getAddr());\n\t\t\t\n\t\t\tif (!instList.contains(inst)) {\n\t\t\t\tinstList.add(inst);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tLog.warning(\"%p already exists\",inst.getAddr());\n\t\t\t}\n\t\t\t\n\t\t}\n\t\telse {\n\t\t\tinstList = new ArrayList<InstructionInfo>();\n\t\t\tinstList.add(inst);\n\t\t\t\n\t\t\tthis.map.put(inst.getAddr(), instList);\n\t\t}\n\t}\n\t\n\tprivate void removeMapIfAvailable(InstructionInfo inst) {\n\t\tList<InstructionInfo> instList;\n\t\t\n\t\tif (this.map == null)\n\t\t\treturn;\n\t\t\n\t\tLog.debug(\"Removing for inst: %x\", inst.getAddr());\n\t\t\n\t\tif (this.map.containsKey(inst.getAddr())) {\n\t\t\tinstList = this.map.get(inst.getAddr());\n\t\t\t\n\t\t\tfor (int i=0;i<instList.size();i++) {\n\t\t\t\tif (instList.get(i).getOwnerCodeRange() == this) {\n\t\t\t\t\tinstList.remove(i);\n\t\t\t\t\ti--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprivate boolean add(long start, int size, boolean singleInstruction) throws InvalidInstructionAddress, OperationAbortedException {\n\t\tInstructionInfo instCtx;\n\t\tint insSize=0;\n\t\tlong addr = start;\n\t\tlong eaddr = addr + size;\n\t\t\n\t\twhile (addr < eaddr)\n\t\t{\n\t\t\tif (singleInstruction)\n\t\t\t\tinsSize = size;\n\t\t\telse\n\t\t\t\tinsSize = getInstructionSize(addr);\n\t\t\t\n\t\t\tif (insSize == 0) {\n\t\t\t\t//TODO: maybe raise an abort event?\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tif (addr == start && size < insSize)\n\t\t\t\treturn false;\n\t\t\t\n\t\t\tinstCtx = new InstructionInfo(this, addr,insSize,1);\n\t\t\t\n\t\t\taddr += insSize;\n\t\t\t\n\t\t\tthis.densityList.add(instCtx);\n\t\t\t\n\t\t\tthis.putMapIfAvailable(instCtx);\n\t\t\tupdateAvgInstSize(insSize);\n\t\t\t\n\t\t}\n\t\t\n\t\tthis.rangeEnd = addr;\n\t\tthis.rangeSize = this.rangeEnd - this.rangeStart;\n\t\t\n\t\t//fix end if neccessary due to instruction size\n\t\t\n\t\tif (addr > eaddr)\n\t\t{\n\t\t\t/*\n\t\t\t * #hmm. the last instruction has overflowed the expected range size\n\t\t\t * so the last instruction must be discarded from the list.\n\t\t\t * this is violates our strict range bound\n\t\t\t */\n\t\t\t\n\t\t\tInstructionInfo lastInst;\n\t\t\t\n\t\t\tlastInst = this.densityList.remove(this.densityList.size()-1);\n\t\t\tthis.removeMapIfAvailable(lastInst);\n\t\t\t\n\t\t\tthis.rangeEnd -= lastInst.getSize();\n\t\t\tthis.rangeSize = this.rangeEnd - this.rangeStart;\n\t\t\t\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tprivate boolean tryApplyOverlappedFromHead(long addr, int size) throws InvalidInstructionAddress, OperationAbortedException {\n\t\tList<InstructionInfo> headPartList = new ArrayList<InstructionInfo>();\n\t\tInstructionInfo inst;\n\t\t\n\t\tint instSize=0;\n\t\tlong currAddr = addr;\n\t\t\n\t\twhile (true)\n\t\t{\n\t\t\tinstSize = getInstructionSize(currAddr);\n\t\t\t\n\t\t\tif (instSize == 0)\n\t\t\t{\n\t\t\t\theadPartList.clear();\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tinst = new InstructionInfo(this,currAddr,instSize,1);\n\t\t\t\n\t\t\theadPartList.add(inst);\n\t\t\t\n\t\t\tcurrAddr += instSize;\n\t\t\t\n\t\t\t//stop if we are at the this range's start point\n\t\t\tif (currAddr == this.rangeStart)\n\t\t\t\tbreak;\n\t\t\telse if (currAddr > this.rangeEnd)\n\t\t\t{\n\t\t\t\t//hmm we are working on wrong place. so cancel operation\n\t\t\t\theadPartList.clear();\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\t\n\t\t//prepend head part to the current density list\n\t\t\n\t\tint nx=0;\n\t\t\n\t\tfor (InstructionInfo ii : headPartList) {\n\t\t\tthis.putMapIfAvailable(ii);\n\t\t\tthis.densityList.add(nx++, ii);\n\t\t}\n\t\t\n\t\t//this.densityList.addAll(0, headPartList);\n\t\theadPartList.clear();\n\t\t\n\t\tLog.debug(\"old range (start: %p, size: %d)\", this.rangeStart,this.rangeSize);\n\t\t\n\t\t//set new range bound\n\t\t\n\t\tthis.rangeStart = addr;\n\t\tthis.rangeSize = this.rangeEnd - this.rangeStart;\n\t\t\n\t\tLog.debug(\"new range (start: %p, size: %d)\", this.rangeStart,this.rangeSize);\n\t\t\n\t\t\n\t\tint remainSize = size - (int)(currAddr - addr);\n\t\t\n\t\tif (remainSize > 0)\n\t\t{\n\t\t\t//just increase the density of the intersected part.\n\t\t\tincrementRangeDensity(currAddr, remainSize);\n\t\t\t//TODO: beware its status\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic boolean tryApply(long addr, int size, boolean singleInstruction) throws InvalidInstructionAddress, OperationAbortedException {\n\t\t\n\t\tif (!isInRange(addr))\n\t\t{\n\t\t\tif (isInRange(addr+size))\n\t\t\t{\n\t\t\t\treturn tryApplyOverlappedFromHead(addr,size);\n\t\t\t}\n\t\t\t\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\t\n\t\tif (addr + size > this.rangeEnd)\n\t\t{\n\t\t\t//addr + size goes out of the range. but is the starting address\n\t\t\t//mapped in the range?\n\t\t\tint ri = getIndexFromAddr(addr);\n\t\t\t\n\t\t\tif (ri == -1) // the address wasn't mapped in the range.\n\t\t\t{\n\t\t\t\t//so is it at range's upper bound?\n\t\t\t\tif (this.rangeEnd == addr)\n\t\t\t\t{\n\t\t\t\t\t//yep. we can append the block\n\t\t\t\t\treturn add(addr, size, singleInstruction);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t//otherwise the address is completely invalid.\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\t//ok. first we have to increment density of the intersected range part\n\t\t\tincrementRangeDensity(addr,(int)(this.rangeEnd-addr));\n\t\t\t\n\t\t\t//then append remaining part\n\t\t\tint excess = (int)((addr + size) - this.rangeEnd);\n\t\t\t\n\t\t\tLog.verbose(\"%d bytes exceeded. expanding range\",excess);\n\t\t\t\n\t\t\tadd(this.rangeEnd,excess,singleInstruction);\n\t\t}\n\t\telse //otherwise its completely overlapped.\n\t\t\tincrementRangeDensity(addr,size);\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic boolean tryApply(long addr, int size) throws InvalidInstructionAddress, OperationAbortedException {\n\t\treturn tryApply(addr,size,false);\n\t}\n\t\n\tpublic boolean tryPutInstruction(long instAddr, int size) throws InvalidInstructionAddress, OperationAbortedException {\n\t\treturn tryApply(instAddr,size,true);\n\t}\n\t\n\tpublic boolean mergeFrom(CodeRange sourceRange) {\n\t\t\n\t\tboolean canBeMerge=false;\n\t\t\n\t\tif (sourceRange.rangeStart <= this.rangeStart &&\n\t\t\t\tsourceRange.rangeEnd >= this.rangeStart)\n\t\t{\n\t\t\tcanBeMerge=true;\n\t\t}\n\t\telse if (sourceRange.rangeStart >= this.rangeStart &&\n\t\t\t\tsourceRange.rangeStart <= this.rangeEnd)\n\t\t{\n\t\t\tcanBeMerge=true;\n\t\t}\n\t\t\n\t\tif (canBeMerge != intersectable(sourceRange)) {\n\t\t\tLog.info(\"WARNING! canBeMerge=%s, intersectable=%s\", \n\t\t\t\t\tBoolean.toString(canBeMerge), Boolean.toString(intersectable(sourceRange)));\n\t\t}\n\t\t\n\t\tif (canBeMerge)\n\t\t\treturn mergeFromInternal(sourceRange);\n\t\t\n\t\t\n\t\treturn false;\n\t}\n\t\n\t\n\tpublic boolean intersectable(CodeRange range) {\n\t\tif (this.rangeEnd < range.rangeStart) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tif (this.rangeStart > range.rangeEnd) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic void unmapFromAddressMap() {\n\t\t\n\t\tfor (InstructionInfo ii : this.densityList) {\n\t\t\tthis.removeMapIfAvailable(ii);\n\t\t}\n\t}\n\t\n\tpublic boolean paintRange(Painter painter) {\n\t\t\n\t\tfor (InstructionInfo inst : this.densityList) {\n\t\t\t\n\t\t\tif (!painter.paint(inst))\n\t\t\t\treturn false;\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic void clearPaint() {\n\t\tfor (InstructionInfo inst : this.densityList) {\n\t\t\tDragonHelper.clearInstructionBackgroundColor(inst.getAddr());\n\t\t}\n\t}\n\t\n\tpublic void setName(String rangeName) {\n\t\tthis.name = rangeName;\n\t}\n\t\n\tpublic final long getRangeStart() {\n\t\treturn this.rangeStart;\n\t}\n\t\n\tpublic final int getRangeSize() {\n\t\treturn (int)this.rangeSize;\n\t}\n\t\n\tpublic final String getName() {\n\t\treturn this.name;\n\t}\n\t\n\tpublic CoverageData getContainerCoverage() {\n\t\treturn this.container;\n\t}\n\n\t@Override\n\tpublic void close() throws Exception {\n\t\tthis.densityList.clear();\n\t}\n\t\n\t@Override\n\tpublic String toString() {\n\t\treturn String.format(\"(Start: %x, End: %x, Size: %d)\", this.rangeStart, this.rangeEnd, this.rangeSize);\n\t}\n\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/BuiltinFunctionBase.java\npackage dragondance.scripting.functions;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport dragondance.Log;\nimport dragondance.components.GuiAffectedOpInterface;\nimport dragondance.datasource.CoverageData;\n\npublic abstract class BuiltinFunctionBase {\n\tprivate String name;\n\tprivate List<String> aliases;\n\t\n\tprivate List<BuiltinArg> args;\n\tprivate CoverageData retVal;\n\t\n\tprotected GuiAffectedOpInterface guiSvc;\n\t\n\tpublic BuiltinFunctionBase(String name) {\n\t\tthis.name = name;\n\t\tthis.args = new ArrayList<BuiltinArg>();\n\t}\n\t\n\tpublic void putArg(BuiltinArg arg1, BuiltinArg arg2) {\n\t\tthis.args.add(arg1);\n\t\tthis.args.add(arg2);\n\t}\n\t\n\tpublic void putArg(BuiltinArg ...fargs) {\n\t\tfor (BuiltinArg arg : fargs)\n\t\t\tthis.args.add(arg);\n\t}\n\t\n\tpublic CoverageData getReturn() {\n\t\treturn this.retVal;\n\t}\n\t\n\tpublic int argCount() {\n\t\treturn this.args.size();\n\t}\n\t\n\tprotected void addAlias(String alias) {\n\t\tif (this.aliases == null)\n\t\t\tthis.aliases = new ArrayList<String>();\n\t\t\n\t\tthis.aliases.add(alias);\n\t}\n\t\n\tprotected void setReturn(CoverageData cov) {\n\t\tthis.retVal = cov;\n\t}\n\t\n\tprotected CoverageData[] prepareFinalArguments() {\n\t\tCoverageData[] covArgs = new CoverageData[this.args.size()];\n\t\tint index=0;\n\t\t\n\t\tfor (BuiltinArg arg : this.args) {\n\t\t\tif (arg.isBuiltinCall()) {\n\t\t\t\tcovArgs[index++] = arg.getAsFunction().execute();\n\t\t\t}\n\t\t\telse if (arg.isVariable()) {\n\t\t\t\tcovArgs[index++] = arg.getAsVariable().getValue();\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn covArgs;\n\t}\n\t\n\tprotected Object[] prepareArguments() {\n\t\tObject[] sargs = new Object[this.args.size()];\n\t\tint index=0;\n\t\t\n\t\tfor (BuiltinArg arg : this.args) {\n\t\t\tif (arg.isBuiltinCall()) {\n\t\t\t\tsargs[index++] = arg.getAsFunction().execute();\n\t\t\t}\n\t\t\telse if (arg.isVariable()) {\n\t\t\t\tsargs[index++] = arg.getAsVariable();\n\t\t\t}\n\t\t\telse if (arg.isInteger()) {\n\t\t\t\tsargs[index++] = arg.getAsLong();\n\t\t\t}\n\t\t\telse\n\t\t\t\tsargs[index++] =arg.getAsString();\n\t\t\t\n\t\t}\n\t\t\n\t\treturn sargs;\n\t}\n\t\n\tprotected String[] getStringArguments() {\n\t\tString[] strArgs = new String[this.args.size()];\n\t\tint index=0;\n\t\t\n\t\tfor (BuiltinArg arg : this.args) {\n\t\t\tstrArgs[index++] = arg.getAsString();\n\t\t}\n\t\t\n\t\treturn strArgs;\n\t}\n\t\n\tpublic List<String> getAliases() {\n\t\treturn this.aliases;\n\t}\n\t\n\tpublic boolean hasAlias() {\n\t\treturn this.aliases != null;\n\t}\n\t\n\tpublic void setGuiApi(GuiAffectedOpInterface guiSvc) {\n\t\tthis.guiSvc = guiSvc;\n\t}\n\t\n\tpublic int requiredArgCount(boolean minimum) {\n\t\treturn 0;\n\t}\n\t\n\tpublic boolean hasReturnType() {\n\t\treturn true;\n\t}\n\t\n\tpublic CoverageData execute() {\n\t\tLog.debug(\"builtin \\\"%s\\\" executed\", this.name);\n\t\treturn this.retVal;\n\t}\n\t\n\tpublic void discard() {\n\t\tif (this.aliases != null)\n\t\t\tthis.aliases.clear();\n\t\t\n\t\tthis.args.clear();\n\t}\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/impl/BuiltinFunctionClear.java\npackage dragondance.scripting.functions.impl;\n\nimport dragondance.datasource.CoverageData;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\npublic class BuiltinFunctionClear extends BuiltinFunctionBase {\n\n\tpublic BuiltinFunctionClear() {\n\t\tsuper(\"clear\");\n\t}\n\t\n\t@Override\n\tpublic int requiredArgCount(boolean minimum) {\n\t\treturn 0;\n\t}\n\t\n\t@Override\n\tpublic boolean hasReturnType() {\n\t\treturn false;\n\t}\n\t\n\t@Override\n\tpublic CoverageData execute() {\n\t\tguiSvc.visualizeCoverage(null);\n\t\treturn super.execute();\n\t}\n\t\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/impl/BuiltinFunctionDiff.java\npackage dragondance.scripting.functions.impl;\n\nimport dragondance.datasource.CoverageData;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\n\npublic class BuiltinFunctionDiff extends BuiltinFunctionBase {\n\n\tpublic BuiltinFunctionDiff() {\n\t\tsuper(\"diff\");\n\t}\n\t\n\t@Override\n\tpublic int requiredArgCount(boolean minimum) {\n\t\tif (minimum)\n\t\t\treturn 2;\n\t\t\n\t\treturn -1;\n\t}\n\t\n\t@Override\n\tpublic CoverageData execute() {\n\t\tCoverageData[] finalArgs = prepareFinalArguments();\n\t\t\n\t\tsetReturn(CoverageData.difference(finalArgs));\n\t\t\n\t\treturn super.execute();\n\t}\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/impl/BuiltinFunctionDistinct.java\npackage dragondance.scripting.functions.impl;\n\nimport dragondance.datasource.CoverageData;\nimport dragondance.scripting.functions.BuiltinAlias;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\n@BuiltinAlias(aliases = {\"xor\"})\npublic class BuiltinFunctionDistinct extends BuiltinFunctionBase {\n\n\tpublic BuiltinFunctionDistinct() {\n\t\tsuper(\"distinct\");\n\t}\n\t\n\t@Override\n\tpublic int requiredArgCount(boolean minimum) {\n\t\tif (minimum)\n\t\t\treturn 2;\n\t\t\n\t\treturn -1;\n\t}\n\t\n\t@Override\n\tpublic CoverageData execute() {\n\t\tCoverageData[] finalArgs = prepareFinalArguments();\n\t\t\n\t\tsetReturn(CoverageData.distinct(finalArgs));\n\t\t\n\t\treturn super.execute();\n\t}\n\n\t\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/impl/BuiltinFunctionGoto.java\npackage dragondance.scripting.functions.impl;\n\nimport dragondance.datasource.CoverageData;\nimport dragondance.exceptions.DragonDanceScriptRuntimeException;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\npublic class BuiltinFunctionGoto extends BuiltinFunctionBase {\n\n\tpublic BuiltinFunctionGoto() {\n\t\tsuper(\"goto\");\n\t}\n\t\n\t@Override\n\tpublic int requiredArgCount(boolean minimum) {\n\t\treturn 1;\n\t}\n\t\n\t@Override\n\tpublic boolean hasReturnType() {\n\t\treturn false;\n\t}\n\t\n\t@Override\n\tpublic CoverageData execute() {\n\t\tObject arg = super.prepareArguments()[0];\n\t\t\n\t\tif (arg instanceof Long) {\n\t\t\tguiSvc.goTo(((Long)arg).longValue());\n\t\t}\n\t\telse\n\t\t\tthrow new DragonDanceScriptRuntimeException(\"invalid arg type for goto\");\n\t\t\n\t\treturn super.execute();\n\t}\n\t\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/impl/BuiltinFunctionIntersect.java\npackage dragondance.scripting.functions.impl;\n\nimport dragondance.datasource.CoverageData;\nimport dragondance.scripting.functions.BuiltinAlias;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\n@BuiltinAlias(aliases = {\"and\"})\npublic class BuiltinFunctionIntersect extends BuiltinFunctionBase {\n\n\tpublic BuiltinFunctionIntersect() {\n\t\tsuper(\"intersect\");\n\t}\n\t\n\t@Override\n\tpublic int requiredArgCount(boolean minimum) {\n\t\tif (minimum)\n\t\t\treturn 2;\n\t\t\n\t\treturn -1;\n\t}\n\t\n\t@Override\n\tpublic CoverageData execute() {\n\t\tCoverageData[] finalArgs = prepareFinalArguments();\n\t\t\n\t\tsetReturn(CoverageData.intersect(finalArgs));\n\t\t\n\t\treturn super.execute();\n\t}\n\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/impl/BuiltinFunctionShow.java\npackage dragondance.scripting.functions.impl;\n\nimport dragondance.datasource.CoverageData;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\npublic class BuiltinFunctionShow extends BuiltinFunctionBase {\n\n\tpublic BuiltinFunctionShow() {\n\t\tsuper(\"show\");\n\t}\n\t\n\t@Override\n\tpublic int requiredArgCount(boolean minimum) {\n\t\treturn 1;\n\t}\n\t\n\t@Override\n\tpublic boolean hasReturnType() {\n\t\treturn false;\n\t}\n\t\n\t@Override\n\tpublic CoverageData execute() {\n\t\tCoverageData[] finalArgs = prepareFinalArguments();\n\t\t\t\n\t\tguiSvc.visualizeCoverage(finalArgs[0]);\n\t\t\n\t\treturn super.execute();\n\t}\n\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/impl/BuiltinFunctionSum.java\npackage dragondance.scripting.functions.impl;\n\nimport dragondance.datasource.CoverageData;\nimport dragondance.scripting.functions.BuiltinAlias;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\n@BuiltinAlias(aliases = {\"or\",\"union\"})\npublic class BuiltinFunctionSum extends BuiltinFunctionBase {\n\n\tpublic BuiltinFunctionSum() {\n\t\tsuper(\"sum\");\n\t}\n\n\t@Override\n\tpublic int requiredArgCount(boolean minimum) {\n\t\tif (minimum)\n\t\t\treturn 2;\n\t\t\n\t\treturn -1;\n\t}\n\t\n\t@Override\n\tpublic CoverageData execute() {\n\t\tCoverageData[] finalArgs = prepareFinalArguments();\n\t\t\n\t\tsetReturn(CoverageData.sum(finalArgs));\n\t\t\n\t\treturn super.execute();\n\t}\n}\n\n<file_path>src/main/java/dragondance/scripting/ScriptVariable.java\npackage dragondance.scripting;\n\nimport dragondance.datasource.CoverageData;\nimport dragondance.exceptions.ScriptParserException;\n\npublic class ScriptVariable {\n\t\n\tprivate String name;\n\tprivate CoverageData coverageValue;\n\t\n\tpublic ScriptVariable(String name) throws ScriptParserException {\n\t\tthis.name = name;\n\t\t\n\t\tif (!DragonDanceScripting.addVariable(this)) \n\t\t\tthrow new ScriptParserException(\"%s already declared\",name);\n\t}\n\t\n\tpublic void setResultCoverage(CoverageData coverage) {\n\t\t\n\t\tif (this.coverageValue != null) {\n\t\t\tif (this.coverageValue.isLogicalCoverageData()) {\n\t\t\t\tthis.coverageValue.closeNothrow();\n\t\t\t}\n\t\t}\n\t\t\n\t\tthis.coverageValue = coverage;\n\t}\n\t\n\tpublic final String getName() {\n\t\treturn this.name;\n\t}\n\t\n\tpublic CoverageData getValue() {\n\t\treturn this.coverageValue;\n\t}\n\t\n\t@Override\n\tpublic String toString() {\n\t\treturn this.name;\n\t}\n\t\n\tpublic final boolean isNull() {\n\t\treturn this.coverageValue == null;\n\t}\n\t\n\tpublic void discard(boolean forceDeletePhysicalCoverage) {\n\t\t//dispose only logical result coverage object. \n\t\t//dont touch the physical coverage data\n\t\t\n\t\tif (this.coverageValue != null) {\n\t\t\tif (this.coverageValue.isLogicalCoverageData())\n\t\t\t\tthis.coverageValue.closeNothrow();\n\t\t\telse if (forceDeletePhysicalCoverage) {\n\t\t\t\tDragonDanceScripting.removeCoverage(this.coverageValue);\n\t\t\t}\n\t\t}\n\t\t\n\t\t//but the holder variable can be delete in any case\n\t\tDragonDanceScripting.removeVariable(this);\n\t}\n\t\n\tpublic void discard() {\n\t\tdiscard(false);\n\t}\n}\n<file_path>src/main/java/dragondance/scripting/functions/impl/BuiltinFunctionDiscard.java\npackage dragondance.scripting.functions.impl;\n\nimport dragondance.datasource.CoverageData;\nimport dragondance.exceptions.DragonDanceScriptRuntimeException;\nimport dragondance.scripting.ScriptVariable;\nimport dragondance.scripting.functions.BuiltinAlias;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\n@BuiltinAlias(aliases = {\"del\"})\npublic class BuiltinFunctionDiscard extends BuiltinFunctionBase {\n\n\tpublic BuiltinFunctionDiscard() {\n\t\tsuper(\"discard\");\n\t}\n\t\n\t@Override\n\tpublic int requiredArgCount(boolean minimum) {\n\t\tif (minimum)\n\t\t\treturn 1;\n\t\t\n\t\treturn -1;\n\t}\n\t\n\t@Override\n\tpublic boolean hasReturnType() {\n\t\treturn false;\n\t}\n\t\n\t@Override\n\tpublic CoverageData execute() {\n\t\tObject[] finalArgs = prepareArguments();\n\t\t\n\t\tfor (Object arg : finalArgs) {\n\t\t\tif (arg instanceof CoverageData) {\n\t\t\t\t((CoverageData)arg).closeNothrow();\n\t\t\t}\n\t\t\telse if (arg instanceof ScriptVariable) {\n\t\t\t\t((ScriptVariable)arg).discard(true);\n\t\t\t}\n\t\t\telse\n\t\t\t\tthrow new DragonDanceScriptRuntimeException(\"invalid arg type for builtin\");\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\treturn super.execute();\n\t}\n\t\n\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/BuiltinArg.java\npackage dragondance.scripting.functions;\n\nimport dragondance.scripting.ScriptVariable;\n\npublic class BuiltinArg {\n\t\n\tprivate Object argContainer;\n\t\n\tpublic BuiltinArg(ScriptVariable var) {\n\t\tthis.argContainer=var;\n\t}\n\t\n\tpublic BuiltinArg(BuiltinFunctionBase func) {\n\t\tthis.argContainer = func;\n\t}\n\t\n\tpublic BuiltinArg(String sarg) {\n\t\tthis.argContainer = sarg;\n\t}\n\t\n\tpublic BuiltinArg(long larg) {\n\t\tthis.argContainer = larg;\n\t}\n\t\n\tpublic boolean isBuiltinCall() {\n\t\treturn this.argContainer instanceof BuiltinFunctionBase;\n\t}\n\t\n\tpublic boolean isVariable() {\n\t\treturn this.argContainer instanceof ScriptVariable;\n\t}\n\t\n\tpublic boolean isString() {\n\t\treturn this.argContainer instanceof String;\n\t}\n\t\n\tpublic boolean isInteger() {\n\t\treturn this.argContainer instanceof Long;\n\t}\n\t\n\tpublic BuiltinFunctionBase getAsFunction() {\n\t\treturn (BuiltinFunctionBase)this.argContainer;\n\t}\n\t\n\tpublic ScriptVariable getAsVariable() {\n\t\treturn (ScriptVariable)this.argContainer;\n\t}\n\t\n\tpublic String getAsString() {\n\t\treturn (String)this.argContainer;\n\t}\n\t\n\tpublic long getAsLong() {\n\t\treturn ((Long)this.argContainer).longValue();\n\t}\n}\n\n<file_path>src/main/java/dragondance/scripting/DragonDanceScriptParser.java\npackage dragondance.scripting;\n\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.ListIterator;\nimport java.util.Stack;\n\nimport dragondance.Log;\nimport dragondance.components.GuiAffectedOpInterface;\nimport dragondance.exceptions.ScriptParserException;\nimport dragondance.scripting.functions.BuiltinArg;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\nclass DDSToken {\n\tpublic final static int TOK_IDENTIFIER=0;\n\tpublic final static int TOK_BUILTIN=1;\n\tpublic final static int TOK_ASSIGN=2;\n\tpublic final static int TOK_OPEN_PARAN=3;\n\tpublic final static int TOK_CLOSE_PARAN=4;\n\tpublic final static int TOK_COMMA=5;\n\tpublic final static int TOK_STRING=6;\n\tpublic final static int TOK_INTEGER=7;\n\t\n\tpublic final static String[] TOK_STRINGS = {\n\t\t\t\"Identifier (argument)\",\n\t\t\t\"Builtin\",\n\t\t\t\"=\",\n\t\t\t\"(\",\n\t\t\t\")\",\n\t\t\t\",\",\n\t\t\t\"String\",\n\t\t\t\"Integer\"\n\t};\n\t\n\tprivate String tok;\n\tprivate int type;\n\tprivate int line,pos;\n\t\n\tpublic DDSToken(String tok, int tokType, int line, int pos) {\n\t\tthis.tok = tok;\n\t\tthis.type = tokType;\n\t\tthis.line = line;\n\t\tthis.pos = pos;\n\t}\n\t\n\tpublic final int getType() {\n\t\treturn this.type;\n\t}\n\t\n\tpublic final String getValue() {\n\t\treturn this.tok;\n\t}\n\t\n\tpublic final long getAsNumber() {\n\t\ttry {\n\t\t\treturn Long.decode(this.tok).longValue();\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tLog.println(e.getMessage());\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\tprivate ScriptParserException buildException(String format, Object ...args) {\n\t\tString msg = String.format(format, args);\n\t\t\n\t\tmsg += \"\\n\\n\" + String.format(\"line: %d, position: %d\",this.line,this.pos);\n\t\t\n\t\treturn new ScriptParserException(msg);\n\t}\n\t\n\tpublic ScriptParserException illegalIdentifier() {\n\t\treturn buildException(this.getValue() + \" is an illegal identifier. it may contains invalid char or begins with digit\");\n\t}\n\t\n\tpublic ScriptParserException unexpectedToken(String expected) {\n\t\treturn buildException(\"\\\"%s\\\": expected but \\\"%s\\\" came.\",expected,this.getValue());\n\t}\n\t\n\tpublic ScriptParserException expected(String expect) {\n\t\treturn buildException(\"\\\"%s\\\" expected.\",expect);\n\t}\n\t\n\t\n\tpublic ScriptParserException alreadyDeclared(String var) {\n\t\treturn buildException(\"\\\"%s\\\" already declared\");\n\t}\n\t\n\tpublic ScriptParserException missingArgument() {\n\t\treturn buildException(\"builtin functions must have at least 2 arguments\");\n\t}\n\t\n\tpublic ScriptParserException variableNotDeclared() {\n\t\treturn buildException(\"\\\"%s\\\" is not declared\",this.getValue());\n\t}\n\t\n\tpublic ScriptParserException suspicious(String msg) {\n\t\treturn buildException(\"Suspicious behaviour: %s\",msg);\n\t}\n\t\n\t@Override\n\tpublic String toString() {\n\t\treturn String.format(\"tok: %s, type: %d\", tok,type);\n\t}\n\t\n\t\n}\n\npublic class DragonDanceScriptParser {\n\t\n\tprivate static GuiAffectedOpInterface guisvc;\n\t\n\tprivate List<DDSToken> tokens;\n\tprivate ListIterator<DDSToken> node = null;\n\tprivate ScriptExecutionUnit execUnit = null;\n\tprivate Stack<BuiltinFunctionBase> callingStack=null;\n\tprivate GuiAffectedOpInterface guiSvc=null;\n\tprivate int currLine=0,currPos=0;\n\tprivate DDSToken dummy = new DDSToken(\"\",0,0,0);\n\t\n\tpublic static void setGuiSvc(GuiAffectedOpInterface gai) {\n\t\tguisvc = gai;\n\t}\n\t\n\tpublic static GuiAffectedOpInterface getGAI() {\n\t\treturn guisvc;\n\t}\n\t\n\tpublic DragonDanceScriptParser() {\n\t\tthis.tokens = new LinkedList<DDSToken>();\n\t\tthis.callingStack = new Stack<BuiltinFunctionBase>();\n\t\tthis.guiSvc = guisvc;\n\t\t\n\t}\n\t\n\tprivate void newExecUnit() {\n\t\t\n\t\tif (this.execUnit != null)\n\t\t\tDragonDanceScripting.addExecutionUnit(this.execUnit);\n\t\t\n\t\tthis.execUnit = new ScriptExecutionUnit();\n\t}\n\t\n\tprivate ScriptExecutionUnit getExecUnit() {\n\t\tif (this.execUnit == null)\n\t\t\tthis.execUnit = new ScriptExecutionUnit();\n\t\t\n\t\treturn this.execUnit;\n\t}\n\t\n\tprivate void pushCallingStack(BuiltinFunctionBase func) {\n\t\tthis.callingStack.push(func);\n\t}\n\t\n\tprivate BuiltinFunctionBase popCallingStack() {\n\t\treturn this.callingStack.pop();\n\t}\n\t\n\tprivate void pushToken(String s, int type) {\n\t\tint pos = this.currPos;\n\t\t\n\t\tif (s.length()>1) {\n\t\t\tpos -= s.length();\n\t\t}\n\t\t\n\t\ttokens.add(new DDSToken(s,type,this.currLine,pos));\n\t\t\n\t}\n\t\n\tprivate void pushToken(char c, int type) {\n\t\tpushToken(Character.toString(c),type);\n\t}\n\t\n\t\n\tprivate boolean isBufferedChar(char c) {\n\t\tif (Character.isLetterOrDigit(c))\n\t\t\treturn true;\n\t\t\n\t\tif (c == '-' || c == '+')\n\t\t\treturn true;\n\t\t\n\t\treturn false;\n\t}\n\t\n\tprivate void processStringBufferAsToken(StringBuffer sb, boolean quoteHint) {\n\t\tString sval = sb.toString();\n\t\tsb.setLength(0);\n\t\t\n\t\t\n\t\tif (DragonDanceScripting.isBuiltin(sval)) {\n\t\t\tpushToken(sval,DDSToken.TOK_BUILTIN);\n\t\t}\n\t\telse if (quoteHint) {\n\t\t\tpushToken(sval,DDSToken.TOK_STRING);\n\t\t}\n\t\telse {\n\t\t\t\n\t\t\ttry {\n\t\t\t\tLong.decode(sval);\n\t\t\t\tpushToken(sval,DDSToken.TOK_INTEGER);\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tpushToken(sval,DDSToken.TOK_IDENTIFIER);\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t}\n\t\n\tprivate boolean tokenize(String script) {\n\t\tStringBuffer sbuf = new StringBuffer();\n\t\tchar c;\n\t\tboolean quoteOn=false;\n\t\t\n\t\tfor (int i=0;i<script.length();i++) {\n\t\t\tc = script.charAt(i);\n\t\t\t\n\t\t\tif (!quoteOn && c == '\\n') {\n\t\t\t\tthis.currLine++;\n\t\t\t\tthis.currPos=0;\n\t\t\t}\n\t\t\t\n\t\t\tif (quoteOn || isBufferedChar(c)) {\n\t\t\t\t\n\t\t\t\tif (quoteOn && c == '\\\"') {\n\t\t\t\t\tprocessStringBufferAsToken(sbuf,true);\n\t\t\t\t\tquoteOn=false;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tsbuf.append(c);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (sbuf.length()>0) {\n\t\t\t\t\tprocessStringBufferAsToken(sbuf,false);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (c == '\\\"') \n\t\t\t\t\tquoteOn=true;\n\t\t\t\telse if (c == '(') \n\t\t\t\t\tpushToken(c, DDSToken.TOK_OPEN_PARAN);\n\t\t\t\telse if (c == ')')\n\t\t\t\t\tpushToken(c, DDSToken.TOK_CLOSE_PARAN);\n\t\t\t\telse if (c == '=')\n\t\t\t\t\tpushToken(c, DDSToken.TOK_ASSIGN);\n\t\t\t\telse if (c == ',')\n\t\t\t\t\tpushToken(c, DDSToken.TOK_COMMA);\n\t\t\t}\n\t\t\t\n\t\t\tthis.currPos++;\n\t\t}\n\t\t\n\t\tif (sbuf.length() > 0) {\n\t\t\tprocessStringBufferAsToken(sbuf,quoteOn);\n\t\t}\n\t\t\n\t\treturn this.tokens.size() > 0;\n\t}\n\t\n\t\n\tprivate String getExpectedTokenStrings(int [] types) {\n\t\tString s = \"\";\n\t\t\n\t\tif (types.length < 1)\n\t\t\treturn \"token\";\n\t\t\n\t\tif (types.length == 1)\n\t\t\treturn DDSToken.TOK_STRINGS[types[0]];\n\t\t\n\t\tfor (int i=0;i<types.length;i++) {\n\t\t\ts += DDSToken.TOK_STRINGS[i];\n\t\t\t\n\t\t\tif (i != types.length-1) {\n\t\t\t\tif (i == types.length-2)\n\t\t\t\t\ts += \" or \";\n\t\t\t\telse\n\t\t\t\t\ts += \", \";\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn s;\n\t}\n\t\n\tprivate DDSToken nextToken(boolean justHint, int ...expected) throws ScriptParserException {\n\t\t\n\t\tDDSToken tok;\n\t\tboolean valid=false;\n\t\t\n\t\tif (!this.node.hasNext()) {\n\t\t\tif (this.node.hasPrevious()) {\n\t\t\t\ttok = this.node.previous();\n\t\t\t}\n\t\t\telse\n\t\t\t\ttok = this.dummy;\n\t\t\t\n\t\t\tthrow tok.expected(getExpectedTokenStrings(expected));\n\t\t}\n\t\t\n\t\ttok = this.node.next();\n\t\t\n\t\tif (expected.length > 0 && !justHint) {\n\t\t\tfor (int i=0;i<expected.length;i++) {\n\t\t\t\tif (tok.getType() == expected[i]) {\n\t\t\t\t\tvalid=true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tvalid=true;\n\t\t}\n\t\t\n\t\t\n\t\tif (!valid)\n\t\t\tthrow tok.unexpectedToken(getExpectedTokenStrings(expected));\n\t\t\n\t\t\n\t\treturn tok;\n\t}\n\t\n\tprivate boolean isBuiltinSatisfiedByArglist(BuiltinFunctionBase builtin) {\n\t\treturn builtin.argCount() >= builtin.requiredArgCount(true);\n\t}\n\t\n\tprivate void handleBuiltinArguments(BuiltinFunctionBase ownerFunc) throws ScriptParserException {\n\t\tDDSToken tok;\n\t\tboolean done=false;\n\t\n\t\t\n\t\twhile (!done) {\n\t\t\t\n\t\t\ttok = nextToken(true, \n\t\t\t\t\tDDSToken.TOK_IDENTIFIER, \n\t\t\t\t\tDDSToken.TOK_STRING,\n\t\t\t\t\tDDSToken.TOK_INTEGER, \n\t\t\t\t\tDDSToken.TOK_CLOSE_PARAN\n\t\t\t\t\t);\n\t\t\t\n\t\t\tif (tok.getType() == DDSToken.TOK_CLOSE_PARAN) {\n\t\t\t\tif (!isBuiltinSatisfiedByArglist(ownerFunc))\n\t\t\t\t\tthrow tok.missingArgument();\n\t\t\t}\n\t\t\telse if (tok.getType() != DDSToken.TOK_IDENTIFIER && \n\t\t\t\t\ttok.getType() != DDSToken.TOK_STRING && \n\t\t\t\t\ttok.getType() != DDSToken.TOK_BUILTIN &&\n\t\t\t\t\ttok.getType() != DDSToken.TOK_INTEGER) {\n\t\t\t\t\n\t\t\t\tthrow tok.unexpectedToken(\"string, integer, coverage variable or builtin call as an argument\");\n\t\t\t}\n\t\t\t\n\t\t\tif (tok.getType() == DDSToken.TOK_IDENTIFIER) {\n\t\t\t\tif (!DragonDanceScripting.isVariableDeclared(tok.getValue()))\n\t\t\t\t\tthrow tok.variableNotDeclared();\n\t\t\t\t\n\t\t\t\tScriptVariable sv = DragonDanceScripting.getVariable(tok.getValue());\n\t\t\t\tBuiltinArg arg = new BuiltinArg(sv);\n\t\t\t\townerFunc.putArg(arg);\n\t\t\t}\n\t\t\telse if (tok.getType() == DDSToken.TOK_STRING) {\n\t\t\t\tBuiltinArg arg = new BuiltinArg(tok.getValue());\n\t\t\t\townerFunc.putArg(arg);\n\t\t\t}\n\t\t\telse if (tok.getType() == DDSToken.TOK_INTEGER) {\n\t\t\t\tBuiltinArg arg = new BuiltinArg(tok.getAsNumber());\n\t\t\t\townerFunc.putArg(arg);\n\t\t\t}\n\t\t\telse if (tok.getType() == DDSToken.TOK_BUILTIN) { //TOK_BUILTIN\n\t\t\t\t\n\t\t\t\tnextToken(false,DDSToken.TOK_OPEN_PARAN);\n\t\t\t\t\n\t\t\t\tBuiltinFunctionBase builtin = DragonDanceScripting.newInstance(tok.getValue(),this.guiSvc);\n\t\t\t\tBuiltinArg arg = new BuiltinArg(builtin);\n\t\t\t\townerFunc.putArg(arg);\n\t\t\t\t\n\t\t\t\t//handleBuiltinArgs\n\t\t\t\t\n\t\t\t\tif (this.callingStack.size() > 8) {\n\t\t\t\t\tthrow tok.suspicious(\n\t\t\t\t\t\t\tString.format(\"is it really needed nested call depth? (%d)\",this.callingStack.size()));\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpushCallingStack(builtin);\n\t\t\t\t\n\t\t\t\thandleBuiltinArguments(builtin);\n\t\t\t\t\n\t\t\t\tnextToken(false,DDSToken.TOK_CLOSE_PARAN);\n\t\t\t\t\n\t\t\t\tpopCallingStack();\n\t\t\t}\n\t\t\telse if (tok.getType() == DDSToken.TOK_CLOSE_PARAN) {\n\t\t\t\tnode.previous();\n\t\t\t\tdone=true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tif (!node.hasNext()) {\n\t\t\t\tif (!isBuiltinSatisfiedByArglist(ownerFunc)) \n\t\t\t\t\tthrow tok.expected(\",\");\n\t\t\t\t\n\t\t\t\tthrow tok.expected(\")\");\n\t\t\t}\n\t\t\t\n\t\t\ttok = node.next();\n\t\t\t\n\t\t\tif (!isBuiltinSatisfiedByArglist(ownerFunc)) {\n\t\t\t\tif (tok.getType() != DDSToken.TOK_COMMA) {\n\t\t\t\t\tif (tok.getType() == DDSToken.TOK_CLOSE_PARAN)\n\t\t\t\t\t\tthrow tok.missingArgument();\n\t\t\t\t\t\n\t\t\t\t\tthrow tok.unexpectedToken(\",\");\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (tok.getType() == DDSToken.TOK_CLOSE_PARAN) {\n\t\t\t\tdone=true;\n\t\t\t\tnode.previous();\n\t\t\t}\n\t\t\t\n\t\t}\n\t}\n\t\n\tprivate void handleBuiltinCall(DDSToken tok) throws ScriptParserException {\n\t\t\n\t\tnextToken(false,DDSToken.TOK_OPEN_PARAN);\n\t\t\n\t\t//push paran stack\n\t\t\n\t\t//init execution unit only top builtin function \n\t\tif (this.callingStack.size() == 0)\n\t\t\tgetExecUnit().initFunction(tok.getValue(), this.guiSvc);\n\t\t\n\t\tpushCallingStack(getExecUnit().getFunction());\n\t\t\n\t\tBuiltinFunctionBase ownerFunc;\n\t\t\n\t\townerFunc = this.callingStack.peek();\n\t\t\n\t\thandleBuiltinArguments(ownerFunc);\n\t\t\n\t\tnextToken(false,DDSToken.TOK_CLOSE_PARAN);\n\t\t\n\t\tnewExecUnit();\n\t\t\n\t\tpopCallingStack();\n\t}\n\t\n\tprivate void handleAssignee(DDSToken tok) throws ScriptParserException {\n\t\tDDSToken ntok;\n\t\t\n\t\tif (Character.isDigit(tok.getValue().charAt(0)))\n\t\t\tthrow tok.illegalIdentifier();\n\t\t\n\t\tif (!node.hasNext())\n\t\t\tthrow tok.expected(\"=\");\n\t\t\n\t\tntok = node.next();\n\t\t\n\t\tif (ntok.getType() != DDSToken.TOK_ASSIGN)\n\t\t\tthrow ntok.unexpectedToken(\"=\");\n\t\t\n\t\tgetExecUnit().initAssigneeVarName(tok.getValue());\n\t}\n\t\n\t\n\tprivate boolean parse() throws ScriptParserException {\n\t\n\t\tDDSToken tok;\n\t\t\n\t\tnode = this.tokens.listIterator();\n\t\t\n\t\twhile (node.hasNext()) {\n\t\t\ttok = node.next();\n\t\t\t\n\t\t\tif (tok.getType() == DDSToken.TOK_IDENTIFIER) {\n\t\t\t\thandleAssignee(tok);\n\t\t\t}\n\t\t\telse if (tok.getType() == DDSToken.TOK_BUILTIN) {\n\t\t\t\thandleBuiltinCall(tok);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic boolean start(String script) throws ScriptParserException {\n\t\t\n\t\tif (!tokenize(script))\n\t\t\treturn false;\n\t\t\n\t\tif (!parse())\n\t\t\treturn false;\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic void discard() {\n\t\ttokens.clear();\n\t\tcallingStack.clear();\n\t}\n}\n\n<file_path>src/main/java/dragondance/scripting/ScriptExecutionUnit.java\npackage dragondance.scripting;\n\nimport dragondance.components.GuiAffectedOpInterface;\nimport dragondance.exceptions.ScriptParserException;\nimport dragondance.scripting.functions.BuiltinArg;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\n\npublic class ScriptExecutionUnit {\n\tprivate ScriptVariable assigneeVar;\n\tprivate BuiltinFunctionBase function;\n\t\n\tpublic void initAssigneeVarName(String name) throws ScriptParserException {\n\t\tif (DragonDanceScripting.isVariableDeclared(name)) {\n\t\t\tthis.assigneeVar = DragonDanceScripting.getVariable(name);\n\t\t}\n\t\telse {\n\t\t\tthis.assigneeVar = new ScriptVariable(name);\n\t\t}\n\t}\n\t\n\tpublic void initFunction(String builtinName, GuiAffectedOpInterface gai) {\n\t\tthis.function = DragonDanceScripting.newInstance(builtinName, gai);\n\t}\n\t\n\tpublic void pushArgument(BuiltinArg arg) {\n\t\tthis.function.putArg(arg);\n\t}\n\t\n\tpublic boolean hasAssignee() {\n\t\treturn this.assigneeVar != null;\n\t}\n\t\n\tpublic boolean hasFunction() {\n\t\treturn this.function != null;\n\t}\n\t\n\tpublic boolean isItExpectFunction() {\n\t\treturn hasAssignee() && !hasFunction();\n\t}\n\t\n\tpublic boolean isCompleted() {\n\t\treturn hasAssignee() && hasFunction();\n\t}\n\t\n\tpublic BuiltinFunctionBase getFunction() {\n\t\treturn this.function;\n\t}\n\t\n\tpublic boolean execute() {\n\t\t\n\t\tif (this.function.execute() == null) {\n\t\t\t\n\t\t\tif (!this.function.hasReturnType())\n\t\t\t\treturn true;\n\t\t\t\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tif (hasAssignee())\n\t\t\tthis.assigneeVar.setResultCoverage(this.function.getReturn());\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic void discard() {\n\t\tthis.function.discard();\n\t\tthis.function = null;\n\t}\n}\n\n<file_path>src/main/java/dragondance/components/MainDockProvider.java\npackage dragondance.components;\n\nimport java.awt.Color;\nimport java.awt.Font;\nimport java.awt.Graphics;\nimport java.awt.Rectangle;\nimport java.awt.event.ComponentEvent;\nimport java.awt.event.ComponentListener;\nimport java.awt.event.InputEvent;\nimport java.awt.event.KeyEvent;\nimport java.awt.event.KeyListener;\nimport java.io.FileNotFoundException;\n\nimport javax.swing.*;\nimport javax.swing.border.BevelBorder;\nimport javax.swing.event.ListSelectionEvent;\nimport javax.swing.event.ListSelectionListener;\nimport javax.swing.table.DefaultTableModel;\n\nimport docking.ActionContext;\nimport docking.ComponentProvider;\nimport docking.action.DockingAction;\nimport docking.action.MenuData;\nimport docking.action.ToolBarData;\nimport docking.widgets.table.GTable;\nimport dragondance.StringResources;\nimport dragondance.datasource.CoverageData;\nimport dragondance.datasource.CoverageDataSource;\nimport dragondance.eng.DragonHelper;\nimport dragondance.eng.session.Session;\nimport dragondance.eng.session.SessionManager;\nimport dragondance.exceptions.InvalidInstructionAddress;\nimport dragondance.exceptions.OperationAbortedException;\nimport dragondance.scripting.DragonDanceScripting;\nimport dragondance.util.TextGraphic;\nimport dragondance.util.Util;\nimport ghidra.framework.plugintool.PluginTool;\nimport resources.Icons;\n\n\npublic class MainDockProvider extends ComponentProvider implements GuiAffectedOpInterface, ComponentListener {\n\n\tprivate JPanel panel = null;\n\tprivate JTextArea txtScript = null;\n\tprivate JScrollPane scriptTextScrollPane=null;\n\tprivate PluginTool tool = null;\n\tprivate GTable table = null;\n\tprivate DefaultTableModel dtm = null;\n\tprivate JLabel infoLabel = null;\n\tprivate TextGraphic txtGraph = null;\n\tprivate JScrollPane scrollPane = null;\n\t\n\tprivate boolean scriptShown=false;\n\t\n\tint infoPanelWidth=425,infoPanelHeight=75;\n\tint covTableWidth=425,covTableHeight=175;\n\t\n\tprivate int lastX=15,lastY=5;\n\t\n\tpublic MainDockProvider(PluginTool tool,String owner) {\n\t\tsuper(tool, \"Dragon Dance\", owner);\n\t\t\n\t\tDragonDanceScripting.setGuiAffectedInterface(this);\n\t\t\n\t\tthis.tool = tool;\n\t\t\n\t\tcreateUi();\n\t\tcreateActions();\n\t\t\n\t\tthis.getComponent().addComponentListener(this);\n\t\t\n\t}\n\t\n\tprivate Font getFont(int size, int type, String ...fontNames) {\n\t\tFont font;\n\t\t\n\t\tfor (String fontName : fontNames) {\n\t\t\tfont = new Font(fontName,type,size);\n\t\t\t\n\t\t\tif (font.getFamily() != null)\n\t\t\t\treturn font;\n\t\t}\n\t\t\n\t\treturn this.getComponent().getFont().deriveFont(type, size);\n\t}\n\t\n\tprivate void createActions() {\n\t\tDockingAction actShell = new DockingAction(\"shell\",getName()) {\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic void actionPerformed(ActionContext context) {\n\t\t\t\t((MainDockProvider)context.getComponentProvider()).buildScriptingUi();\n\t\t\t}\n\t\t};\n\t\t\n\n\t\t\n\t\t\n\t\tDockingAction actAbout = new DockingAction(\"about\",getName()) {\n\n\t\t\t@Override\n\t\t\tpublic void actionPerformed(ActionContext context) {\n\t\t\t\tDragonHelper.showMessage(StringResources.ABOUT);\n\t\t\t}\n\t\t\t\n\t\t};\n\t\t\n\t\tDockingAction actCheckNewVer = new DockingAction(\"checkupdate\",getName()) {\n\t\t\t@Override\n\t\t\tpublic void actionPerformed(ActionContext context) {\n\t\t\t\tif (Util.checkForNewVersion()) {\n\t\t\t\t\tDragonHelper.showMessage(StringResources.NEW_VERSION);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tDragonHelper.showMessage(StringResources.UP_TO_DATE);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\t\n\t\tactShell.setMenuBarData(\n\t\t\t\tnew MenuData(new String[] { \"Scripting shell\" }, null, null));\n\t\t\n\t\tactAbout.setMenuBarData(\n\t\t\t\tnew MenuData(new String[] {\"About\"},null,null));\n\t\t\n\t\tactCheckNewVer.setMenuBarData(\n\t\t\t\tnew MenuData(new String[] {\"Check for update\"},null,null));\n\t\t\n\t\ttool.addLocalAction(this, actShell);\n\t\ttool.addLocalAction(this, actAbout);\n\t\ttool.addLocalAction(this, actCheckNewVer);\n\t\t\n\t\tDockingAction actImport = new DockingAction(\"Import coverage data\",getName()) {\n\n\t\t\t@Override\n\t\t\tpublic void actionPerformed(ActionContext context) {\n\t\t\t\t((MainDockProvider)context.getComponentProvider()).importCoverageAsync();\n\t\t\t}\n\t\t\t\n\t\t};\n\t\t\n\t\tactImport.setToolBarData(new ToolBarData(Icons.ADD_ICON, null));\n\t\t\n\t\ttool.addLocalAction(this, actImport);\n\t\tactImport.setEnabled(true);\n\t}\n\t\n\tprivate String newLine(int count) {\n\t\tString nl = \"\";\n\t\t\n\t\twhile (count-- > 0) {\n\t\t\tnl += System.lineSeparator();\n\t\t}\n\t\t\n\t\treturn nl;\n\t}\n\t\n\tprivate Session getSession() {\n\t\tSession session = SessionManager.getActiveSession();\n\t\t\n\t\tif (session == null) {\n\t\t\tDragonHelper.showWarning(\"There is no active session\");\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\treturn session;\n\t}\n\t\n\tprivate void blit() {\n\t\tthis.infoLabel.repaint();\n\t}\n\t\n\tprivate void writeStatusTextInfoPanel(String msg) {\n\t\tString[] lines = msg.split(\"\\n\");\n\t\t\n\t\tfor (String line : lines) {\n\t\t\ttxtGraph.textOut(line, Color.BLACK).newLine();\n\t\t}\n\t\t\n\t\ttxtGraph.render(true);\n\t\t\n\t\tblit();\n\t}\n\t\n\tprivate void setStatusText(String text) {\n\t\tif (DragonHelper.isUiDispatchThread())\n\t\t\tthis.getTool().setStatusInfo(text);\n\t\telse {\n\t\t\tDragonHelper.runOnSwingThread(() -> \n\t\t\t{\n\t\t\t\tgetTool().setStatusInfo(text);\n\t\t\t\t},\n\t\t\ttrue);\n\t\t}\n\t}\n\t\n\tprivate void drawSelectedCoverageDataInfo(int id) {\n\t\t\n\t\tSession session = getSession();\n\t\t\n\t\tif (session == null)\n\t\t\treturn;\n\t\t\n\t\tCoverageData cov = session.getCoverage(id);\n\t\tCoverageDataSource source = cov.getSource();\n\t\t\n\t\ttxtGraph.pushFont(\"Arial\", 14, Font.PLAIN);\n\t\t\n\t\ttxtGraph.textOut(\"Module count: \", Color.BLUE).\n\t\t\ttextOut(\"%d\", Color.BLACK,source.getModuleCount()).newLine();\n\t\t\n\t\ttxtGraph.textOut(\"Entry count: \", Color.BLUE).\n\t\t\ttextOut(\"%d\", Color.BLACK,source.getEntryCount()).newLine();\n\t\t\n\t\ttxtGraph.textOut(\"Readed module count: \", Color.BLUE).\n\t\t\ttextOut(\"%d\", Color.BLACK,source.getReadedModuleCount()).newLine();\n\t\t\n\t\ttxtGraph.textOut(\"Readed entry count: \", Color.BLUE).\n\t\t\ttextOut(\"%d\", Color.BLACK,source.getReadedEntryCount()).newLine();\n\t\t\n\t\ttxtGraph.floatTextBlock();\n\t\t\n\t\t\n\t\ttxtGraph.textOut(\"Initial range count: \", Color.RED).\n\t\t\ttextOut(\"%d\", Color.BLACK,cov.getInitialRangeCount()).newLine();\n\n\t\ttxtGraph.textOut(\"Range count: \", Color.RED).\n\t\t\ttextOut(\"%d\", Color.BLACK,cov.getRangeCount()).newLine();\n\t\t\n\t\ttxtGraph.textOut(\"Merged range count: \", Color.RED).\n\t\t\ttextOut(\"%d\", Color.BLACK,cov.getMergedRangeCount()).newLine();\n\t\t\n\t\ttxtGraph.textOut(\"Max density: \", Color.RED).\n\t\t\ttextOut(\"%d\", Color.BLACK,cov.getMaxDensity()).newLine();\n\t\t\n\t\ttxtGraph.render(true);\n\t\t\n\t\tblit();\n\t\t\n\t}\n\t\n\tprivate void addCoverageTable(CoverageData coverage) {\n\t\tdtm.addRow(new Object[] {\n\t\t\t\tcoverage.getSourceId(),\n\t\t\t\tcoverage.getName(),\n\t\t\t\tSession.getCoverageTypeString(coverage.getSource().getType())\n\t\t\t\t});\n\t\t\n\t\tdtm.fireTableDataChanged();\n\t}\n\t\n\tprivate void removeFromCoverageTable(int id) {\n\t\tint row = coverageIdToTableRow(id);\n\t\t\n\t\tdtm.removeRow(row);\n\t\tdtm.fireTableDataChanged();\n\t}\n\t\n\tprivate CoverageData importCoverage(String coverageFile) throws FileNotFoundException {\n\t\tCoverageData coverage;\n\t\tSession session = getSession();\n\t\t\n\t\tif (session == null)\n\t\t\treturn null;\n\t\t\n\t\tcoverage = session.addCoverageData(coverageFile);\n\t\t\n\t\tsetStatusText(\"Loading...\");\n\t\t\n\t\tif (!coverage.getSource().process()) {\n\t\t\tDragonHelper.showWarning(\"%s could not be processed\",coverageFile);\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\ttry {\n\t\t\tif (coverage.build()) {\n\t\t\t\t\n\t\t\t\tRunnable postBuildGuiOp = new Runnable() {\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic void run() {\n\t\t\t\t\t\taddCoverageTable(coverage);\n\t\t\t\t\t\twriteStatusTextInfoPanel(StringResources.COVERAGE_IMPORTED_HINT);\n\t\t\t\t\t\tsetStatusText(\"Done\");\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tif (DragonHelper.isUiDispatchThread())\n\t\t\t\t\tpostBuildGuiOp.run();\n\t\t\t\telse\n\t\t\t\t\tDragonHelper.runOnSwingThread(postBuildGuiOp, true);\n\t\n\t\t\t}\n\t\t} catch (InvalidInstructionAddress e1) {\n\t\t\t\n\t\t\tsession.removeCoverageData(coverage.getSourceId());\n\t\t\t\n\t\t\tString msg = e1.getMessage() + newLine(2) + StringResources.MISMATCHED_EXECUTABLE;\n\t\t\tDragonHelper.showWarning(msg, DragonHelper.getExecutableMD5Hash());\n\t\t\t\n\t\t\tsession.removeCoverageData(coverage.getSourceId());\n\t\t\t\n\t\t\treturn null;\n\t\t\n\t\t} catch (OperationAbortedException e1) {\n\t\t\t\n\t\t\tDragonHelper.showWarning( \n\t\t\t\t\t\"Operation could not be continue. (\" +\n\t\t\t\t\te1.getMessage() + \")\");\n\t\t\t\n\t\t\tsession.removeCoverageData(coverage.getSourceId());\n\t\t\t\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\t\n\t\treturn coverage;\n\t\t\n\t}\n\t\n\t\n\tprivate void importCoverageAsync() {\n\t\tString file = DragonHelper.askFile(tool.getToolFrame(),\"Select coverage data\", \"load it up!\");\n\t\t\n\t\tif (file == null)\n\t\t\treturn;\n\t\t\n\t\tDragonHelper.queuePoolWorkItem(() -> {\n\t\t\ttry {\n\t\t\t\timportCoverage(file);\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\tDragonHelper.showWarning(\"File not found\");\n\t\t\t}\n\t\t});\n\t}\n\t\n\tprivate int coverageIdToTableRow(int id) {\n\t\tfor (int i=0;i<dtm.getRowCount();i++) {\n\t\t\tif (((Number)dtm.getValueAt(i, 0)).intValue() == id)\n\t\t\t\treturn i;\n\t\t}\n\t\t\n\t\treturn -1;\n\t}\n\t\n\tprivate int getSelectedCoverageId() {\n\t\tint selIndex = table.getSelectedRow();\n\t\t\n\t\tif (selIndex > -1)\n\t\t{\n\t\t\tint id = ((Number)dtm.getValueAt(selIndex, 0)).intValue();\n\t\t\treturn id;\n\t\t}\n\t\t\n\t\treturn 0;\n\t}\n\t\n\tprivate int[] getSelectedCoverageIds() {\n\t\tint [] selIndexes = table.getSelectedRows();\n\t\tint [] ids = new int[selIndexes.length];\n\t\tint i=0;\n\t\t\n\t\tif (selIndexes.length > 0) {\n\t\t\tfor (int index : selIndexes) {\n\t\t\t\tids[i++] = ((Number)dtm.getValueAt(index, 0)).intValue();\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn ids;\n\t}\n\t\n\tprivate void onDeleteCoverageItemClick() {\n\t\tSession session = getSession();\n\t\t\n\t\tif (session == null)\n\t\t\treturn;\n\t\t\n\t\tint[] ids = getSelectedCoverageIds();\n\t\t\n\t\tif (ids.length == 0)\n\t\t\treturn;\n\t\t\n\t\tfor (int id : ids) {\n\t\t\tif (session.removeCoverageData(id))\n\t\t\t\tremoveFromCoverageTable(id);\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n\tprivate void onSwitchCoverageItemClick() {\n\t\tSession session = null;\n\t\tint id = getSelectedCoverageId();\n\t\t\n\t\tsession = getSession();\n\t\t\n\t\tif (session == null)\n\t\t\treturn;\n\t\t\n\t\tif (id > 0) {\n\t\t\tsession.setActiveCoverage(id);\n\t\t}\n\t}\n\t\n\tprivate CoverageData[] getSelectedCoverageObjects() {\n\t\tSession session = getSession();\n\t\t\n\t\tif (session == null)\n\t\t\treturn null;\n\t\t\n\t\tint[] ids = getSelectedCoverageIds();\n\t\t\n\t\tif (ids.length < 2) {\n\t\t\tDragonHelper.showWarning(StringResources.ATLEAST_2_COVERAGES);\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\tCoverageData[] coverages = new CoverageData[ids.length];\n\t\tint i=0;\n\t\t\n\t\tfor (int id : ids) {\n\t\t\tcoverages[i++] = session.getCoverage(id);\n\t\t}\n\t\n\t\treturn coverages;\n\t}\n\t\n\tprivate final static int OMT_INTERSECT=0;\n\tprivate final static int OMT_DIFF=1;\n\tprivate final static int OMT_DISTINCT=2;\n\tprivate final static int OMT_SUM=3;\n\t\n\tprivate void showMultiCoverageOperation(int type) {\n\t\tSession session = getSession();\n\t\tCoverageData[] coverages = null;\n\t\tCoverageData result = null;\n\t\t\n\t\tif (session == null) {\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tcoverages = getSelectedCoverageObjects();\n\t\t\n\t\tswitch (type) {\n\t\tcase OMT_INTERSECT:\n\t\t\tresult = CoverageData.intersect(coverages);\n\t\t\tbreak;\n\t\tcase OMT_DIFF:\n\t\t\tresult = CoverageData.difference(coverages);\n\t\t\tbreak;\n\t\tcase OMT_DISTINCT:\n\t\t\tresult = CoverageData.distinct(coverages);\n\t\t\tbreak;\n\t\tcase OMT_SUM:\n\t\t\tresult = CoverageData.sum(coverages);\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (result != null) {\n\t\t\tsession.setActiveCoverage(result);\n\t\t}\n\t\t\n\t}\n\t\n\t\n\tprivate void buildInfoPanel() {\n\t\t\n\t\tthis.txtGraph = new TextGraphic(infoPanelWidth,infoPanelHeight, panel.getBackground());\n\t\t\n\t\tthis.infoLabel = new JLabel() {\n\t\t\t@Override\n\t\t\tpublic void paintComponent(Graphics g) {\n\t\t\t\ttxtGraph.dispatch(g);\n\t\t\t}\n\t\t};\n\t\t\n\t\t\n\t\tthis.infoLabel.setBorder(BorderFactory.createCompoundBorder());\n\t\tthis.infoLabel.setBounds(15, lastY + 10, infoPanelWidth,infoPanelHeight);\n\t\tpanel.add(this.infoLabel);\n\t\t\n\t}\n\t\n\t\n\tprivate void buildScriptingUi() {\n\t\t\n\t\t\n\t\tif (this.txtScript == null) {\n\t\t\t\n\t\t\tthis.lastX += 15;\n\t\t\t\n\t\t\tthis.txtScript = new JTextArea();\n\t\t\tthis.txtScript.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));\n\t\t\tthis.txtScript.setWrapStyleWord(true);\n\t\t\t\n\t\t\tthis.scriptTextScrollPane = new JScrollPane(this.txtScript);\n\t\t\t\n\t\t\tthis.scriptTextScrollPane.setBounds(this.lastX, 5, getComponent().getWidth() - this.lastX - 20 , this.covTableHeight);\n\t\t\t\n\t\t\tthis.txtScript.addKeyListener(new KeyListener() {\n\t\n\t\t\t\t@Override\n\t\t\t\tpublic void keyTyped(KeyEvent e) {\n\t\t\t\t}\n\t\n\t\t\t\t@Override\n\t\t\t\tpublic void keyPressed(KeyEvent e) {\n\t\t\t\t\tif (e.getKeyCode() == KeyEvent.VK_ENTER && \n\t\t\t\t\t\t\t(e.getModifiersEx() & InputEvent.ALT_DOWN_MASK) == InputEvent.ALT_DOWN_MASK) {\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\tDragonDanceScripting.execute(txtScript.getText());\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\n\t\t\t\t@Override\n\t\t\t\tpublic void keyReleased(KeyEvent e) {\n\t\t\t\t\t\n\t\t\t\t}});\n\t\t\t\n\t\t\t\n\t\t\tFont fnt = null;\n\t\t\t\n\t\t\tfnt = getFont(14,Font.PLAIN,\"Consolas\",\"Courier New\",\"Times New Roman\");\n\t\t\t\n\t\t\tthis.txtScript.setFont(fnt);\n\t\t\t\n\t\t\tthis.panel.add(this.scriptTextScrollPane);\n\t\t\t\n\t\t\tthis.scriptTextScrollPane.setVisible(true);\n\t\t\tthis.txtScript.setVisible(true);\n\t\t\t\n\t\t\tthis.getComponent().repaint();\n\t\t\t\n\t\t\tthis.scriptShown=true;\n\t\t}\n\t\telse {\n\t\t\tthis.scriptShown = !this.scriptShown;\n\t\t\t\n\t\t\tthis.scriptTextScrollPane.setVisible(this.scriptShown);\n\t\t\t\n\t\t\tif (!this.scriptShown)\n\t\t\t\tDragonDanceScripting.discardScriptingSession(true);\n\t\t}\n\t}\n\t\n\tprivate void buildCoverageListView() {\n\t\t\n\t\tJPopupMenu contextMenu;\n\t\tJMenuItem miDelete,miSwitch;\n\t\tJMenuItem miShowIntersected,miShowDifferences,miShowDistinct,miShowSum;\n\t\t\n\t\tmiDelete = new JMenuItem(\"Delete\");\n\t\tmiSwitch = new JMenuItem(\"Switch to\");\n\t\t\n\t\tmiShowIntersected = new JMenuItem(\"Intersection\");\n\t\tmiShowDifferences = new JMenuItem(\"Difference\");\n\t\tmiShowDistinct = new JMenuItem(\"Distinct\");\n\t\tmiShowSum = new JMenuItem(\"Sum\");\n\t\t\n\t\tmiDelete.addActionListener(e -> {\n\t\t\tonDeleteCoverageItemClick();\n\t\t});\n\t\t\n\t\tmiSwitch.addActionListener(e -> {\n\t\t\tonSwitchCoverageItemClick();\n\t\t});\n\t\t\n\t\tmiShowIntersected.addActionListener(e -> {\n\t\t\tshowMultiCoverageOperation(OMT_INTERSECT);\n\t\t});\n\t\t\n\t\tmiShowDifferences.addActionListener(e -> {\n\t\t\tshowMultiCoverageOperation(OMT_DIFF);\n\t\t});\n\t\t\n\t\tmiShowDistinct.addActionListener(e -> {\n\t\t\tshowMultiCoverageOperation(OMT_DISTINCT);\n\t\t});\n\t\t\n\t\tmiShowSum.addActionListener(e -> {\n\t\t\tshowMultiCoverageOperation(OMT_SUM);\n\t\t});\n\t\t\n\t\tcontextMenu = new JPopupMenu();\n\t\t\n\t\tcontextMenu.add(miDelete);\n\t\tcontextMenu.add(miSwitch);\n\t\tcontextMenu.add(new JSeparator());\n\t\tcontextMenu.add(miShowIntersected);\n\t\tcontextMenu.add(miShowDifferences);\n\t\tcontextMenu.add(miShowDistinct);\n\t\tcontextMenu.add(miShowSum);\n\t\t\n\t\t\n\t\t\n\t\t\n\t\tdtm = new DefaultTableModel();\n\t\t\n\t\tdtm.addColumn(\"Coverage Id\");\n\t\tdtm.addColumn(\"Name\");\n\t\tdtm.addColumn(\"Source type\");\n\t\t\n\t\t\n\t\ttable = new GTable(dtm);\n\t\ttable.setComponentPopupMenu(contextMenu);\n\t\t\n\t\tscrollPane = new JScrollPane(table);\n\n\t\tscrollPane.setBounds(15, lastY, this.covTableWidth, this.covTableHeight);\n\t\ttable.setBounds(scrollPane.getBounds());\n\t\t\n\t\tlastY += this.covTableHeight;\n\t\t\n\t\ttable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);\n\t\t\n\t\ttable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {\n\n\t\t\t@Override\n\t\t\tpublic void valueChanged(ListSelectionEvent e) {\n\t\t\t\t\n\t\t\t\tint id = getSelectedCoverageId();\n\t\t\t\t\n\t\t\t\tif (id > 0)\n\t\t\t\t\tdrawSelectedCoverageDataInfo(id);\n\t\t\t}\n\t\t\t\n\t\t});\n\t\t\n\t\tpanel.add(scrollPane);\n\t}\n\t\n\t\n\tprivate void createUi() {\n\t\tthis.panel = new JPanel();\n\t\tthis.panel.setLayout(null);\n\t\tthis.panel.setSize(700, 500);\n\t\t\n\t\tbuildCoverageListView();\n\n\t\tbuildInfoPanel();\n\t\t\n\t\tlastX += this.covTableWidth ;\n\t\t\n\t\tsetVisible(true);\n\t\t\n\t}\n\n\t@Override\n\tpublic JComponent getComponent() {\n\t\treturn this.panel;\n\t}\n\t\n\t@Override\n\tpublic void componentActivated() {\n\t\n\t}\n\t\n\t@Override\n\tpublic void componentHidden() {\n\t\n\t}\n\t\n\t@Override\n\tpublic void componentShown() {\n\t\n\t}\n\t\n\t//ComponentListener implementations\n\t\n\t@Override\n\tpublic void componentResized(ComponentEvent e) {\n\t\tif (this.scriptShown) {\n\t\t\tRectangle oldbound;\n\t\t\toldbound = this.scriptTextScrollPane.getBounds();\n\t\t\tint scriptTextWidth = getComponent().getWidth() - oldbound.x;\n\t\t\t\n\t\t\tscriptTextWidth -= 20;\n\t\t\t\n\t\t\toldbound.width = scriptTextWidth;\n\t\t\t\n\t\t\tthis.scriptTextScrollPane.setBounds(oldbound);\n\t\t}\n\t}\n\n\t@Override\n\tpublic void componentMoved(ComponentEvent e) {\n\t\t\n\t}\n\n\t@Override\n\tpublic void componentShown(ComponentEvent e) {\n\t\t\n\t}\n\n\t@Override\n\tpublic void componentHidden(ComponentEvent e) {\n\t\t\n\t}\n\n\t//------------------------------------\n\t//Gui related operation interface to the dragondance scripting\n\t@Override\n\tpublic CoverageData loadCoverage(String coverageDataFile) throws FileNotFoundException {\n\t\treturn importCoverage(coverageDataFile);\n\t}\n\n\t@Override\n\tpublic boolean removeCoverage(int id) {\n\t\t\n\t\tSession session = getSession();\n\t\t\n\t\tif (session == null)\n\t\t\treturn false;\n\t\t\n\t\tif (session.removeCoverageData(id))\n\t\t\tremoveFromCoverageTable(id);\n\t\telse\n\t\t\treturn false;\n\t\t\n\t\treturn true;\n\t}\n\n\t@Override\n\tpublic boolean visualizeCoverage(CoverageData coverage) {\n\t\t\n\t\tSession session = getSession();\n\t\t\n\t\tif (session == null) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tif (coverage == null) {\n\t\t\tsession.setActiveCoverage(null);\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\tif (coverage.getRangeCount() > 0) {\n\t\t\treturn session.setActiveCoverage(coverage);\n\t\t}\n\t\t\n\t\tcoverage.closeNothrow();\n\t\t\n\t\tDragonHelper.showWarning(\"result coverage empty, so there is no data to show\");\n\t\t\n\t\treturn false;\n\t}\n\t\n\t@Override\n\tpublic boolean goTo(long offset) {\n\t\tboolean success = DragonHelper.goToAddress(DragonHelper.getImageBase().getOffset() + offset);\n\t\t\n\t\tif (!success) {\n\t\t\tDragonHelper.showWarning(\"offset 0x%x is not valid\",offset);\n\t\t}\n\t\t\n\t\treturn success;\n\t}\n\n\n\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/impl/BuiltinFunctionCwd.java\npackage dragondance.scripting.functions.impl;\n\nimport dragondance.datasource.CoverageData;\nimport dragondance.scripting.DragonDanceScripting;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\npublic class BuiltinFunctionCwd extends BuiltinFunctionBase {\n\n\tpublic BuiltinFunctionCwd() {\n\t\tsuper(\"cwd\");\n\t}\n\t\n\t@Override\n\tpublic int requiredArgCount(boolean minimum) {\n\t\treturn 1;\n\t}\n\t\n\t@Override\n\tpublic boolean hasReturnType() {\n\t\treturn false;\n\t}\n\t\n\t@Override\n\tpublic CoverageData execute() {\n\t\tString[] finalArgs = getStringArguments();\n\t\t\n\t\tDragonDanceScripting.setWorkingDirectory(finalArgs[0]);\n\t\t\n\t\treturn super.execute();\n\t}\n\t\n}\n\n<file_path>src/main/java/dragondance/scripting/functions/impl/BuiltinFunctionImport.java\npackage dragondance.scripting.functions.impl;\n\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.nio.file.Paths;\nimport dragondance.datasource.CoverageData;\nimport dragondance.eng.session.Session;\nimport dragondance.eng.session.SessionManager;\nimport dragondance.exceptions.DragonDanceScriptRuntimeException;\nimport dragondance.scripting.DragonDanceScripting;\nimport dragondance.scripting.functions.BuiltinAlias;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\n\n\n@BuiltinAlias(aliases = { \"load\",\"get\" })\npublic class BuiltinFunctionImport extends BuiltinFunctionBase {\n\n\tpublic BuiltinFunctionImport() {\n\t\tsuper(\"import\");\n\t}\n\t\n\t@Override\n\tpublic int requiredArgCount(boolean minimum) {\n\t\treturn 1; \n\t}\n\t\n\t\n\tprivate String prepareFilePath(String inpFile) {\n\t\tFile file = new File(inpFile);\n\t\t\n\t\tif (file.exists())\n\t\t\treturn inpFile;\n\t\t\n\t\tif (file.isAbsolute())\n\t\t\treturn inpFile;\n\t\t\n\t\tif (DragonDanceScripting.workingDirectory == null)\n\t\t\treturn inpFile;\n\t\t\n\t\treturn Paths.get(DragonDanceScripting.workingDirectory, inpFile).toString();\n\t}\n\t\n\tprivate CoverageData loadCoverage(String fileOrName) throws FileNotFoundException {\n\t\tString prepFile;\n\t\tCoverageData coverage=null;\n\t\tSession session = SessionManager.getActiveSession();\n\t\t\n\t\tif (session == null)\n\t\t\treturn null;\n\t\t\n\t\tif (fileOrName.contains(File.separator) | fileOrName.contains(\".\")) {\n\t\t\tprepFile = prepareFilePath(fileOrName);\n\t\t\t\n\t\t\tcoverage = session.tryGetPreviouslyLoadedCoverage(prepFile);\n\t\t\t\n\t\t\tif (coverage != null)\n\t\t\t\treturn coverage;\n\t\t\t\n\t\t\treturn guiSvc.loadCoverage(prepFile);\n\t\t}\n\t\t\n\t\treturn session.getCoverageByName(fileOrName);\n\t}\n\t\n\t@Override\n\tpublic CoverageData execute() {\n\t\tString[] finalArgs = getStringArguments();\n\t\t\n\t\tCoverageData coverage;\n\t\t\n\t\ttry {\n\t\t\tcoverage = loadCoverage(finalArgs[0]);\n\t\t} catch (FileNotFoundException e) {\n\t\t\tthrow new DragonDanceScriptRuntimeException(String.format(\"\\\"%s\\\" not found\", finalArgs[0]));\n\t\t}\n\t\t\t\n\t\tsetReturn(coverage);\n\t\t\n\t\treturn super.execute();\n\t}\n}\n\n<file_path>src/main/java/dragondance/scripting/DragonDanceScripting.java\npackage dragondance.scripting;\n\nimport java.lang.reflect.InvocationTargetException;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\n\nimport dragondance.Log;\nimport dragondance.components.GuiAffectedOpInterface;\nimport dragondance.datasource.CoverageData;\nimport dragondance.eng.DragonHelper;\nimport dragondance.exceptions.ScriptParserException;\nimport dragondance.scripting.functions.BuiltinAlias;\nimport dragondance.scripting.functions.BuiltinFunctionBase;\nimport dragondance.scripting.functions.impl.BuiltinFunctionClear;\nimport dragondance.scripting.functions.impl.BuiltinFunctionCwd;\nimport dragondance.scripting.functions.impl.BuiltinFunctionDiff;\nimport dragondance.scripting.functions.impl.BuiltinFunctionDiscard;\nimport dragondance.scripting.functions.impl.BuiltinFunctionDistinct;\nimport dragondance.scripting.functions.impl.BuiltinFunctionGoto;\nimport dragondance.scripting.functions.impl.BuiltinFunctionImport;\nimport dragondance.scripting.functions.impl.BuiltinFunctionIntersect;\nimport dragondance.scripting.functions.impl.BuiltinFunctionShow;\nimport dragondance.scripting.functions.impl.BuiltinFunctionSum;\nimport dragondance.util.Util;\n\n\npublic class DragonDanceScripting {\n\tpublic final static HashMap<String,Class<?>> builtinFunctions;\n\tpublic static List<ScriptExecutionUnit> executionUnits;\n\tpublic static HashMap<String, ScriptVariable> variables;\n\tpublic static String workingDirectory;\n\tpublic static String scriptHash = \"\";\n\t\n\tstatic {\n\t\tbuiltinFunctions = new HashMap<String,Class<?>>();\n\t\texecutionUnits = new ArrayList<ScriptExecutionUnit>();\n\t\tvariables = new HashMap<String, ScriptVariable>();\n\t\t\n\t\tregisterBuiltin(\"intersect\", BuiltinFunctionIntersect.class);\n\t\tregisterBuiltin(\"diff\",BuiltinFunctionDiff.class);\n\t\tregisterBuiltin(\"sum\",BuiltinFunctionSum.class);\n\t\tregisterBuiltin(\"distinct\",BuiltinFunctionDistinct.class);\n\t\tregisterBuiltin(\"import\",BuiltinFunctionImport.class);\n\t\tregisterBuiltin(\"cwd\",BuiltinFunctionCwd.class);\n\t\tregisterBuiltin(\"show\",BuiltinFunctionShow.class);\n\t\tregisterBuiltin(\"discard\",BuiltinFunctionDiscard.class);\n\t\tregisterBuiltin(\"goto\",BuiltinFunctionGoto.class);\n\t\tregisterBuiltin(\"clear\",BuiltinFunctionClear.class);\n\t}\n\t\n\tprivate static void discardExecutionUnits() {\n\t\tfor (ScriptExecutionUnit seu : executionUnits) \n\t\t\tseu.discard();\n\t\t\n\t\texecutionUnits.clear();\n\t\t\n\t\tscriptHash = \"\";\n\t}\n\t\n\tprivate static void registerBuiltin(String name, Class<?> clazz) {\n\t\t\n\t\tBuiltinAlias aliases = clazz.getAnnotation(BuiltinAlias.class);\n\t\t\n\t\tbuiltinFunctions.put(name, clazz);\n\t\t\n\t\tif (aliases != null) {\n\t\t\tfor (String alias : aliases.aliases()) {\n\t\t\t\tbuiltinFunctions.put(alias,clazz);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static boolean isBuiltin(String str) {\n\t\treturn builtinFunctions.containsKey(str.toLowerCase());\n\t}\n\t\n\tpublic static BuiltinFunctionBase newInstance(String func, GuiAffectedOpInterface guisvc) {\n\t\tBuiltinFunctionBase funcImpl;\n\t\tClass<?> clazz = null;\n\t\t\n\t\tfunc = func.toLowerCase();\n\t\t\n\t\tif (!builtinFunctions.containsKey(func)) {\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\tclazz = builtinFunctions.get(func);\n\t\t\n\t\ttry {\n\t\t\tfuncImpl = (BuiltinFunctionBase)clazz.getDeclaredConstructor().newInstance();\n\t\t} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException\n\t\t\t\t| NoSuchMethodException | SecurityException e) {\n\t\t\tLog.println(\"type activation error: %s\",e.getMessage());\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\tfuncImpl.setGuiApi(guisvc);\n\t\t\n\t\treturn funcImpl;\n\t}\n\t\n\tpublic static void addExecutionUnit(ScriptExecutionUnit unit) {\n\t\texecutionUnits.add(unit);\n\t}\n\t\n\tpublic static void removeVariable(ScriptVariable var) {\n\t\tvariables.remove(var.getName().toLowerCase());\n\t}\n\t\n\tpublic static void removeVariableByName(String name) {\n\t\tname = name.toLowerCase();\n\t\t\n\t\tif (!variables.containsKey(name))\n\t\t\treturn;\n\t\t\n\t\tvariables.remove(name);\n\t}\n\t\n\tpublic static boolean addVariable(ScriptVariable var) {\n\t\tif (variables.containsKey(var.getName().toLowerCase()))\n\t\t\treturn false;\n\t\t\n\t\tvariables.put(var.getName().toLowerCase(), var);\n\t\treturn true;\n\t}\n\t\n\tpublic static boolean isVariableDeclared(String varName) {\n\t\treturn variables.containsKey(varName.toLowerCase());\n\t}\n\t\n\tpublic static ScriptVariable getVariable(String varName) {\n\t\tif (!isVariableDeclared(varName))\n\t\t\treturn null;\n\t\t\n\t\treturn variables.get(varName.toLowerCase());\n\t}\n\t\n\tpublic static void setGuiAffectedInterface(GuiAffectedOpInterface gai) {\n\t\tDragonDanceScriptParser.setGuiSvc(gai);\n\t}\n\t\n\tpublic static void discardScriptingSession(boolean discardVariablesAlso) {\n\t\tdiscardExecutionUnits();\n\t\t\n\t\tif (discardVariablesAlso) {\n\t\t\tObject[] vars = variables.values().toArray();\n\t\t\t\n\t\t\t//We don't need to clear variables map. cuz discard method removes\n\t\t\t//the scriptvariable from the variable map\n\t\t\t\n\t\t\tfor (Object var : vars)\n\t\t\t\t((ScriptVariable)var).discard();\n\t\t\t\n\t\t}\n\t}\n\t\n\tpublic static boolean execute(String script) {\n\t\t\n\t\tboolean result = true;\n\t\tString shash = Util.md5(script);\n\t\t\n\t\tif (!shash.equals(scriptHash)) {\n\t\t\t\n\t\t\tdiscardExecutionUnits();\n\t\t\t\n\t\t\tDragonDanceScriptParser parser = new DragonDanceScriptParser();\n\t\t\t\n\t\t\ttry {\n\t\t\t\tparser.start(script);\n\t\t\t} catch (ScriptParserException e1) {\n\t\t\t\tDragonHelper.showWarning(e1.getMessage());\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tscriptHash = shash;\n\t\t}\n\t\t\n\t\ttry {\n\t\t\tfor (ScriptExecutionUnit execUnit : executionUnits) {\n\t\t\t\tif (!execUnit.execute()) {\n\t\t\t\t\tresult = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\t\n\t\t\tDragonHelper.showWarning(e.getMessage());\n\t\t\t\n\t\t\tdiscardExecutionUnits();\n\t\t\t\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\treturn result;\n\t}\n\t\n\tpublic static void setWorkingDirectory(String dir) {\n\t\tworkingDirectory = dir;\n\t}\n\t\n\tpublic static void removeCoverage(CoverageData cov) {\n\t\t\n\t\tif (cov.isLogicalCoverageData())\n\t\t\treturn;\n\t\t\n\t\tDragonDanceScriptParser.getGAI().removeCoverage(cov.getSourceId());\n\t}\n\t\n}\n\n<file_path>src/main/java/dragondance/DragondancePlugin.java\npackage dragondance;\n\nimport dragondance.components.MainDockProvider;\nimport dragondance.eng.DragonHelper;\nimport dragondance.eng.Painter;\nimport dragondance.eng.session.Session;\nimport dragondance.eng.session.SessionManager;\nimport dragondance.scripting.DragonDanceScripting;\nimport ghidra.app.plugin.PluginCategoryNames;\nimport ghidra.app.plugin.ProgramPlugin;\nimport ghidra.framework.plugintool.*;\nimport ghidra.framework.plugintool.util.PluginStatus;\nimport ghidra.program.flatapi.FlatProgramAPI;\nimport ghidra.program.model.listing.Program;\n\n\n//@formatter:off\n@PluginInfo(\n\tstatus = PluginStatus.STABLE,\n\tpackageName = DragondancePluginPackage.NAME,\n\tcategory = PluginCategoryNames.MISC,\n\tshortDescription = \"code coverage visualizer\",\n\tdescription = \"this plugin visualizes binary coverage data that are \" +\n\t\t\t\t\t\"collected by Dynamorio or Intel Pin binary instrumentation tools\"\n)\n//@formatter:on\npublic class DragondancePlugin extends ProgramPlugin {\n\tFlatProgramAPI api;\n\tMainDockProvider mainDock;\n\t\n\t\n\tpublic DragondancePlugin(PluginTool tool) {\n\t\tsuper(tool, true, true);\n\t\t\n\t\tmainDock = new MainDockProvider(tool,getName());\n\t\t\n\t}\n\n\t@Override\n\tpublic void init() {\n\t\tsuper.init();\t\n\t}\n\t\n\t@Override\n\tpublic void programActivated(Program program) {\n\t\tsuper.programActivated(program);\n\t\t\n\t\tapi = new FlatProgramAPI(this.currentProgram);\n\t\t\n\t\tDragonHelper.init(tool, api);\n\t\t\n\t\tif (Globals.EnableLogging) {\n\t\t\tLog.setEnable(true);\n\t\t\t\n\t\t\tif (Globals.EnableLoggingFileOutput)\n\t\t\t\tLog.enableFileLogging(true);\n\t\t\t\n\t\t\tif (Globals.EnableGhidraConsoleOutput)\n\t\t\t\tLog.enableGhidraConsoleLogging(true);\n\t\t\t\n\t\t\tif (Globals.DebugMode)\n\t\t\t\tLog.enableDebug(true);\n\t\t\t\n\t\t\tif (Globals.EnableStdoutLog)\n\t\t\t\tLog.enableStdoutLogging(true);\n\t\t\t\n\t\t}\n\t\t\n\t\t//Multi-session logic implemented but not usable from the GUI.\n\t\t//So create a single unnamed session to get things work right.\n\t\tSession.createNew(\"Unnamed session\", DragonHelper.getProgramName());\n\t\t\n\t\tSessionManager.getActiveSession().setPainter(new Painter());\n\t\t\n\t}\n\t\n\t@Override\n\tpublic void programClosed(Program program) {\n\t\t\n\t\tDragonDanceScripting.discardScriptingSession(true);\n\t\t\n\t\ttry {\n\t\t\tSessionManager.getActiveSession().close();\n\t\t} catch (Exception e) {\n\t\t\t\n\t\t}\n\t\t\n\t\t//TODO: this is temporary. \n\t\t\n\t\tsuper.programClosed(program);\n\t\t\n\t}\n\t\n\t@Override\n\tpublic void dispose() {\n\t\tsuper.dispose();\n\t\t\n\t\tLog.done();\n\t\t\n\t}\n}\n\n<file_path>src/main/java/dragondance/datasource/BlockEntry.java\npackage dragondance.datasource;\n\npublic class BlockEntry {\n\tprivate int offset;\n\tprivate int size;\n\tprivate int mid;\n\tprivate int instCount;\n\t\n\tpublic BlockEntry(int entryOffset, int entrySize, int moduleId, int instructionCount) {\n\t\tthis.offset=entryOffset;\n\t\tthis.size=entrySize;\n\t\tthis.mid=moduleId;\n\t\tthis.instCount=instructionCount;\n\t}\n\t\n\tpublic final int getOffset() {\n\t\treturn this.offset;\n\t}\n\t\n\tpublic final int getSize() {\n\t\treturn this.size;\n\t}\n\t\n\tpublic final int getModuleId() {\n\t\treturn this.mid;\n\t}\n\t\n\tpublic final int getInstructionCount() {\n\t\treturn this.instCount;\n\t}\n}\n\n<file_path>src/main/java/dragondance/datasource/CommonDatabaseDataSource.java\npackage dragondance.datasource;\n\nimport java.io.FileNotFoundException;\n\n/*\n Database file format\n \n */\n\npublic class CommonDatabaseDataSource extends CoverageDataSource {\n\n\tpublic CommonDatabaseDataSource(String sourceFile) throws FileNotFoundException {\n\t\tsuper(sourceFile, null,-1);\n\t}\n\t\n\t\n\n}\n\n<file_path>src/main/java/dragondance/datasource/ModuleInfo.java\npackage dragondance.datasource;\n\npublic class ModuleInfo {\n\tprivate int id;\n\tprivate int c_id;\n\tprivate long base;\n\tprivate long end;\n\tprivate String path;\n\t\n\tpublic ModuleInfo(int mid, long mBase, long mEnd, String mPath) {\n\t\tthis(mid,0,mBase,mEnd,mPath);\n\t}\n\t\n\tpublic ModuleInfo(int mid, int cid, long mBase, long mEnd, String mPath) {\n\t\tthis.id=mid;\n\t\tthis.c_id = cid;\n\t\tthis.base = mBase;\n\t\tthis.end = mEnd;\n\t\tthis.path = mPath;\n\t}\n\t\n\tpublic static ModuleInfo make(String id, String cid, String mbase, String mend, String mpath) {\n\t\tModuleInfo mod = new ModuleInfo(-1,-1,0,0,mpath);\n\t\t\n\t\t\n\t\ttry\n\t\t{\n\t\t\tmod.id = Integer.parseInt(id);\n\t\t\tmod.base = Long.parseLong(mbase.replace(\"0x\", \"\"), 16);\n\t\t\tmod.end = Long.parseLong(mend.replace(\"0x\",\"\"),16);\n\t\t\t\n\t\t\tif (cid != null && !cid.isEmpty())\n\t\t\t\tmod.c_id = Integer.parseInt(cid);\n\t\t}\n\t\tcatch (NumberFormatException e) {\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\treturn mod;\n\t}\n\t\n\tpublic static ModuleInfo make(String id, String mbase, String mend, String mpath) {\n\t\treturn make(id,null,mbase,mend,mpath);\n\t}\n\n\tpublic final boolean hasContainingId() {\n\t\treturn c_id > -1;\n\t}\n\t\n\tpublic int getContainingId() {\n\t\treturn c_id;\n\t}\n\t\n\tpublic int getId() {\n\t\treturn id;\n\t}\n\t\n\tpublic long getBase() {\n\t\treturn base;\n\t}\n\n\tpublic long getEnd() {\n\t\treturn end;\n\t}\n\n\tpublic String getPath() {\n\t\treturn path;\n\t}\n\t\n}\n\n<file_path>src/main/java/dragondance/eng/InstructionContext.java\npackage dragondance.eng;\n\nimport ghidra.program.model.listing.CodeUnit;\nimport ghidra.program.model.listing.Instruction;\n\npublic class InstructionContext {\n\t@SuppressWarnings(\"unused\")\n\tprivate Instruction instruction;\n\tprivate CodeUnit codeUnit;\n\tprivate InstructionInfo info;\n\t\n\tpublic InstructionContext(Instruction inst, CodeUnit cu, InstructionInfo info) {\n\t\tthis.instruction = inst;\n\t\tthis.codeUnit = cu;\n\t\t\n\t\tif (info == null) {\n\t\t\tinfo = new InstructionInfo(null,inst.getAddress().getOffset(),cu.getLength(),0);\n\t\t}\n\t\t\n\t\tthis.info = info;\n\t}\n\t\n\tpublic InstructionContext(Instruction inst, CodeUnit cu) {\n\t\tthis(inst,cu,null);\n\t}\n\t\n\tpublic final int getSize() {\n\t\treturn this.codeUnit.getLength();\n\t}\n\t\n\tpublic final long getAddress() {\n\t\treturn this.info.getAddr();\n\t}\n}\n\n<file_path>src/main/java/dragondance/DragondancePluginPackage.java\npackage dragondance;\n\nimport ghidra.framework.plugintool.util.PluginPackage;\n\npublic class DragondancePluginPackage extends PluginPackage {\n\n\tpublic static final String NAME=\"dragondance\";\n\t\n\tpublic DragondancePluginPackage() {\n\t\tsuper(NAME, null, \"dragondance plugin package\");\n\t}\n}\n\n" ]
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
33
Edit dataset card