Check for file inconsistencies.

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Check for file inconsistencies.

Post by Patz QuickBASIC Creations »

Is there a way to open a file and find the first thing wrong with it?
EX. If a file contains the code (in machine code)

Code: Select all

??{.☺23♦@2134◘)53
        ^ The @ is incorrect
and the code it should have is:

Code: Select all

??{.☺23♦R2134◘)53
        ^ The R is correct
I want it to report a value to the main program, through POKEing 2 values (one for ASCII value, another for position). I can do PEEKing, I just need to know how to compare files.

Thnx
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

Read two bytes (in qb) or four bytes (in fb) at a time, compare them, if they dont match, compare each individual byte inside the 2 or 4 byte sequence..

Return the location if/when they dont match..
I have left this dump.
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

OK, is there a way to assign a fingerprint to a program within QB? (and check it)
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

PQBC wrote:OK, is there a way to assign a fingerprint to a program within QB? (and check it)
What I need is something similar to MD5 so I can check a program's 'fingerprint' wthout running the second program.

Boy, I'm quoting myself. I must be getting REALLY lonely... :(
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

getting lonly? reminds me of myself...
Image
MACOSX92person

Post by MACOSX92person »

well, i'd like to see that
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

PQBC wrote:
PQBC wrote:OK, is there a way to assign a fingerprint to a program within QB? (and check it)
What I need is something similar to MD5 so I can check a program's 'fingerprint' wthout running the second program.

Boy, I'm quoting myself. I must be getting REALLY lonely... :(
CRC32 is most likely what you want..

This is a FB adaption of an old QB CRC32 routine:

Code: Select all

'##############################################
'# 
'# QBCRC10.BAS - All PDS/QuickBASIC 4.5 CRC-32 Routine
'# By Rich Geldreich 1992
'# Use, abuse, I don't care!
'# 
'# Adapted to FreeBASIC by J. "Z!re" Pihl of Plantasy Studios 2005
'# Further addaptions and modifications done 19th of August 2005
'#    -Z!re
'# 
'##############################################

declare FUNCTION _CRC32 (Offset as any ptr, Length as integer, Input_CRC as integer = 0) as integer
declare FUNCTION CRC32_File( file as string ) as integer

't$ = DIR$("*.*")
'do while t$ <> ""
'	print t$+": "+str(CRC32_File(t$))
'	t$ = DIR$()
'loop
'sleep

option static
DIM SHARED CRCTable(255) as integer => {_
&H000000000,&H077073096,&H0EE0E612C,&H0990951BA,&H0076DC419,_
&H0706AF48F,&H0E963A535,&H09E6495A3,&H00EDB8832,&H079DCB8A4,_
&H0E0D5E91E,&H097D2D988,&H009B64C2B,&H07EB17CBD,&H0E7B82D07,_
&H090BF1D91,&H01DB71064,&H06AB020F2,&H0F3B97148,&H084BE41DE,_
&H01ADAD47D,&H06DDDE4EB,&H0F4D4B551,&H083D385C7,&H0136C9856,_
&H0646BA8C0,&H0FD62F97A,&H08A65C9EC,&H014015C4F,&H063066CD9,_
&H0FA0F3D63,&H08D080DF5,&H03B6E20C8,&H04C69105E,&H0D56041E4,_
&H0A2677172,&H03C03E4D1,&H04B04D447,&H0D20D85FD,&H0A50AB56B,_
&H035B5A8FA,&H042B2986C,&H0DBBBC9D6,&H0ACBCF940,&H032D86CE3,_
&H045DF5C75,&H0DCD60DCF,&H0ABD13D59,&H026D930AC,&H051DE003A,_
&H0C8D75180,&H0BFD06116,&H021B4F4B5,&H056B3C423,&H0CFBA9599,_
&H0B8BDA50F,&H02802B89E,&H05F058808,&H0C60CD9B2,&H0B10BE924,_
&H02F6F7C87,&H058684C11,&H0C1611DAB,&H0B6662D3D,&H076DC4190,_
&H001DB7106,&H098D220BC,&H0EFD5102A,&H071B18589,&H006B6B51F,_
&H09FBFE4A5,&H0E8B8D433,&H07807C9A2,&H00F00F934,&H09609A88E,_
&H0E10E9818,&H07F6A0DBB,&H0086D3D2D,&H091646C97,&H0E6635C01,_
&H06B6B51F4,&H01C6C6162,&H0856530D8,&H0F262004E,&H06C0695ED,_
&H01B01A57B,&H08208F4C1,&H0F50FC457,&H065B0D9C6,&H012B7E950,_
&H08BBEB8EA,&H0FCB9887C,&H062DD1DDF,&H015DA2D49,&H08CD37CF3,_
&H0FBD44C65,&H04DB26158,&H03AB551CE,&H0A3BC0074,&H0D4BB30E2,_
&H04ADFA541,&H03DD895D7,&H0A4D1C46D,&H0D3D6F4FB,&H04369E96A,_
&H0346ED9FC,&H0AD678846,&H0DA60B8D0,&H044042D73,&H033031DE5,_
&H0AA0A4C5F,&H0DD0D7CC9,&H05005713C,&H0270241AA,&H0BE0B1010,_
&H0C90C2086,&H05768B525,&H0206F85B3,&H0B966D409,&H0CE61E49F,_
&H05EDEF90E,&H029D9C998,&H0B0D09822,&H0C7D7A8B4,&H059B33D17,_
&H02EB40D81,&H0B7BD5C3B,&H0C0BA6CAD,&H0EDB88320,&H09ABFB3B6,_
&H003B6E20C,&H074B1D29A,&H0EAD54739,&H09DD277AF,&H004DB2615,_
&H073DC1683,&H0E3630B12,&H094643B84,&H00D6D6A3E,&H07A6A5AA8,_
&H0E40ECF0B,&H09309FF9D,&H00A00AE27,&H07D079EB1,&H0F00F9344,_
&H08708A3D2,&H01E01F268,&H06906C2FE,&H0F762575D,&H0806567CB,_
&H0196C3671,&H06E6B06E7,&H0FED41B76,&H089D32BE0,&H010DA7A5A,_
&H067DD4ACC,&H0F9B9DF6F,&H08EBEEFF9,&H017B7BE43,&H060B08ED5,_
&H0D6D6A3E8,&H0A1D1937E,&H038D8C2C4,&H04FDFF252,&H0D1BB67F1,_
&H0A6BC5767,&H03FB506DD,&H048B2364B,&H0D80D2BDA,&H0AF0A1B4C,_
&H036034AF6,&H041047A60,&H0DF60EFC3,&H0A867DF55,&H0316E8EEF,_
&H04669BE79,&H0CB61B38C,&H0BC66831A,&H0256FD2A0,&H05268E236,_
&H0CC0C7795,&H0BB0B4703,&H0220216B9,&H05505262F,&H0C5BA3BBE,_
&H0B2BD0B28,&H02BB45A92,&H05CB36A04,&H0C2D7FFA7,&H0B5D0CF31,_
&H02CD99E8B,&H05BDEAE1D,&H09B64C2B0,&H0EC63F226,&H0756AA39C,_
&H0026D930A,&H09C0906A9,&H0EB0E363F,&H072076785,&H005005713,_
&H095BF4A82,&H0E2B87A14,&H07BB12BAE,&H00CB61B38,&H092D28E9B,_
&H0E5D5BE0D,&H07CDCEFB7,&H00BDBDF21,&H086D3D2D4,&H0F1D4E242,_
&H068DDB3F8,&H01FDA836E,&H081BE16CD,&H0F6B9265B,&H06FB077E1,_
&H018B74777,&H088085AE6,&H0FF0F6A70,&H066063BCA,&H011010B5C,_
&H08F659EFF,&H0F862AE69,&H0616BFFD3,&H0166CCF45,&H0A00AE278,_
&H0D70DD2EE,&H04E048354,&H03903B3C2,&H0A7672661,&H0D06016F7,_
&H04969474D,&H03E6E77DB,&H0AED16A4A,&H0D9D65ADC,&H040DF0B66,_
&H037D83BF0,&H0A9BCAE53,&H0DEBB9EC5,&H047B2CF7F,&H030B5FFE9,_
&H0BDBDF21C,&H0CABAC28A,&H053B39330,&H024B4A3A6,&H0BAD03605,_
&H0CDD70693,&H054DE5729,&H023D967BF,&H0B3667A2E,&H0C4614AB8,_
&H05D681B02,&H02A6F2B94,&H0B40BBE37,&H0C30C8EA1,&H05A05DF1B,_
&H02D02EF8D}
option dynamic
FUNCTION _CRC32 (Offset as any ptr, Length as integer, Input_CRC as integer = 0) as integer
	dim memlook as ubyte ptr = cptr( ubyte ptr, offset )
	dim as integer L, a, CRC
	L = Length-1
	CRC = Input_CRC
	FOR a = 0 TO L
		CRC = CRCTable((CINT(CRC) AND 255) XOR memlook[a]) XOR (((CRC AND &HFFFFFF00) \ 256) AND &HFFFFFF)
	NEXT
	_CRC32 = CRC
END FUNCTION

FUNCTION CRC32_File( file as string ) as integer
	dim as integer f, clen, cbuff, fullcrc
	f = freefile
	open file for binary as #f
		clen = lof(f)
		do
			cbuff = 16384
			if cbuff > clen then cbuff = clen
			redim crc32_f_fbuff(cbuff-1) as ubyte
			get #f, , crc32_f_fbuff()
			fullcrc = _CRC32( @crc32_f_fbuff(0), cbuff, fullcrc )
			clen -= cbuff
		loop until clen = 0
	close #f
	return fullcrc
end function
Shouldnt be too hard to convert back to QB
I have left this dump.
Post Reply