wargio / libvle

PowerPC VLE disassembler library
GNU Lesser General Public License v3.0
5 stars 5 forks source link

Usage of the buffer pointer in vle_init #16

Closed Alireza-Razavi closed 3 years ago

Alireza-Razavi commented 3 years ago

I have compiled the project using make.exe and it gave me a static library (.a file extension) Then i imported the static library into my Qt project. I wanna paste the code that you have written in 'example' section in your README file but there is one argument 'buffer' is missed. What is the 'buffer' argument in vle_init(...) and what should i pass ??

wargio commented 3 years ago

It is the pointer to the buffer that contains the assembled instructions/machine code.

Alireza-Razavi commented 3 years ago

Thanks for your answer. How should i write it in Qt/Cpp ? Could you leave me an example code ?

wargio commented 3 years ago
char decoded[128];
vle_t *instr = NULL;
vle_handle handle = {0};

if (vle_init(&handle, buffer, buffer_size, start_address) != 0) {
    // do something since it errored
}

while((instr = vle_next(&handle))) {
    vle_snprint(decoded, sizeof(decoded), instr);
    printf("decoded: %s\n", decoded);
    vle_free(instr);
}
Alireza-Razavi commented 3 years ago

You have not initialized the 'buffer' but you passed to the function. How is it possible to pass an argument which is not declared?!

wargio commented 3 years ago

because you are the one that is supposed to pass the buffer to a .text segment; this library does not implement any executable parser like ELF, PE, etc..

If you use capstone or any similar libraries, is the same

Alireza-Razavi commented 3 years ago

So we couldn't disassemble a Dump file which is compiled for the Power PC with VLE processors ? I have a dump file that i have read from a micro controller (SPC5 with Power architecture) and i wanted to disassemble it using this library.

wargio commented 3 years ago

if the dump is raw binary section, yes you can, if it is not, then you need to parse the container. You can find which format is the file by using file or binwalk or rz-bin (from https://rizin.re)

Alireza-Razavi commented 3 years ago
    ut8 buffer[256];    // Read bytes from dump and load into buffer
    ut8 *p = &buffer[0];  // Pointer to the first element of array

    ut32 start_address = 0x08004000;
    vle_t* instr = NULL;
    vle_handle handle;

    if (vle_init(&handle, p, 256, start_address)) {
        printf("failed to initialize handle\n");
        return;
    }

This is correct ?

wargio commented 3 years ago

yes

Alireza-Razavi commented 3 years ago

Thanks a lot.