Ejemplo n.º 1
0
void *dlsym(void *handle, const char *name)
{
	int error = 0;
	int dl = (int)handle;
	void* symbol;

	if( dl == 0 )
	{
		__dl_set_errno( _DL_EBADHANDLE );
		return( NULL );
	}

	if( name == NULL )
	{
		__dl_set_errno( _DL_EBADSYMBOL );
		return( NULL );
	}

	if( dl == RTLD_NEXT )
	{
		__dl_set_errno( _DL_EBADHANDLE );
		return( NULL );
	}

	error = get_symbol_address( dl, name, -1, (void**) &symbol );
	if( error < 0 )
	{
		__dl_set_errno( _DL_ENOSYM );
		return( NULL );
	}

	return( symbol );
}
Ejemplo n.º 2
0
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
				    const char *pathname, FILE *fp)
{
	void *p;
	int lib;
	char funcname[258];

	if (Py_VerboseFlag)
		printf("load_library %s\n", pathname);

	lib = load_library(pathname, 0);
	if (lib < 0) {
		char buf[512];
		if (Py_VerboseFlag)
			perror(pathname);
		PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s: %.200s",
			      pathname, strerror(errno));
		PyErr_SetString(PyExc_ImportError, buf);
		return NULL;
	}
	PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname);
	if (Py_VerboseFlag)
		printf("get_symbol_address %s\n", funcname);
	if (get_symbol_address(lib, funcname, -1, &p) < 0) {
		p = NULL;
		if (Py_VerboseFlag)
			perror(funcname);
	}

	return (dl_funcptr) p;
}
Ejemplo n.º 3
0
void *
__libc_dlsym (void *map, const char *name)
{
	int error = 0;
	int *dl = (int*)map;
	void* symbol;

	if( name == NULL || dl == NULL || *dl == RTLD_NEXT )
		return NULL;

	error = get_symbol_address( *dl, name, -1, (void**) &symbol );
	if( error < 0 )
		return NULL;

	return symbol;
}
Ejemplo n.º 4
0
static void add_addr(uint64_t addr) {
    add_hex_uint64(addr);
#if ENABLE_Symbols
    if (ctx != NULL) {
        Symbol * sym = NULL;
        char * name = NULL;
        ContextAddress sym_addr = 0;
        if (find_symbol_by_addr(ctx, STACK_NO_FRAME, (ContextAddress)addr, &sym) < 0) return;
        if (get_symbol_name(sym, &name) < 0 || name == NULL) return;
        if (get_symbol_address(sym, &sym_addr) < 0) return;
        if (sym_addr <= addr) {
            add_str(" ; ");
            add_str(name);
            if (sym_addr < addr) {
                add_str(" + 0x");
                add_hex_uint64(addr - sym_addr);
            }
        }
    }
#endif
}
Ejemplo n.º 5
0
void do_sym_to_addr(Monitor* mon, int pid, const char* modName, const char* symName)
{
  get_symbol_address(mon, pid, modName, symName);
}
Ejemplo n.º 6
0
static void command_get_context(char * token, Channel * c) {
    int err = 0;
    char id[256];
    Symbol sym;

    json_read_string(&c->inp, id, sizeof(id));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

    if (id2symbol(id, &sym) < 0) err = errno;

    write_stringz(&c->out, "R");
    write_stringz(&c->out, token);
    write_errno(&c->out, err);

    if (err == 0) {
        char * name = NULL;
        int type_class = TYPE_CLASS_UNKNOWN;
        Symbol type;
        size_t size = 0;
        void * value = NULL;
        unsigned long length = 0;
        unsigned long offset = 0;
        ContextAddress address = 0;
        int frame = STACK_NO_FRAME; /* TODO: symbol frame */

        write_stream(&c->out, '{');

        json_write_string(&c->out, "ID");
        write_stream(&c->out, ':');
        json_write_string(&c->out, id);
        write_stream(&c->out, ',');

        json_write_string(&c->out, "ExeID");
        write_stream(&c->out, ':');
        json_write_string(&c->out, container_id(sym.ctx));
        write_stream(&c->out, ',');

        if (get_symbol_name(&sym, &name) == 0 && name != NULL) {
            json_write_string(&c->out, "Name");
            write_stream(&c->out, ':');
            json_write_string(&c->out, name);
            write_stream(&c->out, ',');
            loc_free(name);
        }

        if (get_symbol_type_class(&sym, &type_class) == 0 && type_class != TYPE_CLASS_UNKNOWN) {
            json_write_string(&c->out, "TypeClass");
            write_stream(&c->out, ':');
            json_write_long(&c->out, type_class);
            write_stream(&c->out, ',');
        }

        if (get_symbol_type(&sym, &type) == 0) {
            json_write_string(&c->out, "TypeID");
            write_stream(&c->out, ':');
            json_write_string(&c->out, symbol2id(&type));
            write_stream(&c->out, ',');
        }

        if (get_symbol_base_type(&sym, &type) == 0) {
            json_write_string(&c->out, "BaseTypeID");
            write_stream(&c->out, ':');
            json_write_string(&c->out, symbol2id(&type));
            write_stream(&c->out, ',');
        }

        if (get_symbol_index_type(&sym, &type) == 0) {
            json_write_string(&c->out, "IndexTypeID");
            write_stream(&c->out, ':');
            json_write_string(&c->out, symbol2id(&type));
            write_stream(&c->out, ',');
        }

        if (get_symbol_size(&sym, frame, &size) == 0) {
            json_write_string(&c->out, "Size");
            write_stream(&c->out, ':');
            json_write_long(&c->out, size);
            write_stream(&c->out, ',');
        }

        if (get_symbol_length(&sym, frame, &length) == 0) {
            json_write_string(&c->out, "Length");
            write_stream(&c->out, ':');
            json_write_long(&c->out, length);
            write_stream(&c->out, ',');
        }

        if (sym.sym_class == SYM_CLASS_REFERENCE) {
            if (get_symbol_offset(&sym, &offset) == 0) {
                json_write_string(&c->out, "Offset");
                write_stream(&c->out, ':');
                json_write_long(&c->out, offset);
                write_stream(&c->out, ',');
            }

            if (get_symbol_address(&sym, frame, &address) == 0) {
                json_write_string(&c->out, "Address");
                write_stream(&c->out, ':');
                json_write_long(&c->out, address);
                write_stream(&c->out, ',');
            }
        }

        if (sym.sym_class == SYM_CLASS_VALUE && get_symbol_value(&sym, &value, &size) == 0) {
            json_write_string(&c->out, "Value");
            write_stream(&c->out, ':');
            json_write_binary(&c->out, value, size);
            write_stream(&c->out, ',');
        }

        json_write_string(&c->out, "Class");
        write_stream(&c->out, ':');
        json_write_long(&c->out, sym.sym_class);

        write_stream(&c->out, '}');
        write_stream(&c->out, 0);
    }
    else {
        write_stringz(&c->out, "null");
    }

    write_stream(&c->out, MARKER_EOM);
}
Ejemplo n.º 7
0
static void disassemble_cache_client(void * x) {
    DisassembleCmdArgs * args = (DisassembleCmdArgs *)x;

    int error = 0;
    Context * ctx = NULL;
    uint8_t * mem_buf = NULL;
    ContextAddress buf_addr = 0;
    ContextAddress buf_size = 0;
    size_t mem_size = 0;
    ByteArrayOutputStream buf;
    OutputStream * buf_out = create_byte_array_output_stream(&buf);
    Channel * c = cache_channel();
    char * data = NULL;
    size_t size = 0;
    ContextISA isa;

    memset(&isa, 0, sizeof(isa));

    ctx = id2ctx(args->id);
    if (ctx == NULL) error = ERR_INV_CONTEXT;
    else if (ctx->exited) error = ERR_ALREADY_EXITED;

    if (!error) check_all_stopped(ctx);

    if (!error) {
        ContextAddress sym_addr = 0;
        ContextAddress sym_size = 0;
        int sym_addr_ok = 0;
        int sym_size_ok = 0;
#if SERVICE_Symbols
        {
            Symbol * sym = NULL;
            if (find_symbol_by_addr(ctx, STACK_NO_FRAME, args->addr, &sym) == 0) {
                if (get_symbol_address(sym, &sym_addr) == 0) sym_addr_ok = 1;
                if (get_symbol_size(sym, &sym_size) == 0) sym_size_ok = 1;
            }
            if (sym_addr_ok && sym_addr <= args->addr) {
                if (args->addr - sym_addr >= 0x1000) {
                    sym_addr_ok = 0;
                    sym_size_ok = 0;
                }
                else if (sym_size_ok && sym_addr + sym_size > args->addr + args->size) {
                    sym_size = args->addr + args->size - sym_addr;
                }
            }
        }
#endif
#if SERVICE_LineNumbers
        if (!sym_addr_ok || !sym_size_ok) {
            CodeArea * area = NULL;
            address_to_line(ctx, args->addr, args->addr + 1, address_to_line_cb, &area);
            if (area != NULL) {
                sym_addr = area->start_address;
                sym_size = area->end_address - area->start_address;
                sym_addr_ok = 1;
                sym_size_ok = 1;
            }
        }
#endif
        if (sym_addr_ok && sym_size_ok && sym_addr <= args->addr && sym_addr + sym_size > args->addr) {
            buf_addr = sym_addr;
            buf_size = sym_size;
            mem_size = (size_t)sym_size;
        }
        else if (sym_addr_ok && sym_addr < args->addr) {
            if (get_isa(ctx, sym_addr, &isa) < 0) {
                error = errno;
            }
            else {
                buf_addr = sym_addr;
                buf_size = args->addr + args->size - sym_addr;
                if (isa.max_instruction_size > 0) {
                    mem_size = (size_t)(buf_size + isa.max_instruction_size);
                }
                else {
                    mem_size = (size_t)(buf_size + MAX_INSTRUCTION_SIZE);
                }
            }
        }
        else {
            /* Use default address alignment */
            if (get_isa(ctx, args->addr, &isa) < 0) {
                error = errno;
            }
            else {
                if (isa.alignment > 0) {
                    buf_addr = args->addr & ~(ContextAddress)(isa.alignment - 1);
                }
                else {
                    buf_addr = args->addr & ~(ContextAddress)(DEFAULT_ALIGMENT - 1);
                }
                buf_size = args->addr + args->size - buf_addr;
                if (isa.max_instruction_size > 0) {
                    mem_size = (size_t)(buf_size + isa.max_instruction_size);
                }
                else {
                    mem_size = (size_t)(buf_size + MAX_INSTRUCTION_SIZE);
                }
            }
        }

        if (!error) {
            mem_buf = (uint8_t *)tmp_alloc(mem_size);
            if (context_read_mem(ctx, buf_addr, mem_buf, mem_size) < 0) error = errno;
            if (error) {
#if ENABLE_ExtendedMemoryErrorReports
                MemoryErrorInfo info;
                if (context_get_mem_error_info(&info) == 0 && info.size_valid > 0) {
                    mem_size = info.size_valid;
                    error = 0;
                }
#endif
            }
        }
    }

    if (!error && disassemble_block(
            ctx, buf_out, mem_buf, buf_addr, buf_size,
            mem_size, &isa, args) < 0) error = errno;

    if (get_error_code(error) == ERR_CACHE_MISS) {
        loc_free(buf.mem);
        buf.mem = NULL;
        buf.max = 0;
        buf.pos = 0;
    }

    cache_exit();

    get_byte_array_output_stream_data(&buf, &data, &size);

    if (!is_channel_closed(c)) {
        OutputStream * out = &c->out;
        write_stringz(out, "R");
        write_stringz(out, args->token);
        write_errno(out, error);
        if (size > 0) {
            write_block_stream(out, data, size);
        }
        else {
            write_string(out, "null");
        }
        write_stream(out, 0);
        write_stream(out, MARKER_EOM);
    }

    loc_free(data);
}