|
2 | 2 |
|
3 | 3 | This command will create or search a [De |
4 | 4 | Bruijn](https://en.wikipedia.org/wiki/De_Bruijn_sequence) cyclic pattern to |
5 | | -facilitate determining offsets in memory. |
| 5 | +facilitate determining offsets in memory. The sequence consists of a number of |
| 6 | +unique substrings of a chosen length. |
6 | 7 |
|
7 | 8 | It should be noted that for better compatibility, the algorithm implemented in |
8 | 9 | `GEF` is the same as the one in `pwntools`, and can therefore be used in |
9 | 10 | conjunction. |
10 | 11 |
|
11 | | -### create |
| 12 | +### create ### |
12 | 13 |
|
13 | | -The sub-command `create` allows to create a new pattern: |
| 14 | +``` |
| 15 | +pattern create [-h] [-n N] [length] |
| 16 | +``` |
| 17 | + |
| 18 | +The sub-command `create` allows one create a new De Bruijn sequence. The |
| 19 | +optional argument `n` determines the length of unique subsequences. Its default |
| 20 | +value matches the currently loaded architecture. The `length` argument sets the |
| 21 | +total length of the whole sequence. |
14 | 22 |
|
15 | 23 | ``` |
16 | | -gef➤ pattern create 128 |
17 | | -[+] Generating a pattern of 128 bytes |
| 24 | +gef➤ pattern create -n 4 128 |
| 25 | +[+] Generating a pattern of 128 bytes (n=4) |
18 | 26 | aaaabaaacaaadaaaeaaafaaagaaahaaaiaaajaaakaaalaaamaaanaaaoaaapaaaqaaaraaasaaataaauaaavaaawaaaxaaayaaazaabbaabcaabdaabeaabfaabgaab |
19 | 27 | [+] Saved as '$_gef0' |
20 | 28 | ``` |
21 | 29 |
|
22 | | -Ths pattern can be used as as input later on. To generate this input, `GEF` |
23 | | -takes into account the size of architecture (16, 32 or 64 bits), to generate |
24 | | -it. |
25 | | - |
26 | 30 | The equivalent command with `pwntools` is |
| 31 | + |
27 | 32 | ```python |
28 | 33 | from pwn import * |
29 | 34 | p = cyclic(128, n=8) |
30 | 35 | ``` |
31 | | -where `n` is the number of bytes of the architecture (8 for 64 bits, 4 for 32). |
32 | 36 |
|
| 37 | +### search ### |
| 38 | + |
| 39 | +``` |
| 40 | +pattern search [-h] [-n N] [--max-length MAX_LENGTH] [pattern] |
| 41 | +``` |
| 42 | + |
| 43 | +The `search` sub-command seeks the `pattern` given as argument, trying to find |
| 44 | +its offset in the De Bruijn sequence. The optional argument `n` determines the |
| 45 | +length of unique subsequences, and it should usually match the length of |
| 46 | +`pattern`. Using `MAX_LENGTH` the maximum length of the sequence to search in |
| 47 | +can be adjusted. |
33 | 48 |
|
34 | | -### search |
| 49 | +Note that the `pattern` can be passed as a GDB symbol (such as a register name), |
| 50 | +a string or a hexadecimal value |
35 | 51 |
|
36 | | -The `search` sub-command seeks the value given as argument, trying to find it in |
37 | | -the De Bruijn sequence |
38 | 52 | ``` |
39 | 53 | gef➤ pattern search 0x6161616161616167 |
40 | 54 | [+] Searching '0x6161616161616167' |
41 | 55 | [+] Found at offset 48 (little-endian search) likely |
42 | 56 | [+] Found at offset 41 (big-endian search) |
43 | | -``` |
44 | | - |
45 | | -Note that registers can also be passed as values: |
46 | | -``` |
47 | 57 | gef➤ pattern search $rbp |
48 | 58 | [+] Searching '$rbp' |
49 | 59 | [+] Found at offset 32 (little-endian search) likely |
50 | 60 | [+] Found at offset 25 (big-endian search) |
| 61 | +gef➤ pattern search aaaaaaac |
| 62 | +[+] Searching for 'aaaaaaac' |
| 63 | +[+] Found at offset 16 (little-endian search) likely |
| 64 | +[+] Found at offset 9 (big-endian search) |
51 | 65 | ``` |
0 commit comments