Created
November 3, 2018 23:47
-
-
Save countingpine/3ae31a152bde15a54068e6c864b221b3 to your computer and use it in GitHub Desktop.
tvsread.c - dump contents of KEY chunks in TeamViewer ".tvs" videos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* tvsread.c: lists KEY chunks in video and uncompresses them to ./key1.data, ./key2.data, ... */ | |
/* See also http://www.jerrysguide.com/tips/demystify-tvs-file-format.html, https://stackoverflow.com/a/53135938/446106 */ | |
/* Fairly quick and dirty. Tested with a Version 5 video from TeamViewer 13. */ | |
/* compile with gcc -lz tvsread.c */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <zlib.h> | |
int main(int arg_c, char **arg_v) { | |
FILE *infile, *outfile; | |
void *cbuf = 0, *ubuf = 0; | |
int clen, ulen; uLongf ulen2; | |
int keycount = 0; | |
char keyfilename[256]; | |
unsigned char line[1024]; | |
char name[4]; | |
infile = fopen(arg_v[1], "rb"); if (!infile) return 1; | |
/* plain text at beginning */ | |
while (memcmp(line, "BEGIN", 5) && !feof(infile)) { | |
fgets(line, 1024, infile); | |
strtok(line, "\n"); | |
puts(line); | |
} | |
/* list of "KEY" chunks - 3-byte name, compressed length, uncompressed length */ | |
printf("%s:\t%3s\t%s\t%s\n", "offset", "name", "len", "ulen"); | |
while (!feof(infile)) { | |
unsigned char key[11]; | |
fread(key, 1, 11, infile); | |
memcpy(name, key, 3); name[3] = '\0'; | |
if (memcmp(name, "KEY", 3)) break; | |
clen = key[3] | key[4] << 8 | key[5] << 16 | key[6] << 24; | |
ulen = key[7] | key[8] << 8 | key[9] << 16 | key[10] << 24; | |
printf("%8x:\t%s\t%d\t%d\n", ftell(infile), name, clen, ulen); | |
if (!(cbuf = realloc(cbuf, clen))) return -1; | |
if (!(ubuf = realloc(ubuf, ulen))) return -1; | |
#if 0 | |
/* skip chunk data */ | |
fseek(infile, clen, SEEK_CUR); | |
#else | |
/* uncompress chunk data and dump to file */ | |
fread(cbuf, 1, clen, infile); | |
ulen2 = ulen; | |
uncompress(ubuf, &ulen2, cbuf, clen); | |
sprintf(keyfilename, "key%d.data", ++keycount); | |
outfile = fopen(keyfilename, "wb"); if (!outfile) break; | |
fwrite(ubuf, 1, ulen2, outfile); | |
fclose(outfile); | |
#endif | |
} | |
fclose(infile); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment