From 9aef335996b3b4419f4b84ae50d064b2ddf69817 Mon Sep 17 00:00:00 2001 From: AShiningRay Date: Thu, 5 Dec 2024 17:15:40 -0300 Subject: [PATCH] PlatformPlayer: Add checks for Qualcomm's PureVoice format Ultra rare, and not likely to be supported at all, but it exists and is used by a samsung version of 3D Hunting Grizzly. Might as well notify of this format whenever it comes up. Also, add array size checks on all conditionals. --- src/org/recompile/mobile/PlatformPlayer.java | 21 +++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/org/recompile/mobile/PlatformPlayer.java b/src/org/recompile/mobile/PlatformPlayer.java index dd965d91..78e3e803 100644 --- a/src/org/recompile/mobile/PlatformPlayer.java +++ b/src/org/recompile/mobile/PlatformPlayer.java @@ -106,43 +106,50 @@ else if(contentType.equalsIgnoreCase("audio/mpeg") || contentType.equalsIgnoreCa final byte[] data = new byte[stream.available()]; stream.read(data, 0, stream.available()); - if(data[0] == 'M' && data[1] == 'T' && data[2] == 'h' && data[3] == 'd') + if(data.length >= 4 && data[0] == 'M' && data[1] == 'T' && data[2] == 'h' && data[3] == 'd') { Mobile.log(Mobile.LOG_WARNING, PlatformPlayer.class.getPackage().getName() + "." + PlatformPlayer.class.getSimpleName() + ": " + "Format is MIDI!"); player = new midiPlayer(new ByteArrayInputStream(data)); contentType = "audio/mid"; } - else if(data[0] == 'R' && data[1] == 'I' && data[2] == 'F' && data[3] == 'F') + else if (data.length >= 15 && data[8] == 'Q' && data[9] == 'L' && data[10] == 'C' && data[11] == 'M' && data[12] == 'f' && data[13] == 'm' && data[14] == 't') + { + // This is for Qualcomm's QCP format, it has to be checked before wav, because Qualcomm's PureVoice also has RIFF as its first bytes + Mobile.log(Mobile.LOG_WARNING, PlatformPlayer.class.getPackage().getName() + "." + PlatformPlayer.class.getSimpleName() + ": " + "Format is Qualcomm PureVoice! (not supported yet)"); + player = new audioplayer(); + contentType = "audio/qcp"; + } + else if(data.length >= 4 && data[0] == 'R' && data[1] == 'I' && data[2] == 'F' && data[3] == 'F') { Mobile.log(Mobile.LOG_WARNING, PlatformPlayer.class.getPackage().getName() + "." + PlatformPlayer.class.getSimpleName() + ": " + "Format is WAV!"); player = new wavPlayer(new ByteArrayInputStream(data)); contentType = "audio/wav"; } - else if(data[0] == 'I' && data[1] == 'D' && data[2] == '3' || ((data[0] == (byte) 0xFF) && (data[1] & 0xE0) == 0xE0)) // Check for MPEG files WITH and WITHOUT the ID3 tag + else if(data.length >= 3 && data[0] == 'I' && data[1] == 'D' && data[2] == '3' || ((data[0] == (byte) 0xFF) && (data[1] & 0xE0) == 0xE0)) // Check for MPEG files WITH and WITHOUT the ID3 tag { Mobile.log(Mobile.LOG_WARNING, PlatformPlayer.class.getPackage().getName() + "." + PlatformPlayer.class.getSimpleName() + ": " + "Format is MPEG!"); player = new MP3Player(new ByteArrayInputStream(data)); contentType = "audio/mpeg"; } - else if(data[0] == 'M' && data[1] == 'M' && data[2] == 'M' && data[3] == 'D') + else if(data.length >= 4 && data[0] == 'M' && data[1] == 'M' && data[2] == 'M' && data[3] == 'D') { Mobile.log(Mobile.LOG_WARNING, PlatformPlayer.class.getPackage().getName() + "." + PlatformPlayer.class.getSimpleName() + ": " + "Format is SMAF/MMF! (not supported yet)"); player = new audioplayer(); contentType = "audio/mmf"; } - else if(data[0] == 'm' && data[1] == 'e' && data[2] == 'l' && data[3] == 'o') + else if(data.length >= 4 && data[0] == 'm' && data[1] == 'e' && data[2] == 'l' && data[3] == 'o') { Mobile.log(Mobile.LOG_WARNING, PlatformPlayer.class.getPackage().getName() + "." + PlatformPlayer.class.getSimpleName() + ": " + "Format is MFi! (not supported yet)"); player = new audioplayer(); contentType = "audio/mfi"; } - else if (data.length >= 6 && data[0] == '#' && data[1] == '!' && data[2] == 'A' && data[3] == 'M' && data[4] == 'R' && data[5] == '\n') + else if(data.length >= 6 && data[0] == '#' && data[1] == '!' && data[2] == 'A' && data[3] == 'M' && data[4] == 'R' && data[5] == '\n') { Mobile.log(Mobile.LOG_WARNING, PlatformPlayer.class.getPackage().getName() + "." + PlatformPlayer.class.getSimpleName() + ": " + "Format is AMR-NB! (not supported yet)"); player = new audioplayer(); contentType = "audio/amr"; } - else if (data.length >= 9 && data[0] == '#' && data[1] == '!' && data[2] == 'A' && data[3] == 'M' && data[4] == 'R' && data[5] == '-' && data[6] == 'W' && data[7] == 'B' && data[8] == '\n') + else if(data.length >= 9 && data[0] == '#' && data[1] == '!' && data[2] == 'A' && data[3] == 'M' && data[4] == 'R' && data[5] == '-' && data[6] == 'W' && data[7] == 'B' && data[8] == '\n') { Mobile.log(Mobile.LOG_WARNING, PlatformPlayer.class.getPackage().getName() + "." + PlatformPlayer.class.getSimpleName() + ": " + "Format is AMR-WB! (not supported yet)"); player = new audioplayer();