Esempio n. 1
0
bool CapstoneTokenizer::Tokenize(duint addr, const unsigned char* data, int datasize, InstructionToken & instruction)
{
    _inst = InstructionToken();

    _success = _cp.Disassemble(addr, data, datasize);
    if(_success)
    {
        if(!tokenizeMnemonic())
            return false;

        for(int i = 0; i < _cp.OpCount(); i++)
        {
            if(i)
            {
                addToken(TokenType::Comma, ",");
                if(_bArgumentSpaces)
                    addToken(TokenType::ArgumentSpace, " ");
            }
            if(!tokenizeOperand(_cp[i]))
                return false;
        }
    }
    else
        addToken(TokenType::Uncategorized, "???");

    instruction = _inst;

    return true;
}
Esempio n. 2
0
	vector<InstructionToken> BaseParser::Tokenize(const string& input, const string& delimiters) {
		stringstream stringStream(input);
		vector<InstructionToken> result;
		string line;
		while (getline(stringStream, line))
		{
			size_t prev = 0, pos;
			while ((pos = line.find_first_of(delimiters, prev)) != std::string::npos)
			{
				if (pos > prev) {

					result.push_back(InstructionToken(line.substr(prev, pos - prev)));
				}

				prev = pos + 1;
			}
			if (prev < line.length()) {
				result.push_back(InstructionToken(line.substr(prev, std::string::npos)));
			}

		}
		return result;
	}
Esempio n. 3
0
VShader::VShader(const DWORD *pFunction, HANDLE Handle)
{
    _Handle = Handle;

    Assert(pFunction != NULL, "Invalid function tokens");
    UINT TokenIndex = 0;
    DWORD VersionToken = pFunction[TokenIndex++];
    _MinorVersion = D3DSHADER_VERSION_MINOR(VersionToken);
    _MajorVersion = D3DSHADER_VERSION_MAJOR(VersionToken);
    bool Done = false;

    if(_MajorVersion == 1)
    {
        g_Context->Files.Assert << "Shader version 1 not supported\n";
        Done = true;
    }

    while(!Done)
    {
        DWORD CurrentToken = pFunction[TokenIndex++];
        if(CurrentToken == D3DVS_END())
        {
            Done = true;
        }
        else if((CurrentToken & D3DSI_OPCODE_MASK) == D3DSIO_COMMENT)
        {
            CompleteInstructions.PushEnd();
            CompleteShaderInstruction &CurInstruction = CompleteInstructions.Last();
            CurInstruction._Instruction._InstructionToken = InstructionToken(CurrentToken);
            UINT CommentLength = (CurrentToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
            for(UINT i = 0; i < CommentLength; i++)
            {
                DWORD CurrentComment = pFunction[TokenIndex++];
                UCHAR *CommentStream = (UCHAR *)&CurrentComment;
                for(UINT i2 = 0; i2 < 4; i2++)
                {
                    CurInstruction.Comment.PushEnd(CommentStream[i2]);
                }
            }
        }
        else
        {
Esempio n. 4
0
         UINT CommentLength = (CurrentToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
         for(UINT i = 0; i < CommentLength; i++)
         {
             DWORD CurrentComment = pFunction[TokenIndex++];
             UCHAR *CommentStream = (UCHAR *)&CurrentComment;
             for(UINT i2 = 0; i2 < 4; i2++)
             {
                 CurInstruction.Comment.PushEnd(CommentStream[i2]);
             }
         }
     }
     else
     {
         CompleteInstructions.PushEnd();
         CompleteShaderInstruction &CurInstruction = CompleteInstructions.Last();
         CurInstruction._Instruction._InstructionToken = InstructionToken(CurrentToken);
         UINT InstructionLength = CurInstruction._Instruction._InstructionToken.Size();
         Assert(InstructionLength <= MaxParameterTokens, "Maximum instruction length exceeded.");
         for(UINT i = 0; i < MaxParameterTokens; i++)
         {
             if(i < InstructionLength)
             {
                 CurInstruction._Instruction._ParamaterTokens[i] = pFunction[TokenIndex++];
             }
             else
             {
                 CurInstruction._Instruction._ParamaterTokens[i] = 0;
             }
         }
     }
 }