/* writeStringValue - write a string value */
bool write_ctx::writeStringValue(value v)
{
    if(s->put(CsFaslTagString))
      return writeString(CsStringAddress(v),CsStringSize(v));
    return false;
}
示例#2
0
/* CsDecodeInstruction - decode a single bytecode instruction */
int CsDecodeInstruction(VM *c,value code,int lc,stream *s)
{
    char buf[100];
    value name;
    byte *cp;
    int i,cnt,n=1;
    OTDEF *op;

    /* get bytecode pointer for this instruction and the method name */
    cp = CsByteVectorAddress(CsCompiledCodeBytecodes(code)) + lc;
    name = CsCompiledCodeName(code);
    
    /* show the address and opcode */
    if (CsStringP(name)) {
        //char *data = CsStringAddress(name);
        //long size = CsStringSize(name);
        //if (size > 32) size = 32;
        //strncpy(buf,(char *)data,(size_t)size);
        //sprintf(&buf[size],":%04x %02x ",lc,*cp);
        s->printf(L"%S:%04x %02x",CsStringAddress(name),lc,*cp);
    }
    else
        s->printf(L"%08lx:%04x %02x ",(long)code,lc,*cp);
    //s->put_str(buf);

    /* display the operands */
    for (op = otab; op->ot_name; ++op)
        if (*cp == op->ot_code) {
            switch (op->ot_fmt) {
            case FMT_NONE:
                sprintf(buf,"      %s\n",op->ot_name);
                s->put_str(buf);
                break;
            case FMT_BYTE:
                sprintf(buf,"%02x    %s %02x\n",cp[1],op->ot_name,cp[1]);
                s->put_str(buf);
                n += 1;
                break;
            case FMT_2BYTE:
                sprintf(buf,"%02x %02x %s %02x %02x\n",cp[1],cp[2],
                        op->ot_name,cp[1],cp[2]);
                s->put_str(buf);
                n += 2;
                break;
            case FMT_WORD:
                sprintf(buf,"%02x %02x %s %02x%02x\n",cp[1],cp[2],
                        op->ot_name,cp[2],cp[1]);
                s->put_str(buf);
                n += 2;
                break;
            case FMT_LIT:
                sprintf(buf,"%02x %02x %s %02x%02x ; ",cp[1],cp[2],
                        op->ot_name,cp[2],cp[1]);
                s->put_str(buf);
                CsPrint(c,CsCompiledCodeLiteral(code,(cp[2] << 8) | cp[1]),s);
                s->put('\n');
                n += 2;
                break;
            case FMT_SWITCH:
                sprintf(buf,"%02x %02x %s %02x%02x\n",cp[1],cp[2],
                        op->ot_name,cp[2],cp[1]);
                s->put_str(buf);
                cnt = cp[2] << 8 | cp[1];
                n += 2 + cnt * 4 + 2;
                i = 3;
                while (--cnt >= 0) {
                    sprintf(buf,"                 %02x%02x %02x%02x ; ",cp[i+1],cp[i],cp[i+3],cp[i+2]);
                    s->put_str(buf);
                    CsPrint(c,CsCompiledCodeLiteral(code,(cp[i+1] << 8) | cp[i]),s);
                    s->put('\n');
                    i += 4;
                }
                sprintf(buf,"                 %02x%02x\n",cp[i+1],cp[i]);
                s->put_str(buf);
                break;
            }
            return n;
        }
    
    /* unknown opcode */
    sprintf(buf,"      <UNKNOWN>\n");
    s->put_str(buf);
    return 1;
}