コード例 #1
0
ファイル: cfam.c プロジェクト: open-power/pdbg
int hmfsi_target_probe(struct target *cfam, struct target *targets, int max_target_count)
{
	struct target *target = targets;
	uint64_t value, chip_id;
	int target_count = 0, i;

	for (i = 0; i < 8 && i < max_target_count; i++) {
		mfsi_target_init(target, "MFSI Port", 0x80000 + i * HMFSI_STRIDE, cfam);
		if (read_target(target, 0xc09, &value)) {
			target_del(target);
			continue;
		}

		/* Ignore unknown chip ids */
		chip_id = GETFIELD(PPC_BITMASK32(12, 19), value);
		if (chip_id != 0xea && chip_id != 0xd3) {
			target_del(target);
			continue;
		}

		target++;
		target_count++;
	}

	return target_count;
}
コード例 #2
0
ファイル: main.c プロジェクト: bitst0rm/crackme_nr1
int main (int argc, const char * argv[])
{

    printf(" __  __                _       __  __         _        ___  \n");
    printf("|  \\/  |__ _ _ _  __ _| |___  |  \\/  |__ _ __| |_ ___ / _ \\ \n");
    printf("| |\\/| / _` | ' \\/ _` | / -_) | |\\/| / _` / _| ' \\___| (_) |\n");
    printf("|_|  |_\\__,_|_||_\\__, |_\\___| |_|  |_\\__,_\\__|_||_|   \\___/ \n");
    printf("                 |___/                                      \n");
    printf("[v%s]                        (c) fG!, 2012, [email protected]\n", VERSION);
    printf("------------------------------------------------------------\n");
        
    uint8_t *targetBuffer = NULL;
    uint32_t fileSize = 0;
    
    // read the target into a buffer
    fileSize = read_target(&targetBuffer, argv[1]);
    // verify if it's a valid mach-o binary
    verify_macho(targetBuffer);
    
    // mangle header
    if (argv[2]) mangle_offsets(targetBuffer, 1);
    else mangle_offsets(targetBuffer, 0);
        
    // write result
    if (write_buffer(targetBuffer, argv[1], fileSize))
    {
        free(targetBuffer);
        exit(1);
    }

    printf("All done, binary headers are mangled!\n");
    free(targetBuffer);
    return(0);
}
コード例 #3
0
/*
 * function that will read the target binary into our buffer and set some information into the structure
 */
uint8_t 
init_target(target_info_t *targetInfo)
{
#if DEBUG
    printf("[DEBUG] Executing %s\n", __FUNCTION__);
#endif
    // read target file into a buffer
    targetInfo->fileSize = read_target(&(targetInfo->buffer), targetInfo->targetBinaryPath);
    // failure if size is 0
    if (targetInfo->fileSize == 0)
    {
#if DEBUG
        printf("[ERROR] File size is 0, init_target failed!\n");
#endif
        return 1;
    }
    // verify if it's a valid mach-o target
    uint32_t magic = *(uint32_t*)(targetInfo->buffer);
    if (magic == MH_MAGIC || magic == MH_MAGIC_64)
    {
        return 0;
    }
#if DEBUG
    fprintf(stderr, "[ERROR] Target %s is not a mach-o binary or is fat (not supported)!\n", targetInfo->targetBinaryPath);
#endif
    return 1;
}
コード例 #4
0
/*------------------------------------------------------------------*/
void AzSvDataS::read_targets_only(const char *y_fn,
                                  int max_data_num)
{
  reset();
  read_target(y_fn, &v_y, max_data_num);
  int data_num = v_y.rowNum();
  m_feat.reform(1, data_num); /* dummy features */
}
コード例 #5
0
ファイル: adu.c プロジェクト: open-power/pdbg
static int adu_reset(struct target *target)
{
	uint64_t val;

	CHECK_ERR(read_target(target, ALTD_CMD_REG, &val));
	val |= FBC_ALTD_CLEAR_STATUS | FBC_ALTD_RESET_AD_PCB;
	CHECK_ERR(write_target(target, ALTD_CMD_REG, val));

	return 0;
}
コード例 #6
0
ファイル: adu.c プロジェクト: open-power/pdbg
static int adu_lock(struct target *target)
{
	uint64_t val;

	CHECK_ERR(read_target(target, ALTD_CMD_REG, &val));

	if (val & FBC_LOCKED)
		PR_INFO("ADU already locked! Ignoring.\n");

	val |= FBC_LOCKED;
	CHECK_ERR(write_target(target, ALTD_CMD_REG, val));

	return 0;
}
コード例 #7
0
ファイル: adu.c プロジェクト: open-power/pdbg
static int adu_unlock(struct target *target)
{
	uint64_t val;

	CHECK_ERR(read_target(target, ALTD_CMD_REG, &val));

	if (!(val & FBC_LOCKED)) {
		PR_INFO("ADU already unlocked!\n");
		return 0;
	}

	val &= ~FBC_LOCKED;
	CHECK_ERR(write_target(target, ALTD_CMD_REG, val));

	return 0;
}
コード例 #8
0
/*------------------------------------------------------------------*/
void AzSvDataS::_read(const char *feat_fn,
                     const char *y_fn,
                     const char *fdic_fn,
                     int max_data_num)
{
  reset();

  read_feat(feat_fn, fdic_fn, &m_feat, &sp_f_dic, max_data_num);
  read_target(y_fn, &v_y, max_data_num);

  /*---  check the dimensionalty  ---*/
  int f_data_num = m_feat.colNum();
  int y_data_num = v_y.rowNum();
  if (f_data_num != y_data_num) {
    AzBytArr s("Data conflict: ");
    s.c(feat_fn); s.c(" has "); s.cn(f_data_num); s.c(" data points, whereas ");
    s.c(y_fn);    s.c(" has "); s.cn(y_data_num); s.c(" data points.");
    throw new AzException(AzInputNotValid, "AzSvDataS::read", s.c_str());
  }
}
コード例 #9
0
ファイル: targets.hpp プロジェクト: 0000-bigtree/nscp
		void add(boost::shared_ptr<nscapi::settings_proxy> proxy, std::wstring path, std::wstring key, std::wstring value) {
			add(read_target(proxy, path, key, value));
		}
コード例 #10
0
ファイル: target.c プロジェクト: open-power/pdbg
int read_next_target(struct target *target, uint64_t addr, uint64_t *value)
{
    assert(target->next);
    return read_target(target->next, target->base + addr, value);
}
コード例 #11
0
void
m32c_syscall (int id)
{
  static char buf[256];
  int rv;

  argp = 0;
  stackp = A16 ? 3 : 4;
  if (trace)
    printf ("\033[31m/* SYSCALL(%d) = %s */\033[0m\n", id, callnames[id]);
  switch (id)
    {
    case SYS_exit:
      {
	int ec = arg (2);
	if (verbose)
	  printf ("[exit %d]\n", ec);
	step_result = M32C_MAKE_EXITED (ec);
      }
      break;

    case SYS_open:
      {
	int path = arg (PTRSZ);
	int oflags = arg (2);
	int cflags = arg (2);

	read_target (buf, path, 256, 1);
	if (trace)
	  printf ("open(\"%s\",0x%x,%#o) = ", buf, oflags, cflags);

	if (callbacks)
	  /* The callback vector ignores CFLAGS.  */
	  rv = callbacks->open (callbacks, buf, oflags);
	else
	  {
	    int h_oflags = 0;

	    if (oflags & 0x0001)
	      h_oflags |= O_WRONLY;
	    if (oflags & 0x0002)
	      h_oflags |= O_RDWR;
	    if (oflags & 0x0200)
	      h_oflags |= O_CREAT;
	    if (oflags & 0x0008)
	      h_oflags |= O_APPEND;
	    if (oflags & 0x0400)
	      h_oflags |= O_TRUNC;
	    rv = open (buf, h_oflags, cflags);
	  }
	if (trace)
	  printf ("%d\n", rv);
	put_reg (r0, rv);
      }
      break;

    case SYS_close:
      {
	int fd = arg (2);

	if (callbacks)
	  rv = callbacks->close (callbacks, fd);
	else if (fd > 2)
	  rv = close (fd);
	else
	  rv = 0;
	if (trace)
	  printf ("close(%d) = %d\n", fd, rv);
	put_reg (r0, rv);
      }
      break;

    case SYS_read:
      {
	int fd = arg (2);
	int addr = arg (PTRSZ);
	int count = arg (2);

	if (count > sizeof (buf))
	  count = sizeof (buf);
	if (callbacks)
	  rv = callbacks->read (callbacks, fd, buf, count);
	else
	  rv = read (fd, buf, count);
	if (trace)
	  printf ("read(%d,%d) = %d\n", fd, count, rv);
	if (rv > 0)
	  write_target (buf, addr, rv, 0);
	put_reg (r0, rv);
      }
      break;

    case SYS_write:
      {
	int fd = arg (2);
	int addr = arg (PTRSZ);
	int count = arg (2);

	if (count > sizeof (buf))
	  count = sizeof (buf);
	if (trace)
	  printf ("write(%d,0x%x,%d)\n", fd, addr, count);
	read_target (buf, addr, count, 0);
	if (trace)
	  fflush (stdout);
	if (callbacks)
	  rv = callbacks->write (callbacks, fd, buf, count);
	else
	  rv = write (fd, buf, count);
	if (trace)
	  printf ("write(%d,%d) = %d\n", fd, count, rv);
	put_reg (r0, rv);
      }
      break;

    case SYS_getpid:
      put_reg (r0, 42);
      break;

    case SYS_gettimeofday:
      {
	int tvaddr = arg (PTRSZ);
	struct timeval tv;

	rv = gettimeofday (&tv, 0);
	if (trace)
	  printf ("gettimeofday: %ld sec %ld usec to 0x%x\n", tv.tv_sec,
		  tv.tv_usec, tvaddr);
	mem_put_si (tvaddr, tv.tv_sec);
	mem_put_si (tvaddr + 4, tv.tv_usec);
	put_reg (r0, rv);
      }
      break;

    case SYS_kill:
      {
	int pid = arg (2);
	int sig = arg (2);
	if (pid == 42)
	  {
	    if (verbose)
	      printf ("[signal %d]\n", sig);
	    step_result = M32C_MAKE_STOPPED (sig);
	  }
      }
      break;

    case 11:
      {
	int heaptop_arg = arg (PTRSZ);
	if (trace)
	  printf ("sbrk: heap top set to %x\n", heaptop_arg);
	heaptop = heaptop_arg;
	if (heapbottom == 0)
	  heapbottom = heaptop_arg;
      }
      break;

    }
}
コード例 #12
0
ファイル: syscalls.c プロジェクト: 5kg/gdb
int
rx_syscall (int id)
{
  static char buf[256];
  int rv;

  argp = 0;
  stackp = 4;
  if (trace)
    printf ("\033[31m/* SYSCALL(%d) = %s */\033[0m\n", id, id <= SYS_link ? callnames[id] : "unknown");
  switch (id)
    {
    case SYS_exit:
      {
	int ec = arg ();
	if (verbose)
	  printf ("[exit %d]\n", ec);
	return RX_MAKE_EXITED (ec);
      }
      break;

    case SYS_open:
      {
	int path = arg ();
	/* The open function is defined as taking a variable number of arguments
	   because the third parameter to it is optional:
	     open (const char * filename, int flags, ...);
	   Hence the oflags and cflags arguments will be on the stack and we need
	   to skip the (empty) argument registers r3 and r4.  */
	argp = 4;
	int oflags = arg ();
	int cflags = arg ();

	read_target (buf, path, 256, 1);
	if (trace)
	  printf ("open(\"%s\",0x%x,%#o) = ", buf, oflags, cflags);

	if (callbacks)
	  /* The callback vector ignores CFLAGS.  */
	  rv = callbacks->open (callbacks, buf, oflags);
	else
	  {
	    int h_oflags = 0;

	    if (oflags & 0x0001)
	      h_oflags |= O_WRONLY;
	    if (oflags & 0x0002)
	      h_oflags |= O_RDWR;
	    if (oflags & 0x0200)
	      h_oflags |= O_CREAT;
	    if (oflags & 0x0008)
	      h_oflags |= O_APPEND;
	    if (oflags & 0x0400)
	      h_oflags |= O_TRUNC;
	    rv = open (buf, h_oflags, cflags);
	  }
	if (trace)
	  printf ("%d\n", rv);
	put_reg (1, rv);
      }
      break;

    case SYS_close:
      {
	int fd = arg ();

	if (callbacks)
	  rv = callbacks->close (callbacks, fd);
	else if (fd > 2)
	  rv = close (fd);
	else
	  rv = 0;
	if (trace)
	  printf ("close(%d) = %d\n", fd, rv);
	put_reg (1, rv);
      }
      break;

    case SYS_read:
      {
	int fd = arg ();
	int addr = arg ();
	int count = arg ();

	if (count > sizeof (buf))
	  count = sizeof (buf);
	if (callbacks)
	  rv = callbacks->read (callbacks, fd, buf, count);
	else
	  rv = read (fd, buf, count);
	if (trace)
	  printf ("read(%d,%d) = %d\n", fd, count, rv);
	if (rv > 0)
	  write_target (buf, addr, rv, 0);
	put_reg (1, rv);
      }
      break;

    case SYS_write:
      {
	int fd = arg ();
	int addr = arg ();
	int count = arg ();

	if (count > sizeof (buf))
	  count = sizeof (buf);
	if (trace)
	  printf ("write(%d,0x%x,%d)\n", fd, addr, count);
	read_target (buf, addr, count, 0);
	if (trace)
	  fflush (stdout);
	if (callbacks)
	  rv = callbacks->write (callbacks, fd, buf, count);
	else
	  rv = write (fd, buf, count);
	if (trace)
	  printf ("write(%d,%d) = %d\n", fd, count, rv);
	put_reg (1, rv);
      }
      break;

    case SYS_getpid:
      put_reg (1, 42);
      break;

    case SYS_gettimeofday:
      {
	int tvaddr = arg ();
	struct timeval tv;

	rv = gettimeofday (&tv, 0);
	if (trace)
	  printf ("gettimeofday: %ld sec %ld usec to 0x%x\n", tv.tv_sec,
		  tv.tv_usec, tvaddr);
	mem_put_si (tvaddr, tv.tv_sec);
	mem_put_si (tvaddr + 4, tv.tv_usec);
	put_reg (1, rv);
      }
      break;

    case SYS_kill:
      {
	int pid = arg ();
	int sig = arg ();
	if (pid == 42)
	  {
	    if (verbose)
	      printf ("[signal %d]\n", sig);
	    return RX_MAKE_STOPPED (sig);
	  }
      }
      break;

    case 11:
      {
	int heaptop_arg = arg ();
	if (trace)
	  printf ("sbrk: heap top set to %x\n", heaptop_arg);
	heaptop = heaptop_arg;
	if (heapbottom == 0)
	  heapbottom = heaptop_arg;
      }
      break;

    case 255:
      {
	int addr = arg ();
	mem_put_si (addr, rx_cycles + mem_usage_cycles());
      }
      break;

    }
  return RX_MAKE_STEPPED ();
}
コード例 #13
0
ファイル: adu.c プロジェクト: open-power/pdbg
/* Return size bytes of memory in *output. *output must point to an
 * array large enough to hold size bytes. */
int adu_getmem(struct target *target, uint64_t start_addr, uint8_t *output, uint64_t size)
{
	int rc = 0;
	uint64_t addr, cmd_reg, ctrl_reg, val;

	CHECK_ERR(adu_lock(target));

	ctrl_reg = TTYPE_TREAD;
	ctrl_reg = SETFIELD(FBC_ALTD_TTYPE, ctrl_reg, TTYPE_DMA_PARTIAL_READ);
	ctrl_reg = SETFIELD(FBC_ALTD_TSIZE, ctrl_reg, 8);

	CHECK_ERR(read_target(target, ALTD_CMD_REG, &cmd_reg));
	cmd_reg |= FBC_ALTD_START_OP;
	cmd_reg = SETFIELD(FBC_ALTD_SCOPE, cmd_reg, SCOPE_SYSTEM);
	cmd_reg = SETFIELD(FBC_ALTD_DROP_PRIORITY, cmd_reg, DROP_PRIORITY_MEDIUM);

	/* We read data in 8-byte aligned chunks */
	for (addr = 8*(start_addr / 8); addr < start_addr + size; addr += 8) {
		uint64_t data;

	retry:
		/* Clear status bits */
		CHECK_ERR(adu_reset(target));

		/* Set the address */
		ctrl_reg = SETFIELD(FBC_ALTD_ADDRESS, ctrl_reg, addr);
		CHECK_ERR(write_target(target, ALTD_CONTROL_REG, ctrl_reg));

		/* Start the command */
		CHECK_ERR(write_target(target, ALTD_CMD_REG, cmd_reg));

		/* Wait for completion */
		do {
			CHECK_ERR(read_target(target, ALTD_STATUS_REG, &val));
		} while (!val);

		if( !(val & FBC_ALTD_ADDR_DONE) ||
		    !(val & FBC_ALTD_DATA_DONE)) {
			/* PBINIT_MISSING is expected occasionally so just retry */
			if (val & FBC_ALTD_PBINIT_MISSING)
				goto retry;
			else {
				PR_ERROR("Unable to read memory. "	\
					 "ALTD_STATUS_REG = 0x%016llx\n", val);
				rc = -1;
				break;
			}
		}

		/* Read data */
		CHECK_ERR(read_target(target, ALTD_DATA_REG, &data));

		/* ADU returns data in big-endian form in the register */
		data = __builtin_bswap64(data);

		if (addr < start_addr) {
			memcpy(output, ((uint8_t *) &data) + (start_addr - addr), 8 - (start_addr - addr));
			output += 8 - (start_addr - addr);
		} else if (addr + 8 > start_addr + size) {
			memcpy(output, &data, start_addr + size - addr);
		} else {
			memcpy(output, &data, 8);
			output += 8;
		}

	}

	adu_unlock(target);

	return rc;
}
コード例 #14
0
 static void readVector(const char *fn, 
                        /*---  output  ---*/
                        AzDvect *v_data) {
   read_target(fn, v_data); 
 }