예제 #1
0
파일: search.c 프로젝트: 0xbad0c0d3/hexedit
void search_backward(void)
{
  char *p, *string, tmp[BLOCK_SEARCH_SIZE], tmpstr[BLOCK_SEARCH_SIZE];
  int quit, sizea, sizeb;
  INT blockstart;

  if (!searchA(&string, &sizea, tmp, sizeof(tmp))) return;
  quit = -1;
  blockstart = base + cursor - sizea + 1;
  do {
    blockstart -= BLOCK_SEARCH_SIZE - sizea + 1;
    sizeb = BLOCK_SEARCH_SIZE;
    if (blockstart < 0) { sizeb -= -blockstart; blockstart = 0; }

    if (sizeb < sizea) quit = -3;
    else {
      if (LSEEK_(fd, blockstart) == -1) { quit = -3; break; }
      if (sizeb != read(fd, tmp, sizeb)) quit = -3;
      else if (getch() != ERR) quit = -2;
      else if ((p = mymemrmem(tmp, sizeb, string, sizea))) quit = p - tmp;
    }

    sprintf(tmpstr,"searching... 0x%08llX", (long long) blockstart);
    nodelay(stdscr, TRUE);
    displayTwoLineMessage(tmpstr, "(press any key to cancel)");

  } while (quit == -1);

  searchB(quit + (quit >= 0 ? blockstart : 0), string);
}
예제 #2
0
파일: mark.c 프로젝트: rofl0r/hexedit0r
void copy_region(void)
{
  typePage *p;

  if (!mark_set) { displayMessageAndWaitForKey("Nothing to copy"); return; }
  sizeCopyBuffer = mark_max - mark_min + 1;
  if (sizeCopyBuffer == 0) return;
  if (sizeCopyBuffer > BIGGEST_COPYING) {
    displayTwoLineMessage("Hey, don't you think that's too big?!", "Really copy (Yes/No)");
    if (tolower(getch()) != 'y') return;
  }
  FREE(copyBuffer);
  if ((copyBuffer = malloc(sizeCopyBuffer)) == NULL) {
    displayMessageAndWaitForKey("Can't allocate that much memory");
    return;
  }
  if (LSEEK_(fd, mark_min) == -1 || read(fd, copyBuffer, sizeCopyBuffer) == -1) {
    displayMessageAndWaitForKey(strerror(errno));
    return;
  }

  for (p = edited; p; p = p->next) {
    if (mark_min < p->base + p->size && p->base <= mark_max) {
      off_t min = MIN(p->base, mark_min);
      memcpy(copyBuffer + p->base - min,
	     p->vals + mark_min - min,
	     MIN(p->base + p->size, mark_max) - MAX(p->base, mark_min) + 1);
    }
  }
  unmarkAll();
  mark_set = FALSE;
}
예제 #3
0
파일: file.c 프로젝트: rofl0r/hexedit0r
int tryloc(off_t loc)
{
  char c;
  if (loc < 0)
    return FALSE;
  if (loc <= lastEditedLoc)
    return TRUE;

  if (loc <= biggestLoc)
    return TRUE;

  if (LSEEK_(fd, loc - 1) != -1 && /* don't have to worry about loc - 1 < 0 */
      read(fd, &c, 1) == 1) {
    biggestLoc = loc;
    return TRUE;
  }
  return FALSE;
}