Exemplo n.º 1
0
int lua_elf_t_section_exists (lua_State * L)
{
    struct _elf * elf;
    struct _elf_section section;
    int section_i;
    int found;
    char * name;
    
    elf = lua_check_elf(L, 1);
    name = (char *) luaL_checkstring(L, 2);
    lua_pop(L, 2);
    
    found = 0;
    for (section_i = 0; section_i < int_t_get(elf_shnum(elf)); section_i++) {
        elf_section(elf, &section, section_i);
        if (strcmp(elf_section_name(&section), name) == 0) {
            found = 1;
            break;
        }
    }
    
    if (found)
        lua_pushboolean(L, 1);
    else
        lua_pushboolean(L, 0);
    
    return 1;
}
Exemplo n.º 2
0
ELF_HANDLE_DECL(elf_shdr) elf_shdr_by_name(struct elf_binary *elf, const char *name)
{
    uint64_t count = elf_shdr_count(elf);
    ELF_HANDLE_DECL(elf_shdr) shdr;
    const char *sname;
    unsigned i;

    for ( i = 0; i < count; i++ )
    {
        shdr = elf_shdr_by_index(elf, i);
        if ( !elf_access_ok(elf, ELF_HANDLE_PTRVAL(shdr), 1) )
            /* input has an insane section header count field */
            break;
        sname = elf_section_name(elf, shdr);
        if ( sname && !strcmp(sname, name) )
            return shdr;
    }
    return ELF_INVALID_HANDLE(elf_shdr);
}
Exemplo n.º 3
0
int lua_elf_t_section (lua_State * L)
{
    struct lua_elf_t * elf;
    struct _elf_section section;
    int section_i = -1;
    int found;
    struct lua_elf_section_t * section_t;
    
    elf = lua_check_elf_t(L, 1);
    if (lua_isnumber(L, 2))
        section_i = luaL_checkinteger(L, 2);
    else if (lua_isstring(L, 2)) {
        found = 0;
        for (section_i = 0; section_i < int_t_get(elf_shnum(elf->elf));
             section_i++) {
            elf_section(elf->elf, &section, section_i);
            if (strcmp(elf_section_name(&section), lua_tostring(L, 2)) == 0) {
                found = 1;
                break;
            }
        }
        if (! found)
            luaL_error(L, "no section found by name %s", lua_tostring(L, 2));
    }
    else
        luaL_error(L, "expected a string or number");
    lua_pop(L, 2);
    
    if (section_i >= int_t_get(elf_shnum(elf->elf)))
        luaL_error(L, "elf does not have %d sections", section_i);
    
    lua_push_elf_section_t(L);
    section_t = lua_check_elf_section_t(L, 1);
    elf_section(elf->elf, &(section_t->section), section_i);
    section_t->elf_t = elf;
    elf->ref_count++;
    
    return 1;
}
Exemplo n.º 4
0
{
    struct lua_elf_section_t ** section;
    
    void * userdata = luaL_checkudata(L, 1, "rop_tools.elf_section_t");
    luaL_argcheck(L, userdata != NULL, 1, "elf_section_t expected");
    section = (struct lua_elf_section_t **) userdata;

    lua_elf_section_t_collect(*section);
    
    return 0;
}


int lua_elf_section_t_name (lua_State * L)
{
    LUA_ELF_SECTION_T_ACCESSOR(lua_pushstring, elf_section_name(section))
}


int lua_elf_section_t_address (lua_State * L)
{
    LUA_ELF_SECTION_T_ACCESSOR(lua_push_uint_t, elf_section_addr(section))
}


int lua_elf_section_t_exec (lua_State * L)
{
    LUA_ELF_SECTION_T_ACCESSOR(lua_pushboolean, elf_section_exec(section))
}