# HG changeset patch # User Mychaela Falconia # Date 1678558582 0 # Node ID ceb71478414dc20127f3a75f6f0c1c8bd254e51b # Parent 50c0fac9a4a814768e1b92fee7daff7a25c8afaf tfo: find-is-hdr program written diff -r 50c0fac9a4a8 -r ceb71478414d .hgignore --- a/.hgignore Sun Jan 15 00:54:33 2023 +0000 +++ b/.hgignore Sat Mar 11 18:16:22 2023 +0000 @@ -82,3 +82,5 @@ ^pirollback/dumpjournal$ ^pirollback/inopath$ ^pirollback/rollback$ + +^tfo/find-is-hdr$ diff -r 50c0fac9a4a8 -r ceb71478414d tfo/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tfo/Makefile Sat Mar 11 18:16:22 2023 +0000 @@ -0,0 +1,14 @@ +CC= gcc +CFLAGS= -O2 +STD= find-is-hdr +PROGS= ${STD} + +all: ${PROGS} + +${STD}: + ${CC} ${CFLAGS} -o $@ $@.c + +find-is-hdr: find-is-hdr.c + +clean: + rm -f ${PROGS} *.o *errs *.out diff -r 50c0fac9a4a8 -r ceb71478414d tfo/find-is-hdr.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tfo/find-is-hdr.c Sat Mar 11 18:16:22 2023 +0000 @@ -0,0 +1,81 @@ +/* + * This program reads a binary file containing a G.711 PCM stream capture + * and looks for an IS_Header pattern as defined in ETSI TS 101 504 + * (GSM 08.62) section A.1.2. The objective is to analyze PCM streams + * originating from extant commercial GSM network operators and see if + * they implement in-band TFO. + */ + +#include +#include +#include +#include +#include +#include +#include + +static char *pcmfile; +static size_t pcm_file_size; +static u_char *filemap; + +static const u_char hdr_pattern[20] = {0, 1, 0, 1, 0, 1, 1, 0, 1, 0, + 0, 1, 1, 0, 1, 0, 1, 0, 0, 1}; + +static void +mmap_pcm_file() +{ + int fd; + struct stat st; + + fd = open(pcmfile, O_RDONLY); + if (fd < 0) { + perror(pcmfile); + exit(1); + } + fstat(fd, &st); + if (!S_ISREG(st.st_mode)) { + fprintf(stderr, "error: %s is not a regular file\n", pcmfile); + exit(1); + } + pcm_file_size = st.st_size; + if (pcm_file_size < 320) { + fprintf(stderr, "error: %s is too short\n", pcmfile); + exit(1); + } + filemap = mmap(NULL, pcm_file_size, PROT_READ, MAP_PRIVATE, fd, 0L); + if (filemap == MAP_FAILED) { + perror("mmap"); + exit(1); + } + close(fd); +} + +static void +try_offset(offset) + size_t offset; +{ + unsigned n; + + for (n = 0; n < 20; n++) { + if ((filemap[offset + n * 16] & 1) != hdr_pattern[n]) + return; + } + printf("Found IS_Header at offset %lu\n", (u_long) offset); +} + +main(argc, argv) + char **argv; +{ + size_t offset, endoff; + + if (argc != 2) { + fprintf(stderr, "usage: %s pcm-capture-file\n", argv[0]); + exit(1); + } + pcmfile = argv[1]; + mmap_pcm_file(); + endoff = pcm_file_size - 320; + for (offset = 0; offset <= endoff; offset++) + try_offset(offset); + exit(0); +}