CSize ResizablePart::GetPreferredSize(void) const { long cx = 0; long cy = 0; if (m_bResizable) { COMTRY { CComPtr<IMgaMetaAspect> mAspect; COMTHROW(m_spPart->get_ParentAspect(&mAspect)); long status; COMTHROW(m_spProject->get_ProjectStatus(&status)); bool inTrans = (status & 0x08L) != 0; CComPtr<IMgaTerritory> terr; CComBSTR bstrVal; CComPtr<IMgaPart> part; CComBSTR regName(PREF_PREFERREDSIZE); if (!inTrans) { COMTHROW(m_spProject->CreateTerritory(NULL, &terr, 0)); COMTHROW(m_spProject->BeginTransaction(terr, TRANSACTION_READ_ONLY)); CComPtr<IMgaFCO> terrFco; COMTHROW(terr->OpenFCO(m_spFCO, &terrFco)); status = OBJECT_ZOMBIE; COMTHROW(terrFco->get_Status(&status)); if (status == OBJECT_EXISTS) { COMTHROW(terrFco->get_Part(mAspect, &part)); if (part) COMTHROW(part->get_RegistryValue(regName, &bstrVal)); } m_spProject->CommitTransaction(); } else { COMTHROW(m_spFCO->get_Part(mAspect, &part)); if (part) COMTHROW(part->get_RegistryValue(regName, &bstrVal)); } if (bstrVal) { int numConverted = swscanf(bstrVal, OLESTR("%ld,%ld"), &cx, &cy); if (numConverted != 2) { cx = 0; cy = 0; } } } catch(hresult_exception &e) { ASSERT(FAILED(e.hr)); SetErrorInfo(e.hr); }
// if <fc> is not-null, use it to print immediates/displacement char* op2string(Operand* o, ValType t, FunctionConfig* fc) { static char buf[30]; int off = 0; uint64_t val; switch(o->type) { case OT_Reg8: case OT_Reg16: case OT_Reg32: case OT_Reg64: case OT_Reg128: case OT_Reg256: sprintf(buf, "%%%s", regName(o->reg, o->type)); break; case OT_Imm8: val = o->val; assert(val < (1l<<8)); switch(t) { case VT_None: case VT_8: break; case VT_16: case VT_32: if (val > 0x7F) val += 0xFFFFFF00; break; case VT_64: if (val > 0x7F) val += 0xFFFFFFFFFFFFFF00; break; default: assert(0); } sprintf(buf, "$0x%lx", val); break; case OT_Imm16: val = o->val; assert(val < (1l<<16)); switch(t) { case VT_32: if (val > 0x7FFF) val += 0xFFFF0000; break; case VT_64: if (val > 0x7FFF) val += 0xFFFFFFFFFFFF0000; break; case VT_16: case VT_None: break; default: assert(0); } sprintf(buf, "$0x%lx", val); break; case OT_Imm32: val = o->val; assert(val < (1l<<32)); switch(t) { case VT_None: case VT_32: break; case VT_64: if (val > 0x7FFFFFFF) val += 0xFFFFFFFF00000000; break; default: assert(0); } sprintf(buf, "$%s", prettyAddress(val, fc)); break; case OT_Imm64: sprintf(buf, "$%s", prettyAddress(o->val, fc)); break; case OT_Ind8: case OT_Ind16: case OT_Ind32: case OT_Ind64: case OT_Ind128: case OT_Ind256: off = 0; switch(o->seg) { case OSO_None: break; case OSO_UseFS: off += sprintf(buf+off, "fs:"); break; case OSO_UseGS: off += sprintf(buf+off, "gs:"); break; default: assert(0); } if (o->val != 0) { if (o->val & (1l<<63)) off += sprintf(buf+off, "-0x%lx", (~ o->val)+1); else off += sprintf(buf+off, "%s", prettyAddress(o->val, fc)); } if ((o->scale == 0) || (o->ireg == Reg_None)) { if (o->reg != Reg_None) sprintf(buf+off,"(%%%s)", regName(o->reg, OT_Reg64)); } else { const char* ri = regName(o->ireg, OT_Reg64); if (o->reg == Reg_None) { sprintf(buf+off,"(,%%%s,%d)", ri, o->scale); } else sprintf(buf+off,"(%%%s,%%%s,%d)", regName(o->reg, OT_Reg64), ri, o->scale); } break; default: assert(0); } return buf; }
const char *Operand::string() const { static char string[256]; if(isVoid(type)) { return 0; } else if(isImm(type)) { if(reference) { return reference; } else { if(value <= 127 && value >= -128) { snprintf(string, 255, "0x%0.2X", value & 0xFF); } else if(value <= 32767 && value -32768) { snprintf(string, 255, "0x%0.4X", value & 0xFFFF); } else { snprintf(string, 255, "0x%0.8X", value); } } } else if(isReg(type)) { return regName(); } else if(isMem(type)) { switch(type) { case OPERAND_MEM8: snprintf(string, 255, "byte ptr ["); break; case OPERAND_MEM16: snprintf(string, 255, "word ptr ["); break; case OPERAND_MEM32: snprintf(string, 255, "dword ptr ["); break; case OPERAND_MEM64: snprintf(string, 255, "qword ptr ["); break; case OPERAND_MEM128: snprintf(string, 255, "xmmword ptr ["); break; case OPERAND_MEM: default: snprintf(string, 255, "byte ptr ["); } if(baseReg != Encoding::REG_UNKNOWN) { snprintf(string, 255, "%s%s", string, regName()); if(indexReg != Encoding::REG_UNKNOWN) { snprintf(string, 255, "%s+", string); } } if(indexReg != Encoding::REG_UNKNOWN) { snprintf(string, 255, "%s%s", string, indexName()); } switch(scale) { case 0: case 1: break; case 2: snprintf(string, 255, "%s*2", string); break; case 4: snprintf(string, 255, "%s*4", string); break; case 8: snprintf(string, 255, "%s*8", string); break; default: throw INTERNAL_ERROR; } if(displacement) { if(baseReg != Encoding::REG_UNKNOWN || indexReg != Encoding::REG_UNKNOWN) { snprintf(string, 255, "%s+", string); } if(reference) { snprintf(string, 255, "%s%s", string, reference); } else { if(displacement <= 32767 && displacement >= -32768) { snprintf(string, 255, "%s%d", string, displacement); } else { snprintf(string, 255, "%s0x%0.8X", string, displacement); } } } snprintf(string, 255, "%s]", string); } else { throw INTERNAL_ERROR; } return strlwr(string); }
// if <fc> is not-null, use it to print immediates/displacement char* op2string(Operand* o, Instr* instr, FunctionConfig* fc) { static char buf[30]; int off = 0; ValType t = instr->vtype; uint64_t val; switch(o->type) { case OT_Reg8: case OT_Reg16: case OT_Reg32: case OT_Reg64: case OT_Reg128: case OT_Reg256: case OT_Reg512: off += sprintf(buf, "%%%s", regName(o->reg)); break; case OT_Imm8: val = o->val; assert(val < (1l<<8)); switch(t) { case VT_None: case VT_8: break; case VT_16: case VT_32: if (val > 0x7F) val += 0xFFFFFF00; break; case VT_64: if (val > 0x7F) val += 0xFFFFFFFFFFFFFF00; break; default: assert(0); } off += sprintf(buf, "$0x%lx", val); break; case OT_Imm16: val = o->val; assert(val < (1l<<16)); switch(t) { case VT_32: if (val > 0x7FFF) val += 0xFFFF0000; break; case VT_64: if (val > 0x7FFF) val += 0xFFFFFFFFFFFF0000; break; case VT_16: case VT_None: break; default: assert(0); } off += sprintf(buf, "$0x%lx", val); break; case OT_Imm32: val = o->val; assert(val < (1l<<32)); switch(t) { case VT_None: case VT_32: break; case VT_64: if (val > 0x7FFFFFFF) val += 0xFFFFFFFF00000000; break; default: assert(0); } off += sprintf(buf, "$%s", prettyAddress(val, fc)); break; case OT_Imm64: off += sprintf(buf, "$%s", prettyAddress(o->val, fc)); break; case OT_Ind8: case OT_Ind16: case OT_Ind32: case OT_Ind64: case OT_Ind128: case OT_Ind256: case OT_Ind512: switch(o->seg) { case OSO_None: break; case OSO_UseFS: off += sprintf(buf+off, "%%fs:"); break; case OSO_UseGS: off += sprintf(buf+off, "%%gs:"); break; default: assert(0); } val = o->val; // for rip-relative addressing, shown displacement is adjusted if ((o->scale == 0) && (o->reg.rt == RT_IP)) { // addr+len is 0 if not decoded val += instr->addr + instr->len; } if (val != 0) { if (val & (1l<<63)) off += sprintf(buf+off, "-0x%lx", (~val)+1); else off += sprintf(buf+off, "%s", prettyAddress(val, fc)); } if ((o->scale == 0) || (o->ireg.rt == RT_None)) { if (o->reg.rt != RT_None) off += sprintf(buf+off,"(%%%s)", regName(o->reg)); else if (off == 0) { // nothing printed yet off += sprintf(buf, "0x0"); } } else { const char* ri = regName(o->ireg); if (o->reg.rt == RT_None) { off += sprintf(buf+off,"(,%%%s,%d)", ri, o->scale); } else off += sprintf(buf+off,"(%%%s,%%%s,%d)", regName(o->reg), ri, o->scale); } break; default: assert(0); } assert(off > 0); return buf; }