Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2016-06-12 23:26:11 +0300
committerJames Almer <jamrial@gmail.com>2016-06-12 23:26:43 +0300
commit15f9189b9cc826b02e423b39a8fabad842d50359 (patch)
tree00fb22451ef90ebea47fa519ee28fc1fe203e2cf /libavformat/redspark.c
parent8fdad638f92223c6c6f6e36fabaf42e8324fcbae (diff)
avformat/redspark: deobfuscate header decrypt code
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat/redspark.c')
-rw-r--r--libavformat/redspark.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/libavformat/redspark.c b/libavformat/redspark.c
index 764b23ec04..c247046584 100644
--- a/libavformat/redspark.c
+++ b/libavformat/redspark.c
@@ -26,6 +26,7 @@
#include "internal.h"
#define HEADER_SIZE 4096
+#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
typedef struct RedSparkContext {
int samples_count;
@@ -38,11 +39,13 @@ static int redspark_probe(AVProbeData *p)
/* Decrypt first 8 bytes of the header */
data = AV_RB32(p->buf);
- data = data ^ (key = data ^ 0x52656453);
+ key = data ^ 0x52656453;
+ data ^= key;
AV_WB32(header, data);
- key = (key << 11) | (key >> 21);
+ key = rol(key, 11);
- data = AV_RB32(p->buf + 4) ^ (((key << 3) | (key >> 29)) + key);
+ key += rol(key, 3);
+ data = AV_RB32(p->buf + 4) ^ key;
AV_WB32(header + 4, data);
if (AV_RB64(header) == AV_RB64("RedSpark"))
@@ -69,12 +72,14 @@ static int redspark_read_header(AVFormatContext *s)
/* Decrypt header */
data = avio_rb32(pb);
- data = data ^ (key = data ^ 0x52656453);
+ key = data ^ 0x52656453;
+ data ^= key;
AV_WB32(header, data);
- key = (key << 11) | (key >> 21);
+ key = rol(key, 11);
for (i = 4; i < HEADER_SIZE; i += 4) {
- data = avio_rb32(pb) ^ (key = ((key << 3) | (key >> 29)) + key);
+ key += rol(key, 3);
+ data = avio_rb32(pb) ^ key;
AV_WB32(header + i, data);
}