Example #1
0
AS3_Val doUnAes(void *data, AS3_Val args)
{
	AS3_Val input = NULL;
    unsigned int in_len;
	char * ar;
	AS3_ArrayValue(args, "AS3ValType, IntType", &input, &in_len);
	ar = (char *)malloc(in_len);
	
	AS3_ByteArray_readBytes((void*)ar, input, in_len);
		
	char * aesData;
	int out_len = 0;
	char * keyStr = "kael";
	
	//use AES to Decrypt the bytes	
	aesData = DES_Decrypt(ar, keyStr, in_len, &out_len );

	//make a new as3 byteArray var
	AS3_Val baNS = AS3_String("flash.utils");
	AS3_Val baClass = AS3_NSGetS(baNS, "ByteArray");
	AS3_Val emptyParams = AS3_Array("");
	AS3_Val byteArray2 = AS3_New(baClass, emptyParams);
	
	AS3_ByteArray_writeBytes(byteArray2, aesData, out_len);
	return byteArray2;
}
static void encodeForFlash(void * self, AS3_Val args)
{
	AS3_Val progress;
	AS3_Val src, dest;
	int len, srcLen, remainingBytes, yieldTicks;
	short raw_data[BLOCKL_MAX], encoded_data[ILBCNOOFWORDS_MAX];

	AS3_ArrayValue(args, "AS3ValType, AS3ValType, AS3ValType, IntType, IntType", &progress, &src, &dest, &srcLen, &yieldTicks);

	iLBC_Enc_Inst_t Enc_Inst;
	initEncode(&Enc_Inst, 30);
	remainingBytes = srcLen;
	int i = 0;
	resetPositionByteArray(src);
	while (remainingBytes > 0){
		remainingBytes -= AS3_ByteArray_readBytes(raw_data, src, Enc_Inst.blockl * sizeof(short));
		len = encode(&Enc_Inst, encoded_data, raw_data);
		AS3_ByteArray_writeBytes(dest, encoded_data, len);
		if(i % yieldTicks == 0){
			AS3_CallT(progress, NULL, "IntType", (int)((1 - ((float)remainingBytes / srcLen)) * 100));
			flyield();//yield to main process
		}
		i++;
	}

	resetPositionByteArray(src);
	resetPositionByteArray(dest);
	// Don't remove progess 100 call here, else complete won't be called!
	AS3_CallT(progress, NULL, "IntType", 100);
}
static void decodeForFlash(void * self, AS3_Val args)
{
	AS3_Val progress;
	AS3_Val src, dest;
	int len, srcLen, yieldTicks;
	short encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX];

	AS3_ArrayValue(args, "AS3ValType, AS3ValType, AS3ValType, IntType, IntType", &progress, &src, &dest, &srcLen, &yieldTicks);

	iLBC_Dec_Inst_t Dec_Inst;
	initDecode(&Dec_Inst, 30, 1);//30ms mode
	
	int i = 0;
	int loops = srcLen / Dec_Inst.no_of_bytes;
	resetPositionByteArray(src);
	while(AS3_ByteArray_readBytes(encoded_data, src, Dec_Inst.no_of_bytes) == Dec_Inst.no_of_bytes){
		len = decode(&Dec_Inst, decoded_data, encoded_data, 1);//1 for no packet loss
		AS3_ByteArray_writeBytes(dest, decoded_data, len * sizeof(short));
		/* write output file */
		if(i % yieldTicks == 0){
			AS3_CallT(progress, NULL, "IntType", (int)((float)i / loops * 100));
			flyield();//yield to main process
		}
		i++;
	}

	resetPositionByteArray(src);
	resetPositionByteArray(dest);
	// Don't remove progess 100 call here, else complete won't be called!
	AS3_CallT(progress, NULL, "IntType", 100);
}
Example #4
0
/**
 * Writes a sample out to an as3 byte array.
 * Used for final output to a sample handler.
 */
static AS3_Val writeBytes(void *self, AS3_Val args) 
{
	int bufferPosition; int channels; int frames;
	float *buffer;
	AS3_Val dst;
	int len;
	
	AS3_ArrayValue(args, "IntType, AS3ValType, IntType, IntType", &bufferPosition, &dst, &channels, &frames);
	buffer = (float *) bufferPosition;
	len = frames * channels * sizeof(float);
	
	AS3_ByteArray_writeBytes(dst, buffer, len);
	return 0;
} 
/* Сохранение состояния в память */
AS3_Val QSPSaveGameAsData(void *param, AS3_Val args)
{
	int len;
	QSP_BOOL isRefresh;
	AS3_Val data;
	QSP_CHAR *buf;
	AS3_ArrayValue(args, "AS3ValType, IntType", &data, &isRefresh);
	if (qspIsExitOnError && qspErrorNum) return AS3_False();
	qspPrepareExecution();
	if (qspIsDisableCodeExec) return AS3_False();
	if (!(len = qspSaveGameStatusToString(&buf))) return AS3_False();
	AS3_ByteArray_seek(data, 0, SEEK_SET);
	AS3_ByteArray_writeBytes(data, buf, len * sizeof(QSP_CHAR));
	free(buf);
	if (isRefresh) qspCallRefreshInt(QSP_FALSE);
	return AS3_True();
}
Example #6
0
AS3_Val doDecode(void* data,AS3_Val args)
{
	AS3_Val input = NULL;
	int in_len;
	char * ar;
	AS3_ArrayValue(args,"AS3ValType,IntType",&input,&in_len);
	ar = (char*)malloc(in_len);

	AS3_ByteArray_readBytes((void*)ar,input,in_len);

	char * decryptData;
	char * key="kael";
	decryptData = dofileEx(ar, key, in_len);
	//make a new as3 byteArray var
	AS3_Val baNS = AS3_String("flash.utils");
	AS3_Val baClass = AS3_NSGetS(baNS, "ByteArray");
	AS3_Val emptyParams = AS3_Array("");
	AS3_Val byteArray2 = AS3_New(baClass, emptyParams);
	
	AS3_ByteArray_writeBytes(byteArray2, decryptData, in_len);
	return byteArray2;
}
Example #7
0
/**
 * Writes a sample out to an as3 byte array in wav file format.
 * Writes as fixed point 16 bit.
 */
static AS3_Val writeWavBytes(void *self, AS3_Val args) 
{
	int bufferPosition; int channels; int frames;
	float *buffer;
	AS3_Val dst;
	int count;
	short *wavOut;
	int framesToWrite; int theseFramesToWrite;
	
	AS3_ArrayValue(args, "IntType, AS3ValType, IntType, IntType", &bufferPosition, &dst, &channels, &frames);
	buffer = (float *) bufferPosition;
	
	framesToWrite = frames * channels;
	
	// Convert and output wav bytes in 16k chunks
	// Convert each buffer into scratch memory, and then writeBytes 
	
	while (framesToWrite > 0) {
		
		theseFramesToWrite = framesToWrite;
		if (theseFramesToWrite > 16384) {
			theseFramesToWrite = 16384;
		}
		framesToWrite -= theseFramesToWrite;
		count = theseFramesToWrite;
		
		wavOut = scratch5; // scratch buffer 5 is 16k of shorts
		while (count--)  {
			*wavOut++ = (short) (*buffer++ * 32768 + 0.5 ); 
		}
		wavOut = scratch5;
	
		AS3_ByteArray_writeBytes(dst, wavOut, theseFramesToWrite * 2 ); // 2 bytes per short
	
	}
	
	return 0;
} 
Example #8
0
AS3_Val call(void* thiz, AS3_Val args)
{
	AS3_Val is;
	AS3_Val os;
	uint8_t* bufIn;
	uint8_t* bufOut;

	int i = 0;
	int j = 0;
	uint32_t color;
	uint32_t* bufDst;

	int w = 0;
	int h = 0;
	int len;
	int type;

	struct
	{
		uint16_t w;
		uint16_t h;
	} size;


	AS3_ArrayValue(args, "AS3ValType,IntType,IntType,AS3ValType", &is, &len, &type, &os);


	for(;;)
	{
		bufIn = malloc(len);
		if(!bufIn)
			break;

		AS3_ByteArray_readBytes(bufIn, is, len);
		bufOut = WebPDecodeRGB(bufIn, len, &w, &h);
		free(bufIn);

		if(!bufOut || w <= 0 || h <= 0)
			break;

		bufDst = (uint32_t*)malloc(w * h * 4);
		if(!bufDst)
			break;

		len = w * h * 3;
		while(i < len)
		{
			color = *(uint32_t*)(bufOut + i);
			color = (color << 8) | 0x000000FF;

			bufDst[j++] = color;
			i += 3;
		}

		free(bufOut);

		size.w = w;
		size.h = h;

		AS3_ByteArray_writeBytes(os, &size, sizeof(size));
		AS3_ByteArray_writeBytes(os, bufDst, w * h * 4);

		free(bufDst);
		break;
	}

	return AS3_Undefined();
}
Example #9
0
File: main.c Project: Glideh/jfrec
int writeByteArray(void *cookie, const char *src, int size)
{
	return AS3_ByteArray_writeBytes((AS3_Val)cookie, (char *)src, size);
}