API reference
ghidralib
This library is an attempt to provide a Pythonic standard library for Ghidra.
The main goal is to make writing quick&dirty scripts actually quick, and not that dirty.
There is no equivalent of FlatProgramAPI from GHidra. You are expected to start by getting an object of interest by calling instance methods, for example
>>> Function("main")
main
to get a function called "main". When you want to do something this library
doesn't support (yet), you can always excape back to Ghidra's wrapped Java
types, by getting a .raw
property, for example:
>>> Function("main").raw.UNKNOWN_STACK_DEPTH_CHANGE
2147483647
For more details, see the documentation at https://msm-code.github.io/ghidralib/.
Addr = GenericAddress | int | str
module-attribute
DataT = GhidraWrapper | JavaObject | str
module-attribute
HIGHLIGHT_COLOR = SearchConstants.SEARCH_HIGHLIGHT_COLOR
module-attribute
Reg = GhRegister | str
module-attribute
Str = (str, bytes, unicode)
module-attribute
T = TypeVar('T')
module-attribute
__version__ = '0.2.0'
module-attribute
bytes = str
module-attribute
interpreter = get_current_interpreter()
module-attribute
long = int
module-attribute
AddressRange
Bases: GhidraWrapper
Wraps a Ghidra AddressRange object.
Source code in ghidralib.py
1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 |
|
addresses
property
Return the addresses in this range.
end
property
Get the last address in this range.
is_empty
property
Return True if this range is empty.
length
property
Get the length of this range.
start
property
Get the first address in this range.
__and__(other)
Return the intersection of this range and the given range.
Source code in ghidralib.py
1884 1885 1886 |
|
__contains__(addr)
Return True if the given address is in this range.
Parameters: |
|
---|
Source code in ghidralib.py
1870 1871 1872 1873 |
|
__iter__()
Iterate over the addresses in this range.
Source code in ghidralib.py
1841 1842 1843 |
|
__len__()
Get the length of this range.
Source code in ghidralib.py
1860 1861 1862 |
|
__nonzero__()
Return True if this range is not empty.
Source code in ghidralib.py
1880 1881 1882 |
|
contains(addr)
Return True if the given address is in this range.
Parameters: |
|
---|
Source code in ghidralib.py
1864 1865 1866 1867 1868 |
|
AddressSet
Bases: GhidraWrapper
Wraps a Ghidra AddressSetView object.
Source code in ghidralib.py
1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 |
|
addresses
property
Return the addresses in this set.
is_empty
property
Return True if this range is empty.
ranges
property
__and__(other)
Return the intersection of this set and the given set.
Source code in ghidralib.py
1932 1933 1934 |
|
__contains__(addr)
Return True if the given address is in this range.
Source code in ghidralib.py
1919 1920 1921 |
|
__get_highlighter()
Source code in ghidralib.py
1948 1949 1950 1951 1952 1953 |
|
__iter__()
Source code in ghidralib.py
1912 1913 |
|
__nonzero__()
Return True if this range is not empty.
Source code in ghidralib.py
1928 1929 1930 |
|
__or__(other)
Computes the union of this set and the given set.
Source code in ghidralib.py
1944 1945 1946 |
|
__sub__(other)
Subtract the given set from this set.
Source code in ghidralib.py
1936 1937 1938 |
|
__xor__(other)
Computes the symmetric difference of this set and the given set.
Source code in ghidralib.py
1940 1941 1942 |
|
contains(addr)
Return True if the given address is in this range.
Source code in ghidralib.py
1915 1916 1917 |
|
create(start, length)
staticmethod
Create a new AddressSet with given address and length.
Source code in ghidralib.py
1897 1898 1899 1900 1901 |
|
empty()
staticmethod
Create a new empty address set
Source code in ghidralib.py
1892 1893 1894 1895 |
|
highlight(color=HIGHLIGHT_COLOR)
Source code in ghidralib.py
1955 1956 1957 |
|
unhighlight()
Source code in ghidralib.py
1959 1960 1961 |
|
BasicBlock
Bases: AddressSet
, BodyTrait
Wraps a Ghidra CodeBlock object
Source code in ghidralib.py
1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 |
|
address
property
Get the address of the first instruction in this basic block.
body
property
Get the address set of this basic block
Technically BasicBlock (CodeBlock) is is already an AddressSet, but I think this is a useful distinction to keep.
bytes
property
Get the bytes of this basic block.
Returns: |
|
---|
destinations
property
Get a list of basic blocks that this basic block jumps to
end_address
property
Get the address of the last byte in this basic block.
Note: this is not the address of the last instruction. Note: end_address - start_address is equal to length - 1. For example, for one-byte basic block, start_address == end_address.
flow_type
property
Get the flow type of this basic block.
In other words, if any weird things with control flow are happening in this node.
instructions
property
Get a list of instructions in this basic block.
length
property
Get the length of this basic block in bytes.
name
property
Get the name of this basic block.
Return the symbol at the start of this basic block, if any. Otherwise, return the address of the first instruction as string.
pcode
property
Get a list of Pcode operations that this basic block was parsed to
sources
property
Get a list of basic blocks that jump to this basic block
start_address
property
Get the address of the first instruction in this basic block.
__eq__(other)
Compare two basic blocks for equality.
Apparently Ghidra doesn't know how to do this
Source code in ghidralib.py
2097 2098 2099 2100 2101 2102 2103 2104 |
|
all(model='basic')
staticmethod
Get a list of all basic blocks in the program.
Source code in ghidralib.py
2006 2007 2008 2009 2010 |
|
get(raw_or_address, model='basic')
staticmethod
Get a BasicBlock object containing the given address, or return None.
This function is tolerant and will accept different types of arguments: * address as int * Address object * symbol as string (will be resolved) * BasicBlock object (wrapped or unwrapped)
Parameters: |
|
---|
Source code in ghidralib.py
1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 |
|
BlockGraph
Bases: PcodeBlock
Source code in ghidralib.py
1221 1222 1223 1224 |
|
blocks
property
BodyTrait
A trait for objects that have a body.
It provides generic methods that work with anything that has a body (an assigned set of addresses in the program), such as highlighting.
Source code in ghidralib.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
|
body
abstractmethod
property
The body of this object
highlight(color=HIGHLIGHT_COLOR)
Highlight this instruction in the listing.
Source code in ghidralib.py
732 733 734 |
|
unhighlight()
Clear the highlight from this instruction.
Source code in ghidralib.py
736 737 738 |
|
ClangTokenGroup
Bases: GhidraWrapper
Represents a group of clang tokens from a decompiler.
Warning: Currently this class is experimental, and should not be relied upon, except to get the Java object (with .raw) or maybe dump (.dump()).
Source code in ghidralib.py
2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 |
|
cleaned
property
Remove all whitespace and comments from this token group, recursively.
dump()
Source code in ghidralib.py
2410 2411 |
|
DataType
Bases: GhidraWrapper
Source code in ghidralib.py
3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 |
|
__len__ = length
class-attribute
instance-attribute
name
property
Get a name of this data type
>>> DataType('int').name
'int'
.
all(only_local=False)
staticmethod
Get all data types
Parameters: |
|
---|
Source code in ghidralib.py
3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 |
|
from_c(c_code, insert=True)
staticmethod
Parse C structure definition and return the parsed DataType.
If insert (true by default), add it to current program.
Example of a valid c_code is typedef void* HINTERNET;
>>> DataType.from_c('typedef void* HINTERNET;')
HINTERNET
>>> DataType.from_c("struct test { short a; short b; short c;};")
pack()
Structure test {
0 short 2 a ""
2 short 2 b ""
4 short 2 c ""
}
Length: 6 Alignment: 2
Parameters: |
|
---|
Source code in ghidralib.py
3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 |
|
get(name_or_raw)
staticmethod
Gets a data type by name, or returns None if not found.
Warning: this method is relatively slow, since it scans all data types in all data type managers.
>>> DataType.get("int")
int
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 |
|
get_name(value)
If this data type is an enum, get the name of the value.
Parameters: |
|
---|
Source code in ghidralib.py
3117 3118 3119 3120 3121 |
|
length()
Get the length of this data type in bytes
>>> DataType('int').length()
4
.
Source code in ghidralib.py
3123 3124 3125 3126 3127 3128 3129 3130 |
|
Emulator
Bases: GhidraWrapper
Wraps a Ghidra EmulatorHelper object.
Source code in ghidralib.py
3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 |
|
emu_start = lambda self, begin, until: self.emulate(begin, until)
class-attribute
instance-attribute
is_at_breakpoint
property
Check if the emulator is at a breakpoint
mem_map = lambda _1, _2, _3: None
class-attribute
instance-attribute
mem_read = read_bytes
class-attribute
instance-attribute
mem_write = write_bytes
class-attribute
instance-attribute
pc
property
writable
Get the program counter of the emulated program.
reg_read = read_register
class-attribute
instance-attribute
reg_write = write_register
class-attribute
instance-attribute
sp
property
writable
Get the current stack pointer register value.
sp_register
property
Get the stack pointer register name for the emulated architecture.
__getitem__(reg)
Read the register of the emulated program.
>>> emulator.write_register("eax", 1337)
>>> emulator["eax"]
1337
Parameters: |
|
---|
Source code in ghidralib.py
3248 3249 3250 3251 3252 3253 3254 3255 3256 |
|
__handle_hook_result(result)
Handle a hook return value and return True if emulation should stop.
Source code in ghidralib.py
3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 |
|
__init__()
Create a new Emulator object.
Source code in ghidralib.py
3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 |
|
__run_with_hooks()
Run the Ghidra emulator, and transparently handle all hooks.
Returns: |
|
---|
Source code in ghidralib.py
3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 |
|
__setitem__(reg, value)
Write to the register of the emulated program.
>>> emulator["eax"] = 1234
>>> emulator.read_register("eax")
1337
Parameters: |
|
---|
Source code in ghidralib.py
3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 |
|
add_breakpoint(address)
Add a breakpoint at the given address.
Parameters: |
|
---|
Source code in ghidralib.py
3517 3518 3519 3520 3521 |
|
add_hook(address, hook)
Add a hook at a specified address.
Hook is a function that gets emulator as parameter. It can return one of:
- 'continue' or None, to continue execution normally
- 'break' to stop execution
- 'skip' to skip the next instruction
Note: multiple hooks at the same address are not currently supported.
Source code in ghidralib.py
3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 |
|
clear_breakpoint(address)
Clear a breakpoint at the given address.
Parameters: |
|
---|
Source code in ghidralib.py
3523 3524 3525 3526 3527 |
|
delete_hook_at(address)
Source code in ghidralib.py
3206 3207 3208 |
|
emulate(start, ends=[], callback=lambda emu: None, stop_when=lambda emu: False, maxsteps=2 ** 48)
Emulate from start to end address, with callback for each executed address.
>>> emu = Emulator()
>>> def callback(emu):
>>> print("executing {:x}'.format(emu.pc))
>>> emu.emulate(Function("main").entrypoint, callback=callback, maxsteps=3)
SUB ESP,0x2d4
PUSH EBX
PUSH EBP
Callback should return one of:
- 'continue' or None, to continue execution normally
- 'break' to stop execution
- 'skip' to skip the next instruction
- 'retry' like continue, but call the callback again (useful after pc change)
- 'continue_then_break' to execute one last instruction before stopping
Returning another value will cause an exception Callback is executed before stop_when condition is checked.
This method is very flexible, but because of that it may be slower than pure Ghidra implementation. Consider .emulate_fast() when this method is too slow for you.
Parameters: |
|
---|
Source code in ghidralib.py
3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 |
|
emulate_fast(start, ends)
Emulate from start to end address, using Ghidra for fast emulation.
The main loop of this function is in Java, which makes it faster, but makes some features (like callbacks) impossible. This function stops on error, when PC reaches one of the ends, and will also call hooks.
This method will set a breakpoint at the end address, and clear it after the emulation is done.
>>> emulator.write_bytes(0x2000, "1")
>>> emulator.emulate_fast(0x1000, 0x1005)
>>> emulator.read_bytes(0x2000, 1)
'0'
Parameters: |
|
---|
Source code in ghidralib.py
3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 |
|
has_hook_at(address)
Source code in ghidralib.py
3202 3203 3204 |
|
new(start, ends=[], callback=lambda emu: None, stop_when=lambda emu: False, maxsteps=2 ** 48)
staticmethod
Emulate from start to end address, with callback for each executed address.
>>> Emulator.new("main", maxsteps=100)["EAX"]
128
This function is a convenience wrapper around emulate and can be always replaced by three lines of code. The above is equivalent to:
>>> emu = Emulator()
>>> emu.emulate("main", maxsteps=100)
>>> emu["EAX"]
128
This function may be used for quickly doing one-off emulations.
See emulate
documentation for info about this method parameters.
Source code in ghidralib.py
3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 |
|
read_bytes(address, length)
Read length
bytes at address
from the emulated program.
>>> emulator.write_bytes(0x1000, "1")
>>> emulator.read_bytes(0x1000, 1)
'1'
Parameters: |
|
---|
Source code in ghidralib.py
3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 |
|
read_cstring(address)
Read a null-terminated string from the emulated program.
This function reads bytes until a nullbyte is encountered.
>>> emu.read_cstring(0x1000)
'Hello, world!'
Parameters: |
|
---|
Source code in ghidralib.py
3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 |
|
read_register(reg)
Read from the register of the emulated program.
>>> emulator.write_register("eax", 1337)
>>> emulator.read_register("eax")
1337
Parameters: |
|
---|
Source code in ghidralib.py
3269 3270 3271 3272 3273 3274 3275 3276 3277 |
|
read_u16(address)
Read a 16bit unsigned integer from the emulated program.
>>> emulator.write_u16(0x1000, 123)
>>> emulator.read_u16(0x1000)
123
Parameters: |
|
---|
Source code in ghidralib.py
3301 3302 3303 3304 3305 3306 3307 3308 3309 |
|
read_u32(address)
Read a 32bit unsigned integer from the emulated program.
>>> emulator.write_u32(0x1000, 123)
>>> emulator.read_u32(0x1000)
123
Parameters: |
|
---|
Source code in ghidralib.py
3311 3312 3313 3314 3315 3316 3317 3318 3319 |
|
read_u64(address)
Read a 64bit unsigned integer from the emulated program.
>>> emulator.write_u64(0x1000, 123)
>>> emulator.read_u64(0x1000)
123
Parameters: |
|
---|
Source code in ghidralib.py
3321 3322 3323 3324 3325 3326 3327 3328 3329 |
|
read_u8(address)
Read a byte from the emulated program.
>>> emulator.write_u8(0x1000, 13)
>>> emulator.read_u8(0x1000)
13
Parameters: |
|
---|
Source code in ghidralib.py
3291 3292 3293 3294 3295 3296 3297 3298 3299 |
|
read_unicode(address)
Read a null-terminated utf-16 string from the emulated program.
This function reads bytes until a null character is encountered.
>>> emu.read_unicode(0x1000)
'Hello, world!'
Parameters: |
|
---|
Source code in ghidralib.py
3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 |
|
read_varnode(varnode)
Read from the varnode from the emulated program.
This method can't read hash varnodes.
>>> fnc = Function("AddNumbers")
>>> emu = Emulator()
>>> emu.write_varnode(fnc.parameters[0].varnode, 2)
>>> emu.write_varnode(fnc.parameters[1].varnode, 2)
>>> emu.emulate(fnc.entrypoint, stop_when=lambda emu: emu.pc not in fnc.body)
>>> emu.read_varnode(func.return_variable.varnode)
4
Parameters: |
|
---|
Source code in ghidralib.py
3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 |
|
set_pc(address)
Set the program counter of the emulated program.
Source code in ghidralib.py
3220 3221 3222 3223 |
|
set_sp(value)
Set the current stack pointer register value.
Parameters: |
|
---|
Source code in ghidralib.py
3242 3243 3244 3245 3246 |
|
single_step()
Do a single emulation step. This will step into calls.
Note: This method will call hooks.
Returns: |
|
---|
Source code in ghidralib.py
3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 |
|
write_bytes(address, value)
Write to the memory of the emulated program.
>>> emulator.write_bytes(0x1000, "1")
>>> emulator.read_bytes(0x1000, 1)
'1'
Parameters: |
|
---|
Source code in ghidralib.py
3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 |
|
write_register(reg, value)
Write to the register of the emulated program.
>>> emulator.write_register("eax", 1)
>>> emulator.read_register("eax")
1
Parameters: |
|
---|
Source code in ghidralib.py
3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 |
|
write_u16(address, value)
Write a 16bit unsigned integer to the emulated program.
>>> emulator.write_u16(0x1000, 13)
>>> emulator.read_u16(0x1000)
13
Parameters: |
|
---|
Source code in ghidralib.py
3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 |
|
write_u32(address, value)
Write a 32bit unsigned integer to the emulated program.
>>> emulator.write_u32(0x1000, 13)
>>> emulator.read_u32(0x1000)
13
Parameters: |
|
---|
Source code in ghidralib.py
3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 |
|
write_u64(address, value)
Write a 64bit unsigned integer to the emulated program.
>>> emulator.write_u64(0x1000, 13)
>>> emulator.read_u64(0x1000)
13
Parameters: |
|
---|
Source code in ghidralib.py
3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 |
|
write_u8(address, value)
Write a byte to the emulated program.
>>> emulator.write_u8(0x1000, 13)
>>> emulator.read_u8(0x1000)
13
Parameters: |
|
---|
Source code in ghidralib.py
3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 |
|
write_varnode(varnode, value)
Set a varnode value in the emulated context.
This method can't set hash and constant varnodes.
>>> fnc = Function("AddNumbers")
>>> emu = Emulator()
>>> emu.write_varnode(fnc.parameters[0].varnode, 2)
>>> emu.write_varnode(fnc.parameters[1].varnode, 2)
>>> emu.emulate(fnc.entrypoint, stop_when=lambda emu: emu.pc not in fnc.body)
>>> emu.read_varnode(func.return_variable.varnode)
4
Parameters: |
|
---|
Source code in ghidralib.py
3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 |
|
FlowType
Bases: GhidraWrapper
Wraps a Ghidra FlowType object
Source code in ghidralib.py
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 |
|
has_fallthrough
property
Return True if this flow has a fallthrough.
is_call
property
Return True if this flow is a call.
is_computed
property
Return True if this flow is a computed jump.
is_conditional
property
Return True if this flow is a conditional jump.
is_jump
property
Return True if this flow is a jump.
is_override
property
Return True if this flow is an override.
is_terminal
property
Return True if this flow is a terminator.
is_unconditional
property
Return True if this flow is an unconditional jump.
Function
Bases: GhidraWrapper
, BodyTrait
Wraps a Ghidra Function object.
Source code in ghidralib.py
2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 |
|
UNDERLYING_CLASS = GhFunction
class-attribute
instance-attribute
address
property
Get the address of this function.
basicblocks
property
Get the basic blocks of this function.
body
property
Get the set of addresses of this function.
called
property
Get all functions that are called by this function.
callers
property
Get all functions that call this function.
calls
property
Get all function calls to this function.
clang_tokens
property
Get clang tokens for the decompiled function.
This returns a ClangTokenGroup object. TODO: wrap the return value.
comment
property
Get the comment of this function, if any.
control_flow
property
Get the control flow graph of this function.
In other words, get a graph that represents how the control flow can move between basic blocks in this function.
entrypoint
property
Get the entrypoint of this function.
exitpoints
property
Get a list of exit points for the function.
This will return a list of addresses of function terminators. For example, if a function has two RETs, this function will return their addresses.
fixup
property
writable
Get the fixup of this function.
high_basicblocks
property
Get the (high-level) Pcode basic blocks for this function.
Warning: this method needs to decompile the function, and is therefore slow.
high_function
property
Decompile this function, and return a high-level function.
Warning: this method needs to decompile the function, and is therefore slow.
high_pcode
property
Get the (high-level) Pcode for this function.
Warning: this method needs to decompile the function, and is therefore slow.
high_symbols
property
Get the high-level symbols for this function.
Warning: this method needs to decompile the function, and is therefore slow.
high_variables
property
Get all variables defined in this function.
Warning: this method needs to decompile the function, and is therefore slow.
instructions
property
Get the assembler instructions for this function.
is_external
property
Return True if this function is external.
is_thunk
property
Return True if this function is a thunk.
local_variables
property
Get the local variables of this function.
name
property
Get the name of this function.
parameters
property
Get the parameters of this function.
pcode
property
Get the (low-level) Pcode for this function.
pcode_tree
property
Get an AST-like representation of the function's Pcode.
Warning: this method needs to decompile the function, and is therefore slow.
primary_symbols
property
Get the primary symbols for this function.
repeatable_comment
property
Get the repeatable comment of this function, if any.
return_type
property
Get the return type of this function.
return_variable
property
Get the variable representing a return value of this function.
stack
property
Get the defined stack variables (both parameters and locals).
symbols
property
Get the symbols for this function.
Unfortunately, the implementation of this function has to iterate over all function addresses (because SymbolTable doesn't export the right method), so it may be quite slow when called frequently. Consider using primary_symbols if adequate.
variables
property
Get all variables defined in this function.
varnodes
property
Get all varnodes associated with a variable in this function.
xref_addrs
property
Get the source addresses of references to this function.
xrefs
property
Get the references to this function.
xrefs_to = xrefs
class-attribute
instance-attribute
add_named_parameter(datatype, name)
Add a parameter with a specified name to this function.
Warning: adding a register parameter will switch the function into custom storage mode. Adding named parameters in custom storage is not implemented
Source code in ghidralib.py
2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 |
|
add_register_parameter(datatype, register, name)
Add a parameter stored in a specified register to this function.
Warning: adding a register parameter will switch the function into custom storage mode. Adding named parameters in custom storage will not work anymore
Source code in ghidralib.py
2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 |
|
all()
staticmethod
Return all functions in the current program.
Source code in ghidralib.py
2473 2474 2475 2476 2477 |
|
create(address, name)
staticmethod
Create a new function at the given address with the given name.
Source code in ghidralib.py
2479 2480 2481 2482 2483 |
|
decompile()
Get decompiled C code for the function as string.
Source code in ghidralib.py
2696 2697 2698 2699 |
|
emulate(*args, **kwargs)
Emulate the function call with given args, and return final emulation state.
The arguments are passed using a calling convention defined in Ghidra. If you want to use a different calling convention, or do additional setup, you have to use the Emulator class directly.
You can pass your own emulator using the emulator
kwarg. You can use this
to do a pre-call setup (for example, write string parameters to memory). But
don't use this to change call parameters, as they are always overwriten.
>>> fnc = Function("ResolveName")
>>> emu = fnc.emulate(1379010213)
>>> emu.read_unicode(emu["eax"])
"HKEY_CLASSES_ROOT"
Parameters: |
|
---|
Source code in ghidralib.py
2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 |
|
emulate_simple(*args, **kwargs)
Emulate the function call with given args, and return the return value.
The arguments are passed using a calling convention defined in Ghidra. If you want to use a different calling convention, or do additional setup, you have to use the Emulator class directly.
You can pass your own emulator using the emulator
kwarg. You can use this
to do a pre-call setup (for example, write string parameters to memory). But
don't use this to change call parameters, as they are always overwriten.
Note: the name is not great, but I can't think of a better name that is not also very long.
>>> fnc = Function("CustomHash")
>>> fnc.emulate_simple("HKEY_CLASSES_ROOT")
1379010213
Parameters: |
|
---|
Source code in ghidralib.py
2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 |
|
fixup_body()
Fixup the function body: follow control flow and add thunks.
Source code in ghidralib.py
2581 2582 2583 2584 2585 |
|
get(addr)
staticmethod
Return a function at the given address, or None if no function exists there.
Source code in ghidralib.py
2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 |
|
get_high_function(simplify='decompile')
Decompile this function, and return a high-level function.
Warning: this method needs to decompile the function, and is therefore slow.
:simplify: the simplification style to use. See DecompilerInterface.setSimplificationStyle.
Source code in ghidralib.py
2716 2717 2718 2719 2720 2721 2722 2723 2724 |
|
get_high_pcode(simplify='decompile')
Decompile this function, and return its high-level Pcode.
Warning: this method needs to decompile the function, and is therefore slow.
:simplify: the simplification style to use. See DecompilerInterface.setSimplificationStyle.
Source code in ghidralib.py
2726 2727 2728 2729 2730 2731 2732 2733 |
|
get_high_pcode_at(address)
Get the high-level Pcode at the given address.
Do not use this function in a loop! Better decompile the whole function first.
Warning: this method needs to decompile the function, and is therefore slow.
Parameters: |
|
---|
Source code in ghidralib.py
2764 2765 2766 2767 2768 2769 2770 2771 2772 |
|
rename(name)
Change the name of this function.
Source code in ghidralib.py
2618 2619 2620 |
|
set_comment(comment)
Set the comment of this function.
Source code in ghidralib.py
2523 2524 2525 |
|
set_repeatable_comment(comment)
Set the repeatable comment of this function.
Source code in ghidralib.py
2542 2543 2544 |
|
symbolic_context()
Returns a SymbolicPropogator instance for this function.
This can be used to get a known values of registers at various addresses.
>>> fnc = Function(0x004061EC)
>>> ctx = fnc.symbolic_context()
>>> print(ctx.register(0x004061fb, "eax"))
TODO: This method should implement a hack described in https://github.com/NationalSecurityAgency/ghidra/issues/3581 because built-in Ghidra symbolic propagator doesn't support memory accesses.
Returns: |
|
---|
Source code in ghidralib.py
2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 |
|
FunctionCall
Bases: BodyTrait
Represents a function call at a given location in the program.
Can be used to get the function being called and the parameters passed to it.
Source code in ghidralib.py
2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 |
|
address
property
body
property
called_function = function
instance-attribute
callee
property
Get the function being called.
caller
property
Get the function where this function call takes place.
calling_function = caller
class-attribute
instance-attribute
high_pcodeop
property
Get the high-level PcodeOp for this function call.
High-level Pcode call
ops have the parameters resolved, so we
can use them to read them when analysing Pcode.
Warning: this works on decompiled functions only, so it will work if the call is done from a region not recognised as function. Warning: this method needs to decompile the function, and is therefore slow.
high_varnodes
property
Get a list of the arguments passed to this function call, as high varnodes.
In other words, decompile the function, and return the varnodes associated with the function parameters, as seen by Ghidra decompiler.
Warning: this works on decompiled functions only, so it will work if the call is done from a region not recognised as function. Warning: this method needs to decompile the function, and is therefore slow.
instruction
property
__init__(function, address)
Source code in ghidralib.py
2283 2284 2285 |
|
infer_args()
Get a list of the arguments passed to this function call, as integers.
This method tries to get arguments of this function, as seen by Ghidra decompiler. A limited symbolic execution is performed to resolve the pointers. If it's not possible to get an argument, None is stored in its place.
Warning: this works on decompiled functions only, so it will work if the call is done from a region not recognised as function. Warning: this method needs to decompile the function, and is therefore slow.
Source code in ghidralib.py
2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 |
|
infer_context()
Emulate the code before this function call, and return the state.
The goal of this function is to recover the state of the CPU before the function call, as well as possible. This will work well when parameters are constants written just before the call, for example:
mov eax, 30
mov ebx, DAT_encrypted_string
call decrypt_string
Then recovering eax is as simple as call.infer_context()["eax"].
Source code in ghidralib.py
2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 |
|
GenericT
Source code in ghidralib.py
435 436 |
|
GhidraWrapper
Bases: object
The base class for all Ghidra wrappers.
This function tries to be as transparent as possible - for example, it will not raise an error on double-wrapping, or when passed instead of a Java type.
>>> instr = getInstructionAt(getAddr(0x1234))
>>> GhidraWrapper(instr)
<Instruction 0x1234>
>>> GhidraWrapper(GhidraWrapper(instr))
<Instruction 0x1234>
>>> getInstructionBefore(Instruction(instr))
<Instruction 0x1233>
Similarly, equality is based on the underlying Java object.
Source code in ghidralib.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|
raw = _java_cast(raw)
instance-attribute
__eq__(other)
Check if this object is equal to another.
This just forwards the call to the underlying object.
Source code in ghidralib.py
321 322 323 324 325 326 327 |
|
__hash__()
Return the hash of this object.
This just forwards the call to the underlying object.
Source code in ghidralib.py
315 316 317 318 319 |
|
__init__(raw)
Initialize the wrapper.
This function will try to resolve the given object to a Ghidra object. The algorithm is as follows:
- If "raw" is a primitive type (int, long, str, unicode, Address), try to resolve it with a static "get" method of the subclass.
- If "raw" is a GhidraWrapper, unwrap it (so GhidraWrapper(GhidraWrapper(x)) is always the same as GhidraWrapper(x).
- If "raw" is None at this point, raise an exception.
- If the subclass has attribute UNDERLYING_CLASS, assert that the wrapped type is of the expected type.
- Save the final "raw" value.
Source code in ghidralib.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
__repr__()
Return a string representation of this object.
This just forwards the call to the underlying object.
Source code in ghidralib.py
303 304 305 306 307 |
|
__str__()
Return a string representation of this object.
This just forwards the call to the underlying object.
Source code in ghidralib.py
297 298 299 300 301 |
|
__tojava__(klass)
Make it possible to pass this object to Java methods.
This only works in Jython, I didn't find a way to do this in JPype yet.
Source code in ghidralib.py
309 310 311 312 313 |
|
Graph
Bases: GenericT
, GhidraWrapper
Wraps a Ghidra AttributedGraph object.
We'd like to store arbitrary object in the graph, but it only supports strings for keys (and names). We have a way to convert objects we are interested in to strings - see _get_unique_string() method.
Source code in ghidralib.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
|
data = {}
instance-attribute
description
property
Return the description of this graph.
edge_count
property
Return the number of edges in this graph.
edges
property
Get all edges in this graph.
Warning: this constructs the list every time, so it's not a light operation. Use edge_count for counting.
name
property
Return the name of this graph.
vertex_count
property
Return the number of vertices in this graph.
vertices
property
Get all vertices in this graph.
Warning: this constructs the list every time, so it's not a light operation. Use vertex_count for counting.
__contains__(vtx)
Check if a given vertex exists in this graph.
Parameters: |
|
---|
Source code in ghidralib.py
490 491 492 493 494 495 496 |
|
__init__(raw)
Create a new Graph wrapper.
We have to keep track of additional data, since AttributedGraph is a bit clunky and can only store string IDs and string values.
Parameters: |
|
---|
Source code in ghidralib.py
449 450 451 452 453 454 455 456 457 |
|
__len__()
Return the number of vertices in this graph.
To get the number of edges, use edge_count.
Source code in ghidralib.py
542 543 544 545 546 |
|
__resolve(vid)
Resolve a vertex ID to a vertex object.
Parameters: |
|
---|
Source code in ghidralib.py
601 602 603 604 605 606 607 608 |
|
bfs(origin, callback=lambda _: None)
Perform a breadth-first search on this graph, starting from the given vertex.
The callback will be called for each vertex visited when first visited, and the returned value is a dictionary of parent vertices for each visited vertex.
>>> g = Graph.create()
>>> a, b, c = g.vertex("a"), g.vertex("b"), g.vertex("c")
>>> g.edge(a, b)
>>> g.edge(b, c)
>>> g.bfs(a)
{'a': None, 'b': 'a', 'c': 'b'}
Warning: This won't reach every node in the graph, if it's not connected.
Parameters: |
|
---|
Source code in ghidralib.py
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
|
construct(vertexlist, getedges)
staticmethod
Create a new Graph from a list of vertices and a function to get edges.
Parameters: |
|
---|
Source code in ghidralib.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
|
create(name=None, description=None)
staticmethod
Create a new Graph.
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
459 460 461 462 463 464 465 466 467 468 469 470 471 |
|
dfs(origin, callback=lambda _: None)
Perform a depth-first search on this graph, starting from the given vertex.
The callback will be called for each vertex visited when first visited, and the returned value is a dictionary of parent vertices for each visited vertex.
>>> g = Graph.create()
>>> a, b, c = g.vertex("a"), g.vertex("b"), g.vertex("c")
>>> g.edge(a, b)
>>> g.edge(b, c)
>>> g.dfs(a)
{'a': None, 'b': 'a', 'c': 'b'}
Warning: This won't reach every node in the graph, if it's not connected.
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
|
edge(src, dst)
Create an edge between two vertices in this graph.
Parameters: |
|
---|
Source code in ghidralib.py
518 519 520 521 522 523 524 525 526 527 |
|
has_vertex(vtx)
Check if a given vertex exists in this graph.
Parameters: |
|
---|
Source code in ghidralib.py
498 499 500 501 502 |
|
show()
Display this graph in the Ghidra GUI.
Source code in ghidralib.py
591 592 593 594 595 596 597 598 599 |
|
to_dot()
Return a DOT representation of this graph.
Source code in ghidralib.py
578 579 580 581 582 583 584 585 586 587 588 589 |
|
toposort(origin)
Perform a topological sort on this graph, starting from the given vertex.
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
|
vertex(vtx, name=None)
Get or create a vertex in this graph.
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
504 505 506 507 508 509 510 511 512 513 514 515 516 |
|
HighFunction
Bases: GhidraWrapper
Source code in ghidralib.py
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 |
|
basicblocks
property
Get a list of basic blocks in this high function.
data_flow
property
Get a data flow graph of varnodes in this function.
Note: I don't think this method is currently very useful, but you can use it to easily get information about all varnodes that impact a value of another varnode
Returns: |
|
---|
function
property
Get the underlying function of this high function.
pcode
property
Get a list of all high PcodeOps in this function.
Note: high PcodeOps are called PcodeOpAST internally.
pcode_tree
property
Get an AST-like representation of the function's Pcode.
Warning: this method needs to decompile the function, and is therefore slow.
symbols
property
Get high symbols used in this function (including parameters).
variables
property
Get high variables defined in this function.
varnodes
property
Get all varnodes used in this function.
__eq__(other)
Compare two high functions.
Fun fact - Ghidra doesn't know how to do this.
Source code in ghidralib.py
1324 1325 1326 1327 1328 1329 1330 |
|
get(address)
staticmethod
Get a HighFunction at a given address, or None if there is none.
Source code in ghidralib.py
1228 1229 1230 1231 1232 1233 1234 1235 1236 |
|
get_pcode_at(address)
Get a list of PcodeOps at a given address.
This list may be empty even if there are instructions at that address.
Source code in ghidralib.py
1243 1244 1245 1246 1247 1248 |
|
HighSymbol
Bases: GhidraWrapper
Source code in ghidralib.py
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 |
|
data_type
property
Return the data type of this symbol
is_this_pointer
property
Return True if this symbol is a "this" pointer for a class
name
property
Return the name of this symbol
size
property
Return the size of this symbol in bytes
symbol
property
Get the corresponding symbol, if it exists.
variable
property
Return the high variable associated with this symbol, if any.
The symbol may have multiple HighVariables associated with it. This method returns the biggest one.
rename(new_name, source=SourceType.USER_DEFINED)
Rename this high symbol.
Parameters: |
|
---|
Source code in ghidralib.py
802 803 804 805 806 807 808 809 |
|
HighVariable
Bases: GhidraWrapper
Source code in ghidralib.py
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
|
data_type
property
Return the data type of this variable
is_addr_tied
property
Return True if ALL varnodes of this variable are addr tied.
is_free
property
Return True if ALL varnodes of this variable are free.
is_input
property
Return True if ALL varnodes of this variable are input.
is_persistent
property
Return True if ALL varnodes of this variable are persistent.
is_unaffected
property
Return True if ALL varnodes of this variable are is unaffected.
name
property
Return the name of this variable
size
property
Return the size of this variable in bytes
symbol
property
varnode
property
Return the Varnode that represents this variable
varnodes
property
Return all Varnodes that represent this variable at some point
rename(new_name)
Rename this high variable.
Source code in ghidralib.py
746 747 748 |
|
Instruction
Bases: GhidraWrapper
, BodyTrait
Wraps a Ghidra Instruction object
Source code in ghidralib.py
1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 |
|
address
property
Get the address of this instruction.
all_flows
property
Get a set of possible flows (next executed addresses).
Note: this INCLUDES fallthrough.
body
property
Get the address range this instruction.
bytes
property
Get the bytes of this instruction.
fallthrough
property
Get the fallthrough address (next address executed), if any.
For normal instruction, this is the next instruction address. For jumps, this is None. Can be overriden by fallthrough override.
flow_type
property
Get the flow type of this instruction.
For example, for x86 JMP this will return RefType.UNCONDITIONAL_JUMP
flows
property
Get a set of possible flows (next executed addresses).
Note: this DOES NOT INCLUDE a fallthrough. A strange design decision IMO, but I'm being faithful to Ghidra API.
has_fallthrough
property
Return true if this instruction has a fallthrough.
has_fallthrough_override
property
Return true if this instruction fallthrough was overriden.
high_pcode
property
Get high Pcode for this instruction.
WARNING: do not use this in a loop. Use Function.high_pcode instead.
input_varnodes
property
Get a list of output (LOW) varnodes for this instruction.
length
property
Get the length of this instruction in bytes.
mnemonic
property
Get the mnemonic of this instruction.
next
property
Get the next instruction.
operand_values
property
Return operands as primitive values (int or a string representation).
This is equivalent to calling .operands() and then calling .value() on each operand.
operands
property
Return operands as primitive values (int or a string representation).
More specifically, this will convert constants and addresses into integers, and for registers the name will be returned.
If you know operand type, call .scalar(), .register() or .list() instead.
output_varnodes
property
Get a list of output (LOW) varnodes for this instruction.
pcode
property
Get a list of Pcode operations that this instruction was parsed to
prev = previous
class-attribute
instance-attribute
previous
property
Get the previous instruction.
xrefs_from
property
Get a list of references from this instruction.
xrefs_to
property
Get a list of references to this instruction.
__convert_operand(operand)
Convert an operand to a scalar or address.
Source code in ghidralib.py
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 |
|
__len__()
Get the length of this instruction in bytes.
Source code in ghidralib.py
1698 1699 1700 |
|
add_operand_reference(op_ndx, ref_addr, ref_type, src_type=SourceType.USER_DEFINED)
Add a reference to an operand of this instruction.
Source code in ghidralib.py
1758 1759 1760 1761 1762 |
|
all()
staticmethod
Get all instruction defined in the current program.
Source code in ghidralib.py
1601 1602 1603 1604 1605 |
|
clear_fallthrough_override()
This clears the fallthrough override for this instruction.
Alias for del self.fallthrough_override
Source code in ghidralib.py
1795 1796 1797 1798 1799 |
|
create(address)
staticmethod
Create an instruction at the given address.
Note: this will force ghidra to disassemble at the given address,
and return the created instruction. If you want to actually change the
instruction at the given address, use assemble_at
instead.
If you want to just create an instruction object, use assemble
method.
Parameters: |
|
---|
Source code in ghidralib.py
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 |
|
get(address)
staticmethod
Get an instruction at the address, or None if not found.
Note: This will return None if the instruction is not defined in Ghidra
at the given address. If you want to disassemble an address, not necessarily
defined in Ghidra, try :func:disassemble_at
instead.
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 |
|
operand(ndx)
Get the nth operand of this instruction as an object.
Source code in ghidralib.py
1722 1723 1724 1725 |
|
set_fallthrough_override(value)
Override the fallthrough address for this instruction.
This sets the next instruction that will be executed after this instruction, assuming the current instruction doesn't jump anywhere. You can clear this with clear_fallthrough_override
Parameters: |
|
---|
Source code in ghidralib.py
1785 1786 1787 1788 1789 1790 1791 1792 1793 |
|
write_jumptable(targets)
Provide a list of addresses where this instruction may jump.
Warning: For this to work, the instruction must be a part of a function.
This is useful for fixing unrecognised switches, for example.
Note: the new switch instruction will use all references of type COMPUTED_JUMP already defined for the instruction (maybe we should clear them first?).
Source code in ghidralib.py
1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 |
|
JavaObject
A fake class, used for static type hints.
Source code in ghidralib.py
199 200 201 202 203 204 |
|
__getattribute__(name)
This attribute exists to make mypy happy.
Source code in ghidralib.py
202 203 204 |
|
MemoryBlock
Bases: GhidraWrapper
, BodyTrait
A Ghidra wrapper for a Ghidra MemoryBlock
Source code in ghidralib.py
3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 |
|
address = start
class-attribute
instance-attribute
body
property
Get the address range this instruction.
bytes
property
Get the bytes of this instruction.
comment
property
Get the comment associated with this MemoryBlock
end
property
length = size
class-attribute
instance-attribute
name
property
Get the name of this MemoryBlock
size
property
Get the size of this MemoryBlock
start
property
Get the first address of this MemoryBlock
all()
staticmethod
Get all MemoryBlocks in the current program
Source code in ghidralib.py
3727 3728 3729 3730 3731 |
|
get(raw_or_name)
staticmethod
Gets a MemoryBlock by name or containing the given address.
Note: for a string argument, this will try to get memoryblock by name, and if it fails, it will fall back to the regular behaviour of "resolve the symbol to the address, and get element by address
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 |
|
Operand
Operand helper for instruction, may be a register, const or a list
Source code in ghidralib.py
1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 |
|
is_list
property
Return True if this operand is a list.
is_register
property
Return True if this operand is a register.
is_scalar
property
Return True if this operand is a scalar.
list
property
Gets this operand value as a list
raw = operand
instance-attribute
register
property
Gets this operand value as a register name
scalar
property
Gets this operand value as a scalar
value
property
Return internal representation of this operand - string, int or a list
__init__(operand)
Source code in ghidralib.py
1535 1536 |
|
Parameter
Bases: Variable
Wraps a Ghidra Parameter object.
Source code in ghidralib.py
2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 |
|
formal_data_type
property
Returns the formal data type of this parameter.
ordinal
property
Returns the ordinal of this parameter.
PcodeBlock
Bases: GhidraWrapper
Source code in ghidralib.py
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 |
|
has_children
property
Returns True if this block has any children and can be iterated over.
This function is necessary because Ghidra's code uses isinstance() checks to dispatch types. We return true for instances of Java BlockGraph.
incoming_edges
property
outgoing_edges
property
pcode
property
PcodeOp
Bases: GhidraWrapper
Pcode is a Ghidra's low-level intermediate language. Instructions from any processor are transformed into PCode before any analysis takes place. There is a finite number of possible operations.
While Ghidra doesn't define "High Pcode", this library refers to analysed Pcode as "High Pcode". While theoretically still the same object, Pcode is transformed significantly, for example before function parameter analysis "CALL" opcodes have no inputs.
Source code in ghidralib.py
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 |
|
BOOL_AND = 39
class-attribute
instance-attribute
BOOL_NEGATE = 37
class-attribute
instance-attribute
BOOL_OR = 40
class-attribute
instance-attribute
BOOL_XOR = 38
class-attribute
instance-attribute
BRANCH = 4
class-attribute
instance-attribute
BRANCHIND = 6
class-attribute
instance-attribute
CALL = 7
class-attribute
instance-attribute
CALLIND = 8
class-attribute
instance-attribute
CALLOTHER = 9
class-attribute
instance-attribute
CAST = 64
class-attribute
instance-attribute
CBRANCH = 5
class-attribute
instance-attribute
COPY = 1
class-attribute
instance-attribute
CPOOLREF = 68
class-attribute
instance-attribute
EXTRACT = 71
class-attribute
instance-attribute
FLOAT_ABS = 52
class-attribute
instance-attribute
FLOAT_ADD = 47
class-attribute
instance-attribute
FLOAT_CEIL = 57
class-attribute
instance-attribute
FLOAT_DIV = 48
class-attribute
instance-attribute
FLOAT_EQUAL = 41
class-attribute
instance-attribute
FLOAT_FLOAT2FLOAT = 55
class-attribute
instance-attribute
FLOAT_FLOOR = 58
class-attribute
instance-attribute
FLOAT_INT2FLOAT = 54
class-attribute
instance-attribute
FLOAT_LESS = 43
class-attribute
instance-attribute
FLOAT_LESSEQUAL = 44
class-attribute
instance-attribute
FLOAT_MULT = 49
class-attribute
instance-attribute
FLOAT_NAN = 46
class-attribute
instance-attribute
FLOAT_NEG = 51
class-attribute
instance-attribute
FLOAT_NOTEQUAL = 42
class-attribute
instance-attribute
FLOAT_ROUND = 59
class-attribute
instance-attribute
FLOAT_SQRT = 53
class-attribute
instance-attribute
FLOAT_SUB = 50
class-attribute
instance-attribute
FLOAT_TRUNC = 56
class-attribute
instance-attribute
INDIRECT = 61
class-attribute
instance-attribute
INSERT = 70
class-attribute
instance-attribute
INT_2COMP = 24
class-attribute
instance-attribute
INT_ADD = 19
class-attribute
instance-attribute
INT_AND = 27
class-attribute
instance-attribute
INT_CARRY = 21
class-attribute
instance-attribute
INT_DIV = 33
class-attribute
instance-attribute
INT_EQUAL = 11
class-attribute
instance-attribute
INT_LEFT = 29
class-attribute
instance-attribute
INT_LESS = 15
class-attribute
instance-attribute
INT_LESSEQUAL = 16
class-attribute
instance-attribute
INT_MULT = 32
class-attribute
instance-attribute
INT_NEGATE = 25
class-attribute
instance-attribute
INT_NOTEQUAL = 12
class-attribute
instance-attribute
INT_OR = 28
class-attribute
instance-attribute
INT_REM = 35
class-attribute
instance-attribute
INT_RIGHT = 30
class-attribute
instance-attribute
INT_SBORROW = 23
class-attribute
instance-attribute
INT_SCARRY = 22
class-attribute
instance-attribute
INT_SDIV = 34
class-attribute
instance-attribute
INT_SEXT = 18
class-attribute
instance-attribute
INT_SLESS = 13
class-attribute
instance-attribute
INT_SLESSEQUAL = 14
class-attribute
instance-attribute
INT_SREM = 36
class-attribute
instance-attribute
INT_SRIGHT = 31
class-attribute
instance-attribute
INT_SUB = 20
class-attribute
instance-attribute
INT_XOR = 26
class-attribute
instance-attribute
INT_ZEXT = 17
class-attribute
instance-attribute
LOAD = 2
class-attribute
instance-attribute
LZCOUNT = 73
class-attribute
instance-attribute
MULTIEQUAL = 60
class-attribute
instance-attribute
NEW = 69
class-attribute
instance-attribute
PCODE_MAX = 74
class-attribute
instance-attribute
PIECE = 62
class-attribute
instance-attribute
POPCOUNT = 72
class-attribute
instance-attribute
PTRADD = 65
class-attribute
instance-attribute
PTRSUB = 66
class-attribute
instance-attribute
RETURN = 10
class-attribute
instance-attribute
SEGMENTOP = 67
class-attribute
instance-attribute
STORE = 3
class-attribute
instance-attribute
SUBPIECE = 63
class-attribute
instance-attribute
UNIMPLEMENTED = 0
class-attribute
instance-attribute
address
property
Get an address in the program where this instruction is located
inputs
property
inputs_simple
property
Return inputs as primitive values (int or a string representation).
More specifically, this will convert constants and addresses into integers, for registers names are returned, and for unique and hash varnodes ad-hoc string encoding is used (hash:ID or uniq:ID where ID is varnode identifier).
mnemonic
property
Get a string representation of the operation, for example "COPY"
opcode
property
output
property
result
property
Try to evaluate the pcode operation to a constant value.
Right now this is very poor and doesn't try to implement most of the opcodes. Mostly because I suspect I'm reinventing the wheel, and there is code to do this already in Ghidra.
Returns: |
|
---|
get_high_pcode_at(address)
staticmethod
Get a high pcode for the instruction at a specified address
Convenience wrapper for Function(address).get_high_pcode_at(address).
Source code in ghidralib.py
1132 1133 1134 1135 1136 1137 |
|
Program
Bases: GhidraWrapper
A static class that represents the current program
Source code in ghidralib.py
3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 |
|
analyze()
staticmethod
Analyze changes. This will block when autoanalysis changes place.
Run this when you did changes that you will need to proceed with the rest of the script.
Source code in ghidralib.py
3848 3849 3850 3851 3852 3853 3854 |
|
basicblocks()
staticmethod
Get all the basic blocks defined in the program.
Source code in ghidralib.py
3813 3814 3815 3816 |
|
body()
staticmethod
Get the set of all addresses of the program.
Source code in ghidralib.py
3833 3834 3835 3836 3837 |
|
call_graph()
staticmethod
Get the call graph for this program.
Source code in ghidralib.py
3801 3802 3803 3804 |
|
control_flow()
staticmethod
Get a graph representing the whole program control flow.
Warning: This graph may be big, so don't try to display it.
Source code in ghidralib.py
3806 3807 3808 3809 3810 3811 |
|
create_data(address, datatype)
staticmethod
Force the type of the data defined at the given address to datatype
.
This function will clear the old type if it already has one
Parameters: |
|
---|
Source code in ghidralib.py
3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 |
|
current()
staticmethod
Get the current program. Equivalent to getCurrentProgram()
This method must be used instead of currentProgram, because the latter won't work well if user is using multiple programs at the same time (for example, many tabs in the same tool).
Source code in ghidralib.py
3839 3840 3841 3842 3843 3844 3845 3846 |
|
functions()
staticmethod
Get all the functions defined in the program.
Source code in ghidralib.py
3823 3824 3825 3826 |
|
instructions()
staticmethod
Get all the instructions defined in the program.
Source code in ghidralib.py
3828 3829 3830 3831 |
|
location()
staticmethod
Get the current location in the program.
>>> current_location()
0x1000
Returns: |
|
---|
Source code in ghidralib.py
3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 |
|
memory_blocks()
staticmethod
Get memory blocks defined for the current program.
Source code in ghidralib.py
3818 3819 3820 3821 |
|
RefType
Bases: GhidraWrapper
Source code in ghidralib.py
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 |
|
CALLOTHER_OVERRIDE_CALL = _reftype_placeholder()
class-attribute
instance-attribute
CALLOTHER_OVERRIDE_JUMP = _reftype_placeholder()
class-attribute
instance-attribute
CALL_OVERRIDE_UNCONDITIONAL = _reftype_placeholder()
class-attribute
instance-attribute
CALL_TERMINATOR = _reftype_placeholder()
class-attribute
instance-attribute
COMPUTED_CALL = _reftype_placeholder()
class-attribute
instance-attribute
COMPUTED_CALL_TERMINATOR = _reftype_placeholder()
class-attribute
instance-attribute
COMPUTED_JUMP = _reftype_placeholder()
class-attribute
instance-attribute
CONDITIONAL_CALL = _reftype_placeholder()
class-attribute
instance-attribute
CONDITIONAL_CALL_TERMINATOR = _reftype_placeholder()
class-attribute
instance-attribute
CONDITIONAL_COMPUTED_CALL = _reftype_placeholder()
class-attribute
instance-attribute
CONDITIONAL_COMPUTED_JUMP = _reftype_placeholder()
class-attribute
instance-attribute
CONDITIONAL_JUMP = _reftype_placeholder()
class-attribute
instance-attribute
CONDITIONAL_TERMINATOR = _reftype_placeholder()
class-attribute
instance-attribute
FALL_THROUGH = _reftype_placeholder()
class-attribute
instance-attribute
FLOW = _reftype_placeholder()
class-attribute
instance-attribute
INDIRECTION = _reftype_placeholder()
class-attribute
instance-attribute
INVALID = _reftype_placeholder()
class-attribute
instance-attribute
JUMP_OVERRIDE_UNCONDITIONAL = _reftype_placeholder()
class-attribute
instance-attribute
JUMP_TERMINATOR = _reftype_placeholder()
class-attribute
instance-attribute
TERMINATOR = _reftype_placeholder()
class-attribute
instance-attribute
UNCONDITIONAL_CALL = _reftype_placeholder()
class-attribute
instance-attribute
UNCONDITIONAL_JUMP = _reftype_placeholder()
class-attribute
instance-attribute
has_fallthrough
property
writable
is_call
property
writable
is_computed
property
writable
is_conditional
property
writable
is_data
property
is_flow
property
is_jump
property
writable
is_override
property
is_read
property
is_terminal
property
is_unconditional
property
is_write
property
Reference
Bases: GhidraWrapper
Source code in ghidralib.py
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 |
|
from_address
property
Return the address of the source of the reference.
is_call
property
Return True if the reference is a call.
is_jump
property
Return True if the reference is a jump.
reftype
property
Return the type of reference.
source
property
to_address
property
Return the address of the target of the reference.
Register
Bases: GhidraWrapper
Source code in ghidralib.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 |
|
name
property
Return the name of this register
size
property
Return the size of this register in bytes
This will tell the total number of bytes this register contains - because register values don't have to be byte-aligned
varnode
property
Return the varnode associated with this register
Warning: this doesn't support registers that are not byte-aligned (for example, flag registers). It will round the address down to byte.
get(raw_or_name)
staticmethod
Get a register by name
Source code in ghidralib.py
852 853 854 855 856 857 858 859 |
|
Symbol
Bases: GhidraWrapper
Wraps a Ghidra Symbol object.
Source code in ghidralib.py
2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 |
|
address
property
Get the address of this symbol.
is_external
property
Return true if this symbol is external, otherwise false.
Note: when resolving by name, local symbols take precedence over external ones (in particular for function thunks - in contrast to Ghidra default behaviour).
Returns: |
|
---|
name
property
Get the name of this symbol.
name_with_namespace
property
Get the fully qualified name of this symbol.
xref_addrs
property
Get the addresses of all references to this symbol.
xrefs
property
Get a list of references to this symbol.
xrefs_to = xrefs
class-attribute
instance-attribute
all()
staticmethod
Get all symbols defined in the program.
Source code in ghidralib.py
2979 2980 2981 2982 2983 2984 |
|
create(address, name, source=SourceType.USER_DEFINED)
staticmethod
Create a new symbol (also called label) at the given address.
Parameters: |
|
---|
Source code in ghidralib.py
2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 |
|
delete()
Delete this symbol.
Source code in ghidralib.py
3039 3040 3041 |
|
get(raw_or_name)
staticmethod
Get a symbol with the provided name or at the provided address.
Return None if the symbol was not found.
Note: when resolving by name, local symbols take precedence over external ones (in particular for function thunks - in contrast to Ghidra default behaviour).
Parameters: |
|
---|
Source code in ghidralib.py
2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 |
|
remove(address, name)
staticmethod
Remove the symbol with the given name at the given address.
Parameters: |
|
---|
Source code in ghidralib.py
2998 2999 3000 3001 3002 3003 3004 |
|
rename(new_name, source=SourceType.USER_DEFINED)
Rename this symbol.
>>> main = Symbol.get("main")
>>> main.rename("main_renamed")
>>> main.name
'main_renamed'
Parameters: |
|
---|
Source code in ghidralib.py
3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 |
|
resolve_external(external_symbol)
staticmethod
Resolves an external address to a RAM location, if possible.
If the symbol has no RAM location, just return its offset.
Why is this ugly thing here? Again, we want to support external symbols, and we are interested in their RAM address in the program address space. In some cases, Ghidra will give an external address a "location" in the RAM space. So, for example, if current program jumps to that external function (or read that external variable etc), it will read that location as far as Ghidra is concerned (for example, Emulator will use it for calls). This is important for emulating Windows binaries, that use address tables for imports.
Parameters: |
|
---|
Source code in ghidralib.py
2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 |
|
resolve_thunk_if_exists(external_symbol)
staticmethod
Returns a function thunk leading to a passed external symbol, if it exists.
If there is no function thunk, original symbol is returned.
Why is this ugly thing here? Well, we want to support external symbols,
especially external functions. Thunks are much more useful for us when
thinking in context of the analysed program - when Linux program calls
printf
it jumps to the appropriate printf
thunk, not to libc
directly. So this is the location that we want to patch/hook/trace/etc when
thinking about printf. But the thing is that Ghidra SymbolTable API will
not even return thunks! So we trace the external function references, and
return the first (almost certainly only) Thunk reference.
Parameters: |
|
---|
Source code in ghidralib.py
2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 |
|
set_type(datatype)
Set the data type of this symbol.
Source code in ghidralib.py
3035 3036 3037 |
|
SymbolicPropogator
Bases: GhidraWrapper
Wraps SymbolicPropogator. Can be used to get known values at various locations in a given function (or outside of a function)
Source code in ghidralib.py
2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 |
|
create()
staticmethod
Source code in ghidralib.py
2418 2419 2420 |
|
flow_constants(addr, body, evaluator)
Flow constants from the given address in the given body
Parameters: |
|
---|
Source code in ghidralib.py
2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 |
|
register_at(addr, register)
Get a known register value at the given address (or None)
Warning: this value is signed.
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 |
|
Variable
Bases: GhidraWrapper
Wraps a Ghidra Variable object
Source code in ghidralib.py
2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 |
|
comment
property
writable
"Get the comment for this variable
data_type
property
writable
Get the data type of this variable
function
property
Get the function associated with this variable.
has_bad_storage
property
Check if this variable has bad storage (could not be resolved)
is_auto
property
Check if this variable is an automatic parameter.
Some parameters are "hidden parameters" dictated by the calling convention. This method returns true for such paramteters.
is_compound
property
Check if this variable is a compound variable
is_constant
property
Check if this variable consists of a single constant-space varnode
is_forced_indirect
property
Check if this variable was forced to be a pointer by calling convention
is_hash
property
Check if this variable consists of a single hash-space varnode.
is_memory
property
Check if this variable is stored in memory
is_register
property
Check if this variable consists of a single register.
is_stack
property
Check if this variable is a stack variable
is_unassigned_storage
property
Check if this variable has no assigned storage (varnodes)
is_unique
property
Check if this variable is of type unique
is_valid
property
Check if this variable is valid
is_void
property
Check if this variable is of type void
name
property
writable
Get the name of this variable
register
property
Get the register associated with this variable.
Raises an exception if this variable is not a register variable.
source
property
Get the source type of this variable
stack_offfset
property
Get the stack offset of this variable.
symbol
property
Get the symbol for this variable
varnode
property
Get the first varnode associated with this variable.
Warning: there may be more than one varnode associated with a variable.
varnodes
property
Get all varnodes associated with this variable.
rename(name, source=SourceType.USER_DEFINED)
Rename this variable
Source code in ghidralib.py
2120 2121 2122 2123 2124 |
|
set_comment(comment)
Set the comment for this variable
Source code in ghidralib.py
2153 2154 2155 |
|
Varnode
Bases: GhidraWrapper
Source code in ghidralib.py
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 |
|
as_register
property
Return the name of the register this varnode is stored in.
Warning: even if is_register returns true, this does not mean you can use this method safely. Use is_named_register to make sure.
defining_pcodeop
property
Return a PcodeOp that defined this varnode
descendants
property
Return a list of all descendants of this varnode
free
property
has_value
property
Return true if this varnode can be converted to a integer value.
In particular, this will return true for Address and Constant varnodes
high
property
is_addr_tied
property
is_address
property
is_constant
property
Note: addresses are not constants in Ghidra-speak. Use has_value to check if the varnode has a predictable value.
is_free
property
is_hash
property
is_input
property
is_named_register
property
"Return True if this varnode is stored entirely in a named register.
"Named" in this context means that it has a conventional name, like RAX. Not all register varnodes are named, for example, the upper 32 bits of RAX have no commonly used name.
is_persistent
property
is_register
property
Return True if this varnode is stored entirely in a register.
Warning: this does not mean that it can be cast to a register! This may be, for example, upper 32 bits of RAX. Use is_named_register instead.
is_stack
property
is_unaffected
property
is_unique
property
offset
property
simple
property
Convert Varnode to a primitive value (int or a string representation)
More specifically, this will convert constants and addresses into integers, for registers names are returned, and for unique and hash varnodes ad-hoc string encoding is used (hash:ID or uniq:ID where ID is varnode identifier).
This is useful for simple analyses when programmer already knows what type of value is expected at the given position.
size
property
symbol
property
value
property
Get the value of this varnode. Traverse defining pcodeops if necessary.
intersects(other)
Return true if this varnode intersects other
Source code in ghidralib.py
1039 1040 1041 |
|
rename(new_name)
Try to rename the current varnode. This only makes sense for variables.
Source code in ghidralib.py
971 972 973 |
|
unicode
A fake stub class, to keep type-checker relatively happy
Source code in ghidralib.py
156 157 158 159 160 161 |
|
encode()
A fake method, to keep type-checker relatively happy
Source code in ghidralib.py
159 160 161 |
|
assemble(instructions, address=0)
Assemble the given instructions and return them as a list of instructions.
Note: Address is important, because instruction meaning may depend on the location.
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 |
|
assemble_at(address, instructions, pad_to=0)
Assemble the given instructions and write them at the given address.
Note: Ghidra is a bit picky, and case-sensitive when it comes to opcodes. For example, use "MOV EAX, EBX" instead of "mov eax, ebx".
>>> assemble_at(Function("exit").entrypoint, "RET")
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 |
|
assemble_to_bytes(instructions, address=0)
Assemble the given instructions and return them as an array of bytes.
Note: Ghidra is a bit picky, and case-sensitive when it comes to opcodes. For example, use "MOV EAX, EBX" instead of "mov eax, ebx".
Note: Address is important, because instruction bytes may depend on the location.
>>> assemble_to_bytes("ADD EAX, EAX")
"À"
>>> assemble_to_bytes(["ADD EAX, EAX", "ADD EAX, EAX"])
"ÀÀ"
Parameters: |
|
---|
Source code in ghidralib.py
3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 |
|
can_resolve(addr)
Check if a passed value address can be resolved.
This is useful for checking if resolve()
will succeed.
See resolve
documentation for more details.
Source code in ghidralib.py
406 407 408 409 410 411 |
|
collect_iterator(iterator)
Collect a Java iterator to a Python list.
Source code in ghidralib.py
421 422 423 424 425 426 |
|
disassemble_at(address, max_instr=None, max_bytes=None)
Disassemble the bytes from the program memory at the given address.
If neither max_bytes
nor max_instr
are specified, this function will
disassemble one instruction. If at least one of them is specified,
this function will disassemble until one of the conditions occurs.
>>> disassemble_at(0x0403ED0)
[INC ESI]
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 |
|
disassemble_bytes(data, addr=0, max_instr=None)
Disassemble the given bytes and return a list of Instructions.
This function will return early if an exception during disassembly occurs.
>>> disassemble_bytes('F')
[INC ESI]
Note: Address is important, because instruction meaning may depend on the location.
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 |
|
enhex(s)
Convert raw bytes to a hex string.
>>> enhex([0x01, 0x02])
'0102'
Parameters: |
|
---|
Source code in ghidralib.py
4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 |
|
findall_pattern(byte_pattern)
Find all occurrences of a byte pattern in the program.
>>> findall_pattern("01 02 ?? 04")
[0x1000, 0x1004]
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 |
|
findone_pattern(byte_pattern, start=0)
Find the first occurrence of a byte pattern in the program (or None).
>>> findone_pattern("01 02 ?? 04")
0x1000
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 |
|
from_bytes(b)
Decode a bytes as a little-endian integer.
>>> from_bytes('ab')
25185
Parameters: |
|
---|
Source code in ghidralib.py
4124 4125 4126 4127 4128 4129 4130 4131 4132 |
|
get_string(address)
Get the string defined at the given address.
This function will return None if the data defined in Ghidra at the
given address is not a string. This function will also return None
if the string at adress
was not defined in Ghidra. To read a
null-terminated string from Ghidra memory, use read_cstring
instead.
>>> get_string(0x1000)
'Hello, world!'
Parameters: |
|
---|
Source code in ghidralib.py
4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 |
|
read_bytes(address, length)
Read a byte stream from program at address.
>>> read_bytes(0x1000, 4)
'test'
Parameters: |
|
---|
Source code in ghidralib.py
4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 |
|
read_cstring(address)
Read a null-terminated string from Ghidra memory.
This function ignores metadata available to Ghidra and just reads the bytes until a nullbyte is encountered.
>>> read_cstring(0x1000)
'Hello, world!'
Parameters: |
|
---|
Source code in ghidralib.py
4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 |
|
read_u16(address)
Read a 16bit integer from program at address.
>>> read_u16(0x1000)
0x0102
Parameters: |
|
---|
Source code in ghidralib.py
4082 4083 4084 4085 4086 4087 4088 4089 |
|
read_u32(address)
Read a 32bit integer from program at address.
>>> read_u32(0x1000)
0x01020304
Parameters: |
|
---|
Source code in ghidralib.py
4092 4093 4094 4095 4096 4097 4098 4099 |
|
read_u64(address)
Read a 64bit integer from program at address.
>>> read_u32(0x1000)
0x0102030405060708
Parameters: |
|
---|
Source code in ghidralib.py
4102 4103 4104 4105 4106 4107 4108 4109 |
|
read_u8(address)
Read a byte from program at address.
>>> read_u8(0x1000)
0x01
Parameters: |
|
---|
Source code in ghidralib.py
4072 4073 4074 4075 4076 4077 4078 4079 |
|
read_unicode(address)
Read a null-terminated utf-16 string from Ghidra memory.
This function ignores metadata available to Ghidra and just reads the bytes until a null character is encountered.
>>> read_unicode(0x1000)
'Hello, world!'
Parameters: |
|
---|
Source code in ghidralib.py
4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 |
|
resolve(addr)
Convert an arbitrary addressable value to a Ghidra Address object.
This library accepts one of three things as addressses:
- A Ghidra Address object
- An integer representing an address
- A string representing a symbol name
This function is responsible from converting the addressable values (Addr
)
to Ghidra addresses (GenericAddress
).
>>> resolve(0x1234)
0x1234
>>> resolve(Symbol("main"))
0x1234
>>> resolve(toAddr(0x1234))
0x1234
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
to_bytes(value, length)
Encode an integer as a little-endian byte stream.
>>> to_bytes(0x0102, 2)
'\x01\x02'
Parameters: |
|
---|
Source code in ghidralib.py
4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 |
|
try_resolve(addr)
Convert an arbitrary addressable value to a Ghidra Address object.
See resolve
documentation for more details.
Parameters: |
|
---|
Returns: |
|
---|
Source code in ghidralib.py
393 394 395 396 397 398 399 400 401 402 403 |
|
unhex(s)
Decode a hex string.
>>> unhex("01 02")
'0102'
Parameters: |
|
---|
Source code in ghidralib.py
4167 4168 4169 4170 4171 4172 4173 4174 |
|
unwrap(wrapper_or_java_type)
If the argument is a GhidraWrapper, return the underlying Java object.
Source code in ghidralib.py
414 415 416 417 418 |
|
write_bytes(address, data)
Write the provided bytes at a given address.
>>> write_bytes(0x1000, "test)
>>> read_bytes(0x1000, 4)
'test'
Parameters: |
|
---|
Source code in ghidralib.py
4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 |
|
xor(a, b)
XOR two bytestrings together.
If two bytestrings are not the same length, the result will be truncated to the length of the shorter string.
>>> xor("\x01\x02", "\x03\x04")
'\x02\x06'
Parameters: |
|
---|
Source code in ghidralib.py
4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 |
|