// File: illmat[P]MemCrawl/maps.cpp
// Function: getRegions(std::vector<scanRegion, std::allocator<scanRegion>>&, int)
int getRegions(std::vector<scanRegion> &regions, pid_t pid)
{
    std::stringstream path;
    path << "/proc/" << pid << "/maps";
    std::cout << "path:" << path.str() << std::endl;
    FILE *fp;
    char *line = NULL;
    size_t len = 0;
    ssize_t read;

    fp = fopen(path.str().c_str(), "r");
    if (fp == NULL)
    {
        std::cout << "unable to open file" << std::endl;
        return 1;
    }

    scanRegion lineBuffer;
    char readable, writeable;

    while ((read = getline(&line, &len, fp)) != -1)
    {
        if (sscanf(line, "%lx-%lx %c%c", &lineBuffer.startRegion, &lineBuffer.endRegion, &readable, &writeable) >= 4)
        {
            if ((readable == 'r') && (writeable == 'w'))
            {
                regions.push_back(lineBuffer);
            }
        }

    }
    fclose(fp);
    free(line);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x3170
leaq -0x190(%rbp), %rdi
leaq 0x2bed(%rip), %rsi      # 0x9159
callq 0x3230
movq %rax, -0x238(%rbp)
jmp 0x657a
movq -0x238(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x33d0
movq %rax, -0x240(%rbp)
jmp 0x6592
movq -0x240(%rbp), %rdi
leaq 0x2bc0(%rip), %rsi      # 0x9160
callq 0x3230
jmp 0x65a7
movq 0x6a22(%rip), %rdi      # 0xcfd0
leaq 0x2bb1(%rip), %rsi      # 0x9166
callq 0x3230
movq %rax, -0x248(%rbp)
jmp 0x65c3
leaq -0x1d0(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x3220
jmp 0x65d8
movq -0x248(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x3200
movq %rax, -0x250(%rbp)
jmp 0x65f4
movq -0x250(%rbp), %rdi
movq 0x69be(%rip), %rsi      # 0xcfc0
callq 0x3280
jmp 0x6609
leaq -0x1d0(%rbp), %rdi
callq 0x3150
movq $0x0, -0x1e0(%rbp)
movq $0x0, -0x1e8(%rbp)
leaq -0x210(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x3220
jmp 0x6640
leaq -0x210(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
leaq 0x2b16(%rip), %rsi      # 0x916c
callq 0x32d0
movq %rax, -0x258(%rbp)
jmp 0x6664
movq -0x258(%rbp), %rax
movq %rax, -0x1d8(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x3150
cmpq $0x0, -0x1d8(%rbp)
jne 0x6730
movq 0x693d(%rip), %rdi      # 0xcfd0
leaq 0x2ad4(%rip), %rsi      # 0x916e
callq 0x3230
movq %rax, -0x260(%rbp)
jmp 0x66a8
movq -0x260(%rbp), %rdi
movq 0x690a(%rip), %rsi      # 0xcfc0
callq 0x3280
jmp 0x66bd
movl $0x1, -0x4(%rbp)
movl $0x1, -0x214(%rbp)
jmp 0x6801
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x6819
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x3150
jmp 0x6819
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x3150
jmp 0x6819
jmp 0x6732
movq -0x1d8(%rbp), %rdx
leaq -0x1e0(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x3320
movq %rax, -0x268(%rbp)
jmp 0x6755
movq -0x268(%rbp), %rax
movq %rax, -0x1f0(%rbp)
cmpq $-0x1, %rax
je 0x67d6
movq -0x1e0(%rbp), %rdi
leaq -0x228(%rbp), %rdx
leaq -0x228(%rbp), %rcx
addq $0x8, %rcx
leaq 0x29f9(%rip), %rsi      # 0x9182
leaq -0x229(%rbp), %r8
leaq -0x22a(%rbp), %r9
movb $0x0, %al
callq 0x3210
cmpl $0x4, %eax
jl 0x67d1
movsbl -0x229(%rbp), %eax
cmpl $0x72, %eax
jne 0x67cf
movsbl -0x22a(%rbp), %eax
cmpl $0x77, %eax
jne 0x67cf
movq -0x10(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x6840
jmp 0x67cd
jmp 0x67cf
jmp 0x67d1
jmp 0x6732
movq -0x1d8(%rbp), %rdi
callq 0x3240
jmp 0x67e4
movq -0x1e0(%rbp), %rdi
callq 0x32e0
movl $0x0, -0x4(%rbp)
movl $0x1, -0x214(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x3190
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
leaq -0x1a0(%rbp), %rdi
callq 0x3190
movq -0x1a8(%rbp), %rdi
callq 0x33e0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)