XRef
Documentation menu
xrefcode.com / docs / cli / data

$ xref data

On this page
  1. Usage
  2. Arguments and options
  3. Examples
  4. A string in read-only data
  5. The same bytes as a hex dump
  6. Zero-initialised data
  7. An address outside the binary
  8. Reading the output
  9. Limits
  10. Provenance

Read typed values at a virtual address of the binary: the address is mapped through the load segments (ELF PT_LOAD, Mach-O segments) and each element is printed with its address. Use it when pseudo-C or assembly loads from a constant address (a table indexed by some value, a string, a constant) and you want the values without writing an ELF reader.

Usage

xref data [OPTIONS] --as <AS_TYPE> <VA>

Arguments and options

Arguments

<VA>
Virtual address to read from (0x... hex or decimal).

Options

--as <AS_TYPE>
Data type to read (f64, f32, u64, u32, u16, u8, i64, i32, i16, i8, bytes, str) [possible values: f64, f32, u64, u32, u16, u8, i64, i32, i16, i8, bytes, str].
--count <COUNT>
Number of elements to read (byte count for bytes; default 1, or 64 for bytes).
--max-len <MAX_LEN>
Maximum string length to read up to the first NUL (default 256).
default 256

Examples

A string in read-only data

0x492c0b is the string ripgrep's statistics serializer passes (see card). The serializer slices it by length, so the bytes after the first key belong to the next keys:

Command
$ xref -b rg data 0x492c0b --as str
Output
0x492c0b  str  "elapsedsearchessearches_with_matchbytes_searchedbytes_printedmatched_linesmatchesbeginendmatchcontextstartnanoshumanPoisonError\n"
stderr
xref: load 2.5ms, total 2.5ms

The same bytes as a hex dump

Command
$ xref -b rg data 0x492c0b --as bytes --count 32
Output
0x492c0b  65 6c 61 70 73 65 64 73 65 61 72 63 68 65 73 73
0x492c1b  65 61 72 63 68 65 73 5f 77 69 74 68 5f 6d 61 74
stderr
xref: load 2.4ms, total 2.4ms

Zero-initialised data

0x84a560 is past the file-backed part of ripgrep's writable segment, so the values are zero in the file and marked (bss):

Command
$ xref -b rg data 0x84a560 --as u64 --count 2
Output
0x84a560  u64  0  (bss)
0x84a568  u64  0  (bss)
stderr
xref: load 1.9ms, total 1.9ms

An address outside the binary

Command
$ xref -b rg data 0x900000 --as f64

(no stdout)

Exit status 1.

stderr
xref: VA 0x900000 is outside all segments; nearest segment is 0x785af0..0x896148 (permissions: ?w- (read bit not recorded))

Reading the output

Limits

Provenance

Recorded with a development build of xref after 0.4.0 on Linux x86-64, on rg = ripgrep 14.1.1 (official stripped release). Output is unchanged except that whitespace at the end of each line and empty lines at the end of the output are removed; long outputs are cut where marked.

Source: docs/cli/data.md · generated for the site; edit the Markdown, not this page.