Example #1
0
File: pdf.c Project: db00/reader
//Method exposed to ActionScript
//Takes a String and echos it
static AS3_Val echo(void* self, AS3_Val args)
{
	AS3_Val byteArray;
	AS3_ArrayValue( args, "AS3ValType", &byteArray);
	AS3_Val length = AS3_GetS(byteArray, "length");  

	sztrace("length getted!");
	int len = AS3_IntValue(length);
	//if(len>0) return length;

	char *data=NULL;
	data=malloc(len);
	memset(data,0,len);
	int fileLen = AS3_ByteArray_readBytes(data,byteArray, len);
	char *out= NULL;
	out = malloc(fileLen);
	memset(out,0,fileLen);



	ByteArray * bytearray = ByteArray_new(fileLen);
	bytearray->data = data;

	PdfFile_free(PdfFile_parse(bytearray,out));
	ByteArray_free(bytearray);

	return AS3_String(out);
}
Example #2
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);
}
static AS3_Val initparam(void* self, AS3_Val args) {
	AS3_Val	tmp = AS3_Undefined();
    int il, len;

    for (il=0; il < sizeof(models)/sizeof(LAYER); ++il) {
        tmp = AS3_Get(args, AS3_Int(2*il));
        len = AS3_IntValue(AS3_GetS(tmp, "length"));
        models[il].w = (float*) malloc(len);
        AS3_ByteArray_readBytes(models[il].w, tmp, len);

        tmp = AS3_Get(args, AS3_Int(2*il+1));
        len = AS3_IntValue(AS3_GetS(tmp, "length"));
        models[il].b = (float*) malloc(len);
        AS3_ByteArray_readBytes(models[il].b, tmp, len);
    }
    
    data = (float*) malloc(BUF_SIZE);
    o = (float*) malloc(BUF_SIZE);
        
	return AS3_Int(0);
}
Example #6
0
static AS3_Val readWavBytes(void *self, AS3_Val args) 
{
	int bufferPosition; int channels; int frames; int bitDepth;
	float *buffer;
	AS3_Val wavBytes;
	int count; int framesToRead; int theseFramesToRead;
	short *wavIn;
	float divisor;
	
	// It's way slow to call writeBytes for every frame
	// We need to use a scratch buffer and fill it with shorts
	// And then make one call to writeBytes
	
	// AS3 ARGS:  buffer:uint, wavBytes:ByteArray, bitsPerSample:int, channels: int, frames: int
	
	AS3_ArrayValue(args, "IntType, AS3ValType, IntType, IntType, IntType", &bufferPosition, &wavBytes, &bitDepth, &channels, &frames);
	buffer = (float *) bufferPosition;
	framesToRead = frames * channels;
	divisor = 1 / pow(2, bitDepth);
	
	// Divide the wav data into 16k buffers because each call to readBytes is slow
	// Scan each buffer of wav data (shorts) and divide down to floating point
	// Loop until all the data is read
	
	while (framesToRead > 0) {
		
		wavIn = scratch5; // scratch buffer 5 is 16k of shorts
		
		theseFramesToRead = framesToRead;
		if (theseFramesToRead > 16384) {
			theseFramesToRead = 16384;
		}
		framesToRead -= theseFramesToRead;
		
		AS3_ByteArray_readBytes(wavIn, wavBytes, theseFramesToRead * 2 ); // 2 bytes per short
		count = theseFramesToRead;
		while (count--) {
			*buffer++ = (float) (*wavIn++ * divisor);
		}

	}
	
	return 0;
	
}
/* Загрузка состояния из памяти */
AS3_Val QSPOpenSavedGameFromData(void *param, AS3_Val args)
{
	AS3_Val data;
	int dataSize, dataLen;
	QSP_BOOL isRefresh;
	QSP_CHAR *ptr;
	AS3_ArrayValue(args, "AS3ValType, IntType, IntType", &data, &dataSize, &isRefresh);
	if (qspIsExitOnError && qspErrorNum) return AS3_False();
	qspPrepareExecution();
	if (qspIsDisableCodeExec) return AS3_False();
	dataLen = dataSize / sizeof(QSP_CHAR);
	ptr = (QSP_CHAR *)malloc((dataLen + 1) * sizeof(QSP_CHAR));
	AS3_ByteArray_seek(data, 0, SEEK_SET);
	AS3_ByteArray_readBytes(ptr, data, dataSize);
	ptr[dataLen] = 0;
	qspOpenGameStatusFromString(ptr);
	free(ptr);
	if (qspErrorNum) return AS3_False();
	if (isRefresh) qspCallRefreshInt(QSP_FALSE);
	return AS3_True();
}
/* Загрузка новой игры из памяти */
AS3_Val QSPLoadGameWorldFromData(void *param, AS3_Val args)
{
	char *ptr;
	AS3_Val data;
	int dataSize;
	char *fileName;
	QSP_CHAR *fileNameWC;
	AS3_ArrayValue(args, "AS3ValType, IntType, StrType", &data, &dataSize, &fileName);
	if (qspIsExitOnError && qspErrorNum) return AS3_False();
	qspResetError();
	if (qspIsDisableCodeExec) return AS3_False();
	ptr = (char *)malloc(dataSize + 3);
	AS3_ByteArray_seek(data, 0, SEEK_SET);
	AS3_ByteArray_readBytes(ptr, data, dataSize);
	ptr[dataSize] = ptr[dataSize + 1] = ptr[dataSize + 2] = 0;
	fileNameWC = qspC2W(fileName);
	qspOpenQuestFromData(ptr, dataSize + 3, fileNameWC, QSP_FALSE);
	free(fileNameWC);
	free(ptr);
	if (qspErrorNum) return AS3_False();
	return AS3_True();
}
Example #9
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 #10
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 #11
0
File: main.c Project: Glideh/jfrec
int readByteArray(void *cookie, char *dst, int size)
{
	return AS3_ByteArray_readBytes(dst, (AS3_Val)cookie, size);
}