예제 #1
0
//--------------------------------------------------------------------------
uint32 win32_debmod_t::calc_imagesize(ea_t ea)
{
  wince_module_t wm;
  if ( find_module(ea, &wm) )
    return get_e32(&wm).vsize;
  return 0;
}
//--------------------------------------------------------------------------
uint32 win32_debmod_t::calc_imagesize(ea_t ea)
{
  if ( _GetModuleInformation )
  {
    HMODULE hMod;
    if ( ea == 0 )
    {
      hMod = 0;
    }
    else
    {
      modbase_to_entry_t mbh = {ea, };
      int code = for_each_module(pid, &get_module_by_base, &mbh);
      if ( code == 1 )
        hMod = mbh.me.hModule;
      else
        hMod = (HMODULE)ea; // last resort
    }
    MODULEINFO mi;
    if ( _GetModuleInformation(process_handle, hMod, &mi, sizeof(mi)) )
      return mi.SizeOfImage;
  }

  wince_module_t wm;
  if ( find_module(ea, &wm) )
    return get_e32(&wm).vsize;
  return 0;
}
예제 #3
0
//--------------------------------------------------------------------------
// WinCE device seems to freeze and require a hard reset if a bpt is
// set at coredll (and other system areas?)
// we never write there
bool win32_debmod_t::may_write(ea_t ea)
{
  static area_t forbidden_area;
  if ( forbidden_area.startEA == 0 )
  {
    wince_module_t coredll;
    find_module_by_name("coredll", &coredll);
    common_e32_lite &e32 = get_e32(&coredll);
    forbidden_area.startEA = e32.vbase;
    forbidden_area.endEA   = e32.vbase + e32.vsize;
  }
  if ( ea >= 0x80000000 || forbidden_area.contains(ea) )
  {
    SetLastError(ERROR_ACCESS_DENIED);
    return false;
  }
  return true;
}
예제 #4
0
//--------------------------------------------------------------------------
bool win32_debmod_t::get_dll_exports(
        const images_t &dlls,
        ea_t imagebase,
        name_info_t &ni,
        const char *exported_name)
{
  int i;
  wince_module_t wm;
  if ( !find_module(imagebase, &wm) )
    return false;

  common_e32_lite &e32 = get_e32(&wm);
  petab_t *pexpdir;
  if ( is_ce500() )
  {
    win500_e32_lite *e32_500 = (win500_e32_lite *)&e32;
    pexpdir = &e32_500->unit[E32_LITE_EXP];
  }
  else
  {
    win420_e32_lite *e32_420 = (win420_e32_lite *)&e32;
    pexpdir = &e32_420->unit[E32_LITE_EXP];
  }

  petab_t &expdir = *pexpdir;
  if ( expdir.size <= 0 )
    return false;

  // calculate the export directory address
  ea_t o32_ptr = (ea_t)get_o32_ptr(&wm);
  ea_t exp_ea = BADADDR;

  // no memory or bad object count
  o32_lite *ao32 = new o32_lite[e32.objcnt];
  if ( ao32 == NULL )
    return false;

  if ( myread(o32_ptr, ao32, e32.objcnt * sizeof(o32_lite)) )
  {
    for ( i=0; i < e32.objcnt; i++ )
    {
      o32_lite &o32 = ao32[i];
      if ( expdir.rva >= o32.rva && expdir.rva+expdir.size <= o32.rva+o32.vsize )
        exp_ea = o32.realaddr + (expdir.rva - o32.rva);
    }
  }
  delete [] ao32;
  if ( exp_ea == BADADDR )
    return false;

  // read export section
  uchar *data = new uchar[expdir.size];
  if ( data == NULL )
    return false;

  bool ok = false;
  const uint32 *end = (const uint32 *)(data + expdir.size);
  if ( myread(exp_ea, data, expdir.size) )
  {
    peexpdir_t &ed = *(peexpdir_t *)data;
    char *dllname = (char *)data + ed.dllname - expdir.rva;
    if ( dllname < (char *)data || dllname >= (char*)end )
      dllname = "";
    char *dot = strrchr(dllname, '.');
    if ( dot != NULL )
      *dot = '\0';

    const uint32 *names = (const uint32 *)(data + ed.namtab - expdir.rva);
    const uint16 *ords  = (const uint16 *)(data + ed.ordtab - expdir.rva);
    const uint32 *addrs = (const uint32 *)(data + ed.adrtab - expdir.rva);
    if ( names < end && (uint32*)ords < end && addrs < end )
    {
      // ordinals -> names
      typedef std::map<int, qstring> expfunc_t;
      expfunc_t funcs;
      for ( i=0; i < ed.nnames; i++ )
      {
        const char *name = (char*)data + names[i] - expdir.rva;
        if ( name >= (char*)data && name < (char*)end )
          funcs.insert(make_pair(ed.ordbase + ords[i], qstring(name)));
      }
      for ( i=0; i < ed.naddrs; i++ )
      {
        char buf[MAXSTR];
        uint32 adr = addrs[i];
        if ( adr == 0 )
          continue;
        int ord = ed.ordbase + i;
        ea_t fulladdr = imagebase + adr;
        expfunc_t::iterator p = funcs.find(ord);
        if ( p != funcs.end() )
          qsnprintf(buf, sizeof(buf), "%s_%s", dllname, p->second.c_str());
        else
          qsnprintf(buf, sizeof(buf), "%s_%d", dllname, ord);
        ni.addrs.push_back(fulladdr);
        ni.names.push_back(qstrdup(buf));
        ok = true;
      }
    }
  }
  delete [] data;
  return ok;
}
예제 #5
0
//--------------------------------------------------------------------------
static int match_module_base(wince_module_t *wm, void *ud)
{
  ea_t base = *(ea_t *)ud;
  return get_e32(wm).vbase == base;
}