int main(int argc, char** argv) { if(argc < 3) usage(); long rsaptr = getRSAPointer(argv[1]); long hostptr = getHostPointer(argv[1]); printf("%lo %lo", rsaptr, hostptr); int childpid = fork(); if(childpid == -1) fatal("Unable to fork."); if(childpid == 0) { printf("I'm the child"); //chdir(TIBIA_ENV); execl(TIBIA_PATH, (const char*) NULL, (char*) NULL); exit(0); } sleep(2); pid_t pid = findPid("Tibia"); //write RSA key char data[310] = ""; strcpy(data, RSA_KEY); writeMemory(pid, rsaptr, data, RSALEN); //DEBUG readMemory(pid, rsaptr, data, RSALEN); printf("rsa: %s\n", data); //DEBUG //read pointer to Hostname struct unsigned char ptrdata[4] = ""; readMemory(pid, hostptr, ptrdata, 4); //read offset+4 on Hostname struct readMemory(pid, chartohex(ptrdata)+4, ptrdata, 4); char loc[26] = ""; strcpy(loc,argv[2]); int len = 26; writeMemory(pid, chartohex(ptrdata), loc, len); readMemory(pid,chartohex(ptrdata), data, 30); printf("IP changed to: %s\n", data); return 1; }
// Main program: Initialize the cpu, read initial memory values, // and execute the read-in program starting at location 00. // int main(void) { printf("*** STUB *** CS 350 Lab 7, Weicheng Huang\n"); initCPU(); readMemory(); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; char command[80]; fgets(command, sizeof command, stdin); while(isEnd==0){ printf("%s", prompt); fgets(command, sizeof command, stdin); // Read past end of current line. if(command[0] == 'q'){ isEnd = 1; }else if(command[0] == 'h'||command[0]=='?'){ helpMsg(); }else{ isEnd=instruction_cycle(); } } printf("\nRegisters:\n"); dumpRegisters(regs); printf("\nMemory:\n"); dumpMemory(mem); }
int main ( int argc, char **argv ) { double time_spent; struct timeval tv1, tv2; #ifdef DEBUG printf("IN MAIN\n"); #endif /*Displays Help Command*/ if(argc!=MIN_REQUIRED) { help("WRONG NUMBER OF ARGUMENTS");} if(!strcmp(argv[1], "-h")){ help("HELP: ");} if(argc == 2){ checkArgs(argv[1]);} gettimeofday(&tv1, NULL); readFile(argv[1]); populateMemory(); readMemory(); gettimeofday(&tv2, NULL); /*printf("%x", 0x3f%0x10);*/ time_spent= (double)(tv2.tv_usec - tv1.tv_usec)/1000000 + (double)(tv2.tv_sec - tv1.tv_sec); printf("\n=========\n TIME REQUIRED: %.0f microseconds\n=========\n", time_spent* 1000000); #ifdef DEBUG printf("OUT OF MAIN\n"); #endif return 0; }
int BeeServer::main(const std::vector<std::string>& args) { if (_serverState == SERVER_IDLE) { //create shared memory if start with non params readMemory(); _serverFlag = true; setServerState(SERVER_RUNNING); writeMemory(_serverState); ServerArgv* exRun = new ServerArgv(*this); _exThread.start(*exRun); //BeeTask* pTask = new BeeTask(); //string rule = Application::instance().config().getString("rule"); //pTask->setRule(rule); //TaskManager tm; //tm.start(pTask); task(); waitForTerminationRequest(); //tm.cancelAll(); //tm.joinAll(); } return Application::EXIT_OK; }
usbMsgLen_t usbFunctionSetup(uint8_t data[8]) { usbRequest_t *rq = (void *)data; usbMsgPtr = usbOutputBuffer; if (rq->bRequest == REQ_TEST_PROGRAMMER) { usbOutputBuffer[0] = ERROR_OK; usbOutputBuffer[1] = MAJOR_VERSION; usbOutputBuffer[2] = MINOR_VERSION; usbOutputBuffer[3] = rq->wValue.bytes[0]; usbOutputBuffer[4] = rq->wValue.bytes[1]; usbOutputBuffer[5] = rq->wIndex.bytes[0]; usbOutputBuffer[6] = rq->wIndex.bytes[1]; return 7; } else if (rq->bRequest == REQ_TURN_PROG_ON) { return turnProgOn(); } else if (rq->bRequest == REQ_TURN_PROG_OFF) { return turnProgOff(); } else if (rq->bRequest == REQ_TEST_NRF) { return nrfTest(); } else if (rq->bRequest == REQ_PROGRAM_PAGE) { return programPage(rq->wValue.word, rq->wIndex.word); } else if(rq->bRequest == REQ_READ) { return readMemory(rq->wValue.word, rq->wIndex.word); } else if(rq->bRequest == REQ_ERASE_PAGE) { return erasePage(rq->wValue.word); } return 0; }
void OdyPatch::readPatch(unsigned char patchNum) { unsigned int startAddr = (unsigned int)PATCH_SIZE * patchNum; unsigned int addr = 0; unsigned char i,j; unsigned char data[PATCH_SIZE]; readMemory((void*)data,(const void*)startAddr, sizeof(data)); for(i=0;i<10;++i) { setFunctionValue(i<<1,uncompressFourBit(data[addr],false)); setFunctionValue((i<<1)+1,uncompressFourBit(data[addr],true)); addr++; } for(i=0;i<6;++i) { setCtrlValue(i,data[addr]); addr++; } for(i=0;i<2;++i) //no need to read/write last 3 func opts { for(j=0;j<8;++j) { setOptionValue((i*8)+j,(bool)bitRead(data[addr],j)); } addr++; } }
void TED7360::reset(bool cold_reset) { if (cold_reset) { // reset TED registers this->initRegisters(); // make sure that RAM size is detected correctly for (uint8_t j = 0xC0; j < 0xFF; j++) { if ((j & uint8_t(0x02)) != uint8_t(0) && !(j == uint8_t(0xFE) && segmentTable[0xFC] == (uint8_t *) 0)) continue; if (segmentTable[j] != (uint8_t *) 0) { for (uint16_t i = 0x3FFD; i > 0x3FF5; i--) { if (segmentTable[j][i] != readMemory(i | 0xC000)) break; if (i == 0x3FF6) { segmentTable[j][i] = (segmentTable[j][i] + uint8_t(1)) & uint8_t(0xFF); } } } } // force RAM testing writeMemory(0x0508, 0x00); } // reset ROM banking writeMemory(0xFDD0, 0x00); // reset CPU writeMemory(0x0000, 0x00); writeMemory(0x0001, 0x00); M7501::reset(cold_reset); }
int main ( int argc, char **argv ) { double time_spent; struct timeval tv1, tv2; #ifdef DEBUG printf("IN MAIN\n"); #endif /*Check Arguments*/ if(argc!=MIN_REQUIRED) help("WRONG NUMBER OF ARGUMENTS"); if(!strcmp(argv[1], "-h")) help("HELP: "); if(argc == 2) checkArgs(argv[1]); /*Tracks time*/ gettimeofday(&tv1, NULL); /*Reads File and Populates Data*/ readFile( argv[1]); /*Populates Memory*/ populateMemory(); /*Runs through fetch decode execute loop*/ readMemory(); /*Tracks time*/ gettimeofday(&tv2, NULL); time_spent= (double)(tv2.tv_usec - tv1.tv_usec)/1000000 + (double)(tv2.tv_sec - tv1.tv_sec); printf("\n=========\n TIME REQUIRED: %.0f microseconds\n=========\n", time_spent* 1000000); #ifdef DEBUG printf("OUT OF MAIN\n"); #endif return 0; }
// Main program: Initialize the cpu, read initial memory values, // and execute the read-in program starting at location 00. // int main(void) { printf("*** STUB *** CS 350 Lab 8, Your name\n"); initCPU(); readMemory(); char prompt[] = "> "; printf("\nBeginning execution:\n"); printf("At the %sprompt, press return to execute the next instruction\n", prompt); printf("(or d to dump registers and memory, q to quit, or h or ? for help)\n"); char command[80]; // User inputted command line char cmd_char; // 'q' for quit etc. int simulator_quit = 0; // Have we seen simulator quit command? int nbr_read; // Number of items read by sscanf while (!commands_done) { printf("%s", prompt); fgets(command, sizeof command, stdin); // Read through end of current line. nbr_read = sscanf("%c", &cmd_char); if (nbr_read > 0) { printf("*** STUB *** read in %c command\n"); } else { printf("*** STUB *** read in a number or empty line\n"); } } // When we see the quit command, dump the control unit and memory // and quit // printf("*** STUB *** quitting'n"); }
// // int regs[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // int mem[100] = { 0 }; // Careful: Leading 0s in constants indicates octal nbr // int isEnd = 0; // int pc; // int ir; // int opcode;//operation code // int radd;//register address // int mmadd;//memory address // Main program: Initialize the cpu, read initial memory values, // and execute the read-in program starting at location 00. // int main(void) { printf(" ******************** STUB ********************\n "); printf("Lab9 CS350 Author:Weicheng Huang\n"); CPU c; initCPU(&c); readMemory(&c); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; char command[80]; fgets(command, sizeof command, stdin); while(c.running==1){ printf("%s", prompt); fgets(command, sizeof command, stdin); // Read past end of current line. if(command[0] == 'q'){ c.running = 0; }else if(command[0] == 'h'||command[0]=='?'){ helpMsg(); }else{ c.running=instruction_cycle(&c); } } printf("\nRegisters:\n"); dumpRegisters(&c); printf("\nMemory:\n"); dumpMemory(&c); }
void BeeServer::start(const std::string& name, const std::string& value) { readMemory(); if (_serverState == SERVER_RUNNING) { std::cout<<"process already started"<<std::endl; } }
void Recompiler::lfsx(Instruction code) { llvm::Value* addr; llvm::Value* frd; addr = builder.CreateAdd(getGPR(code.ra), getGPR(code.rb)); frd = readMemory(addr, 32); setFPR(code.frd, frd); }
void Recompiler::ldx(Instruction code) { llvm::Value* addr; llvm::Value* rd; addr = builder.CreateAdd(getGPR(code.ra), getGPR(code.rb)); rd = readMemory(addr, 64); setGPR(code.rd, rd); }
// // Execute will execute the code in the target process/thread, // the techinique for PTRACE is to read CPU state, rewrite the // code portion pointed by PC with the code, resuming the process/thread, // wait for the completion, read the CPU state back to grab return // values, then restoring the previous code. // ErrorCode PTrace::execute(ProcessThreadId const &ptid, ProcessInfo const &pinfo, void const *code, size_t length, uint64_t &result) { Architecture::CPUState savedState, resultState; std::string savedCode; if (!ptid.valid() || code == nullptr || length == 0) return kErrorInvalidArgument; // 1. Read and save the CPU state ErrorCode error = readCPUState(ptid, pinfo, savedState); if (error != kSuccess) return error; // 2. Copy the code at PC savedCode.resize(length); error = readMemory(ptid, savedState.pc(), &savedCode[0], length); if (error != kSuccess) return error; // 3. Write the code to execute at PC error = writeMemory(ptid, savedState.pc(), code, length); if (error != kSuccess) goto fail; // 3. Resume and wait error = resume(ptid, pinfo); if (error == kSuccess) { error = wait(ptid); } if (error == kSuccess) { // 4. Read back the CPU state error = readCPUState(ptid, pinfo, resultState); if (error == kSuccess) { // 5. Save the result result = resultState.retval(); } } // 6. Write back the old code error = writeMemory(ptid, savedState.pc(), &savedCode[0], length); if (error != kSuccess) goto fail; // 7. Restore CPU state error = writeCPUState(ptid, pinfo, savedState); if (error != kSuccess) goto fail; // Success!! We injected and executed code! return kSuccess; fail: return kill(ptid, SIGKILL); // we can't really do much at this point :( }
void Recompiler::lbzx(Instruction code) { llvm::Value* addr; llvm::Value* rd; addr = builder.CreateAdd(getGPR(code.ra), getGPR(code.rb)); rd = readMemory(addr, 8); rd = builder.CreateZExt(rd, builder.getInt64Ty()); setGPR(code.rd, rd); }
void Recompiler::ldu(Instruction code) { llvm::Value* addr = builder.getInt64(code.ds << 2); llvm::Value* rd; addr = builder.CreateAdd(addr, getGPR(code.ra)); rd = readMemory(addr, 64); setGPR(code.ra, addr); setGPR(code.rd, rd); }
void Recompiler::lfsu(Instruction code) { llvm::Value* addr = builder.getInt64(code.d); llvm::Value* frd; addr = builder.CreateAdd(addr, getGPR(code.ra)); frd = readMemory(addr, 32); setGPR(code.ra, addr); setGPR(code.frd, frd); }
void BeeServer::stop(const std::string& name, const std::string& value) { readMemory(); if (_serverState != SERVER_RUNNING) { std::cout<<"System is not in running!"<<std::endl; } setServerState(SERVER_FINISHED); writeMemory(_serverState); }
void Recompiler::lfd(Instruction code) { llvm::Value* addr = builder.getInt64(code.d); llvm::Value* frd; if (code.ra) { addr = builder.CreateAdd(addr, getGPR(code.ra)); } frd = readMemory(addr, 64); setGPR(code.frd, frd); }
void showCpu(Cpu_t *cpu) { SYSTEMOUT_("adr") SYSTEMOUTOCT("",cpu->Pc); SYSTEMOUTOCT(":",readMemory(cpu,0)); SYSTEMOUTOCT("Sp:",cpu->Sp); SYSTEMOUTOCT("A:",cpu->A); printf("SF:%01o ",((cpu->flags)>>SF_FLAG)&1); printf("AF:%01o ",((cpu->flags)>>AF_FLAG)&1); SYSTEMOUTOCT("DISPLAY:",cpu->display); SYSTEMOUTOCT("OUTPORT:",cpu->outport); }
// Main program: Initialize the cpu, read initial memory values, // and execute the read-in program starting at location 00. // int main(void) { printf("CS 350 Lab 8, Raman Walwyn-Venugopal\n"); initCPU(); readMemory(); char prompt[]="> "; printf("\nBeginning execution:\n"); printf("At the %sprompt, press return to execute the next instruction\n", prompt); printf("(or d to dump registers and memory, q to quit, or h or ? for help)\n"); char command[80]; // User inputted command line char cmd_char; // 'q' for quit etc. int simulator_quit = 0; // Have we seen simulator quit command? int nbr_read; // Number of items read by sscanf int commands_done=0; char c; while (!commands_done) { printf("%s", prompt); fgets(command, sizeof command, stdin); // Read through end of current line. //nbr_read = sscanf(command, "%c", &cmd_char); if (strcmp(command,"h\n") == 0 || strcmp(command,"?\n")==0){ helpMsg(); } else if (strcmp(command, "d\n")==0){ dumpControlUnit(pc, ir, regs); dumpMemory(mem); } else if (strcmp(command,"q\n")==0){ commands_done=1; } else if (isdigit(command[0])){ int cycles=atoi(command); int d; for (d=0;d<cycles;d++){ instruction_cycle(); } } else if(strcmp(command, "\n")==0){ instruction_cycle(); } else{ printf("Error! Please enter an appropiate value or h for help\n"); } } dumpControlUnit(pc, ir, regs); dumpMemory(mem); printf("GOODBYE!\n"); }
void Recompiler::lwz(Instruction code) { llvm::Value* addr = builder.getInt64(code.ds << 2); llvm::Value* rd; if (code.ra) { addr = builder.CreateAdd(addr, getGPR(code.ra)); } rd = readMemory(addr, 32); rd = builder.CreateZExt(rd, builder.getInt64Ty()); setGPR(code.rd, rd); }
void GetCommArea( void ) { if( CommonAddr.segment == 0 ) { /* can't get the common */ Comm.cgraph_top = 0; /* region yet. */ Comm.top_ip = 0; Comm.top_cs = 0; Comm.pop_no = 0; Comm.push_no = 0; Comm.in_hook = 1; /* don't record this sample */ } else { readMemory( &CommonAddr, sizeof( Comm ), (char *)&Comm ); } }
ErrorCode PTrace::readString(ProcessThreadId const &ptid, Address const &address, std::string &str, size_t length, size_t *count) { char buf[length]; ErrorCode err = readMemory(ptid, address, buf, length, count); if (err != kSuccess) return err; if (strnlen(buf, length) == length) return kErrorNameTooLong; str = std::string(buf); return kSuccess; }
static void displayTrace(void) { NumberList **trace = NULL; int address; MemCell data; char buff[201]; trace = getTrace(); while(popNumber(trace, &address) == ERR_None) { data = readMemory(address); sprintf(buff, " [Memory] %010u:\t%d\n", address, data.getal); consoleOut(buff); } }
int main(void) { char input; int counter = 0; printf("CS 350 Lab 8, Jamal Kharrat\nSDC Simulator Framework\n\n"); initCPU(); readMemory(); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; printf("%s", prompt); char command[80]; fgets(command, sizeof command, stdin); // Read past end of current line. do { scanf("%c", &input); if(input == '\r' | input == '\n') { instruction_cycle(); printf("%s", prompt); counter++; } else if(input == 'q') printf("Quitting\n"); // display quiting message else if(input == 'h') helpMsg(); // call help message else { printf("Invalid Input, try again: "); break; } } while (input != 'q' & counter < 10); printf("\nRegisters:\n"); dumpRegisters(regs); printf("\nMemory:\n"); dumpMemory(mem); }
void BeeServer::query(const std::string& name, const std::string& value) { readMemory(); switch (_serverState) { case SERVER_IDLE: std::cout<<"System is not in running!"<<std::endl; break; case SERVER_RUNNING: std::cout<<_chalNo<<": running"<<std::endl; break; default: break; } std::cout<<"query state: "<<_serverState<<std::endl; setServerState(SERVER_QUERY); }
ErrorCode ProcessBase::readMemoryBuffer(Address const &address, size_t length, std::string &buffer) { if (_pid == kAnyProcessId) return kErrorProcessNotFound; else if (!address.valid()) return kErrorInvalidArgument; buffer.resize(length); size_t nread; ErrorCode error = readMemory(address, &buffer[0], length, &nread); if (error != kSuccess) { buffer.clear(); return error; } buffer.resize(nread); return kSuccess; }
uint32_t VirtualMachine::disassembleInstruction(std::string& buf, uint32_t addr, bool isCPUAddress, int32_t offs) const { uint32_t addrMask = (isCPUAddress ? 0x0000FFFFU : 0x003FFFFFU); addr &= addrMask; uint32_t baseAddr = (addr + uint32_t(offs)) & addrMask; uint8_t opNum = readMemory(addr, isCPUAddress); char tmpBuf[40]; if (isCPUAddress) std::sprintf(&(tmpBuf[0]), " %04X %02X ???", (unsigned int) baseAddr, (unsigned int) opNum); else std::sprintf(&(tmpBuf[0]), "%06X %02X ???", (unsigned int) baseAddr, (unsigned int) opNum); buf = &(tmpBuf[0]); addr = (addr + 1U) & addrMask; return addr; }
int MemoryMap::processReadCommand(MEMMAP_Message& msg,MEMMAP_Message& msg_reply) { int counter; unsigned char address; unsigned char value; for(counter=0;counter<msg.Field.Length;counter++){ address = msg.Field.Address + counter; value = msg.Field.data[counter]; if(readMemory(address,&value) == true){ // reply to the host msg_reply.Field.data[counter] = value; } else { // printf("read method error\n"); } } msg_reply.Field.Header[0] = MEMMAP_HEADER1; msg_reply.Field.Header[1] = MEMMAP_HEADER2; msg_reply.Field.Cmd = MEMMAP_CMD_RETURN; msg_reply.Field.Address = msg.Field.Address; msg_reply.Field.Length = msg.Field.Length; { int len; unsigned char sum; int i; len = msg_reply.Field.Length; sum = 0; sum = msg_reply.Field.Cmd; sum ^= msg_reply.Field.Address; sum ^= msg_reply.Field.Length; for(i=0;i<len;i++){ sum ^= msg_reply.Field.data[i]; } msg_reply.Field.Sum = sum; } return true; }