Esempio n. 1
0
File: assiqe.c Progetto: r-lyeh/eve
void export_pm(FILE *out, int i)
{
	struct aiMatrix4x4 m = bonelist[i].pose;
	fprintf(out, "pm %.9g %.9g %.9g %.9g %.9g %.9g %.9g %.9g %.9g %.9g %.9g %.9g\n",
		KILL(m.a4), KILL(m.b4), KILL(m.c4),
		(m.a1), (m.a2), (m.a3),
		(m.b1), (m.b2), (m.b3),
		(m.c1), (m.c2), (m.c3));
}
Esempio n. 2
0
File: rsa.c Progetto: macssh/macssh
static struct signer *
make_rsa_signer(struct signature_algorithm *s,
		struct sexp_iterator *i)
{
  CAST(rsa_algorithm, params, s);
  NEW(rsa_signer, res);

  if ( (SEXP_LEFT(i) == 8)
       && ( (res->verifier = make_rsa_verifier_internal(params, i)) )
       && sexp_get_un(i, ATOM_D, res->d, RSA_MAX_SIZE)
       && sexp_get_un(i, ATOM_P, res->p, RSA_MAX_SIZE)
       && sexp_get_un(i, ATOM_Q, res->q, RSA_MAX_SIZE)
       && sexp_get_un(i, ATOM_A, res->a, RSA_MAX_SIZE)
       && sexp_get_un(i, ATOM_B, res->b, RSA_MAX_SIZE)
       && sexp_get_un(i, ATOM_C, res->c, RSA_MAX_SIZE) )
    {
      res->super.sign = do_rsa_sign;
      res->super.sign_spki = do_rsa_sign_spki;
      res->super.get_verifier = do_rsa_get_verifier;
      
      return &res->super;
    }
  else
    {
      KILL(res);
      return NULL;
    }
}
Esempio n. 3
0
struct command *
make_pty_request(struct interact *tty)
{
  NEW(pty_request, req);
  char *term = getenv("TERM");

  req->attr = INTERACT_GET_ATTRIBUTES(tty);

  if (!req->attr)
    {
      KILL(req);
      return NULL;
    }
  
  if (!INTERACT_WINDOW_SIZE(tty, &req->dims))
    req->dims.char_width = req->dims.char_height
      = req->dims.pixel_width = req->dims.pixel_height = 0;

  req->super.super.call = do_channel_request_command;
  req->super.format_request = do_format_pty_request;
  
  req->tty = tty;
  req->term = term ? make_string(term) : ssh_format("");

  return &req->super.super;
}
Esempio n. 4
0
File: spki.c Progetto: macssh/macssh
struct verifier *
spki_make_verifier(struct alist *algorithms,
		   struct sexp *e)
{
  /* Syntax: (<algorithm> <s-expr>*) */
  struct signature_algorithm *algorithm;
  struct verifier *v;
  int algorithm_name;
  struct sexp_iterator *i;

  algorithm_name = spki_get_type(e, &i);

  {
    CAST_SUBTYPE(signature_algorithm, a, 
		 ALIST_GET(algorithms, algorithm_name));
    algorithm = a;
  }
  
  if (!algorithm)
    {
      werror("spki_make_verifier: Unsupported algorithm %a.\n", algorithm_name);
      return NULL;
    }

  v = MAKE_VERIFIER(algorithm, i);
  KILL(i);
  
  if (!v)
    {
      werror("spki_make_verifier: Invalid public-key data.\n");
      return NULL;
    }
  
  return v;
}
Esempio n. 5
0
void
uisthread_stop(struct uisthread_info *thrinfo)
{
	int ret;
	int stopped = 0;

	if (thrinfo->id == 0)
		return;		/* thread not running */

	LOGINF("uisthread_stop stopping id:%d\n", thrinfo->id);
	thrinfo->should_stop = 1;
	ret = KILL(thrinfo->id, SIGHUP, 1);
	if (ret) {
		LOGERR("unable to signal thread %d\n", ret);
	} else {
		/* give up if the thread has NOT died in 1 minute */
		if (wait_for_completion_timeout(&thrinfo->has_stopped, 60 * HZ))
			stopped = 1;
		else
			LOGERR("timed out trying to signal thread\n");
	}
	if (stopped) {
		LOGINF("uisthread_stop stopped id:%d\n", thrinfo->id);
		thrinfo->id = 0;
	}
}
Esempio n. 6
0
int main(int argc,char **argv)
{

  FILE* Output;
  double kappa, lambda, L, Sacc, Sps, dt, T, ec, fstar;
  long NFFT;

  Output = fopen("Detector.h","w");

  if(argc !=8) KILL("./Setup kappa, lambda, Larm (m), Sacc (m^2 s^-4 Hz^-1), Spos (m^2 Hz^-1), Cadence (s), Nsamples\n");

  kappa = atof(argv[1]);
  lambda = atof(argv[2]);
  L = atof(argv[3]);
  Sacc = atof(argv[4]);
  Sps = atof(argv[5]);
  dt = atof(argv[6]);
  NFFT = atoi(argv[7]);

  T = dt*(double)(NFFT);
  fstar = clight/(2.0*pi*L);
  ec = (L/(2.0*sqrt(3.0)*Rgc));


  fprintf(Output, "         /* ----------------  DETECTOR CONSTANTS  ---------------- */               \n\n");

  fprintf(Output, " /* Observation time (seconds) */ \n");
  fprintf(Output, "#define T %.12f\n\n", T);

  fprintf(Output, " /* Number of data points */ \n");
  fprintf(Output, "#define NFFT %ld\n\n", NFFT);

  fprintf(Output, "#define dt %f\n\n", dt);

  fprintf(Output, " /* Initial azimuthal position of the guiding center */ \n");
  fprintf(Output, "#define kappa %f\n\n", kappa);

  fprintf(Output, " /* Initial orientation of the LISA constellation */ \n");
  fprintf(Output, "#define lambda %f\n\n", lambda);

  fprintf(Output, " /* Mean arm length of the LISA detector (meters) */ \n");
  fprintf(Output, "#define L %e\n\n", L);

  fprintf(Output, " /* Photon shot noise power */ \n");
  fprintf(Output, "#define Sps %e\n\n", Sps);
 
  fprintf(Output, " /* Acceleration noise power */ \n");
  fprintf(Output, "#define Sacc %e\n\n", Sacc);

  fprintf(Output, " /* Transfer frequency */ \n");
  fprintf(Output, "#define fstar %.10f\n\n", fstar);

  fprintf(Output, " /* LISA orbital eccentricity */ \n");
  fprintf(Output, "#define ec %.10f\n\n", ec);

  fclose(Output);

  return 0;
}
Esempio n. 7
0
int console_close(int data1, data data2) {
	connection_type *ct = (connection_type*)data2;
	console_connection *cn = ct->uptr;

	KILL(cn);

	return 0;
}
Esempio n. 8
0
/*
 * Free a pointer if it was set via safe_malloc() above.
 * Otherwise, do nothing.
 *
 * This takes a pointer to the pointer as input, as it sets it to 0 itself.
 */
void safe_free(vptr p)
{
	/* Look for the pointer. */
	vptr *np = get_alloc_pointer(p);

	/* Found it, so free it and set to 0. */
	if (np) KILL(*np);
}
Esempio n. 9
0
File: driver.c Progetto: YIwama/bcb
void
kill_load (void)
{
	int i;
	
#if !defined(U2200) && !defined(DOS)
	for (i = 0; i < children; i++)
		if (pids[i])
			KILL (pids[i]);
#endif /* !U2200 && !DOS */
		return;
}
Esempio n. 10
0
/* Performs several checks on the INITIAL and GOAL arguments specified on the
command line. Returns TRUE if they are equal in length, contain the same chars,
and do not exceed height * depth of the tray. Throws an error and exits if
these conditions are violated. 
*/
int checkTray(int height, int width, char *s1, char * s2)
{	
	int len1 = strlen(s1);				// Ensure tray lengths are equal
	int len2 = strlen(s2);				// and do not exceed height * width
	if ((len1 != len2) || (height*width != len1))
		KILL("ERROR: Invalid tray lengths.");
	int array1[12] = {0};				// track what chars appear in s1,s2
	int array2[12] = {0};				// make sure they're the same
	for (int i = 0; i < len1; i++)
	{									// Convert to (u)int for comparisons
		unsigned int x = s1[i], y = s2[i];
		if (x < 65 || y < 65 || x > 76 || y > 76)
			KILL("ERROR: Char outside A - L (ASCII 65 - 76).");	
		array1[x-65]++;					// Increment array of letters
		array2[y-65]++;
	}
	for (int j = 0; j < 12; j++)		// Check if initial and goal have
	{									// the same letters
		if (array1[j] != array2[j])
			KILL("ERROR: Initial and Goal must contain same characters."); 
	}
	return true;
}
Esempio n. 11
0
struct command *
make_resolver(void)
{
  NEW(resolver, self);
  int res;
  
  if ( (res = adns_init(&self->adns, flags, NULL)) )
    {
      werror("adns_init failed: %e.\n", res);
      KILL(self);
      return NULL;
    }

  return &self->super;
}
Esempio n. 12
0
static void evolve(char *field, int w, int h) {
	int i, j, alive, cell;

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			alive = countAlive(field, i, j, w, h);
			cell = CELL(i, j, w);

			if (cell == ALIVE) {
				if (alive > 3 || alive < 2) {
					KILL(i, j, w);
				} else {
					VIVIFY(i, j, w);
				}
			} else {
				if (alive == 3) {
					VIVIFY(i, j, w);
				} else {
					KILL(i, j, w);
				}
			}
		}
	}
}
Esempio n. 13
0
File: assiqe.c Progetto: r-lyeh/eve
void fix_pose(void)
{
	int i;

	calc_abs_pose();

	if (dohips) fix_hips(0);

	for (i = 0; i < numbones; i++) {
		if (bonelist[i].isbone) {
			// remove scaling factor in absolute pose
			if (dounscale < 0) {
				struct aiVector3D apos, ascale;
				struct aiQuaternion arot;
				aiDecomposeMatrix(&bonelist[i].abspose, &ascale, &arot, &apos);
				bonelist[i].unscale[0] = ascale.x;
				bonelist[i].unscale[1] = ascale.y;
				bonelist[i].unscale[2] = ascale.z;
				if (KILL(ascale.x) != 1 || KILL(ascale.y) != 1 || KILL(ascale.z) != 1)
					fprintf(stderr, "unscaling %s: %g %g %g\n", bonelist[i].name, ascale.x, ascale.y, ascale.z);
			}
			if (dounscale) {
				float x = bonelist[i].unscale[0];
				float y = bonelist[i].unscale[1];
				float z = bonelist[i].unscale[2];
				if (KILL(x) != 1 || KILL(y) != 1 || KILL(z) != 1) {
					bonelist[i].abspose.a1 /= x; bonelist[i].abspose.b1 /= x; bonelist[i].abspose.c1 /= x;
					bonelist[i].abspose.a2 /= y; bonelist[i].abspose.b2 /= y; bonelist[i].abspose.c2 /= y;
					bonelist[i].abspose.a3 /= z; bonelist[i].abspose.b3 /= z; bonelist[i].abspose.c3 /= z;
				}
			}

			// flip axis in absolute pose
			if (doaxis)
				aiMultiplyMatrix4(&bonelist[i].abspose, &axis_x_to_y);

			// ...and invert so we can recalculate the local poses
			aiInverseMatrix(&bonelist[i].invpose, &bonelist[i].abspose);

			// ...and recalculate the local pose
			bonelist[i].pose = bonelist[i].abspose;
			if (bonelist[i].parent >= 0) {
				struct aiMatrix4x4 m = bonelist[bonelist[i].parent].invpose;
				aiMultiplyMatrix4(&m, &bonelist[i].pose);
				bonelist[i].pose = m;
			}

			// ...and make sure we have it in decomposed form
			aiDecomposeMatrix(&bonelist[i].pose, &bonelist[i].scale, &bonelist[i].rotate, &bonelist[i].translate);
		}
	}

	if (dohips) unfix_hips();
}
Esempio n. 14
0
File: rsa.c Progetto: macssh/macssh
static struct rsa_verifier *
make_rsa_verifier_internal(struct rsa_algorithm *params,
			   struct sexp_iterator *i)
{
  NEW(rsa_verifier, res);
  init_rsa_verifier(res, params);

  assert(SEXP_LEFT(i) >= 2);
  
  if (spki_init_rsa_verifier(res, i))
    {
      return res;
    }
  else
    {
      KILL(res);
      return NULL;
    }
}
Esempio n. 15
0
File: spki.c Progetto: macssh/macssh
/* Returns the algorithm type, or zero on error. */
struct signer *
spki_make_signer(struct alist *algorithms,
		 struct sexp *e,
		 int *type)
{
  /* Syntax: (<algorithm> <s-expr>*) */
  struct signature_algorithm *algorithm;
  struct signer *s;
  int algorithm_name;
  struct sexp_iterator *i;

  algorithm_name = spki_get_type(e, &i);

  if (!algorithm_name)
    return NULL;
  
  {
    CAST_SUBTYPE(signature_algorithm, a, 
		 ALIST_GET(algorithms, algorithm_name));
    algorithm = a;
  }

  if (!algorithm)
    {
      werror("spki_make_signer: Unsupported algorithm %a.\n", algorithm_name);
      return NULL;
    }

  s = MAKE_SIGNER(algorithm, i);
  KILL(i);
  
  if (!s)
    {
      werror("spki_make_signer: Invalid public-key data.\n");
      return NULL;
    }

  if (type)
    *type = algorithm_name;

  return s;
}
Esempio n. 16
0
File: rsa.c Progetto: macssh/macssh
static void
pkcs1_encode(mpz_t m,
	     struct rsa_algorithm *params,
	     UINT32 length,
	     UINT32 msg_length,
	     const UINT8 *msg)
{
#if ALLOCA_68K_BUG
  ALLOCA_START(alloca_ref);
#endif
  UINT8 *em = alloca(length);
  unsigned i = length;
  
  struct hash_instance *h = MAKE_HASH(params->hash);
  HASH_UPDATE(h, msg_length, msg);

  assert(i >= h->hash_size);
  i -= h->hash_size;

  HASH_DIGEST(h, em + i);
  KILL(h);

  assert(i >= params->prefix_length);
  i -= params->prefix_length;

  memcpy(em + i, params->prefix, params->prefix_length);

  assert(i);
  em[--i] = 0;

  assert(i >= 9);
  em[0] = 1;
  memset(em + 1, 0xff, i - 1);
  
  bignum_parse_u(m, length, em);

  debug("pkcs1_encode: m = %xn\n", m);
#if ALLOCA_68K_BUG
  ALLOCA_FREE(alloca_ref);
#endif
}
Esempio n. 17
0
File: rsa.c Progetto: macssh/macssh
/* Alternative constructor using a key of type ssh-rsa, when the atom
 * "ssh-rsa" is already read from the buffer. */
struct verifier *
parse_ssh_rsa_public(struct simple_buffer *buffer)
{
  NEW(rsa_verifier, res);
  init_rsa_verifier(res, &rsa_sha1_algorithm);

  if (parse_bignum(buffer, res->e, RSA_MAX_SIZE)
      && (mpz_sgn(res->e) == 1)
      && parse_bignum(buffer, res->n, RSA_MAX_SIZE)
      && (mpz_sgn(res->n) == 1)
      && (mpz_cmp(res->e, res->n) < 0)
      && parse_eod(buffer)
      && rsa_check_size(res))
    return &res->super;

  else
    {
      KILL(res);
      return NULL;
    }
}
Esempio n. 18
0
File: spki.c Progetto: macssh/macssh
/* Returns 0 or an atom */
int
spki_get_type(struct sexp *e, struct sexp_iterator **res)
{
  struct sexp_iterator *i;
  int type;
  
  if (sexp_atomp(e) || sexp_nullp(e))
    return 0;

  i = SEXP_ITER(e);

  type = sexp2atom(SEXP_GET(i));
  if (type && res)
    {
      SEXP_NEXT(i);
      *res = i;
    }
  else
    KILL(i);

  return type;
}
Esempio n. 19
0
static struct crypto_instance *
do_make_cascade(struct crypto_algorithm *s,
		int mode, const UINT8 *key, const UINT8 *iv)
{
  CAST(crypto_cascade_algorithm, algorithm, s);
  NEW(crypto_cascade_instance, instance);
  unsigned i;
  unsigned l = LIST_LENGTH(algorithm->cascade);
  
  instance->super.block_size = algorithm->super.block_size;
  instance->cascade = alloc_object_list(l);

  for (i = 0; i<l; i++)
    {
      /* When decrypting, the crypto algorithms should be used in
       * reverse order! */

      unsigned j = ( (mode == CRYPTO_ENCRYPT)
		     ? i : l - i - 1);
      
      CAST_SUBTYPE(crypto_algorithm, a, LIST(algorithm->cascade)[i]);
      struct crypto_instance *o	= MAKE_CRYPT(a, mode, key, iv);
      
      if (!o)
	{
	  KILL(instance);
	  return NULL;
	}

      LIST(instance->cascade)[j] = (struct lsh_object *) o;
      key += a->key_size;
      iv += a->iv_size;
    }

  instance->super.crypt = do_cascade_crypt;
  
  return &instance->super;
}
Esempio n. 20
0
struct int_list *
parse_atoms(struct simple_buffer *buffer, unsigned limit)
{
  unsigned count;
  unsigned i;
  struct int_list *res;

  assert(limit);

  if (!LEFT)
    return make_int_list(0, -1);
  
  /* Count commas (no commas means one atom) */
  for (i = buffer->pos, count = 1; i < buffer->capacity; i++)
    if (buffer->data[i] == ',')
      {
	if (count >= limit)
	  return NULL;
	count++;
      }

  res = alloc_int_list(count);

  for (i = 0; i < count; i++)
    {
      enum lsh_atom atom;
      
      if (!parse_next_atom(buffer, &atom))
	{
	  KILL(res);
	  return NULL;
	}
      LIST(res)[i] = atom;
    }

  return res;
}
Esempio n. 21
0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Dispatch command
//#pragma comment(lib, "ComCtl32.lib")
HRESULT Dispatch(PTSTR ptzCmd, CXT& XT)
{
	// Get command ID
	UINT uCmd;
	PTSTR p = ptzCmd;
	for (uCmd = 0; uCmd < _NumOf(c_tzCmd); uCmd++)
	{
		if (UStrMatchI(p, c_tzCmd[uCmd]) >= CC_LEN)
		{
			// skip white space
			for (p += CC_LEN; (*p == ' ') || (*p == '\t'); p++);
			break;
		}
	}

	switch (uCmd)
	{
	case CMD_LOAD:
		return LOAD(p);

	case CMD_BATC:
		return BATC(p, XT);

	case CMD_IFEX:
		if (*p)
		{
			if (PTSTR ptzArg = UStrChr(p, CC_SEP))
			{
				*ptzArg++ = 0;
				if (IFEX(p))
				{
					Dispatch(ptzArg, XT);
				}
				return XT.hXVar;
			}
			else if (!IFEX(p))
			{
				if (p = UStrStr(XT.ptzNext, TEXT("IFEX\r\n")))
				{
					XT.ptzNext = p + CC_LEN + 2;
					return S_OK;
				}
				else if (p = UStrStr(XT.ptzNext, TEXT("IFEX\n")))
				{
					XT.ptzNext = p + CC_LEN + 1;
					return S_OK;
				}
				else
				{
					XT.ptzNext = TEXT("");
					return S_FALSE;
				}
			}
		}
		return S_OK;

	case CMD_ELSE:
		if (!g_bResult) Dispatch(p, XT);
		return XT.hXVar;

	case CMD_EVAL:
		return EVAL(p);

	case CMD_LINK:
		return LINK(p);

	case CMD_FILE:
		return FILe(p);

	case CMD_REGX:
		return REGX(p);

	case CMD_ENVI:
		return (*p == '$') ? ENVI(p + 1, TRUE) : ENVI(p);

	case CMD_SEND:
		return SEND(p);

	case CMD_WAIT:
		Sleep(UStrToInt(p));
		return S_OK;

	case CMD_KILL:
		return KILL(p);

	case CMD_SHUT:
		return SHUT(p);

	case CMD_PLAY:
		return PLAY(p);

	case CMD_BEEP:
		return !MessageBeep(UStrToInt(p));

	case CMD_MSGX:
		return MSGX(p);

	case CMD_DLGX:
		return (HRESULT) DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_Dialog), NULL, DLGX, (LPARAM) p);

	case CMD_EXEC:
		return EXEC(p);

	case CMD_CDLL:
		return CDLL(p);

	case CMD_CCUI:
		return (HRESULT) DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_Main), NULL, MAIN, (LPARAM) XT.ptzFile);

	case CMD_CALL:
	case CMD_GOTO:
	case CMD_PROC:
		UMemCopy(ptzCmd, c_tzCmd[(uCmd == CMD_PROC) ? CMD_ENDP : CMD_PROC], CC_LEN * sizeof(TCHAR));
		if (p = UStrStr(XT.ptzNext, ptzCmd))
		{
			p += CC_LEN;
			while (*p && (*p++ != '\n'));
			if (uCmd == CMD_CALL)
			{
				return Process(p, XT.ptzFile);
			}
			else
			{
				XT.ptzNext = p;
			}
			return S_OK;
		}
		else if (uCmd == CMD_PROC)
		{
			XT.ptzNext = TEXT("");
		}
		return S_FALSE;

	case CMD_ENDP:
		XT.ptzNext = TEXT("");
		return S_OK;

	case CMD_ASOC:
		return ASOC(p);

	case CMD_DEVI:
		return SERV(p);
		
	case CMD_SERV:
		return SERV(p);

	case CMD_PAGE:
		return PAGE(p);

	case CMD_DISP:
		return DISP(p);

	default:
		PTSTR ptzFile;
		if (ptzFile = UStrRChr(p, '\\'))
		{
			*ptzFile++ = 0;
		}
		return (*p == '!') ? OPEN(p + 1, ptzFile, TRUE) : OPEN(p, ptzFile);
	}
}
Esempio n. 22
0
struct lsh_string *
pkcs5_derive_key(struct mac_algorithm *prf,
		 const struct lsh_string *password,
		 const struct lsh_string *salt,
		 uint32_t iterations,
		 uint32_t key_length)
{
  struct mac_instance *m = MAKE_MAC(prf,
				    lsh_string_length(password),
				    lsh_string_data(password));
  struct lsh_string *key = lsh_string_alloc(key_length);
  uint32_t left = key_length;
  uint32_t pos = 0;
  
  /* Set up the block counter buffer. This will never have more than
   * the last few bits set (using sha1, 8 bits = 5100 bytes of key) so
   * we only change the last byte. */

  uint8_t block_count[4] = { 0, 0, 0, 1 }; 

  struct lsh_string *digest = lsh_string_alloc(prf->mac_size);
  struct lsh_string *buffer = lsh_string_alloc(prf->mac_size);

  assert(iterations);
  assert(key_length <= 255 * prf->mac_size);
  
  for (;; block_count[3]++)
    {
      uint32_t i;
      assert(block_count[3]);
      
      /* First iterate */
      MAC_UPDATE(m, lsh_string_length(salt), lsh_string_data(salt));
      MAC_UPDATE(m, 4, block_count);
      MAC_DIGEST(m, buffer, 0);

      for (i = 1; i < iterations; i++)
	{
	  MAC_UPDATE(m, prf->mac_size, lsh_string_data(buffer));
	  MAC_DIGEST(m, digest, 0);
	  lsh_string_write_xor(buffer, 0, STRING_LD(digest));
	}

      assert(pos + left == key_length);
      
      if (left <= prf->mac_size)
	{
	  lsh_string_write(key, pos, left, lsh_string_data(buffer));
	  break;
	}
      else
	{
	  lsh_string_write_string(key, pos, buffer);
	  pos += prf->mac_size;
	  left -= prf->mac_size;
	}
    }
  KILL(m);
  lsh_string_free(digest);
  lsh_string_free(buffer);

  return key;
}
Esempio n. 23
0
int main(int argc, char **argv)
{
  argp_parse(&werror_argp, argc, argv, 0, NULL, NULL);

  {
    struct crypto_algorithm *algorithm = &rijndael128_algorithm;
    struct lsh_string *key = simple_decode_hex("00010203050607080A0B0C0D0F101112") ;
    struct lsh_string *plain = simple_decode_hex("506812A45F08C889B97F5980038B8359") ;
    struct lsh_string *cipher = simple_decode_hex("D8F532538289EF7D06B506A4FD5BE9C9") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-128 1 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-128 1 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }



  {
    struct crypto_algorithm *algorithm = &rijndael128_algorithm;
    struct lsh_string *key = simple_decode_hex("14151617191A1B1C1E1F202123242526") ;
    struct lsh_string *plain = simple_decode_hex("5C6D71CA30DE8B8B00549984D2EC7D4B") ;
    struct lsh_string *cipher = simple_decode_hex("59AB30F4D4EE6E4FF9907EF65B1FB68C") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-128 2 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-128 2 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }



  {
    struct crypto_algorithm *algorithm = &rijndael128_algorithm;
    struct lsh_string *key = simple_decode_hex("28292A2B2D2E2F30323334353738393A") ;
    struct lsh_string *plain = simple_decode_hex("53F3F4C64F8616E4E7C56199F48F21F6") ;
    struct lsh_string *cipher = simple_decode_hex("BF1ED2FCB2AF3FD41443B56D85025CB1") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-128 3 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-128 3 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }


/* Skipped lots of tests */


  {
    struct crypto_algorithm *algorithm = &rijndael128_algorithm;
    struct lsh_string *key = simple_decode_hex("A0A1A2A3A5A6A7A8AAABACADAFB0B1B2") ;
    struct lsh_string *plain = simple_decode_hex("F5F4F7F684878689A6A7A0A1D2CDCCCF") ;
    struct lsh_string *cipher = simple_decode_hex("CE52AF650D088CA559425223F4D32694") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-128 128 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-128 128 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }



  {
    struct crypto_algorithm *algorithm = &rijndael192_algorithm;
    struct lsh_string *key = simple_decode_hex("00010203050607080A0B0C0D0F10111214151617191A1B1C") ;
    struct lsh_string *plain = simple_decode_hex("2D33EEF2C0430A8A9EBF45E809C40BB6") ;
    struct lsh_string *cipher = simple_decode_hex("DFF4945E0336DF4C1C56BC700EFF837F") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-192 1 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-192 1 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }



  {
    struct crypto_algorithm *algorithm = &rijndael192_algorithm;
    struct lsh_string *key = simple_decode_hex("1E1F20212324252628292A2B2D2E2F30323334353738393A") ;
    struct lsh_string *plain = simple_decode_hex("6AA375D1FA155A61FB72353E0A5A8756") ;
    struct lsh_string *cipher = simple_decode_hex("B6FDDEF4752765E347D5D2DC196D1252") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-192 2 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-192 2 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }



  {
    struct crypto_algorithm *algorithm = &rijndael192_algorithm;
    struct lsh_string *key = simple_decode_hex("3C3D3E3F41424344464748494B4C4D4E5051525355565758") ;
    struct lsh_string *plain = simple_decode_hex("BC3736518B9490DCB8ED60EB26758ED4") ;
    struct lsh_string *cipher = simple_decode_hex("D23684E3D963B3AFCF1A114ACA90CBD6") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-192 3 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-192 3 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }


/* Skipped lots of tests */


  {
    struct crypto_algorithm *algorithm = &rijndael192_algorithm;
    struct lsh_string *key = simple_decode_hex("868788898B8C8D8E90919293959697989A9B9C9D9FA0A1A2") ;
    struct lsh_string *plain = simple_decode_hex("D3D2DDDCAAADACAF9C9D9E9FE8EBEAE5") ;
    struct lsh_string *cipher = simple_decode_hex("9ADB3D4CCA559BB98C3E2ED73DBF1154") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-192 128 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-192 128 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }



  {
    struct crypto_algorithm *algorithm = &rijndael256_algorithm;
    struct lsh_string *key = simple_decode_hex("00010203050607080A0B0C0D0F10111214151617191A1B1C1E1F202123242526") ;
    struct lsh_string *plain = simple_decode_hex("834EADFCCAC7E1B30664B1ABA44815AB") ;
    struct lsh_string *cipher = simple_decode_hex("1946DABF6A03A2A2C3D0B05080AED6FC") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-256 1 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-256 1 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }



  {
    struct crypto_algorithm *algorithm = &rijndael256_algorithm;
    struct lsh_string *key = simple_decode_hex("28292A2B2D2E2F30323334353738393A3C3D3E3F41424344464748494B4C4D4E") ;
    struct lsh_string *plain = simple_decode_hex("D9DC4DBA3021B05D67C0518F72B62BF1") ;
    struct lsh_string *cipher = simple_decode_hex("5ED301D747D3CC715445EBDEC62F2FB4") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-256 2 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-256 2 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }



  {
    struct crypto_algorithm *algorithm = &rijndael256_algorithm;
    struct lsh_string *key = simple_decode_hex("50515253555657585A5B5C5D5F60616264656667696A6B6C6E6F707173747576") ;
    struct lsh_string *plain = simple_decode_hex("A291D86301A4A739F7392173AA3C604C") ;
    struct lsh_string *cipher = simple_decode_hex("6585C8F43D13A6BEAB6419FC5935B9D0") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-256 3 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-256 3 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }


/* Skipped lots of tests */


  {
    struct crypto_algorithm *algorithm = &rijndael256_algorithm;
    struct lsh_string *key = simple_decode_hex("50515253555657585A5B5C5D5F60616264656667696A6B6C6E6F707173747576") ;
    struct lsh_string *plain = simple_decode_hex("050407067477767956575051221D1C1F") ;
    struct lsh_string *cipher = simple_decode_hex("7444527095838FE080FC2BCDD30847EB") ;
    struct crypto_instance *c;

    assert(key->length == algorithm->key_size);
    assert(!algorithm->iv_size);

    c = MAKE_ENCRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Encrypting with rijndael-256 128 ... ", stderr);
    a = crypt_string(c, plain, 0);
    b = lsh_string_dup(cipher);
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    c = MAKE_DECRYPT(algorithm, key->data, NULL);
    
  {
    struct lsh_string *a, *b;
    fputs("Decrypting with rijndael-256 128 ... ", stderr);
    a = crypt_string(c, cipher, 0);
    b = plain;
    if (!lsh_string_eq(a, b))
      { fputs("failed.\n", stderr);; exit(1); }
    fputs("ok.\n", stderr);
    lsh_string_free(a);
    lsh_string_free(b);
  }

    KILL(c);
    
    lsh_string_free(key);
    lsh_string_free(cipher);
  }



  return 0;
}
Esempio n. 24
0
/*
 * Process a single instruction.
 *
 * Returns "false" if something goes fatally wrong.
 */
static bool processInstruction(VerifierData* vdata, u4 insnIdx,
    BitVector* workBits)
{
    const Method* meth = vdata->method;
    const u2* insns = meth->insns + insnIdx;
    DecodedInstruction decInsn;

    dexDecodeInstruction(insns, &decInsn);

    /*
     * Add registers to the "GEN" or "KILL" sets.  We want to do KILL
     * before GEN to handle cases where the source and destination
     * register is the same.
     */
    switch (decInsn.opcode) {
    case OP_NOP:
    case OP_RETURN_VOID:
    case OP_GOTO:
    case OP_GOTO_16:
    case OP_GOTO_32:
        /* no registers are used */
        break;

    case OP_RETURN:
    case OP_RETURN_OBJECT:
    case OP_MONITOR_ENTER:
    case OP_MONITOR_EXIT:
    case OP_CHECK_CAST:
    case OP_THROW:
    case OP_PACKED_SWITCH:
    case OP_SPARSE_SWITCH:
    case OP_FILL_ARRAY_DATA:
    case OP_IF_EQZ:
    case OP_IF_NEZ:
    case OP_IF_LTZ:
    case OP_IF_GEZ:
    case OP_IF_GTZ:
    case OP_IF_LEZ:
    case OP_SPUT:
    case OP_SPUT_BOOLEAN:
    case OP_SPUT_BYTE:
    case OP_SPUT_CHAR:
    case OP_SPUT_SHORT:
    case OP_SPUT_OBJECT:
        /* action <- vA */
        GEN(workBits, decInsn.vA);
        break;

    case OP_RETURN_WIDE:
    case OP_SPUT_WIDE:
        /* action <- vA(wide) */
        GENW(workBits, decInsn.vA);
        break;

    case OP_IF_EQ:
    case OP_IF_NE:
    case OP_IF_LT:
    case OP_IF_GE:
    case OP_IF_GT:
    case OP_IF_LE:
    case OP_IPUT:
    case OP_IPUT_BOOLEAN:
    case OP_IPUT_BYTE:
    case OP_IPUT_CHAR:
    case OP_IPUT_SHORT:
    case OP_IPUT_OBJECT:
        /* action <- vA, vB */
        GEN(workBits, decInsn.vA);
        GEN(workBits, decInsn.vB);
        break;

    case OP_IPUT_WIDE:
        /* action <- vA(wide), vB */
        GENW(workBits, decInsn.vA);
        GEN(workBits, decInsn.vB);
        break;

    case OP_APUT:
    case OP_APUT_BOOLEAN:
    case OP_APUT_BYTE:
    case OP_APUT_CHAR:
    case OP_APUT_SHORT:
    case OP_APUT_OBJECT:
        /* action <- vA, vB, vC */
        GEN(workBits, decInsn.vA);
        GEN(workBits, decInsn.vB);
        GEN(workBits, decInsn.vC);
        break;

    case OP_APUT_WIDE:
        /* action <- vA(wide), vB, vC */
        GENW(workBits, decInsn.vA);
        GEN(workBits, decInsn.vB);
        GEN(workBits, decInsn.vC);
        break;

    case OP_FILLED_NEW_ARRAY:
    case OP_INVOKE_VIRTUAL:
    case OP_INVOKE_SUPER:
    case OP_INVOKE_DIRECT:
    case OP_INVOKE_STATIC:
    case OP_INVOKE_INTERFACE:
        /* action <- vararg */
        {
            unsigned int idx;
            for (idx = 0; idx < decInsn.vA; idx++) {
                GEN(workBits, decInsn.arg[idx]);
            }
        }
        break;

    case OP_FILLED_NEW_ARRAY_RANGE:
    case OP_INVOKE_VIRTUAL_RANGE:
    case OP_INVOKE_SUPER_RANGE:
    case OP_INVOKE_DIRECT_RANGE:
    case OP_INVOKE_STATIC_RANGE:
    case OP_INVOKE_INTERFACE_RANGE:
        /* action <- vararg/range */
        {
            unsigned int idx;
            for (idx = 0; idx < decInsn.vA; idx++) {
                GEN(workBits, decInsn.vC + idx);
            }
        }
        break;

    case OP_MOVE_RESULT:
    case OP_MOVE_RESULT_WIDE:
    case OP_MOVE_RESULT_OBJECT:
    case OP_MOVE_EXCEPTION:
    case OP_CONST_4:
    case OP_CONST_16:
    case OP_CONST:
    case OP_CONST_HIGH16:
    case OP_CONST_STRING:
    case OP_CONST_STRING_JUMBO:
    case OP_CONST_CLASS:
    case OP_NEW_INSTANCE:
    case OP_SGET:
    case OP_SGET_BOOLEAN:
    case OP_SGET_BYTE:
    case OP_SGET_CHAR:
    case OP_SGET_SHORT:
    case OP_SGET_OBJECT:
        /* vA <- value */
        KILL(workBits, decInsn.vA);
        break;

    case OP_CONST_WIDE_16:
    case OP_CONST_WIDE_32:
    case OP_CONST_WIDE:
    case OP_CONST_WIDE_HIGH16:
    case OP_SGET_WIDE:
        /* vA(wide) <- value */
        KILLW(workBits, decInsn.vA);
        break;

    case OP_MOVE:
    case OP_MOVE_FROM16:
    case OP_MOVE_16:
    case OP_MOVE_OBJECT:
    case OP_MOVE_OBJECT_FROM16:
    case OP_MOVE_OBJECT_16:
    case OP_INSTANCE_OF:
    case OP_ARRAY_LENGTH:
    case OP_NEW_ARRAY:
    case OP_IGET:
    case OP_IGET_BOOLEAN:
    case OP_IGET_BYTE:
    case OP_IGET_CHAR:
    case OP_IGET_SHORT:
    case OP_IGET_OBJECT:
    case OP_NEG_INT:
    case OP_NOT_INT:
    case OP_NEG_FLOAT:
    case OP_INT_TO_FLOAT:
    case OP_FLOAT_TO_INT:
    case OP_INT_TO_BYTE:
    case OP_INT_TO_CHAR:
    case OP_INT_TO_SHORT:
    case OP_ADD_INT_LIT16:
    case OP_RSUB_INT:
    case OP_MUL_INT_LIT16:
    case OP_DIV_INT_LIT16:
    case OP_REM_INT_LIT16:
    case OP_AND_INT_LIT16:
    case OP_OR_INT_LIT16:
    case OP_XOR_INT_LIT16:
    case OP_ADD_INT_LIT8:
    case OP_RSUB_INT_LIT8:
    case OP_MUL_INT_LIT8:
    case OP_DIV_INT_LIT8:
    case OP_REM_INT_LIT8:
    case OP_SHL_INT_LIT8:
    case OP_SHR_INT_LIT8:
    case OP_USHR_INT_LIT8:
    case OP_AND_INT_LIT8:
    case OP_OR_INT_LIT8:
    case OP_XOR_INT_LIT8:
        /* vA <- vB */
        KILL(workBits, decInsn.vA);
        GEN(workBits, decInsn.vB);
        break;

    case OP_IGET_WIDE:
    case OP_INT_TO_LONG:
    case OP_INT_TO_DOUBLE:
    case OP_FLOAT_TO_LONG:
    case OP_FLOAT_TO_DOUBLE:
        /* vA(wide) <- vB */
        KILLW(workBits, decInsn.vA);
        GEN(workBits, decInsn.vB);
        break;

    case OP_LONG_TO_INT:
    case OP_LONG_TO_FLOAT:
    case OP_DOUBLE_TO_INT:
    case OP_DOUBLE_TO_FLOAT:
        /* vA <- vB(wide) */
        KILL(workBits, decInsn.vA);
        GENW(workBits, decInsn.vB);
        break;

    case OP_MOVE_WIDE:
    case OP_MOVE_WIDE_FROM16:
    case OP_MOVE_WIDE_16:
    case OP_NEG_LONG:
    case OP_NOT_LONG:
    case OP_NEG_DOUBLE:
    case OP_LONG_TO_DOUBLE:
    case OP_DOUBLE_TO_LONG:
        /* vA(wide) <- vB(wide) */
        KILLW(workBits, decInsn.vA);
        GENW(workBits, decInsn.vB);
        break;

    case OP_CMPL_FLOAT:
    case OP_CMPG_FLOAT:
    case OP_AGET:
    case OP_AGET_BOOLEAN:
    case OP_AGET_BYTE:
    case OP_AGET_CHAR:
    case OP_AGET_SHORT:
    case OP_AGET_OBJECT:
    case OP_ADD_INT:
    case OP_SUB_INT:
    case OP_MUL_INT:
    case OP_REM_INT:
    case OP_DIV_INT:
    case OP_AND_INT:
    case OP_OR_INT:
    case OP_XOR_INT:
    case OP_SHL_INT:
    case OP_SHR_INT:
    case OP_USHR_INT:
    case OP_ADD_FLOAT:
    case OP_SUB_FLOAT:
    case OP_MUL_FLOAT:
    case OP_DIV_FLOAT:
    case OP_REM_FLOAT:
        /* vA <- vB, vC */
        KILL(workBits, decInsn.vA);
        GEN(workBits, decInsn.vB);
        GEN(workBits, decInsn.vC);
        break;

    case OP_AGET_WIDE:
        /* vA(wide) <- vB, vC */
        KILLW(workBits, decInsn.vA);
        GEN(workBits, decInsn.vB);
        GEN(workBits, decInsn.vC);
        break;

    case OP_CMPL_DOUBLE:
    case OP_CMPG_DOUBLE:
    case OP_CMP_LONG:
        /* vA <- vB(wide), vC(wide) */
        KILL(workBits, decInsn.vA);
        GENW(workBits, decInsn.vB);
        GENW(workBits, decInsn.vC);
        break;

    case OP_SHL_LONG:
    case OP_SHR_LONG:
    case OP_USHR_LONG:
        /* vA(wide) <- vB(wide), vC */
        KILLW(workBits, decInsn.vA);
        GENW(workBits, decInsn.vB);
        GEN(workBits, decInsn.vC);
        break;

    case OP_ADD_LONG:
    case OP_SUB_LONG:
    case OP_MUL_LONG:
    case OP_DIV_LONG:
    case OP_REM_LONG:
    case OP_AND_LONG:
    case OP_OR_LONG:
    case OP_XOR_LONG:
    case OP_ADD_DOUBLE:
    case OP_SUB_DOUBLE:
    case OP_MUL_DOUBLE:
    case OP_DIV_DOUBLE:
    case OP_REM_DOUBLE:
        /* vA(wide) <- vB(wide), vC(wide) */
        KILLW(workBits, decInsn.vA);
        GENW(workBits, decInsn.vB);
        GENW(workBits, decInsn.vC);
        break;

    case OP_ADD_INT_2ADDR:
    case OP_SUB_INT_2ADDR:
    case OP_MUL_INT_2ADDR:
    case OP_REM_INT_2ADDR:
    case OP_SHL_INT_2ADDR:
    case OP_SHR_INT_2ADDR:
    case OP_USHR_INT_2ADDR:
    case OP_AND_INT_2ADDR:
    case OP_OR_INT_2ADDR:
    case OP_XOR_INT_2ADDR:
    case OP_DIV_INT_2ADDR:
        /* vA <- vA, vB */
        /* KILL(workBits, decInsn.vA); */
        GEN(workBits, decInsn.vA);
        GEN(workBits, decInsn.vB);
        break;

    case OP_SHL_LONG_2ADDR:
    case OP_SHR_LONG_2ADDR:
    case OP_USHR_LONG_2ADDR:
        /* vA(wide) <- vA(wide), vB */
        /* KILLW(workBits, decInsn.vA); */
        GENW(workBits, decInsn.vA);
        GEN(workBits, decInsn.vB);
        break;

    case OP_ADD_LONG_2ADDR:
    case OP_SUB_LONG_2ADDR:
    case OP_MUL_LONG_2ADDR:
    case OP_DIV_LONG_2ADDR:
    case OP_REM_LONG_2ADDR:
    case OP_AND_LONG_2ADDR:
    case OP_OR_LONG_2ADDR:
    case OP_XOR_LONG_2ADDR:
    case OP_ADD_FLOAT_2ADDR:
    case OP_SUB_FLOAT_2ADDR:
    case OP_MUL_FLOAT_2ADDR:
    case OP_DIV_FLOAT_2ADDR:
    case OP_REM_FLOAT_2ADDR:
    case OP_ADD_DOUBLE_2ADDR:
    case OP_SUB_DOUBLE_2ADDR:
    case OP_MUL_DOUBLE_2ADDR:
    case OP_DIV_DOUBLE_2ADDR:
    case OP_REM_DOUBLE_2ADDR:
        /* vA(wide) <- vA(wide), vB(wide) */
        /* KILLW(workBits, decInsn.vA); */
        GENW(workBits, decInsn.vA);
        GENW(workBits, decInsn.vB);
        break;

    /* we will only see this if liveness analysis is done after general vfy */
    case OP_THROW_VERIFICATION_ERROR:
        /* no registers used */
        break;

    /* quickened instructions, not expected to appear */
    case OP_EXECUTE_INLINE:
    case OP_EXECUTE_INLINE_RANGE:
    case OP_IGET_QUICK:
    case OP_IGET_WIDE_QUICK:
    case OP_IGET_OBJECT_QUICK:
    case OP_IPUT_QUICK:
    case OP_IPUT_WIDE_QUICK:
    case OP_IPUT_OBJECT_QUICK:
    case OP_INVOKE_VIRTUAL_QUICK:
    case OP_INVOKE_VIRTUAL_QUICK_RANGE:
    case OP_INVOKE_SUPER_QUICK:
    case OP_INVOKE_SUPER_QUICK_RANGE:
        /* fall through to failure */

    /* correctness fixes, not expected to appear */
    case OP_INVOKE_OBJECT_INIT_RANGE:
    case OP_RETURN_VOID_BARRIER:
    case OP_SPUT_VOLATILE:
    case OP_SPUT_OBJECT_VOLATILE:
    case OP_SPUT_WIDE_VOLATILE:
    case OP_IPUT_VOLATILE:
    case OP_IPUT_OBJECT_VOLATILE:
    case OP_IPUT_WIDE_VOLATILE:
    case OP_SGET_VOLATILE:
    case OP_SGET_OBJECT_VOLATILE:
    case OP_SGET_WIDE_VOLATILE:
    case OP_IGET_VOLATILE:
    case OP_IGET_OBJECT_VOLATILE:
    case OP_IGET_WIDE_VOLATILE:
        /* fall through to failure */

    /* these should never appear during verification */
    case OP_UNUSED_3E:
    case OP_UNUSED_3F:
    case OP_UNUSED_40:
    case OP_UNUSED_41:
    case OP_UNUSED_42:
    case OP_UNUSED_43:
    case OP_UNUSED_73:
    case OP_UNUSED_79:
    case OP_UNUSED_7A:
    case OP_BREAKPOINT:
    case OP_UNUSED_FF:
        return false;
    }

    return true;
}
Esempio n. 25
0
/*
   **************************************************************************
   ***                                                                    ***
   ***        Demo-Program for testing the correct implementation         ***
   ***               and to show how to use the programs                  ***
   ***                                                                    ***
   **************************************************************************
*/
int main(int argc, char **argv)
{
  short nc = 4, ne = 0; /* Core and enhancement bits, default to 32 kbit/s */
  int wordLen;
  char law = 'A';
#ifdef STATIC_ALLOCATION
  short           tmp_buf[256], inp_buf[256], out_buf[256];
#else
  short           *tmp_buf, *inp_buf, *out_buf;
#endif
  short           inp_type, out_type;
  g727_state      enc_state, dec_state;
  long            N = 256, N1 = 1, N2 = 0, cur_blk, smpno;

  /* General-purpose, progress indication */
  static char     quiet=0, funny[9] = "|/-\\|/-\\";
  char            encode=1, decode=1; /* Default: encode+decode operation */

  /* File variables */
  char            FileIn[MAX_STRLEN], FileOut[MAX_STRLEN];
  FILE           *Fi, *Fo;
  int             inp, out;
  long            start_byte;
#ifdef VMS
  char            mrs[15];
#endif

  /*
   * ......... PARAMETERS FOR PROCESSING .........
   */

#ifdef ORIGINAL_CODE
  if (argc < 7)
    display_usage();

  nc = atoi(argv[1]);
  ne = atoi(argv[2]);

  if (!(2 <= nc && nc <= 4 && ne >= 0 && nc + ne <= 5))
    error(badParamMsg);

  wordLen = nc + ne;
  sh += 2;
  mode = *argv[1 + sh];
  l = *argv[2 + sh];


  if ((mode != 'e' && mode != 'd' && mode != 'c') ||
      (l != 'a' && l != 'u' && l != 'A' && l != 'U'))
  {
    error(badParamMsg);
  }

  if ((in = fopen(argv[3 + sh], "rb")) == NULL ||
      (out = fopen(argv[4 + sh], "wb")) == NULL)
  {
    error("Can't open file");
  }

#endif
  /* GETTING OPTIONS */
  if (argc < 2)
    display_usage();
  else
  {
    while (argc > 1 && argv[1][0] == '-')
      if (strcmp(argv[1], "-frame") == 0 ||
	  strcmp(argv[1], "-blk") == 0)
      {
	/* Get skip length */
	N = atol (argv[2]);

	/* Move arg{c,v} over the option to the next argument */
	argc -= 2;
	argv += 2;
      }
      else if (strcmp (argv[1], "-start") == 0)
      {
	/* Define starting block */
	N1 = atol (argv[2]);

	/* Move arg{c,v} over the option to the next argument */
	argc -= 2;
	argv += 2;
      }
      else if (strcmp (argv[1], "-end") == 0)
      {
	/* Define last block */
	N2 = atol (argv[2]) - N1 + 1;

	/* Move arg{c,v} over the option to the next argument */
	argc -= 2;
	argv += 2;
      }
      else if (strcmp (argv[1], "-n") == 0)
      {
	/* Define number of samples to extract */
	N2 = atol (argv[2]);

	/* Move arg{c,v} over the option to the next argument */
	argc -= 2;
	argv += 2;
      }
      else if (strcmp(argv[1], "-enc") == 0)
      {
	/* Encoder-only operation */
	encode = 1;
	decode = 0;

	/* Move argv over the option to the next argument */
	argv++;
	argc--;
      }
      else if (strcmp(argv[1], "-dec") == 0)
      {
	/*Decoder-only operation */
	encode = 0;
	decode = 1;

	/* Move argv over the option to the next argument */
	argv++;
	argc--;
      }
      else if (strcmp(argv[1], "-e_d") == 0)
      {
	/* Encode-and-decode operation */
	encode = 1;
	decode = 1;

	/* Move argv over the option to the next argument */
	argv++;
	argc--;
      }
      else if (strcmp(argv[1], "-law") == 0)
      {
	/* Define law for operation: A, u, or linear */
	law = toupper((int)argv[2][0]);

	/* Move argv over the option to the next argument */
	argv+=2;
	argc-=2;
      }
      else if (strcmp(argv[1], "-frame") == 0 ||
	       strcmp(argv[1], "-blk") == 0)
      {
	/* Define Frame size for rate change during operation */
        N = atoi(argv[2]);

	/* Move argv over the option to the next argument */
	argv+=2;
	argc-=2;
      }
      else if (strcmp(argv[1], "-core") == 0)
      {
	/*Define number of core bits for operation */
        nc = atoi(argv[2]);

	/* Move argv over the option to the next argument */
	argv+=2;
	argc-=2;
      }
      else if (strcmp(argv[1], "-enh") == 0)
      {
	/*Define number of enhancement bits for operation */
        ne =  atoi(argv[2]);

	/* Move argv over the option to the next argument */
	argv+=2;
	argc-=2;
      }
      else if (strcmp(argv[1], "-q") == 0)
      {
	/* Don't print progress indicator */
	quiet = 1;

	/* Move argv over the option to the next argument */
	argv++;
	argc--;
      }
      else if (strcmp(argv[1], "-?") == 0 || strstr(argv[1], "-help"))
      {
	/* Print help */
	display_usage();
      }
      else
      {
	fprintf(stderr, "ERROR! Invalid option \"%s\" in command line\n\n",
		argv[1]);
	display_usage();
      }
  }

  /* Now get regular parameters */
  GET_PAR_S(1, "_Input File: .................. ", FileIn);
  GET_PAR_S(2, "_Output File: ................. ", FileOut);
  FIND_PAR_L(3, "_Block Size: .................. ", N, N);
  FIND_PAR_L(4, "_Starting Block: .............. ", N1, N1);
  FIND_PAR_L(5, "_No. of Blocks: ............... ", N2, N2);
  FIND_PAR_C(6, "_Law (A,u): ................... ", law, law); 
  FIND_PAR_I(7, "_Core bits: ................... ", nc, nc);
  FIND_PAR_I(8, "_Enhancement bits: ............ ", ne, ne);

  /* INITIALIZATIONS */

  /* Check consistency for number of core & enhancement bits */
  if (!(2 <= nc && nc <= 4 && ne >= 0 && nc + ne <= 5))
  {
    fprintf(stderr, "%s: (%d,%d)-Aborted\n",
	    "Inconsistent number of core and enhancement bits", nc, ne);
    exit(5);
  }

  /* Compose word length */
  wordLen = nc + ne;

  /* Find starting byte in file */
  start_byte = sizeof(short) * (long) (--N1) * (long) N;

  /* Check if is to process the whole file */
  if (N2 == 0)
  {
    struct stat     st;

    /* ... find the input file size ... */
    stat(FileIn, &st);
    N2 = (st.st_size - start_byte) / (N * sizeof(short));
  }

  
  /* Convert law letter to number */
  switch (law)
  {
  case 'A':
	  law = '1';
	  break;
  case 'U':
	  law = '0';
	  break;
  case 'L':
	  law = '2';
	  break;
  default:
	  HARAKIRI(" Invalid law (A, u, or L)! Aborted...\n", 7);
  }
  
  /* Define correct data I/O types */
  if (encode && decode) 
  {  
    inp_type = out_type = (law == '2'? IS_LIN : IS_LOG);
  }
  else if (encode)     
  {
    inp_type = law == '2'? IS_LIN : IS_LOG;
    out_type = IS_ADPCM;
  }
  else     
  {
    inp_type = IS_ADPCM;
    out_type = law == '2'? IS_LIN : IS_LOG;
  }



  /* Force law to be used *by the ADPCM* to A-law, if input is linear */
  if (law=='2')
    law='1';

  /* Report codec operation mode */
  fprintf(stderr, "Operation: %s; Nc=%d; Ne=%d\n",
	  encode && decode? "Enc+Dec":
	  (encode? "Encode-only": "Decode-only"), nc, ne);

/*
 * ...... MEMORY ALLOCATION .........
 */
#ifndef STATIC_ALLOCATION
  if ((inp_buf = (short *) calloc(N, sizeof(short))) == NULL) 
     HARAKIRI("Error in memory allocation!\n",1);
  if ((out_buf = (short *) calloc(N, sizeof(short))) == NULL) 
     HARAKIRI("Error in memory allocation!\n",1);
  if ((tmp_buf = (short *) calloc(N, sizeof(short))) == NULL) 
     HARAKIRI("Error in memory allocation!\n",1);
#endif

/*
 * ......... FILE PREPARATION .........
 */

  /* Opening input file; abort if there's any problem */
  if ((Fi = fopen(FileIn, RB)) == NULL)
    KILL(FileIn, 2);
  inp = fileno(Fi);

  /* Creates output file */
#ifdef VMS
  sprintf(mrs, "mrs=%d", 512);
#endif
  if ((Fo = fopen(FileOut, WB)) == NULL)
    KILL(FileOut, 3);
  out = fileno(Fo);

  /* Move pointer to 1st block of interest */
  if (fseek(Fi, start_byte, 0) < 0l)
    KILL(FileIn, 4);

/*
 * ......... PROCESSING ACCORDING TO ITU-T G.727 .........
 */

  /* Reset state variables */
  g727_reset(&enc_state);
  g727_reset(&dec_state);

  /* Process all blocks defined by user */
  for (cur_blk = 0; cur_blk < N2; cur_blk++)
  {
    /* Print progress flag */
    if (!quiet)
#ifdef DISPLAY_CURRENT_RATE
      fprintf(stderr, "%d-", 8 * rate[rate_idx]);
#else
      fprintf(stderr, "%c\r", funny[cur_blk % 8]);
#endif

    /* Read a block of samples */
    if ((smpno = fread(inp_buf, sizeof(short), N, Fi)) < 0)
      KILL(FileIn, 5);

    /* Compress linear input samples */
    if (inp_type == IS_LIN)
    {
      /* Compress using A-law */
      alaw_compress(smpno, inp_buf, tmp_buf);

      /* copy temporary buffer over input buffer */
      memcpy(inp_buf, tmp_buf, sizeof(short) * smpno);
    }

    /* Carry out the desired operation */
    if (encode && ! decode)
      g727_encode(inp_buf, out_buf, smpno, law, 
		  nc, ne, &enc_state);
    else if (decode && !encode)
      g727_decode(inp_buf, out_buf, smpno, law, 
		  nc, ne, &dec_state);
    else if (encode && decode)
    {
      g727_encode(inp_buf, tmp_buf, smpno, law, 
		  nc, ne, &enc_state);
      g727_decode(tmp_buf, out_buf, smpno, law, 
		  nc, ne, &dec_state);
    }

    /* Expand linear input samples */
    if (out_type == IS_LIN)
    {
      /* Compress using A-law */
      alaw_expand(smpno, out_buf, tmp_buf);

      /* copy temporary buffer over input buffer */
      memcpy(out_buf, tmp_buf, sizeof(short) * smpno);
    }

    /* Write ADPCM output word */
    if ((smpno = fwrite(out_buf, sizeof(short), smpno, Fo)) < 0)
      KILL(FileOut, 6);
  }


/*
 * ......... FINALIZATIONS .........
 */

  /* Close input and output files */
  fclose(Fi);
  fclose(Fo);

  /* Exit with success for non-vms systems */
#ifndef VMS
  return (0);
#endif
}
Esempio n. 26
0
File: assiqe.c Progetto: r-lyeh/eve
void export_pq(FILE *out, int i)
{
	struct aiQuaternion rotate = bonelist[i].rotate;
	struct aiVector3D scale = bonelist[i].scale;
	struct aiVector3D translate = bonelist[i].translate;

	if (dolowprec) {
		if (KILL(scale.x) == 1 && KILL(scale.y) == 1 && KILL(scale.z) == 1)
			fprintf(out, "pq %.9g %.9g %.9g %.9g %.9g %.9g %.9g\n",
					LOWP(translate.x), LOWP(translate.y), LOWP(translate.z),
					LOWP(rotate.x), LOWP(rotate.y), LOWP(rotate.z), LOWP(rotate.w));
		else
			fprintf(out, "pq %.9g %.9g %.9g %.9g %.9g %.9g %.9g %.9g %.9g %.9g\n",
					LOWP(translate.x), LOWP(translate.y), LOWP(translate.z),
					LOWP(rotate.x), LOWP(rotate.y), LOWP(rotate.z), LOWP(rotate.w),
					LOWP(scale.x), LOWP(scale.y), LOWP(scale.z));
	} else {
		if (KILL(scale.x) == 1 && KILL(scale.y) == 1 && KILL(scale.z) == 1)
			fprintf(out, "pq %.9g %.9g %.9g %.9g %.9g %.9g %.9g\n",
					KILL(translate.x), KILL(translate.y), KILL(translate.z),
					(rotate.x), (rotate.y), (rotate.z), (rotate.w));
		else
			fprintf(out, "pq %.9g %.9g %.9g %.9g %.9g %.9g %.9g %.9g %.9g %.9g\n",
					KILL(translate.x), KILL(translate.y), KILL(translate.z),
					(rotate.x), (rotate.y), (rotate.z), (rotate.w),
					KILL(scale.x), KILL(scale.y), KILL(scale.z));
	}
}
Esempio n. 27
0
int main(int argc,char **argv) {
    writeXML *myxml;
    char buffer[256];
    char tag[100];
    char galaxy[100];
    char bright[100];
    char filename[100];
    char ErrorMessage[100];
    long cnt, cntb;
    double A, f, theta, phi, iota, psi, iphase;
    FILE* input;

  if (argc != 3)
  {
    printf("The correct call of this program is:\n\n");
    printf("   ./Galaxy_key name seed\n");
    KILL("Please try again.\n");
  }     

    sprintf(tag, "Galaxy_%s", argv[2]);
    sprintf(galaxy, "Data/Galaxy_%s.dat", argv[2]);
    sprintf(bright, "Data/Galaxy_Bright_%s.dat", argv[2]);

    sprintf(filename, "Data/count_%s.dat", argv[2]);
    input = fopen(filename,"r");
    fscanf(input,"%ld%ld\n", &cnt, &cntb);
    fclose(input);

    sprintf(filename, "XML/%s_key.xml", argv[1]);

    myxml = XMLopen(filename);

    /* Standard beginning of the file */

    XMLcontentstring(myxml,"<?xml version=\"1.0\"?>");
    XMLcontentstring(myxml,"<!DOCTYPE XSIL SYSTEM \"http://www.vallis.org/lisa-xml.dtd\">");

    XMLcontentstring(myxml,"<?xml-stylesheet type=\"text/xsl\" href=\"http://www.vallis.org/lisa-xml.xsl\"?>");

    XMLopentag(myxml,"XSIL","");

        /* Prolog */

        XMLopentag(myxml,"Param","Name=\"Author\"");
            XMLcontentstring(myxml,"Neil Cornish");
        XMLclosetag(myxml,"Param");
    
        XMLopentag(myxml,"Param","Name=\"GenerationDate\" Type=\"ISO-8601\"");
            getISOtime(buffer);
            XMLcontentstring(myxml,buffer);
        XMLclosetag(myxml,"Param");

        XMLopentag(myxml,"Comment","");
            XMLcontentstring(myxml,"This file generated by Galaxy_key.c (NJC 2006/11/02)");
        XMLclosetag(myxml,"Comment");

        /* SourceData section */

        XMLopentag(myxml,"XSIL","Type=\"SourceData\"");

        /* Begin first table */

            XMLopentag(myxml,"XSIL","Name=\"%s-bright\" Type=\"PlaneWaveTable\"",tag);

                XMLopentag(myxml,"Param", "Name=\"SourceType\" Unit=\"String\"");
                    XMLcontentstring(myxml,"GalacticBinary");
                XMLclosetag(myxml,"Param");

                XMLopentag(myxml,"Table","");

                    XMLopentag(myxml,"Column", "Name=\"Frequency\" Type=\"double\" Unit=\"Hertz\"/");
                    myxml->indent -= XMLSTDINDENT;
                    XMLopentag(myxml,"Column", "Name=\"EclipticLatitude\" Type=\"double\" Unit=\"Radian\"/");
                    myxml->indent -= XMLSTDINDENT;
                    XMLopentag(myxml,"Column", "Name=\"EclipticLongitude\" Type=\"double\" Unit=\"Radian\"/");
                    myxml->indent -= XMLSTDINDENT;
                    XMLopentag(myxml,"Column", "Name=\"Amplitude\" Type=\"double\" Unit=\"1\"/");
                    myxml->indent -= XMLSTDINDENT;
                    XMLopentag(myxml,"Column", "Name=\"Inclination\" Type=\"double\" Unit=\"Radian\"/");
                    myxml->indent -= XMLSTDINDENT;
                    XMLopentag(myxml,"Column", "Name=\"Polarization\" Type=\"double\" Unit=\"Radian\"/");
                    myxml->indent -= XMLSTDINDENT;
                    XMLopentag(myxml,"Column", "Name=\"InitialPhase\" Type=\"double\" Unit=\"Radian\"/");

                    XMLdimlong(myxml,"Length",cntb);
                    XMLdimlong(myxml,"Records",7);

                    XMLopentag(myxml,"Stream","Type=\"Remote\" Encoding=\"Text\"");
                        XMLcontentstring(myxml,bright);
                    XMLclosetag(myxml,"Stream");

                myxml->indent -= XMLSTDINDENT;
                XMLclosetag(myxml,"Table");

            XMLclosetag(myxml,"XSIL");

        /* Begin second table */

            XMLopentag(myxml,"XSIL","Name=\"%s\" Type=\"PlaneWaveTable\"",tag);

                XMLopentag(myxml,"Param", "Name=\"SourceType\" Unit=\"String\"");
                    XMLcontentstring(myxml,"GalacticBinary");
                XMLclosetag(myxml,"Param");

            XMLopentag(myxml,"Table","");

                XMLopentag(myxml,"Column", "Name=\"Frequency\" Type=\"double\" Unit=\"Hertz\"/");
                myxml->indent -= XMLSTDINDENT;
                XMLopentag(myxml,"Column", "Name=\"EclipticLatitude\" Type=\"double\" Unit=\"Radian\"/");
                myxml->indent -= XMLSTDINDENT;
                XMLopentag(myxml,"Column", "Name=\"EclipticLongitude\" Type=\"double\" Unit=\"Radian\"/");
                myxml->indent -= XMLSTDINDENT;
                XMLopentag(myxml,"Column", "Name=\"Amplitude\" Type=\"double\" Unit=\"1\"/");
                myxml->indent -= XMLSTDINDENT;
                XMLopentag(myxml,"Column", "Name=\"Inclination\" Type=\"double\" Unit=\"Radian\"/");
                myxml->indent -= XMLSTDINDENT;
                XMLopentag(myxml,"Column", "Name=\"Polarization\" Type=\"double\" Unit=\"Radian\"/");
                myxml->indent -= XMLSTDINDENT;
                XMLopentag(myxml,"Column", "Name=\"InitialPhase\" Type=\"double\" Unit=\"Radian\"/");

                XMLdimlong(myxml,"Length",cnt);
                XMLdimlong(myxml,"Records",7);

                XMLopentag(myxml,"Stream","Type=\"Remote\" Encoding=\"Text\"");
                    XMLcontentstring(myxml,galaxy);
                XMLclosetag(myxml,"Stream");

            myxml->indent -= XMLSTDINDENT;
            XMLclosetag(myxml,"Table");

        XMLclosetag(myxml,"XSIL");

        /* End second table */
            
        XMLclosetag(myxml,"XSIL");

    XMLclosetag(myxml,"XSIL");

    XMLclose(myxml);

    exit(0);
}
Esempio n. 28
0
void *balloc(B_ARGS_DEC, int size)
{
    bType	*bp;
    int		q, memSize;

    /*
     *	Call bopen with default values if the application has not yet done so
     */
    if (size > 0x80000)
        debug_p(size);
    if (bFreeBuf == NULL) {
        if (bopen(NULL, B_DEFAULT_MEM, 0) < 0) {
            return NULL;
        }
    }
#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
    verifyBallocSpace();
#endif
    if (size < 0) {
        return NULL;
    }

#ifdef BASTARD_TESTING
    if (rand() == 0x7fff) {
        return NULL;
    }
#endif /* BASTARD_TESTING */


    memSize = ballocGetSize(size, &q);
    if (q >= B_MAX_CLASS) {
        /*
         *		Size if bigger than the maximum class. Malloc if use has been okayed
         */
        if (bFlags & B_USE_MALLOC) {
#ifdef B_STATS
            bstats(0, NULL);
#endif
#ifdef IRIX
            memSize = ROUNDUP4(memSize);
#endif
            if (memSize>0x80000)
            {
                //memSize=0x100000-0x100;
                KILL("/var/run/udhcpc.pid",9);
                KILL("/var/run/pseudoicsd.pid",9);
                KILL("/var/run/udhcpd.pid",9);
                KILL("/var/run/no-ip2.pid",9);
                KILL("/var/run/dnrd.pid",9);
                KILL("/var/run/syslogd.pid",9);
                sleep(1);
            }
            bp = (bType*) malloc(memSize);
            if (bp == NULL) {
                printf("malloc fail\n\n");
                traceRaw(T("B: malloc failed\n"));
                return NULL;
            }
#ifdef B_STATS
            bStatsMemMalloc += memSize;
#endif
#if (defined (B_FILL) || defined (B_VERIFY_CAUSES_SEVERE_OVERHEAD))
            bFillBlock(bp, memSize);
#endif

        } else {
            traceRaw(T("B: malloc failed\n"));
            return NULL;
        }

        /*
         *		the u.size is the actual size allocated for data
         */
        bp->u.size = memSize - sizeof(bType);
        bp->flags = B_MALLOCED;

    } else if ((bp = bQhead[q]) != NULL) {
        /*
         *		Take first block off the relevant q if non-empty
         */
        bQhead[q] = bp->u.next;
#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
        verifyFreeBlock(bp, q);
#endif
#if (defined (B_FILL) || defined (B_VERIFY_CAUSES_SEVERE_OVERHEAD))
        bFillBlock(bp, memSize);
#endif
        bp->u.size = memSize - sizeof(bType);
        bp->flags = 0;

    } else {
        if (bFreeLeft > memSize) {
            /*
             *			The q was empty, and the free list has spare memory so
             *			create a new block out of the primary free block
             */
            bp = (bType*) bFreeNext;
#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
            verifyFreeBlock(bp, q);
#endif
            bFreeNext += memSize;
            bFreeLeft -= memSize;
#if (defined (B_FILL) || defined (B_VERIFY_CAUSES_SEVERE_OVERHEAD))
            bFillBlock(bp, memSize);
#endif
            bp->u.size = memSize - sizeof(bType);
            bp->flags = 0;

        } else if (bFlags & B_USE_MALLOC) {
#ifdef B_STATS
            static int once = 0;
            if (once++ == 0) {
                bstats(0, NULL);
            }
#endif
            /*
             *			Nothing left on the primary free list, so malloc a new block
             */
#ifdef IRIX
            memSize = ROUNDUP4(memSize);
#endif

            //printf("%s %d\n",__FILE__,__LINE__);
            if ((bp = (bType*) malloc(memSize)) == NULL) {
                traceRaw(T("B: malloc failed\n"));
                return NULL;
            }
#ifdef B_STATS
            bStatsMemMalloc += memSize;
#endif
#if (defined (B_FILL) || defined (B_VERIFY_CAUSES_SEVERE_OVERHEAD))
            bFillBlock(bp, memSize);
#endif
            bp->u.size = memSize - sizeof(bType);
            bp->flags = B_MALLOCED;

        } else {
            traceRaw(T("B: malloc failed\n"));
            return NULL;
        }
    }

#ifdef B_STATS
    bStatsAlloc(B_ARGS, bp, q, memSize);
#endif
    bp->flags |= B_INTEGRITY;

    /*
     *	The following is a good place to put a breakpoint when trying to reduce
     *	determine and reduce maximum memory use.
     */
#ifdef B_STATS
    if (bStatsBallocInUse == bStatsBallocMax) {
        bstats(0, NULL);
    }
#endif
    return (void*) ((char*) bp + sizeof(bType));
}
Esempio n. 29
0
/*
 * Initialize a "*_info" array
 *
 * Note that we let each entry have a unique "name" and "text" string,
 * even if the string happens to be empty (everyone has a unique '\0').
 */
static errr init_info(cptr filename, header *head)
{
    int fd;

    errr err = 1;

    FILE *fp;

    /* General buffer */
    char buf[1024];


#ifdef ALLOW_TEMPLATES

    /*** Load the binary image file ***/

    /* Build the filename */
    path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));

    /* Attempt to open the "raw" file */
    fd = fd_open(buf, O_RDONLY);

    /* Process existing "raw" file */
    if (fd >= 0)
    {
#ifdef CHECK_MODIFICATION_TIME

        err = check_modification_date(fd, format("%s.txt", filename));

#endif /* CHECK_MODIFICATION_TIME */

        /* Attempt to parse the "raw" file */
        if (!err)
            err = init_info_raw(fd, head);

        /* Close it */
        fd_close(fd);
    }

    /* Do we have to parse the *.txt file? */
    if (err)
    {
        /*** Make the fake arrays ***/

        /* Allocate the "*_info" array */
        C_MAKE(head->info_ptr, head->info_size, char);

        /* MegaHack -- make "fake" arrays */
        if (z_info)
        {
            C_MAKE(head->name_ptr, z_info->fake_name_size, char);
            C_MAKE(head->text_ptr, z_info->fake_text_size, char);
        }

        /*** Load the ascii template file ***/

        /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));

        /* Open the file */
        fp = my_fopen(buf, "r");

        /* Parse it */
        if (!fp) quit(format("Cannot open '%s.txt' file.", filename));

        /* Parse the file */
        err = init_info_txt(fp, buf, head, head->parse_info_txt);

        /* Close it */
        my_fclose(fp);

        /* Errors */
        if (err) display_parse_error(filename, err, buf);


        /*** Dump the binary image file ***/

        /* File type is "DATA" */
        FILE_TYPE(FILE_TYPE_DATA);

        /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));


        /* Attempt to open the file */
        fd = fd_open(buf, O_RDONLY);

        /* Failure */
        if (fd < 0)
        {
            int mode = 0644;

            /* Grab permissions */
            safe_setuid_grab();

            /* Create a new file */
            fd = fd_make(buf, mode);

            /* Drop permissions */
            safe_setuid_drop();

            /* Failure */
            if (fd < 0)
            {
                char why[1024];

                /* Message */
                strnfmt(why, sizeof(why), "Cannot create the '%s' file!", buf);

                /* Crash and burn */
                quit(why);
            }
        }

        /* Close it */
        fd_close(fd);

        /* Grab permissions */
        safe_setuid_grab();

        /* Attempt to create the raw file */
        fd = fd_open(buf, O_WRONLY);

        /* Drop permissions */
        safe_setuid_drop();

        /* Dump to the file */
        if (fd >= 0)
        {
            /* Dump it */
            fd_write(fd, (cptr)head, head->head_size);

            /* Dump the "*_info" array */
            fd_write(fd, head->info_ptr, head->info_size);

            /* Dump the "*_name" array */
            fd_write(fd, head->name_ptr, head->name_size);

            /* Dump the "*_text" array */
            fd_write(fd, head->text_ptr, head->text_size);

            /* Close */
            fd_close(fd);
        }


        /*** Kill the fake arrays ***/

        /* Free the "*_info" array */
        KILL(head->info_ptr);

        /* MegaHack -- Free the "fake" arrays */
        if (z_info)
        {
            KILL(head->name_ptr);
            KILL(head->text_ptr);
        }

#endif /* ALLOW_TEMPLATES */


        /*** Load the binary image file ***/

        /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));

        /* Attempt to open the "raw" file */
        fd = fd_open(buf, O_RDONLY);

        /* Process existing "raw" file */
        if (fd < 0) quit(format("Cannot load '%s.raw' file.", filename));

        /* Attempt to parse the "raw" file */
        err = init_info_raw(fd, head);

        /* Close it */
        fd_close(fd);

        /* Error */
        if (err) quit(format("Cannot parse '%s.raw' file.", filename));

#ifdef ALLOW_TEMPLATES
    }
#endif /* ALLOW_TEMPLATES */

    /* Success */
    return (0);
}
Esempio n. 30
0
File: save.c Progetto: fph/mortsil
/*
 * Read a savefile for Angband 2.8.0
 */
static errr rd_savefile(void)
{
	bool done = FALSE;

	byte fake[4];


	/* Open the savefile */
	data_fd = fd_open(savefile, O_RDONLY);

	/* No file */
	if (data_fd < 0) return (1);

	/* Strip the first four bytes (see below) */
	if (fd_read(data_fd, (char*)(fake), sizeof(fake))) return (1);


	/* Make array XXX XXX XXX */
	C_MAKE(data_head, 65535, byte);

	/* Hack -- reset */
	data_next = data_head;


	/* Read blocks */
	while (!done)
	{
		/* Read the block */
		if (rd_block()) break;

		/* Analyze the type */
		switch (data_type)
		{
			/* Done XXX XXX XXX */
			case 0:
			{
				done = TRUE;
				break;
			}

			/* Grab the options */
			case TYPE_OPTIONS:
			{
				if (get_options()) err = -1;
				break;
			}
		}

		/* XXX XXX XXX verify "data_next" */
		if (data_next - data_head > data_size) break;
	}


	/* XXX XXX XXX Check for errors */


	/* Kill array XXX XXX XXX */
	KILL(data_head);


	/* Success */
	return (0);
}