C++11 port

This commit is contained in:
Ryou Ezoe 2016-03-02 17:30:06 +09:00
parent 681e525aac
commit 9b4a17c757
4 changed files with 116 additions and 82 deletions

21
Makefile Normal file
View File

@ -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

View File

@ -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.

78
main.c
View File

@ -1,78 +0,0 @@
// SYSTEM BUS RADIO
// https://github.com/fulldecent/system-bus-radio
// Copyright 2016 William Entriken
#include <stdio.h>
#include <emmintrin.h>
#include <mach/mach_traps.h>
#include <mach/mach_time.h>
#include <math.h>
__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, reg_one);
_mm_stream_si128(&reg, 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);
}
}

73
main.cpp Normal file
View File

@ -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 <iostream>
#include <iomanip>
#include <chrono>
#include <thread>
#include <atomic>
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<rep>( nsec_per_sec / frequency) ) ;
auto start = high_resolution_clock::now() ;
auto const end = start + nanoseconds( static_cast<rep>(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<unsigned> 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);
}
}