Articles tagged #nom

Day 11 (Advent of Code 2022)

It's a new day, it's a new advent of code puzzle.

In that one, we have to apparently cosplay as an IBM mainframe and just.. crunch them numbers. This doesn't look fun, and I can't think of a clever twist to make it fun, so let's try to make it short and sweet.

Parsing

Our input looks like this:

Monkey 0:
  Starting items: 79, 
  Operation new = old  
  Test divisible by 
    If true throw to monkey 
    If false throw to monkey 

Monkey 
  Starting items    
  Operation new = old + 
  Test divisible by 
    If true throw to monkey 
    If false throw to monkey 

etc

Day 5 (Advent of Code 2022)

Part 1

The day 5 challenge actually looks fun!

Our input looks like this:

    [D]
[N] [C]
[Z] [M] [P]
 1   2   3

move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2

Which is a visual representation of stacks, and so, for once, we have some serious parsing to do, and that means I finally have a good reason to bust out the nom crate.

GDB scripting and Indirect functions

In the last article, we cleaned up our dynamic linker a little. We even implemented the Dynamic relocation.

But it's still pretty far away from running real-world applications.

Let's try running a simple C application with it:

// in `samples/puts.c`

#include <stdio.h>

int main() {
    puts("Hello from C");
    return 0;
}
$ cd samples/
$ gcc puts.c -o puts
$ ../target/debug/elk ./puts
Loading "/home/amos/ftl/elk/samples/puts"
Loading "/usr/lib/libc-2.32.so"
Fatal error: Could not read symbols from ELF object: Parsing error: String("Unknown SymType 10 (0xa)"):
input: 1a 00 10 00 a0 bf 0b 00 00 00 00 00 c1 00 00 00 00 00 00 00

Go back to the homepage.