B4J Question Getting total size of Asset files

MegatenFreak

Active Member
Licensed User
Hi.
Is there a way to find the collective total size of all files in the app's Assets when the app runs?
The File.Size and other methods apparently don't work on asset files.
(the purpose is to make sure those files weren't somehow tampered with, without the lengthy/complex methods of CRC checking and stuff)
 

MegatenFreak

Active Member
Licensed User
In that case, I'll have to load each file and recalculate the CRC and compare it to the original one, right?
What's the fast CRC calculation method for that purpose? Should I use a library or implement an algorithm myself?
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Be aware that you have no control over what happens to the program and therefore your security measure(s) in the APK with the user.

OliverA CRC calculation:
Sub Process_Globals
    Dim mHexImage() As Byte
End Sub

Sub AppStart (Args() As String)
    Log("Hello world!!!")
    Dim aString As String = "Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» " & Chr(0)
    mHexImage = aString.GetBytes("iso-8859-1")
    'Log($"10: ${mHexImage(10)}, 11: ${mHexImage(11)}"$)
    Log($"CRC value: ${Get_Buf_CRC(0, 221)}"$)
End Sub

Sub Get_Buf_CRC( buf_offset As Int, numBytes As Int) As Int ' needs unsigned int16
    Dim crc As Int = 0, i As Int
    For i = 0 To numBytes-1
        crc = UpdateCRC( crc, mHexImage(buf_offset + i))
    Next
    Return crc
End Sub
    
Sub UpdateCRC( crc As Int, newbyte As Byte ) As Int
    Dim CRCpoly As Int = 0x8408        ' CRC16-CCITT FCS (X^16+X^12+X^5+1)
    Dim i As Int

    crc = Bit.Xor( crc, Bit.And(newbyte, 0xFF) )
    For i = 0 To 7
        If Bit.And( crc, 0x0001 ) = 1 Then
            crc = crc/2
            crc = Bit.Xor( crc, CRCpoly )
        Else
            crc = crc/2
        End If
    Next
    Return crc
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…