Ejemplo n.º 1
0
//----------------------------------------------------------------------
static void trace_sp(void)
{
  // @sp++
  if ( cmd.Op1.type == o_phrase
    && issp(cmd.Op1.reg)
    && cmd.Op1.phtype == ph_post )
  {
    ssize_t size = get_dtyp_size(cmd.Op2.dtyp);
    if ( cmd.Op2.type == o_reglist )
      size *= cmd.Op2.nregs;
    add_stkpnt(size);
    return;
  }

  // @--sp
  if ( cmd.Op2.type == o_phrase
    && issp(cmd.Op2.reg)
    && cmd.Op2.phtype == ph_pre )
  {
    ssize_t size = get_dtyp_size(cmd.Op1.dtyp);
    if ( cmd.Op1.type == o_reglist )
      size *= cmd.Op1.nregs;
    add_stkpnt(-size);
    return;
  }

  int v;
  switch ( cmd.itype )
  {
    case H8_add:
    case H8_adds:
      if ( !issp(cmd.Op2.reg) )
        break;
      if ( get_op_value(cmd.Op1, &v) )
        add_stkpnt(v);
      break;
    case H8_sub:
    case H8_subs:
      if ( !issp(cmd.Op2.reg) )
        break;
      if ( get_op_value(cmd.Op1, &v) )
        add_stkpnt(-v);
      break;
    case H8_push:
      add_stkpnt(-get_dtyp_size(cmd.Op1.dtyp));
      break;
    case H8_pop:
      add_stkpnt( get_dtyp_size(cmd.Op1.dtyp));
      break;
  }
}
Ejemplo n.º 2
0
//----------------------------------------------------------------------
int idaapi is_sp_based(const op_t &x)
{
  return OP_SP_ADD
       | ((x.type == o_displ || x.type == o_phrase) && issp(x.phrase)
         ? OP_SP_BASED
         : OP_FP_BASED);
}
Ejemplo n.º 3
0
//----------------------------------------------------------------------
static void trace_sp(void)
{
  // @sp++
  if ( is_sp_inc(cmd.Op1) )
  {
    int size = 2;
    if ( cmd.Op2.type == o_reglist )
      size *= calc_reglist_count(cmd.Op2.reg);
    add_stkpnt(size);
    return;
  }

  // @--sp
  if ( is_sp_dec(cmd.Op2) )
  {
    int size = 2;
    if ( cmd.Op1.type == o_reglist )
      size *= calc_reglist_count(cmd.Op1.reg);
    add_stkpnt(-size);
    return;
  }
  // xxx @--sp
  if ( is_sp_dec(cmd.Op1) )
  {
    add_stkpnt(-2);
    return;
  }

  int v;
  switch ( cmd.itype )
  {
    case H8500_add_g:
    case H8500_add_q:
    case H8500_adds:
      if ( issp(cmd.Op2.reg) && get_op_value(cmd.Op1, &v) )
        add_stkpnt(v);
      break;
    case H8500_sub:
    case H8500_subs:
      if ( issp(cmd.Op2.reg) && get_op_value(cmd.Op1, &v) )
        add_stkpnt(-v);
      break;
  }
}
Ejemplo n.º 4
0
//----------------------------------------------------------------------
bool idaapi create_func_frame(func_t *pfn)
{
  int code = 0;
  if ( pfn->frame == BADNODE )
  {
    size_t regs = 0;
    ea_t ea = pfn->startEA;
    bool bpused = false;
    while ( ea < pfn->endEA )                 // skip all pushregs
    {                                         // (must test that ea is lower
                                              // than pfn->endEA)
      decode_insn(ea);
      ea += cmd.size;
      switch ( cmd.itype )
      {
        case H8_nop:
          continue;
        case H8_push:
          regs += get_dtyp_size(cmd.Op1.dtyp);
          continue;
        case H8_stm:
          if ( !issp(cmd.Op2.reg) ) break;
          regs += cmd.Op1.nregs * get_dtyp_size(cmd.Op1.dtyp);
          continue;
        case H8_mov:  // mov.l er6, sp
          if ( cmd.Op1.type == o_reg && issp(cmd.Op1.reg)
            && cmd.Op2.type == o_reg && isbp(cmd.Op2.reg) )
              bpused = true;
          break;
        default:
          break;
      }
      break;
    }
    uint32 frsize  = 0;
    uint32 argsize = 0;
    if ( frsize != 0 || argsize != 0 || regs != 0 || bpused )
    {
      setflag((uint32 &)pfn->flags,FUNC_FRAME,bpused);
      return add_frame(pfn, frsize, (ushort)regs, argsize);
    }
  }
  return code;
}
void WorldLoader::readString(std::string s){
    jsonRoot = parseJSON(s);
    JSONValue& jo = *jsonRoot;
    
    if (!serverMode){
        //Read and load the textures
        std::cout<<"Reading textures\n";
        std::vector<std::string> textures = jo["textures"].keys();
        
        for (std::vector<std::string>::iterator it=textures.begin(); it!=textures.end(); it++){
            //std::cout<<*it<<std::endl;
            tm.addTexture(*jo["textures"][*it],*it);
        }
    }
    //Read Projection details..
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(parseDouble(*jo["projection"]["fov"]),
                    parseDouble(*jo["projection"]["aspectRatio"]),
                    parseDouble(*jo["projection"]["near"]),
                    parseDouble(*jo["projection"]["far"])
    );

    //std::cout<<jo.stringise()<<std::endl;

    //load objects..
    int objectsCount = jo["objects"].length();
    //std::cout<<"Loading "<<objectsCount<<" objects."<<std::endl;
    for (int i=0; i<objectsCount; i++){
        GLObject* glo;
        if (*jo["objects"][i]["type"] == "cube"){
            glo = new GLCube();
            glo->setTextureManager(&tm);
            glo->setTexturePrefix(*jo["objects"][i]["texturePrefix"]);
            if (serverMode){
                jo["objects"][i].setMapValue("oid",parseJSON("\"" + getNewRandomOID() + "\""));
            }
            glo->setObjectID(*jo["objects"][i]["oid"]);
            
            
            //set up transformations..
            double position[3], rotation[3], size[3];
            std::istringstream  issp(*jo["objects"][i]["position"]),
                                isso(*jo["objects"][i]["orientation"]),
                                isss(*jo["objects"][i]["dimensions"]);
            
            issp>>position[0]>>position[1]>>position[2];
            isso>>rotation[0]>>rotation[1]>>rotation[2];
            isss>>size[0]>>size[1]>>size[2];
            glo->setPosition(position[0], position[1], position[2]);
            glo->setRotation(rotation[0], rotation[1], rotation[2]);
            glo->setSize(size[0], size[1], size[2]);
        }else{
Ejemplo n.º 6
0
//----------------------------------------------------------------------
static void process_operand(op_t &x,int isAlt,int isload)
{
  switch ( x.type )
  {
    case o_reg:
    case o_reglist:
      return;
    case o_imm:
      QASSERT(10090, isload);
      process_immediate_number(x.n);
      if ( op_adds_xrefs(uFlag, x.n) )
        ua_add_off_drefs2(x, dr_O, calc_opimm_flags());
      break;
    case o_phrase:
    case o_displ:
      process_immediate_number(x.n);
      if ( isAlt ) break;
      if ( op_adds_xrefs(uFlag, x.n) )
      {
        ea_t ea = ua_add_off_drefs2(x, isload ? dr_R : dr_W, calc_opdispl_flags());
        if ( ea != BADADDR )
        {
          ua_dodata2(x.offb, ea, x.dtyp);
          if ( !isload )
            doVar(ea);
        }
      }
      // create stack variables if required
      if ( x.type == o_displ
        && may_create_stkvars()
        && !isDefArg(uFlag, x.n) )
      {
        func_t *pfn = get_func(cmd.ea);
        if ( pfn != NULL
          && (issp(x.phrase)
              || isbp(x.phrase) && (pfn->flags & FUNC_FRAME) != 0) )
        {
          if ( ua_stkvar2(x, x.addr, STKVAR_VALID_SIZE) )
            op_stkvar(cmd.ea, x.n);
        }
      }
      break;
    case o_near:
    case o_far:
      {
        cref_t ftype = x.type == o_near ? fl_JN : fl_JF;
        ea_t ea = calc_mem(x);
        if ( InstrIsSet(cmd.itype, CF_CALL) )
        {
          if ( !func_does_return(ea) )
            flow = false;
          ftype = x.type == o_near ? fl_CN : fl_CF;
        }
        ua_add_cref(x.offb, ea, ftype);
      }
      break;
    case o_mem:
      {
        ea_t ea = calc_mem(x);
        ua_add_dref(x.offb, ea, isload ? dr_R : dr_W);
        ua_dodata2(x.offb, ea, x.dtyp);
        if ( !isload ) doVar(ea);
      }
      break;
    default:
      INTERR(10091);
  }
}
Ejemplo n.º 7
0
//----------------------------------------------------------------------
// @sp++
inline bool is_sp_inc(const op_t &x)
{
  return x.type == o_phrase
      && issp(x.reg)
      && x.phtype == ph_post;
}
Ejemplo n.º 8
0
//----------------------------------------------------------------------
static void process_operand(op_t &x,int isAlt,int isload)
{
  switch ( x.type )
  {
    case o_reg:
    case o_phrase:
    case o_reglist:
      return;
    case o_imm:
      QASSERT(10094, isload);
      process_immediate_number(x.n);
      if ( op_adds_xrefs(uFlag, x.n) )
        ua_add_off_drefs2(x, dr_O, OOFS_IFSIGN|OOFW_IMM);
      break;
    case o_displ:
      process_immediate_number(x.n);
      if ( isAlt )
        break;
      if ( op_adds_xrefs(uFlag, x.n) )
      {
        ea_t ea = ua_add_off_drefs2(x, isload ? dr_R : dr_W, get_displ_outf(x));
        if ( ea != BADADDR )
        {
          ua_dodata2(x.offb, ea, x.dtyp);
          if ( !isload )
            doVar(ea);
        }
      }
      // create stack variables if required
      if ( may_create_stkvars() && !isDefArg(uFlag, x.n) )
      {
        func_t *pfn = get_func(cmd.ea);
        if ( pfn != NULL
          && (issp(x.phrase)
              || isbp(x.phrase) && (pfn->flags & FUNC_FRAME) != 0) )
        {
          if ( ua_stkvar2(x, x.addr, STKVAR_VALID_SIZE) )
            op_stkvar(cmd.ea, x.n);
        }
      }
      break;
    case o_near:
      add_code_xref(x, calc_mem(x.addr));
      break;
    case o_mem:
    case o_memind:
      {
        ea_t ea = calc_mem(x.addr);
        if ( !isEnabled(ea) && find_sym(ea) ) break;    // address not here
        ua_add_dref(x.offb, ea, isload ? dr_R : dr_W);
        ua_dodata2(x.offb, ea, x.dtyp);
        if ( x.type == o_memind )
        {
          ssize_t size = get_dtyp_size(x.dtyp);
          flags_t F = getFlags(ea);
          if ( (isWord(F) || isDwrd(F))
            && (!isDefArg0(F) || isOff0(F)) )
          {
            ea_t target = calc_mem(size == 2
                                ? get_word(ea)
                                : (get_long(ea) & 0xFFFFFFL));
            if ( isEnabled(target) ) add_code_xref(x, target);
            if ( !isOff0(F) )
              set_offset(ea, 0, calc_mem(0));
          }
          break;
        }
        if ( !isload ) doVar(ea);
      }
      break;
    default:
      INTERR(10095);
  }
}
Ejemplo n.º 9
0
void ParseExpression(TokenList &a_list, const std::string &a_expression)
{
	enum class ParseState {None, Number, Name} state = ParseState::None;
	int elen = a_expression.length() + 1;
	int idx = 0;
	int tstart = 0;
	char c_char, n_char;

	while (true)
	{
		if (idx < elen)
		{
			c_char = a_expression[idx];
			if (idx + 1 < elen) n_char = a_expression[idx + 1];
			else n_char = 0;
			idx++;
		}
		else
		{
			if (state == ParseState::Name)
			{
				a_list.AddToken(ExtractValue(a_expression, tstart, idx - 1, Token::Type::Name));
				a_list.tail->index = tstart + 1;
			}
			else if (state == ParseState::Number)
			{
				a_list.AddToken(ExtractValue(a_expression, tstart, idx - 1, Token::Type::Number));
				a_list.tail->index = tstart + 1;
			}
			break;
		}

		if (std::isspace(c_char) && state != ParseState::None)
		{
			a_list.AddToken(ExtractValue(a_expression, tstart, idx - 1, (state == ParseState::Name ? Token::Type::Name : Token::Type::Number)));
			a_list.tail->index = tstart + 1;
			state = ParseState::None;
		}
		else if (isop(c_char))
		{
			if (state != ParseState::None)
			{
				a_list.AddToken(ExtractValue(a_expression, tstart, idx - 1, (state == ParseState::Name ? Token::Type::Name : Token::Type::Number)));
				a_list.tail->index = tstart + 1;
			}

			switch (c_char)
			{
			case '+': a_list.AddToken(new Token(Token::OpType::Add, idx)); break;
			case '-':
				if (a_list.count == 0 || a_list.tail->optype != Token::OpType::None)
					a_list.AddToken(new Token(Token::OpType::Unary, idx));
				else a_list.AddToken(new Token(Token::OpType::Sub, idx));
				break;
			case '*': a_list.AddToken(new Token(Token::OpType::Mul, idx)); break;
			case '/': a_list.AddToken(new Token(Token::OpType::Div, idx)); break;
			case '^': a_list.AddToken(new Token(Token::OpType::Pow, idx)); break;
			case '%': a_list.AddToken(new Token(Token::OpType::Mod, idx)); break;
			case '(': a_list.AddToken(new Token(Token::OpType::LPar, idx)); break;
			case ')': a_list.AddToken(new Token(Token::OpType::RPar, idx)); break;
			case ',': a_list.AddToken(new Token(Token::OpType::Comma, idx)); break;
			case '<':
				if (n_char == '=')
				{
					a_list.AddToken(new Token(Token::OpType::LE, idx));
					idx++;
				}
				else a_list.AddToken(new Token(Token::OpType::LT, idx));
				break;
			case '>':
				if (n_char == '=')
				{
					a_list.AddToken(new Token(Token::OpType::GE, idx));
					idx++;
				}
				else a_list.AddToken(new Token(Token::OpType::GT, idx));
				break;
			case '=':
				if (n_char == '=')
				{
					a_list.AddToken(new Token(Token::OpType::EQ, idx));
					idx++;
				}
				break;
			case '!':
				if (n_char == '=')
				{
					a_list.AddToken(new Token(Token::OpType::NE, idx));
					idx++;
				}
				break;
			}
			state = ParseState::None;
		}
		else if (issp(c_char) && state == ParseState::None && !isalpha(n_char))
		{
			switch (c_char)
			{
			case 't': a_list.AddToken(new Token(Token::SpecialType::Time, idx)); break;
			case 'x': a_list.AddToken(new Token(Token::SpecialType::XAxis, idx)); break;
			}
		}
		else if (state == ParseState::None && std::isalnum(c_char))
		{
			if (std::isdigit(c_char))
			{
				tstart = idx - 1;
				state = ParseState::Number;
			}
			else if (std::isalpha(c_char))
			{
				tstart = idx - 1;
				state = ParseState::Name;
			}
		}
	}
}