mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-21 23:13:08 +08:00
Fix registry error and use [MT] to rebuild zlib, x264 and libyuv
This commit is contained in:
@@ -168,6 +168,7 @@
|
||||
<ClCompile Include="AudioManager.cpp" />
|
||||
<ClCompile Include="Buffer.cpp" />
|
||||
<ClCompile Include="CaptureVideo.cpp" />
|
||||
<ClCompile Include="clang_rt_compat.c" />
|
||||
<ClCompile Include="ClientDll.cpp" />
|
||||
<ClCompile Include="Common.cpp" />
|
||||
<ClCompile Include="FileManager.cpp" />
|
||||
|
||||
39
client/clang_rt_compat.c
Normal file
39
client/clang_rt_compat.c
Normal file
@@ -0,0 +1,39 @@
|
||||
// clang_rt_compat.c
|
||||
// 兼容 32 位 Clang 编译的 libx264 运行时函数
|
||||
|
||||
#ifdef _M_IX86
|
||||
|
||||
#pragma comment(linker, "/alternatename:__ultof3=_ultof3_impl")
|
||||
#pragma comment(linker, "/alternatename:__dtoul3_legacy=_dtoul3_impl")
|
||||
#pragma comment(linker, "/alternatename:__dtol3=_dtol3_impl")
|
||||
#pragma comment(linker, "/alternatename:__ltod3=_ltod3_impl")
|
||||
#pragma comment(linker, "/alternatename:__ultod3=_ultod3_impl")
|
||||
|
||||
// unsigned long long to float
|
||||
float __cdecl ultof3_impl(unsigned long long a) {
|
||||
return (float)a;
|
||||
}
|
||||
|
||||
// double to unsigned long long
|
||||
unsigned long long __cdecl dtoul3_impl(double a) {
|
||||
if (a < 0) return 0;
|
||||
if (a >= 18446744073709551616.0) return 0xFFFFFFFFFFFFFFFFULL;
|
||||
return (unsigned long long)a;
|
||||
}
|
||||
|
||||
// double to long long
|
||||
long long __cdecl dtol3_impl(double a) {
|
||||
return (long long)a;
|
||||
}
|
||||
|
||||
// long long to double
|
||||
double __cdecl ltod3_impl(long long a) {
|
||||
return (double)a;
|
||||
}
|
||||
|
||||
// unsigned long long to double
|
||||
double __cdecl ultod3_impl(unsigned long long a) {
|
||||
return (double)a;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -178,6 +178,7 @@
|
||||
<ClCompile Include="AudioManager.cpp" />
|
||||
<ClCompile Include="Buffer.cpp" />
|
||||
<ClCompile Include="CaptureVideo.cpp" />
|
||||
<ClCompile Include="clang_rt_compat.c" />
|
||||
<ClCompile Include="ClientDll.cpp" />
|
||||
<ClCompile Include="Common.cpp" />
|
||||
<ClCompile Include="FileManager.cpp" />
|
||||
|
||||
122
common/iniFile.h
122
common/iniFile.h
@@ -5,7 +5,93 @@
|
||||
#define YAMA_PATH "Software\\YAMA"
|
||||
#define CLIENT_PATH "Software\\ServerD11"
|
||||
|
||||
// <20><><EFBFBD>ö<EFBFBD>ȡ<EFBFBD><C8A1>: <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>.
|
||||
#define NO_CURRENTKEY 1
|
||||
|
||||
#if NO_CURRENTKEY
|
||||
#include <wtsapi32.h>
|
||||
#include <sddl.h>
|
||||
#pragma comment(lib, "wtsapi32.lib")
|
||||
|
||||
// 获取当前会话用户的注册表根键
|
||||
// SYSTEM 进程无法使用 HKEY_CURRENT_USER,需要通过 HKEY_USERS\<SID> 访问
|
||||
// 返回的 HKEY 需要调用者在使用完毕后调用 RegCloseKey 关闭
|
||||
inline HKEY GetCurrentUserRegistryKey()
|
||||
{
|
||||
HKEY hUserKey = NULL;
|
||||
// 获取当前进程的会话 ID
|
||||
DWORD sessionId = 0;
|
||||
ProcessIdToSessionId(GetCurrentProcessId(), &sessionId);
|
||||
|
||||
// 获取该会话的用户令牌
|
||||
HANDLE hUserToken = NULL;
|
||||
if (!WTSQueryUserToken(sessionId, &hUserToken)) {
|
||||
// 如果失败(可能不是服务进程),回退到 HKEY_CURRENT_USER
|
||||
return HKEY_CURRENT_USER;
|
||||
}
|
||||
|
||||
// 获取令牌中的用户信息大小
|
||||
DWORD dwSize = 0;
|
||||
GetTokenInformation(hUserToken, TokenUser, NULL, 0, &dwSize);
|
||||
if (dwSize == 0) {
|
||||
CloseHandle(hUserToken);
|
||||
return HKEY_CURRENT_USER;
|
||||
}
|
||||
|
||||
// 分配内存并获取用户信息
|
||||
TOKEN_USER* pTokenUser = (TOKEN_USER*)malloc(dwSize);
|
||||
if (!pTokenUser) {
|
||||
CloseHandle(hUserToken);
|
||||
return HKEY_CURRENT_USER;
|
||||
}
|
||||
|
||||
if (!GetTokenInformation(hUserToken, TokenUser, pTokenUser, dwSize, &dwSize)) {
|
||||
free(pTokenUser);
|
||||
CloseHandle(hUserToken);
|
||||
return HKEY_CURRENT_USER;
|
||||
}
|
||||
|
||||
// 将 SID 转换为字符串
|
||||
LPSTR szSid = NULL;
|
||||
if (!ConvertSidToStringSidA(pTokenUser->User.Sid, &szSid)) {
|
||||
free(pTokenUser);
|
||||
CloseHandle(hUserToken);
|
||||
return HKEY_CURRENT_USER;
|
||||
}
|
||||
|
||||
// 打开 HKEY_USERS\<SID>
|
||||
if (RegOpenKeyExA(HKEY_USERS, szSid, 0, KEY_READ | KEY_WRITE, &hUserKey) != ERROR_SUCCESS) {
|
||||
// 尝试只读方式
|
||||
if (RegOpenKeyExA(HKEY_USERS, szSid, 0, KEY_READ, &hUserKey) != ERROR_SUCCESS) {
|
||||
hUserKey = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
LocalFree(szSid);
|
||||
free(pTokenUser);
|
||||
CloseHandle(hUserToken);
|
||||
|
||||
return hUserKey ? hUserKey : HKEY_CURRENT_USER;
|
||||
}
|
||||
|
||||
// 检查是否需要关闭注册表根键(非预定义键需要关闭)
|
||||
inline void CloseUserRegistryKeyIfNeeded(HKEY hKey)
|
||||
{
|
||||
if (hKey != HKEY_CURRENT_USER &&
|
||||
hKey != HKEY_LOCAL_MACHINE &&
|
||||
hKey != HKEY_USERS &&
|
||||
hKey != HKEY_CLASSES_ROOT &&
|
||||
hKey != NULL) {
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#define GetCurrentUserRegistryKey() HKEY_CURRENT_USER
|
||||
#define CloseUserRegistryKeyIfNeeded(hKey)
|
||||
#endif
|
||||
|
||||
|
||||
// 配置读取类: 文件配置.
|
||||
class config
|
||||
{
|
||||
private:
|
||||
@@ -29,7 +115,7 @@ public:
|
||||
return ::GetPrivateProfileIntA(MainKey.c_str(), SubKey.c_str(), nDef, m_IniFilePath);
|
||||
}
|
||||
|
||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĵ<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 获取配置项中的第一个整数
|
||||
virtual int Get1Int(const std::string& MainKey, const std::string& SubKey, char ch=';', int nDef=0)
|
||||
{
|
||||
std::string s = GetStr(MainKey, SubKey, "");
|
||||
@@ -56,7 +142,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// <EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>ȡ<EFBFBD><EFBFBD>: ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// 配置读取类: 注册表配置.
|
||||
class iniFile : public config
|
||||
{
|
||||
private:
|
||||
@@ -64,21 +150,24 @@ private:
|
||||
std::string m_SubKeyPath;
|
||||
|
||||
public:
|
||||
~iniFile() {}
|
||||
~iniFile()
|
||||
{
|
||||
CloseUserRegistryKeyIfNeeded(m_hRootKey);
|
||||
}
|
||||
|
||||
iniFile(const std::string& path = YAMA_PATH)
|
||||
{
|
||||
m_hRootKey = HKEY_CURRENT_USER;
|
||||
m_hRootKey = GetCurrentUserRegistryKey();
|
||||
m_SubKeyPath = path;
|
||||
}
|
||||
|
||||
// д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>дΪ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
||||
// 写入整数,实际写为字符串
|
||||
bool SetInt(const std::string& MainKey, const std::string& SubKey, int Data) override
|
||||
{
|
||||
return SetStr(MainKey, SubKey, std::to_string(Data));
|
||||
}
|
||||
|
||||
// д<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
||||
// 写入字符串
|
||||
bool SetStr(const std::string& MainKey, const std::string& SubKey, const std::string& Data) override
|
||||
{
|
||||
std::string fullPath = m_SubKeyPath + "\\" + MainKey;
|
||||
@@ -93,7 +182,7 @@ public:
|
||||
return bRet;
|
||||
}
|
||||
|
||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
||||
// 读取字符串
|
||||
std::string GetStr(const std::string& MainKey, const std::string& SubKey, const std::string& def = "") override
|
||||
{
|
||||
std::string fullPath = m_SubKeyPath + "\\" + MainKey;
|
||||
@@ -113,7 +202,7 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>
|
||||
// 读取整数,先从字符串中转换
|
||||
int GetInt(const std::string& MainKey, const std::string& SubKey, int defVal = 0) override
|
||||
{
|
||||
std::string val = GetStr(MainKey, SubKey);
|
||||
@@ -135,27 +224,30 @@ private:
|
||||
std::string m_SubKeyPath;
|
||||
|
||||
public:
|
||||
~binFile() {}
|
||||
~binFile()
|
||||
{
|
||||
CloseUserRegistryKeyIfNeeded(m_hRootKey);
|
||||
}
|
||||
|
||||
binFile(const std::string& path = CLIENT_PATH)
|
||||
{
|
||||
m_hRootKey = HKEY_CURRENT_USER;
|
||||
m_hRootKey = GetCurrentUserRegistryKey();
|
||||
m_SubKeyPath = path;
|
||||
}
|
||||
|
||||
// д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>дΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>
|
||||
// 写入整数(写为二进制)
|
||||
bool SetInt(const std::string& MainKey, const std::string& SubKey, int Data) override
|
||||
{
|
||||
return SetBinary(MainKey, SubKey, reinterpret_cast<const BYTE*>(&Data), sizeof(int));
|
||||
}
|
||||
|
||||
// д<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>ʽ<EFBFBD><EFBFBD>
|
||||
// 写入字符串(以二进制方式)
|
||||
bool SetStr(const std::string& MainKey, const std::string& SubKey, const std::string& Data) override
|
||||
{
|
||||
return SetBinary(MainKey, SubKey, reinterpret_cast<const BYTE*>(Data.data()), static_cast<DWORD>(Data.size()));
|
||||
}
|
||||
|
||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 读取字符串(从二进制数据转换)
|
||||
std::string GetStr(const std::string& MainKey, const std::string& SubKey, const std::string& def = "") override
|
||||
{
|
||||
std::vector<BYTE> buffer;
|
||||
@@ -165,7 +257,7 @@ public:
|
||||
return std::string(buffer.begin(), buffer.end());
|
||||
}
|
||||
|
||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 读取整数(从二进制解析)
|
||||
int GetInt(const std::string& MainKey, const std::string& SubKey, int defVal = 0) override
|
||||
{
|
||||
std::vector<BYTE> buffer;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,7 +9,7 @@
|
||||
#include "InputDlg.h"
|
||||
#include <bcrypt.h>
|
||||
#include <wincrypt.h>
|
||||
#include <ntstatus.h>
|
||||
// #include <ntstatus.h>
|
||||
|
||||
enum Index {
|
||||
IndexTestRun_DLL,
|
||||
|
||||
Reference in New Issue
Block a user