Skip to content

Commit fb7c7bb

Browse files
committed
docs: small emulator docs tweaks
1 parent b8ec547 commit fb7c7bb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ More detailed tutorial about specific features is in development. Completed chap
135135

136136
* [Emulator](https://msm-code.github.io/ghidralib/emulator/)
137137

138-
If you prefer to learn by example, tou can also browse the [examples](./examples/) directory.
138+
If you prefer to learn by example, you can also browse the [examples](./examples/) directory.
139139

140140
A fair warning: ghidralib is still actively developed and the API may change
141141
slightly in the future. But this doesn't matter for your one-off scripts, does it?

docs/emulator.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ void check(int value) {
3232
}
3333

3434
int main(int argc, char *argv[]) {
35+
if (argc != 2) { return 1; }
3536
check(atoi(argv[1]));
37+
return 0;
3638
}
3739
```
3840
@@ -274,6 +276,10 @@ emu.add_hook(Symbol("hash").address, hash_hook)
274276
emu.emulate(Symbol("check").address)
275277
```
276278

279+
**Exercise**: Create a hook for `atoi` function that will simulate the libc function -
280+
it should parse the string from the parameter and return it in RAX. Test it by emulating
281+
the "call atoi" instruction with a string parameter.
282+
277283
### State inspection
278284

279285
Of course, after emulation we are interested in the final state of the emulator.
@@ -319,6 +325,10 @@ It doesn't get any easier than that. The `simple` in the name refers to the retu
319325
in many cases you will want to use `Function.emulate` to get the whole context of the
320326
emulator after execution.
321327

328+
**Exercise**: Complete the `atoi` hook from the previous exercise first. Then create an emulator,
329+
add `printf` and `atoi` hooks, and execute a `main` function with the correct parameters.
330+
This will require you to pass correct `argc` and `argv` parameters.
331+
322332
### Misc features
323333

324334
**maxsteps**

0 commit comments

Comments
 (0)