Android Question Decryption Error

nazilabdulla

Member
Licensed User
Longtime User
Decryption Code:
Sub DecryptFile (SFile As String,DFile As String, Password As String)As ResumableSub
Dim size As Long = File.Size(SFile, "")
Dim rafInput, rafOutput As RandomAccessFile
rafInput.Initialize(SFile, "", True)
rafOutput.Initialize(DFile, "", False)
Dim b() As Byte
Dim enc As B4XCipher
Do While rafInput.CurrentPosition < size
Dim blockLength As Int = rafInput.ReadInt(rafInput.CurrentPosition)
If b.Length <> blockLength Then
Dim b(blockLength) As Byte
End If
rafInput.ReadBytes(b, 0, b.Length, rafInput.CurrentPosition)
Dim bb() As Byte = enc.Decrypt(b, Password)
rafOutput.WriteBytes(bb, 0, bb.Length, rafOutput.CurrentPosition)
' ProgressBar1.Progress = rafInput.CurrentPosition / size
Sleep(30)
Loop
rafInput.Close
rafOutput.Close
Return True
End Sub


ERROR:
Copying updated assets files (20)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 193 (CommonClass)
java.lang.NegativeArraySizeException: Dimension 0: -1571423762
    at java.lang.reflect.Array.createMultiArray(Native Method)
    at java.lang.reflect.Array.newInstance(Array.java:335)
    at anywheresoftware.b4a.shell.ArraysUtils.createArray(ArraysUtils.java:39)
    at anywheresoftware.b4a.shell.Shell.createArray(Shell.java:576)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:380)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
    at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1705)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6892)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

The file which need to decrypt , is attached here.
Password : 123456
 

Attachments

  • master.txt
    51.5 KB · Views: 131

OliverA

Expert
Licensed User
Longtime User
Either 1) your input file is corrupt or 2) the method to read the file is not correct.

Currently, you are reading 4 bytes which give a block length. The first read gives you a block length of 52552. The second read (at position 52556) returns the -1571423762 (or adjusted for an unsigned integer: 2723543533). The file only has 52732 bytes. Therefore either 1) the input data is corrupt or 2) position 52556 does not contain a block size (and you are reading the file incorrectly).
 
Upvote 0
Top