Skip to content

Commit

Permalink
Merge pull request #49 from smasherprog/Development
Browse files Browse the repository at this point in the history
Major updates
  • Loading branch information
smasherprog authored Jun 12, 2016
2 parents 3339acd + c52a345 commit 973ee66
Show file tree
Hide file tree
Showing 24 changed files with 419 additions and 250 deletions.
2 changes: 1 addition & 1 deletion Core/ConnectWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace SL {
ptr->Host = host.substr(0, portspecified);
}
else ptr->Host = host;
#if defined(DEBUG) || defined(_DEBUG)
#if defined(DEBUG) || defined(_DEBUG) || !defined(NDEBUG)

if (!ptr->_Config->Public_Certficate) {
ptr->_Config->Public_Certficate = std::static_pointer_cast<Crypto::ICrypoLoader>(std::make_shared<Crypto::InMemoryCrypoLoader>(Crypto::cert.data(), Crypto::cert.size()));
Expand Down
2 changes: 1 addition & 1 deletion Core/ConnectionInfoWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace SL {
else {
auto config = ptr->config;

#if defined(DEBUG) || defined(_DEBUG)
#if defined(DEBUG) || defined(_DEBUG) || !defined(NDEBUG)

if (!config->Private_Key || !config->Public_Certficate || config->Password.empty()) {
config->Private_Key = std::static_pointer_cast<Crypto::ICrypoLoader>(std::make_shared<Crypto::InMemoryCrypoLoader>(Crypto::private_key.data(), Crypto::private_key.size()));
Expand Down
5 changes: 5 additions & 0 deletions Core/Core.project
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@
<VirtualDirectory Name="Crypto">
<File Name="crypto.h"/>
<File Name="crypto.cpp"/>
<File Name="FileCrypoLoader.cpp"/>
<File Name="FileCrypoLoader.h"/>
<File Name="ICrypoLoader.h"/>
<File Name="InMemoryCrypoLoader.cpp"/>
<File Name="InMemoryCrypoLoader.h"/>
</VirtualDirectory>
<Settings Type="Static Library">
<GlobalSettings>
Expand Down
280 changes: 141 additions & 139 deletions Core/Core.vcxitems

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions Core/HttpsSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ namespace SL {

HttpsSocketImpl(IBaseNetworkDriver* netdriver, boost::asio::io_service& io_service, std::shared_ptr<boost::asio::ssl::context> sslcontext) :
_socket(io_service, *sslcontext),
_IBaseNetworkDriver(netdriver),
_read_deadline(io_service),
_write_deadline(io_service),
_IBaseNetworkDriver(netdriver)
_write_deadline(io_service)

{
_read_deadline.expires_at(boost::posix_time::pos_infin);
_write_deadline.expires_at(boost::posix_time::pos_infin);
Expand All @@ -90,13 +91,13 @@ namespace SL {
std::shared_ptr<boost::asio::ssl::context> _ssl_context;
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> _socket;

IBaseNetworkDriver* _IBaseNetworkDriver = nullptr;

IBaseNetworkDriver* _IBaseNetworkDriver;

std::deque<OutgoingPacket> _OutgoingPackets;
std::vector<char> _IncomingBuffer;
boost::asio::deadline_timer _read_deadline;
boost::asio::deadline_timer _write_deadline;

std::deque<OutgoingPacket> _OutgoingPackets;
std::vector<char> _IncomingBuffer;
std::unordered_map<std::string, std::string> _Header;
bool _Server = false;
std::string _Host;
Expand Down Expand Up @@ -129,7 +130,6 @@ namespace SL {
auto compack(std::make_shared<Packet>(std::move(pack)));
_socket.get_io_service().post([self, compack, beforesize]()
{
auto outgoingempty = self->_OutgoingPackets.empty();
self->_OutgoingPackets.push_back({ compack, beforesize });
self->writeheader();

Expand Down Expand Up @@ -377,6 +377,10 @@ namespace SL {
if (ec) SL_RAT_LOG(Utilities::Logging_Levels::ERROR_log_level, "use_certificate_chain_file error " << ec.message());
ec.clear();

sslcontext->set_default_verify_paths(ec);
if (ec) SL_RAT_LOG(Utilities::Logging_Levels::ERROR_log_level, "set_default_verify_paths error " << ec.message());
ec.clear();

boost::asio::const_buffer privkey(config->Private_Key->get_buffer(), config->Private_Key->get_size());
sslcontext->use_private_key(privkey, boost::asio::ssl::context::pem, ec);
if (ec) SL_RAT_LOG(Utilities::Logging_Levels::ERROR_log_level, "use_private_key_file error " << ec.message());
Expand Down
7 changes: 5 additions & 2 deletions Core/ImageControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ namespace SL {

case FL_PUSH:
_ImageControlInfo._MouseCallback(e, Fl::event_button(), Input::Mouse::Press::DOWN, Fl::event_x() + _ImageControlInfo._Scroller->xposition(), Fl::event_y() + _ImageControlInfo._Scroller->yposition());
break;
return 1;
case FL_RELEASE:
_ImageControlInfo._MouseCallback(e, Fl::event_button(), Input::Mouse::Press::UP, Fl::event_x() + _ImageControlInfo._Scroller->xposition(), Fl::event_y() + _ImageControlInfo._Scroller->yposition());
break;
break;
case FL_ENTER:
return 1;
case FL_DRAG:
case FL_MOUSEWHEEL:
case FL_MOVE:
Expand All @@ -161,6 +163,7 @@ namespace SL {
_ImageControlInfo._KeyCallback(e, Input::Keyboard::Press::UP);
return 1;
case FL_FOCUS:

return 1;
default:
break;
Expand Down
108 changes: 100 additions & 8 deletions Core/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,50 @@
#define SL_DIVIDE 0xf06F

#if _WIN32

unsigned int Map_ToPlatformKey(unsigned int key) {
if (key >= 0x0030 && key <= 0x0039) return key;//VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39)
else if (key >= 0x0041 && key <= 0x005A) {//VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A)
return key;// regular ascii alphabet characters
}
else if (key >= 0x0061 && key <= 0x007a) {
return key - static_cast<unsigned int>('a' - 'A');//on windows, the keys are always in CAPS...
}

switch (key) {

case (FL_BackSpace):
return VK_BACK;
case (FL_Tab):
return VK_TAB;
case (FL_Enter):
return VK_RETURN;
case(' '):
return VK_SPACE;

case('='):
return VK_OEM_PLUS;
case(','):
return VK_OEM_COMMA;
case('-'):
return VK_OEM_MINUS;
case('.'):
return VK_OEM_PERIOD;
case (';'):
return VK_OEM_1;
case('/'):
return VK_OEM_2;
case('`'):
return VK_OEM_3;
case('['):
return VK_OEM_4;
case('\\'):
return VK_OEM_5;
case(']'):
return VK_OEM_6;
case('\''):
return VK_OEM_7;

case (FL_Help):
return VK_HELP;
case (FL_Shift_L):
Expand Down Expand Up @@ -136,6 +178,40 @@ unsigned int Map_ToPlatformKey(unsigned int key) {
return VK_F24;
case (FL_Num_Lock):
return VK_NUMLOCK;
case (FL_KP +'0'):
return VK_NUMPAD0;
case (FL_KP + '1'):
return VK_NUMPAD1;
case (FL_KP + '2'):
return VK_NUMPAD2;
case (FL_KP + '3'):
return VK_NUMPAD3;
case (FL_KP + '4'):
return VK_NUMPAD4;
case (FL_KP + '5'):
return VK_NUMPAD5;
case (FL_KP + '6'):
return VK_NUMPAD6;
case (FL_KP + '7'):
return VK_NUMPAD7;
case (FL_KP + '8'):
return VK_NUMPAD8;
case (FL_KP + '9'):
return VK_NUMPAD9;
case (FL_KP + '/'):
return VK_DIVIDE;
case (FL_KP + '*'):
return VK_MULTIPLY;
case (FL_KP + '-'):
return VK_SUBTRACT;
case (FL_KP + '+'):
return VK_ADD;
case (FL_KP + '.'):
return VK_DECIMAL;

case (FL_KP_Enter):
return VK_RETURN;

case (FL_Scroll_Lock):
return VK_SCROLL;
case (FL_Volume_Down):
Expand All @@ -159,7 +235,14 @@ unsigned int Map_ToPlatformKey(unsigned int key) {

#elif __linux__
unsigned int Map_ToPlatformKey(unsigned int key) {
switch (key) {
switch (key) {
case (FL_BackSpace):
return XK_BackSpace;
case (FL_Tab):
return XK_Tab;
case (FL_Enter):
return XK_Return;

case (FL_Help):
return XK_Help;
case (FL_Shift_L):
Expand Down Expand Up @@ -294,20 +377,28 @@ void SL::Remote_Access_Library::Input::SimulateKeyboardEvent(KeyEvent ev)
{
SL_RAT_LOG(Utilities::Logging_Levels::INFO_log_level, "Received SetKeyEvent Key:" << ev.Key << " SpecialKey: " << ev.SpecialKey << " PressData: " << ev.PressData);
if (ev.Key == 0) return;//unmapped key
#if _WIN32
ev.Key = Map_ToPlatformKey(ev.Key);
#else

if (ev.Key & 0xf000) {//special key, needs to be mapped to platform specific code
ev.Key = Map_ToPlatformKey(ev.Key);
}//must be ascii char, do a check to make sure it is actually an ascii char. Below are the hex values of ascii chars
else if ( ev.Key != 0x0008 && ev.Key != 0x0009 && ev.Key != 0x000d && ev.Key != 0x0020 && ev.Key != 0x0027 && !(ev.Key >= 0x002b && ev.Key <= 0x007f)) {
else if (ev.Key != 0x0020 && ev.Key != 0x0027 && !(ev.Key >= 0x002b && ev.Key <= 0x007f)) {
SL_RAT_LOG(Utilities::Logging_Levels::Debug_log_level, "Recevied a key event which is outside of the asci char set");
return;
}
#endif

if (ev.Key == 0) {//no mapping available
SL_RAT_LOG(Utilities::Logging_Levels::Debug_log_level, "No Mapping Available for key");
return;
}

#if _WIN32



INPUT input;
memset(&input, 0, sizeof(input));
input.type = INPUT_KEYBOARD;
Expand All @@ -320,20 +411,21 @@ void SL::Remote_Access_Library::Input::SimulateKeyboardEvent(KeyEvent ev)

#elif __ANDROID__

hkl
#elif __linux__


auto display = XOpenDisplay(NULL);
auto keycode = XKeysymToKeycode(display, ev.Key);
SL_RAT_LOG(Utilities::Logging_Levels::Debug_log_level, "AFter XKeysymToKeycode '"<<keycode<<"'");
SL_RAT_LOG(Utilities::Logging_Levels::Debug_log_level, "AFter XKeysymToKeycode '" << keycode << "'");
if (keycode == 0) return;
XTestGrabControl(display, True);
//XTestGrabControl(display, True);

XTestFakeKeyEvent(display, keycode, ev.PressData == Keyboard::Press::DOWN ? True : False, 0);
XSync(display, False);
XTestGrabControl(display, False);
XTestFakeKeyEvent(display, keycode, ev.PressData == Keyboard::Press::DOWN ? True : False, CurrentTime);
//XSync(display, True);
//XTestGrabControl(display, False);
XCloseDisplay(display);
std::this_thread::sleep_for(std::chrono::milliseconds(1));

#endif

Expand Down
6 changes: 3 additions & 3 deletions Core/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace SL {
UP,
DOWN
};
enum Specials : unsigned int {
enum Specials : unsigned int {
NO_PRESS_DATA,
ALT,
CTRL,
SHIFT,
NO_PRESS_DATA
SHIFT
};
}

Expand Down
5 changes: 5 additions & 0 deletions Core/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ void SL::Remote_Access_Library::Utilities::Log(Logging_Levels level, const char*


#else





std::cout << Logging_level_Names[level] << ": FILE: " << file << " Line: " << line << " Func: " << func << " Msg: " << data.str() << std::endl;

#endif
Expand Down
59 changes: 41 additions & 18 deletions Core/Mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,54 @@ namespace SL
{
auto desktopdc = RAIIHDC(GetDC(NULL));
auto capturedc = RAIIHDC(CreateCompatibleDC(desktopdc.get()));
auto capturebmp = RAIIHBITMAP(
CreateCompatibleBitmap(desktopdc.get(), 32, 32)); // 32 x 32 is the biggest allowed for windows...
if (!desktopdc || !capturedc || !capturebmp)
auto capturebmp = RAIIHBITMAP(CreateCompatibleBitmap(desktopdc.get(), 32, 32)); // 32 x 32 is the biggest allowed for windows...
if (!desktopdc || !capturedc || !capturebmp) {
SL_RAT_LOG(Utilities::Logging_Levels::ERROR_log_level, "Couldnt get Init DC!");
return Utilities::Image::CreateImage(0, 0);
}


auto originalBmp = SelectObject(capturedc.get(), capturebmp.get());

CURSORINFO cursorInfo;
cursorInfo.cbSize = sizeof(cursorInfo);
if (GetCursorInfo(&cursorInfo) == FALSE)
if (GetCursorInfo(&cursorInfo) == FALSE) {
SL_RAT_LOG(Utilities::Logging_Levels::ERROR_log_level, "GetCursorInfo == FALSE");
return Utilities::Image::CreateImage(0, 0);

ICONINFOEX ii = { 0 };
}
ICONINFOEXA ii = { 0 };
ii.cbSize = sizeof(ii);
if (GetIconInfoEx(cursorInfo.hCursor, &ii) == FALSE)
if (GetIconInfoExA(cursorInfo.hCursor, &ii) == FALSE) {
//this tends to fail on hyper-v enviornments generating alot of noise. so lower its level to Info..
SL_RAT_LOG(Utilities::Logging_Levels::INFO_log_level, "GetIconInfoEx == FALSE");
return Utilities::Image::CreateImage(0, 0);
}
auto colorbmp = RAIIHBITMAP(ii.hbmColor); // make sure this is cleaned up properly
auto maskbmp = RAIIHBITMAP(ii.hbmMask); // make sure this is cleaned up properly
if (DrawIcon(capturedc.get(), 0, 0, cursorInfo.hCursor) == FALSE)
if (DrawIcon(capturedc.get(), 0, 0, cursorInfo.hCursor) == FALSE) {
SL_RAT_LOG(Utilities::Logging_Levels::ERROR_log_level, "DrawIcon == FALSE");
return Utilities::Image::CreateImage(0, 0);
}
BITMAP bm;
int height = 0;
bm.bmWidth = 32;
int width = 0;
if (ii.hbmColor != NULL) {
GetObject(colorbmp.get(), sizeof(bm), &bm);
height = bm.bmHeight;

if (GetObject(colorbmp.get(), sizeof(bm), &bm) != NULL) {
height = bm.bmHeight;
width = bm.bmWidth;
}
}
else if (ii.hbmMask != NULL) {
GetObject(maskbmp.get(), sizeof(bm), &bm);
height = bm.bmHeight / 2;
if (GetObject(maskbmp.get(), sizeof(bm), &bm) != NULL) {
height = bm.bmHeight / 2;
width = bm.bmWidth;
}
}
if (height <= 0 || width <= 0 || height > 32 || width > 32) {
SL_RAT_LOG(Utilities::Logging_Levels::ERROR_log_level, "Cursor dimensions are outside normal sizes, could be an error");
return Utilities::Image::CreateImage(0, 0);
}
int width = bm.bmWidth;


BITMAPINFOHEADER bi;
memset(&bi, 0, sizeof(bi));
Expand All @@ -72,6 +87,7 @@ namespace SL
bi.biSizeImage = ((width * bi.biBitCount + 31) / 32) * 4 * height;

auto retimg(Utilities::Image::CreateImage(width, height));

GetDIBits(desktopdc.get(), capturebmp.get(), 0, (UINT)height, retimg->data(), (BITMAPINFO*)&bi, DIB_RGB_COLORS);

SelectObject(capturedc.get(), originalBmp);
Expand All @@ -98,11 +114,18 @@ namespace SL
Utilities::Point pos;
CURSORINFO cursorInfo;
cursorInfo.cbSize = sizeof(cursorInfo);
GetCursorInfo(&cursorInfo);
if(GetCursorInfo(&cursorInfo) == FALSE) {
SL_RAT_LOG(Utilities::Logging_Levels::ERROR_log_level, "GetCursorInfo == FALSE");
return pos;
}

ICONINFOEX ii = { 0 };
ICONINFOEXA ii = { 0 };
ii.cbSize = sizeof(ii);
GetIconInfoEx(cursorInfo.hCursor, &ii);
if(GetIconInfoExA(cursorInfo.hCursor, &ii) == FALSE) {
//this tends to fail on hyper-v enviornments generating alot of noise. so lower its level to Info..
SL_RAT_LOG(Utilities::Logging_Levels::INFO_log_level, "GetIconInfoEx == FALSE");
return pos;
}
auto colorbmp = RAIIHBITMAP(ii.hbmColor); // make sure this is cleaned up properly
auto maskbmp = RAIIHBITMAP(ii.hbmMask); // make sure this is cleaned up properly

Expand Down
Loading

0 comments on commit 973ee66

Please sign in to comment.