The main handle for reading/parsing a binary code. BinHandle essentially provides a low-level interface for a chunk of binary code. One can use BinHandle to parse/lift/disassemble instructions at a specific address or to access file-specific data.
Record Field | Description |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Instance member | Description |
Full Usage:
this.ReadASCII(bp)
Parameters:
BinaryPointer
-
BinaryPointer.
Returns: string
Return the corresponding ASCII string.
|
|
Full Usage:
this.ReadASCII(addr)
Parameters:
Addr
-
The address.
Returns: string
Return the corresponding ASCII string.
|
|
Full Usage:
this.ReadBytes(bp, nBytes)
Parameters:
BinaryPointer
-
BInaryPointer.
nBytes : int
-
The size of the byte array (in bytes).
Returns: byte[]
Return the byte array if succeed. Otherwise, raise an exception.
|
|
Full Usage:
this.ReadBytes(addr, nBytes)
Parameters:
Addr
-
The address.
nBytes : int
-
The size of the byte array (in bytes).
Returns: byte[]
Return the byte array if succeed. Otherwise, raise an exception.
|
|
Full Usage:
this.ReadInt(bp, size)
Parameters:
BinaryPointer
-
The binary pointer.
size : int
-
The size of the integer in bytes. Maximum 8 bytes is
possible.
Returns: int64
Return the corresponding integer (int64).
|
Return the corresponding integer value of the size from the current binary, which is pointed to by the binary pointer (bp).
|
Full Usage:
this.ReadInt(addr, size)
Parameters:
Addr
-
The address.
size : int
-
The size of the integer in bytes. Maximum 8 bytes is
possible.
Returns: int64
Return the corresponding integer (int64).
|
|
Full Usage:
this.ReadUInt(bp, size)
Parameters:
BinaryPointer
-
BinaryPointer.
size : int
-
The size of the integer in bytes. Maximum 8 bytes is
possible.
Returns: uint64
Return the corresponding unsigned integer (uint64).
|
Return the corresponding unsigned integer value of the size from the binary, which is pointed to by the binary pointer (bp).
|
Full Usage:
this.ReadUInt(addr, size)
Parameters:
Addr
-
The address.
size : int
-
The size of the integer in bytes. Maximum 8 bytes is
possible.
Returns: uint64
Return the corresponding unsigned integer (uint64).
|
|
Static member | Description |
Full Usage:
BinHandle.DisasmBBlock(hdl, showAddr, resolveSymbol, bp)
Parameters:
BinHandle
showAddr : bool
resolveSymbol : bool
bp : BinaryPointer
Returns: Result<(string * BinaryPointer), (string * BinaryPointer)>
|
Return the disassembled string for a basic block starting at address pointed to by the binary pointer (bp) along with the fall-through address of the block. This function returns a partial disassembly if parsing of the bblock was not successful.
|
Full Usage:
BinHandle.DisasmInstr(hdl) (showAddr) (resolveSymbol) (ins)
Parameters:
BinHandle
-
BinHandle.
showAddr : bool
-
Whether to show the instruction address or
not.
resolveSymbol : bool
-
Whether to resolve symbols while disassembling
the instruction.
ins : Instruction
-
The instruction to disassemble.
Returns: string
Disassembled string.
|
|
Full Usage:
BinHandle.DisasmInstrSimple(ins)
Parameters:
Instruction
-
The instruction to disassemble.
Returns: string
Disassembled string.
|
Return a disassembled string from the parsed instruction. This function returns a simplified disassembly, which does not contain the instruction address nor symbols.
|
|
Initialize an empty BinHandle. This function is useful when you want to delay loading the actual body of your binary blob but also want to specify the os.
|
|
Initialize an empty BinHandle solely from an ISA, assuming that the archMode is NoMode, and the format is RawBinary. This function is useful when you want to delay loading the actual body of your binary blob.
|
Full Usage:
BinHandle.Init(isa, archMode)
Parameters:
ISA
-
ISA.
archMode : ArchOperationMode
-
ArchOperatinoMode.
Returns: BinHandle
BinHandle.
|
Initialize an empty BinHandle. This function is useful when you want to delay loading the actual body of your binary blob.
|
|
Initialize a BinHandle from an ISA and a byte sequence, assuming that the archMode is NoMode, and the format is RawBinary.
|
|
Initialize a BinHandle from an ISA and a binary file path, assuming that the archMode is NoMode. B2R2 will automatically detect the file format of the given binary file, but it will refer to the given ISA parameter either when the binary has multiple architectures, e.g., a fat binary on macOS, or when B2R2 cannot recognize the given file format. If the given binary file does not follow the known formats, then B2R2 consider it as a raw binary with base address at 0.
|
|
Initialize a BinHandle from an ISA and a byte sequence, assuming that the archMode is NoMode. This function behaves the same as the 2-argument constructor Init (isa, bytes), with a difference of using the specified base address when initializing the BinHandle.
|
|
Initialize a BinHandle from an ISA and a binary file path, assuming that the archMode is NoMode. This function behaves the same as the 2-argument constructor Init (isa, fileName), with a difference of using the specified base address when initializing the BinHandle.
|
Full Usage:
BinHandle.Init(isa, archMode, autoDetect, baseAddr, fileName)
Parameters:
ISA
-
ISA.
archMode : ArchOperationMode
-
ArchOperatinoMode.
autoDetect : bool
-
Whether to perform auto format detection.
baseAddr : Addr option
-
Base address for calculating instruction
addresses.
fileName : string
-
Binary file.
Returns: BinHandle
BinHandle.
|
Initialize a BinHandle from a given binary file (fileName). This function will read the file and parse it. It will automatically detect the file format if autoDetect is true. Otherwise, it will cnosider the file as a raw binary.
|
Full Usage:
BinHandle.Init(isa, archMode, autoDetect, baseAddr, bytes)
Parameters:
ISA
-
ISA.
archMode : ArchOperationMode
-
ArchOperatinoMode.
autoDetect : bool
-
Perform auto format detection or not.
baseAddr : Addr option
-
Base address for calculating instruction
addresses.
bytes : byte[]
-
Raw binary sequence.
Returns: BinHandle
BinHandle.
|
Initialize a BInHnalder from a given binary byte sequence. This function will read the byte sequence and automatically detect its binary format if autoDetect is true. Otherwise, it will consider the given binary sequence as a raw binary (just a series of machine instructions without specific file format).
|
Full Usage:
BinHandle.LiftBBlock(hdl, bp)
Parameters:
BinHandle
bp : BinaryPointer
Returns: Result<(Stmt[] * BinaryPointer), (Stmt[] * BinaryPointer)>
|
Return the lifted IR (an array of statements) of a basic block pointed to by the binary pointer (bp). This function returns a partial bblock with Error, if the parsing of the bblock was not successful.
|
Full Usage:
BinHandle.LiftInstr(hdl) (ins)
Parameters:
BinHandle
ins : Instruction
Returns: Stmt[]
|
Lift a parsed instruction (Instruction) to produce an array of IR statements from a given BinHandle.
|
Full Usage:
BinHandle.LiftOptimizedInstr(hdl) (ins)
Parameters:
BinHandle
ins : Instruction
Returns: Stmt[]
|
Lift a parsed instruction (Instruction) to produce an array of optimized IR statements from a given BinHandle.
|
|
|
Full Usage:
BinHandle.ParseBBlock(arg1, bp)
Parameters:
BinHandle
bp : BinaryPointer
Returns: Result<Instruction list, Instruction list>
|
Parse a basic block pointed to by the binary pointer (bp), and return the sequence of the instructions of the basic block. This function may return an incomplete basic block as an Error type. This function can be safely used for any ISAs, and thus, this should be the main parsing function.
|
Full Usage:
BinHandle.ParseBBlock(arg1, addr)
Parameters: Returns: Result<Instruction list, Instruction list>
|
Parse a basic block from the given address, and return the sequence of the instructions of the basic block. This function may return an incomplete basic block as an Error type. This function can be safely used for any ISAs, and thus, this should be the main parsing function.
|
Full Usage:
BinHandle.ParseInstr(hdl, bp)
Parameters:
BinHandle
-
BinHandle.
bp : BinaryPointer
-
BinaryPointer.
Returns: Instruction
Parsed instruction.
|
Parse one instruction pointed to by binary pointer (bp) from the BinHandle, and return the corresponding instruction. This function raises an exception if the parsing process failed.
|
|
Parse one instruction at the given address (addr) from the BinHandle, and return the corresponding instruction. This function raises an exception if the parsing process failed.
|
|
|
Full Usage:
BinHandle.ReadASCII(hdl, bp)
Parameters:
BinHandle
-
BinHandle.
bp : BinaryPointer
-
BinaryPointer.
Returns: string
Return the corresponding ASCII string.
|
|
|
|
Full Usage:
BinHandle.ReadBytes(hdl, bp, nBytes)
Parameters:
BinHandle
-
BinHandle.
bp : BinaryPointer
-
BinaryPointer.
nBytes : int
-
The size of the byte array (in bytes).
Returns: byte[]
Return the byte array if succeed. Otherwise, raise an exception.
|
Return the byte array of size (nBytes) from the given BinHandle, which is pointed to by the BinaryPointer (bp).
|
|
|
Full Usage:
BinHandle.ReadInt(hdl, bp, size)
Parameters:
BinHandle
-
BinHandle.
bp : BinaryPointer
-
BinaryPointer.
size : int
-
The size of the integer in bytes. Maximum 8 bytes is
possible.
Returns: int64
Return the corresponding integer (int64).
|
Return the corresponding integer value of the size from the given BinHandle (hdl), which is pointed to by the binary pointer (bp).
|
|
|
Full Usage:
BinHandle.ReadUInt(hdl, bp, size)
Parameters:
BinHandle
-
BinHandle.
bp : BinaryPointer
-
BinaryPointer.
size : int
-
The size of the integer in bytes. Maximum 8 bytes is
possible.
Returns: uint64
Return the corresponding unsigned integer (uint64).
|
Return the corresponding unsigned integer value of the size from the given BinHandle (hdl), which is pointed to by the binary pointer (bp).
|
|
|
Full Usage:
BinHandle.TryParseInstr(hdl, bp)
Parameters:
BinHandle
-
BinHandle.
bp : BinaryPointer
-
BinaryPointer.
Returns: Result<Instruction, ErrorCase>
Parsed instruction (option type).
|
Parse one instruction pointed to by the binary pointer (bp) from the BinHandle, and return the corresponding instruction. This function does not raise an exception, but returns an option type.
|
Full Usage:
BinHandle.TryParseInstr(hdl, addr)
Parameters: Returns: Result<Instruction, ErrorCase>
Parsed instruction (option type).
|
Parse one instruction at the given address (addr) from the BinHandle, and return the corresponding instruction. This function does not raise an exception, but returns an option type.
|
Full Usage:
BinHandle.TryReadBytes(hdl, bp, nBytes)
Parameters:
BinHandle
-
BinHandle.
bp : BinaryPointer
-
BinaryPointer.
nBytes : int
-
The size of the byte array (in bytes).
Returns: Result<byte[], ErrorCase>
Return (byte []) if succeeded, (ErrorCase) otherwise.
|
Return the byte array of size (nBytes) from the BinHandler (hdl), which is pointed to by the BinaryPointer (bp). The return value is an option type. When the given address is invalid, this function returns None.
|
|
Return the byte array of size (nBytes) at the addr from the given BinHandle (hdl). The return value is an option type. When the given address is invalid, this function returns None. |
Full Usage:
BinHandle.TryReadInt(hdl, bp, size)
Parameters:
BinHandle
-
BinHandle.
bp : BinaryPointer
-
BinaryPointer.
size : int
-
The size of the integer in bytes. Maximum 8 bytes is
possible.
Returns: Result<int64, ErrorCase>
Return the corresponding value (int64) if the address and the size is
valid. Otherwise ErrorCase.
|
Return the corresponding integer option value of the size from the given BinHandle (hdl), which is pointed to by the binary pointer (bp).
|
Full Usage:
BinHandle.TryReadInt(hdl, addr, size)
Parameters:
BinHandle
-
BinHandle.
addr : Addr
-
The address.
size : int
-
The size of the integer in bytes. Maximum 8 bytes is
possible.
Returns: Result<int64, ErrorCase>
Return the corresponding value (int64) if the address and the size is
valid. Otherwise ErrorCase.
|
|
Full Usage:
BinHandle.TryReadUInt(hdl, bp, size)
Parameters:
BinHandle
-
BinHandle.
bp : BinaryPointer
-
BinaryPointer.
size : int
-
The size of the integer in bytes. Maximum 8 bytes is
possible.
Returns: Result<uint64, ErrorCase>
Return the corresponding unsigned integer (uint64) if the address and
the size is valid. Otherwise, ErrorCase.
|
Return the corresponding unsigned integer option value of the size from the given BinHandle (hdl), which is pointed to by the binary pointer (bp).
|
Full Usage:
BinHandle.TryReadUInt(hdl, addr, size)
Parameters:
BinHandle
-
BinHandle.
addr : Addr
-
The address.
size : int
-
The size of the integer in bytes. Maximum 8 bytes is
possible.
Returns: Result<uint64, ErrorCase>
Return the corresponding unsigned integer (uint64) if the address and
the size is valid. Otherwise, ErrorCase.
|
Return the corresponding unsigned integer option value at the addr of the size from the given BinHandle. |
|
|