cyrus-and / gdb-dashboard

Modular visual interface for GDB in Python
MIT License
11.1k stars 780 forks source link

Memory window #289

Closed VinayWolf closed 1 year ago

VinayWolf commented 1 year ago

Hello, for viewing memory locations i am using basic memory location accessing code in C. but that location is not showing in the window.Can you provide any sample code for memory windows access.

include

This is the code i am using but not getting memory lcoations in memory window

int main() { // Declare a pointer variable of type 'unsigned short' unsigned short ptr; // Declare a variable to hold the memory location unsigned int memory_location = 0x1234; // Assign the memory location to the pointer variable ptr = (unsigned short )memory_location; // Assign a value to the memory location using the pointer variable ptr = 0xABCD; // Read the value from the memory location using the pointer variable unsigned short value = ptr; // Print the value to the console printf("Value at memory location 0x%04X is 0x%04X\n", memory_location, value); return 0; }

please help me out. Thank You

cyrus-and commented 1 year ago

The Memory module is used to watch memory locations and show the corresponding hex dump:

>>> dashboard memory watch argv[0]
─── Memory ───────────────────────────────────────────────────────────────────────────
─── argv[0] ──────────────────────────────────────────────────────────────────────────
0x00007fffffffef3e  2f 72 6f 6f 74 2f 70 72 6f 67 72 61 6d 00 48 4f  /root/program·HO

The Expressions module is used to dump values:

>>> dashboard expressions watch argv[0]
─── Expressions ─────────────────────────────────
argv[0] = 0x7fffffffef3e "/root/program": 47 '/'
VinayWolf commented 1 year ago

Hello, can you just provide any sample code for the memory window demo.As per the your github gdb dashboard image where in memory window variables with memory and its values are showing.Provide sample code you have tested. Thank You.

On Fri, 24 Mar 2023 at 18:20, Andrea Cardaci @.***> wrote:

Closed #289 https://github.com/cyrus-and/gdb-dashboard/issues/289 as completed.

— Reply to this email directly, view it on GitHub https://github.com/cyrus-and/gdb-dashboard/issues/289#event-8838346953, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZC4KW7JSPDHX7553FWY2I3W5WJ73ANCNFSM6AAAAAAWGFLOCQ . You are receiving this because you authored the thread.Message ID: @.***>

cyrus-and commented 1 year ago

Not sure why you need this but here it is:

/* -*- compile-command: "gcc -Wall -pedantic -ggdb3 xor.c -o xor" -*- */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static void encrypt(const char *password, const char *text, char *output)
{
    size_t password_length;
    size_t text_length;
    size_t i;

    /* obtain the lengths */
    password_length = strlen(password);
    text_length = strlen(text);

    /* perform the encryption */
    for (i = 0; i < text_length; i++) {
        output[i] = text[i] ^ password[i % password_length];
    }
}

static void dump(char *output, size_t length)
{
    size_t i;

    /* write each byte in hex base */
    for (i = 0; i < length; i++) {
        printf("%02x ", output[i]);
    }

    /* write terminator */
    printf("\n");
}

int main(int argc, char *argv[])
{
    const char *password;
    const char *text;
    size_t text_length;
    char *output;

    /* check program arguments */
    if (argc != 3) {
        fprintf(stderr, "[!] Usage: <password> <text>\n");
        return EXIT_FAILURE;
    } else {
        password = argv[1];
        text = argv[2];
    }

    /* allocate output buffer */
    text_length = strlen(text);
    output = malloc(text_length);

    /* encrypt the text */
    encrypt(password, text, output);

    /* dump the cipertext */
    dump(output, text_length);

    /* clean up and exit */
    free(output);
    return 0;
}

And the corresponding GDB script is:

set confirm off
set disassembly-flavor intel

dashboard assembly -style opcodes True
dashboard memory -style cumulative True
dashboard variables -style compact False

break xor.c:56
break encrypt
break dump if i = 5
run hunter2 'doesnt look like stars to me'
disable 3

dashboard memory watch password
dashboard memory watch text 32
dashboard memory watch output 32

dashboard expression watch text[i]
dashboard expression watch password[i % password_length]
dashboard expression watch output[i]

continue

print output
print password

watch output[10]

continue

next
next
VinayWolf commented 1 year ago

Dear, sorry for inconvenience,while I was debugging it was showing a 16-byte address so I asked you for the code. Thanks

On Thu, 30 Mar 2023 at 14:50, Andrea Cardaci @.***> wrote:

Not sure why you need this but here it is:

/ -- compile-command: "gcc -Wall -pedantic -ggdb3 xor.c -o xor" -- /

include

include

include

static void encrypt(const char password, const char text, char *output) { size_t password_length; size_t text_length; size_t i;

/* obtain the lengths */
password_length = strlen(password);
text_length = strlen(text);

/* perform the encryption */
for (i = 0; i < text_length; i++) {
    output[i] = text[i] ^ password[i % password_length];
}

} static void dump(char *output, size_t length) { size_t i;

/* write each byte in hex base */
for (i = 0; i < length; i++) {
    printf("%02x ", output[i]);
}

/* write terminator */
printf("\n");

} int main(int argc, char argv[]) { const char password; const char text; size_t text_length; char output;

/* check program arguments */
if (argc != 3) {
    fprintf(stderr, "[!] Usage: <password> <text>\n");
    return EXIT_FAILURE;
} else {
    password = argv[1];
    text = argv[2];
}

/* allocate output buffer */
text_length = strlen(text);
output = malloc(text_length);

/* encrypt the text */
encrypt(password, text, output);

/* dump the cipertext */
dump(output, text_length);

/* clean up and exit */
free(output);
return 0;

}

And the corresponding GDB script is:

set confirm offset disassembly-flavor intel

dashboard assembly -style opcodes True dashboard memory -style cumulative True dashboard variables -style compact False break xor.c:56break encryptbreak dump if i = 5run hunter2 'doesnt look like stars to me'disable 3

dashboard memory watch password dashboard memory watch text 32 dashboard memory watch output 32

dashboard expression watch text[i] dashboard expression watch password[i % password_length] dashboard expression watch output[i] continue print outputprint password watch output[10] continue nextnext

— Reply to this email directly, view it on GitHub https://github.com/cyrus-and/gdb-dashboard/issues/289#issuecomment-1489975150, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZC4KW7G7G3NGPWMSVDO4TDW6VF5PANCNFSM6AAAAAAWGFLOCQ . You are receiving this because you authored the thread.Message ID: @.***>

cyrus-and commented 1 year ago

No inconvenience at all, good luck!