Ejemplo n.º 1
0
int Imp_Dlls::get_dlls(void)
{
  tMPORT_DIRECTORY_ENTRY ImpDir;
  ea_t dir_va;

  if ( 0 == (dir_va = m_imp) )
    return(-1); // no import

  segment_t *seg = getseg(m_imp);
  if ( !seg )
  {
    warning("Bad import structure");
    return -2;
  }
  while(dir_va < seg->endEA)
  {
    ImpDir.ImportLookUp     = get_long(dir_va+0x00);
    ImpDir.TimeDateStamp    = get_long(dir_va+0x04);
    ImpDir.ForwardChain     = get_long(dir_va+0x08);
    ImpDir.NameRVA          = get_long(dir_va+0x0C);
    ImpDir.AddressTableRVA  = get_long(dir_va+0x10);

    if ( 0 == ImpDir.NameRVA )
      break; // all done

    add_import(ImpDir.NameRVA + loaded_base);
    dir_va += 0x14; // next dir
  }

  return(0); // all ok
}
Ejemplo n.º 2
0
glxlink::glxlink(char *filename)
{
	bool ok = true;
	globals = NULL;
	imports = NULL;
	exports = NULL;
	objects = NULL;
	handle = NULL;
	settag = NULL;
	init = NULL;
	sync = NULL;
	term = NULL;
	glxflags = 0;
	valid_to = 0;
	last_t = 0;

	FILE *fp = fopen(filename,"rt");
	if ( fp==NULL )
		throw "file open failed";
	output_debug("opened link '%s'", filename);

	char line[1024];
	int linenum=0;
	while ( fgets(line,sizeof(line),fp)!=NULL )
	{
		linenum++;
		if ( line[0]=='#' ) continue;
		char tag[64], data[1024]="";
		if ( sscanf(line,"%s %[^\r\n]",tag,data)>0 )
		{
			output_debug("%s(%d): %s %s", filename, linenum, tag,data);
			if ( settag!=NULL )
			{
				if ( strcmp(tag,"global")==0 )
				{
					add_global(data);
				}
				else if ( strcmp(tag,"object")==0 )
				{
					add_object(data);
				}
				else if ( strcmp(tag,"export")==0 )
				{
					add_export(data);
				}
				else if ( strcmp(tag,"import")==0 )
				{
					add_import(data);
				}
				else if ( !(*settag)(this,tag,data) )
					output_error("%s(%d): tag '%s' not accepted", filename, linenum, tag);
			}
			else if ( strcmp(tag,"target")==0)
			{
				if ( !set_target(data) )
				{
					output_error("%s(%d): target '%s' is not valid", filename, linenum, data);
					ok = false;
				}
			}
			else
				output_warning("%s(%d): tag '%s' cannot be processed until target module is loaded", filename, linenum, tag);
		}
	}

	fclose(fp);

	// append to link list
	next = first;
	first = this;

	if ( ok )
		output_verbose("link '%s' ok", filename);
	else
		throw "cannot establish link";
}