diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6f343cc --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +all : gmain cmain + +clean : + rm -f gmain + rm -f cmain + +grun : gmain + ./gmain + +crun : cmain + ./cmain + + +gmain : main.cpp + g++ -Wall -O2 -std=c++11 -pthread -lrt -o gmain main.cpp + +cmain : main.cpp + clang++ -Wall -O2 -std=c++11 -stdlib=libc++ -pthread -lrt -o cmain main.cpp + + +.PHONY : all clean run diff --git a/README.md b/README.md index 4f4d5b6..19c3605 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,31 @@ Publicly available documents already discuss exfiltration from secured systems u How to Use It ------------------ -Compile the problem using: +You need a decent C++11 implementation(GCC or Clang) +Compile the program by make: - gcc main.c -Wall -O2 -o main +If you have GCC: -And run it on an Apple MacBook Air (13-inch, Early 2015): + make gmain + +If you have Clang: + + make cmain + +If you have both: + + make + +And run it on your computer: + +For GCC: + + make grun + +For Clang: + + make crun - ./main Then use a Sony STR-K670P radio receiver with the included antenna and tune it to 1580 kHz on AM. diff --git a/main.c b/main.c deleted file mode 100644 index 5218224..0000000 --- a/main.c +++ /dev/null @@ -1,78 +0,0 @@ -// SYSTEM BUS RADIO -// https://github.com/fulldecent/system-bus-radio -// Copyright 2016 William Entriken - -#include -#include -#include -#include -#include - -__m128i reg; -__m128i reg_zero; -__m128i reg_one; -mach_port_t clock_port; -mach_timespec_t remain; - -static inline void square_am_signal(float time, float frequency) { - printf("Playing / %0.3f seconds / %4.0f Hz\n", time, frequency); - uint64_t period = NSEC_PER_SEC / frequency; - - uint64_t start = mach_absolute_time(); - uint64_t end = start + time * NSEC_PER_SEC; - - while (mach_absolute_time() < end) { - uint64_t mid = start + period / 2; - uint64_t reset = start + period; - while (mach_absolute_time() < mid) { - _mm_stream_si128(®, reg_one); - _mm_stream_si128(®, reg_zero); - } - clock_sleep_trap(clock_port, TIME_ABSOLUTE, reset / NSEC_PER_SEC, reset % NSEC_PER_SEC, &remain); - start = reset; - } -} - -int main() -{ - mach_timebase_info_data_t theTimeBaseInfo; - mach_timebase_info(&theTimeBaseInfo); - puts("TESTING TIME BASE: the following should be 1 / 1"); - printf(" Mach base: %u / %u nanoseconds\n\n", theTimeBaseInfo.numer, theTimeBaseInfo.denom); - - uint64_t start = mach_absolute_time(); - uint64_t end = mach_absolute_time(); - printf("TESTING TIME TO EXECUTE mach_absolute_time()\n Result: %lld nanoseconds\n\n", end - start); - - reg_zero = _mm_set_epi32(0, 0, 0, 0); - reg_one = _mm_set_epi32(-1, -1, -1, -1); - - while (1) { - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2093); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2673); - square_am_signal(0.790, 2673); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2349); - square_am_signal(0.790, 2349); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 3136); - square_am_signal(0.790, 3136); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2093); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2349); - square_am_signal(0.790, 2093); - } -} diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e3770a4 --- /dev/null +++ b/main.cpp @@ -0,0 +1,73 @@ +// SYSTEM BUS RADIO +// https://github.com/fulldecent/system-bus-radio +// Copyright 2016 William Entriken +// C++11 port by Ryou Ezoe + +#include +#include +#include +#include +#include + +void square_am_signal(float time, float frequency) +{ + using namespace std::chrono ; + + std::cout << "Playing / " << time << " seconds / " << frequency << " Hz\n" ; + + seconds const sec{1} ; + nanoseconds const nsec{ sec } ; + using rep = nanoseconds::rep ; + auto nsec_per_sec = nsec.count() ; + + nanoseconds const period( static_cast( nsec_per_sec / frequency) ) ; + + auto start = high_resolution_clock::now() ; + auto const end = start + nanoseconds( static_cast(time * nsec_per_sec) ) ; + + while (high_resolution_clock::now() < end) + { + auto mid = start + period / 2 ; + auto reset = start + period ; + while (high_resolution_clock::now() < mid) + { + std::atomic x{0} ; + ++x ; + } + std::this_thread::sleep_until( reset ) ; + start = reset; + } +} + +int main() +{ + while (1) + { + square_am_signal(0.400, 2673); + square_am_signal(0.400, 2349); + square_am_signal(0.400, 2093); + square_am_signal(0.400, 2349); + square_am_signal(0.400, 2673); + square_am_signal(0.400, 2673); + square_am_signal(0.790, 2673); + square_am_signal(0.400, 2349); + square_am_signal(0.400, 2349); + square_am_signal(0.790, 2349); + square_am_signal(0.400, 2673); + square_am_signal(0.400, 3136); + square_am_signal(0.790, 3136); + square_am_signal(0.400, 2673); + square_am_signal(0.400, 2349); + square_am_signal(0.400, 2093); + square_am_signal(0.400, 2349); + square_am_signal(0.400, 2673); + square_am_signal(0.400, 2673); + square_am_signal(0.400, 2673); + square_am_signal(0.400, 2673); + square_am_signal(0.400, 2349); + square_am_signal(0.400, 2349); + square_am_signal(0.400, 2673); + square_am_signal(0.400, 2349); + square_am_signal(0.790, 2093); + } +}