Beispiel #1
0
static void process_file(const char *filename)
{
	FILE *fp;
	int count;
	unsigned char buf[32];
	unsigned int iterations;
	const char *ext[] = {".psafe3"};

	if (!(fp = fopen(filename, "rb"))) {
		fprintf(stderr, "! %s: %s\n", filename, strerror(errno));
		return;
	}
	count = fread(buf, 4, 1, fp);
	assert(count == 1);
	if(memcmp(buf, magic, 4)) {
		fprintf(stderr, "%s : Couldn't find PWS3 magic string. Is this a Password Safe file?\n", filename);
		exit(1);
	}
	count = fread(buf, 32, 1, fp);
	assert(count == 1);
	iterations = fget32(fp);

	printf("%s:$pwsafe$*3*", strip_suffixes(basename(filename), ext, 1));
	print_hex(buf, 32);
	printf("*%d*", iterations);
	count = fread(buf, 32, 1, fp);
	assert(count == 1);
	print_hex(buf,32);
	printf("\n");

	fclose(fp);
}
Beispiel #2
0
void seekmkf(FILE* fp,int n)
{
	long offset;
	long t;
	fseek(fp,4*n,SEEK_SET);
	offset=fget32(fp);
	fseek(fp,offset,SEEK_SET);
}
Beispiel #3
0
void LoadUEFState(char *StateName) {
	char errmsg[256];
	char UEFId[10];
//--	int CompletionBits=0; // These bits should be filled in
//## Unused.
	long RPos=0,FLength,CPos;
	unsigned int Block,Length;
	int Version;
	strcpy(UEFId,"BlankFile");
	UEFState=fopen(StateName,"rb");
	if (UEFState != NULL)
	{
//->		fseek(UEFState,NULL,SEEK_END);
//++
		fseek(UEFState,0,SEEK_END);
//<-
		FLength=ftell(UEFState);
		fseek(UEFState,0,SEEK_SET);  // Get File length for eof comparison.
		fatal_fread(UEFId,10,1,UEFState);
		if (strcmp(UEFId,"UEF File!")!=0) {
			MessageBox(GETHWND,"The file selected is not a UEF File.","BeebEm",MB_ICONERROR|MB_OK);
			fclose(UEFState);
			return;
		}
		Version=fget16(UEFState);
		sprintf(errmsg,"UEF Version %x",Version);
		//MessageBox(GETHWND,errmsg,"BeebEm",MB_OK);
		RPos=ftell(UEFState);

		while (ftell(UEFState)<FLength) {
			Block=fget16(UEFState);
			Length=fget32(UEFState);
			CPos=ftell(UEFState);
			sprintf(errmsg,"Block %04X - Length %d (%04X)",Block,Length,Length);
			//MessageBox(GETHWND,errmsg,"BeebEm",MB_ICONERROR|MB_OK);
			if (Block==0x046A) LoadEmuUEF(UEFState,Version);
			if (Block==0x0460) Load6502UEF(UEFState);
			if (Block==0x0461) LoadRomRegsUEF(UEFState);
			if (Block==0x0462) LoadMainMemUEF(UEFState);
			if (Block==0x0463) LoadShadMemUEF(UEFState);
			if (Block==0x0464) LoadPrivMemUEF(UEFState);
			if (Block==0x0465) LoadFileMemUEF(UEFState);
			if (Block==0x0466) LoadSWRMMemUEF(UEFState);
			if (Block==0x0467) LoadViaUEF(UEFState);
			if (Block==0x0468) LoadVideoUEF(UEFState);
			if (Block==0x046B) LoadSoundUEF(UEFState);
			if (Block==0x046D) LoadIntegraBHiddenMemUEF(UEFState);
			if (Block==0x046E) Load8271UEF(UEFState);
			if (Block==0x046F) Load1770UEF(UEFState,Version);
			if (Block==0x0470) LoadTubeUEF(UEFState);
			if (Block==0x0471) Load65C02UEF(UEFState);
			if (Block==0x0472) Load65C02MemUEF(UEFState);
			if (Block==0x0473) LoadSerialUEF(UEFState);
			fseek(UEFState,CPos+Length,SEEK_SET); // Skip unrecognised blocks (and over any gaps)
		}

		fclose(UEFState);

		mainWin->SetRomMenu();
		mainWin->SetDiscWriteProtects();
	}
	else
	{
		char errstr[256];
		sprintf(errstr, "Cannot open state file: %s", StateName);
		MessageBox(GETHWND,errstr,"BeebEm",MB_ICONERROR|MB_OK);
	}
}
Beispiel #4
0
int main(int argc,char* argv[])
{	
	int map=0,pat=0,mapgroup=0;
	int maps=-1,pats,mapgroups,pmaps;
	int mapchg=1,patchg=1,mapgroupchg=1;
	int width[0x200],height[0x200];
	int px,py,pw,ph;
	int rle0,data,i,j,t;
	int running=1;
	int len=0,s;
	int max;
	int vx[0x200],vy[0x200];
	char filename[12];
	char tosay[100];
	byte *buf=(byte*)malloc(0x12000),
	     *here;
	
	static BITMAP *bmp[0x200];
	BITMAP *tb;;
	PALETTE pal;
	
	FILE* fp=fopen(argv[1],"rb");
	FILE* fppat=fopen("pat.mkf","rb");
	
	if((fp==NULL)||(fppat==NULL))
	{
		printf("Usage:rle *.mkf");
		exit(-1);
	}
	
	//*(strrchr(argv[1],'.'))='\0';
	
	mapgroups=fget32(fp)/4-2,pats=fget32(fppat)/4-2;
	
	allegro_init();
	set_gfx_mode(GFX_AUTODETECT_WINDOWED,320,200,0,0);
	install_keyboard();
	atexit(allegro_exit);


	tb=create_bitmap(320,200);
	clear(tb);

	while(running)
	{		
		if(mapgroupchg)
		{	
			seekmkf(fp,mapgroup);s=ftell(fp);
			seekmkf(fp,mapgroup+1);len=ftell(fp)-s;
			if(len==0)
			{
				mapgroupchg=mapchg=1;
				map=0;
				mapgroup++;
				continue;
			}
			else
			{
				fseek(fp,s,SEEK_SET);
				fread(buf,len,1,fp);
				max=*(int*)(buf+4);
				deyj1(&buf);
				pmaps=maps;
				maps=(*(short*)(buf))-1;
				map=0;
				mapchg=1;
				mapgroupchg=0;
				for(j=0;j<=maps;j++)
				{
					if((here=seeksub(buf,j,max))==NULL)
					{
						maps=j-1;break;
					}
					width[j]=*(short*)(here),height[j]=*(short*)(here+2);
					vx[j]=(320-width[j])/2,vy[j]=(200-height[j])/2;
					here+=4;
					if(j<=pmaps) destroy_bitmap(bmp[j]);
					bmp[j]=create_bitmap(width[j],height[j]);
					for(i=0;i<width[j]*height[j];)
					{
						data=*here++;
						rle0=data>0x80?1:0;
						t=i;
						if(rle0)
							for(;i<t+data-0x80;i++)
								putpixel(bmp[j],i%width[j],i/width[j],0);
						else
							for(;i<t+data;i++)
								putpixel(bmp[j],i%width[j],i/width[j],*here++);
					}
				}
				blit(tb,screen,0,0,0,0,320,200);
			}
		}
		
		//change a palette
		if(patchg)
		{
			seekmkf(fppat,pat);
			for(i=0;i<256;i++)
			{	pal[i].r=fget8(fppat);
				pal[i].g=fget8(fppat);
				pal[i].b=fget8(fppat);
			}
			set_palette(pal);
			patchg=0;
		}		
		
		//render a frame
		if(mapchg)
		{
			if((vx[map]>px)||(vy[map]>py)||(width[map]<pw)||(height[map]<ph))
				blit(tb,screen,0,0,0,0,320,200);
			px=vx[map],py=vy[map],pw=width[map],ph=height[map];
			blit(bmp[map], screen, 0, 0, px, py, pw, ph);
			mapchg=0;
		}
		
		textprintf(screen,font,0,0,0xFF,"group:%x,id:%x,pat:%x",mapgroup,map,pat);			

		//Event handling
		while(!keypressed())	rest(100000);
		switch(readkey()>>8) {
		case KEY_DOWN:
			map=(map+1)%(maps+1);
			mapchg=1;
			if(!map)	
				blit(tb,screen,0,0,0,0,320,200);
			break;
		case KEY_RIGHT:
			pat=(pat+1>pats)?pat:pat+1;
			patchg=1;
			break;
		case KEY_PGDN:
			mapgroup=(mapgroup+1>mapgroups)?mapgroup:mapgroup+1;
			mapgroupchg=1;
			break;
		case KEY_UP:
			map=(map-1<0)?maps:map-1;
			mapchg=1;
			break;
		case KEY_LEFT:
			pat=(pat-1<0)?0:pat-1;
			patchg=1;
			break;
		case KEY_PGUP:
			mapgroup=(mapgroup-1<0)?mapgroup:mapgroup-1;
			mapgroupchg=1;
			break;
		case KEY_ESC:
			running=0;
			break;
		case KEY_S:
			sprintf(filename,"%s-%d-%d.bmp",argv[1],mapgroup,map);
			save_bmp(filename,bmp[map],pal);
			break;
		}
	}
	//finalize
	destroy_bitmap(tb);
	for(i=0;i<maps;i++)
		destroy_bitmap(bmp[i]);
	fclose(fp);fclose(fppat);
	free(buf);
	return 0;
}
Beispiel #5
0
static void process_file(char *filename, char *parentfile)
{
    FILE *fp;
    int i;
    struct stat sb;
    uint16_t versionMajor;
    uint16_t versionMinor;
    char path[4096] = { 0 };
    uint32_t encryptionFlags;
    char *buffer, *xmlfile;
    FILE *ofp;
    xmlDocPtr doc;
    xmlNodePtr cur;
    int spinCount;
    int pkeBlockSize;
    int pkeKeyBits;
    int pkeHashSize;
    unsigned char *pkeSaltValue;
    unsigned char encryptedVerifierHashInput[16 + 2];
    unsigned char encryptedVerifierHashValue[64 + 2];
    int version;
    xmlChar *spinCountXML;
    xmlChar *saltSizeXML;
    xmlChar *pkeBlockSizeXML;
    xmlChar *pkeKeyBitsXML;
    xmlChar *pkeHashSizeXML;
    xmlChar *pkeSaltValueXML;
    xmlChar *hashAlgorithm;
    xmlChar *encryptedVerifierHashInputXML;
    xmlChar *encryptedVerifierHashValueXML;

    uint32_t headerLength;
    uint32_t skipFlags;
    uint32_t sizeExtra;
    uint32_t algId;
    uint32_t algHashId;
    uint32_t keySize;
    uint32_t providerType;
    char CSPName[1024];
    uint32_t saltSize;
    char salt[1024];
    char encryptedVerifier[16];
    uint32_t verifierHashSize;
    char encryptedVerifierHash[64];

    if(stat(filename, &sb) != 0) {
    }

    if (!(fp = fopen(filename, "rb"))) {
        fprintf(stderr, "! %s : %s\n", filename, strerror(errno));
        return;
    }

    while (!feof(fp)) {
        versionMajor = fget16(fp);
        versionMinor = fget16(fp);
        encryptionFlags = fget32(fp);
        if (encryptionFlags == fExternal) {
            fprintf(stderr, "%s : An external cryptographic provider is not supported\n", parentfile);
            return;
        }
        if (versionMinor == 0x04 && versionMajor == 0x04) { /* Office 2010 and 2013 files */
            if (encryptionFlags != fAgile)
                fprintf(stderr, "%s : The encryption flags are not consistent with the encryption type\n", parentfile);
            /* rest of the data is in XML format, dump it to a file */
            strcpy(path, filename);
            buffer = (char*)malloc(sb.st_size);
            fread(buffer, sb.st_size - 8, 1, fp);
            xmlfile = strcat(path, ".xml");
            if (!(ofp = fopen(xmlfile, "w"))) {
                fprintf(stderr, "! %s : %s\n", filename, strerror(errno));
                return;
            }
            fwrite(buffer, sb.st_size - 8, 1, ofp);
            fclose(ofp);
            /* process XML file */
            doc = xmlParseFile(xmlfile);
            if (doc == NULL ) {
                fprintf(stderr, "Document not parsed successfully. \n");
                return;
            }
            cur = xmlDocGetRootElement(doc);
            if (cur == NULL) {
                fprintf(stderr, "empty document\n");
                xmlFreeDoc(doc);
                return;
            }
            cur = cur->xmlChildrenNode;
            while (cur != NULL) {
                if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyEncryptors")))
                    break;
                cur = cur->next;
            }
            cur = cur->xmlChildrenNode;
            while (cur != NULL) {
                if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyEncryptor")))
                    break;
                cur = cur->next;
            }
            cur = cur->xmlChildrenNode;
            /* we are now at "encryptedKey" node */
            spinCountXML = xmlGetProp(cur, "spinCount");
            spinCount = atoi(spinCountXML);
            xmlFree(spinCountXML);
            saltSizeXML = xmlGetProp(cur, "saltSize");
            saltSize = atoi(saltSizeXML);
            xmlFree(saltSizeXML);
            pkeBlockSizeXML = xmlGetProp(cur, "blockSize");
            pkeBlockSize = atoi(pkeBlockSizeXML);
            xmlFree(pkeBlockSizeXML);
            pkeKeyBitsXML = xmlGetProp(cur, "keyBits");
            pkeKeyBits = atoi(pkeKeyBitsXML);
            xmlFree(pkeKeyBitsXML);
            pkeHashSizeXML = xmlGetProp(cur, "hashSize");
            hashAlgorithm = xmlGetProp(cur, "hashAlgorithm");
            if(strcmp(hashAlgorithm, "SHA1") == 0) {
                version = 2010;
            }
            else if (strcmp(hashAlgorithm, "SHA512") == 0) {
                version = 2013;
            }
            else {
                fprintf(stderr, "%s uses un-supported hashing algorithm %s, please file a bug! \n", parentfile, hashAlgorithm);
                return;
            }
            pkeHashSize = atoi(pkeHashSizeXML);
            xmlFree(pkeHashSizeXML);
            pkeSaltValueXML = xmlGetProp(cur, "saltValue");
            pkeSaltValue = (unsigned char*)malloc(16 + 2);
            base64_decode(pkeSaltValueXML, strlen(pkeSaltValueXML), pkeSaltValue);
            xmlFree(pkeSaltValueXML);
            encryptedVerifierHashInputXML = xmlGetProp(cur, "encryptedVerifierHashInput");
            base64_decode(encryptedVerifierHashInputXML, strlen(encryptedVerifierHashInputXML), encryptedVerifierHashInput);
            xmlFree(encryptedVerifierHashInputXML);
            encryptedVerifierHashValueXML = xmlGetProp(cur, "encryptedVerifierHashValue");
            base64_decode(encryptedVerifierHashValueXML, strlen(encryptedVerifierHashValueXML), encryptedVerifierHashValue);
            xmlFree(encryptedVerifierHashValueXML);
            printf("%s:$office$*%d*%d*%d*%d*", parentfile, version, spinCount, pkeKeyBits, saltSize);
            print_hex(pkeSaltValue, saltSize);
            printf("*");
            print_hex(encryptedVerifierHashInput, 16);
            printf("*");
            print_hex(encryptedVerifierHashValue, 32);
            printf("\n");
            xmlFreeDoc(doc);
            unlink(xmlfile);
            return;
        }
        /* Office 2007 file processing */
        // Encryption header
        headerLength = fget32(fp);
        skipFlags = fget32(fp);
        headerLength -= 4;
        sizeExtra = fget32(fp);
        headerLength -= 4;
        algId = fget32(fp);
        headerLength -= 4;
        algHashId = fget32(fp);
        headerLength -= 4;
        keySize = fget32(fp);
        headerLength -= 4;
        providerType = fget32(fp);
        headerLength -= 4;
        (void)fget32(fp);
        headerLength -= 4;	// Reserved 1
        (void)fget32(fp);
        headerLength -= 4;	// Reserved 2
        fread(CSPName, headerLength, 1, fp);
        // Encryption verifier
        saltSize = fget32(fp);
        fread(salt, saltSize, 1, fp);
        fread(encryptedVerifier, 16, 1, fp);
        verifierHashSize = fget32(fp);
        if(providerType == PTRC4)
            fread(encryptedVerifierHash, 0x14, 1, fp);
        else
            fread(encryptedVerifierHash, 0x20, 1, fp);
        version = 2007;
        printf("%s:$office$*%d*%d*%d*%d*", parentfile, version, verifierHashSize, keySize, saltSize);
        print_hex(salt, saltSize);
        printf("*");
        print_hex(encryptedVerifier, 16);
        printf("*");
        print_hex(encryptedVerifierHash, 32);
        printf("\n");
        break;
    }
}
static void process_file(const char *filename)
{
	FILE *fp;
	unsigned char buf[4];
	long pos, cipheroff;
	unsigned char salt[SALTLEN];
	unsigned char iv[IVLEN];
	unsigned char ct[CTLEN];
	size_t nread;
	int err;

	if (!(fp = fopen(filename, "rb"))) {
		fprintf(stderr, "! %s: %s\n", filename, strerror(errno));
		return;
	}

	err = fseek(fp, -4, SEEK_END);

	while(1) {
		err |= fseek(fp, -8, SEEK_CUR);
		if (err || fread(buf, 4, 1, fp) != 1) {
			fprintf(stderr, "%s: Couldn't find db key. Is a keychain file?\n", filename);
			exit(1);
		}
		if (!memcmp(buf, magic, 4))
			break;
	}

	pos = ftell(fp) - 4;

	// ciphertext offset
	err = fseek(fp, pos + 8, SEEK_SET);
	cipheroff = fget32(fp);
	err |= ferror(fp);

	// salt
	err |= fseek(fp, pos + 44, SEEK_SET);
	nread = fread(salt, SALTLEN, 1, fp);

	// IV
	err |= fseek(fp, pos + 64, SEEK_SET);
	nread += fread(iv, IVLEN, 1, fp);

	// ciphertext
	err |= fseek(fp, pos + cipheroff, SEEK_SET);
	nread += fread(ct, CTLEN, 1, fp);

	if (err || ferror(fp) || nread != 3) {
		fprintf(stderr, "%s: Couldn't parse the file. Is a keychain file?\n", filename);
		exit(1);
	}

	// output
	printf("%s:$keychain$*", filename);
	print_hex(salt, SALTLEN);
	printf("*");
	print_hex(iv, IVLEN);
	printf("*");
	print_hex(ct, CTLEN);
	printf("\n");

	fclose(fp);
}
Beispiel #7
0
static void process_file(const char *filename)
{
    FILE *fp;
    unsigned char buf[4];
    unsigned char salt[SALTLEN];
    unsigned char iv[IVLEN];
    unsigned char ct[CTLEN];
    long pos, cipheroff;
    size_t bytes;

    if (!(fp = fopen(filename, "rb"))) {
        fprintf(stderr, "! %s: %s\n", filename, strerror(errno));
        return;
    }
    fseek(fp, -4, SEEK_END);

    while(1) {
        fseek(fp, -8, SEEK_CUR);
        if(fread(buf, 4, 1, fp) == 0) {
            fprintf(stderr, "%s : Couldn't find db key. Is it a keychain file?\n", filename);
            exit(1);
        }
        if(!memcmp(buf, magic, 4))
            break;
    }

    pos = ftell(fp) - 4;

    // ciphertext offset
    fseek(fp, pos + 8, SEEK_SET);
    cipheroff = fget32(fp);

    // salt
    fseek(fp, pos + 44, SEEK_SET);
    bytes = fread(salt, 1, SALTLEN, fp);
    if(bytes != SALTLEN) {
        fprintf(stderr, "Something went wrong - fread(salt) error\n");
        exit(1);
    }
    // IV
    fseek(fp, pos + 64, SEEK_SET);
    bytes = fread(iv, 1, IVLEN, fp);
    if(bytes != IVLEN) {
        fprintf(stderr, "Something went wrong - fread(iv) error\n");
        exit(1);
    }
    // ciphertext
    fseek(fp, pos + cipheroff, SEEK_SET);
    bytes = fread(ct, 1, CTLEN, fp);
    if(bytes != CTLEN) {
        fprintf(stderr, "Something went wrong - fread(ct) error\n");
        exit(1);
    }
    // output
    printf("%s:$keychain$*", basename(filename));
    print_hex(salt, SALTLEN);
    printf("*");
    print_hex(iv, IVLEN);
    printf("*");
    print_hex(ct, CTLEN);
    printf("\n");

    fclose(fp);
}
HRESULT XPTypeLibParse(FILE* fp, IXPTypeLib** ppTypeLib)
{
	CXPTypeLib* pTypeLib = new CXPTypeLib;
	pTypeLib->fp = fp;

	int nread = fread(pTypeLib->header.magic, 1, 16, fp);
	if (nread >= 16 && memcmp(pTypeLib->header.magic, "XPCOM\nTypeLib\r\n\032", 16)==0)
	{
		pTypeLib->header.major_version = fget8(fp);
		pTypeLib->header.minor_version = fget8(fp);
		pTypeLib->header.num_interfaces = fget16(fp);
		pTypeLib->header.file_length = fget32(fp);
		pTypeLib->header.interface_directory = fget32(fp);
		pTypeLib->header.data_pool = fget32(fp);

		if (pTypeLib->header.major_version > 1)
		{
//			ATLTRACE("XPCOM TypeLib unsupported major version %d\n", pTypeLib->header.major_version);
			return E_FAIL;
		}

		pTypeLib->ifaces = new CXPIFaceInfo*[pTypeLib->header.num_interfaces];

		fseek(fp, -1 + pTypeLib->header.interface_directory/* + i*sizeof(InterfaceDirectoryEntry)*/, SEEK_SET);

		int i;

		// Read all these in one go
		for (i = 0; i < pTypeLib->header.num_interfaces; i++)
		{
			pTypeLib->ifaces[i] = new CXPIFaceInfo;

			fread(&pTypeLib->ifaces[i]->m_iface_entry.m_iid, 16, 1, fp);
			pTypeLib->ifaces[i]->m_iface_entry.m_name = fget32(fp);
			pTypeLib->ifaces[i]->m_iface_entry.m_namespace = fget32(fp);
			pTypeLib->ifaces[i]->m_iface_entry.m_interface_descriptor = fget32(fp);
		}

		// I currently also read the rest now, but later I may read it only when necessary
		for (i = 0; i < 44/*pTypeLib->header.num_interfaces*/; i++)
		{
			ReadIdentifierFromLocation(fp, -1 + pTypeLib->header.data_pool + pTypeLib->ifaces[i]->m_iface_entry.m_name, pTypeLib->ifaces[i]->m_name);

			if (pTypeLib->ifaces[i]->m_iface_entry.m_namespace)
			{
				ReadIdentifierFromLocation(fp, -1 + pTypeLib->header.data_pool + pTypeLib->ifaces[i]->m_iface_entry.m_namespace, pTypeLib->ifaces[i]->m_namespace);
			}

			pTypeLib->ifaces[i]->m_nFuncs = 0;
			if (pTypeLib->ifaces[i]->m_iface_entry.m_interface_descriptor)
			{
				fseek(fp, -1 + pTypeLib->header.data_pool + pTypeLib->ifaces[i]->m_iface_entry.m_interface_descriptor, SEEK_SET);

				uint16 parent_interface_index = fget16(fp);
				pTypeLib->ifaces[i]->m_nFuncs = fget16(fp);

				pTypeLib->ifaces[i]->m_funcs = new XPFUNCDESC*[pTypeLib->ifaces[i]->m_nFuncs];

				for (int m = 0; m < pTypeLib->ifaces[i]->m_nFuncs; m++)
				{
					pTypeLib->ifaces[i]->m_funcs[m] = new XPFUNCDESC;
					/*
MethodDescriptor {
    boolean         is_getter;
    boolean         is_setter;
    boolean         is_not_xpcom;
    boolean         is_constructor;
    boolean         is_hidden;
    uint3           reserved;
    Identifier*     name;
    uint8           num_args;
    ParamDescriptor params[num_args];
    ParamDescriptor result;
}
*/

					uint8 flags = fget8(fp);
					DWORD name = fget32(fp);
					uint8 num_args = fget8(fp);

					for (int p = 0; p < num_args; p++)
					{
						ReadParamDescriptor(fp);
					}
					ReadParamDescriptor(fp);

					sysstring str;
					ReadIdentifierFromLocation(fp, -1 + pTypeLib->header.data_pool + name, str);
					pTypeLib->ifaces[i]->m_funcs[m]->name = str;
				}

				uint16 num_constants = fget16(fp);
				for (int c = 0; c < num_constants; c++)
				{
				/*
				ConstDescriptor
				{ 
				Identifier*     name;
				TypeDescriptor  type; 
				<type>          value;}
				*/
					DWORD name = fget32(fp);
					uint8 tag = ReadTypeDescriptor(fp);
					if (tag == 0)
					{
						char value = fget8(fp);
					}
					else if (tag == 1)
					{
						short value = fget16(fp);
					}
					else if (tag == 2)
					{
						long value = fget32(fp);
					}
					else if (tag == 4)
					{
						uint8 value = fget8(fp);
					}
					else if (tag == 5)
					{
						uint16 value = fget16(fp);
					}
					else if (tag == 6)
					{
						uint32 value = fget32(fp);
					}
					else
					{
						throw -1;//exit(1);
					}
				}
				/*
				boolean                  is_scriptable;
				boolean                  is_function;
				uint6                    reserved;
				*/
				uint8 flags = fget8(fp);

		/*
InterfaceDescriptor {
    uint16                   parent_interface_index;
    uint16                   num_methods;
    MethodDescriptor         method_descriptors[num_methods];
    uint16                   num_constants;
    ConstDescriptor          const_descriptors[num_constants];
    boolean                  is_scriptable;
    boolean                  is_function;
    uint6                    reserved;

}
		*/
			}
		}

		*ppTypeLib = pTypeLib;
		return S_OK;
	}
	else
	{
		return E_FAIL;
	}
}
Beispiel #9
0
static void process_file(const char *fname)
{
	unsigned char filename[1024];
	FILE *fp;
	int i;
	char path[LARGE_ENOUGH];

	if (!(fp = fopen(fname, "rb"))) {
		fprintf(stderr, "! %s : %s\n", fname, strerror(errno));
		return;
	}

	while (!feof(fp)) {
		uint32_t id = fget32(fp);

		if (id == 0x04034b50UL) {	/* local header */
			uint16_t version = fget16(fp);
			uint16_t flags = fget16(fp);
			uint16_t compression_method = fget16(fp);
			uint16_t lastmod_time = fget16(fp);
			uint16_t lastmod_date = fget16(fp);
			uint32_t crc = fget32(fp);
			uint32_t compressed_size = fget32(fp);
			uint32_t uncompressed_size = fget32(fp);
			uint16_t filename_length = fget16(fp);
			uint16_t extrafield_length = fget16(fp);
			/* unused variables */
			(void) version;
			(void) lastmod_time;
			(void) lastmod_date;
			(void) crc;
			(void) uncompressed_size;

			if (filename_length > 250) {
				fprintf(stderr, "! %s: Invalid zip file, filename length too long!\n", fname);
				return;
			}
			if (fread(filename, 1, filename_length, fp) != filename_length) {
				fprintf(stderr, "Error, in fread of file data!\n");
				goto cleanup;
			}
			filename[filename_length] = 0;

			if (compression_method == 99) {	/* AES encryption */
				uint16_t efh_id = fget16(fp);
				uint16_t efh_datasize = fget16(fp);
				uint16_t efh_vendor_version = fget16(fp);
				uint16_t efh_vendor_id = fget16(fp);
				char efh_aes_strength = fgetc(fp);
				uint16_t actual_compression_method = fget16(fp);
				unsigned char salt[16];
				char *bname;
				int n = 0;
				uint16_t password_verification_value;
				unsigned char *p;
				strnzcpy(path, fname, sizeof(path));
				bname = basename(path);

				fprintf(stderr,
				    "%s->%s is using AES encryption, extrafield_length is %d\n",
				    fname, filename, extrafield_length);
				/* unused variables */
				(void) efh_id;
				(void) efh_datasize;
				(void) efh_vendor_version;
				(void) efh_vendor_id;
				(void) efh_aes_strength;
				(void) actual_compression_method;

				printf("%s:$zip$*0*%d*", bname,
				    efh_aes_strength);
				switch (efh_aes_strength) {
				case 1:
					n = 8;
					if (fread(salt, 1, n, fp) != n) {
						fprintf(stderr, "Error, in fread of file data!\n");
						goto cleanup;
					}
					break;
				case 2:
					n = 12;
					if (fread(salt, 1, n, fp) != n) {
						fprintf(stderr, "Error, in fread of file data!\n");
						goto cleanup;
					}
					break;
				case 3:
					n = 16;
					if (fread(salt, 1, n, fp) != n) {
						fprintf(stderr, "Error, in fread of file data!\n");
						goto cleanup;
					}
					break;

				}
				for (i = 0; i < n; i++) {
					printf("%c%c",
					    itoa16[ARCH_INDEX(salt[i] >> 4)],
					    itoa16[ARCH_INDEX(salt[i] &
						    0x0f)]);
				}
				password_verification_value = fget16(fp);
				p = (unsigned char *) &password_verification_value;
				printf("*");
				for (i = 0; i < 2; i++) {
					printf("%c%c",
					    itoa16[ARCH_INDEX(p[i] >> 4)],
					    itoa16[ARCH_INDEX(p[i] & 0x0f)]);
				}
				printf(":::::%s\n", fname);
				fseek(fp, 10, SEEK_CUR);

			} else if (flags & 1) {	/* old encryption */
Beispiel #10
0
void process_database(char* encryptedDatabase)
{
	long dataStartOffset;
	unsigned long transformRounds;
	unsigned char *masterSeed;
	int masterSeedLength;
	unsigned char *transformSeed;
	int transformSeedLength;
	unsigned char *initializationVectors;
	int initializationVectorsLength;
	unsigned char *expectedStartBytes;
	int expectedStartBytesLength;

	FILE *fp = fopen(encryptedDatabase, "rb");
	if (!fp) {
		fprintf(stderr, "! %s : %s\n", encryptedDatabase, strerror(errno));
		return;
	}
	uint32_t uSig1 = fget32(fp);
	uint32_t uSig2 = fget32(fp);
	if ((uSig1 == FileSignatureOld1) && (uSig2 == FileSignatureOld2)) {
		fprintf(stderr, "! %s : Old format, not supported currently\n", encryptedDatabase);
		fclose(fp);
		return;
	}
	if ((uSig1 == FileSignature1) && (uSig2 == FileSignature2)) {
	}
	else if ((uSig1 == FileSignaturePreRelease1) && (uSig2 == FileSignaturePreRelease2)) {
	}
	else {
		fprintf(stderr, "! %s : Unknown format: File signature invalid\n", encryptedDatabase);
		fclose(fp);
		return;
	}
        uint32_t uVersion = fget32(fp);
	if ((uVersion & FileVersionCriticalMask) > (FileVersion32 & FileVersionCriticalMask)) {
		fprintf(stderr, "! %s : Unknown format: File version unsupported\n", encryptedDatabase);
		fclose(fp);
		return;
	}
	int endReached = 0;
	while (!endReached)
	{
		unsigned char btFieldID = fgetc(fp);
                uint16_t uSize = fget16(fp);

		unsigned char *pbData = NULL;
		if (uSize > 0)
		{
			pbData = (unsigned char*)malloc(uSize);
			fread(pbData, uSize, 1, fp);
		}
		enum Kdb4HeaderFieldID kdbID = btFieldID;
		switch (kdbID)
		{
			case EndOfHeader:
				endReached = 1;  // end of header
				free(pbData);
				break;

                        case MasterSeed:
				masterSeed = pbData;
				masterSeedLength = uSize;
				break;

                        case TransformSeed:
				transformSeed = pbData;
				transformSeedLength = uSize;
				break;

                        case TransformRounds:
				transformRounds = BytesToUInt64(pbData);
				free(pbData);
				break;

                        case EncryptionIV:
				initializationVectors = pbData;
				initializationVectorsLength = uSize;
				break;

                        case StreamStartBytes:
				expectedStartBytes = pbData;
				expectedStartBytesLength = uSize;
				break;

			default:
				free(pbData);
				break;
		}
	}
	dataStartOffset = ftell(fp);
	if(transformRounds == 0) {
		fprintf(stderr, "! %s : transformRounds can't be 0\n", encryptedDatabase);
		return;
	}
#ifdef KEEPASS_DEBUG
	fprintf(stderr, "%d, %d, %d, %d\n", masterSeedLength, transformSeedLength, initializationVectorsLength, expectedStartBytesLength);
#endif
	printf("%s:$keepass$*2*%ld*%ld*",encryptedDatabase, transformRounds, dataStartOffset);
	print_hex(masterSeed, masterSeedLength);
	printf("*");
	print_hex(transformSeed, transformSeedLength);
	printf("*");
	print_hex(initializationVectors, initializationVectorsLength);
	printf("*");
	print_hex(expectedStartBytes, expectedStartBytesLength);
	printf("\n");
	free(masterSeed);
	free(transformSeed);
	free(initializationVectors);
	free(expectedStartBytes);
	fclose(fp);
}