void AddressWidget::notifyRequestedLoadUrl() { const QString url = text().trimmed(); if (isAddress(url)) { emit requestedLoadUrl(getUrl()); } }
void AddressWidget::mouseReleaseEvent(QMouseEvent *event) { if (text().isEmpty() && event->button() == Qt::MiddleButton && !QApplication::clipboard()->text().isEmpty()) { const QString text = QApplication::clipboard()->text().trimmed(); if (isAddress(text)) { emit requestedLoadUrl(QUrl(text)); } event->accept(); } else { QLineEdit::mouseReleaseEvent(event); } }
/* Function Name: checkLine * Purpose: Determines validity of a line of YAS * * Parameters: char * to a line of YAS * Returns: -1 : all spaces in line or instruction. * 0 : invalid line * 1 : valid line * Modifies: - */ int checkLine(char * line) { if(isSpaces(line, 0, 21) && line[22] == '|') return -1; //The case of an empty line else{ if(!isSpaces(line, 0, 1)) //Check initial spaces return 0; if(!isAddress(line)) //Check for address return 0; if(!(line[7] == ':' && line[8] == ' ' && line[21] == ' ' && line[22] == '|')) //Check particular spots return 0; if(!(isData(line))) //Check for data { //If no data... if(!isSpaces(line, 9, 20))//Check if only spaces return 0; //If not spaces OR valid data else return -1; //If just spaces } return 1; } }
bool checkLine(char * record) { bool validLine = FALSE; if(isAddress(record)) { //If there is an address and there is data if(isData(record)){ if(isSpaces(record,0,1) && isSpaces(record,8,8) && isSpaces(record,21,21)){ if(record[22] == '|'){ validLine =TRUE; } } } //If there is an address and no data else{ if(isSpaces(record,0,1) && isSpaces(record,8,21) && record[22] == '|') validLine = TRUE; } } //If there is no address else{ if(isSpaces(record,0,21) && record[22]== '|') validLine = TRUE; } return validLine; }
void testFunctions(){ printf("inside main\n \n "); printf("\n validFileName tests: \n"); printf("bumba.y should return 0: "); printf("%d\n", validFileName("bumba.y")); printf("noDot should return 0: "); printf("%d\n", validFileName("noDot")); printf("victory.yo should return 1: "); printf("%d\n", validFileName("victory.yo")); printf("\n isAddress tests: \n"); printf(" 0x01H: should return 0:"); printf("%d\n",isAddress(" 0x01H:")); printf(" 1x014: should return 0:"); printf("%d\n",isAddress(" 1x014:")); printf(" 0x014: should return 1:"); printf("%d\n",isAddress(" 0x014:")); printf(" 0x6A4: should return 1:"); printf("%d\n",isAddress(" 0x064:")); //need to add testing for 0x014:00 ... spaces ... | printf("\n isData tests: \n"); printf(" 0x014: 0z should return 0:"); printf("%d\n",isData(" 0x014: 0z")); printf(" 0x014: 00ddxx01daq should return 0:"); printf("%d\n",isData(" 0x014: 00ddxx01da0q")); printf(" 0x014: 00345dzqa000 should return 0:"); printf("%d\n",isData(" 0x014: 000345dzqa000")); printf(" 0x014: 00ddd0000000 should return 1:"); printf("%d\n",isData(" 0x014: 00ddd0000000 ")); printf(" 0x014: 00000000001 should return 1: "); printf("%d\n",isData(" 0x014: 000000000001")); printf(" 0x014: 01 should return 1: "); printf("%d\n",isData(" 0x014: 01")); printf("\n isSpaces tests: \n"); printf("should return 0: wxrHtl-jhplzsk"); printf("%d\n",isSpaces("wxrHtl-jhplzsk",0,14)); printf("%d\n",isSpaces("wxrHtl-jhplzsk",0,14)); printf("isSpaces should return 1: "); printf("%d\n",isSpaces(" ",0,14)); printf("isSpaces should return 1: "); printf("%d\n",isSpaces(" ",0,2)); printf("isSpaces should return 0: "); printf("%d\n",isSpaces("d ",0,2)); printf("checkHex tests: \n"); printf("abcdzf0123456789 should return 0: "); printf("%d\n",checkHex("abcdzf0123456789",0,15)); printf("abcdef0123456789 should return 1: "); printf("%d\n",checkHex("abcdef0123456789",0,15)); printf("grabAddress tests: \n"); printf(" 0x01a should return 0x01a: "); printf("%x\n",grabAddress(" 0x01a")); printf(" 0x014 should return 0x014: "); printf("%x\n",grabAddress(" 0x014")); printf("grabDataByte tests: \n"); printf(" 01a402, 4 should return 02: "); printf("%x\n", grabDataByte("01a402",4)); printf(" 01a402, 2 should return a4: "); printf("%x\n", grabDataByte("01a402",2)); printf(" 01, 0 should return 01: "); printf("%x\n", grabDataByte("01",0)); printf("countBytes tests: \n"); printf(" 0x014: 00000000001 should return 5: "); printf("%x\n", countBytes(" 0x014: 0000000001 ")); printf(" 0x014: 0201 should return 2: "); printf("%x\n", countBytes(" 0x014: 0201")); printf(" 0x014: 020100 should return 3: "); printf("%x\n", countBytes(" 0x014: 020100")); printf(" 0x014: should return 0: "); printf("%x\n", countBytes(" 0x014: ")); printf("checkLine tests: \n"); printf(" 0x014 000000000001 |comments should return 0: "); printf("%d\n", checkLine(" 0x014 000000000001 |comments\n")); printf("0x014: 000000000001 |comments should return 0: "); printf("%d\n", checkLine("0x014: 000000000001 |comments\n")); printf(" 0x014: 000000000001 |comments should return 1: "); printf("%d\n", checkLine(" 0x014: 000000000001 |comments\n")); //printf(" 01a402, 2 should return a4: "); //printf("%x\n", grabDataByte("01a402",2)); //printf(" 01, 0 should return 01: "); /* printf("discardRest should return 0: \n"); printf("%d\n",discardRest("",0,15)); printf("discardRest should return 1: \n"); printf("%d\n",discardRest("",0,15)); */ }
/* * main function for this program */ void main(int argc, char *argv[]) { int i = 0, fdsrc, numbytes, len, got_function = 0; char fname[] = "vmlinux.asm"; char *str=NULL, *line=NULL, *fun=NULL; char *header=NULL, *cmd=NULL; char *buf, ch, *cmd_buf; char addrcmd[256]; struct stat filestat; char start_addr[32]; char end_addr[32]; char pre_addr[32]; parse_args(argc, argv); /* read the assembly file, it must have function name and code and its address */ if (is_bin_name == 0 || is_asm_name == 0) { printf("You should specify binary or assembly file name\n"); exit(-1); } if((fdsrc = open(asm_name, O_RDONLY)) < 0) { perror("open fdsrc"); exit(EXIT_FAILURE); } fstat(fdsrc, &filestat); buf=malloc(filestat.st_size); if (buf == NULL){ printf("allocate memory fail\n"); exit(EXIT_FAILURE); } cmd_buf=malloc(1024); if (cmd_buf == NULL) { printf("allocate command output fail\n"); exit(EXIT_FAILURE); } /* read up to 10 bytes, write up to 10 bytes */ while ((numbytes = read(fdsrc, buf, filestat.st_size)) != 0) { str=buf; while(1) { line=get_line(&str); if (line == 0) break; if (line && *line == 0) continue; header = strsep_t(&line, ":"); cmd = strsep_t(&line, "\n"); /* try to find start of function */ if (isAddress(header) == 0){ if (strcmp(header, "...") == 0) continue; if (got_function == 1) { //unsigned long uladdr = 0; //parse_hex(trim(end_addr), &uladdr); //uladdr -= 8;/* to prevent invalid probe address */ //sprintf(end_addr, "%x", uladdr); printf("FUNCTION:%s;START_ADDRESS:%s;END_ADDRESS:%s\n", trim(func_name), trim(start_addr), trim(end_addr)); close(fdsrc); exit(EXIT_SUCCESS); } fun=get_FuncName(&header, start_addr); if (fun != NULL) { if (strcmp(fun, func_name) == 0) { got_function=1; } } continue; }else { if (got_function == 1){ if (strncmp(cmd, "e8bd8", 5) == 0) strcpy(end_addr, header); //printf("end_addr:%s cmd:%s\n", end_addr, cmd); } } } } printf("FUNCTION:%s;START_ADDRESS:%s;END_ADDRESS:%s\n", trim(func_name), "NULL", "NULL"); /* close our files and exit */ close(fdsrc); exit(EXIT_SUCCESS); }
/** * load * This function takes a command line argument containing * the name of a file and loads the contents of the file * into memory byte by byte until there is an error * @param: argc: the number of args * args: the name of the file * @return: goodLine: returns false if an error was found */ bool load(int argc, char *args) { bool goodLine = TRUE; int lineNumber = 1; if(validFileName(args)){ FILE * fi; fi = fopen(args,"r"); char record[80]; int prevAdr = -1,startAdr,lineSize; int firstLine = 0; int loop; int dataLoc,byteLoc; int dataLength; bool lastLineData; bool memError; while(fgets(record,80,fi)!=NULL && goodLine){ dataLoc = 9; //Where data starts byteLoc = 0; //Which byte of data to get if (isAddress(record)){ startAdr=setLastAddress(record); //Address in a record } int lineSize = lineLength(record); //Length of record if(record[lineSize]!='\n') { discardRest(record,fi); } //Calls the checkLine if(checkLine(record)) { dataLength = lengthOfData(record); //Length of data in a record //If the record isn't the first line of the file if(firstLine==1) { if(!(lastLineData&&startAdr>prevAdr)) { //If there was data on the last line make sure the address is bigger goodLine = FALSE; //printf("Error on line %d\n",lineNumber); } } //If the record is the first line else{ if(isAddress(record)) { firstLine = 1; } } } //checkLine returns false else{ //printf("Error on line %d\n",lineNumber); goodLine = FALSE; } //If all checks have passed if(goodLine){ //Goes through the data for(loop = 0; loop < dataLength;loop+=2){ //Adds the byte to memory putByte(startAdr,grabDataByte(record,byteLoc),&memError); //printf("%x\n",grabDataByte(record,byteLoc)); startAdr++; byteLoc+=2; } //puts(record); //Output record prevAdr = startAdr - 1; lineNumber++; lastLineData = isData(record); } else if(goodLine == FALSE){ printf("Error on line %d\n", lineNumber); puts(record); } } fclose(fi); } //If the file didn't open else{ goodLine = FALSE; printf("Error opening file"); } return goodLine; }