Exemplo n.º 1
0
Arquivo: main.cpp Projeto: Raekye/hmmm
int main(int argc, char* argv[]) {
	llvm::InitializeNativeTarget();
	std::cout << "Started." << std::endl;
	if (argc > 1) {
		std::string str = "";
		std::ifstream f(argv[1]);
		if (f.is_open()) {
			std::string line;
			while (std::getline(f, line)) {
				str += line + "\n";
			}
		}
		std::cout << "Reading from file, contents:\n" << str << std::endl;
		run_code(str.c_str());
	} else {
		std::string line;
		while (true) {
			std::cout << "> ";
			if (!std::getline(std::cin, line)) {
				break;
			}
			run_code(line.c_str());
		}
	}
	std::cout << "Done." << std::endl;
	return 0;
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: DevCool/C_Dev
/* main() - entry point for all programs.
 */
int main(int argc, char *argv[])
{
#if defined(_WIN32) || (_WIN64)
	return run_code(&argc, &argv);
#endif
	return 0;
}
Exemplo n.º 3
0
PyObject *run_script_forcode(PyObject *dict, const char *script, 
			     const char *locale) {
  // try compiling the code
  PyObject *retval = Py_CompileString(script, "<string>", Py_file_input);

  // try running the code
  if(retval != NULL)
    run_code(retval, dict, locale);
  
  // did we end up with an error?
  if(retval == NULL || !last_script_ok())
    log_pyerr("Script terminated with an error:\r\n%s", script);

  // return our code object
  return retval;
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
	char *outfile=NULL;
	int read=0, write=0, output=0, list=0, c, index;
	const struct option long_options[] = {
		{"list",	no_argument,		NULL,	'l'},
		{"read",	no_argument,		NULL,	'r'},
		{"write",	no_argument,		NULL,	'w'},
		{"output",	required_argument,	NULL,	'o'},
		{"help",	no_argument,		NULL,	'h'},
		{"version",	no_argument,		NULL,	'v'},
		{NULL, 0, NULL, 0}
	};
	while ((c = getopt_long(argc, argv, "lrwho:", long_options, &index)) != -1) {
		switch (c) {
		case 'l':
			list = 1;
			break;
		case 'r':
			read = 1;
			break;
		case 'w':
			write = 1;
			break;
		case 'h':
			usage(stdout);
			return 0;
		case 'o':
			output = 1;
			outfile = optarg;
			break;
		case 'v':
			version();
			return 0;
		default:
			usage(stderr);
			return -1;
		}
	}
	if (write+read+list > 1) {
		fputs("Conflicting actions given simultaneously.\n", stderr);
		usage(stderr);
		return -1;
	} else if (!write+read+list) {
		write = 1;
	}
	if (output && !write) {
		fputs("It only makes sense to use --output with --write.\n", stderr);
		usage(stderr);
		return 1;
	}
	if (list) {
		list_sections();
	} else if (read) {
		FILE *f=NULL;
		for (index = optind; index < argc; index++) {
			f = open_file(argv[index], "r");
			run_code(argv[index], f);
			if (fclose(f))
				file_error(argv[index], "closing");
		}
		/* If we haven't opened anything, use stdin */
		if (!f)
			run_code("stdin", stdin);
	} else {
		FILE *f;
		if (outfile)
			f = open_file(outfile, "w");
		else
			f = stdout;
		if (optind < argc) {
			fputs("--write takes no arguments\n", stderr);
			usage(stderr);
			return -1;
		}
		create_code();
		output_code(f);
	}
	return 0;
}
Exemplo n.º 5
0
//let gcc help us generate shellcode, less asm, hard code dlsym
void shellcode(dlopen_t dlopen_f,void *pos){
    char *str_array = NULL;
    //construct string table in function
    asm __volatile__ ("mov %[result],pc":[result]"=r" (str_array));
    asm __volatile__ ("b .L_strlen_start");
    asm __volatile__ (".align 1");
    asm __volatile__ (".asciz \"printf\"");
    asm __volatile__ (".asciz \"__android_log_print\"");
    asm __volatile__ (".asciz \"mmap\"");
    asm __volatile__ (".asciz \"ashmem_pin_region\"");
    asm __volatile__ (".asciz \"ashmem_unpin_region\"");
    asm __volatile__ (".asciz \"ashmem_get_size_region\"");
    asm __volatile__ (".asciz \"mprotect\"");
    asm __volatile__ (".asciz \"malloc\"");
    asm __volatile__ (".asciz \"memcpy\"");
    asm __volatile__ (".asciz \"fd is %d, %x,%s\\n\"");
    asm __volatile__ (".asciz \"\xff\"");
    asm __volatile__ (".align 1");
    asm __volatile__ (".L_strlen_start:");
    //printf("start exec shellcode\n");
    char *fun_array[50];
    char *p = str_array;
    for(int i=0;i<50;i++){
        if(*p==0xff)
            break;
        fun_array[i]=p;
        while(*p++!=0);
    }
    if((int)dlopen_f%2==0)
        dlopen_f = (dlopen_t)((int)(dlopen_f)+1);
    dlsym_t dlsym_f = (dlsym_t)((int)dlopen_f+8);
    void *handle = dlopen_f(NULL,RTLD_NOW);

    int f = 0;
    printf_t printf_f = (printf_t)dlsym_f(handle,fun_array[f++]);
    #define getaddr(func_name) func_name##_t func_name##_f = (func_name##_t)dlsym_f(handle,fun_array[f++])
    getaddr(__android_log_print);
    getaddr(mmap);
    getaddr(ashmem_pin_region);
    getaddr(ashmem_unpin_region);
    getaddr(ashmem_get_size_region);
    getaddr(mprotect);
    getaddr(malloc);
    getaddr(memcpy);
    int s=9;
    int fd_memory = *(int*)(int(pos)+12);
    int pipe_from_client = *(int*)(int(pos)+16);
    int pipe_to_client = *(int*)(int(pos)+20);
    ashmem_pin_region_f(fd_memory, 0, 0);
    int ashem_size=ashmem_get_size_region_f(fd_memory);
    uint8_t *shm = (uint8_t*)mmap_f(NULL, ashem_size, PROT_READ, MAP_SHARED, fd_memory, 0);
    //ashmem_unpin_region_f(fd_memory, 0, 0);
    //can't mprotect ashmem as read and write, copy it to heap
    char *code = (char*)malloc_f(ashem_size);
    memcpy_f(code, shm, ashem_size);
    mprotect_f((void*)((uint32_t)code&0xfffff000), ashem_size, PROT_READ|PROT_WRITE|PROT_EXEC);
    //printf("start exec load so from memory\n");
    printf_f(fun_array[s],fd_memory,(char*)code,fun_array[s-2]);
    __android_log_print_f(3,fun_array[0],fun_array[s],fd_memory,code,fun_array[s-2]);
    so_start_t so_start = (so_start_t)run_code((char*)code,dlopen_f);
    //mprotect_f((void*)((uint32_t)code&0xfffff000), ashem_size, PROT_READ|PROT_EXEC);
    so_start(pipe_from_client,pipe_to_client);
}
Exemplo n.º 6
0
int main() {
  run_code("public09.a");
  return 0;
}
// Runs program with input from test files in testFiles vector.
void TestSuite::runTests()
{
    int numCorrect = 0, numWrong = 0;
    int i;
    string name;
    string logName;
    string stored_dir;
    double rate;
    bool crit = false;
    string crit_string = "crit.tst";
    bool crit_passed = true;
    char buff[40];
    int chpid = 45;
	
    //Get directory of current program
    i = testProgram.rfind('.');
    testProgram = testProgram.substr(0, i);

    // Create log file.
    logName = testProgram + "-";
    logName += exeTime;
    logName += ".log";
    ofstream fout(logName.c_str());
    if (!fout)
    {
        return;
    }

    // Iterate over test files.
    vector<string>::iterator it;
    for ( it = testFiles.begin(); it != testFiles.end() ; it++ )
    {

        //Determine if this is a critical test
        if(it->find(crit_string) != string::npos)
        {
            crit = true;
        }

        // Get test file name without path.
        size_t pos = it->rfind("/");
        if(pos != std::string::npos)
        {
            name = it->substr(pos+1,it->length());
        }

        // Output test file name to log file.
        fout << name;


        // Run program with given test file.
        run_code(*it,name);

		//else, do a failed program log file i supposd

        // Determine corresponding answer file.
        string ans = *it;
        ans.replace(ans.end()-4, ans.end(),answerExtension);

        // Output results.
        if (correct_answer(ans))
        {
            numCorrect++;
            fout << ": PASS" << endl;
        }
        else
        {
            //If this was a crit test, they auto fail
            if(crit)
            {
                crit_passed = false;
            }
            numWrong++;
            fout << ": FAIL" << endl;
        }

    }



    //If all possible crit tests were passed
    if(crit_passed)
    {
        // Output pass and fail stats.
        rate = ( numCorrect / (double)(numCorrect + numWrong) ) * 100;
        fout << rate <<  "% CORRECT," << numCorrect << " PASSED," << numWrong << " FAILED";
        sprintf(buff, "  %f%% Correct\n", rate);
        i = testProgram.rfind('/');
        studentResults.push_back(testProgram.substr(i+1) + string(buff));
    }
    else
    {
        //If one or more were not passed
        fout << "Failed: Did not pass one or more acceptance tests (Labeled as crit)" << endl;
        i = testProgram.rfind('/');
        studentResults.push_back(testProgram.substr(i) + "  FAILED\n");
    }


    fout << "\n" <<  get_gcov(testProgram) << endl;
    fout.close();
    if(profiling)
        get_gprof(testProgram);
}