Exemplo n.º 1
0
	void print(int level, FILE *file)
	{
		int count = 0;

		fprintf (file, "{");

		for (map<StringObject *, BaseObject *>::iterator iter = m_map.begin(); iter != m_map.end(); iter ++)
		{
			if (count > 0)
			{
				fprintf (file, ", ");
			}

			StringObject *key = iter->first;
			BaseObject *obj = iter->second;

			key->print(level, file);
			fprintf (file, ": ");
			obj->print(level + 1, file);
			count ++;
		}

		fprintf (file, "}");

	}
Exemplo n.º 2
0
bool StringObject::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned i)
{
    StringObject* thisObject = jsCast<StringObject*>(cell);
    if (thisObject->internalValue()->canGetIndex(i))
        return false;
    return JSObject::deletePropertyByIndex(thisObject, exec, i);
}
Exemplo n.º 3
0
bool StringObject::getOwnPropertySlot(JSObject* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    StringObject* thisObject = jsCast<StringObject*>(cell);
    if (thisObject->internalValue()->getStringPropertySlot(exec, propertyName, slot))
        return true;
    return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot);
}
Exemplo n.º 4
0
bool StringObject::getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, unsigned propertyName, PropertySlot& slot)
{
    StringObject* thisObject = jsCast<StringObject*>(object);
    if (thisObject->internalValue()->getStringPropertySlot(exec, propertyName, slot))
        return true;    
    return JSObject::getOwnPropertySlot(thisObject, exec, Identifier::from(exec, propertyName), slot);
}
Exemplo n.º 5
0
bool StringObject::getOwnPropertySlot(JSCell* cell, ExecState* exec, unsigned propertyName, PropertySlot& slot)
{
    StringObject* thisObject = static_cast<StringObject*>(cell);
    if (thisObject->internalValue()->getStringPropertySlot(exec, propertyName, slot))
        return true;    
    return JSObject::getOwnPropertySlot(thisObject, exec, Identifier::from(exec, propertyName), slot);
}
Exemplo n.º 6
0
bool StringObject::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
{
    StringObject* thisObject = jsCast<StringObject*>(object);
    if (thisObject->internalValue()->getStringPropertyDescriptor(exec, propertyName, descriptor))
        return true;    
    return JSObject::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
}
/* Returns the taint on an object.
 * - Currently only arrays and java.lang.String is supported
 */
u4 getObjectTaint(Object* obj, const char* descriptor)
{
    ArrayObject *arrObj = NULL;
    if (obj == NULL) {
	return TAINT_CLEAR;
    }

    if (descriptor[0] == '[') {
	/* Get the taint from the array */
	arrObj = (ArrayObject*) obj;
	if (arrObj != NULL) {
	    return arrObj->taint.tag;
	}
    } 
    
    if (strcmp(descriptor, "Ljava/lang/String;") == 0) {
    StringObject * strObj = (StringObject*) obj;
	arrObj = strObj->array();
	if (arrObj != NULL) {
	    return arrObj->taint.tag;
	} /* else, empty string? don't worry about it */
    } 

    /* TODO: What about classes derived from String? */

    /* Don't worry about other object types */
    return TAINT_CLEAR;
}
Exemplo n.º 8
0
void StringObject::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
    StringObject* thisObject = jsCast<StringObject*>(object);
    int size = thisObject->internalValue()->length();
    for (int i = 0; i < size; ++i)
        propertyNames.add(Identifier(exec, String::number(i)));
    if (mode == IncludeDontEnumProperties)
        propertyNames.add(exec->propertyNames().length);
    return JSObject::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
}
Exemplo n.º 9
0
bool StringObject::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
{
    StringObject* thisObject = jsCast<StringObject*>(cell);
    if (propertyName == exec->propertyNames().length)
        return false;
    Optional<uint32_t> index = parseIndex(propertyName);
    if (index && thisObject->internalValue()->canGetIndex(index.value()))
        return false;
    return JSObject::deleteProperty(thisObject, exec, propertyName);
}
Exemplo n.º 10
0
bool StringObject::putByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, JSValue value, bool shouldThrow)
{
    VM& vm = exec->vm();
    auto scope = DECLARE_THROW_SCOPE(vm);

    StringObject* thisObject = jsCast<StringObject*>(cell);
    if (thisObject->internalValue()->canGetIndex(propertyName))
        return typeError(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    return JSObject::putByIndex(cell, exec, propertyName, value, shouldThrow);
}
Exemplo n.º 11
0
void StringObject::putByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, JSValue value, bool shouldThrow)
{
    StringObject* thisObject = jsCast<StringObject*>(cell);
    if (thisObject->internalValue()->canGetIndex(propertyName)) {
        if (shouldThrow)
            throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
        return;
    }
    JSObject::putByIndex(cell, exec, propertyName, value, shouldThrow);
}
Exemplo n.º 12
0
bool StringObject::deleteProperty(JSCell* cell, ExecState* exec, const Identifier& propertyName)
{
    StringObject* thisObject = static_cast<StringObject*>(cell);
    if (propertyName == exec->propertyNames().length)
        return false;
    bool isStrictUInt32;
    unsigned i = propertyName.toUInt32(isStrictUInt32);
    if (isStrictUInt32 && thisObject->internalValue()->canGetIndex(i))
        return false;
    return JSObject::deleteProperty(thisObject, exec, propertyName);
}
Exemplo n.º 13
0
//  Arity: 2 -> 0
Ref * sysMD5( Ref * pc, class MachineClass * vm ) {
    if ( vm->count != 1 ) throw Ginger::Mishap( "ArgsMismatch" );
    StringObject input = Cell( vm->fastPop() ).asStringObject();
    
    MD5Digester digester;
    digester.update( input.getCharPtr(), input.length() );

    vm->fastPush( vm->heap().copyString( pc, digester.digest().c_str() ) );
    
    return pc;
}
Exemplo n.º 14
0
bool StringObject::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
{
    StringObject* thisObject = jsCast<StringObject*>(cell);
    if (propertyName == exec->propertyNames().length)
        return false;
    unsigned i = propertyName.asIndex();
    if (thisObject->internalValue()->canGetIndex(i)) {
        ASSERT(i != PropertyName::NotAnIndex); // No need for an explicit check, the above test would always fail!
        return false;
    }
    return JSObject::deleteProperty(thisObject, exec, propertyName);
}
Exemplo n.º 15
0
bool StringObject::less(IObject *obj)
{
    StringObject *temp = dynamic_cast<StringObject*>(obj);
    if(this->equal(obj)) return false;
    int min = strlen(value);
    if((int)strlen(temp->getStr()) < min) min = strlen(temp->getStr());
    char *checkThis = this->getStr();
    char *checkObj = temp->getStr();
    int count = 0;
    for(count = 0; count < min; ++count)
    {
        if(checkThis[count] > checkObj[count]) return false;
        else if(checkThis[count] < checkObj[count]) return true;
    }
    if(count == (int)strlen(value)) return true;
    else return false;
}
Exemplo n.º 16
0
	void ObjTracer::extract_str(const Object * const obj, ObjWriteMode flag)
	{
		if ( !check_obj ( obj ) )
		{	
			ALOG(LOG_VERBOSE, "YWB", "OBJECT NULL");
			fprintf(traceFile_, "\n");
			return;
		}
		else
		{
			StringObject * so = (StringObject *) obj;
			const u2 *s = so->chars();
			if ( s == NULL )
        		{
        			ALOG(LOG_VERBOSE, "YWB","string is null");
        			return;
        		}
        		this->record_str( obj, s, sizeof(u2) * so->length(), flag );		
		}

	}
Exemplo n.º 17
0
bool StringObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool throwException)
{
    VM& vm = exec->vm();
    auto scope = DECLARE_THROW_SCOPE(vm);
    StringObject* thisObject = jsCast<StringObject*>(object);

    if (isStringOwnProperty(exec, thisObject, propertyName)) {
        // The current PropertyDescriptor is always
        // PropertyDescriptor{[[Value]]: value, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false}.
        // This ensures that any property descriptor cannot change the existing one.
        // Here, simply return the result of validateAndApplyPropertyDescriptor.
        // https://tc39.github.io/ecma262/#sec-string-exotic-objects-getownproperty-p
        PropertyDescriptor current;
        bool isCurrentDefined = thisObject->getOwnPropertyDescriptor(exec, propertyName, current);
        ASSERT(isCurrentDefined);
        bool isExtensible = thisObject->isExtensible(exec);
        RETURN_IF_EXCEPTION(scope, false);
        return validateAndApplyPropertyDescriptor(exec, nullptr, propertyName, isExtensible, descriptor, isCurrentDefined, current, throwException);
    }

    return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
}
Exemplo n.º 18
0
	void Tracer::extract_str (Object * obj, ObjWriteMode flag)
	{
		if ( !check_obj ( obj ) )
		{
			FILE *f;
			ALOG(LOG_VERBOSE, "YWB", "OBJECT NULL");
			if (flag == OPC_OBJ || flag == OPC_STR)
				f = fpObj_;
			else if (flag == FUNC_STR || flag == FUNC_OBJ)
				f = fpFuncs_;
			else
			{
				ALOG ( LOG_VERBOSE, "YWB", "error in which file to write" );
				return;
			}
			fprintf(f, "\n");
			fflush(f);
			return;
		}

/*
		if ( strcmp (obj->clazz->descriptor, "Ljava/lang/String;") != 0)
		{
			ALOG(LOG_VERBOSE,"YWB","NOT STRING");
			return;
		}	
*/		
		{			
			StringObject * so = (StringObject *) obj;
			const u2 *s = so->chars();
			if ( s == NULL )
        	{
        		ALOG(LOG_VERBOSE, "YWB","string is null");
        		return;
        	}
        	this->record_str( s, sizeof(u2) * so->length(), flag );
		}
	}
Exemplo n.º 19
0
//////////////////////////////////////////////////////////////
//	Send SMS alert
//////////////////////////////////////////////////////////////
bool CSNAPIClient::sms(CHARPTR host,USHORT port,CHARPTR sender,CHARPTR dialno,CHARPTR start)
{
	CMemplate memplate;
	CHttpClient client;
	StringObject result;
	httpResponseCode ret;

	//	Build URI
	CHAR uri[CBUFF_MEDIUM];
	sprintf(uri,"http://%s:%u/smsalert",host,port);
	result.Create();

	memplate.create(&babylon);
	memplate.createField(MTF_TEXT,"name","64,1,\"");
	memplate.createField(MTF_TEXT,"number","64,1,\"");

	SMetastruct *meta = memplate.metaAlloc("guests",10);
	int counter=2;

	//	Sneak in extra params
	meta->set(0,0,sender);
	meta->set(0,1,dialno);
	meta->set(1,0,start);
	meta->set(1,1,"");
		
	//	Build list
	onSMSRequest(*meta);

	//	Post request
	client.registerComs(this);
	ret = client.httpPost(uri,*meta,result);

	delete meta;
	result.Destroy();

	return ret == 200;
}
Exemplo n.º 20
0
bool StringObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor, bool throwException)
{
    StringObject* thisObject = jsCast<StringObject*>(object);

    if (propertyName == exec->propertyNames().length) {
        if (!object->isExtensible()) {
            if (throwException)
                throwError(exec, createTypeError(exec, ASCIILiteral("Attempting to define property on object that is not extensible.")));
            return false;
        }
        if (descriptor.configurablePresent() && descriptor.configurable()) {
            if (throwException)
                throwError(exec, createTypeError(exec, ASCIILiteral("Attempting to configurable attribute of unconfigurable property.")));
            return false;
        }
        if (descriptor.enumerablePresent() && descriptor.enumerable()) {
            if (throwException)
                throwError(exec, createTypeError(exec, ASCIILiteral("Attempting to change enumerable attribute of unconfigurable property.")));
            return false;
        }
        if (descriptor.isAccessorDescriptor()) {
            if (throwException)
                throwError(exec, createTypeError(exec, ASCIILiteral("Attempting to change access mechanism for an unconfigurable property.")));
            return false;
        }
        if (descriptor.writablePresent() && descriptor.writable()) {
            if (throwException)
                throwError(exec, createTypeError(exec, ASCIILiteral("Attempting to change writable attribute of unconfigurable property.")));
            return false;
        }
        if (!descriptor.value())
            return true;
        if (propertyName == exec->propertyNames().length && sameValue(exec, descriptor.value(), jsNumber(thisObject->internalValue()->length())))
            return true;
        if (throwException)
            throwError(exec, createTypeError(exec, ASCIILiteral("Attempting to change value of a readonly property.")));
        return false;
    }

    return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
}
Exemplo n.º 21
0
void test3()
{
	printf("Test 3 started!\n");

	StringObject* all = newStringObject();
	StringObject* first = newStringObject();
	StringObject* second = newStringObject();
	int pid1, pid2;

	all->append(all, "A child processed died.");
	first->append(first, "A child processed died.2");
	second->append(second, "A child processed died.3");

	proc_waiter_register(-1, proc_wait_cb, all);
	proc_waiter_register(-1, proc_wait_cb, first);
	proc_waiter_register(-1, proc_wait_cb, second);

	pid1 = fork();
	if(!pid1)
	{
		usleep(1000);
		exit(0);
	}
	usleep(10000);

	proc_waiter_deregister(-1, NULL, first);

	pid2 = fork();
	if(!pid2)
	{
		usleep(1000);
		exit(0);
	}
	sleep(1);

	proc_waiter_deregister_all();
	proc_waiter_stop();
	printf("Test 3 complete!\n\n\n");
}
Exemplo n.º 22
0
inline StringObject* StringObject::create(ExecState* exec, JSGlobalObject* globalObject, JSString* string)
{
    StringObject* object = new (NotNull, allocateCell<StringObject>(*exec->heap())) StringObject(exec->globalData(), globalObject->stringObjectStructure());
    object->finishCreation(exec->globalData(), string);
    return object;
}
Exemplo n.º 23
0
bool StringObject::equal(IObject *obj)
{
    StringObject *temp = dynamic_cast<StringObject*>(obj);
    if((strcmp(this->value, temp->getStr())) == 0) return true;
    else return false;
}
Exemplo n.º 24
0
StringObject* constructString(VM& vm, JSGlobalObject* globalObject, JSValue string)
{
    StringObject* object = StringObject::create(vm, globalObject->stringObjectStructure());
    object->setInternalValue(vm, string);
    return object;
}
Exemplo n.º 25
0
//////////////////////////
//	Read header & populate string with body
//////////////////////////
bool CMimeProtocol::readMimeResponse(int link,CHARPTR headers,int size,StringObject& content)
{
	CHAR buffer[CBUFF_HUGE+2];

	CHARPTR ptrHeadEnd;
	CHARPTR ptrContLen;

	int read=0;
	int bytes;

	//	1st read headers
	while(true){

		//	Wait
		if(!waitForEvent(link,10000)){

			content.strcpy(headers);
			return read > 0;
		}
				
		//	Read next lot
		if((bytes = recvTcp(link,&headers[read],size-read)) <= 0)
			return false;

		read+=bytes;
		headers[read]=0;
	
		//	Check for header & body
		ptrHeadEnd=strstr(headers,"\r\n\r\n");
		
		//	No header yet
		if(ptrHeadEnd)
			break;
	}

	ptrContLen=strstr(headers,"Content-Length: ");
	int contentLength;

	//	Terminate
	*ptrHeadEnd=0;

	//	Header & nobody - copy headers
	if(!ptrContLen){

		//	Just keep reading until server closes connection
		contentLength=128000;
		content.strcpy(headers);
	}
	else{

		//	Get content length
		if(!strparse(ptrContLen,"Content-Length: %1d",&contentLength))
			return false;

		//	Skip to start of body
		ptrHeadEnd += strlen("\r\n\r\n");
		content.strcpy(ptrHeadEnd);
	}

	//	Calculate remaining
	read = strlen(ptrHeadEnd);

	while(read < contentLength){
		
		//	Read next lot
		if((bytes = recvTcp(link,buffer,CBUFF_HUGE)) <= 0){

			switch(bytes){

				//	Remote closure
				case 0:
				return true;

			 	// Error - check
				default:
				switch(OSALASTERROR){

					//	No data to read - try again
		 			case OSAWOULDBLOCK:

						if(!waitForEvent(link,2000))
							return false;
			 
 					continue;

					// Oh oh
		 			default:
					return false;
				}
				break;
			}
		}

		buffer[bytes] = 0;
		read+=bytes;

		content.strcat(buffer);
	}

	//	Good to go
	return true;
}
Exemplo n.º 26
0
ToUnicodeCMap::ToUnicodeCMap(IndirectObject * io)
{
  this->indirectObject = io;
  if(io != null)
  {
    //Probably not necessary but harmless
    io->load(); 
    io->processAsStream();
  }
  
  if(this->indirectObject->unencodedStream != null)
  {
    char * stream = this->indirectObject->unencodedStream;
    char * bcsr = strstr(stream, "begincodespacerange");
    bcsr += 19; //skip 'begincodespacerange' keyword
    bcsr = StringUtils::skipWhiteSpace(bcsr, this->indirectObject->unencodedStreamSize - (bcsr - stream));
    do
    {
      StringObject * codeFrom = new StringObject(&bcsr, bcsr);
      StringObject * codeTo = new StringObject(&bcsr, bcsr);
      if(codeFrom->isHexa && codeTo->isHexa)
      {
        codeRanges.push_front(make_pair(codeFrom, codeTo));
      }
      else
      {
        cerr<<"\nToUnicodeMap: Couldn't read code ranges properly.\n";
        break;
      }
      bcsr = StringUtils::skipWhiteSpace(bcsr, this->indirectObject->unencodedStreamSize - (bcsr - stream));
    }while(*bcsr == '<');
    codeRanges.sort(compareRangeLen);

    char * bbfc = strstr(stream, "beginbfchar");
    while(bbfc != null)
    {
      bbfc += 11; //skip 'beginbfchar' keyword
      do
      {
        StringObject code = StringObject(&bbfc, bbfc);
        StringObject * utfString = new StringObject(&bbfc, bbfc);
        if(code.isHexa)
          codeCharMap[code.toNum()] = utfString;
        bbfc = StringUtils::skipWhiteSpace(bbfc, this->indirectObject->unencodedStreamSize - (bbfc - stream));
      }while(*bbfc == '<');
      bbfc = strstr(bbfc, "beginbfchar");
    }
    
    list<bfrange> rangeMapList;
    bbfc = strstr(stream, "beginbfrange");
    while(bbfc != null)
    {
      bbfc += 12;
      do
      {
        StringObject beginCode = StringObject(&bbfc, bbfc);
        StringObject endCode = StringObject(&bbfc, bbfc);
        PdfObject * objectForRange = PdfObject::readValue(&bbfc, bbfc, false);
        BFRange bfr = BFRange();
        bfr.begin = beginCode.toNum();
        bfr.end = endCode.toNum();
        bfr.object = objectForRange;
        rangeMapList.push_front(bfr);
        bbfc = StringUtils::skipWhiteSpace(bbfc, this->indirectObject->unencodedStreamSize - (bbfc - stream));
      }while(*bbfc == '<');
      bbfc = strstr(bbfc, "beginbfrange");
    }
    rangeMapList.sort(compareBFRanges);

    while(!rangeMapList.empty())
    {
      codeRangeMapVector.push_back(rangeMapList.front());
      rangeMapList.pop_front();
    }
  }
}
Exemplo n.º 27
0
inline StringObject* StringObject::create(VM& vm, JSGlobalObject* globalObject, JSString* string)
{
    StringObject* object = new (NotNull, allocateCell<StringObject>(vm.heap)) StringObject(vm, globalObject->stringObjectStructure());
    object->finishCreation(vm, string);
    return object;
}
Exemplo n.º 28
0
StringObject * ToUnicodeCMap::getUTFChar(unsigned char * charCode, int len)
{
  int charCodeNum = 0;
  for(int i = 0; i<len; i++)
  {
    charCodeNum *= 16;
    charCodeNum += charCode[i];
  }
  StringObject * utfChar = codeCharMap[charCodeNum];
  if(utfChar == null)
  {
    //try to find range for char
    BFRange * range = null;
    int endSearch = codeRangeMapVector.size()-1;
    if(endSearch > 0)
    {
      int beginSearch = 0;
      do
      {
        int actualSearch = (beginSearch + endSearch) / 2;
        BFRange * actualItem = &codeRangeMapVector[actualSearch];
        if(actualItem->begin <= charCodeNum &&
          actualItem->end >= charCodeNum)
        {
          range = actualItem;
          break;
        }
        if(actualItem->begin > charCodeNum)
        {
          endSearch = actualSearch-1;
        }
        else
        {
          beginSearch = actualSearch+1;
        }
      }while(beginSearch <= endSearch);
    }
    if(range == null)
    {
      //Couldn't map character properly.
      return null;
    }
    else
    {
      int increment = charCodeNum - range->begin;
      if(range->object->objectType == PdfObject::TYPE_STRING)
      {
        StringObject * string = (StringObject*) range->object;
        int numResult = string->toNum();
        numResult += increment;
        int len = string->getByteStringLen()*2;
        char * hexaString = new char[len+3];
        hexaString[0] = '<';
        hexaString[len+1] = '>';
        hexaString[len+2] = 0;
        for(int i = len; i>0; i--)
        {
          int byte = numResult % 16;
          switch(byte)
          {
          case 0: 
            hexaString[i] = '0';
            break;
          case 1: 
            hexaString[i] = '1';
            break;
          case 2: 
            hexaString[i] = '2';
            break;
          case 3: 
            hexaString[i] = '3';
            break;
          case 4: 
            hexaString[i] = '4';
            break;
          case 5: 
            hexaString[i] = '5';
            break;
          case 6: 
            hexaString[i] = '6';
            break;
          case 7: 
            hexaString[i] = '7';
            break;
          case 8: 
            hexaString[i] = '8';
            break;
          case 9: 
            hexaString[i] = '9';
            break;
          case 10: 
            hexaString[i] = 'A';
            break;
          case 11: 
            hexaString[i] = 'B';
            break;
          case 12: 
            hexaString[i] = 'C';
            break;
          case 13: 
            hexaString[i] = 'D';
            break;
          case 14: 
            hexaString[i] = 'E';
            break;
          case 15: 
            hexaString[i] = 'F';
            break;
          }
          numResult /= 16;
        }
        char * _dummy = null;
        utfChar = new StringObject(&_dummy, hexaString);
      }
      else if(range->object->objectType == PdfObject::TYPE_ARRAY)
      {
        ArrayObject * utfArray = (ArrayObject*) range->object;
        utfChar = (StringObject*) utfArray->objectList[increment];
      }
      else
      {
        //Couldn't find utf value in found range.
        return null;
      }
      // add result to char map - so there is no need to create the string again next time the char is used
      this->codeCharMap[charCodeNum] = utfChar; 
    }
  }
  return utfChar;
}
Exemplo n.º 29
0
void thingamadooberObject::init(const StringObject &src)
{
  delete tokenizer;
  tokenizer=new StringTokenizer(src.AsCharArray(),"");
}
Exemplo n.º 30
0
StringObject* constructString(ExecState* exec, JSGlobalObject* globalObject, JSValue string)
{
    StringObject* object = StringObject::create(exec, globalObject->stringObjectStructure());
    object->setInternalValue(exec->globalData(), string);
    return object;
}