### Complete Example Script Source: https://context7.com/daenerys-sre/source/llms.txt A comprehensive example demonstrating multiple Daenerys API functions working together for analysis. ```APIDOC ## Complete Example Script ### Description A comprehensive example demonstrating multiple Daenerys API functions working together, including getting the current location, program boundaries, and memory content. ### Method N/A (Script Execution) ### Endpoint N/A ### Parameters N/A ### Request Example ```python # Daenerys IDAPython complete example #@category Daenerys.IDAPython.Examples import idc import idaapi def analyze_current_location(): """Analyze the current cursor location""" print("=" * 50) print("Daenerys Analysis Report") print("=" * 50) # Get current position ea = idc.here() print("\n[Location Info]") print("Current address: 0x%x" % ea) # Program boundaries print("\n[Program Boundaries]") print("Min address: 0x%x" % idc.MinEA()) print("Max address: 0x%x" % idc.MaxEA()) print("BADADDR: 0x%x" % idc.BADADDR) # Memory content at current location print("\n[Memory Content at 0x%x]" % ea) bytes_hex = [] bytes_ascii = [] for i in range(16): b = idc.Byte(ea + i) bytes_hex.append("%02x" % b) bytes_ascii.append(chr(b) if 32 <= b < 127 else '.') print("Hex: %s" % ' '.join(bytes_hex)) print("ASCII: %s" % ''.join(bytes_ascii)) # Validate address print("\n[Validation]") if ea != idc.BADADDR and idc.MinEA() <= ea <= idc.MaxEA(): print("Address 0x%x is valid and within program bounds" % ea) else: print("Address validation failed") print("=" * 50) # Run analysis analyze_current_location() ``` ### Response #### Success Response (200) N/A (Script execution output) #### Response Example ```text ================================================== Daenerys Analysis Report ================================================== [Location Info] Current address: 0x401000 [Program Boundaries] Min address: 0x400000 Max address: 0x40f000 BADADDR: 0xffffffffffffffff [Memory Content at 0x401000] Hex: 55 8b ec 83 ec 10 53 56 57 8b 7d 08 85 ff 74 4a ASCII: U..........}..tJ [Validation] Address 0x401000 is valid and within program bounds ================================================== ``` ``` -------------------------------- ### Run IDAPython script in Ghidra Source: https://github.com/daenerys-sre/source/blob/master/README.md Example script demonstrating basic IDAPython API usage within the Ghidra environment. ```python # Daenerys IDAPython example script #@category Daenerys.IDAPython.Examples import idc print("Hello world from Ghidra...") print("Current address is: %x" % idc.here()) print("Min address: %x - Max address: %x" % (idc.MinEA(), idc.MaxEA())) print("Byte at current address is: %02x" % idc.Byte(idc.here())) print("BADADDR=%x" % idc.BADADDR) ``` -------------------------------- ### Complete Daenerys IDAPython Analysis Script Source: https://context7.com/daenerys-sre/source/llms.txt A comprehensive example demonstrating location analysis, boundary checking, and memory inspection. ```python # Daenerys IDAPython complete example #@category Daenerys.IDAPython.Examples import idc import idaapi def analyze_current_location(): """Analyze the current cursor location""" print("=" * 50) print("Daenerys Analysis Report") print("=" * 50) # Get current position ea = idc.here() print("\n[Location Info]") print("Current address: 0x%x" % ea) # Program boundaries print("\n[Program Boundaries]") print("Min address: 0x%x" % idc.MinEA()) print("Max address: 0x%x" % idc.MaxEA()) print("BADADDR: 0x%x" % idc.BADADDR) # Memory content at current location print("\n[Memory Content at 0x%x]" % ea) bytes_hex = [] bytes_ascii = [] for i in range(16): b = idc.Byte(ea + i) bytes_hex.append("%02x" % b) bytes_ascii.append(chr(b) if 32 <= b < 127 else '.') print("Hex: %s" % ' '.join(bytes_hex)) print("ASCII: %s" % ''.join(bytes_ascii)) # Validate address print("\n[Validation]") if ea != idc.BADADDR and idc.MinEA() <= ea <= idc.MaxEA(): print("Address 0x%x is valid and within program bounds" % ea) else: print("Address validation failed") print("=" * 50) # Run analysis analyze_current_location() ``` -------------------------------- ### Install Daenerys Adapter Scripts Source: https://context7.com/daenerys-sre/source/llms.txt Copy the adapter scripts from the 'ida' folder to your Ghidra Jython scripts path. Ensure the required files (idaapi.py, idc.py, daenerys_utils.py) are present. ```python # Copy files to Ghidra scripts directory: # Windows: C:\Users\[username]\.ghidra\.ghidra-9.0\dev\ghidra_scripts\bin # Or add the path via Ghidra's Script Manager window # Required files: # - idaapi.py (core API adapter) # - idc.py (IDA convenience functions adapter) # - daenerys_utils.py (utility functions) ``` -------------------------------- ### idc.ScreenEA() - Get Screen Effective Address Source: https://context7.com/daenerys-sre/source/llms.txt Returns the effective address currently visible/selected on screen. Functionally identical to `idc.here()` but follows IDA Pro naming convention. ```APIDOC ## idc.ScreenEA() - Get Screen Effective Address ### Description Returns the effective address currently visible/selected on screen. Functionally identical to `idc.here()` but follows IDA Pro naming convention. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters None ### Request Example ```python import idc # Get the screen's current effective address ea = idc.ScreenEA() print("Screen EA: 0x%08x" % ea) # Navigate and analyze from current position if ea != idc.BADADDR: byte_value = idc.Byte(ea) print("Byte at screen position: 0x%02x" % byte_value) ``` ### Response #### Success Response (Address) - **ea** (integer) - The screen's current effective address. #### Response Example ``` Screen EA: 0x401000 Byte at screen position: 0x55 ``` ``` -------------------------------- ### idc.MinEA() and idc.MaxEA() - Get Program Address Bounds Source: https://context7.com/daenerys-sre/source/llms.txt Returns the minimum and maximum effective addresses used in the currently loaded program. Essential for iterating through program memory or validating address ranges. ```APIDOC ## idc.MinEA() and idc.MaxEA() - Get Program Address Bounds ### Description Returns the minimum and maximum effective addresses used in the currently loaded program. Essential for iterating through program memory or validating address ranges. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters None ### Request Example ```python import idc # Get program address boundaries min_addr = idc.MinEA() max_addr = idc.MaxEA() print("Program address range:") print("Min address: 0x%x" % min_addr) print("Max address: 0x%x" % max_addr) print("Program size: %d bytes" % (max_addr - min_addr)) ``` ### Response #### Success Response (Address Range) - **min_addr** (integer) - The minimum effective address of the program. - **max_addr** (integer) - The maximum effective address of the program. #### Response Example ``` Program address range: Min address: 0x400000 Max address: 0x40f000 Program size: 61440 bytes ``` ``` -------------------------------- ### Get Program Address Bounds with idc.MinEA() and idc.MaxEA() Source: https://context7.com/daenerys-sre/source/llms.txt Retrieves the minimum and maximum effective addresses of the loaded program. This is useful for iterating through program memory or validating address ranges. The program size can be calculated from these bounds. ```python import idc # Get program address boundaries min_addr = idc.MinEA() max_addr = idc.MaxEA() print("Program address range:") print("Min address: 0x%x" % min_addr) print("Max address: 0x%x" % max_addr) print("Program size: %d bytes" % (max_addr - min_addr)) # Output example: # Min address: 0x400000 # Max address: 0x40f000 # Program size: 61440 bytes ``` -------------------------------- ### Get Current Cursor Address with idc.here() Source: https://context7.com/daenerys-sre/source/llms.txt Retrieves the current cursor position (effective address) in the disassembly view. This function is equivalent to IDA Pro's `idc.here()` and maps to Ghidra's current address state. ```python #@category Daenerys.IDAPython.Examples import idc # Get the current cursor position in the disassembly current_ea = idc.here() print("Current address is: %x" % current_ea) # Output example: # Current address is: 401000 ``` -------------------------------- ### idc.here() - Get Current Cursor Address Source: https://context7.com/daenerys-sre/source/llms.txt Returns the current cursor position (effective address) in the disassembly view. This is equivalent to IDA Pro's `idc.here()` function and maps to Ghidra's current address state. ```APIDOC ## idc.here() - Get Current Cursor Address ### Description Returns the current cursor position (effective address) in the disassembly view. This is equivalent to IDA Pro's `idc.here()` function and maps to Ghidra's current address state. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters None ### Request Example ```python #@category Daenerys.IDAPython.Examples import idc # Get the current cursor position in the disassembly current_ea = idc.here() print("Current address is: %x" % current_ea) ``` ### Response #### Success Response (Address) - **current_ea** (integer) - The current effective address. #### Response Example ``` Current address is: 401000 ``` ``` -------------------------------- ### Get Screen Effective Address with idc.ScreenEA() Source: https://context7.com/daenerys-sre/source/llms.txt Returns the effective address currently visible or selected on screen. This function is functionally identical to `idc.here()` but uses IDA Pro's naming convention. It can be used to read byte values at the current screen position. ```python import idc # Get the screen's current effective address ea = idc.ScreenEA() print("Screen EA: 0x%08x" % ea) # Navigate and analyze from current position if ea != idc.BADADDR: byte_value = idc.Byte(ea) print("Byte at screen position: 0x%02x" % byte_value) ``` -------------------------------- ### idaapi.get_screen_ea() - Get Current Screen Address Source: https://context7.com/daenerys-sre/source/llms.txt Low-level function to retrieve the current screen address. Returns an `ea_t` object containing both the numeric address and the underlying Ghidra Address object. ```APIDOC ## idaapi.get_screen_ea() - Get Current Screen Address ### Description Low-level function to retrieve the current screen address. Returns an `ea_t` object containing both the numeric address and the underlying Ghidra Address object. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters None ### Request Example ```python import idaapi # Get current address with full ea_t object ea = idaapi.get_screen_ea() print("Current EA: 0x%x" % ea) # Access the underlying Ghidra Address object ghidra_addr = ea.address print("Ghidra Address object: %s" % ghidra_addr) ``` ### Response #### Success Response (Address Information) - **ea** (ea_t object) - An object containing the current effective address. - **ghidra_addr** (Ghidra Address object) - The underlying Ghidra Address object. #### Response Example ``` Current EA: 0x401000 Ghidra Address object: 0x0000000000401000 ``` ``` -------------------------------- ### Get Current Screen Address with idaapi.get_screen_ea() Source: https://context7.com/daenerys-sre/source/llms.txt A low-level function to retrieve the current screen address. It returns an `ea_t` object that contains both the numeric address and the underlying Ghidra Address object, allowing access to Ghidra-specific details. ```python import idaapi # Get current address with full ea_t object ea = idaapi.get_screen_ea() print("Current EA: 0x%x" % ea) # Access the underlying Ghidra Address object ghidra_addr = ea.address print("Ghidra Address object: %s" % ghidra_addr) ``` -------------------------------- ### Access Program Information via cvar.inf Source: https://context7.com/daenerys-sre/source/llms.txt Retrieves program-level metadata such as address boundaries using the inf structure. ```python import idaapi # Access program info through cvar.inf min_ea = idaapi.cvar.inf.min_ea max_ea = idaapi.cvar.inf.max_ea print("Program boundaries from cvar.inf:") print(" min_ea: 0x%x" % min_ea) print(" max_ea: 0x%x" % max_ea) # Calculate program size program_size = max_ea - min_ea print(" Total size: %d bytes (%.2f KB)" % (program_size, program_size / 1024.0)) ``` -------------------------------- ### idaapi.cvar.inf - Program Information Structure Source: https://context7.com/daenerys-sre/source/llms.txt Provides access to program-level information through the `inf` structure, including minimum and maximum addresses. ```APIDOC ## idaapi.cvar.inf ### Description Provides access to program-level information through the `inf` structure, including minimum and maximum addresses. ### Method N/A (Structure Access) ### Endpoint N/A ### Parameters N/A ### Request Example ```python import idaapi min_ea = idaapi.cvar.inf.min_ea max_ea = idaapi.cvar.inf.max_ea print("Program boundaries from cvar.inf:") print(" min_ea: 0x%x" % min_ea) print(" max_ea: 0x%x" % max_ea) program_size = max_ea - min_ea print(" Total size: %d bytes (%.2f KB)" % (program_size, program_size / 1024.0)) ``` ### Response #### Success Response (200) N/A (Accesses program information) #### Response Example ```json { "min_ea": "0x400000", "max_ea": "0x40f000", "program_size_bytes": 61440, "program_size_kb": 60.00 } ``` ``` -------------------------------- ### idaapi.ghidra_state() - Access Ghidra Script State Source: https://context7.com/daenerys-sre/source/llms.txt Returns the current Ghidra script execution state, providing access to Ghidra-specific functionality when needed. ```APIDOC ## idaapi.ghidra_state() ### Description Returns the current Ghidra script execution state, providing access to Ghidra-specific functionality when needed. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters N/A ### Request Example ```python import idaapi import sys state = idaapi.ghidra_state() current_addr = state.getCurrentAddress() print("State current address: %s" % current_addr) global_state = sys.__ghidra_state__ print("Global state matches: %s" % (state == global_state)) ``` ### Response #### Success Response (200) N/A (Returns the Ghidra script state) #### Response Example ```json { "current_address": "0x401000", "state_match": true } ``` ``` -------------------------------- ### idaapi.AddressToEA() - Convert Ghidra Address to EA Source: https://context7.com/daenerys-sre/source/llms.txt Converts a Ghidra Address object to an IDAPython-compatible effective address (ea_t). The returned ea_t preserves both the numeric value and the original Ghidra Address. ```APIDOC ## idaapi.AddressToEA() ### Description Converts a Ghidra Address object to an IDAPython-compatible effective address (`ea_t`). The returned `ea_t` preserves both the numeric value and the original Ghidra Address. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python import idaapi ghidra_addr = idaapi.ghidra_program_getMinAddress() ea = idaapi.AddressToEA(ghidra_addr) print("Converted address: 0x%x" % ea) print("Original Ghidra addr preserved: %s" % ea.address) ``` ### Response #### Success Response (200) N/A (Returns an effective address) #### Response Example ```json { "effective_address": "0x401000" } ``` ``` -------------------------------- ### idc.BADADDR - Invalid Address Constant Source: https://context7.com/daenerys-sre/source/llms.txt Constant representing an invalid address. Value depends on program bitness: `0xFFFFFFFF` for 32-bit programs, `0xFFFFFFFFFFFFFFFF` for 64-bit programs. ```APIDOC ## idc.BADADDR - Invalid Address Constant ### Description Constant representing an invalid address. Value depends on program bitness: `0xFFFFFFFF` for 32-bit programs, `0xFFFFFFFFFFFFFFFF` for 64-bit programs. ### Method N/A (Constant Value) ### Endpoint N/A ### Parameters None ### Request Example ```python import idc # Check if an address is valid def is_valid_address(ea): """Check if address is within program bounds and not BADADDR""" if ea == idc.BADADDR: return False return idc.MinEA() <= ea <= idc.MaxEA() # Example usage test_addr = idc.here() if test_addr != idc.BADADDR: print("Valid address: 0x%x" % test_addr) else: print("Invalid address detected") print("BADADDR value: 0x%x" % idc.BADADDR) ``` ### Response #### Success Response (Address Check) - **is_valid_address** (boolean) - True if the address is valid, False otherwise. - **BADADDR value** (integer) - The constant value representing an invalid address. #### Response Example ``` Valid address: 0x401000 BADADDR value: 0xffffffffffffffff ``` ``` -------------------------------- ### Convert Ghidra Address to EA Source: https://context7.com/daenerys-sre/source/llms.txt Translates a Ghidra Address object into an IDAPython-compatible effective address (ea_t). ```python import idaapi # Convert Ghidra Address to ea_t ghidra_addr = idaapi.ghidra_program_getMinAddress() ea = idaapi.AddressToEA(ghidra_addr) print("Converted address: 0x%x" % ea) print("Original Ghidra addr preserved: %s" % ea.address) ``` -------------------------------- ### idaapi.eaToAddress() - Convert EA to Ghidra Address Source: https://context7.com/daenerys-sre/source/llms.txt Converts an effective address (numeric or ea_t) back to a Ghidra Address object. Handles multiple input types: GenericAddress, ea_t, or plain numeric values. ```APIDOC ## idaapi.eaToAddress() ### Description Converts an effective address (numeric or `ea_t`) back to a Ghidra Address object. Handles multiple input types: GenericAddress, `ea_t`, or plain numeric values. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python import idaapi numeric_ea = 0x401000 ghidra_addr = idaapi.eaToAddress(numeric_ea) if ghidra_addr != idaapi.Address.NO_ADDRESS: print("Valid Ghidra address: %s" % ghidra_addr) print("Is memory address: %s" % ghidra_addr.isMemoryAddress()) else: print("Failed to convert address") ``` ### Response #### Success Response (200) N/A (Returns a Ghidra Address object) #### Response Example ```json { "ghidra_address": "0x401000", "is_memory_address": true } ``` ``` -------------------------------- ### Convert EA to Ghidra Address Source: https://context7.com/daenerys-sre/source/llms.txt Translates an effective address back into a Ghidra Address object, supporting multiple input types. ```python import idaapi # Convert numeric address to Ghidra Address numeric_ea = 0x401000 ghidra_addr = idaapi.eaToAddress(numeric_ea) if ghidra_addr != idaapi.Address.NO_ADDRESS: print("Valid Ghidra address: %s" % ghidra_addr) print("Is memory address: %s" % ghidra_addr.isMemoryAddress()) else: print("Failed to convert address") ``` -------------------------------- ### idc.Byte() - Read Byte from Memory Source: https://context7.com/daenerys-sre/source/llms.txt Reads a single byte from the specified effective address. Returns the byte value as an unsigned integer (0-255). ```APIDOC ## idc.Byte() - Read Byte from Memory ### Description Reads a single byte from the specified effective address. Returns the byte value as an unsigned integer (0-255). ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters - **ea** (integer) - Required - The effective address from which to read the byte. ### Request Example ```python import idc # Read a single byte at current address ea = idc.here() byte_val = idc.Byte(ea) print("Byte at 0x%x: 0x%02x" % (ea, byte_val)) # Read multiple consecutive bytes def read_bytes(start_ea, count): """Read multiple bytes from memory""" result = [] for i in range(count): result.append(idc.Byte(start_ea + i)) return result # Read first 16 bytes from current position bytes_data = read_bytes(idc.here(), 16) hex_dump = ' '.join('%02x' % b for b in bytes_data) print("Hex dump: %s" % hex_dump) ``` ### Response #### Success Response (Byte Value) - **byte_val** (integer) - The value of the byte read from the specified address (0-255). #### Response Example ``` Byte at 0x401000: 0x55 Hex dump: 55 8b ec 83 ec 10 53 56 57 8b 7d 08 85 ff 74 4a ``` ``` -------------------------------- ### Read Byte from Memory with idc.Byte() Source: https://context7.com/daenerys-sre/source/llms.txt Reads a single byte from a specified effective address, returning it as an unsigned integer (0-255). This function can be used to read multiple consecutive bytes by incrementing the address. ```python import idc # Read a single byte at current address ea = idc.here() byte_val = idc.Byte(ea) print("Byte at 0x%x: 0x%02x" % (ea, byte_val)) # Read multiple consecutive bytes def read_bytes(start_ea, count): """Read multiple bytes from memory""" result = [] for i in range(count): result.append(idc.Byte(start_ea + i)) return result # Read first 16 bytes from current position bytes_data = read_bytes(idc.here(), 16) hex_dump = ' '.join('%02x' % b for b in bytes_data) print("Hex dump: %s" % hex_dump) # Output example: # Byte at 0x401000: 0x55 # Hex dump: 55 8b ec 83 ec 10 53 56 57 8b 7d 08 85 ff 74 4a ``` -------------------------------- ### Access Ghidra Script State Source: https://context7.com/daenerys-sre/source/llms.txt Retrieves the current Ghidra script execution state for advanced operations. ```python import idaapi # Get Ghidra state for advanced operations state = idaapi.ghidra_state() # Access current program through state current_addr = state.getCurrentAddress() print("State current address: %s" % current_addr) # The state is also available globally via sys module import sys global_state = sys.__ghidra_state__ print("Global state matches: %s" % (state == global_state)) ``` -------------------------------- ### Read Memory Bytes with idaapi.get_wide_byte Source: https://context7.com/daenerys-sre/source/llms.txt Reads a byte from a specific address or a range of bytes. Handles conversion from signed to unsigned byte values. ```python import idaapi # Read byte using low-level API ea = idaapi.get_screen_ea() byte_val = idaapi.get_wide_byte(ea) print("Byte value: 0x%02x (%d)" % (byte_val, byte_val)) # Read a range of bytes def dump_memory(start_ea, length): """Dump memory contents as hex string""" hex_bytes = [] for offset in range(length): b = idaapi.get_wide_byte(start_ea + offset) hex_bytes.append("%02X" % b) return ' '.join(hex_bytes) print("Memory dump: %s" % dump_memory(ea, 8)) ``` -------------------------------- ### idaapi.get_wide_byte() - Read Byte Value Source: https://context7.com/daenerys-sre/source/llms.txt Reads a byte from memory at the specified effective address and handles the conversion from Ghidra's signed byte representation to unsigned. ```APIDOC ## idaapi.get_wide_byte() ### Description Reads a byte from memory at the specified effective address. Handles the conversion from Ghidra's signed byte representation to unsigned. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python import idaapi ea = idaapi.get_screen_ea() byte_val = idaapi.get_wide_byte(ea) print("Byte value: 0x%02x (%d)" % (byte_val, byte_val)) def dump_memory(start_ea, length): """Dump memory contents as hex string""" hex_bytes = [] for offset in range(length): b = idaapi.get_wide_byte(start_ea + offset) hex_bytes.append("%02X" % b) return ' '.join(hex_bytes) print("Memory dump: %s" % dump_memory(ea, 8)) ``` ### Response #### Success Response (200) N/A (Returns a byte value) #### Response Example ```json { "byte_value": 123 } ``` ``` -------------------------------- ### Invalid Address Constant idc.BADADDR Source: https://context7.com/daenerys-sre/source/llms.txt A constant representing an invalid address. Its value is `0xFFFFFFFF` for 32-bit programs and `0xFFFFFFFFFFFFFFFF` for 64-bit programs. It is used to check if an address is valid or within program bounds. ```python import idc # Check if an address is valid def is_valid_address(ea): """Check if address is within program bounds and not BADADDR""" if ea == idc.BADADDR: return False return idc.MinEA() <= ea <= idc.MaxEA() # Example usage test_addr = idc.here() if test_addr != idc.BADADDR: print("Valid address: 0x%x" % test_addr) else: print("Invalid address detected") print("BADADDR value: 0x%x" % idc.BADADDR) # Output example (64-bit): # Valid address: 0x401000 # BADADDR value: 0xffffffffffffffff ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.