예제 #1
0
파일: parser.c 프로젝트: MatzFan/bpmtk
int ParseConfigSearchAndWrite(TCHAR *pszLine, CONFIG *pConfig)
{
	int iStart;
	int iLen;
	OPTIONS sO;
	TCHAR *pszSearch;
	TCHAR *pszWrite;
	unsigned char *pucArgumentSearch;
	int iBytesSearch;
	unsigned char *pucArgumentWrite;
	int iBytesWrite;
	struct CommandSearchAndWrite *pCSAW;
	int iTokenArgument;
	
	iStart = GetToken(0, pszLine, &iLen, NULL);
	if (-1 == iStart)
		return -1;

  ZeroMemory(&sO, sizeof(OPTIONS));
  sO.bModule = TRUE;
  sO.bMemory = TRUE;
  iStart = ParseOptions(pszLine+iStart, &sO);
	if (-1 == iStart)
		return -1;

	if (NULL != sO.pszModule && NULL != sO.pszMemory)
		return -1;
		
	if (!TwoRemainingTokens(pszLine+iStart, &pszSearch, &pszWrite))
		return -1;
	iTokenArgument = ParseArgument(pszSearch, &pucArgumentSearch, &iBytesSearch);
	free(pszSearch);
	if (0 == iBytesSearch || (TOK_HEX != iTokenArgument && TOK_ASCII != iTokenArgument && TOK_UNICODE != iTokenArgument))
		return -1;
	iTokenArgument = ParseArgument(pszWrite, &pucArgumentWrite, &iBytesWrite);
	free(pszWrite);
	if (0 == iBytesWrite || (TOK_HEX != iTokenArgument && TOK_ASCII != iTokenArgument && TOK_UNICODE != iTokenArgument))
		return -1;

	pCSAW = malloc(sizeof(struct CommandSearchAndWrite));
	if (NULL == pCSAW)
    return -1;
	pCSAW->searchLen = iBytesSearch;
	pCSAW->searchBytes = pucArgumentSearch;
	pCSAW->writeLen = iBytesWrite;
	pCSAW->writeBytes = pucArgumentWrite;
	pCSAW->pszModule = sO.pszModule;
	if (NULL != sO.pszMemory)
		if (TOK_WRITABLE == LookupToken(sO.pszMemory))
			pCSAW->dwMemory = PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY|PAGE_READWRITE|PAGE_WRITECOPY;
		else
				return -1;
	else
		pCSAW->dwMemory = 0;
	return AddStatement(pConfig, COMMAND_SEARCH_AND_WRITE, pCSAW);
}
예제 #2
0
bool ParseFunctionCall(FunctionEvent *Event, BinaryOperator *Bop,
                       vector<ValueDecl*>& References,
                       ASTContext& Ctx) {

  // TODO: better distinguishing between callee and/or caller
  Event->set_context(FunctionEvent::Callee);

  // Since we might care about the return value, we must instrument exiting
  // the function rather than entering it.
  Event->set_direction(FunctionEvent::Exit);

  Expr *LHS = Bop->getLHS();
  bool LHSisICE = LHS->isIntegerConstantExpr(Ctx);

  Expr *RHS = Bop->getRHS();

  if (!(LHSisICE ^ RHS->isIntegerConstantExpr(Ctx))) {
    Report("One of {LHS,RHS} must be ICE", Bop->getLocStart(), Ctx)
      << Bop->getSourceRange();
    return false;
  }

  Expr *RetVal = (LHSisICE ? LHS : RHS);
  Expr *FnCall = (LHSisICE ? RHS : LHS);
  if (!ParseArgument(Event->mutable_expectedreturnvalue(), RetVal, References,
                     Ctx))
    return false;

  auto FnCallExpr = dyn_cast<CallExpr>(FnCall);
  if (!FnCallExpr) {
    Report("Not a function call", FnCall->getLocStart(), Ctx)
      << FnCall->getSourceRange();
    return false;
  }

  auto Fn = FnCallExpr->getDirectCallee();
  if (!Fn) {
    Report("Not a direct function call", FnCallExpr->getLocStart(), Ctx)
      << FnCallExpr->getSourceRange();
    return false;
  }

  if (!ParseFunctionRef(Event->mutable_function(), Fn, Ctx)) return false;

  for (auto I = FnCallExpr->arg_begin(); I != FnCallExpr->arg_end(); ++I) {
    if (!ParseArgument(Event->add_argument(), I->IgnoreImplicit(), References,
                       Ctx))
      return false;
  }

  return true;
}
예제 #3
0
파일: proxy.cpp 프로젝트: bymzy/forfun
int main(int argc,char * argv[])
{
    std::string local_addr;
    std::string remote_addr;
    int         local_port = 0;
    int         remote_port = 0;;
    int         err = 0;

    do {
        err = ParseArgument(argc,argv,local_addr,remote_addr,local_port,remote_port);
        if ( 0 != err ) {
            std::cerr<<"ParseArgument error!"<<std::endl;
            break;
        } else {
            std::cout<<"proxyer addr:"<<local_addr<<std::endl
                <<"proxyer listen port:"<<local_port<<std::endl
                <<"remote addr:"<<remote_addr<<std::endl
                <<"remote listen port"<<remote_port<<std::endl;
        }
        Proxyer server(local_addr,local_port,remote_addr,remote_port);
        err = server.Start();
        if ( 0 != err ) {
            std::cerr<<"proxyer server run error!"<<std::endl;
        } else {
            std::cout<<"proxy server exit!"<<std::endl;
        }

    } while(0);

    return err;
}
예제 #4
0
bool ParseFunctionExit(FunctionEvent *Event, CallExpr *Call,
                       vector<ValueDecl*>& References,
                       ASTContext& Ctx) {
  assert(Call->getDirectCallee() != NULL);
  assert(Call->getDirectCallee()->getName() == "__tesla_leaving");

  // TODO: better distinguishing between callee and/or caller
  Event->set_context(FunctionEvent::Callee);
  Event->set_direction(FunctionEvent::Exit);

  if ((Call->getNumArgs() != 1) || (Call->getArg(0) == NULL)) {
    Report("__tesla_leaving predicate should have one argument: the function",
        Call->getLocStart(), Ctx)
      << Call->getSourceRange();
    return false;
  }

  auto FnRef = dyn_cast<DeclRefExpr>(Call->getArg(0)->IgnoreImplicit());
  if (!FnRef) {
    Report("Expected a function call", Call->getLocStart(), Ctx)
      << Call->getSourceRange();
    return false;
  }

  auto Fn = dyn_cast<FunctionDecl>(FnRef->getDecl());
  assert(Fn != NULL);

  for (auto I = Fn->param_begin(); I != Fn->param_end(); ++I) {
    if (!ParseArgument(Event->add_argument(), *I, References, Ctx))
      return false;
  }

  return ParseFunctionRef(Event->mutable_function(), Fn, Ctx);
}
void CParser::ParseArgumentList()
{	
	int nTabs = 5;
	CString sToken = m_oToken.GetCurrentToken();
	m_sProgress = m_sProgress + GetTabs(nTabs) + 
		"ParseArgumentList\r\n";
	ETokenType tt = m_oToken.GetCurrentTokenType();
	CString stt = m_oToken.GetCurrentTokenTypeInString();

	// arg list may be empty
	if(sToken == ")")
		return;

	while(sToken != ")")
	//while(1)
	{
		ParseArgument();

		sToken = m_oToken.GetCurrentToken();

		if(sToken == ")")
			break;
		else if(sToken != ",")		
		{
			m_sProgress = m_sProgress + GetTabs(nTabs+1) +
				GetErrorString();
			while(sToken != ",")
			{
				sToken = m_oToken.GetNextToken();
				if(sToken == ")")
					break;
			}

		}

		// skip Comma
		if(sToken == ",")
			m_oToken.GetNextToken();													
	}

	//return "true";
} // ParseArgumentList()
예제 #6
0
파일: parser.c 프로젝트: MatzFan/bpmtk
int ParseConfigWrite(TCHAR *pszLine, CONFIG *pConfig)
{
	int iStart;
	int iLen;
	OPTIONS sO;
	TCHAR *pszAddress;
	TCHAR *pszData;
	struct CommandWrite *pCW;
	DWORD dwAddress;
	unsigned char *pucBytes;
	int iBytes;
	int iTokenArgument;
	
	iStart = GetToken(0, pszLine, &iLen, NULL);
	if (-1 == iStart)
		return -1;

  ZeroMemory(&sO, sizeof(OPTIONS));
  sO.bVersion = TRUE;
  iStart = ParseOptions(pszLine+iStart, &sO);
	if (-1 == iStart)
		return -1;

	if (!TwoRemainingTokens(pszLine+iStart, &pszAddress, &pszData))
		return -1;
	dwAddress = ParseAddress(pszAddress);
	free(pszAddress);
	iTokenArgument = ParseArgument(pszData, &pucBytes, &iBytes);
	free(pszData);
	if (0 == dwAddress || 0 == iBytes || (TOK_HEX != iTokenArgument && TOK_ASCII != iTokenArgument && TOK_UNICODE != iTokenArgument))
		return -1;
		
	pCW = malloc(sizeof(struct CommandWrite));
	if (NULL == pCW)
		return -1;
	pCW->address = dwAddress;
	pCW->len = iBytes;
	pCW->bytes = pucBytes;
	pCW->pszVersion = sO.pszVersion;
	return AddStatement(pConfig, COMMAND_WRITE, pCW);
}
ProgramOption::ProgramOption(int argc, char **argv) {
    InitDefaultValues();

    fopt = new FileOperation();


    int ret = ParseArgument(argc, argv, fopt);
    if (ret != 0) {
        std::cerr << "Chyba programoptiondi" << std::endl;
        this->finish = ret;
    }
    else{

    }


    ProcessOption(fopt);



    delete fopt;
}
예제 #8
0
파일: GenPy.cpp 프로젝트: kbochenina/Snap
int CallPyFunction(const char *moduleName, const char *funcName, const TStrV& args, const TStrV& argTypes,  PyObject** res, PyObject*** pyObjects = nullptr)
{
	PyObject *pName, *pModule, *pFunc, *pArgs;
	bool err = false;
	// get PyObject representation of moduleName
	pName = PyUnicode_FromString(moduleName);
	TExeTm execTime;
	// import module
	pModule = PyImport_Import(pName);
	cout << "Time of importing module " << moduleName << ": " << execTime.GetTmStr() << endl;
	// we don't need pName anymore
	Py_DECREF(pName);
	// if module was loaded 
	if (pModule != nullptr) {
		// get pointer to function
		pFunc = PyObject_GetAttrString(pModule, funcName);
		// check function for existence
		if (pFunc && PyCallable_Check(pFunc)) {
			// a number of arguments
			int argc = argTypes.Len();
			// tuple of arguments
			pArgs = PyTuple_New(argc);
			// index of current PyObject in array of PyObjects
			int argPyObjIndex = 0, argStrIndex = 0;
			// parsing arguments
			for (size_t i = 0; i < argc; i++)
			{
				PyObject **arg = new PyObject*[1];
				//printf("argtypes[%d] = %s\n", i, argTypes[i].CStr());
				if (argTypes[i] != "pyobject"){
					if (!ParseArgument(args[argStrIndex++], argTypes[i], arg))
						err = true;
				}
				else
				{
					// non-safe
					*arg = pyObjects[argPyObjIndex++][0];
				}
				PyTuple_SetItem(pArgs, i, *arg);
				Py_DECREF(arg);
			}
			//TExeTm execTime;
			*res = PyObject_CallObject(pFunc, pArgs);
			//cout << "Time of execution of function " << funcName << ": " << execTime.GetTmStr() << endl; 
			if (PyErr_Occurred()){
                PyErr_Print();
				err = true;
			}
			if (res == nullptr)
			{
				PyErr_Print();
                fprintf(stderr,"Call failed\n");
                err = true;
			}
			//Py_DECREF(pArgs);
		}
		else {
            if (PyErr_Occurred())
                PyErr_Print();
            fprintf(stderr, "Cannot find function \"%s\" in module \"%s\"\n", funcName, moduleName);
			err = true;
        }
	}
	else {
		PyErr_Print();
		fprintf(stderr, "Failed to load \"%s\"\n", moduleName);
		err = true;
    }
	if (err == true) return 0;
	//Py_DECREF(pArgs);
	Py_DECREF(pFunc);
	Py_DECREF(pModule);
	
	return 1;
}
예제 #9
0
파일: parser.c 프로젝트: MatzFan/bpmtk
int ParseConfigInjectCode(TCHAR *pszLine, CONFIG *pConfig)
{
	TCHAR *pszToken;
	struct CommandInjectCode *pCInjectCode;
	unsigned char *pucBytes;
	int iBytes;
	OPTIONS sO;
	int iStart;
	int iTokenArgument;

  ZeroMemory(&sO, sizeof(OPTIONS));
  sO.bMinimumLength = TRUE;
  sO.bExecute = TRUE;
  iStart = ParseOptions(pszLine, &sO);
	if (iStart < 0)
		return -1;

	if (!OneRemainingToken(pszLine+iStart, &pszToken))
    return -2;

	iTokenArgument = ParseArgument(pszToken, &pucBytes, &iBytes);
	free(pszToken);
	if (0 == iBytes || (TOK_HEX != iTokenArgument && TOK_ASCII != iTokenArgument && TOK_UNICODE != iTokenArgument && TOK_FILE != iTokenArgument))
	{
		free(pucBytes);
		return -3;
	}
	
	pCInjectCode = malloc(sizeof(struct CommandInjectCode));
	if (NULL == pCInjectCode)
	{
		free(pucBytes);
		return -4;
	}
	pCInjectCode->pbBytes = pucBytes;
	pCInjectCode->lBytesSize = iBytes;
	pCInjectCode->bFilename = TOK_FILE == iTokenArgument;
	if (NULL != sO.pszMinimumLength)
	{
		if (ParseUnsignedNumber(sO.pszMinimumLength, &(pCInjectCode->uiMinimumBytesSize)) < 0)
			return -5;
	}
	else
		pCInjectCode->uiMinimumBytesSize = 0;
	if (NULL != sO.pszExecute)
		switch(LookupToken(sO.pszExecute))
		{
			case TOK_YES:
				pCInjectCode->bExecute = TRUE;
				break;
				
			case TOK_NO:
				pCInjectCode->bExecute = FALSE;
				break;

			default:
				return -2;
		}
	else
		pCInjectCode->bExecute = TRUE;
		

	return AddStatement(pConfig, COMMAND_INJECT_CODE, pCInjectCode);
}
예제 #10
0
void CommandLine::ParseArguments(int argc, const char* argv[])
{
	for (auto index = 0; index < argc; ++index)
		ParseArgument(argv[index]);
}