Skip to content

Commit

Permalink
Remove string encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
namazso committed Jul 15, 2023
1 parent 877aab8 commit e3c6c63
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 224 deletions.
2 changes: 1 addition & 1 deletion AlgorithmsDlls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ foreach (FLAVOR ${FLAVORS})
PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/AlgorithmsDll_${FLAVOR}.dll")
set_property(TARGET "AlgorithmsDll_${FLAVOR}"
PROPERTY PDB_NAME "${CMAKE_CURRENT_SOURCE_DIR}/AlgorithmsDll_${FLAVOR}.pdb")
target_link_options("AlgorithmsDll_${FLAVOR}" INTERFACE "/DELAYLOAD:AlgorithmsDll_${FLAVOR}")
target_link_options("AlgorithmsDll_${FLAVOR}" INTERFACE "/DELAYLOAD:AlgorithmsDll_${FLAVOR}.dll")

target_link_libraries(AlgorithmsDlls INTERFACE "AlgorithmsDll_${FLAVOR}")
endforeach ()
2 changes: 2 additions & 0 deletions OpenHashTab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target_link_libraries(OpenHashTab PRIVATE
concurrentqueue
tiny-json
ntdll.lib
winhttp.lib
)

target_compile_definitions(OpenHashTab PRIVATE
Expand All @@ -32,6 +33,7 @@ target_compile_options(OpenHashTab PRIVATE
target_link_options(OpenHashTab PRIVATE
/EXPORT:DllCanUnloadNow
/EXPORT:DllGetClassObject
/DELAYLOAD:winhttp.dll
)

target_precompile_headers(OpenHashTab PRIVATE stdafx.h)
Expand Down
15 changes: 8 additions & 7 deletions OpenHashTab/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "SettingsDialog.h"

#include "Settings.h"
#include "stringencrypt.h"
#include "utl.h"

struct SettingCheckbox {
Expand Down Expand Up @@ -256,12 +255,14 @@ INT_PTR SettingsDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) {
return TRUE;
} else if (pnmhdr->idFrom == IDC_PROJECT_LINK && (pnmhdr->code == NM_CLICK || pnmhdr->code == NM_RETURN)) {
const auto pnmlink = (PNMLINK)pnmhdr;
const auto shell32 = LoadLibraryExW(ESTRt(L"shell32"), nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (shell32) {
const auto pShellExecute = (decltype(&::ShellExecuteW))(void*)GetProcAddress(shell32, ESTRt("ShellExecuteW"));
if (pShellExecute)
pShellExecute(nullptr, L"open", pnmlink->item.szUrl, nullptr, nullptr, SW_SHOW);
}
ShellExecute(
nullptr,
L"open",
pnmlink->item.szUrl,
nullptr,
nullptr,
SW_SHOW
);
return TRUE;
}
break;
Expand Down
220 changes: 91 additions & 129 deletions OpenHashTab/https.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,173 +15,135 @@
// along with OpenHashTab. If not, see <https://www.gnu.org/licenses/>.
#include "https.h"

#include "stringencrypt.h"

struct WinHTTPFunctions {
HMODULE h;

#define FN(name) decltype(&::name) name = (decltype(&::name))(void*)GetProcAddress(h, ESTRt(#name))

FN(WinHttpOpen);
FN(WinHttpConnect);
FN(WinHttpOpenRequest);
FN(WinHttpSendRequest);
FN(WinHttpReceiveResponse);
FN(WinHttpQueryHeaders);
FN(WinHttpQueryDataAvailable);
FN(WinHttpReadData);
FN(WinHttpCloseHandle);

#undef FN

explicit WinHTTPFunctions(HMODULE h)
: h(h) {}
};

HTTPResult DoHTTPS(const HTTPRequest& r) {
HTTPResult result{};

const auto h = LoadLibraryExW(ESTRt(L"winhttp"), nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (h) {
const auto fn = WinHTTPFunctions{h};

// Use WinHttpOpen to obtain a session handle.
const auto session = fn.WinHttpOpen(
r.user_agent,
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS,
// Use WinHttpOpen to obtain a session handle.
const auto session = WinHttpOpen(
r.user_agent,
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS,
0
);

if (session) {
// Specify an HTTP server.
const auto connection = WinHttpConnect(
session,
r.server_name,
INTERNET_DEFAULT_HTTPS_PORT,
0
);

if (session) {
// Specify an HTTP server.
const auto connection = fn.WinHttpConnect(
session,
r.server_name,
INTERNET_DEFAULT_HTTPS_PORT,
0
if (connection) {
// Create an HTTP Request handle.
const auto request = WinHttpOpenRequest(
connection,
r.method,
r.uri,
nullptr,
WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_SECURE
);

if (connection) {
// Create an HTTP Request handle.
const auto request = fn.WinHttpOpenRequest(
connection,
r.method,
r.uri,
nullptr,
WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_SECURE
if (request) {
// Send a Request.
auto ret = WinHttpSendRequest(
request,
r.headers,
static_cast<DWORD>(-1L),
const_cast<LPVOID>(r.body),
r.body_size,
r.body_size,
0
);

if (request) {
// Send a Request.
auto ret = fn.WinHttpSendRequest(
if (ret) {
ret = WinHttpReceiveResponse(
request,
r.headers,
static_cast<DWORD>(-1L),
const_cast<LPVOID>(r.body),
r.body_size,
r.body_size,
0
nullptr
);

if (ret) {
ret = fn.WinHttpReceiveResponse(
DWORD http_code = 0;
DWORD size = sizeof(http_code);
ret = WinHttpQueryHeaders(
request,
nullptr
WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
WINHTTP_HEADER_NAME_BY_INDEX,
&http_code,
&size,
WINHTTP_NO_HEADER_INDEX
);

if (ret) {
DWORD http_code = 0;
DWORD size = sizeof(http_code);
ret = fn.WinHttpQueryHeaders(
request,
WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
WINHTTP_HEADER_NAME_BY_INDEX,
&http_code,
&size,
WINHTTP_NO_HEADER_INDEX
);

if (ret) {
DWORD bytes_available;
std::string out;
do {
bytes_available = 0;
ret = fn.WinHttpQueryDataAvailable(
request,
&bytes_available
);
if (!ret) {
result.error_location = 8;
break;
}

if (bytes_available == 0) {
result.error_code = 0;
result.http_code = http_code;
result.body = std::move(out);
goto success;
}
DWORD bytes_available;
std::string out;
do {
bytes_available = 0;
ret = WinHttpQueryDataAvailable(
request,
&bytes_available
);
if (!ret) {
result.error_location = 8;
break;
}

if (bytes_available == 0) {
result.error_code = 0;
result.http_code = http_code;
result.body = std::move(out);
goto success;
}

DWORD bytes_read = 0;
const auto old_size = out.size();
out.resize(old_size + bytes_available);
ret = WinHttpReadData(
request,
(LPVOID)(out.data() + old_size),
bytes_available,
&bytes_read
);
if (!ret) {
result.error_location = 8;
break;
}
out.resize(old_size + bytes_read);
} while (true);

DWORD bytes_read = 0;
const auto old_size = out.size();
out.resize(old_size + bytes_available);
ret = fn.WinHttpReadData(
request,
(LPVOID)(out.data() + old_size),
bytes_available,
&bytes_read
);
if (!ret) {
result.error_location = 8;
break;
}
out.resize(old_size + bytes_read);
} while (true);

result.error_code = GetLastError();
result.error_code = GetLastError();

success:;
} else {
result.error_code = GetLastError();
result.error_location = 7;
}

} else {
result.error_code = GetLastError();
result.error_location = 6;
result.error_location = 7;
}

} else {
result.error_code = GetLastError();
result.error_location = 5;
result.error_location = 6;
}

fn.WinHttpCloseHandle(request);
} else {
result.error_code = GetLastError();
result.error_location = 4;
result.error_location = 5;
}

fn.WinHttpCloseHandle(connection);
WinHttpCloseHandle(request);
} else {
result.error_code = GetLastError();
result.error_location = 3;
result.error_location = 4;
}

fn.WinHttpCloseHandle(session);
WinHttpCloseHandle(connection);
} else {
result.error_code = GetLastError();
result.error_location = 2;
result.error_location = 3;
}

FreeLibrary(h);
WinHttpCloseHandle(session);
} else {
result.error_code = GetLastError();
result.error_location = 1;
result.error_location = 2;
}

return result;
Expand Down
49 changes: 0 additions & 49 deletions OpenHashTab/stringencrypt.h

This file was deleted.

Loading

0 comments on commit e3c6c63

Please sign in to comment.