├── IPCServer ├── x64 │ └── Release │ │ └── IPCServer.log ├── Main.h ├── stdafx.h ├── dllmain.cpp ├── Main.cpp ├── targetver.h ├── IPCServer.h ├── IPCPacket.h ├── IPCServer.vcxproj.filters ├── HandleGetter.h ├── IPCServer.cpp └── HandleGetter.cpp ├── LambseaLoader ├── cpuz141.h ├── Lib.cpp ├── Exports.h ├── LambseaLib.vcxproj.user ├── LambseaDriver.h ├── Global.h ├── LambseaLib.vcxproj.filters ├── hde │ ├── pstdint.h │ ├── hde64.h │ └── table64.h └── LambseaLib.vcxproj ├── lambsea ├── Memory.h ├── stdafx.h ├── dllmain.cpp ├── targetver.h ├── GameBase.cpp ├── D3D9Render.cpp ├── DriverInterface.h ├── FW1FontWrapper │ ├── FW1Precompiled.cpp │ ├── FW1CompileSettings.h │ ├── FW1Precompiled.h │ ├── CFW1ColorRGBA.cpp │ ├── CFW1TextGeometry.cpp │ ├── FW1FontWrapper.cpp │ ├── CFW1ColorRGBA.h │ ├── CFW1TextRenderer.cpp │ ├── CFW1TextGeometry.h │ ├── CFW1ColorRGBAInterface.cpp │ ├── CFW1GlyphVertexDrawerInterface.cpp │ ├── CFW1GlyphVertexDrawer.h │ ├── CFW1DWriteRenderTarget.h │ ├── CFW1Factory.cpp │ ├── CFW1StateSaver.h │ ├── CFW1Object.h │ ├── CFW1GlyphAtlas.h │ ├── CFW1GlyphRenderStates.h │ ├── CFW1GlyphAtlas.cpp │ ├── CFW1GlyphProvider.h │ ├── CFW1TextGeometryInterface.cpp │ ├── CFW1DWriteRenderTargetInterface.cpp │ ├── CFW1Factory.h │ ├── CFW1GlyphSheet.h │ ├── CFW1GlyphRenderStatesInterface.cpp │ ├── CFW1GlyphProviderInterface.cpp │ ├── CFW1FontWrapper.h │ ├── CFW1GlyphAtlasInterface.cpp │ ├── CFW1FontWrapper.cpp │ ├── CFW1TextRenderer.h │ ├── CFW1DWriteRenderTarget.cpp │ ├── CFW1StateSaver.cpp │ ├── CFW1TextRendererInterface.cpp │ └── CFW1GlyphSheet.cpp ├── LambseaExternal.h ├── DriverInterface.cpp ├── LambseaExternal.cpp ├── lambsea.vcxproj.user ├── D3D11Render │ ├── D3D11Shader.h │ ├── Helper.h │ ├── D3D11StateSaver.h │ ├── D3D11Renderer.h │ └── D3D11StateSaver.cpp ├── Driver-resrvlib-Interface.h ├── UndocumentNt.h ├── Offsets.h ├── UndocumentNt.cpp ├── XorStrings.h ├── D3D9Render.h ├── Injection.h ├── Decrypt.h └── lambsea.vcxproj.filters ├── BEFucker ├── Main.h ├── BEFucker.vcxproj.user ├── stdafx.h ├── targetver.h ├── dllmain.cpp ├── Helpers.cpp ├── Helpers.h ├── Hooks.h └── Main.cpp ├── README.md └── External.sln /IPCServer/x64/Release/IPCServer.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /LambseaLoader/cpuz141.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | extern unsigned char CpuzShellcode[46400]; -------------------------------------------------------------------------------- /IPCServer/Main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | void WINAPI Mainroutine(); -------------------------------------------------------------------------------- /lambsea/Memory.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/lambsea/Memory.h -------------------------------------------------------------------------------- /lambsea/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/lambsea/stdafx.h -------------------------------------------------------------------------------- /IPCServer/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/IPCServer/stdafx.h -------------------------------------------------------------------------------- /lambsea/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/lambsea/dllmain.cpp -------------------------------------------------------------------------------- /lambsea/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/lambsea/targetver.h -------------------------------------------------------------------------------- /IPCServer/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/IPCServer/dllmain.cpp -------------------------------------------------------------------------------- /LambseaLoader/Lib.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/LambseaLoader/Lib.cpp -------------------------------------------------------------------------------- /lambsea/GameBase.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/lambsea/GameBase.cpp -------------------------------------------------------------------------------- /LambseaLoader/Exports.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/LambseaLoader/Exports.h -------------------------------------------------------------------------------- /lambsea/D3D9Render.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/lambsea/D3D9Render.cpp -------------------------------------------------------------------------------- /lambsea/DriverInterface.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/lambsea/DriverInterface.h -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/FW1Precompiled.cpp: -------------------------------------------------------------------------------- 1 | // FW1Precompiled.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | -------------------------------------------------------------------------------- /lambsea/LambseaExternal.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/lambsea/LambseaExternal.h -------------------------------------------------------------------------------- /lambsea/DriverInterface.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/lambsea/DriverInterface.cpp -------------------------------------------------------------------------------- /lambsea/LambseaExternal.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a4501150/LambseaExternal/HEAD/lambsea/LambseaExternal.cpp -------------------------------------------------------------------------------- /IPCServer/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | #include "HandleGetter.h" 3 | #include "IPCServer.h" 4 | void Mainroutine() 5 | { 6 | ServerGateway* sg = new ServerGateway(); 7 | } 8 | -------------------------------------------------------------------------------- /BEFucker/Main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | namespace Huorong 4 | { 5 | //Variables 6 | 7 | //Functions 8 | void Initialise(); 9 | void Release(); 10 | } -------------------------------------------------------------------------------- /BEFucker/BEFucker.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /lambsea/lambsea.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /LambseaLoader/LambseaLib.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /BEFucker/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define WIN32_LEAN_AND_MEAN 3 | 4 | #include "targetver.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LambseaExternal 2 | Written in C++, utilizing Windows APIs to modify game memory and issue directives to kernel drivers. 3 | Using D3D9 to draw lines on created overlay window to provide ESP functionalities. 4 | 5 | # Legal Disclaimer 6 | This is the outdated and detected PUBG Game hack, Uploaded for learning purpose ONLY. 7 | -------------------------------------------------------------------------------- /BEFucker/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /IPCServer/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /LambseaLoader/LambseaDriver.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------ 2 | //----------- Created with 010 Editor ----------- 3 | //------ www.sweetscape.com/010editor/ ------ 4 | // 5 | // File : C:\Users\Jinyang\Desktop\LambseaDriver.sys 6 | // Address : 0 (0x0) 7 | // Size : 5696 (0x1640) 8 | //------------------------------------------------------------ 9 | extern unsigned char Lambsea[174920]; 10 | -------------------------------------------------------------------------------- /lambsea/D3D11Render/D3D11Shader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | static char D3D11FillShader[] = 4 | "struct VSOut" 5 | "{" 6 | " float4 Col : COLOR;" 7 | " float4 Pos : SV_POSITION;" 8 | "};" 9 | 10 | "VSOut VS(float4 Col : COLOR, float4 Pos : POSITION)" 11 | "{" 12 | " VSOut Output;" 13 | " Output.Pos = Pos;" 14 | " Output.Col = Col;" 15 | " return Output;" 16 | "}" 17 | 18 | "float4 PS(float4 Col : COLOR) : SV_TARGET" 19 | "{" 20 | " return Col;" 21 | "}"; -------------------------------------------------------------------------------- /IPCServer/IPCServer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IPCPacket.h" 3 | 4 | class ServerGateway 5 | { 6 | public: 7 | ServerGateway(); 8 | ~ServerGateway(); 9 | 10 | void Init(); 11 | BOOL AnswerPing(IPCPacket incomingPacket); 12 | BOOL AnswerGetBaseaddress(); 13 | BOOL AnswerReadProcessMemory(IPCPacket incomingPacket); 14 | BOOL AnswerWriteProcessMemory(IPCPacket incomingPacket); 15 | 16 | private: 17 | HANDLE hNamedPipe; 18 | HANDLE hGame; 19 | LPWSTR PipeName; 20 | }; -------------------------------------------------------------------------------- /IPCServer/IPCPacket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | #define MAXPIPEFILESIZE 0x500 5 | #define MAXDATASIZE 0x200 6 | 7 | #define PIPENAME L"\\\\.\\pipe\\lambsea" 8 | 9 | enum OrderType 10 | { 11 | IPCPing, 12 | IPCGetBaseOrder, 13 | IPCReadOrder, 14 | IPCWriteOrder 15 | }; 16 | 17 | typedef struct IPCPacket IPCPacket; 18 | struct IPCPacket { 19 | int Order = 0; 20 | int size = 0; 21 | DWORD_PTR Address = 0; 22 | unsigned char data[MAXDATASIZE] = {0}; 23 | }; -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/FW1CompileSettings.h: -------------------------------------------------------------------------------- 1 | // FW1CompileSettings.h 2 | 3 | #ifndef IncludeGuard__FW1_FW1CompileSettings_h 4 | #define IncludeGuard__FW1_FW1CompileSettings_h 5 | 6 | 7 | // Define if building a DLL for the font-wrapper 8 | #define FW1_COMPILETODLL 9 | 10 | // Define to use LoadLibrary instead of linking to DLLs 11 | #define FW1_DELAYLOAD_DWRITE_DLL 12 | #define FW1_DELAYLOAD_D3DCOMPILER_XX_DLL 13 | 14 | 15 | #endif// IncludeGuard__FW1_FW1CompileSettings_h 16 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/FW1Precompiled.h: -------------------------------------------------------------------------------- 1 | // FW1Precompiled.h 2 | #ifndef IncludeGuard__FW1_FW1Precompiled_h 3 | #define IncludeGuard__FW1_FW1Precompiled_h 4 | 5 | #define NOMINMAX 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "FW1CompileSettings.h" 19 | #include "FW1FontWrapper.h" 20 | 21 | 22 | #endif// IncludeGuard__FW1_FW1Precompiled_h 23 | -------------------------------------------------------------------------------- /BEFucker/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // dllmain.cpp : Defines the entry point for the DLL application. 3 | #include "stdafx.h" 4 | #include "Main.h" 5 | 6 | BOOL APIENTRY DllMain( HMODULE hModule, 7 | DWORD ul_reason_for_call, 8 | LPVOID lpReserved 9 | ) 10 | { 11 | switch (ul_reason_for_call) 12 | { 13 | case DLL_PROCESS_ATTACH: 14 | DisableThreadLibraryCalls(hModule); // PERFOMANCE? 15 | CreateThread(NULL, NULL, reinterpret_cast(Huorong::Initialise), NULL, NULL, NULL); 16 | break; 17 | 18 | case DLL_PROCESS_DETACH: 19 | Huorong::Release(); 20 | break; 21 | } 22 | return TRUE; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1ColorRGBA.cpp: -------------------------------------------------------------------------------- 1 | // CFW1ColorRGBA.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1ColorRGBA.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Construct 12 | CFW1ColorRGBA::CFW1ColorRGBA() : 13 | m_color32(0xffffffff) 14 | { 15 | } 16 | 17 | 18 | // Destruct 19 | CFW1ColorRGBA::~CFW1ColorRGBA() { 20 | } 21 | 22 | 23 | // Init 24 | HRESULT CFW1ColorRGBA::initColor(IFW1Factory *pFW1Factory, UINT32 initialColor32) { 25 | HRESULT hResult = initBaseObject(pFW1Factory); 26 | if(FAILED(hResult)) 27 | return hResult; 28 | 29 | m_color32 = initialColor32; 30 | 31 | return S_OK; 32 | } 33 | 34 | 35 | }// namespace FW1FontWrapper 36 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1TextGeometry.cpp: -------------------------------------------------------------------------------- 1 | // CFW1TextGeometry.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1TextGeometry.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Construct 12 | CFW1TextGeometry::CFW1TextGeometry() : 13 | m_maxSheetIndex(0), 14 | m_sorted(false) 15 | { 16 | } 17 | 18 | 19 | // Destruct 20 | CFW1TextGeometry::~CFW1TextGeometry() { 21 | } 22 | 23 | 24 | // Init glyph provider 25 | HRESULT CFW1TextGeometry::initTextGeometry(IFW1Factory *pFW1Factory) { 26 | HRESULT hResult = initBaseObject(pFW1Factory); 27 | if(FAILED(hResult)) 28 | return hResult; 29 | 30 | return hResult; 31 | } 32 | 33 | 34 | }// namespace FW1FontWrapper 35 | -------------------------------------------------------------------------------- /lambsea/D3D11Render/Helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "D3D11Renderer.h" 4 | 5 | static HMODULE GetD3DCompiler() 6 | { 7 | wchar_t buf[32]; 8 | for (int i = 50; i >= 30; i--) 9 | { 10 | wsprintf(buf, L"D3DCompiler_%d.dll", i); 11 | HMODULE mod = LoadLibrary(buf); 12 | if (mod) 13 | return mod; 14 | } 15 | 16 | return NULL; 17 | } 18 | 19 | template inline void SAFE_DELETE(T *&p) 20 | { 21 | if (p) 22 | { 23 | delete p; 24 | p = NULL; 25 | } 26 | } 27 | 28 | template inline void SAFE_DELETE_ARRAY(T *&p) 29 | { 30 | if (p) 31 | { 32 | delete[] p; 33 | p = NULL; 34 | } 35 | } 36 | 37 | template inline void SAFE_RELEASE(T *&p) 38 | { 39 | if (p) 40 | { 41 | p->Release(); 42 | p = NULL; 43 | } 44 | } -------------------------------------------------------------------------------- /lambsea/Driver-resrvlib-Interface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | typedef BOOL(WINAPI *reserve_init)(); 5 | 6 | typedef BOOL(WINAPI *reserve_module) 7 | ( 8 | ULONG uProc, 9 | LPCSTR sModule, 10 | ULONGLONG *phmModule, 11 | ULONG *puModSize 12 | ); 13 | 14 | typedef BOOL(WINAPI *reserve_alloc) 15 | ( 16 | ULONG uProc, 17 | ULONGLONG &pbAddr, 18 | ULONG nSize, 19 | ULONG uProtect 20 | ); 21 | 22 | typedef BOOL(WINAPI *reserve_free) 23 | ( 24 | ULONG uProc, 25 | ULONGLONG pbAddr, 26 | ULONG nSize 27 | ); 28 | 29 | typedef BOOL(WINAPI *reserve_read) 30 | ( 31 | ULONG uProc, 32 | ULONGLONG pbAddr, 33 | PVOID pbData, 34 | ULONG uSize 35 | ); 36 | 37 | typedef BOOL(WINAPI *reserve_write) 38 | ( 39 | ULONG uProc, 40 | ULONGLONG pbAddr, 41 | PVOID pbData, 42 | ULONG uSize 43 | ); -------------------------------------------------------------------------------- /lambsea/UndocumentNt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #ifndef NT_SUCCESS 6 | #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) 7 | #endif 8 | 9 | typedef enum _SYSTEM_INFORMATION_CLASS { 10 | SystemBasicInformation = 0, 11 | SystemPerformanceInformation = 2, 12 | SystemTimeOfDayInformation = 3, 13 | SystemProcessInformation = 5, 14 | SystemProcessorPerformanceInformation = 8, 15 | SystemInterruptInformation = 23, 16 | SystemExceptionInformation = 33, 17 | SystemRegistryQuotaInformation = 37, 18 | SystemLookasideInformation = 45, 19 | SystemPolicyInformation = 134, 20 | } SYSTEM_INFORMATION_CLASS; 21 | 22 | typedef NTSTATUS 23 | (NTAPI 24 | *fNtQuerySystemInformation)( 25 | IN SYSTEM_INFORMATION_CLASS SystemInformationClass, 26 | OUT PVOID SystemInformation, 27 | IN ULONG SystemInformationLength, 28 | OUT PULONG ReturnLength OPTIONAL 29 | ); 30 | 31 | HANDLE NtQueryProcessStatus(HANDLE watchedPID); -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/FW1FontWrapper.cpp: -------------------------------------------------------------------------------- 1 | // FW1FontWrapper.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1Factory.h" 6 | 7 | #ifndef FW1_DELAYLOAD_DWRITE_DLL 8 | #pragma comment (lib, "DWrite.lib") 9 | #endif 10 | 11 | #ifndef FW1_DELAYLOAD_D3DCOMPILER_XX_DLL 12 | #pragma comment (lib, "DWrite.lib") 13 | #endif 14 | 15 | #ifdef FW1_COMPILETODLL 16 | #ifndef _M_X64 17 | #pragma comment (linker, "/EXPORT:FW1CreateFactory=_FW1CreateFactory@8,@1") 18 | #endif 19 | #endif 20 | 21 | 22 | // Create FW1 factory 23 | extern "C" HRESULT STDMETHODCALLTYPE FW1CreateFactory(UINT32 Version, IFW1Factory **ppFactory) { 24 | if(Version != FW1_VERSION) 25 | return E_FAIL; 26 | 27 | if(ppFactory == NULL) 28 | return E_INVALIDARG; 29 | 30 | FW1FontWrapper::CFW1Factory *pFactory = new FW1FontWrapper::CFW1Factory; 31 | HRESULT hResult = pFactory->initFactory(); 32 | if(FAILED(hResult)) { 33 | pFactory->Release(); 34 | } 35 | else { 36 | *ppFactory = pFactory; 37 | 38 | hResult = S_OK; 39 | } 40 | 41 | return hResult; 42 | } 43 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1ColorRGBA.h: -------------------------------------------------------------------------------- 1 | // CFW1ColorRGBA.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1ColorRGBA 4 | #define IncludeGuard__FW1_CFW1ColorRGBA 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // A color 13 | class CFW1ColorRGBA : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1Color32 19 | virtual void STDMETHODCALLTYPE SetColor(UINT32 Color); 20 | virtual void STDMETHODCALLTYPE SetColor(FLOAT Red, FLOAT Green, FLOAT Blue, FLOAT Alpha); 21 | virtual void STDMETHODCALLTYPE SetColor(const FLOAT *pColor); 22 | virtual void STDMETHODCALLTYPE SetColor(const BYTE *pColor); 23 | 24 | virtual UINT32 STDMETHODCALLTYPE GetColor32(); 25 | 26 | // Public functions 27 | public: 28 | CFW1ColorRGBA(); 29 | 30 | HRESULT initColor(IFW1Factory *pFW1Factory, UINT32 initialColor32); 31 | 32 | // Internal functions 33 | private: 34 | virtual ~CFW1ColorRGBA(); 35 | 36 | // Internal data 37 | private: 38 | UINT32 m_color32; 39 | }; 40 | 41 | 42 | }// namespace FW1FontWrapper 43 | 44 | 45 | #endif// IncludeGuard__FW1_CFW1ColorRGBA 46 | -------------------------------------------------------------------------------- /LambseaLoader/Global.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #if !defined UNICODE 3 | #error ANSI build is not supported 4 | #endif 5 | 6 | #if (_MSC_VER >= 1900) 7 | #ifdef _DEBUG 8 | #pragma comment(lib, "vcruntimed.lib") 9 | #pragma comment(lib, "ucrtd.lib") 10 | #else 11 | //#pragma comment(lib, "libvcruntime.lib") 12 | //#pragma comment(lib, "vcruntime.lib") 13 | //#pragma comment(lib, "ucrt.lib") 14 | #endif 15 | #endif 16 | 17 | 18 | //disable nonmeaningful warnings. 19 | #pragma warning(disable: 4005) // macro redefinition 20 | #pragma warning(disable: 4054) // %s : from function pointer %s to data pointer %s 21 | #pragma warning(disable: 4055) // %s : from data pointer %s to function pointer %s 22 | #pragma warning(disable: 4152) // nonstandard extension, function/data pointer conversion in expression 23 | #pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union 24 | #pragma warning(disable: 6102) // Using %s from failed function call at line %u 25 | #pragma warning(disable: 6320) // exception-filter expression is the constant EXCEPTION_EXECUTE_HANDLER 26 | 27 | #define _CRT_SECURE_NO_WARNINGS 28 | 29 | #include 30 | #include 31 | #include "ntos.h" 32 | #include "hde\hde64.h" 33 | #include -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1TextRenderer.cpp: -------------------------------------------------------------------------------- 1 | // CFW1TextRenderer.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1TextRenderer.h" 6 | 7 | #define SAFE_RELEASE(pObject) { if(pObject) { (pObject)->Release(); (pObject) = NULL; } } 8 | 9 | 10 | namespace FW1FontWrapper { 11 | 12 | 13 | // Construct 14 | CFW1TextRenderer::CFW1TextRenderer() : 15 | m_pGlyphProvider(NULL), 16 | 17 | m_currentFlags(0), 18 | m_currentColor(0xff000000), 19 | 20 | m_cachedGlyphMap(0), 21 | m_pCachedGlyphMapFontFace(NULL), 22 | m_cachedGlyphMapFontSize(0), 23 | 24 | m_pDWriteTextRendererProxy(0) 25 | { 26 | } 27 | 28 | 29 | // Destruct 30 | CFW1TextRenderer::~CFW1TextRenderer() { 31 | SAFE_RELEASE(m_pGlyphProvider); 32 | 33 | delete m_pDWriteTextRendererProxy; 34 | } 35 | 36 | 37 | // Init 38 | HRESULT CFW1TextRenderer::initTextRenderer( 39 | IFW1Factory *pFW1Factory, 40 | IFW1GlyphProvider *pGlyphProvider 41 | ) { 42 | HRESULT hResult = initBaseObject(pFW1Factory); 43 | if(FAILED(hResult)) 44 | return hResult; 45 | 46 | if(pGlyphProvider == NULL) 47 | return E_INVALIDARG; 48 | 49 | pGlyphProvider->AddRef(); 50 | m_pGlyphProvider = pGlyphProvider; 51 | 52 | m_pDWriteTextRendererProxy = new CDWriteTextRendererProxy(this); 53 | 54 | return S_OK; 55 | } 56 | 57 | 58 | }// namespace FW1FontWrapper 59 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1TextGeometry.h: -------------------------------------------------------------------------------- 1 | // CFW1TextGeometry.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1TextGeometry 4 | #define IncludeGuard__FW1_CFW1TextGeometry 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Vector of vertices with sorting per glyph sheet 13 | class CFW1TextGeometry : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1TextGeometry 19 | virtual void STDMETHODCALLTYPE Clear(); 20 | virtual void STDMETHODCALLTYPE AddGlyphVertex(const FW1_GLYPHVERTEX *pVertex); 21 | 22 | virtual FW1_VERTEXDATA STDMETHODCALLTYPE GetGlyphVerticesTemp(); 23 | 24 | // Public functions 25 | public: 26 | CFW1TextGeometry(); 27 | 28 | HRESULT initTextGeometry(IFW1Factory *pFW1Factory); 29 | 30 | // Internal functions 31 | private: 32 | virtual ~CFW1TextGeometry(); 33 | 34 | // Internal data 35 | private: 36 | std::vector m_vertices; 37 | std::vector m_sortedVertices; 38 | 39 | UINT m_maxSheetIndex; 40 | std::vector m_vertexCounts; 41 | std::vector m_vertexStartIndices; 42 | bool m_sorted; 43 | }; 44 | 45 | 46 | }// namespace FW1FontWrapper 47 | 48 | 49 | #endif// IncludeGuard__FW1_CFW1TextGeometry 50 | -------------------------------------------------------------------------------- /LambseaLoader/LambseaLib.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {5fcd2c19-3bcc-4e3d-81ee-ee60d21fedb5} 6 | 7 | 8 | {28073f6a-a6af-437b-b2f2-0556826c21e4} 9 | 10 | 11 | {cfec9a51-be3e-41c7-8088-5972cc40d83c} 12 | 13 | 14 | 15 | 16 | hde 17 | 18 | 19 | 20 | CPUZBinary 21 | 22 | 23 | 24 | 25 | 26 | hde 27 | 28 | 29 | hde 30 | 31 | 32 | hde 33 | 34 | 35 | 36 | Header 37 | 38 | 39 | Header 40 | 41 | 42 | CPUZBinary 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /IPCServer/IPCServer.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {98c8933f-e7c9-4d37-a411-f4d2729d43b3} 6 | 7 | 8 | {3d41a3f4-2616-48b3-ad2f-f5a015bff30f} 9 | 10 | 11 | {4eacd759-cd53-4c7d-ad39-c356aeb8bd98} 12 | 13 | 14 | {f3fccf69-f44b-484c-a97d-3f509bf589d2} 15 | 16 | 17 | 18 | 19 | IPCDataStructure 20 | 21 | 22 | IPCServer 23 | 24 | 25 | Helpers 26 | 27 | 28 | Misc 29 | 30 | 31 | 32 | 33 | Helpers 34 | 35 | 36 | 37 | 38 | IPCServer 39 | 40 | 41 | Misc 42 | 43 | 44 | Helpers 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /LambseaLoader/hde/pstdint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2015 Tsuda Kageyu. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | // Integer types for HDE. 32 | typedef INT8 int8_t; 33 | typedef INT16 int16_t; 34 | typedef INT32 int32_t; 35 | typedef INT64 int64_t; 36 | typedef UINT8 uint8_t; 37 | typedef UINT16 uint16_t; 38 | typedef UINT32 uint32_t; 39 | typedef UINT64 uint64_t; 40 | -------------------------------------------------------------------------------- /lambsea/Offsets.h: -------------------------------------------------------------------------------- 1 | #define GameInstanceOffset 0x140 2 | #define LocalPlayerArrayOffset 0x38 3 | #define ViewPointOffset 0x58 4 | #define RealWorldOffset 0x80 5 | #define PlayerControllerOffset 0x30 6 | #define PlayerCameraManagerOffset 0x448 7 | #define CameraCacheOffset 0x420 8 | #define ULevelOffset 0x30 9 | 10 | #define AActorArrayOffset 0xA0 11 | #define AActorArrayLengthOffset AActorArrayOffset+0x8 12 | #define AActorIDoffset 0x18 13 | 14 | #define RootCompOffset 0x188 15 | #define LocationOffset 0x0290 16 | 17 | #define APawnOffset 0x170 18 | #define PlayerStateOffset 0x3D0 19 | #define TeamIDoffset 0x484 20 | #define PlayerNameOffset 0x3B8 21 | #define AHUDOffset 0x440 22 | #define PlayerIDOffset 0x3D8 23 | #define HealthOffset 0x115C 24 | 25 | #define MeshOffset 0x410 26 | #define BoneArrayOffset 0x960 27 | 28 | #define ControlRotationOffset 0x3E0 29 | #define AcknowledgedPawnOffset 0x428 30 | 31 | #define DroppedItemGroupArrayOffset 0x2E8 32 | #define DroppedItemGroupArrayCountOffset DroppedItemGroupArrayOffset+0x8 33 | #define DroppedItemGroupRelativeOffset 0x2D0 34 | #define UItemOffset 0x538 35 | #define UItemFStringOffset 0x40 36 | 37 | #define WeaponProcessorOffset 0xA48 38 | #define EquippedWeaponArrayOffset 0x4B8 39 | #define CurrentWeaponIndexOffset 0x4C8 40 | 41 | #define FWeaponDataOffset 0x550 42 | #define FRecoilInfoOffset 0xB90 43 | #define FTrajectoryWeaponDataOffset 0xB10 44 | #define FWeaponGunDataOffset 0x8B8 45 | #define FWeaponDeviationDataOffset 0x948 46 | #define FWeaponGunAnimOffset 0x990 47 | 48 | #define pTrajectoryGravityZOffset 0xAE8 49 | #define pRecoilSpreadScaleOffset 0xAEC 50 | #define pWalkSpreadOffset 0xB00 51 | #define pRunSpreadOffset 0xB04 52 | #define pJumpSpreadOffset 0xB08 53 | 54 | 55 | #define GameStateOffset 0xF8 56 | #define TimeSecondsOffset 0x3DC 57 | #define LastRenderTimeOffset 0x6A4 -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1ColorRGBAInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1ColorRGBAInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1ColorRGBA.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1ColorRGBA::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1ColorRGBA))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Set the color 27 | void STDMETHODCALLTYPE CFW1ColorRGBA::SetColor(UINT32 Color) { 28 | m_color32 = Color; 29 | } 30 | 31 | 32 | // Set the color 33 | void STDMETHODCALLTYPE CFW1ColorRGBA::SetColor(FLOAT Red, FLOAT Green, FLOAT Blue, FLOAT Alpha) { 34 | UINT32 color32; 35 | BYTE *colorBytes = reinterpret_cast(&color32); 36 | colorBytes[0] = static_cast(Red * 255.0f + 0.5f); 37 | colorBytes[1] = static_cast(Green * 255.0f + 0.5f); 38 | colorBytes[2] = static_cast(Blue * 255.0f + 0.5f); 39 | colorBytes[3] = static_cast(Alpha * 255.0f + 0.5f); 40 | 41 | m_color32 = color32; 42 | } 43 | 44 | 45 | // Set the color 46 | void STDMETHODCALLTYPE CFW1ColorRGBA::SetColor(const FLOAT *pColor) { 47 | SetColor(pColor[0], pColor[1], pColor[2], pColor[3]); 48 | } 49 | 50 | 51 | // Set the color 52 | void STDMETHODCALLTYPE CFW1ColorRGBA::SetColor(const BYTE *pColor) { 53 | UINT32 color32; 54 | BYTE *colorBytes = reinterpret_cast(&color32); 55 | for(int i=0; i < 4; ++i) 56 | colorBytes[i] = pColor[i]; 57 | 58 | m_color32 = color32; 59 | } 60 | 61 | 62 | // Get the color 63 | UINT32 STDMETHODCALLTYPE CFW1ColorRGBA::GetColor32() { 64 | return m_color32; 65 | } 66 | 67 | 68 | }// namespace FW1FontWrapper 69 | -------------------------------------------------------------------------------- /BEFucker/Helpers.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Helpers.h" 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | ofstream myfile; 9 | 10 | //HOOKING 11 | void Helpers::HookFunction(PVOID *oFunction, PVOID pDetour) 12 | { 13 | DetourTransactionBegin(); 14 | DetourUpdateThread(GetCurrentThread()); 15 | DetourAttach(oFunction, pDetour); 16 | DetourTransactionCommit(); 17 | } 18 | void Helpers::UnhookFunction(PVOID *oFunction, PVOID pDetour) 19 | { 20 | DetourTransactionBegin(); 21 | DetourUpdateThread(GetCurrentThread()); 22 | DetourDetach(oFunction, pDetour); 23 | DetourTransactionCommit(); 24 | } 25 | 26 | 27 | 28 | 29 | 30 | //MISCELLANEOUS 31 | 32 | void Helpers::Log(char* szMessage) 33 | { 34 | std::cout << "[+] " << szMessage << std::endl; 35 | } 36 | 37 | void Helpers::LogToFile(char * szMessage) 38 | { 39 | myfile.open("c:\\intel\\GUID", std::ios_base::app); 40 | myfile << szMessage << endl; 41 | myfile.close(); 42 | } 43 | 44 | void Helpers::LogToFileEx(const char * szMessage) 45 | { 46 | myfile.open("c:\\intel\\GUID", std::ios_base::app); 47 | myfile << szMessage << endl; 48 | myfile.close(); 49 | } 50 | 51 | void Helpers::LogAddressToFile(char * szMessage, uintptr_t iAddress) 52 | { 53 | myfile.open("c:\\intel\\GUID", std::ios_base::app); 54 | myfile << szMessage << ": 0x" << hex << iAddress << endl; 55 | myfile.close(); 56 | } 57 | 58 | void Helpers::LogValueToFile(char * szMessage, DWORD_PTR value) 59 | { 60 | myfile.open("c:\\intel\\GUID", std::ios_base::app); 61 | myfile << szMessage << value << endl; 62 | myfile.close(); 63 | } 64 | 65 | void Helpers::LogAddress(char* szName, uintptr_t iAddress) 66 | { 67 | std::cout << "[+] " << szName << ": 0x" << std::hex << iAddress << std::endl; 68 | } 69 | void Helpers::LogError(char* szMessage) 70 | { 71 | std::cout << "[Error] " << szMessage << std::endl; 72 | } 73 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1GlyphVertexDrawerInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1GlyphVertexDrawerInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1GlyphVertexDrawer.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1GlyphVertexDrawer::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1GlyphVertexDrawer))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Get the D3D11 device used by this vetex drawer 27 | HRESULT STDMETHODCALLTYPE CFW1GlyphVertexDrawer::GetDevice(ID3D11Device **ppDevice) { 28 | if(ppDevice == NULL) 29 | return E_INVALIDARG; 30 | 31 | m_pDevice->AddRef(); 32 | *ppDevice = m_pDevice; 33 | 34 | return S_OK; 35 | } 36 | 37 | 38 | // Draw vertices 39 | UINT STDMETHODCALLTYPE CFW1GlyphVertexDrawer::DrawVertices( 40 | ID3D11DeviceContext *pContext, 41 | IFW1GlyphAtlas *pGlyphAtlas, 42 | const FW1_VERTEXDATA *pVertexData, 43 | UINT Flags, 44 | UINT PreboundSheet 45 | ) { 46 | UINT stride; 47 | UINT offset = 0; 48 | 49 | if((Flags & FW1_NOGEOMETRYSHADER) == 0) 50 | stride = sizeof(FW1_GLYPHVERTEX); 51 | else { 52 | stride = sizeof(QuadVertex); 53 | if((Flags & FW1_BUFFERSPREPARED) == 0) 54 | pContext->IASetIndexBuffer(m_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0); 55 | } 56 | if((Flags & FW1_BUFFERSPREPARED) == 0) 57 | pContext->IASetVertexBuffers(0, 1, &m_pVertexBuffer, &stride, &offset); 58 | 59 | if((Flags & FW1_NOGEOMETRYSHADER) == 0) 60 | return drawVertices(pContext, pGlyphAtlas, pVertexData, PreboundSheet); 61 | else 62 | return drawGlyphsAsQuads(pContext, pGlyphAtlas, pVertexData, PreboundSheet); 63 | } 64 | 65 | 66 | }// namespace FW1FontWrapper 67 | -------------------------------------------------------------------------------- /lambsea/D3D11Render/D3D11StateSaver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "D3D11Renderer.h" 4 | 5 | class D3D11StateSaver 6 | { 7 | private: 8 | bool m_savedState; 9 | D3D_FEATURE_LEVEL m_featureLevel; 10 | ID3D11DeviceContext *m_pContext; 11 | D3D11_PRIMITIVE_TOPOLOGY m_primitiveTopology; 12 | ID3D11InputLayout *m_pInputLayout; 13 | ID3D11BlendState *m_pBlendState; 14 | float m_blendFactor[4]; 15 | UINT m_sampleMask; 16 | ID3D11DepthStencilState *m_pDepthStencilState; 17 | UINT m_stencilRef; 18 | ID3D11RasterizerState *m_pRasterizerState; 19 | ID3D11ShaderResourceView *m_pPSSRV; 20 | ID3D11SamplerState *m_pSamplerState; 21 | ID3D11VertexShader *m_pVS; 22 | ID3D11ClassInstance *m_pVSClassInstances[256]; 23 | UINT m_numVSClassInstances; 24 | ID3D11Buffer *m_pVSConstantBuffer; 25 | ID3D11GeometryShader *m_pGS; 26 | ID3D11ClassInstance *m_pGSClassInstances[256]; 27 | UINT m_numGSClassInstances; 28 | ID3D11Buffer *m_pGSConstantBuffer; 29 | ID3D11ShaderResourceView *m_pGSSRV; 30 | ID3D11PixelShader *m_pPS; 31 | ID3D11ClassInstance *m_pPSClassInstances[256]; 32 | UINT m_numPSClassInstances; 33 | ID3D11HullShader *m_pHS; 34 | ID3D11ClassInstance *m_pHSClassInstances[256]; 35 | UINT m_numHSClassInstances; 36 | ID3D11DomainShader *m_pDS; 37 | ID3D11ClassInstance *m_pDSClassInstances[256]; 38 | UINT m_numDSClassInstances; 39 | ID3D11Buffer *m_pVB; 40 | UINT m_vertexStride; 41 | UINT m_vertexOffset; 42 | ID3D11Buffer *m_pIndexBuffer; 43 | DXGI_FORMAT m_indexFormat; 44 | UINT m_indexOffset; 45 | 46 | D3D11StateSaver(const D3D11StateSaver&); 47 | D3D11StateSaver& operator=(const D3D11StateSaver&); 48 | 49 | public: 50 | D3D11StateSaver(); 51 | ~D3D11StateSaver(); 52 | 53 | HRESULT saveCurrentState(ID3D11DeviceContext *pContext); 54 | HRESULT restoreSavedState(); 55 | void releaseSavedState(); 56 | }; -------------------------------------------------------------------------------- /lambsea/UndocumentNt.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UndocumentNt.h" 3 | #include 4 | fNtQuerySystemInformation NtQuerySystemInformation = (fNtQuerySystemInformation)GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtQuerySystemInformation"); 5 | 6 | struct UNICODE_STRING 7 | { 8 | WORD Length; 9 | WORD MaxLength; 10 | wchar_t * szBuffer; 11 | }; 12 | 13 | typedef struct _SYSTEM_PROCESS_INFO 14 | { 15 | ULONG NextEntryOffset; 16 | ULONG NumberOfThreads; 17 | LARGE_INTEGER Reserved[3]; 18 | LARGE_INTEGER CreateTime; 19 | LARGE_INTEGER UserTime; 20 | LARGE_INTEGER KernelTime; 21 | UNICODE_STRING ImageName; 22 | ULONG BasePriority; 23 | HANDLE ProcessId; 24 | HANDLE InheritedFromProcessId; 25 | }SYSTEM_PROCESS_INFO, *PSYSTEM_PROCESS_INFO; 26 | 27 | 28 | HANDLE NtQueryProcessStatus(HANDLE watchedPID) 29 | { 30 | NTSTATUS status; 31 | PVOID buffer; 32 | PSYSTEM_PROCESS_INFO psi = { 0 }; 33 | ULONG ReturnLenght = 0; 34 | 35 | 36 | status = NtQuerySystemInformation(SystemProcessInformation, NULL, NULL, &ReturnLenght); 37 | 38 | if (status != STATUS_INFO_LENGTH_MISMATCH && !NT_SUCCESS(status)) 39 | return (HANDLE)STATUS_ACCESS_DENIED; 40 | 41 | buffer = VirtualAlloc(NULL, ReturnLenght, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); 42 | 43 | if (!NT_SUCCESS(status = NtQuerySystemInformation(SystemProcessInformation, buffer, ReturnLenght, NULL))) 44 | { 45 | VirtualFree(buffer, 0, MEM_RELEASE); 46 | //printf("failed status is 0x%I64X", status); 47 | return (HANDLE)status; 48 | } 49 | 50 | psi = (PSYSTEM_PROCESS_INFO)buffer; 51 | 52 | while (psi->NextEntryOffset) // Loop over the list until we reach the last entry. 53 | { 54 | if (psi->ProcessId == watchedPID) 55 | { 56 | //printf("founded!\n"); 57 | HANDLE tmp = psi->ProcessId; 58 | VirtualFree(psi, 0, MEM_RELEASE); 59 | return tmp; 60 | } 61 | psi = (PSYSTEM_PROCESS_INFO)((LPBYTE)psi + psi->NextEntryOffset); // Calculate the address of the next entry. 62 | } 63 | 64 | VirtualFree(psi, 0, MEM_RELEASE); 65 | return (HANDLE)0xdeadbeef; 66 | } 67 | -------------------------------------------------------------------------------- /BEFucker/Helpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | namespace Helpers 5 | { 6 | void LogAddress(char* szName, uintptr_t iAddress); 7 | void LogError(char* szMessage); 8 | void Log(char* szMessage); 9 | void LogToFile(char* szMessage); 10 | void LogToFileEx(const char * szMessage); 11 | void LogAddressToFile(char * szMessage, uintptr_t iAddress); 12 | 13 | void LogValueToFile(char * szMessage, DWORD_PTR value); 14 | 15 | void HookFunction(PVOID *oFunction, PVOID pDetour); 16 | void UnhookFunction(PVOID *oFunction, PVOID pDetour); 17 | 18 | 19 | } 20 | 21 | namespace Iat_hook 22 | { 23 | 24 | inline void** find(const char* function, HMODULE module) 25 | { 26 | if (!module) 27 | module = GetModuleHandle(0); 28 | 29 | PIMAGE_DOS_HEADER img_dos_headers = (PIMAGE_DOS_HEADER)module; 30 | PIMAGE_NT_HEADERS img_nt_headers = (PIMAGE_NT_HEADERS)((BYTE*)img_dos_headers + img_dos_headers->e_lfanew); 31 | PIMAGE_IMPORT_DESCRIPTOR img_import_desc = (PIMAGE_IMPORT_DESCRIPTOR)((BYTE*)img_dos_headers + img_nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); 32 | if (img_dos_headers->e_magic != IMAGE_DOS_SIGNATURE) 33 | printf("ERROR: e_magic is no valid DOS signature\n"); 34 | 35 | for (IMAGE_IMPORT_DESCRIPTOR *iid = img_import_desc; iid->Name != 0; iid++) { 36 | for (int func_idx = 0; *(func_idx + (void**)(iid->FirstThunk + (size_t)module)) != nullptr; func_idx++) { 37 | char* mod_func_name = (char*)(*(func_idx + (size_t*)(iid->OriginalFirstThunk + (size_t)module)) + (size_t)module + 2); 38 | const intptr_t nmod_func_name = (intptr_t)mod_func_name; 39 | if (nmod_func_name >= 0) { 40 | if (!::strcmp(function, mod_func_name)) 41 | return func_idx + (void**)(iid->FirstThunk + (size_t)module); 42 | } 43 | } 44 | } 45 | 46 | return 0; 47 | 48 | } 49 | 50 | inline uintptr_t detour_iat_ptr(const char* function, void* newfunction, HMODULE module = 0) 51 | { 52 | auto&& func_ptr = find(function, module); 53 | if (*func_ptr == newfunction || *func_ptr == nullptr) 54 | return 0; 55 | 56 | uintptr_t ret = (uintptr_t)*func_ptr; 57 | *func_ptr = newfunction; 58 | 59 | return ret; 60 | } 61 | }; -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1GlyphVertexDrawer.h: -------------------------------------------------------------------------------- 1 | // CFW1GlyphVertexDrawer.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1GlyphVertexDrawer 4 | #define IncludeGuard__FW1_CFW1GlyphVertexDrawer 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Draws glyph-vertices from system memory using a dynamic vertex buffer 13 | class CFW1GlyphVertexDrawer : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1GlyphVertexDrawer 19 | virtual HRESULT STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice); 20 | 21 | virtual UINT STDMETHODCALLTYPE DrawVertices( 22 | ID3D11DeviceContext *pContext, 23 | IFW1GlyphAtlas *pGlyphAtlas, 24 | const FW1_VERTEXDATA *pVertexData, 25 | UINT Flags, 26 | UINT PreboundSheet 27 | ); 28 | 29 | // Public functions 30 | public: 31 | CFW1GlyphVertexDrawer(); 32 | 33 | HRESULT initVertexDrawer(IFW1Factory *pFW1Factory, ID3D11Device *pDevice, UINT vertexBufferSize); 34 | 35 | // Internal types 36 | private: 37 | struct QuadVertex { 38 | FLOAT positionX; 39 | FLOAT positionY; 40 | FLOAT texCoordX; 41 | FLOAT texCoordY; 42 | UINT32 color; 43 | }; 44 | 45 | // Internal functions 46 | private: 47 | virtual ~CFW1GlyphVertexDrawer(); 48 | 49 | HRESULT createBuffers(); 50 | 51 | UINT drawVertices( 52 | ID3D11DeviceContext *pContext, 53 | IFW1GlyphAtlas *pGlyphAtlas, 54 | const FW1_VERTEXDATA *vertexData, 55 | UINT preboundSheet 56 | ); 57 | UINT drawGlyphsAsQuads( 58 | ID3D11DeviceContext *pContext, 59 | IFW1GlyphAtlas *pGlyphAtlas, 60 | const FW1_VERTEXDATA *vertexData, 61 | UINT preboundSheet 62 | ); 63 | 64 | // Internal data 65 | private: 66 | std::wstring m_lastError; 67 | 68 | ID3D11Device *m_pDevice; 69 | 70 | ID3D11Buffer *m_pVertexBuffer; 71 | ID3D11Buffer *m_pIndexBuffer; 72 | UINT m_vertexBufferSize; 73 | UINT m_maxIndexCount; 74 | }; 75 | 76 | 77 | }// namespace FW1FontWrapper 78 | 79 | 80 | #endif// IncludeGuard__FW1_CFW1GlyphVertexDrawer 81 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1DWriteRenderTarget.h: -------------------------------------------------------------------------------- 1 | // CFW1DWriteRenderTarget.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1DWriteRenderTarget 4 | #define IncludeGuard__FW1_CFW1DWriteRenderTarget 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Render target that provides pixels of one glyph-image at a time 13 | class CFW1DWriteRenderTarget : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1DWriteRenderTarget 19 | virtual HRESULT STDMETHODCALLTYPE DrawGlyphTemp( 20 | IDWriteFontFace *pFontFace, 21 | UINT16 GlyphIndex, 22 | FLOAT FontSize, 23 | DWRITE_RENDERING_MODE RenderingMode, 24 | DWRITE_MEASURING_MODE MeasuringMode, 25 | FW1_GLYPHIMAGEDATA *pOutData 26 | ); 27 | 28 | // Public functions 29 | public: 30 | CFW1DWriteRenderTarget(); 31 | 32 | HRESULT initRenderTarget( 33 | IFW1Factory *pFW1Factory, 34 | IDWriteFactory *pDWriteFactory, 35 | UINT renderTargetWidth, 36 | UINT renderTargetHeight 37 | ); 38 | 39 | // Internal types 40 | private: 41 | struct DWGlyphData { 42 | FLOAT offsetX; 43 | FLOAT offsetY; 44 | LONG maxWidth; 45 | LONG maxHeight; 46 | }; 47 | 48 | typedef std::map RenderingParamsMap; 49 | 50 | // Internal functions 51 | private: 52 | virtual ~CFW1DWriteRenderTarget(); 53 | 54 | HRESULT createRenderTarget(IDWriteFactory *pDWriteFactory); 55 | 56 | void initGlyphData( 57 | const DWRITE_FONT_METRICS *fontMetrics, 58 | const DWRITE_GLYPH_METRICS *glyphMetrics, 59 | FLOAT fontSize, 60 | DWGlyphData *outGlyphData 61 | ); 62 | 63 | // Internal data 64 | private: 65 | std::wstring m_lastError; 66 | 67 | IDWriteBitmapRenderTarget *m_pRenderTarget; 68 | HDC m_hDC; 69 | HBRUSH m_hBlackBrush; 70 | LPVOID m_bmBits; 71 | UINT m_bmWidthBytes; 72 | UINT m_bmBytesPixel; 73 | UINT m_renderTargetWidth; 74 | UINT m_renderTargetHeight; 75 | RenderingParamsMap m_renderingParams; 76 | }; 77 | 78 | 79 | }// namespace FW1FontWrapper 80 | 81 | 82 | #endif// IncludeGuard__FW1_CFW1DWriteRenderTarget 83 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1Factory.cpp: -------------------------------------------------------------------------------- 1 | // CFW1Factory.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1Factory.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Construct 12 | CFW1Factory::CFW1Factory() : 13 | m_cRefCount(1) 14 | { 15 | InitializeCriticalSection(&m_errorStringCriticalSection); 16 | } 17 | 18 | 19 | // Destruct 20 | CFW1Factory::~CFW1Factory() { 21 | DeleteCriticalSection(&m_errorStringCriticalSection); 22 | } 23 | 24 | 25 | // Init 26 | HRESULT CFW1Factory::initFactory() { 27 | return S_OK; 28 | } 29 | 30 | 31 | // Create a DWrite factory 32 | HRESULT CFW1Factory::createDWriteFactory(IDWriteFactory **ppDWriteFactory) { 33 | HRESULT hResult = E_FAIL; 34 | 35 | typedef HRESULT (WINAPI * PFN_DWRITECREATEFACTORY)(__in DWRITE_FACTORY_TYPE factoryType, __in REFIID iid, __out IUnknown **factory); 36 | PFN_DWRITECREATEFACTORY pfnDWriteCreateFactory = NULL; 37 | 38 | #ifdef FW1_DELAYLOAD_DWRITE_DLL 39 | HMODULE hDWriteLib = LoadLibrary(TEXT("DWrite.dll")); 40 | if(hDWriteLib == NULL) { 41 | DWORD dwErr = GetLastError(); 42 | dwErr; 43 | setErrorString(L"Failed to load DWrite.dll"); 44 | } 45 | else { 46 | pfnDWriteCreateFactory = 47 | reinterpret_cast(GetProcAddress(hDWriteLib, "DWriteCreateFactory")); 48 | if(pfnDWriteCreateFactory == NULL) { 49 | DWORD dwErr = GetLastError(); 50 | dwErr; 51 | setErrorString(L"Failed to load DWriteCreateFactory"); 52 | } 53 | } 54 | #else 55 | pfnDWriteCreateFactory = DWriteCreateFactory; 56 | #endif 57 | 58 | if(pfnDWriteCreateFactory != NULL) { 59 | IDWriteFactory *pDWriteFactory; 60 | 61 | hResult = pfnDWriteCreateFactory( 62 | DWRITE_FACTORY_TYPE_SHARED, 63 | __uuidof(IDWriteFactory), 64 | reinterpret_cast(&pDWriteFactory) 65 | ); 66 | if(FAILED(hResult)) { 67 | setErrorString(L"DWriteCreateFactory failed"); 68 | } 69 | else { 70 | *ppDWriteFactory = pDWriteFactory; 71 | 72 | hResult = S_OK; 73 | } 74 | } 75 | 76 | return hResult; 77 | } 78 | 79 | 80 | // Set error string 81 | void CFW1Factory::setErrorString(const wchar_t *str) { 82 | EnterCriticalSection(&m_errorStringCriticalSection); 83 | m_lastError = str; 84 | LeaveCriticalSection(&m_errorStringCriticalSection); 85 | } 86 | 87 | 88 | }// namespace FW1FontWrapper 89 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1StateSaver.h: -------------------------------------------------------------------------------- 1 | // CFW1StateSaver.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1StateSaver 4 | #define IncludeGuard__FW1_CFW1StateSaver 5 | 6 | 7 | namespace FW1FontWrapper { 8 | 9 | 10 | // Saves all the states that can be changed when drawing a string 11 | class CFW1StateSaver { 12 | // Public functions 13 | public: 14 | CFW1StateSaver(); 15 | ~CFW1StateSaver(); 16 | 17 | HRESULT saveCurrentState(ID3D11DeviceContext *pContext); 18 | HRESULT restoreSavedState(); 19 | void releaseSavedState(); 20 | 21 | // Internal data 22 | private: 23 | bool m_savedState; 24 | D3D_FEATURE_LEVEL m_featureLevel; 25 | ID3D11DeviceContext *m_pContext; 26 | D3D11_PRIMITIVE_TOPOLOGY m_primitiveTopology; 27 | ID3D11InputLayout *m_pInputLayout; 28 | ID3D11BlendState *m_pBlendState; 29 | FLOAT m_blendFactor[4]; 30 | UINT m_sampleMask; 31 | ID3D11DepthStencilState *m_pDepthStencilState; 32 | UINT m_stencilRef; 33 | ID3D11RasterizerState *m_pRasterizerState; 34 | ID3D11ShaderResourceView *m_pPSSRV; 35 | ID3D11SamplerState *m_pSamplerState; 36 | ID3D11VertexShader *m_pVS; 37 | ID3D11ClassInstance *m_pVSClassInstances[256]; 38 | UINT m_numVSClassInstances; 39 | ID3D11Buffer *m_pVSConstantBuffer; 40 | ID3D11GeometryShader *m_pGS; 41 | ID3D11ClassInstance *m_pGSClassInstances[256]; 42 | UINT m_numGSClassInstances; 43 | ID3D11Buffer *m_pGSConstantBuffer; 44 | ID3D11ShaderResourceView *m_pGSSRV; 45 | ID3D11PixelShader *m_pPS; 46 | ID3D11ClassInstance *m_pPSClassInstances[256]; 47 | UINT m_numPSClassInstances; 48 | ID3D11HullShader *m_pHS; 49 | ID3D11ClassInstance *m_pHSClassInstances[256]; 50 | UINT m_numHSClassInstances; 51 | ID3D11DomainShader *m_pDS; 52 | ID3D11ClassInstance *m_pDSClassInstances[256]; 53 | UINT m_numDSClassInstances; 54 | ID3D11Buffer *m_pVB; 55 | UINT m_vertexStride; 56 | UINT m_vertexOffset; 57 | ID3D11Buffer *m_pIndexBuffer; 58 | DXGI_FORMAT m_indexFormat; 59 | UINT m_indexOffset; 60 | 61 | private: 62 | CFW1StateSaver(const CFW1StateSaver&); 63 | CFW1StateSaver& operator=(const CFW1StateSaver&); 64 | }; 65 | 66 | 67 | }// namespace FW1FontWrapper 68 | 69 | 70 | #endif// IncludeGuard__FW1_CFW1StateSaver 71 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1Object.h: -------------------------------------------------------------------------------- 1 | // CFW1Object.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1Object 4 | #define IncludeGuard__FW1_CFW1Object 5 | 6 | 7 | namespace FW1FontWrapper { 8 | 9 | 10 | // Helper baseclass to avoid writing IUnknown and IFW1Object implementations once per class 11 | template 12 | class CFW1Object : public IBase { 13 | public: 14 | // IUnknown 15 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) = 0 { 16 | if(ppvObject == NULL) 17 | return E_INVALIDARG; 18 | 19 | if(IsEqualIID(riid, __uuidof(IUnknown))) { 20 | *ppvObject = static_cast(this); 21 | AddRef(); 22 | return S_OK; 23 | } 24 | else if(IsEqualIID(riid, __uuidof(IFW1Object))) { 25 | *ppvObject = static_cast(this); 26 | AddRef(); 27 | return S_OK; 28 | } 29 | 30 | *ppvObject = NULL; 31 | return E_NOINTERFACE; 32 | } 33 | 34 | virtual ULONG STDMETHODCALLTYPE AddRef() { 35 | return static_cast(InterlockedIncrement(reinterpret_cast(&m_cRefCount))); 36 | } 37 | 38 | virtual ULONG STDMETHODCALLTYPE Release() { 39 | ULONG newCount = static_cast(InterlockedDecrement(reinterpret_cast(&m_cRefCount))); 40 | 41 | if(newCount == 0) 42 | delete this; 43 | 44 | return newCount; 45 | } 46 | 47 | // IFW1Object 48 | virtual HRESULT STDMETHODCALLTYPE GetFactory(IFW1Factory **ppFW1Factory) { 49 | if(ppFW1Factory == NULL) 50 | return E_INVALIDARG; 51 | 52 | m_pFW1Factory->AddRef(); 53 | *ppFW1Factory = m_pFW1Factory; 54 | 55 | return S_OK; 56 | } 57 | 58 | // Internal functions 59 | protected: 60 | CFW1Object() : 61 | m_cRefCount(1), 62 | 63 | m_pFW1Factory(NULL) 64 | { 65 | } 66 | 67 | virtual ~CFW1Object() { 68 | if(m_pFW1Factory != NULL) 69 | m_pFW1Factory->Release(); 70 | } 71 | 72 | HRESULT initBaseObject(IFW1Factory *pFW1Factory) { 73 | if(pFW1Factory == NULL) 74 | return E_INVALIDARG; 75 | 76 | pFW1Factory->AddRef(); 77 | m_pFW1Factory = pFW1Factory; 78 | 79 | return S_OK; 80 | } 81 | 82 | // Internal data 83 | protected: 84 | IFW1Factory *m_pFW1Factory; 85 | 86 | private: 87 | ULONG m_cRefCount; 88 | 89 | private: 90 | CFW1Object(const CFW1Object&); 91 | CFW1Object& operator=(const CFW1Object&); 92 | }; 93 | 94 | 95 | }// namespace FW1FontWrapper 96 | 97 | 98 | #endif// IncludeGuard__FW1_CFW1Object 99 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1GlyphAtlas.h: -------------------------------------------------------------------------------- 1 | // CFW1GlyphAtlas.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1GlyphAtlas 4 | #define IncludeGuard__FW1_CFW1GlyphAtlas 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | class CFW1GlyphAtlas : public CFW1Object { 13 | // Interface 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1GlyphAtlas 19 | virtual HRESULT STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice); 20 | 21 | virtual UINT STDMETHODCALLTYPE GetTotalGlyphCount(); 22 | virtual UINT STDMETHODCALLTYPE GetSheetCount(); 23 | 24 | virtual HRESULT STDMETHODCALLTYPE GetSheet(UINT SheetIndex, IFW1GlyphSheet **ppGlyphSheet); 25 | 26 | virtual const FW1_GLYPHCOORDS* STDMETHODCALLTYPE GetGlyphCoords(UINT SheetIndex); 27 | virtual HRESULT STDMETHODCALLTYPE BindSheet(ID3D11DeviceContext *pContext, UINT SheetIndex, UINT Flags); 28 | 29 | virtual UINT STDMETHODCALLTYPE InsertGlyph( 30 | const FW1_GLYPHMETRICS *pGlyphMetrics, 31 | const void *pGlyphData, 32 | UINT RowPitch, 33 | UINT PixelStride 34 | ); 35 | virtual UINT STDMETHODCALLTYPE InsertSheet(IFW1GlyphSheet *pGlyphSheet); 36 | virtual void STDMETHODCALLTYPE Flush(ID3D11DeviceContext *pContext); 37 | 38 | // Public functions 39 | public: 40 | CFW1GlyphAtlas(); 41 | 42 | HRESULT initGlyphAtlas( 43 | IFW1Factory *pFW1Factory, 44 | ID3D11Device *pDevice, 45 | UINT sheetWidth, 46 | UINT sheetHeight, 47 | bool coordBuffer, 48 | bool allowOversizedTexture, 49 | UINT maxGlyphCountPerSheet, 50 | UINT mipLevelCount, 51 | UINT maxSheetCount 52 | ); 53 | 54 | // Internal functions 55 | private: 56 | virtual ~CFW1GlyphAtlas(); 57 | 58 | HRESULT createGlyphSheet(IFW1GlyphSheet **ppGlyphSheet); 59 | 60 | // Internal data 61 | private: 62 | ID3D11Device *m_pDevice; 63 | UINT m_sheetWidth; 64 | UINT m_sheetHeight; 65 | bool m_hardwareCoordBuffer; 66 | bool m_allowOversizedGlyph; 67 | UINT m_maxGlyphCount; 68 | UINT m_mipLevelCount; 69 | 70 | IFW1GlyphSheet **m_glyphSheets; 71 | UINT m_sheetCount; 72 | UINT m_maxSheetCount; 73 | UINT m_currentSheetIndex; 74 | UINT m_flushedSheetIndex; 75 | 76 | CRITICAL_SECTION m_glyphSheetsCriticalSection; 77 | }; 78 | 79 | 80 | }// namespace FW1FontWrapper 81 | 82 | 83 | #endif// IncludeGuard__FW1_CFW1GlyphAtlas 84 | -------------------------------------------------------------------------------- /lambsea/XorStrings.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Compile Time String Encryption 4 | // Prevent strings from being stored in rdata/data 5 | // Inline strings in .text and store these on the stack when decrypting 6 | // After the string is decreypted and used, it disappears right away 7 | // How to use: XorString("String") 8 | // Purpose: Prevent generic scan to trigger in case hooks fail 9 | // Initally wrote by LeFF (for malwares) 10 | 11 | #define CompileTimeAsSeed ((__TIME__[7] - '0') * 1 + (__TIME__[6] - '0') * 10 + \ 12 | (__TIME__[4] - '0') * 60 + (__TIME__[3] - '0') * 600 + \ 13 | (__TIME__[1] - '0') * 3600 + (__TIME__[0] - '0') * 36000) 14 | 15 | template struct EnsureCompileTime { 16 | enum : int { 17 | Value = X 18 | }; 19 | }; 20 | 21 | constexpr int LinearCongruentGenerator(int Rounds) { 22 | return 1013904223 + 1664525 * ((Rounds> 0) ? LinearCongruentGenerator(Rounds - 1) : CompileTimeAsSeed & 0xFFFFFFFF); 23 | } 24 | 25 | #define Random() EnsureCompileTime::Value 26 | #define RandomNumber(Min, Max) (Min + (Random() % (Max - Min + 1))) 27 | 28 | template struct IndexList {}; 29 | 30 | template struct Append; 31 | template struct Append, Right> { 32 | typedef IndexList Result; 33 | }; 34 | 35 | template struct ConstructIndexList { 36 | typedef typename Append::Result, N - 1>::Result Result; 37 | }; 38 | template <> struct ConstructIndexList<0> { 39 | typedef IndexList<> Result; 40 | }; 41 | 42 | const char XORKEY = static_cast(RandomNumber(0, 0xFF)); 43 | constexpr char EncryptCharacter(const char Character, int Index) { 44 | return Character ^ (XORKEY + Index); 45 | } 46 | 47 | template class CXorString; 48 | template class CXorString > { 49 | private: 50 | char Value[sizeof...(Index) + 1]; 51 | public: 52 | constexpr CXorString(const char* const String) 53 | : Value{ EncryptCharacter(String[Index], Index)... } {} 54 | 55 | char* decrypt() { 56 | for(int t = 0; t < sizeof...(Index); t++) { 57 | Value[t] = Value[t] ^ (XORKEY + t); 58 | } 59 | Value[sizeof...(Index)] = '\0'; 60 | return Value; 61 | } 62 | 63 | char* get() { 64 | return Value; 65 | } 66 | }; 67 | 68 | #define XorS(X, String) CXorString::Result> X(String) 69 | #define XorString( String ) ( CXorString::Result>( String ).decrypt() ) -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1GlyphRenderStates.h: -------------------------------------------------------------------------------- 1 | // CFW1GlyphRenderStates.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1GlyphRenderStates 4 | #define IncludeGuard__FW1_CFW1GlyphRenderStates 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Shader etc. needed to draw glyphs 13 | class CFW1GlyphRenderStates : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1GlyphRenderStates 19 | virtual HRESULT STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice); 20 | 21 | virtual void STDMETHODCALLTYPE SetStates(ID3D11DeviceContext *pContext, UINT Flags); 22 | virtual void STDMETHODCALLTYPE UpdateShaderConstants( 23 | ID3D11DeviceContext *pContext, 24 | const FW1_RECTF *pClipRect, 25 | const FLOAT *pTransformMatrix 26 | ); 27 | virtual BOOL STDMETHODCALLTYPE HasGeometryShader(); 28 | 29 | // Public functions 30 | public: 31 | CFW1GlyphRenderStates(); 32 | 33 | HRESULT initRenderResources( 34 | IFW1Factory *pFW1Factory, 35 | ID3D11Device *pDevice, 36 | bool wantGeometryShader, 37 | bool anisotropicFiltering 38 | ); 39 | 40 | // Internal types 41 | private: 42 | struct ShaderConstants { 43 | FLOAT TransformMatrix[16]; 44 | FLOAT ClipRect[4]; 45 | }; 46 | 47 | // Internal functions 48 | private: 49 | virtual ~CFW1GlyphRenderStates(); 50 | 51 | HRESULT createQuadShaders(); 52 | HRESULT createGlyphShaders(); 53 | HRESULT createPixelShaders(); 54 | HRESULT createConstantBuffer(); 55 | HRESULT createRenderStates(bool anisotropicFiltering); 56 | 57 | // Internal data 58 | private: 59 | std::wstring m_lastError; 60 | 61 | pD3DCompile m_pfnD3DCompile; 62 | 63 | ID3D11Device *m_pDevice; 64 | D3D_FEATURE_LEVEL m_featureLevel; 65 | 66 | ID3D11VertexShader *m_pVertexShaderQuad; 67 | ID3D11VertexShader *m_pVertexShaderClipQuad; 68 | ID3D11InputLayout *m_pQuadInputLayout; 69 | 70 | ID3D11VertexShader *m_pVertexShaderPoint; 71 | ID3D11InputLayout *m_pPointInputLayout; 72 | ID3D11GeometryShader *m_pGeometryShaderPoint; 73 | ID3D11GeometryShader *m_pGeometryShaderClipPoint; 74 | bool m_hasGeometryShader; 75 | 76 | ID3D11PixelShader *m_pPixelShader; 77 | ID3D11PixelShader *m_pPixelShaderClip; 78 | 79 | ID3D11Buffer *m_pConstantBuffer; 80 | 81 | ID3D11BlendState *m_pBlendState; 82 | ID3D11SamplerState *m_pSamplerState; 83 | ID3D11RasterizerState *m_pRasterizerState; 84 | ID3D11DepthStencilState *m_pDepthStencilState; 85 | }; 86 | 87 | 88 | }// namespace FW1FontWrapper 89 | 90 | 91 | #endif// IncludeGuard__FW1_CFW1GlyphRenderStates 92 | -------------------------------------------------------------------------------- /External.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26730.12 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BEFucker", "BEFucker\BEFucker.vcxproj", "{A10735E8-909A-42E7-805B-B1B3BD3BE762}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lambsea", "lambsea\lambsea.vcxproj", "{9063F6A0-C241-44B7-8985-C654EBA7BB43}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LambseaLoader", "LambseaLoader\LambseaLib.vcxproj", "{4978F2E2-D242-4D82-931C-F65028592DD4}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|x64 = Debug|x64 15 | Debug|x86 = Debug|x86 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {A10735E8-909A-42E7-805B-B1B3BD3BE762}.Debug|x64.ActiveCfg = Debug|x64 21 | {A10735E8-909A-42E7-805B-B1B3BD3BE762}.Debug|x64.Build.0 = Debug|x64 22 | {A10735E8-909A-42E7-805B-B1B3BD3BE762}.Debug|x86.ActiveCfg = Debug|Win32 23 | {A10735E8-909A-42E7-805B-B1B3BD3BE762}.Debug|x86.Build.0 = Debug|Win32 24 | {A10735E8-909A-42E7-805B-B1B3BD3BE762}.Release|x64.ActiveCfg = Release|x64 25 | {A10735E8-909A-42E7-805B-B1B3BD3BE762}.Release|x64.Build.0 = Release|x64 26 | {A10735E8-909A-42E7-805B-B1B3BD3BE762}.Release|x86.ActiveCfg = Release|Win32 27 | {A10735E8-909A-42E7-805B-B1B3BD3BE762}.Release|x86.Build.0 = Release|Win32 28 | {9063F6A0-C241-44B7-8985-C654EBA7BB43}.Debug|x64.ActiveCfg = Debug|x64 29 | {9063F6A0-C241-44B7-8985-C654EBA7BB43}.Debug|x64.Build.0 = Debug|x64 30 | {9063F6A0-C241-44B7-8985-C654EBA7BB43}.Debug|x86.ActiveCfg = Debug|Win32 31 | {9063F6A0-C241-44B7-8985-C654EBA7BB43}.Debug|x86.Build.0 = Debug|Win32 32 | {9063F6A0-C241-44B7-8985-C654EBA7BB43}.Release|x64.ActiveCfg = Release|x64 33 | {9063F6A0-C241-44B7-8985-C654EBA7BB43}.Release|x64.Build.0 = Release|x64 34 | {9063F6A0-C241-44B7-8985-C654EBA7BB43}.Release|x86.ActiveCfg = Release|Win32 35 | {9063F6A0-C241-44B7-8985-C654EBA7BB43}.Release|x86.Build.0 = Release|Win32 36 | {4978F2E2-D242-4D82-931C-F65028592DD4}.Debug|x64.ActiveCfg = Debug|x64 37 | {4978F2E2-D242-4D82-931C-F65028592DD4}.Debug|x64.Build.0 = Debug|x64 38 | {4978F2E2-D242-4D82-931C-F65028592DD4}.Debug|x86.ActiveCfg = Debug|Win32 39 | {4978F2E2-D242-4D82-931C-F65028592DD4}.Debug|x86.Build.0 = Debug|Win32 40 | {4978F2E2-D242-4D82-931C-F65028592DD4}.Release|x64.ActiveCfg = Release|x64 41 | {4978F2E2-D242-4D82-931C-F65028592DD4}.Release|x64.Build.0 = Release|x64 42 | {4978F2E2-D242-4D82-931C-F65028592DD4}.Release|x86.ActiveCfg = Release|Win32 43 | {4978F2E2-D242-4D82-931C-F65028592DD4}.Release|x86.Build.0 = Release|Win32 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {E3CDBB2D-353C-45FA-87C5-66018A88BFE1} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /lambsea/D3D11Render/D3D11Renderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #pragma warning (push) 4 | #pragma warning (disable: 4005) 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #pragma warning (pop) 13 | #include 14 | #include 15 | 16 | #include "Helper.h" 17 | #include "D3D11StateSaver.h" 18 | #include "D3D11Shader.h" 19 | #pragma comment(lib, "d3d11.lib") 20 | 21 | #include "../FW1FontWrapper/FW1FontWrapper.h" 22 | 23 | typedef unsigned char uchar; 24 | 25 | class Color 26 | { 27 | public: 28 | uchar A, R, G, B; 29 | 30 | Color() 31 | { 32 | A = R = G = B = 0; 33 | } 34 | 35 | Color(uchar A, uchar R, uchar G, uchar B) 36 | { 37 | this->A = A; 38 | this->R = R; 39 | this->G = G; 40 | this->B = B; 41 | } 42 | }; 43 | 44 | class D3D11Renderer 45 | { 46 | private: 47 | struct COLOR_VERTEX 48 | { 49 | D3DXVECTOR3 Position; 50 | D3DXCOLOR Color; 51 | }; 52 | 53 | ID3D11RasterizerState * rwState; 54 | ID3D11RasterizerState * rsState; 55 | 56 | enum eDepthState 57 | { 58 | ENABLED, 59 | DISABLED, 60 | READ_NO_WRITE, 61 | NO_READ_NO_WRITE, 62 | _DEPTH_COUNT 63 | }; 64 | 65 | ID3D11DepthStencilState* myDepthStencilStates[static_cast(eDepthState::_DEPTH_COUNT)]; 66 | 67 | IDXGISwapChain *swapChain; 68 | ID3D11Device *device; 69 | ID3D11DeviceContext *deviceContext; 70 | ID3D11InputLayout *mInputLayout; 71 | ID3D11Buffer *mVertexBuffer; 72 | ID3D11VertexShader *mVS; 73 | ID3D11PixelShader *mPS; 74 | ID3D11BlendState *transparency; 75 | 76 | ID3D11Texture2D* RenderTargetTexture; 77 | ID3D11RenderTargetView* RenderTargetView; 78 | 79 | D3D11StateSaver *stateSaver; 80 | bool restoreState = false; 81 | IFW1FontWrapper *pFontWrapper; 82 | 83 | public: 84 | D3D11Renderer(IDXGISwapChain *SwapChain); 85 | ~D3D11Renderer(); 86 | 87 | bool Initialize(); 88 | bool InitializePresent(); 89 | 90 | void FillRect(float x, float y, float w, float h, Color color); 91 | void DrawLine(float x1, float y1, float x2, float y2, Color color); 92 | void DrawHealthBar(float x, float y, float w, float health, float max); 93 | void DrawHealthBar(float x, float y, float w, float h, float health, float max); 94 | 95 | void DrawRectangle(float width, float height, float centerx, float centery, Color color); 96 | void DrawCircle(int x0, int y0, int radius, float thickness, Color color); 97 | void DrawCircleEx(float r, float centerx, float centery, Color color); 98 | void DrawString(int x, int y, DWORD color, void* g_pFont, const wchar_t *fmt, ...); 99 | void DrawBox(float x, float y, float width, float height, Color color); 100 | 101 | void* GetFont(); 102 | 103 | ID3D11Device* GetDevice() { return this->device; }; 104 | ID3D11DeviceContext* GetContext() { return this->deviceContext; }; 105 | ID3D11RenderTargetView* GetRTV() { return this->RenderTargetView; }; 106 | 107 | float GetScreenWidth(); 108 | float GetScreenHeight(); 109 | void BeginScene(); 110 | void EndScene(); 111 | }; -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1GlyphAtlas.cpp: -------------------------------------------------------------------------------- 1 | // CFW1GlyphAtlas.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1GlyphAtlas.h" 6 | 7 | #define SAFE_RELEASE(pObject) { if(pObject) { (pObject)->Release(); (pObject) = NULL; } } 8 | 9 | 10 | namespace FW1FontWrapper { 11 | 12 | 13 | // Construct 14 | CFW1GlyphAtlas::CFW1GlyphAtlas() : 15 | m_pDevice(NULL), 16 | m_sheetWidth(0), 17 | m_sheetHeight(0), 18 | m_hardwareCoordBuffer(false), 19 | m_allowOversizedGlyph(false), 20 | m_maxGlyphCount(0), 21 | m_mipLevelCount(0), 22 | 23 | m_glyphSheets(0), 24 | m_sheetCount(0), 25 | m_maxSheetCount(0), 26 | m_currentSheetIndex(0), 27 | m_flushedSheetIndex(0) 28 | { 29 | InitializeCriticalSection(&m_glyphSheetsCriticalSection); 30 | } 31 | 32 | 33 | // Destruct 34 | CFW1GlyphAtlas::~CFW1GlyphAtlas() { 35 | SAFE_RELEASE(m_pDevice); 36 | 37 | for(UINT i=0; i < m_sheetCount; ++i) 38 | m_glyphSheets[i]->Release(); 39 | delete[] m_glyphSheets; 40 | 41 | DeleteCriticalSection(&m_glyphSheetsCriticalSection); 42 | } 43 | 44 | 45 | // Init 46 | HRESULT CFW1GlyphAtlas::initGlyphAtlas( 47 | IFW1Factory *pFW1Factory, 48 | ID3D11Device *pDevice, 49 | UINT sheetWidth, 50 | UINT sheetHeight, 51 | bool coordBuffer, 52 | bool allowOversizedGlyph, 53 | UINT maxGlyphCount, 54 | UINT mipLevelCount, 55 | UINT maxSheetCount 56 | ) { 57 | HRESULT hResult = initBaseObject(pFW1Factory); 58 | if(FAILED(hResult)) 59 | return hResult; 60 | 61 | if(pDevice == NULL) 62 | return E_INVALIDARG; 63 | 64 | pDevice->AddRef(); 65 | m_pDevice = pDevice; 66 | 67 | m_sheetWidth = sheetWidth; 68 | m_sheetHeight = sheetHeight; 69 | m_hardwareCoordBuffer = coordBuffer; 70 | m_allowOversizedGlyph = allowOversizedGlyph; 71 | m_mipLevelCount = mipLevelCount; 72 | m_maxGlyphCount = maxGlyphCount; 73 | 74 | m_maxSheetCount = 4096; 75 | if(maxSheetCount > 0 && maxSheetCount < 655536) 76 | m_maxSheetCount = maxSheetCount; 77 | m_glyphSheets = new IFW1GlyphSheet* [m_maxSheetCount]; 78 | 79 | // Default glyph 80 | BYTE glyph0Pixels[256]; 81 | FillMemory(glyph0Pixels, 256, 0xff); 82 | 83 | FW1_GLYPHMETRICS glyph0Metrics; 84 | glyph0Metrics.OffsetX = 0.0f; 85 | glyph0Metrics.OffsetY = 0.0f; 86 | glyph0Metrics.Width = 16; 87 | glyph0Metrics.Height = 16; 88 | 89 | UINT glyph0 = InsertGlyph(&glyph0Metrics, glyph0Pixels, 16, 1); 90 | if(glyph0 == 0xffffffff) 91 | return E_FAIL; 92 | else 93 | return S_OK; 94 | } 95 | 96 | 97 | // Create new glyph sheet 98 | HRESULT CFW1GlyphAtlas::createGlyphSheet(IFW1GlyphSheet **ppGlyphSheet) { 99 | IFW1GlyphSheet *pGlyphSheet; 100 | HRESULT hResult = m_pFW1Factory->CreateGlyphSheet( 101 | m_pDevice, 102 | m_sheetWidth, 103 | m_sheetHeight, 104 | m_hardwareCoordBuffer, 105 | m_allowOversizedGlyph, 106 | m_maxGlyphCount, 107 | m_mipLevelCount, 108 | &pGlyphSheet 109 | ); 110 | if(FAILED(hResult)) { 111 | } 112 | else { 113 | *ppGlyphSheet = pGlyphSheet; 114 | 115 | hResult = S_OK; 116 | } 117 | 118 | return hResult; 119 | } 120 | 121 | 122 | }// namespace FW1FontWrapper 123 | -------------------------------------------------------------------------------- /LambseaLoader/hde/hde64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde64.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE64_H_ 11 | #define _HDE64_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include "pstdint.h" 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_IMM64 0x00000020 30 | #define F_DISP8 0x00000040 31 | #define F_DISP16 0x00000080 32 | #define F_DISP32 0x00000100 33 | #define F_RELATIVE 0x00000200 34 | #define F_ERROR 0x00001000 35 | #define F_ERROR_OPCODE 0x00002000 36 | #define F_ERROR_LENGTH 0x00004000 37 | #define F_ERROR_LOCK 0x00008000 38 | #define F_ERROR_OPERAND 0x00010000 39 | #define F_PREFIX_REPNZ 0x01000000 40 | #define F_PREFIX_REPX 0x02000000 41 | #define F_PREFIX_REP 0x03000000 42 | #define F_PREFIX_66 0x04000000 43 | #define F_PREFIX_67 0x08000000 44 | #define F_PREFIX_LOCK 0x10000000 45 | #define F_PREFIX_SEG 0x20000000 46 | #define F_PREFIX_REX 0x40000000 47 | #define F_PREFIX_ANY 0x7f000000 48 | 49 | #define PREFIX_SEGMENT_CS 0x2e 50 | #define PREFIX_SEGMENT_SS 0x36 51 | #define PREFIX_SEGMENT_DS 0x3e 52 | #define PREFIX_SEGMENT_ES 0x26 53 | #define PREFIX_SEGMENT_FS 0x64 54 | #define PREFIX_SEGMENT_GS 0x65 55 | #define PREFIX_LOCK 0xf0 56 | #define PREFIX_REPNZ 0xf2 57 | #define PREFIX_REPX 0xf3 58 | #define PREFIX_OPERAND_SIZE 0x66 59 | #define PREFIX_ADDRESS_SIZE 0x67 60 | 61 | #pragma pack(push,1) 62 | 63 | typedef struct { 64 | uint8_t len; 65 | uint8_t p_rep; 66 | uint8_t p_lock; 67 | uint8_t p_seg; 68 | uint8_t p_66; 69 | uint8_t p_67; 70 | uint8_t rex; 71 | uint8_t rex_w; 72 | uint8_t rex_r; 73 | uint8_t rex_x; 74 | uint8_t rex_b; 75 | uint8_t opcode; 76 | uint8_t opcode2; 77 | uint8_t modrm; 78 | uint8_t modrm_mod; 79 | uint8_t modrm_reg; 80 | uint8_t modrm_rm; 81 | uint8_t sib; 82 | uint8_t sib_scale; 83 | uint8_t sib_index; 84 | uint8_t sib_base; 85 | union { 86 | uint8_t imm8; 87 | uint16_t imm16; 88 | uint32_t imm32; 89 | uint64_t imm64; 90 | } imm; 91 | union { 92 | uint8_t disp8; 93 | uint16_t disp16; 94 | uint32_t disp32; 95 | } disp; 96 | uint32_t flags; 97 | } hde64s; 98 | 99 | #pragma pack(pop) 100 | 101 | #ifdef __cplusplus 102 | extern "C" { 103 | #endif 104 | 105 | /* __cdecl */ 106 | unsigned int hde64_disasm(const void *code, hde64s *hs); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* _HDE64_H_ */ 113 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1GlyphProvider.h: -------------------------------------------------------------------------------- 1 | // CFW1GlyphProvider.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1GlyphProvider 4 | #define IncludeGuard__FW1_CFW1GlyphProvider 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Fonts and glyphs-maps collection to match glyphs to images in a glyph-atlas 13 | class CFW1GlyphProvider : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1GlyphProvider 19 | virtual HRESULT STDMETHODCALLTYPE GetGlyphAtlas(IFW1GlyphAtlas **ppGlyphAtlas); 20 | virtual HRESULT STDMETHODCALLTYPE GetDWriteFactory(IDWriteFactory **ppDWriteFactory); 21 | virtual HRESULT STDMETHODCALLTYPE GetDWriteFontCollection(IDWriteFontCollection **ppFontCollection); 22 | 23 | virtual const void* STDMETHODCALLTYPE GetGlyphMapFromFont( 24 | IDWriteFontFace *pFontFace, 25 | FLOAT FontSize, 26 | UINT FontFlags 27 | ); 28 | virtual UINT STDMETHODCALLTYPE GetAtlasIdFromGlyphIndex( 29 | const void* pGlyphMap, 30 | UINT16 GlyphIndex, 31 | IDWriteFontFace *pFontFace, 32 | UINT FontFlags 33 | ); 34 | 35 | // Public functions 36 | public: 37 | CFW1GlyphProvider(); 38 | 39 | HRESULT initGlyphProvider( 40 | IFW1Factory *pFW1Factory, 41 | IFW1GlyphAtlas *pGlyphAtlas, 42 | IDWriteFactory *pDWriteFactory, 43 | IDWriteFontCollection *pFontCollection, 44 | UINT maxGlyphWidth, 45 | UINT maxGlyphHeight 46 | ); 47 | 48 | // Internal types 49 | private: 50 | struct GlyphMap { 51 | FLOAT fontSize; 52 | UINT fontFlags; 53 | 54 | UINT *glyphs; 55 | UINT glyphCount; 56 | }; 57 | 58 | struct FontInfo { 59 | IDWriteFontFace *pFontFace; 60 | std::wstring uniqueName; 61 | }; 62 | 63 | typedef std::pair > FontId; 64 | typedef std::map FontMap; 65 | 66 | FontId makeFontId(UINT fontIndex, UINT fontFlags, FLOAT fontSize) { 67 | UINT relevantFlags = (fontFlags & (FW1_ALIASED)); 68 | return std::make_pair(fontIndex, std::make_pair(relevantFlags, fontSize)); 69 | } 70 | 71 | // Internal functions 72 | private: 73 | virtual ~CFW1GlyphProvider(); 74 | 75 | UINT getFontIndexFromFontFace(IDWriteFontFace *pFontFace); 76 | std::wstring getUniqueNameFromFontFace(IDWriteFontFace *pFontFace); 77 | 78 | UINT insertNewGlyph(GlyphMap *glyphMap, UINT16 glyphIndex, IDWriteFontFace *pFontFace); 79 | 80 | // Internal data 81 | private: 82 | IFW1GlyphAtlas *m_pGlyphAtlas; 83 | 84 | IDWriteFactory *m_pDWriteFactory; 85 | UINT m_maxGlyphWidth; 86 | UINT m_maxGlyphHeight; 87 | std::stack m_glyphRenderTargets; 88 | 89 | IDWriteFontCollection *m_pFontCollection; 90 | std::vector m_fonts; 91 | 92 | FontMap m_fontMap; 93 | 94 | CRITICAL_SECTION m_renderTargetsCriticalSection; 95 | CRITICAL_SECTION m_glyphMapsCriticalSection; 96 | CRITICAL_SECTION m_fontsCriticalSection; 97 | CRITICAL_SECTION m_insertGlyphCriticalSection; 98 | }; 99 | 100 | 101 | }// namespace FW1FontWrapper 102 | 103 | 104 | #endif// IncludeGuard__FW1_CFW1GlyphProvider 105 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1TextGeometryInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1TextGeometryInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1TextGeometry.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1TextGeometry::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1TextGeometry))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Clear geometry 27 | void STDMETHODCALLTYPE CFW1TextGeometry::Clear() { 28 | m_vertices.clear(); 29 | m_maxSheetIndex = 0; 30 | 31 | m_sorted = false; 32 | } 33 | 34 | 35 | // Add a vertex 36 | void STDMETHODCALLTYPE CFW1TextGeometry::AddGlyphVertex(const FW1_GLYPHVERTEX *pVertex) { 37 | m_vertices.push_back(*pVertex); 38 | 39 | UINT sheetIndex = pVertex->GlyphIndex >> 16; 40 | m_maxSheetIndex = std::max(m_maxSheetIndex, sheetIndex); 41 | 42 | m_sorted = false; 43 | } 44 | 45 | 46 | // Get current glyph vertices 47 | FW1_VERTEXDATA STDMETHODCALLTYPE CFW1TextGeometry::GetGlyphVerticesTemp() { 48 | FW1_VERTEXDATA vertexData; 49 | 50 | if(!m_vertices.empty()) { 51 | UINT32 sheetCount = m_maxSheetIndex + 1; 52 | 53 | // Sort and prepare vertices 54 | if(!m_sorted) { 55 | m_sortedVertices.resize(m_vertices.size()); 56 | m_vertexCounts.resize(sheetCount); 57 | m_vertexStartIndices.resize(sheetCount); 58 | 59 | std::fill(m_vertexCounts.begin(), m_vertexCounts.end(), 0); 60 | 61 | UINT * const vertexCounts = &m_vertexCounts[0]; 62 | const FW1_GLYPHVERTEX * const vertices = &m_vertices[0]; 63 | const UINT32 vertexCount = static_cast(m_vertices.size()); 64 | 65 | for(UINT32 i=0; i < vertexCount; ++i) { 66 | UINT32 sheetIndex = vertices[i].GlyphIndex >> 16; 67 | 68 | ++vertexCounts[sheetIndex]; 69 | } 70 | 71 | UINT * const vertexStartIndices = &m_vertexStartIndices[0]; 72 | 73 | UINT currentStartIndex = 0; 74 | for(UINT32 i=0; i < sheetCount; ++i) { 75 | vertexStartIndices[i] = currentStartIndex; 76 | 77 | currentStartIndex += vertexCounts[i]; 78 | } 79 | 80 | FW1_GLYPHVERTEX * const sortedVertices = &m_sortedVertices[0]; 81 | 82 | for(UINT32 i=0; i < vertexCount; ++i) { 83 | const FW1_GLYPHVERTEX &vertex = vertices[i]; 84 | UINT32 sheetIndex = vertex.GlyphIndex >> 16; 85 | 86 | UINT &vertexIndex = vertexStartIndices[sheetIndex]; 87 | 88 | sortedVertices[vertexIndex] = vertex; 89 | sortedVertices[vertexIndex].GlyphIndex &= 0xffff; 90 | 91 | ++vertexIndex; 92 | } 93 | 94 | m_sorted = true; 95 | } 96 | 97 | vertexData.SheetCount = sheetCount; 98 | vertexData.pVertexCounts = &m_vertexCounts[0]; 99 | vertexData.TotalVertexCount = static_cast(m_vertices.size()); 100 | vertexData.pVertices = &m_sortedVertices[0]; 101 | } 102 | else { 103 | vertexData.SheetCount = 0; 104 | vertexData.pVertexCounts = 0; 105 | vertexData.TotalVertexCount = 0; 106 | vertexData.pVertices = 0; 107 | } 108 | 109 | return vertexData; 110 | } 111 | 112 | 113 | }// namespace FW1FontWrapper 114 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1DWriteRenderTargetInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1DWriteRenderTargetInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1DWriteRenderTarget.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1DWriteRenderTarget::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1DWriteRenderTarget))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Draw glyph to temporary storage 27 | HRESULT STDMETHODCALLTYPE CFW1DWriteRenderTarget::DrawGlyphTemp( 28 | IDWriteFontFace *pFontFace, 29 | UINT16 GlyphIndex, 30 | FLOAT FontSize, 31 | DWRITE_RENDERING_MODE RenderingMode, 32 | DWRITE_MEASURING_MODE MeasuringMode, 33 | FW1_GLYPHIMAGEDATA *pOutData 34 | ) { 35 | // Font metrics 36 | DWRITE_FONT_METRICS fontMetrics; 37 | pFontFace->GetMetrics(&fontMetrics); 38 | 39 | // Glyph metrics 40 | DWRITE_GLYPH_METRICS glyphMetrics; 41 | HRESULT hResult = pFontFace->GetDesignGlyphMetrics(&GlyphIndex, 1, &glyphMetrics, FALSE); 42 | if(FAILED(hResult)) 43 | return hResult; 44 | 45 | // Calculate pixel measurements 46 | DWGlyphData dwGlyphData; 47 | initGlyphData(&fontMetrics, &glyphMetrics, FontSize, &dwGlyphData); 48 | 49 | // Set up drawing 50 | FLOAT glyphAdvance = 0.0f; 51 | DWRITE_GLYPH_OFFSET glyphOffset = {0.0f, 0.0f}; 52 | 53 | DWRITE_GLYPH_RUN glyphRun; 54 | ZeroMemory(&glyphRun, sizeof(glyphRun)); 55 | glyphRun.fontFace = pFontFace; 56 | glyphRun.fontEmSize = FontSize; 57 | glyphRun.glyphCount = 1; 58 | glyphRun.glyphIndices = &GlyphIndex; 59 | glyphRun.glyphAdvances = &glyphAdvance; 60 | glyphRun.glyphOffsets = &glyphOffset; 61 | 62 | // Clear background 63 | RECT rect; 64 | SetRect(&rect, 0, 0, 2+dwGlyphData.maxWidth+5, 2+dwGlyphData.maxHeight+5); 65 | int iRet = FillRect(m_hDC, &rect, m_hBlackBrush); 66 | if(iRet == 0) { 67 | } 68 | 69 | // Rendering mode 70 | IDWriteRenderingParams *pRenderingParams; 71 | 72 | RenderingParamsMap::iterator it = m_renderingParams.find(RenderingMode); 73 | if(it != m_renderingParams.end()) 74 | pRenderingParams = it->second; 75 | else 76 | pRenderingParams = m_renderingParams.begin()->second; 77 | 78 | // Draw 79 | hResult = m_pRenderTarget->DrawGlyphRun( 80 | 2.0f - dwGlyphData.offsetX, 81 | 2.0f - dwGlyphData.offsetY, 82 | MeasuringMode, 83 | &glyphRun, 84 | pRenderingParams, 85 | RGB(255, 255, 255), 86 | &rect 87 | ); 88 | if(FAILED(hResult)) 89 | return hResult; 90 | 91 | // Clip to valid render target to avoid buffer overruns in case the glyph was too large 92 | rect.left = std::max(rect.left, 0L); 93 | rect.top = std::max(rect.top, 0L); 94 | rect.right = std::min(static_cast(m_renderTargetWidth), rect.right); 95 | rect.bottom = std::min(static_cast(m_renderTargetHeight), rect.bottom); 96 | 97 | // Return glyph data 98 | pOutData->Metrics.OffsetX = dwGlyphData.offsetX + static_cast(rect.left) - 2.0f; 99 | pOutData->Metrics.OffsetY = dwGlyphData.offsetY + static_cast(rect.top) - 2.0f; 100 | pOutData->Metrics.Width = static_cast(rect.right - rect.left); 101 | pOutData->Metrics.Height = static_cast(rect.bottom - rect.top); 102 | pOutData->pGlyphPixels = 103 | static_cast(m_bmBits) 104 | + rect.top * m_bmWidthBytes 105 | + rect.left * m_bmBytesPixel; 106 | pOutData->RowPitch = m_bmWidthBytes; 107 | pOutData->PixelStride = m_bmBytesPixel; 108 | 109 | return S_OK; 110 | } 111 | 112 | 113 | }// namespace FW1FontWrapper 114 | -------------------------------------------------------------------------------- /LambseaLoader/hde/table64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #define C_NONE 0x00 9 | #define C_MODRM 0x01 10 | #define C_IMM8 0x02 11 | #define C_IMM16 0x04 12 | #define C_IMM_P66 0x10 13 | #define C_REL8 0x20 14 | #define C_REL32 0x40 15 | #define C_GROUP 0x80 16 | #define C_ERROR 0xff 17 | 18 | #define PRE_ANY 0x00 19 | #define PRE_NONE 0x01 20 | #define PRE_F2 0x02 21 | #define PRE_F3 0x04 22 | #define PRE_66 0x08 23 | #define PRE_67 0x10 24 | #define PRE_LOCK 0x20 25 | #define PRE_SEG 0x40 26 | #define PRE_ALL 0xff 27 | 28 | #define DELTA_OPCODES 0x4a 29 | #define DELTA_FPU_REG 0xfd 30 | #define DELTA_FPU_MODRM 0x104 31 | #define DELTA_PREFIXES 0x13c 32 | #define DELTA_OP_LOCK_OK 0x1ae 33 | #define DELTA_OP2_LOCK_OK 0x1c6 34 | #define DELTA_OP_ONLY_MEM 0x1d8 35 | #define DELTA_OP2_ONLY_MEM 0x1e7 36 | 37 | unsigned char hde64_table[] = { 38 | 0xa5,0xaa,0xa5,0xb8,0xa5,0xaa,0xa5,0xaa,0xa5,0xb8,0xa5,0xb8,0xa5,0xb8,0xa5, 39 | 0xb8,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xac,0xc0,0xcc,0xc0,0xa1,0xa1, 40 | 0xa1,0xa1,0xb1,0xa5,0xa5,0xa6,0xc0,0xc0,0xd7,0xda,0xe0,0xc0,0xe4,0xc0,0xea, 41 | 0xea,0xe0,0xe0,0x98,0xc8,0xee,0xf1,0xa5,0xd3,0xa5,0xa5,0xa1,0xea,0x9e,0xc0, 42 | 0xc0,0xc2,0xc0,0xe6,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0xab, 43 | 0x8b,0x90,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x92,0x5b,0x5b,0x76,0x90,0x92,0x92, 44 | 0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x6a,0x73,0x90, 45 | 0x5b,0x52,0x52,0x52,0x52,0x5b,0x5b,0x5b,0x5b,0x77,0x7c,0x77,0x85,0x5b,0x5b, 46 | 0x70,0x5b,0x7a,0xaf,0x76,0x76,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b, 47 | 0x5b,0x5b,0x86,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xd5,0x03,0xcc,0x01,0xbc, 48 | 0x03,0xf0,0x03,0x03,0x04,0x00,0x50,0x50,0x50,0x50,0xff,0x20,0x20,0x20,0x20, 49 | 0x01,0x01,0x01,0x01,0xc4,0x02,0x10,0xff,0xff,0xff,0x01,0x00,0x03,0x11,0xff, 50 | 0x03,0xc4,0xc6,0xc8,0x02,0x10,0x00,0xff,0xcc,0x01,0x01,0x01,0x00,0x00,0x00, 51 | 0x00,0x01,0x01,0x03,0x01,0xff,0xff,0xc0,0xc2,0x10,0x11,0x02,0x03,0x01,0x01, 52 | 0x01,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x10, 53 | 0x10,0x10,0x10,0x02,0x10,0x00,0x00,0xc6,0xc8,0x02,0x02,0x02,0x02,0x06,0x00, 54 | 0x04,0x00,0x02,0xff,0x00,0xc0,0xc2,0x01,0x01,0x03,0x03,0x03,0xca,0x40,0x00, 55 | 0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00,0x00,0x00,0x00, 56 | 0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0xff,0x00, 57 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff, 58 | 0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00, 59 | 0xff,0x40,0x40,0x40,0x40,0x41,0x49,0x40,0x40,0x40,0x40,0x4c,0x42,0x40,0x40, 60 | 0x40,0x40,0x40,0x40,0x40,0x40,0x4f,0x44,0x53,0x40,0x40,0x40,0x44,0x57,0x43, 61 | 0x5c,0x40,0x60,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, 62 | 0x40,0x40,0x64,0x66,0x6e,0x6b,0x40,0x40,0x6a,0x46,0x40,0x40,0x44,0x46,0x40, 63 | 0x40,0x5b,0x44,0x40,0x40,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x01,0x06, 64 | 0x06,0x02,0x06,0x06,0x00,0x06,0x00,0x0a,0x0a,0x00,0x00,0x00,0x02,0x07,0x07, 65 | 0x06,0x02,0x0d,0x06,0x06,0x06,0x0e,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 66 | 0x04,0x04,0x05,0x06,0x06,0x06,0x00,0x00,0x00,0x0e,0x00,0x00,0x08,0x00,0x10, 67 | 0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01,0x86,0x00, 68 | 0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba,0xf8,0xbb, 69 | 0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00,0xc4,0xff, 70 | 0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00,0x13,0x09, 71 | 0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07,0xb2,0xff, 72 | 0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf,0xe7,0x08, 73 | 0x00,0xf0,0x02,0x00 74 | }; 75 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1Factory.h: -------------------------------------------------------------------------------- 1 | // CFW1Factory.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1Factory 4 | #define IncludeGuard__FW1_CFW1Factory 5 | 6 | 7 | namespace FW1FontWrapper { 8 | 9 | 10 | // Factory that creates FW1 objects 11 | class CFW1Factory : public IFW1Factory { 12 | public: 13 | // IUnknown 14 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 15 | virtual ULONG STDMETHODCALLTYPE AddRef(); 16 | virtual ULONG STDMETHODCALLTYPE Release(); 17 | 18 | // IFW1Factory 19 | virtual HRESULT STDMETHODCALLTYPE CreateFontWrapper( 20 | ID3D11Device *pDevice, 21 | LPCWSTR pszFontFamily, 22 | IFW1FontWrapper **ppFontWrapper 23 | ); 24 | virtual HRESULT STDMETHODCALLTYPE CreateFontWrapper( 25 | ID3D11Device *pDevice, 26 | IDWriteFactory *pDWriteFactory, 27 | const FW1_FONTWRAPPERCREATEPARAMS *pCreateParams, 28 | IFW1FontWrapper **ppFontWrapper 29 | ); 30 | virtual HRESULT STDMETHODCALLTYPE CreateFontWrapper( 31 | ID3D11Device *pDevice, 32 | IFW1GlyphAtlas *pGlyphAtlas, 33 | IFW1GlyphProvider *pGlyphProvider, 34 | IFW1GlyphVertexDrawer *pGlyphVertexDrawer, 35 | IFW1GlyphRenderStates *pGlyphRenderStates, 36 | IDWriteFactory *pDWriteFactory, 37 | const FW1_DWRITEFONTPARAMS *pDefaultFontParams, 38 | IFW1FontWrapper **ppFontWrapper 39 | ); 40 | virtual HRESULT STDMETHODCALLTYPE CreateGlyphVertexDrawer( 41 | ID3D11Device *pDevice, 42 | UINT VertexBufferSize, 43 | IFW1GlyphVertexDrawer **ppGlyphVertexDrawer 44 | ); 45 | virtual HRESULT STDMETHODCALLTYPE CreateGlyphRenderStates( 46 | ID3D11Device *pDevice, 47 | BOOL DisableGeometryShader, 48 | BOOL AnisotropicFiltering, 49 | IFW1GlyphRenderStates **ppGlyphRenderStates 50 | ); 51 | virtual HRESULT STDMETHODCALLTYPE CreateTextRenderer( 52 | IFW1GlyphProvider *pGlyphProvider, 53 | IFW1TextRenderer **ppTextRenderer 54 | ); 55 | virtual HRESULT STDMETHODCALLTYPE CreateTextGeometry( 56 | IFW1TextGeometry **ppTextGeometry 57 | ); 58 | virtual HRESULT STDMETHODCALLTYPE CreateGlyphProvider( 59 | IFW1GlyphAtlas *pGlyphAtlas, 60 | IDWriteFactory *pDWriteFactory, 61 | IDWriteFontCollection *pFontCollection, 62 | UINT MaxGlyphWidth, 63 | UINT MaxGlyphHeight, 64 | IFW1GlyphProvider **ppGlyphProvider 65 | ); 66 | virtual HRESULT STDMETHODCALLTYPE CreateDWriteRenderTarget( 67 | IDWriteFactory *pDWriteFactory, 68 | UINT RenderTargetWidth, 69 | UINT RenderTargetHeight, 70 | IFW1DWriteRenderTarget **ppRenderTarget 71 | ); 72 | virtual HRESULT STDMETHODCALLTYPE CreateGlyphAtlas( 73 | ID3D11Device *pDevice, 74 | UINT GlyphSheetWidth, 75 | UINT GlyphSheetHeight, 76 | BOOL HardwareCoordBuffer, 77 | BOOL AllowOversizedGlyph, 78 | UINT MaxGlyphCountPerSheet, 79 | UINT MipLevels, 80 | UINT MaxGlyphSheetCount, 81 | IFW1GlyphAtlas **ppGlyphAtlas 82 | ); 83 | virtual HRESULT STDMETHODCALLTYPE CreateGlyphSheet( 84 | ID3D11Device *pDevice, 85 | UINT GlyphSheetWidth, 86 | UINT GlyphSheetHeight, 87 | BOOL HardwareCoordBuffer, 88 | BOOL AllowOversizedGlyph, 89 | UINT MaxGlyphCount, 90 | UINT MipLevels, 91 | IFW1GlyphSheet **ppGlyphSheet 92 | ); 93 | virtual HRESULT STDMETHODCALLTYPE CreateColor( 94 | UINT32 Color, 95 | IFW1ColorRGBA **ppColor 96 | ); 97 | 98 | // Public functions 99 | public: 100 | CFW1Factory(); 101 | 102 | HRESULT initFactory(); 103 | 104 | // Internal functions 105 | private: 106 | virtual ~CFW1Factory(); 107 | 108 | HRESULT createDWriteFactory(IDWriteFactory **ppDWriteFactory); 109 | 110 | void setErrorString(const wchar_t *str); 111 | 112 | // Internal data 113 | private: 114 | ULONG m_cRefCount; 115 | 116 | std::wstring m_lastError; 117 | CRITICAL_SECTION m_errorStringCriticalSection; 118 | 119 | private: 120 | CFW1Factory(const CFW1Factory&); 121 | CFW1Factory& operator=(const CFW1Factory&); 122 | }; 123 | 124 | 125 | }// namespace FW1FontWrapper 126 | 127 | 128 | #endif// IncludeGuard__FW1_CFW1Factory 129 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1GlyphSheet.h: -------------------------------------------------------------------------------- 1 | // CFW1GlyphSheet.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1GlyphSheet 4 | #define IncludeGuard__FW1_CFW1GlyphSheet 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // A texture containing multiple glyphimages 13 | class CFW1GlyphSheet : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1GlyphSheet 19 | virtual HRESULT STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice); 20 | virtual void STDMETHODCALLTYPE GetDesc(FW1_GLYPHSHEETDESC *pDesc); 21 | 22 | virtual HRESULT STDMETHODCALLTYPE GetSheetTexture(ID3D11ShaderResourceView **ppSheetTextureSRV); 23 | virtual HRESULT STDMETHODCALLTYPE GetCoordBuffer(ID3D11ShaderResourceView **ppCoordBufferSRV); 24 | 25 | virtual const FW1_GLYPHCOORDS* STDMETHODCALLTYPE GetGlyphCoords(); 26 | virtual HRESULT STDMETHODCALLTYPE BindSheet(ID3D11DeviceContext *pContext, UINT Flags); 27 | 28 | virtual UINT STDMETHODCALLTYPE InsertGlyph( 29 | const FW1_GLYPHMETRICS *pGlyphMetrics, 30 | const void *pGlyphData, 31 | UINT RowPitch, 32 | UINT PixelStride 33 | ); 34 | virtual void STDMETHODCALLTYPE CloseSheet(); 35 | virtual void STDMETHODCALLTYPE Flush(ID3D11DeviceContext *pContext); 36 | 37 | // Public functions 38 | public: 39 | CFW1GlyphSheet(); 40 | 41 | HRESULT initGlyphSheet( 42 | IFW1Factory *pFW1Factory, 43 | ID3D11Device *pDevice, 44 | UINT sheetWidth, 45 | UINT sheetHeight, 46 | bool coordBuffer, 47 | bool allowOversizedGlyph, 48 | UINT maxGlyphCount, 49 | UINT mipLevelCount 50 | ); 51 | 52 | // Internal types 53 | private: 54 | struct RectUI { 55 | UINT left; 56 | UINT top; 57 | UINT right; 58 | UINT bottom; 59 | }; 60 | 61 | class HeightRange { 62 | public: 63 | HeightRange(UINT totalWidth); 64 | ~HeightRange(); 65 | 66 | UINT findMin(UINT width, UINT *outMin); 67 | void update(UINT startX, UINT width, UINT newHeight); 68 | 69 | private: 70 | HeightRange(); 71 | HeightRange(const HeightRange&); 72 | HeightRange& operator=(const HeightRange&); 73 | 74 | UINT findMax(UINT startX, UINT width); 75 | 76 | UINT *m_heights; 77 | UINT m_totalWidth; 78 | }; 79 | 80 | class CriticalSectionLock { 81 | public: 82 | CriticalSectionLock(LPCRITICAL_SECTION pCriticalSection) : m_pCriticalSection(pCriticalSection) { 83 | EnterCriticalSection(m_pCriticalSection); 84 | } 85 | ~CriticalSectionLock() { 86 | LeaveCriticalSection(m_pCriticalSection); 87 | } 88 | 89 | private: 90 | CriticalSectionLock(); 91 | CriticalSectionLock(const CriticalSectionLock&); 92 | CriticalSectionLock& operator=(const CriticalSectionLock&); 93 | 94 | LPCRITICAL_SECTION m_pCriticalSection; 95 | }; 96 | 97 | // Internal functions 98 | private: 99 | virtual ~CFW1GlyphSheet(); 100 | 101 | HRESULT createDeviceResources(); 102 | 103 | // Internal data 104 | private: 105 | std::wstring m_lastError; 106 | 107 | UINT m_sheetWidth; 108 | UINT m_sheetHeight; 109 | bool m_hardwareCoordBuffer; 110 | bool m_allowOversizedGlyph; 111 | UINT m_mipLevelCount; 112 | UINT m_alignWidth; 113 | 114 | UINT8 *m_textureData; 115 | FW1_GLYPHCOORDS *m_glyphCoords; 116 | UINT m_maxGlyphCount; 117 | UINT m_glyphCount; 118 | 119 | ID3D11Device *m_pDevice; 120 | 121 | ID3D11Texture2D *m_pTexture; 122 | ID3D11ShaderResourceView *m_pTextureSRV; 123 | ID3D11Buffer *m_pCoordBuffer; 124 | ID3D11ShaderResourceView *m_pCoordBufferSRV; 125 | 126 | bool m_closed; 127 | bool m_static; 128 | 129 | HeightRange *m_heightRange; 130 | 131 | UINT m_updatedGlyphCount; 132 | RectUI m_dirtyRect; 133 | CRITICAL_SECTION m_sheetCriticalSection; 134 | CRITICAL_SECTION m_flushCriticalSection; 135 | }; 136 | 137 | 138 | }// namespace FW1FontWrapper 139 | 140 | 141 | #endif// IncludeGuard__FW1_CFW1GlyphSheet 142 | -------------------------------------------------------------------------------- /IPCServer/HandleGetter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | #include 4 | #include 5 | #include "winternl.h" 6 | 7 | 8 | typedef struct _OBJECT_NAME_INFORMATION 9 | { 10 | UNICODE_STRING Name; 11 | } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION; 12 | 13 | typedef struct _OBJECT_TYPE_INFORMATION 14 | { 15 | UNICODE_STRING TypeName; 16 | ULONG TotalNumberOfObjects; 17 | ULONG TotalNumberOfHandles; 18 | ULONG TotalPagedPoolUsage; 19 | ULONG TotalNonPagedPoolUsage; 20 | ULONG TotalNamePoolUsage; 21 | ULONG TotalHandleTableUsage; 22 | ULONG HighWaterNumberOfObjects; 23 | ULONG HighWaterNumberOfHandles; 24 | ULONG HighWaterPagedPoolUsage; 25 | ULONG HighWaterNonPagedPoolUsage; 26 | ULONG HighWaterNamePoolUsage; 27 | ULONG HighWaterHandleTableUsage; 28 | ULONG InvalidAttributes; 29 | GENERIC_MAPPING GenericMapping; 30 | ULONG ValidAccessMask; 31 | BOOLEAN SecurityRequired; 32 | BOOLEAN MaintainHandleCount; 33 | ULONG PoolType; 34 | ULONG DefaultPagedPoolCharge; 35 | ULONG DefaultNonPagedPoolCharge; 36 | } OBJECT_TYPE_INFORMATION, *POBJECT_TYPE_INFORMATION; 37 | 38 | typedef struct _OBJECT_HANDLE_ATTRIBUTE_INFORMATION 39 | { 40 | BOOLEAN Inherit; 41 | BOOLEAN ProtectFromClose; 42 | } OBJECT_HANDLE_ATTRIBUTE_INFORMATION, *POBJECT_HANDLE_ATTRIBUTE_INFORMATION; 43 | 44 | typedef struct _OBJECT_DIRECTORY_INFORMATION 45 | { 46 | UNICODE_STRING Name; 47 | UNICODE_STRING TypeName; 48 | } OBJECT_DIRECTORY_INFORMATION, *POBJECT_DIRECTORY_INFORMATION; 49 | 50 | typedef struct _OBJECT_HANDLE_FLAG_INFORMATION { 51 | BOOLEAN Inherit; 52 | BOOLEAN ProtectFromClose; 53 | } OBJECT_HANDLE_FLAG_INFORMATION, *POBJECT_HANDLE_FLAG_INFORMATION; 54 | 55 | typedef struct _SYSTEM_OBJECT_INFORMATION // Size=48 56 | { 57 | ULONG NextEntryOffset; // Size=4 Offset=0 58 | PVOID Object; // Size=4 Offset=4 59 | PVOID CreatorUniqueProcess; // Size=4 Offset=8 60 | USHORT CreatorBackTraceIndex; // Size=2 Offset=12 61 | USHORT Flags; // Size=2 Offset=14 62 | LONG PointerCount; // Size=4 Offset=16 63 | LONG HandleCount; // Size=4 Offset=20 64 | ULONG PagedPoolCharge; // Size=4 Offset=24 65 | ULONG NonPagedPoolCharge; // Size=4 Offset=28 66 | PVOID ExclusiveProcessId; // Size=4 Offset=32 67 | PVOID SecurityDescriptor; // Size=4 Offset=36 68 | OBJECT_NAME_INFORMATION NameInfo; // Size=8 Offset=40 69 | } SYSTEM_OBJECT_INFORMATION, *PSYSTEM_OBJECT_INFORMATION; 70 | 71 | typedef struct _SYSTEM_HANDLE_TABLE_ENTRY_INFO 72 | { 73 | USHORT UniqueProcessId; 74 | USHORT CreatorBackTraceIndex; 75 | UCHAR ObjectTypeIndex; 76 | UCHAR HandleAttributes; 77 | USHORT HandleValue; 78 | PVOID Object; 79 | ULONG GrantedAccess; 80 | } SYSTEM_HANDLE_TABLE_ENTRY_INFO, *PSYSTEM_HANDLE_TABLE_ENTRY_INFO; 81 | 82 | typedef struct _SYSTEM_HANDLE 83 | { 84 | DWORD dwProcessId; 85 | BYTE bObjectType; 86 | BYTE bFlags; 87 | WORD wValue; 88 | PVOID pAddress; 89 | DWORD GrantedAccess; 90 | }SYSTEM_HANDLE; 91 | 92 | typedef struct _SYSTEM_HANDLE_INFORMATION 93 | { 94 | ULONG NumberOfHandles; 95 | SYSTEM_HANDLE_TABLE_ENTRY_INFO Handles[1]; 96 | } SYSTEM_HANDLE_INFORMATION, *PSYSTEM_HANDLE_INFORMATION; 97 | 98 | 99 | 100 | //NTSTATUS NTAPI NtQueryObject( 101 | // _In_opt_ HANDLE Handle, 102 | // _In_ OBJECT_INFORMATION_CLASS ObjectInformationClass, 103 | // _Out_opt_ PVOID ObjectInformation, 104 | // _In_ ULONG ObjectInformationLength, 105 | // _Out_opt_ PULONG ReturnLength 106 | //); 107 | // 108 | //NTSTATUS WINAPI NtQuerySystemInformation( 109 | // _In_ SYSTEM_INFORMATION_CLASS SystemInformationClass, 110 | // _Inout_ PVOID SystemInformation, 111 | // _In_ ULONG SystemInformationLength, 112 | // _Out_opt_ PULONG ReturnLength 113 | //); 114 | 115 | #ifndef NT_SUCCESS 116 | #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) 117 | #endif 118 | 119 | typedef std::function ENUM_HANDLE_CALLBACK; 120 | 121 | bool EnablePrivilege( 122 | LPCWSTR lpPrivilegeName 123 | ); 124 | 125 | bool DisablePrivilege( 126 | LPCWSTR lpPrivilegeName 127 | ); 128 | 129 | NTSTATUS EnumerateHandles(ENUM_HANDLE_CALLBACK callback); 130 | HANDLE GetHandleToProcess(LPWSTR process); 131 | void PrintSelfToOthersHandles(); 132 | -------------------------------------------------------------------------------- /lambsea/D3D9Render.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | //d3d9 - related 5 | #include 6 | #include 7 | #include 8 | 9 | #pragma comment(lib,"d3d9.lib") 10 | #pragma comment(lib,"d3dx9.lib") 11 | #pragma comment(lib,"winmm.lib") 12 | #pragma comment(lib,"Dwmapi.lib") 13 | 14 | #define D3D9RENDER 15 | 16 | class D3D9Render 17 | { 18 | public: 19 | D3D9Render(); 20 | ~D3D9Render(); 21 | 22 | void Initialize(); 23 | int GetScreenWidth(); 24 | int GetScreenHeight(); 25 | 26 | void Render(void(*entityloop)(void)); 27 | void SetupWindow(); 28 | 29 | MARGINS GetMargines() { return this->margin; }; 30 | LPD3DXFONT GetFont() { return this->pFont; }; 31 | HWND GetSpawnedWindow() { return this->hSpawnedWindow; }; 32 | 33 | void DrawString(int x, int y, DWORD color, LPD3DXFONT g_pFont, const wchar_t *fmt, ...); 34 | void DrawLine(float x, float y, float xx, float yy, D3DCOLOR color); 35 | void DrawBox(float x, float y, float width, float height, D3DCOLOR color); 36 | void DrawFilledRect(float x, float y, float w, float h, D3DCOLOR color); 37 | void FillRect(float x, float y, float w, float h, D3DCOLOR color); 38 | void DrawHealthBar(float x, float y, float w, float h, float health, float max); 39 | void DrawHealthBar(float x, float y, float w, float health, float max); 40 | 41 | 42 | 43 | 44 | private: 45 | 46 | struct vertex 47 | { 48 | FLOAT x, y, z, rhw; 49 | DWORD color; 50 | }; 51 | 52 | LPDIRECT3DVERTEXBUFFER9 g_pVB = 0; // Buffer to hold vertices 53 | LPDIRECT3DINDEXBUFFER9 g_pIB = 0; // Buffer to hold indices 54 | LPD3DXFONT pFont; 55 | LPDIRECT3D9 d3d; // the pointer to our Direct3D interface 56 | LPDIRECT3DDEVICE9 d3ddev; 57 | MARGINS margin; 58 | ID3DXLine* d3dLine; 59 | 60 | HWND hSpawnedWindow; 61 | }; 62 | 63 | 64 | inline void D3D9Render::DrawString(int x, int y, DWORD color, LPD3DXFONT g_pFont, const wchar_t * fmt, ...) 65 | { 66 | wchar_t buf[1024] = { 0 }; 67 | va_list va_alist; 68 | RECT FontPos = { x, y, x + 150, y + 20 }; 69 | va_start(va_alist, fmt); 70 | vswprintf_s(buf, fmt, va_alist); 71 | va_end(va_alist); 72 | g_pFont->DrawTextW(NULL, buf, -1, &FontPos, DT_NOCLIP, color); 73 | } 74 | 75 | inline void D3D9Render::DrawLine(float x, float y, float xx, float yy, D3DCOLOR color) 76 | { 77 | D3DXVECTOR2 dLine[2]; 78 | 79 | d3dLine->SetWidth(1.f); 80 | 81 | dLine[0].x = x; 82 | dLine[0].y = y; 83 | dLine[1].x = xx; 84 | dLine[1].y = yy; 85 | 86 | d3dLine->Draw(dLine, 2, color); 87 | } 88 | 89 | inline void D3D9Render::DrawBox(float x, float y, float width, float height, D3DCOLOR color) 90 | { 91 | D3DXVECTOR2 points[5]; 92 | points[0] = D3DXVECTOR2(x, y); 93 | points[1] = D3DXVECTOR2(x + width, y); 94 | points[2] = D3DXVECTOR2(x + width, y + height); 95 | points[3] = D3DXVECTOR2(x, y + height); 96 | points[4] = D3DXVECTOR2(x, y); 97 | d3dLine->SetWidth(1); 98 | d3dLine->Draw(points, 5, color); 99 | } 100 | 101 | inline void D3D9Render::DrawFilledRect(float x, float y, float w, float h, D3DCOLOR color) 102 | { 103 | 104 | D3DXVECTOR2 dLine[2]; 105 | 106 | y = y + h / 2; 107 | 108 | d3dLine->SetWidth(h); 109 | 110 | dLine[0].x = x; 111 | dLine[0].y = y; 112 | 113 | dLine[1].x = x + w; 114 | dLine[1].y = y; 115 | 116 | d3dLine->Draw(dLine, 2, color); 117 | 118 | } 119 | 120 | inline void D3D9Render::FillRect(float x, float y, float w, float h, D3DCOLOR color) 121 | { 122 | return DrawFilledRect(x, y, w, h, color); 123 | } 124 | 125 | inline void D3D9Render::DrawHealthBar(float x, float y, float w, float h, float health, float max) 126 | { 127 | if (!max) 128 | return; 129 | 130 | if (w < 5) 131 | return; 132 | 133 | if (health < 0) 134 | health = 0; 135 | 136 | float ratio = health / max; 137 | 138 | D3DCOLOR col = D3DCOLOR_ARGB(255, (int)(255 - 255 * ratio), (int)(255 * ratio), 0); 139 | 140 | float step = (w / max); 141 | float draw = (step * health); 142 | 143 | DrawFilledRect(x, y, w, h, D3DCOLOR_ARGB(255, 0, 0, 0)); 144 | DrawFilledRect(x, y, draw, h, col); 145 | } 146 | 147 | inline void D3D9Render::DrawHealthBar(float x, float y, float w, float health, float max) 148 | { 149 | DrawHealthBar(x, y, w, 4.0f, health, max); 150 | } 151 | 152 | 153 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1GlyphRenderStatesInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1GlyphRenderStatesInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1GlyphRenderStates.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1GlyphRenderStates::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1GlyphRenderStates))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Get the D3D11 device used by the render states 27 | HRESULT STDMETHODCALLTYPE CFW1GlyphRenderStates::GetDevice(ID3D11Device **ppDevice) { 28 | if(ppDevice == NULL) 29 | return E_INVALIDARG; 30 | 31 | m_pDevice->AddRef(); 32 | *ppDevice = m_pDevice; 33 | 34 | return S_OK; 35 | } 36 | 37 | 38 | // Set render states for glyph drawing 39 | void STDMETHODCALLTYPE CFW1GlyphRenderStates::SetStates(ID3D11DeviceContext *pContext, UINT Flags) { 40 | if(m_hasGeometryShader && ((Flags & FW1_NOGEOMETRYSHADER) == 0)) { 41 | // Point vertices with geometry shader 42 | pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); 43 | pContext->IASetInputLayout(m_pPointInputLayout); 44 | pContext->VSSetShader(m_pVertexShaderPoint, NULL, 0); 45 | if((Flags & FW1_CLIPRECT) != 0) 46 | pContext->GSSetShader(m_pGeometryShaderClipPoint, NULL, 0); 47 | else 48 | pContext->GSSetShader(m_pGeometryShaderPoint, NULL, 0); 49 | pContext->PSSetShader(m_pPixelShader, NULL, 0); 50 | pContext->GSSetConstantBuffers(0, 1, &m_pConstantBuffer); 51 | } 52 | else { 53 | // Quads constructed on the CPU 54 | pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 55 | pContext->IASetInputLayout(m_pQuadInputLayout); 56 | if((Flags & FW1_CLIPRECT) != 0) { 57 | pContext->VSSetShader(m_pVertexShaderClipQuad, NULL, 0); 58 | pContext->PSSetShader(m_pPixelShaderClip, NULL, 0); 59 | } 60 | else { 61 | pContext->VSSetShader(m_pVertexShaderQuad, NULL, 0); 62 | pContext->PSSetShader(m_pPixelShader, NULL, 0); 63 | } 64 | pContext->VSSetConstantBuffers(0, 1, &m_pConstantBuffer); 65 | 66 | if(m_featureLevel >= D3D_FEATURE_LEVEL_10_0) 67 | pContext->GSSetShader(NULL, NULL, 0); 68 | } 69 | 70 | if(m_featureLevel >= D3D_FEATURE_LEVEL_11_0) { 71 | pContext->DSSetShader(NULL, NULL, 0); 72 | pContext->HSSetShader(NULL, NULL, 0); 73 | } 74 | 75 | pContext->OMSetBlendState(m_pBlendState, NULL, 0xffffffff); 76 | pContext->OMSetDepthStencilState(m_pDepthStencilState, 0); 77 | 78 | pContext->RSSetState(m_pRasterizerState); 79 | 80 | pContext->PSSetSamplers(0, 1, &m_pSamplerState); 81 | } 82 | 83 | 84 | // Update constant buffer 85 | void STDMETHODCALLTYPE CFW1GlyphRenderStates::UpdateShaderConstants( 86 | ID3D11DeviceContext *pContext, 87 | const FW1_RECTF *pClipRect, 88 | const FLOAT *pTransformMatrix 89 | ) { 90 | // Shader constants 91 | ShaderConstants constants; 92 | ZeroMemory(&constants, sizeof(constants)); 93 | 94 | // Transform matrix 95 | if(pTransformMatrix != NULL) 96 | CopyMemory(constants.TransformMatrix, pTransformMatrix, 16*sizeof(FLOAT)); 97 | else { 98 | // Get viewport size for orthographic transform 99 | FLOAT w = 512.0f; 100 | FLOAT h = 512.0f; 101 | 102 | D3D11_VIEWPORT vp; 103 | UINT nvp = 1; 104 | pContext->RSGetViewports(&nvp, &vp); 105 | if(nvp > 0) { 106 | if(vp.Width >= 1.0f && vp.Height >= 1.0f) { 107 | w = vp.Width; 108 | h = vp.Height; 109 | } 110 | } 111 | 112 | constants.TransformMatrix[0] = 2.0f / w; 113 | constants.TransformMatrix[12] = -1.0f; 114 | constants.TransformMatrix[5] = -2.0f / h; 115 | constants.TransformMatrix[13] = 1.0f; 116 | constants.TransformMatrix[10] = 1.0f; 117 | constants.TransformMatrix[15] = 1.0f; 118 | } 119 | 120 | // Clip rect 121 | if(pClipRect != NULL) { 122 | constants.ClipRect[0] = -pClipRect->Left; 123 | constants.ClipRect[1] = -pClipRect->Top; 124 | constants.ClipRect[2] = pClipRect->Right; 125 | constants.ClipRect[3] = pClipRect->Bottom; 126 | } 127 | else { 128 | constants.ClipRect[0] = FLT_MAX; 129 | constants.ClipRect[1] = FLT_MAX; 130 | constants.ClipRect[2] = FLT_MAX; 131 | constants.ClipRect[3] = FLT_MAX; 132 | } 133 | 134 | // Update constant buffer 135 | D3D11_MAPPED_SUBRESOURCE msr; 136 | HRESULT hResult = pContext->Map(m_pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &msr); 137 | if(SUCCEEDED(hResult)) { 138 | CopyMemory(msr.pData, &constants, sizeof(constants)); 139 | 140 | pContext->Unmap(m_pConstantBuffer, 0); 141 | } 142 | } 143 | 144 | 145 | // Check for geometry shader 146 | BOOL STDMETHODCALLTYPE CFW1GlyphRenderStates::HasGeometryShader() { 147 | return (m_hasGeometryShader ? TRUE : FALSE); 148 | } 149 | 150 | 151 | }// namespace FW1FontWrapper 152 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1GlyphProviderInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1GlyphProviderInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1GlyphProvider.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1GlyphProvider::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1GlyphProvider))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Get glyph atlas 27 | HRESULT STDMETHODCALLTYPE CFW1GlyphProvider::GetGlyphAtlas(IFW1GlyphAtlas **ppGlyphAtlas) { 28 | if(ppGlyphAtlas == NULL) 29 | return E_INVALIDARG; 30 | 31 | m_pGlyphAtlas->AddRef(); 32 | *ppGlyphAtlas = m_pGlyphAtlas; 33 | 34 | return S_OK; 35 | } 36 | 37 | 38 | // Get DWrite factory 39 | HRESULT STDMETHODCALLTYPE CFW1GlyphProvider::GetDWriteFactory(IDWriteFactory **ppDWriteFactory) { 40 | if(ppDWriteFactory == NULL) 41 | return E_INVALIDARG; 42 | 43 | m_pDWriteFactory->AddRef(); 44 | *ppDWriteFactory = m_pDWriteFactory; 45 | 46 | return S_OK; 47 | } 48 | 49 | 50 | // Get DWrite font collection 51 | HRESULT STDMETHODCALLTYPE CFW1GlyphProvider::GetDWriteFontCollection(IDWriteFontCollection **ppFontCollection) { 52 | if(ppFontCollection == NULL) 53 | return E_INVALIDARG; 54 | 55 | m_pFontCollection->AddRef(); 56 | *ppFontCollection = m_pFontCollection; 57 | 58 | return S_OK; 59 | } 60 | 61 | 62 | // Get glyph map 63 | const void* STDMETHODCALLTYPE CFW1GlyphProvider::GetGlyphMapFromFont( 64 | IDWriteFontFace *pFontFace, 65 | FLOAT FontSize, 66 | UINT FontFlags 67 | ) { 68 | // Get font id 69 | UINT fontIndex = getFontIndexFromFontFace(pFontFace); 70 | FontId fontId = makeFontId(fontIndex, FontFlags, FontSize); 71 | 72 | const void *glyphMap = 0; 73 | 74 | // Get the glyph-map 75 | EnterCriticalSection(&m_glyphMapsCriticalSection); 76 | FontMap::iterator it = m_fontMap.find(fontId); 77 | if(it != m_fontMap.end()) 78 | glyphMap = (*it).second; 79 | LeaveCriticalSection(&m_glyphMapsCriticalSection); 80 | 81 | if(glyphMap == 0 && (FontFlags & FW1_NONEWGLYPHS) == 0) { 82 | // Create a new glyph-map 83 | GlyphMap *newGlyphMap = new GlyphMap; 84 | newGlyphMap->fontSize = FontSize; 85 | newGlyphMap->fontFlags = FontFlags; 86 | newGlyphMap->glyphCount = pFontFace->GetGlyphCount(); 87 | newGlyphMap->glyphs = new UINT[newGlyphMap->glyphCount]; 88 | for(UINT i=0; i < newGlyphMap->glyphCount; ++i) 89 | newGlyphMap->glyphs[i] = 0xffffffff; 90 | 91 | bool needless = false; 92 | 93 | // Inert the new glyph-map and map the font-id to its index 94 | EnterCriticalSection(&m_glyphMapsCriticalSection); 95 | 96 | it = m_fontMap.find(fontId); 97 | if(it != m_fontMap.end()) { 98 | glyphMap = (*it).second; 99 | needless = true; 100 | } 101 | else { 102 | m_fontMap.insert(std::make_pair(fontId, newGlyphMap)); 103 | glyphMap = newGlyphMap; 104 | } 105 | 106 | LeaveCriticalSection(&m_glyphMapsCriticalSection); 107 | 108 | if(needless) {// Simultaneous creation on two threads 109 | delete[] newGlyphMap->glyphs; 110 | delete newGlyphMap; 111 | } 112 | else { 113 | UINT glyphAtlasId = insertNewGlyph(newGlyphMap, 0, pFontFace); 114 | glyphAtlasId; 115 | } 116 | } 117 | 118 | return glyphMap; 119 | } 120 | 121 | 122 | // Get atlas id of a glyph 123 | UINT STDMETHODCALLTYPE CFW1GlyphProvider::GetAtlasIdFromGlyphIndex( 124 | const void *pGlyphMap, 125 | UINT16 GlyphIndex, 126 | IDWriteFontFace *pFontFace, 127 | UINT FontFlags 128 | ) { 129 | GlyphMap *glyphMap = static_cast(const_cast(pGlyphMap)); 130 | 131 | if(glyphMap == 0) 132 | return 0; 133 | 134 | if(GlyphIndex >= glyphMap->glyphCount) 135 | return 0; 136 | 137 | // Get the atlas id for this glyph 138 | UINT glyphAtlasId = glyphMap->glyphs[GlyphIndex]; 139 | if(glyphAtlasId == 0xffffffff && (FontFlags & FW1_NONEWGLYPHS) == 0) 140 | glyphAtlasId = insertNewGlyph(glyphMap, GlyphIndex, pFontFace); 141 | 142 | // Fall back to the font default-glyph or the atlas default-glyph on failure 143 | if(glyphAtlasId == 0xffffffff) { 144 | glyphAtlasId = glyphMap->glyphs[0]; 145 | 146 | if((FontFlags & FW1_NONEWGLYPHS) == 0) { 147 | if(glyphAtlasId == 0xffffffff) { 148 | if(GlyphIndex == 0) 149 | glyphAtlasId = 0; 150 | else 151 | glyphAtlasId = GetAtlasIdFromGlyphIndex(pGlyphMap, 0, pFontFace, FontFlags); 152 | } 153 | 154 | EnterCriticalSection(&m_insertGlyphCriticalSection); 155 | if(glyphMap->glyphs[GlyphIndex] == 0xffffffff) 156 | glyphMap->glyphs[GlyphIndex] = glyphAtlasId; 157 | LeaveCriticalSection(&m_insertGlyphCriticalSection); 158 | } 159 | 160 | if(glyphAtlasId == 0xffffffff) 161 | glyphAtlasId = 0; 162 | } 163 | 164 | return glyphAtlasId; 165 | } 166 | 167 | 168 | }// namespace FW1FontWrapper 169 | -------------------------------------------------------------------------------- /BEFucker/Hooks.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | #include 4 | 5 | // DEFINITIONS 6 | typedef NTSTATUS(__stdcall *fNtCreateFile) 7 | (OUT PHANDLE FileHandle, 8 | IN ACCESS_MASK DesiredAccess, 9 | IN POBJECT_ATTRIBUTES ObjectAttributes, 10 | OUT PIO_STATUS_BLOCK IoStatusBlock, 11 | IN PLARGE_INTEGER AllocationSize OPTIONAL, 12 | IN ULONG FileAttributes, 13 | IN ULONG ShareAccess, 14 | IN ULONG CreateDisposition, 15 | IN ULONG CreateOptions, 16 | IN PVOID EaBuffer OPTIONAL, 17 | IN ULONG EaLength 18 | ); 19 | 20 | typedef BOOL(__stdcall *fCryptCATAdminCalcHashFromFileHandle) 21 | ( 22 | _In_ HANDLE hFile, 23 | _Inout_ DWORD *pcbHash, 24 | _In_ BYTE *pbHash, 25 | _In_ DWORD dwFlags 26 | ); 27 | 28 | typedef NTSTATUS(NTAPI *fNtReadVirtualMemory)( 29 | IN HANDLE ProcessHandle, 30 | IN PVOID BaseAddress, 31 | OUT PVOID Buffer, 32 | IN ULONG BufferLength, 33 | OUT PULONG ReturnLength OPTIONAL 34 | ); 35 | 36 | typedef enum _MEMORY_INFORMATION_CLASS { 37 | MemoryBasicInformation, // MEMORY_BASIC_INFORMATION 38 | MemoryWorkingSetInformation, // MEMORY_WORKING_SET_INFORMATION 39 | MemoryMappedFilenameInformation, // UNICODE_STRING 40 | MemoryRegionInformation, // MEMORY_REGION_INFORMATION 41 | MemoryWorkingSetExInformation, // MEMORY_WORKING_SET_EX_INFORMATION 42 | MemorySharedCommitInformation // MEMORY_SHARED_COMMIT_INFORMATION 43 | } MEMORY_INFORMATION_CLASS; 44 | 45 | 46 | 47 | typedef NTSTATUS(NTAPI *fNtQueryVirtualMemory) 48 | ( 49 | IN HANDLE ProcessHandle, 50 | IN PVOID BaseAddress, 51 | IN MEMORY_INFORMATION_CLASS MemoryInformationClass, 52 | OUT PVOID Buffer, 53 | IN ULONG Length, 54 | OUT PULONG ResultLength OPTIONAL 55 | ); 56 | 57 | typedef struct _DEBUG_BUFFER { 58 | HANDLE SectionHandle; 59 | PVOID SectionBase; 60 | PVOID RemoteSectionBase; 61 | ULONG SectionBaseDelta; 62 | HANDLE EventPairHandle; 63 | ULONG Unknown[2]; 64 | HANDLE RemoteThreadHandle; 65 | ULONG InfoClassMask; 66 | ULONG SizeOfInfo; 67 | ULONG AllocatedSize; 68 | ULONG SectionSize; 69 | PVOID ModuleInformation; 70 | PVOID BackTraceInformation; 71 | PVOID HeapInformation; 72 | PVOID LockInformation; 73 | PVOID Reserved[8]; 74 | } DEBUG_BUFFER, *PDEBUG_BUFFER; 75 | 76 | typedef NTSTATUS(NTAPI *fNtQuerySystemInformation)( 77 | ULONG SystemInformationClass, 78 | PVOID SystemInformation, 79 | ULONG SystemInformationLength, 80 | PULONG ReturnLength 81 | ); 82 | 83 | typedef VOID(__stdcall *_RtlInitUnicodeString) 84 | ( 85 | PUNICODE_STRING DestinationString, 86 | PCWSTR SourceString 87 | ); 88 | 89 | 90 | typedef DWORD(WINAPI *fGetDeviceDriverFileName)( 91 | _In_ LPVOID ImageBase, 92 | _Out_ LPTSTR lpFilename, 93 | _In_ DWORD nSize 94 | ); 95 | 96 | typedef BOOL (WINAPI *fK32EnumDeviceDrivers)( 97 | _Out_ LPVOID *lpImageBase, 98 | _In_ DWORD cb, 99 | _Out_ LPDWORD lpcbNeeded 100 | ); 101 | 102 | typedef PCCERT_CONTEXT (WINAPI *fCertEnumCertificatesInStore)( 103 | _In_ HCERTSTORE hCertStore, 104 | _In_ PCCERT_CONTEXT pPrevCertContext 105 | ); 106 | 107 | typedef BOOL (WINAPI *fEnumWindows) 108 | ( 109 | _In_ WNDENUMPROC lpEnumFunc, 110 | _In_ LPARAM lParam 111 | ); 112 | 113 | 114 | namespace Fuckers //Hooks 115 | { 116 | //ORIGINAL FUNCTIONS 117 | 118 | //fuck be's file check 119 | extern fNtCreateFile NtCreateFileOrig; 120 | extern fCryptCATAdminCalcHashFromFileHandle CryptCATAdminCalcHashFromFileHandleOrig; 121 | 122 | extern fNtQueryVirtualMemory NtQueryVirtualMemoryOrig; 123 | extern fNtReadVirtualMemory NtReadVirtualMemoryOrig; 124 | extern fNtQuerySystemInformation NtQuerySystemInformationOrig; 125 | 126 | extern fK32EnumDeviceDrivers K32EnumDeviceDriversOrig; 127 | extern fCertEnumCertificatesInStore CertEnumCertificatesInStoreOrig; 128 | 129 | extern fEnumWindows EnumWindowsOrig; 130 | 131 | //HOOK FUNCTIONS 132 | NTSTATUS NTAPI NtCreateFileHook(PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, void* IoStatusBlock, PLARGE_INTEGER AllocationSize, ULONG FileAttributes, ULONG ShareAccess, ULONG CreateDisposition, ULONG CreateOptions, PVOID EaBuffer, ULONG EaLength); 133 | BOOL WINAPI CryptCATAdminCalcHashFromFileHandleHook(HANDLE hFile, DWORD * pcbHash, BYTE * pbHash, DWORD dwFlags); 134 | 135 | NTSTATUS NTAPI NtReadVirtualMemoryHook(HANDLE ProcessHandle,PVOID BaseAddress,PVOID Buffer,ULONG BufferLength,PULONG ReturnLength OPTIONAL); 136 | NTSTATUS NTAPI NtQueryVirtualMemoryHook(HANDLE ProcessHandle,PVOID BaseAddress, MEMORY_INFORMATION_CLASS MemoryInformationClass,PVOID Buffer,ULONG Length,PULONG ResultLength OPTIONAL); 137 | NTSTATUS NTAPI NtQuerySystemInformationHook(ULONG SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength); 138 | 139 | BOOL WINAPI K32EnumDeviceDriversHook( 140 | LPVOID *lpImageBase, 141 | DWORD cb, 142 | LPDWORD lpcbNeeded 143 | ); 144 | 145 | PCCERT_CONTEXT WINAPI CertEnumCertificatesInStoreHook( 146 | HCERTSTORE hCertStore, 147 | PCCERT_CONTEXT pPrevCertContext 148 | ); 149 | 150 | 151 | BOOL WINAPI EnumWindowsHook( 152 | WNDENUMPROC lpEnumFunc, 153 | LPARAM lParam 154 | ); 155 | 156 | 157 | } -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1FontWrapper.h: -------------------------------------------------------------------------------- 1 | // CFW1FontWrapper.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1FontWrapper 4 | #define IncludeGuard__FW1_CFW1FontWrapper 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Font-wrapper simplifying drawing strings and text-layouts 13 | class CFW1FontWrapper : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1FontWrapper 19 | virtual HRESULT STDMETHODCALLTYPE GetFactory(IFW1Factory **ppFactory); 20 | 21 | virtual HRESULT STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice); 22 | virtual HRESULT STDMETHODCALLTYPE GetDWriteFactory(IDWriteFactory **ppDWriteFactory); 23 | virtual HRESULT STDMETHODCALLTYPE GetGlyphAtlas(IFW1GlyphAtlas **ppGlyphAtlas); 24 | virtual HRESULT STDMETHODCALLTYPE GetGlyphProvider(IFW1GlyphProvider **ppGlyphProvider); 25 | virtual HRESULT STDMETHODCALLTYPE GetRenderStates(IFW1GlyphRenderStates **ppRenderStates); 26 | virtual HRESULT STDMETHODCALLTYPE GetVertexDrawer(IFW1GlyphVertexDrawer **ppVertexDrawer); 27 | 28 | virtual void STDMETHODCALLTYPE DrawTextLayout( 29 | ID3D11DeviceContext *pContext, 30 | IDWriteTextLayout *pTextLayout, 31 | FLOAT OriginX, 32 | FLOAT OriginY, 33 | UINT32 Color, 34 | UINT Flags 35 | ); 36 | virtual void STDMETHODCALLTYPE DrawTextLayout( 37 | ID3D11DeviceContext *pContext, 38 | IDWriteTextLayout *pTextLayout, 39 | FLOAT OriginX, 40 | FLOAT OriginY, 41 | UINT32 Color, 42 | const FW1_RECTF *pClipRect, 43 | const FLOAT *pTransformMatrix, 44 | UINT Flags 45 | ); 46 | 47 | virtual void STDMETHODCALLTYPE DrawString( 48 | ID3D11DeviceContext *pContext, 49 | const WCHAR *pszString, 50 | FLOAT FontSize, 51 | FLOAT X, 52 | FLOAT Y, 53 | UINT32 Color, 54 | UINT Flags 55 | ); 56 | virtual void STDMETHODCALLTYPE DrawString( 57 | ID3D11DeviceContext *pContext, 58 | const WCHAR *pszString, 59 | const WCHAR *pszFontFamily, 60 | FLOAT FontSize, 61 | FLOAT X, 62 | FLOAT Y, 63 | UINT32 Color, 64 | UINT Flags 65 | ); 66 | virtual void STDMETHODCALLTYPE DrawString( 67 | ID3D11DeviceContext *pContext, 68 | const WCHAR *pszString, 69 | const WCHAR *pszFontFamily, 70 | FLOAT FontSize, 71 | const FW1_RECTF *pLayoutRect, 72 | UINT32 Color, 73 | const FW1_RECTF *pClipRect, 74 | const FLOAT *pTransformMatrix, 75 | UINT Flags 76 | ); 77 | 78 | virtual FW1_RECTF STDMETHODCALLTYPE MeasureString( 79 | const WCHAR *pszString, 80 | const WCHAR *pszFontFamily, 81 | FLOAT FontSize, 82 | const FW1_RECTF *pLayoutRect, 83 | UINT Flags 84 | ); 85 | 86 | virtual void STDMETHODCALLTYPE AnalyzeString( 87 | ID3D11DeviceContext *pContext, 88 | const WCHAR *pszString, 89 | const WCHAR *pszFontFamily, 90 | FLOAT FontSize, 91 | const FW1_RECTF *pLayoutRect, 92 | UINT32 Color, 93 | UINT Flags, 94 | IFW1TextGeometry *pTextGeometry 95 | ); 96 | 97 | virtual void STDMETHODCALLTYPE AnalyzeTextLayout( 98 | ID3D11DeviceContext *pContext, 99 | IDWriteTextLayout *pTextLayout, 100 | FLOAT OriginX, 101 | FLOAT OriginY, 102 | UINT32 Color, 103 | UINT Flags, 104 | IFW1TextGeometry *pTextGeometry 105 | ); 106 | 107 | virtual void STDMETHODCALLTYPE DrawGeometry( 108 | ID3D11DeviceContext *pContext, 109 | IFW1TextGeometry *pGeometry, 110 | const FW1_RECTF *pClipRect, 111 | const FLOAT *pTransformMatrix, 112 | UINT Flags 113 | ); 114 | 115 | virtual void STDMETHODCALLTYPE Flush(ID3D11DeviceContext *pContext); 116 | 117 | // Public functions 118 | public: 119 | CFW1FontWrapper(); 120 | 121 | HRESULT initFontWrapper( 122 | IFW1Factory *pFW1Factory, 123 | ID3D11Device *pDevice, 124 | IFW1GlyphAtlas *pGlyphAtlas, 125 | IFW1GlyphProvider *pGlyphProvider, 126 | IFW1GlyphVertexDrawer *pGlyphVertexDrawer, 127 | IFW1GlyphRenderStates *pGlyphRenderStates, 128 | IDWriteFactory *pDWriteFactory, 129 | const FW1_DWRITEFONTPARAMS *pDefaultFontParams 130 | ); 131 | 132 | // Internal functions 133 | private: 134 | virtual ~CFW1FontWrapper(); 135 | 136 | IDWriteTextLayout* createTextLayout( 137 | const WCHAR *pszString, 138 | const WCHAR *pszFontFamily, 139 | FLOAT fontSize, 140 | const FW1_RECTF *pLayoutRect, 141 | UINT flags 142 | ); 143 | 144 | // Internal data 145 | private: 146 | std::wstring m_lastError; 147 | 148 | ID3D11Device *m_pDevice; 149 | D3D_FEATURE_LEVEL m_featureLevel; 150 | IDWriteFactory *m_pDWriteFactory; 151 | 152 | IFW1GlyphAtlas *m_pGlyphAtlas; 153 | IFW1GlyphProvider *m_pGlyphProvider; 154 | 155 | IFW1GlyphRenderStates *m_pGlyphRenderStates; 156 | IFW1GlyphVertexDrawer *m_pGlyphVertexDrawer; 157 | 158 | CRITICAL_SECTION m_textRenderersCriticalSection; 159 | std::stack m_textRenderers; 160 | CRITICAL_SECTION m_textGeometriesCriticalSection; 161 | std::stack m_textGeometries; 162 | 163 | bool m_defaultTextInited; 164 | IDWriteTextFormat *m_pDefaultTextFormat; 165 | }; 166 | 167 | 168 | }// namespace FW1FontWrapper 169 | 170 | 171 | #endif// IncludeGuard__FW1_CFW1FontWrapper 172 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1GlyphAtlasInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1GlyphAtlasInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1GlyphAtlas.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1GlyphAtlas::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1GlyphAtlas))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Get the D3D11 device used by this atlas 27 | HRESULT STDMETHODCALLTYPE CFW1GlyphAtlas::GetDevice(ID3D11Device **ppDevice) { 28 | if(ppDevice == NULL) 29 | return E_INVALIDARG; 30 | 31 | m_pDevice->AddRef(); 32 | *ppDevice = m_pDevice; 33 | 34 | return S_OK; 35 | } 36 | 37 | 38 | // Get total glyph count in atlas 39 | UINT STDMETHODCALLTYPE CFW1GlyphAtlas::GetTotalGlyphCount() { 40 | UINT total = 0; 41 | 42 | for(UINT i=0; i < m_sheetCount; ++i) { 43 | FW1_GLYPHSHEETDESC desc; 44 | m_glyphSheets[i]->GetDesc(&desc); 45 | 46 | total += desc.GlyphCount; 47 | } 48 | 49 | return total; 50 | } 51 | 52 | 53 | // Get sheet count 54 | UINT STDMETHODCALLTYPE CFW1GlyphAtlas::GetSheetCount() { 55 | return m_sheetCount; 56 | } 57 | 58 | 59 | // Get sheet 60 | HRESULT STDMETHODCALLTYPE CFW1GlyphAtlas::GetSheet(UINT SheetIndex, IFW1GlyphSheet **ppGlyphSheet) { 61 | if(ppGlyphSheet == NULL) 62 | return E_INVALIDARG; 63 | 64 | if(SheetIndex < m_sheetCount) { 65 | *ppGlyphSheet = m_glyphSheets[SheetIndex]; 66 | 67 | return S_OK; 68 | } 69 | 70 | *ppGlyphSheet = NULL; 71 | 72 | return E_INVALIDARG; 73 | } 74 | 75 | // Get texture coordinates 76 | const FW1_GLYPHCOORDS* STDMETHODCALLTYPE CFW1GlyphAtlas::GetGlyphCoords(UINT SheetIndex) { 77 | if(SheetIndex < m_sheetCount) 78 | return m_glyphSheets[SheetIndex]->GetGlyphCoords(); 79 | 80 | return 0; 81 | } 82 | 83 | 84 | // Set sheet shader resources 85 | HRESULT STDMETHODCALLTYPE CFW1GlyphAtlas::BindSheet(ID3D11DeviceContext *pContext, UINT SheetIndex, UINT Flags) { 86 | if(SheetIndex < m_sheetCount) 87 | return m_glyphSheets[SheetIndex]->BindSheet(pContext, Flags); 88 | 89 | return E_INVALIDARG; 90 | } 91 | 92 | 93 | // Insert texture into atlas 94 | UINT STDMETHODCALLTYPE CFW1GlyphAtlas::InsertGlyph( 95 | const FW1_GLYPHMETRICS *pGlyphMetrics, 96 | const void *pGlyphData, 97 | UINT RowPitch, 98 | UINT PixelStride 99 | ) { 100 | UINT glyphIndex = 0xffffffff; 101 | UINT sheetIndex = 0; 102 | 103 | // Get open sheet range 104 | EnterCriticalSection(&m_glyphSheetsCriticalSection); 105 | UINT start = m_currentSheetIndex; 106 | UINT end = m_sheetCount; 107 | LeaveCriticalSection(&m_glyphSheetsCriticalSection); 108 | 109 | // Attempt to insert glyph 110 | for(UINT i=start; i < end; ++i) { 111 | IFW1GlyphSheet *pGlyphSheet = m_glyphSheets[i]; 112 | 113 | glyphIndex = pGlyphSheet->InsertGlyph(pGlyphMetrics, pGlyphData, RowPitch, PixelStride); 114 | if(glyphIndex != 0xffffffff) { 115 | sheetIndex = i; 116 | break; 117 | } 118 | } 119 | 120 | // Try to create a new glyph sheet on failure 121 | if(glyphIndex == 0xffffffff && m_sheetCount < m_maxSheetCount) { 122 | IFW1GlyphSheet *pGlyphSheet; 123 | if(SUCCEEDED(createGlyphSheet(&pGlyphSheet))) { 124 | glyphIndex = pGlyphSheet->InsertGlyph(pGlyphMetrics, pGlyphData, RowPitch, PixelStride); 125 | 126 | UINT newSheetIndex = InsertSheet(pGlyphSheet); 127 | if(newSheetIndex != 0xffffffff) 128 | sheetIndex = newSheetIndex; 129 | else 130 | glyphIndex = 0xffffffff; 131 | 132 | pGlyphSheet->Release(); 133 | } 134 | } 135 | 136 | if(glyphIndex == 0xffffffff) 137 | return 0xffffffff; 138 | 139 | return (sheetIndex << 16) | glyphIndex; 140 | } 141 | 142 | 143 | // Insert glyph sheets 144 | UINT STDMETHODCALLTYPE CFW1GlyphAtlas::InsertSheet(IFW1GlyphSheet *pGlyphSheet) { 145 | if(pGlyphSheet == NULL) 146 | return 0xffffffff; 147 | 148 | UINT sheetIndex = 0xffffffff; 149 | 150 | EnterCriticalSection(&m_glyphSheetsCriticalSection); 151 | if(m_sheetCount < m_maxSheetCount) { 152 | pGlyphSheet->AddRef(); 153 | 154 | sheetIndex = m_sheetCount; 155 | 156 | m_glyphSheets[sheetIndex] = pGlyphSheet; 157 | 158 | _WriteBarrier(); 159 | MemoryBarrier(); 160 | 161 | ++m_sheetCount; 162 | 163 | // Restrict the number of open sheets 164 | UINT numActiveSheets = 4; 165 | 166 | if(m_sheetCount > m_currentSheetIndex + numActiveSheets) { 167 | m_glyphSheets[m_currentSheetIndex]->CloseSheet(); 168 | 169 | ++m_currentSheetIndex; 170 | } 171 | } 172 | LeaveCriticalSection(&m_glyphSheetsCriticalSection); 173 | 174 | return sheetIndex; 175 | } 176 | 177 | 178 | // Flush all sheets with possible new glyphs 179 | void STDMETHODCALLTYPE CFW1GlyphAtlas::Flush(ID3D11DeviceContext *pContext) { 180 | UINT first = 0; 181 | UINT end = 0; 182 | 183 | EnterCriticalSection(&m_glyphSheetsCriticalSection); 184 | 185 | first = m_flushedSheetIndex; 186 | end = m_sheetCount; 187 | 188 | m_flushedSheetIndex = m_currentSheetIndex; 189 | 190 | LeaveCriticalSection(&m_glyphSheetsCriticalSection); 191 | 192 | for(UINT i=first; i < end; ++i) 193 | m_glyphSheets[i]->Flush(pContext); 194 | } 195 | 196 | 197 | }// namespace FW1FontWrapper 198 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1FontWrapper.cpp: -------------------------------------------------------------------------------- 1 | // CFW1FontWrapper.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1FontWrapper.h" 6 | 7 | #define SAFE_RELEASE(pObject) { if(pObject) { (pObject)->Release(); (pObject) = NULL; } } 8 | 9 | 10 | namespace FW1FontWrapper { 11 | 12 | 13 | // Construct 14 | CFW1FontWrapper::CFW1FontWrapper() : 15 | m_pDevice(NULL), 16 | m_featureLevel(D3D_FEATURE_LEVEL_9_1), 17 | m_pDWriteFactory(NULL), 18 | 19 | m_pGlyphAtlas(NULL), 20 | m_pGlyphProvider(NULL), 21 | 22 | m_pGlyphRenderStates(NULL), 23 | m_pGlyphVertexDrawer(NULL), 24 | 25 | m_defaultTextInited(false), 26 | m_pDefaultTextFormat(NULL) 27 | { 28 | InitializeCriticalSection(&m_textRenderersCriticalSection); 29 | InitializeCriticalSection(&m_textGeometriesCriticalSection); 30 | } 31 | 32 | 33 | // Destruct 34 | CFW1FontWrapper::~CFW1FontWrapper() { 35 | SAFE_RELEASE(m_pFW1Factory); 36 | 37 | SAFE_RELEASE(m_pDevice); 38 | SAFE_RELEASE(m_pDWriteFactory); 39 | 40 | SAFE_RELEASE(m_pGlyphAtlas); 41 | SAFE_RELEASE(m_pGlyphProvider); 42 | 43 | SAFE_RELEASE(m_pGlyphRenderStates); 44 | SAFE_RELEASE(m_pGlyphVertexDrawer); 45 | 46 | while(!m_textRenderers.empty()) { 47 | m_textRenderers.top()->Release(); 48 | m_textRenderers.pop(); 49 | } 50 | 51 | while(!m_textGeometries.empty()) { 52 | m_textGeometries.top()->Release(); 53 | m_textGeometries.pop(); 54 | } 55 | 56 | SAFE_RELEASE(m_pDefaultTextFormat); 57 | 58 | DeleteCriticalSection(&m_textRenderersCriticalSection); 59 | DeleteCriticalSection(&m_textGeometriesCriticalSection); 60 | } 61 | 62 | 63 | // Init 64 | HRESULT CFW1FontWrapper::initFontWrapper( 65 | IFW1Factory *pFW1Factory, 66 | ID3D11Device *pDevice, 67 | IFW1GlyphAtlas *pGlyphAtlas, 68 | IFW1GlyphProvider *pGlyphProvider, 69 | IFW1GlyphVertexDrawer *pGlyphVertexDrawer, 70 | IFW1GlyphRenderStates *pGlyphRenderStates, 71 | IDWriteFactory *pDWriteFactory, 72 | const FW1_DWRITEFONTPARAMS *pDefaultFontParams 73 | ) { 74 | HRESULT hResult = initBaseObject(pFW1Factory); 75 | if(FAILED(hResult)) 76 | return hResult; 77 | 78 | if( 79 | pDevice == NULL || 80 | pGlyphAtlas == NULL || 81 | pGlyphProvider == NULL || 82 | pGlyphVertexDrawer == NULL || 83 | pGlyphRenderStates == NULL || 84 | pDWriteFactory == NULL 85 | ) 86 | return E_INVALIDARG; 87 | 88 | pDevice->AddRef(); 89 | m_pDevice = pDevice; 90 | m_featureLevel = m_pDevice->GetFeatureLevel(); 91 | 92 | pDWriteFactory->AddRef(); 93 | m_pDWriteFactory = pDWriteFactory; 94 | 95 | pGlyphAtlas->AddRef(); 96 | m_pGlyphAtlas = pGlyphAtlas; 97 | pGlyphProvider->AddRef(); 98 | m_pGlyphProvider = pGlyphProvider; 99 | 100 | pGlyphRenderStates->AddRef(); 101 | m_pGlyphRenderStates = pGlyphRenderStates; 102 | pGlyphVertexDrawer->AddRef(); 103 | m_pGlyphVertexDrawer = pGlyphVertexDrawer; 104 | 105 | // Create default text format for strings, if provided 106 | if(pDefaultFontParams->pszFontFamily != NULL && pDefaultFontParams->pszFontFamily[0] != 0) { 107 | IDWriteTextFormat *pTextFormat; 108 | hResult = m_pDWriteFactory->CreateTextFormat( 109 | pDefaultFontParams->pszFontFamily, 110 | NULL, 111 | pDefaultFontParams->FontWeight, 112 | pDefaultFontParams->FontStyle, 113 | pDefaultFontParams->FontStretch, 114 | 32.0f, 115 | (pDefaultFontParams->pszLocale != NULL) ? pDefaultFontParams->pszLocale : L"", 116 | &pTextFormat 117 | ); 118 | if(FAILED(hResult)) { 119 | m_lastError = L"Failed to create DWrite text format"; 120 | } 121 | else { 122 | m_pDefaultTextFormat = pTextFormat; 123 | m_defaultTextInited = true; 124 | 125 | hResult = S_OK; 126 | } 127 | } 128 | 129 | return hResult; 130 | } 131 | 132 | 133 | // Create text layout from string 134 | IDWriteTextLayout* CFW1FontWrapper::createTextLayout( 135 | const WCHAR *pszString, 136 | const WCHAR *pszFontFamily, 137 | FLOAT fontSize, 138 | const FW1_RECTF *pLayoutRect, 139 | UINT flags 140 | ) { 141 | if(m_defaultTextInited) { 142 | UINT32 stringLength = 0; 143 | while(pszString[stringLength] != 0) 144 | ++stringLength; 145 | 146 | // Create DWrite text layout for the string 147 | IDWriteTextLayout *pTextLayout; 148 | HRESULT hResult = m_pDWriteFactory->CreateTextLayout( 149 | pszString, 150 | stringLength, 151 | m_pDefaultTextFormat, 152 | pLayoutRect->Right - pLayoutRect->Left, 153 | pLayoutRect->Bottom - pLayoutRect->Top, 154 | &pTextLayout 155 | ); 156 | if(SUCCEEDED(hResult)) { 157 | // Layout settings 158 | DWRITE_TEXT_RANGE allText = {0, stringLength}; 159 | pTextLayout->SetFontSize(fontSize, allText); 160 | 161 | if(pszFontFamily != NULL) 162 | pTextLayout->SetFontFamilyName(pszFontFamily, allText); 163 | 164 | if((flags & FW1_NOWORDWRAP) != 0) 165 | pTextLayout->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); 166 | 167 | if(flags & FW1_RIGHT) 168 | pTextLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING); 169 | else if(flags & FW1_CENTER) 170 | pTextLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER); 171 | if(flags & FW1_BOTTOM) 172 | pTextLayout->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_FAR); 173 | else if(flags & FW1_VCENTER) 174 | pTextLayout->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER); 175 | 176 | return pTextLayout; 177 | } 178 | } 179 | 180 | return NULL; 181 | } 182 | 183 | 184 | }// namespace FW1FontWrapper 185 | -------------------------------------------------------------------------------- /IPCServer/IPCServer.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IPCServer.h" 3 | #include "HandleGetter.h" 4 | #define Gamename L"TslGame.exe" 5 | 6 | ServerGateway::ServerGateway() 7 | { 8 | this->PipeName = PIPENAME; 9 | //printf("[ok] Wait Client\n"); 10 | 11 | while (TRUE) { 12 | 13 | this->hNamedPipe = CreateNamedPipe(PipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, MAXPIPEFILESIZE, MAXPIPEFILESIZE, 0, NULL); 14 | // Wait for the client to connect; if it succeeds, the function returns a nonzero value. If the function returns zero, GetLastError returns ERROR_PIPE_CONNECTED. 15 | auto m_clientConnected = ConnectNamedPipe(hNamedPipe, NULL) ? 16 | TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); 17 | 18 | if (hNamedPipe == INVALID_HANDLE_VALUE) { 19 | //printf("ERROR ]> CreateNamedPipe failed. GetLastError: %d\n" ,GetLastError()); 20 | return; 21 | } 22 | 23 | if (m_clientConnected) { 24 | //printf("[ok] Client Connected\n"); 25 | Init(); 26 | } 27 | else { 28 | CloseHandle(hNamedPipe); // The client could not connect, so close the pipe. 29 | } 30 | 31 | } 32 | 33 | } 34 | 35 | ServerGateway::~ServerGateway() 36 | { 37 | } 38 | 39 | void ServerGateway::Init() 40 | { 41 | HANDLE hHeap = GetProcessHeap(); 42 | void* rquestBuffer = HeapAlloc(hHeap, 0, MAXPIPEFILESIZE); 43 | BOOL bSuccess; 44 | DWORD cbBytesRead = 0; 45 | 46 | hGame = GetHandleToProcess(Gamename); 47 | 48 | while (TRUE) { 49 | 50 | bSuccess = ReadFile(hNamedPipe, rquestBuffer, MAXPIPEFILESIZE, &cbBytesRead, NULL); 51 | 52 | if (!bSuccess || cbBytesRead == 0) { 53 | if (GetLastError() == ERROR_BROKEN_PIPE) { 54 | //printf("INFO ]> Broken pipe (Client disconnected). GetLastError: %d\n", GetLastError()); 55 | } 56 | else { 57 | //printf("ERROR ]> ReadFile failed. GetLastError: %d\n", GetLastError()); 58 | } 59 | break; 60 | } 61 | 62 | IPCPacket incomingPacket; 63 | memcpy(&incomingPacket, rquestBuffer, sizeof(IPCPacket)); 64 | 65 | switch (incomingPacket.Order) { 66 | 67 | case IPCPing: 68 | //printf("ping\n"); 69 | 70 | break; 71 | case IPCGetBaseOrder: 72 | //printf("IPCGetBaseOrder\n"); 73 | AnswerGetBaseaddress(); 74 | break; 75 | case IPCReadOrder: 76 | //printf("IPCReadOrder\n"); 77 | //printf("address 0x%I64X\n", incomingPacket.Address); 78 | AnswerReadProcessMemory(incomingPacket); 79 | break; 80 | case IPCWriteOrder: 81 | //printf("IPCWriteOrder\n"); 82 | //printf("address 0x%I64X\n", incomingPacket.Address); 83 | AnswerWriteProcessMemory(incomingPacket); 84 | break; 85 | 86 | } 87 | 88 | } 89 | 90 | // Flush the pipe to allow the client to read the pipe's contents before disconnecting. 91 | // Then disconnect the pipe, and close the handle to this pipe instance. 92 | FlushFileBuffers(hNamedPipe); 93 | DisconnectNamedPipe(hNamedPipe); 94 | CloseHandle(hNamedPipe); 95 | HeapFree(hHeap, 0, rquestBuffer); 96 | //printf("[ok] Gateway closing.\n"); 97 | } 98 | 99 | BOOL ServerGateway::AnswerGetBaseaddress() 100 | { 101 | DWORD_PTR lpBase = 0x0; 102 | int triedTime = 0; 103 | 104 | while (TRUE) 105 | { 106 | HMODULE hMods[512]; 107 | DWORD cb; 108 | if (EnumProcessModulesEx(hGame, hMods, sizeof(hMods), &cb, LIST_MODULES_ALL)) 109 | { 110 | wchar_t szModName[MAX_PATH] = { NULL }; 111 | for (int i = 0; i < cb / sizeof(HMODULE); i++) 112 | { 113 | if (GetModuleBaseName(hGame, hMods[i], szModName, MAX_PATH)) 114 | { 115 | if (!std::wcscmp(szModName, Gamename)) 116 | { 117 | lpBase = (DWORD_PTR)hMods[i]; 118 | break; 119 | } 120 | } 121 | else 122 | { 123 | break; 124 | } 125 | ZeroMemory(szModName, MAX_PATH); 126 | } 127 | } 128 | else 129 | { 130 | //printf("EnumProcessModulesEx failed\n"); 131 | triedTime++; 132 | Sleep(500); 133 | if (triedTime >= 4) 134 | { 135 | lpBase = 0x0; 136 | break; 137 | } 138 | } 139 | if (lpBase != 0) 140 | break; 141 | } 142 | 143 | IPCPacket out; 144 | out.Address = lpBase; 145 | out.size = sizeof(lpBase); 146 | //printf("Readed 0x%I64X\n", out.Address); 147 | DWORD bytesWrittenInPipe = 0; 148 | auto fSuccess = WriteFile(hNamedPipe, &out, sizeof(out), &bytesWrittenInPipe, NULL); 149 | return fSuccess; 150 | 151 | 152 | } 153 | 154 | BOOL ServerGateway::AnswerReadProcessMemory(IPCPacket incomingPacket) 155 | { 156 | DWORD_PTR address = incomingPacket.Address; 157 | DWORD_PTR size = incomingPacket.size; 158 | 159 | __try 160 | { 161 | auto ret = ReadProcessMemory(hGame, (LPCVOID)address, &incomingPacket.data, size, NULL); 162 | if (!ret) 163 | incomingPacket.size = 0; 164 | } 165 | __except (EXCEPTION_EXECUTE_HANDLER) 166 | { 167 | incomingPacket.size = 0; 168 | } 169 | 170 | DWORD bytesWrittenInPipe = 0; 171 | auto fSuccess = WriteFile(hNamedPipe, &incomingPacket, sizeof(incomingPacket), &bytesWrittenInPipe, NULL); 172 | return fSuccess; 173 | 174 | } 175 | 176 | BOOL ServerGateway::AnswerWriteProcessMemory(IPCPacket incomingPacket) 177 | { 178 | DWORD_PTR address = incomingPacket.Address; 179 | DWORD_PTR size = incomingPacket.size; 180 | 181 | __try 182 | { 183 | auto ret = WriteProcessMemory(hGame, (LPVOID)address, &incomingPacket.data, size, NULL); 184 | if (!ret) 185 | incomingPacket.size = 0; 186 | } 187 | __except (EXCEPTION_EXECUTE_HANDLER) 188 | { 189 | incomingPacket.size = 0; 190 | } 191 | 192 | DWORD bytesWrittenInPipe = 0; 193 | auto fSuccess = WriteFile(hNamedPipe, &incomingPacket, sizeof(incomingPacket), &bytesWrittenInPipe, NULL); 194 | return fSuccess; 195 | } 196 | -------------------------------------------------------------------------------- /lambsea/Injection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | #define ReCa reinterpret_cast 5 | 6 | typedef NTSTATUS(__stdcall * f_NtCreateThreadEx)(HANDLE * pHandle, ACCESS_MASK DesiredAccess, void * pAttr, HANDLE hProc, void * pFunc, void * pArg, 7 | ULONG Flags, SIZE_T ZeroBits, SIZE_T StackSize, SIZE_T MaxStackSize, void * pAttrListOut); 8 | 9 | struct UNICODE_STRING 10 | { 11 | WORD Length; 12 | WORD MaxLength; 13 | wchar_t * szBuffer; 14 | }; 15 | 16 | struct LDR_DATA_TABLE_ENTRY 17 | { 18 | LIST_ENTRY InLoadOrder; 19 | LIST_ENTRY InMemoryOrder; 20 | LIST_ENTRY InInitOrder; 21 | void * DllBase; 22 | void * EntryPoint; 23 | ULONG SizeOfImage; 24 | UNICODE_STRING FullDllName; 25 | UNICODE_STRING BaseDllName; 26 | }; 27 | typedef NTSTATUS(__stdcall * f_LdrLoadDll)(wchar_t * szOptPath, ULONG ulFlags, UNICODE_STRING * pModuleFileName, HANDLE * pOut); 28 | struct LDR_LOAD_DLL_DATA 29 | { 30 | f_LdrLoadDll pLdrLoadDll; 31 | HANDLE Out; 32 | UNICODE_STRING pModuleFileName; 33 | BYTE Data[MAX_PATH * 2]; 34 | }; 35 | 36 | bool SetPrivilegeA(const char * szPrivilege, bool bState = true) 37 | { 38 | HANDLE hToken = nullptr; 39 | if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) 40 | { 41 | return false; 42 | } 43 | 44 | TOKEN_PRIVILEGES TokenPrivileges = { 0 }; 45 | TokenPrivileges.PrivilegeCount = 1; 46 | TokenPrivileges.Privileges[0].Attributes = bState ? SE_PRIVILEGE_ENABLED : 0; 47 | 48 | if (!LookupPrivilegeValueA(nullptr, szPrivilege, &TokenPrivileges.Privileges[0].Luid)) 49 | { 50 | CloseHandle(hToken); 51 | return false; 52 | } 53 | 54 | if (!AdjustTokenPrivileges(hToken, FALSE, &TokenPrivileges, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr)) 55 | { 56 | CloseHandle(hToken); 57 | return false; 58 | } 59 | 60 | CloseHandle(hToken); 61 | 62 | return true; 63 | } 64 | 65 | bool FileExistsA(const char * szFile) 66 | { 67 | return (GetFileAttributesA(szFile) != INVALID_FILE_ATTRIBUTES); 68 | } 69 | 70 | void __stdcall LdrLoadDllShell(LDR_LOAD_DLL_DATA * pData) 71 | { 72 | if (!pData) 73 | return; 74 | 75 | pData->pModuleFileName.szBuffer = ReCa(pData->Data); 76 | pData->pLdrLoadDll(nullptr, 0, &pData->pModuleFileName, &pData->Out); 77 | } 78 | 79 | UINT __forceinline _strlenA(const char * szString) 80 | { 81 | UINT Ret = 0; 82 | for (; *szString++; Ret++); 83 | return Ret; 84 | } 85 | 86 | HANDLE StartRoutine(HANDLE hTargetProc, void * pRoutine, void * pArg) 87 | { 88 | auto _NtCTE = reinterpret_cast(GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtCreateThreadEx")); 89 | if (!_NtCTE) 90 | { 91 | HANDLE hThread = CreateRemoteThreadEx(hTargetProc, nullptr, 0, ReCa(pRoutine), pArg, 0, nullptr, nullptr); 92 | if (!hThread) 93 | return INVALID_HANDLE_VALUE; 94 | 95 | return hThread; 96 | } 97 | 98 | HANDLE hThread = nullptr; 99 | _NtCTE(&hThread, THREAD_ALL_ACCESS, nullptr, hTargetProc, pRoutine, pArg, 0, 0, 0, 0, nullptr); 100 | 101 | if (!hThread) 102 | return INVALID_HANDLE_VALUE; 103 | 104 | return hThread; 105 | } 106 | 107 | DWORD LdrLoadDllStub(const char * szDllFile, HANDLE hProc) 108 | { 109 | if (!hProc) 110 | return GetLastError(); 111 | if (!szDllFile || !FileExistsA(szDllFile)) 112 | return -1; 113 | 114 | LDR_LOAD_DLL_DATA data{ 0 }; 115 | data.pModuleFileName.szBuffer = ReCa(data.Data); 116 | data.pModuleFileName.MaxLength = MAX_PATH * 2; 117 | 118 | size_t len = _strlenA(szDllFile); 119 | mbstowcs_s(&len, data.pModuleFileName.szBuffer, len + 1, szDllFile, len); 120 | data.pModuleFileName.Length = (WORD)(len * 2) - 2; 121 | 122 | HINSTANCE hNTDLL = GetModuleHandleA("ntdll.dll"); 123 | if (!hNTDLL) 124 | { 125 | return GetLastError(); 126 | } 127 | 128 | FARPROC pFunc = GetProcAddress(hNTDLL, "LdrLoadDll"); 129 | if (!pFunc) 130 | { 131 | return GetLastError(); 132 | } 133 | 134 | data.pLdrLoadDll = ReCa(pFunc); 135 | 136 | BYTE * pArg = ReCa(VirtualAllocEx(hProc, nullptr, sizeof(LDR_LOAD_DLL_DATA) + 0x200, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE)); 137 | 138 | if (!pArg) 139 | { 140 | return GetLastError(); 141 | } 142 | 143 | if (!WriteProcessMemory(hProc, pArg, &data, sizeof(LDR_LOAD_DLL_DATA), nullptr)) 144 | { 145 | VirtualFreeEx(hProc, pArg, 0, MEM_RELEASE); 146 | return GetLastError(); 147 | } 148 | 149 | if (!WriteProcessMemory(hProc, pArg + sizeof(LDR_LOAD_DLL_DATA), LdrLoadDllShell, 0x100, nullptr)) 150 | { 151 | VirtualFreeEx(hProc, pArg, 0, MEM_RELEASE); 152 | return GetLastError(); 153 | } 154 | 155 | HANDLE hThread = StartRoutine(hProc, pArg + sizeof(LDR_LOAD_DLL_DATA), pArg); 156 | 157 | if (!hThread) 158 | { 159 | VirtualFreeEx(hProc, pArg, 0, MEM_RELEASE); 160 | return GetLastError(); 161 | } 162 | else 163 | { 164 | WaitForSingleObject(hThread, INFINITE); 165 | CloseHandle(hThread); 166 | } 167 | 168 | VirtualFreeEx(hProc, pArg, 0, MEM_RELEASE); 169 | 170 | return 0; 171 | } 172 | 173 | bool InjectBE(const char* file, int PID) { 174 | 175 | if (!SetPrivilegeA("SeDebugPrivilege", true)) 176 | { 177 | wprintf_s(L"Enable SeDebugPrivilege Failed, Er Code %d",(int)GetLastError()); 178 | return FALSE; 179 | } 180 | 181 | HANDLE hProc = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION, FALSE, PID); 182 | if (!hProc) 183 | { 184 | wprintf_s(L"OpenProcess Failed, Er Code %d", (int)GetLastError()); 185 | return FALSE; 186 | } 187 | 188 | char buffer[MAX_PATH] = { 0 }; 189 | GetFullPathNameA(file, MAX_PATH, buffer, NULL); 190 | auto ret = LdrLoadDllStub(buffer, hProc); 191 | CloseHandle(hProc); 192 | 193 | if (ret == 0) 194 | return TRUE; 195 | else 196 | return FALSE; 197 | 198 | } -------------------------------------------------------------------------------- /BEFucker/Main.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "stdafx.h" 4 | #include "Main.h" 5 | #include "Helpers.h" 6 | #include "Hooks.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | void Huorong::Initialise() 17 | { 18 | Helpers::LogToFile("============================="); 19 | Helpers::LogToFile("Shit Is Initializing."); 20 | 21 | //get function pointers 22 | Fuckers::NtCreateFileOrig = reinterpret_cast(GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtCreateFile")); 23 | Fuckers::CryptCATAdminCalcHashFromFileHandleOrig = reinterpret_cast(GetProcAddress(GetModuleHandleA("Wintrust.dll"), "CryptCATAdminCalcHashFromFileHandle")); 24 | Fuckers::NtQueryVirtualMemoryOrig = reinterpret_cast(GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtQueryVirtualMemory")); 25 | Fuckers::NtReadVirtualMemoryOrig = reinterpret_cast(GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtReadVirtualMemory")); 26 | Fuckers::NtQuerySystemInformationOrig = reinterpret_cast(GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtQuerySystemInformation")); 27 | //Fuckers::K32GetDeviceDriverFileNameOrig = reinterpret_cast(GetProcAddress(GetModuleHandleA("Kernel32.dll"), "K32GetDeviceDriverFileName")); 28 | //Fuckers::K32EnumDeviceDriversOrig = reinterpret_cast(GetProcAddress(GetModuleHandleA("Kernel32.dll"), "K32EnumDeviceDrivers")); 29 | //Fuckers::CertEnumCertificatesInStoreOrig = reinterpret_cast(GetProcAddress(GetModuleHandleA("Crypt32.dll"), "CertEnumCertificatesInStore")); 30 | Fuckers::EnumWindowsOrig = reinterpret_cast(GetProcAddress(GetModuleHandleA("User32.dll"), "EnumWindows")); 31 | 32 | //LETSHOOK 33 | Helpers::HookFunction(reinterpret_cast(&Fuckers::NtCreateFileOrig), Fuckers::NtCreateFileHook); 34 | Helpers::HookFunction(reinterpret_cast(&Fuckers::CryptCATAdminCalcHashFromFileHandleOrig), Fuckers::CryptCATAdminCalcHashFromFileHandleHook); 35 | Helpers::HookFunction(reinterpret_cast(&Fuckers::NtReadVirtualMemoryOrig), Fuckers::NtReadVirtualMemoryHook); 36 | Helpers::HookFunction(reinterpret_cast(&Fuckers::NtQueryVirtualMemoryOrig), Fuckers::NtQueryVirtualMemoryHook); 37 | Helpers::HookFunction(reinterpret_cast(&Fuckers::NtQuerySystemInformationOrig), Fuckers::NtQuerySystemInformationHook); 38 | //Helpers::HookFunction(reinterpret_cast(&Fuckers::K32GetDeviceDriverFileNameOrig), Fuckers::K32GetDeviceDriverFileNameHook); 39 | //Helpers::HookFunction(reinterpret_cast(&Fuckers::K32EnumDeviceDriversOrig), Fuckers::K32EnumDeviceDriversHook); 40 | //Helpers::HookFunction(reinterpret_cast(&Fuckers::CertEnumCertificatesInStoreOrig), Fuckers::CertEnumCertificatesInStoreHook); 41 | Helpers::HookFunction(reinterpret_cast(&Fuckers::EnumWindowsOrig), Fuckers::EnumWindowsHook); 42 | 43 | 44 | 45 | //try hook again end 46 | Helpers::LogToFile("Original Address:"); 47 | Helpers::LogAddressToFile("NtCreateFileOrig ", (DWORD_PTR)&Fuckers::NtCreateFileOrig); 48 | Helpers::LogAddressToFile("CryptCATAdminCalcHashFromFileHandleOrig ", (DWORD_PTR)&Fuckers::CryptCATAdminCalcHashFromFileHandleOrig); 49 | Helpers::LogAddressToFile("NtQueryVirtualMemoryOrig ", (DWORD_PTR)&Fuckers::NtQueryVirtualMemoryOrig); 50 | Helpers::LogAddressToFile("NtReadVirtualMemoryOrig ", (DWORD_PTR)&Fuckers::NtReadVirtualMemoryOrig); 51 | Helpers::LogAddressToFile("NtQuerySystemInformationOrig ", (DWORD_PTR)&Fuckers::NtQuerySystemInformationOrig); 52 | Helpers::LogAddressToFile("EnumWindowsOrig ", (DWORD_PTR)&Fuckers::EnumWindowsOrig); 53 | 54 | Helpers::LogToFile("Hook Address:"); 55 | Helpers::LogAddressToFile("NtCreateFileHook ", (DWORD_PTR)Fuckers::NtCreateFileHook); 56 | Helpers::LogAddressToFile("CryptCATAdminCalcHashFromFileHandleHook ", (DWORD_PTR)Fuckers::CryptCATAdminCalcHashFromFileHandleHook); 57 | Helpers::LogAddressToFile("NtQueryVirtualMemoryHook ", (DWORD_PTR)Fuckers::NtQueryVirtualMemoryHook); 58 | Helpers::LogAddressToFile("NtReadVirtualMemoryHook ", (DWORD_PTR)Fuckers::NtReadVirtualMemoryHook); 59 | Helpers::LogAddressToFile("NtQuerySystemInformationHook ", (DWORD_PTR)&Fuckers::NtQuerySystemInformationHook); 60 | Helpers::LogAddressToFile("EnumWindowsHook ", (DWORD_PTR)&Fuckers::EnumWindowsHook); 61 | 62 | Helpers::LogToFile("Shit Is Live."); 63 | Helpers::LogToFile("============================="); 64 | 65 | 66 | } 67 | 68 | void Huorong::Release() 69 | { 70 | 71 | //UNHOOK 72 | Helpers::UnhookFunction(reinterpret_cast(&Fuckers::NtCreateFileOrig), Fuckers::NtCreateFileHook); 73 | Helpers::UnhookFunction(reinterpret_cast(&Fuckers::CryptCATAdminCalcHashFromFileHandleOrig), Fuckers::CryptCATAdminCalcHashFromFileHandleHook); 74 | Helpers::UnhookFunction(reinterpret_cast(&Fuckers::NtQueryVirtualMemoryOrig), Fuckers::NtQueryVirtualMemoryHook); 75 | Helpers::UnhookFunction(reinterpret_cast(&Fuckers::NtReadVirtualMemoryOrig), Fuckers::NtReadVirtualMemoryHook); 76 | Helpers::UnhookFunction(reinterpret_cast(&Fuckers::NtQuerySystemInformationOrig), Fuckers::NtQuerySystemInformationHook); 77 | //Helpers::UnhookFunction(reinterpret_cast(&Fuckers::K32GetDeviceDriverFileNameOrig), Fuckers::K32GetDeviceDriverFileNameHook); 78 | //Helpers::UnhookFunction(reinterpret_cast(&Fuckers::K32EnumDeviceDriversOrig), Fuckers::K32EnumDeviceDriversHook); 79 | Helpers::UnhookFunction(reinterpret_cast(&Fuckers::EnumWindowsOrig), Fuckers::EnumWindowsHook); 80 | 81 | Helpers::LogToFile("============================="); 82 | Helpers::LogToFile("Shit Release Done"); 83 | Helpers::LogToFile("============================="); 84 | 85 | } 86 | 87 | 88 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1TextRenderer.h: -------------------------------------------------------------------------------- 1 | // CFW1TextRenderer.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1TextRenderer 4 | #define IncludeGuard__FW1_CFW1TextRenderer 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Converts a DWrite text layout to vertices 13 | class CFW1TextRenderer : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1DWriteTextRenderer 19 | virtual HRESULT STDMETHODCALLTYPE GetGlyphProvider(IFW1GlyphProvider **ppGlyphProvider); 20 | 21 | virtual HRESULT STDMETHODCALLTYPE DrawTextLayout( 22 | IDWriteTextLayout *pTextLayout, 23 | FLOAT OriginX, 24 | FLOAT OriginY, 25 | UINT32 Color, 26 | UINT Flags, 27 | IFW1TextGeometry *pTextGeometry 28 | ); 29 | 30 | // Public functions 31 | public: 32 | CFW1TextRenderer(); 33 | 34 | HRESULT initTextRenderer( 35 | IFW1Factory *pFW1Factory, 36 | IFW1GlyphProvider *pGlyphProvider 37 | ); 38 | 39 | // Internal functions 40 | private: 41 | virtual ~CFW1TextRenderer(); 42 | 43 | // IDWritePixelSnapping interface (called via proxy) 44 | HRESULT IsPixelSnappingDisabled(void *clientDrawingContext, BOOL *isDisabled); 45 | HRESULT GetCurrentTransform(void *clientDrawingContext, DWRITE_MATRIX *transform); 46 | HRESULT GetPixelsPerDip(void *clientDrawingContext, FLOAT *pixelsPerDip); 47 | 48 | // IDWriteTextRenderer interface (called via proxy) 49 | HRESULT DrawGlyphRun( 50 | void *clientDrawingContext, 51 | FLOAT baselineOriginX, 52 | FLOAT baselineOriginY, 53 | DWRITE_MEASURING_MODE measuringMode, 54 | const DWRITE_GLYPH_RUN *glyphRun, 55 | const DWRITE_GLYPH_RUN_DESCRIPTION *glyphRunDescription, 56 | IUnknown *clientDrawingEffect 57 | ); 58 | HRESULT DrawUnderline( 59 | void *clientDrawingContext, 60 | FLOAT baselineOriginX, 61 | FLOAT baselineOriginY, 62 | const DWRITE_UNDERLINE *underline, 63 | IUnknown *clientDrawingEffect 64 | ); 65 | HRESULT DrawStrikethrough( 66 | void *clientDrawingContext, 67 | FLOAT baselineOriginX, 68 | FLOAT baselineOriginY, 69 | const DWRITE_STRIKETHROUGH *strikethrough, 70 | IUnknown *clientDrawingEffect 71 | ); 72 | HRESULT DrawInlineObject( 73 | void *clientDrawingContext, 74 | FLOAT originX, 75 | FLOAT originY, 76 | IDWriteInlineObject *inlineObject, 77 | BOOL isSideways, 78 | BOOL isRightToLeft, 79 | IUnknown *clientDrawingEffect 80 | ); 81 | 82 | // Internal data 83 | private: 84 | IFW1GlyphProvider *m_pGlyphProvider; 85 | 86 | UINT m_currentFlags; 87 | UINT32 m_currentColor; 88 | 89 | const void *m_cachedGlyphMap; 90 | IDWriteFontFace *m_pCachedGlyphMapFontFace; 91 | FLOAT m_cachedGlyphMapFontSize; 92 | 93 | 94 | // Proxy for IDWriteTextRenderer interface 95 | private: 96 | class CDWriteTextRendererProxy : public IDWriteTextRenderer { 97 | public: 98 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) { 99 | return m_realObject->QueryInterface(riid, ppvObject); 100 | } 101 | virtual ULONG STDMETHODCALLTYPE AddRef() { 102 | return m_realObject->AddRef(); 103 | } 104 | virtual ULONG STDMETHODCALLTYPE Release() { 105 | return m_realObject->Release(); 106 | } 107 | 108 | virtual HRESULT STDMETHODCALLTYPE IsPixelSnappingDisabled(void *clientDrawingContext, BOOL *isDisabled) { 109 | return m_realObject->IsPixelSnappingDisabled(clientDrawingContext, isDisabled); 110 | } 111 | virtual HRESULT STDMETHODCALLTYPE GetCurrentTransform(void *clientDrawingContext, DWRITE_MATRIX *transform) { 112 | return m_realObject->GetCurrentTransform(clientDrawingContext, transform); 113 | } 114 | virtual HRESULT STDMETHODCALLTYPE GetPixelsPerDip(void *clientDrawingContext, FLOAT *pixelsPerDip) { 115 | return m_realObject->GetPixelsPerDip(clientDrawingContext, pixelsPerDip); 116 | } 117 | 118 | virtual HRESULT STDMETHODCALLTYPE DrawGlyphRun(void *clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, DWRITE_MEASURING_MODE measuringMode, const DWRITE_GLYPH_RUN *glyphRun, const DWRITE_GLYPH_RUN_DESCRIPTION *glyphRunDescription, IUnknown *clientDrawingEffect) { 119 | return m_realObject->DrawGlyphRun(clientDrawingContext, baselineOriginX, baselineOriginY, measuringMode, glyphRun, glyphRunDescription, clientDrawingEffect); 120 | } 121 | virtual HRESULT STDMETHODCALLTYPE DrawUnderline(void *clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, const DWRITE_UNDERLINE *underline, IUnknown *clientDrawingEffect) { 122 | return m_realObject->DrawUnderline(clientDrawingContext, baselineOriginX, baselineOriginY, underline, clientDrawingEffect); 123 | } 124 | virtual HRESULT STDMETHODCALLTYPE DrawStrikethrough(void *clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, const DWRITE_STRIKETHROUGH *strikethrough, IUnknown *clientDrawingEffect) { 125 | return m_realObject->DrawStrikethrough(clientDrawingContext, baselineOriginX, baselineOriginY, strikethrough, clientDrawingEffect); 126 | } 127 | virtual HRESULT STDMETHODCALLTYPE DrawInlineObject(void *clientDrawingContext, FLOAT originX, FLOAT originY, IDWriteInlineObject *inlineObject, BOOL isSideways, BOOL isRightToLeft, IUnknown *clientDrawingEffect) { 128 | return m_realObject->DrawInlineObject(clientDrawingContext, originX, originY, inlineObject, isSideways, isRightToLeft, clientDrawingEffect); 129 | } 130 | 131 | public: 132 | CDWriteTextRendererProxy(CFW1TextRenderer *realObject) : m_realObject(realObject) {} 133 | 134 | private: 135 | CDWriteTextRendererProxy(const CDWriteTextRendererProxy&); 136 | CDWriteTextRendererProxy& operator=(const CDWriteTextRendererProxy&); 137 | 138 | private: 139 | CFW1TextRenderer *m_realObject; 140 | } *m_pDWriteTextRendererProxy; 141 | }; 142 | 143 | 144 | }// namespace FW1FontWrapper 145 | 146 | 147 | #endif// IncludeGuard__FW1_CFW1TextRenderer 148 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1DWriteRenderTarget.cpp: -------------------------------------------------------------------------------- 1 | // CFW1DWriteRenderTarget.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1DWriteRenderTarget.h" 6 | 7 | #define SAFE_RELEASE(pObject) { if(pObject) { (pObject)->Release(); (pObject) = NULL; } } 8 | 9 | 10 | namespace FW1FontWrapper { 11 | 12 | 13 | // Construct 14 | CFW1DWriteRenderTarget::CFW1DWriteRenderTarget() : 15 | m_pRenderTarget(NULL), 16 | m_hDC(NULL), 17 | m_hBlackBrush(NULL), 18 | m_bmWidthBytes(0), 19 | m_bmBytesPixel(0), 20 | m_renderTargetWidth(0), 21 | m_renderTargetHeight(0) 22 | { 23 | } 24 | 25 | 26 | // Destruct 27 | CFW1DWriteRenderTarget::~CFW1DWriteRenderTarget() { 28 | if(m_hBlackBrush != NULL) 29 | DeleteObject(m_hBlackBrush); 30 | 31 | SAFE_RELEASE(m_pRenderTarget); 32 | 33 | for(RenderingParamsMap::iterator it = m_renderingParams.begin(); it != m_renderingParams.end(); ++it) 34 | it->second->Release(); 35 | } 36 | 37 | 38 | // Init 39 | HRESULT CFW1DWriteRenderTarget::initRenderTarget( 40 | IFW1Factory *pFW1Factory, 41 | IDWriteFactory *pDWriteFactory, 42 | UINT renderTargetWidth, 43 | UINT renderTargetHeight 44 | ) { 45 | HRESULT hResult = initBaseObject(pFW1Factory); 46 | if(FAILED(hResult)) 47 | return hResult; 48 | 49 | if(pDWriteFactory == NULL) 50 | return E_INVALIDARG; 51 | 52 | m_renderTargetWidth = 384; 53 | if(renderTargetWidth > 0) 54 | m_renderTargetWidth = renderTargetWidth; 55 | 56 | m_renderTargetHeight = 384; 57 | if(renderTargetHeight > 0) 58 | m_renderTargetHeight = renderTargetHeight; 59 | 60 | // Create render target 61 | hResult = createRenderTarget(pDWriteFactory); 62 | 63 | if(SUCCEEDED(hResult)) 64 | hResult = S_OK; 65 | 66 | return hResult; 67 | } 68 | 69 | 70 | // Create render target 71 | HRESULT CFW1DWriteRenderTarget::createRenderTarget(IDWriteFactory *pDWriteFactory) { 72 | IDWriteGdiInterop *pGDIInterop; 73 | HRESULT hResult = pDWriteFactory->GetGdiInterop(&pGDIInterop); 74 | if(FAILED(hResult)) { 75 | m_lastError = L"Failed to get GDI interop"; 76 | } 77 | else { 78 | IDWriteBitmapRenderTarget *pRenderTarget; 79 | hResult = pGDIInterop->CreateBitmapRenderTarget( 80 | NULL, 81 | m_renderTargetWidth, 82 | m_renderTargetHeight, 83 | &pRenderTarget 84 | ); 85 | if(FAILED(hResult)) { 86 | m_lastError = L"Failed to create bitmap render target"; 87 | } 88 | else { 89 | hResult = pRenderTarget->SetPixelsPerDip(1.0f); 90 | hResult = S_OK; 91 | 92 | HDC hDC = pRenderTarget->GetMemoryDC(); 93 | if(hDC == NULL) { 94 | m_lastError = L"Failed to get render target DC"; 95 | hResult = E_FAIL; 96 | } 97 | else { 98 | HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0)); 99 | if(hBrush == NULL) { 100 | m_lastError = L"Failed to create brush"; 101 | hResult = E_FAIL; 102 | } 103 | else { 104 | HBITMAP hBitmap = static_cast(GetCurrentObject(hDC, OBJ_BITMAP)); 105 | if(hBitmap == NULL) { 106 | m_lastError = L"GetCurrentObject failed"; 107 | hResult = E_FAIL; 108 | } 109 | else { 110 | DIBSECTION dib; 111 | int iResult = GetObject(hBitmap, sizeof(dib), &dib); 112 | if(iResult < sizeof(dib)) { 113 | m_lastError = L"GetObject failed"; 114 | hResult = E_FAIL; 115 | } 116 | else { 117 | // Store render target resources and info 118 | m_pRenderTarget = pRenderTarget; 119 | 120 | m_hDC = hDC; 121 | m_hBlackBrush = hBrush; 122 | 123 | m_bmBits = dib.dsBm.bmBits; 124 | m_bmWidthBytes = static_cast(dib.dsBm.bmWidthBytes); 125 | m_bmBytesPixel = static_cast(dib.dsBm.bmBitsPixel) / 8; 126 | 127 | hResult = S_OK; 128 | } 129 | } 130 | 131 | if(FAILED(hResult)) 132 | DeleteObject(hBrush); 133 | } 134 | } 135 | 136 | if(FAILED(hResult)) 137 | pRenderTarget->Release(); 138 | } 139 | 140 | pGDIInterop->Release(); 141 | } 142 | 143 | // Create rendering params for all accepted rendering modes 144 | if(SUCCEEDED(hResult)) { 145 | const UINT renderingModeCount = 2; 146 | DWRITE_RENDERING_MODE renderingModes[renderingModeCount] = { 147 | DWRITE_RENDERING_MODE_DEFAULT, 148 | DWRITE_RENDERING_MODE_ALIASED 149 | }; 150 | 151 | for(UINT i=0; i < renderingModeCount; ++i) { 152 | DWRITE_RENDERING_MODE renderingMode = renderingModes[i]; 153 | IDWriteRenderingParams *pRenderingParams; 154 | 155 | hResult = pDWriteFactory->CreateCustomRenderingParams( 156 | 1.0f, 157 | 0.0f, 158 | 0.0f, 159 | DWRITE_PIXEL_GEOMETRY_FLAT, 160 | renderingMode, 161 | &pRenderingParams 162 | ); 163 | if(SUCCEEDED(hResult)) 164 | m_renderingParams.insert(std::make_pair(renderingMode, pRenderingParams)); 165 | } 166 | 167 | if(m_renderingParams.empty()) { 168 | m_lastError = L"Failed to create rendering params"; 169 | hResult = E_FAIL; 170 | } 171 | else 172 | hResult = S_OK; 173 | } 174 | 175 | return hResult; 176 | } 177 | 178 | 179 | // Init glyph data 180 | void CFW1DWriteRenderTarget::initGlyphData( 181 | const DWRITE_FONT_METRICS *fontMetrics, 182 | const DWRITE_GLYPH_METRICS *glyphMetrics, 183 | FLOAT fontSize, 184 | DWGlyphData *outGlyphData 185 | ) { 186 | // Calculate pixel-space coordinates 187 | FLOAT fscale = fontSize / static_cast(fontMetrics->designUnitsPerEm); 188 | 189 | FLOAT l = static_cast(glyphMetrics->leftSideBearing) * fscale; 190 | FLOAT t = static_cast(glyphMetrics->topSideBearing) * fscale; 191 | 192 | FLOAT r = static_cast(glyphMetrics->rightSideBearing) * fscale; 193 | FLOAT b = static_cast(glyphMetrics->bottomSideBearing) * fscale; 194 | 195 | FLOAT v = static_cast(glyphMetrics->verticalOriginY) * fscale; 196 | 197 | FLOAT aw = static_cast(glyphMetrics->advanceWidth) * fscale; 198 | FLOAT ah = static_cast(glyphMetrics->advanceHeight) * fscale; 199 | 200 | // Set up glyph data 201 | outGlyphData->offsetX = floor(l); 202 | outGlyphData->offsetY = floor(t) - floor(v); 203 | outGlyphData->maxWidth = static_cast(aw - r - l + 2.0f); 204 | outGlyphData->maxHeight = static_cast(ah - b - t + 2.0f); 205 | } 206 | 207 | 208 | }// namespace FW1FontWrapper 209 | -------------------------------------------------------------------------------- /lambsea/D3D11Render/D3D11StateSaver.cpp: -------------------------------------------------------------------------------- 1 | #include "D3D11Renderer.h" 2 | 3 | D3D11StateSaver::D3D11StateSaver() : 4 | m_savedState(false), 5 | m_featureLevel(D3D_FEATURE_LEVEL_11_0), 6 | m_pContext(NULL), 7 | m_primitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED), 8 | m_pInputLayout(NULL), 9 | m_pBlendState(NULL), 10 | m_sampleMask(0xffffffff), 11 | m_pDepthStencilState(NULL), 12 | m_stencilRef(0), 13 | m_pRasterizerState(NULL), 14 | m_pPSSRV(NULL), 15 | m_pSamplerState(NULL), 16 | m_pVS(NULL), 17 | m_numVSClassInstances(0), 18 | m_pVSConstantBuffer(NULL), 19 | m_pGS(NULL), 20 | m_numGSClassInstances(0), 21 | m_pGSConstantBuffer(NULL), 22 | m_pGSSRV(NULL), 23 | m_pPS(NULL), 24 | m_numPSClassInstances(0), 25 | m_pHS(NULL), 26 | m_numHSClassInstances(0), 27 | m_pDS(NULL), 28 | m_numDSClassInstances(0), 29 | m_pVB(NULL), 30 | m_vertexStride(0), 31 | m_vertexOffset(0), 32 | m_pIndexBuffer(NULL), 33 | m_indexFormat(DXGI_FORMAT_UNKNOWN), 34 | m_indexOffset(0) 35 | { 36 | for (int i = 0; i < 4; ++i) 37 | m_blendFactor[i] = 0.0f; 38 | for (int i = 0; i < 256; ++i) 39 | { 40 | m_pVSClassInstances[i] = NULL; 41 | m_pGSClassInstances[i] = NULL; 42 | m_pPSClassInstances[i] = NULL; 43 | m_pHSClassInstances[i] = NULL; 44 | m_pDSClassInstances[i] = NULL; 45 | } 46 | } 47 | 48 | D3D11StateSaver::~D3D11StateSaver() 49 | { 50 | releaseSavedState(); 51 | } 52 | 53 | HRESULT D3D11StateSaver::saveCurrentState(ID3D11DeviceContext *pContext) 54 | { 55 | if (m_savedState) 56 | releaseSavedState(); 57 | if (pContext == NULL) 58 | return E_INVALIDARG; 59 | 60 | ID3D11Device *pDevice; 61 | pContext->GetDevice(&pDevice); 62 | if (pDevice != NULL) { 63 | m_featureLevel = pDevice->GetFeatureLevel(); 64 | pDevice->Release(); 65 | } 66 | 67 | pContext->AddRef(); 68 | m_pContext = pContext; 69 | 70 | m_pContext->IAGetPrimitiveTopology(&m_primitiveTopology); 71 | m_pContext->IAGetInputLayout(&m_pInputLayout); 72 | 73 | m_pContext->OMGetBlendState(&m_pBlendState, m_blendFactor, &m_sampleMask); 74 | m_pContext->OMGetDepthStencilState(&m_pDepthStencilState, &m_stencilRef); 75 | 76 | m_pContext->RSGetState(&m_pRasterizerState); 77 | 78 | m_numVSClassInstances = 256; 79 | m_pContext->VSGetShader(&m_pVS, m_pVSClassInstances, &m_numVSClassInstances); 80 | m_pContext->VSGetConstantBuffers(0, 1, &m_pVSConstantBuffer); 81 | 82 | m_numPSClassInstances = 256; 83 | m_pContext->PSGetShader(&m_pPS, m_pPSClassInstances, &m_numPSClassInstances); 84 | m_pContext->PSGetShaderResources(0, 1, &m_pPSSRV); 85 | pContext->PSGetSamplers(0, 1, &m_pSamplerState); 86 | 87 | if (m_featureLevel >= D3D_FEATURE_LEVEL_10_0) 88 | { 89 | m_numGSClassInstances = 256; 90 | m_pContext->GSGetShader(&m_pGS, m_pGSClassInstances, &m_numGSClassInstances); 91 | m_pContext->GSGetConstantBuffers(0, 1, &m_pGSConstantBuffer); 92 | 93 | m_pContext->GSGetShaderResources(0, 1, &m_pGSSRV); 94 | 95 | if (m_featureLevel >= D3D_FEATURE_LEVEL_11_0) 96 | { 97 | m_numHSClassInstances = 256; 98 | m_pContext->HSGetShader(&m_pHS, m_pHSClassInstances, &m_numHSClassInstances); 99 | 100 | m_numDSClassInstances = 256; 101 | m_pContext->DSGetShader(&m_pDS, m_pDSClassInstances, &m_numDSClassInstances); 102 | } 103 | } 104 | 105 | m_pContext->IAGetVertexBuffers(0, 1, &m_pVB, &m_vertexStride, &m_vertexOffset); 106 | 107 | m_pContext->IAGetIndexBuffer(&m_pIndexBuffer, &m_indexFormat, &m_indexOffset); 108 | 109 | m_savedState = true; 110 | 111 | return S_OK; 112 | } 113 | 114 | HRESULT D3D11StateSaver::restoreSavedState() 115 | { 116 | if (!m_savedState) 117 | return E_FAIL; 118 | 119 | m_pContext->IASetPrimitiveTopology(m_primitiveTopology); 120 | m_pContext->IASetInputLayout(m_pInputLayout); 121 | 122 | m_pContext->OMSetBlendState(m_pBlendState, m_blendFactor, m_sampleMask); 123 | m_pContext->OMSetDepthStencilState(m_pDepthStencilState, m_stencilRef); 124 | 125 | m_pContext->RSSetState(m_pRasterizerState); 126 | 127 | m_pContext->VSSetShader(m_pVS, m_pVSClassInstances, m_numVSClassInstances); 128 | m_pContext->VSSetConstantBuffers(0, 1, &m_pVSConstantBuffer); 129 | 130 | m_pContext->PSSetShader(m_pPS, m_pPSClassInstances, m_numPSClassInstances); 131 | m_pContext->PSSetShaderResources(0, 1, &m_pPSSRV); 132 | m_pContext->PSSetSamplers(0, 1, &m_pSamplerState); 133 | 134 | if (m_featureLevel >= D3D_FEATURE_LEVEL_10_0) 135 | { 136 | m_pContext->GSSetShader(m_pGS, m_pGSClassInstances, m_numGSClassInstances); 137 | m_pContext->GSSetConstantBuffers(0, 1, &m_pGSConstantBuffer); 138 | 139 | m_pContext->GSSetShaderResources(0, 1, &m_pGSSRV); 140 | 141 | if (m_featureLevel >= D3D_FEATURE_LEVEL_11_0) 142 | { 143 | m_pContext->HSSetShader(m_pHS, m_pHSClassInstances, m_numHSClassInstances); 144 | 145 | m_pContext->DSSetShader(m_pDS, m_pDSClassInstances, m_numDSClassInstances); 146 | } 147 | } 148 | 149 | m_pContext->IASetVertexBuffers(0, 1, &m_pVB, &m_vertexStride, &m_vertexOffset); 150 | 151 | m_pContext->IASetIndexBuffer(m_pIndexBuffer, m_indexFormat, m_indexOffset); 152 | 153 | return S_OK; 154 | } 155 | 156 | void D3D11StateSaver::releaseSavedState() 157 | { 158 | m_primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED; 159 | SAFE_RELEASE(m_pInputLayout); 160 | SAFE_RELEASE(m_pBlendState); 161 | for (int i = 0; i < 4; ++i) 162 | m_blendFactor[i] = 0.0f; 163 | m_sampleMask = 0xffffffff; 164 | SAFE_RELEASE(m_pDepthStencilState); 165 | m_stencilRef = 0; 166 | SAFE_RELEASE(m_pRasterizerState); 167 | SAFE_RELEASE(m_pPSSRV); 168 | SAFE_RELEASE(m_pSamplerState); 169 | SAFE_RELEASE(m_pVS); 170 | for (UINT i = 0; i < m_numVSClassInstances; ++i) 171 | SAFE_RELEASE(m_pVSClassInstances[i]); 172 | m_numVSClassInstances = 0; 173 | SAFE_RELEASE(m_pVSConstantBuffer); 174 | SAFE_RELEASE(m_pGS); 175 | for (UINT i = 0; i < m_numGSClassInstances; ++i) 176 | SAFE_RELEASE(m_pGSClassInstances[i]); 177 | m_numGSClassInstances = 0; 178 | SAFE_RELEASE(m_pGSConstantBuffer); 179 | SAFE_RELEASE(m_pGSSRV); 180 | SAFE_RELEASE(m_pPS); 181 | for (UINT i = 0; i < m_numPSClassInstances; ++i) 182 | SAFE_RELEASE(m_pPSClassInstances[i]); 183 | m_numPSClassInstances = 0; 184 | SAFE_RELEASE(m_pHS); 185 | for (UINT i = 0; i < m_numHSClassInstances; ++i) 186 | SAFE_RELEASE(m_pHSClassInstances[i]); 187 | m_numHSClassInstances = 0; 188 | SAFE_RELEASE(m_pDS); 189 | for (UINT i = 0; i < m_numDSClassInstances; ++i) 190 | SAFE_RELEASE(m_pDSClassInstances[i]); 191 | m_numDSClassInstances = 0; 192 | SAFE_RELEASE(m_pVB); 193 | m_vertexStride = 0; 194 | m_vertexOffset = 0; 195 | SAFE_RELEASE(m_pIndexBuffer); 196 | m_indexFormat = DXGI_FORMAT_UNKNOWN; 197 | m_indexOffset = 0; 198 | 199 | SAFE_RELEASE(m_pContext); 200 | m_featureLevel = D3D_FEATURE_LEVEL_11_0; 201 | 202 | m_savedState = false; 203 | } -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1StateSaver.cpp: -------------------------------------------------------------------------------- 1 | // CFW1StateSaver.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1StateSaver.h" 6 | 7 | #define SAFE_RELEASE(pObject) { if(pObject) { (pObject)->Release(); (pObject) = NULL; } } 8 | 9 | 10 | namespace FW1FontWrapper { 11 | 12 | 13 | // Construct 14 | CFW1StateSaver::CFW1StateSaver() : 15 | m_savedState(false), 16 | m_featureLevel(D3D_FEATURE_LEVEL_11_0), 17 | m_pContext(NULL), 18 | m_primitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED), 19 | m_pInputLayout(NULL), 20 | m_pBlendState(NULL), 21 | m_sampleMask(0xffffffff), 22 | m_pDepthStencilState(NULL), 23 | m_stencilRef(0), 24 | m_pRasterizerState(NULL), 25 | m_pPSSRV(NULL), 26 | m_pSamplerState(NULL), 27 | m_pVS(NULL), 28 | m_numVSClassInstances(0), 29 | m_pVSConstantBuffer(NULL), 30 | m_pGS(NULL), 31 | m_numGSClassInstances(0), 32 | m_pGSConstantBuffer(NULL), 33 | m_pGSSRV(NULL), 34 | m_pPS(NULL), 35 | m_numPSClassInstances(0), 36 | m_pHS(NULL), 37 | m_numHSClassInstances(0), 38 | m_pDS(NULL), 39 | m_numDSClassInstances(0), 40 | m_pVB(NULL), 41 | m_vertexStride(0), 42 | m_vertexOffset(0), 43 | m_pIndexBuffer(NULL), 44 | m_indexFormat(DXGI_FORMAT_UNKNOWN), 45 | m_indexOffset(0) 46 | { 47 | for(int i=0; i < 4; ++i) 48 | m_blendFactor[i] = 0.0f; 49 | for(int i=0; i < 256; ++i) { 50 | m_pVSClassInstances[i] = NULL; 51 | m_pGSClassInstances[i] = NULL; 52 | m_pPSClassInstances[i] = NULL; 53 | m_pHSClassInstances[i] = NULL; 54 | m_pDSClassInstances[i] = NULL; 55 | } 56 | } 57 | 58 | 59 | // Destruct 60 | CFW1StateSaver::~CFW1StateSaver() { 61 | releaseSavedState(); 62 | } 63 | 64 | 65 | // Save all states that are changed by the font-wrapper when drawing a string 66 | HRESULT CFW1StateSaver::saveCurrentState(ID3D11DeviceContext *pContext) { 67 | if(m_savedState) 68 | releaseSavedState(); 69 | if(pContext == NULL) 70 | return E_INVALIDARG; 71 | 72 | ID3D11Device *pDevice; 73 | pContext->GetDevice(&pDevice); 74 | if(pDevice != NULL) { 75 | m_featureLevel = pDevice->GetFeatureLevel(); 76 | pDevice->Release(); 77 | } 78 | 79 | pContext->AddRef(); 80 | m_pContext = pContext; 81 | 82 | m_pContext->IAGetPrimitiveTopology(&m_primitiveTopology); 83 | m_pContext->IAGetInputLayout(&m_pInputLayout); 84 | 85 | m_pContext->OMGetBlendState(&m_pBlendState, m_blendFactor, &m_sampleMask); 86 | m_pContext->OMGetDepthStencilState(&m_pDepthStencilState, &m_stencilRef); 87 | 88 | m_pContext->RSGetState(&m_pRasterizerState); 89 | 90 | m_numVSClassInstances = 256; 91 | m_pContext->VSGetShader(&m_pVS, m_pVSClassInstances, &m_numVSClassInstances); 92 | m_pContext->VSGetConstantBuffers(0, 1, &m_pVSConstantBuffer); 93 | 94 | m_numPSClassInstances = 256; 95 | m_pContext->PSGetShader(&m_pPS, m_pPSClassInstances, &m_numPSClassInstances); 96 | m_pContext->PSGetShaderResources(0, 1, &m_pPSSRV); 97 | pContext->PSGetSamplers(0, 1, &m_pSamplerState); 98 | 99 | if(m_featureLevel >= D3D_FEATURE_LEVEL_10_0) { 100 | m_numGSClassInstances = 256; 101 | m_pContext->GSGetShader(&m_pGS, m_pGSClassInstances, &m_numGSClassInstances); 102 | m_pContext->GSGetConstantBuffers(0, 1, &m_pGSConstantBuffer); 103 | 104 | m_pContext->GSGetShaderResources(0, 1, &m_pGSSRV); 105 | 106 | if(m_featureLevel >= D3D_FEATURE_LEVEL_11_0) { 107 | m_numHSClassInstances = 256; 108 | m_pContext->HSGetShader(&m_pHS, m_pHSClassInstances, &m_numHSClassInstances); 109 | 110 | m_numDSClassInstances = 256; 111 | m_pContext->DSGetShader(&m_pDS, m_pDSClassInstances, &m_numDSClassInstances); 112 | } 113 | } 114 | 115 | m_pContext->IAGetVertexBuffers(0, 1, &m_pVB, &m_vertexStride, &m_vertexOffset); 116 | 117 | m_pContext->IAGetIndexBuffer(&m_pIndexBuffer, &m_indexFormat, &m_indexOffset); 118 | 119 | m_savedState = true; 120 | 121 | return S_OK; 122 | } 123 | 124 | 125 | // Restore state 126 | HRESULT CFW1StateSaver::restoreSavedState() { 127 | if(!m_savedState) 128 | return E_FAIL; 129 | 130 | m_pContext->IASetPrimitiveTopology(m_primitiveTopology); 131 | m_pContext->IASetInputLayout(m_pInputLayout); 132 | 133 | m_pContext->OMSetBlendState(m_pBlendState, m_blendFactor, m_sampleMask); 134 | m_pContext->OMSetDepthStencilState(m_pDepthStencilState, m_stencilRef); 135 | 136 | m_pContext->RSSetState(m_pRasterizerState); 137 | 138 | m_pContext->VSSetShader(m_pVS, m_pVSClassInstances, m_numVSClassInstances); 139 | m_pContext->VSSetConstantBuffers(0, 1, &m_pVSConstantBuffer); 140 | 141 | m_pContext->PSSetShader(m_pPS, m_pPSClassInstances, m_numPSClassInstances); 142 | m_pContext->PSSetShaderResources(0, 1, &m_pPSSRV); 143 | m_pContext->PSSetSamplers(0, 1, &m_pSamplerState); 144 | 145 | if(m_featureLevel >= D3D_FEATURE_LEVEL_10_0) { 146 | m_pContext->GSSetShader(m_pGS, m_pGSClassInstances, m_numGSClassInstances); 147 | m_pContext->GSSetConstantBuffers(0, 1, &m_pGSConstantBuffer); 148 | 149 | m_pContext->GSSetShaderResources(0, 1, &m_pGSSRV); 150 | 151 | if(m_featureLevel >= D3D_FEATURE_LEVEL_11_0) { 152 | m_pContext->HSSetShader(m_pHS, m_pHSClassInstances, m_numHSClassInstances); 153 | 154 | m_pContext->DSSetShader(m_pDS, m_pDSClassInstances, m_numDSClassInstances); 155 | } 156 | } 157 | 158 | m_pContext->IASetVertexBuffers(0, 1, &m_pVB, &m_vertexStride, &m_vertexOffset); 159 | 160 | m_pContext->IASetIndexBuffer(m_pIndexBuffer, m_indexFormat, m_indexOffset); 161 | 162 | return S_OK; 163 | } 164 | 165 | 166 | // Release state 167 | void CFW1StateSaver::releaseSavedState() { 168 | m_primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED; 169 | SAFE_RELEASE(m_pInputLayout); 170 | SAFE_RELEASE(m_pBlendState); 171 | for(int i=0; i < 4; ++i) 172 | m_blendFactor[i] = 0.0f; 173 | m_sampleMask = 0xffffffff; 174 | SAFE_RELEASE(m_pDepthStencilState); 175 | m_stencilRef = 0; 176 | SAFE_RELEASE(m_pRasterizerState); 177 | SAFE_RELEASE(m_pPSSRV); 178 | SAFE_RELEASE(m_pSamplerState); 179 | SAFE_RELEASE(m_pVS); 180 | for(UINT i=0; i < m_numVSClassInstances; ++i) 181 | SAFE_RELEASE(m_pVSClassInstances[i]); 182 | m_numVSClassInstances = 0; 183 | SAFE_RELEASE(m_pVSConstantBuffer); 184 | SAFE_RELEASE(m_pGS); 185 | for(UINT i=0; i < m_numGSClassInstances; ++i) 186 | SAFE_RELEASE(m_pGSClassInstances[i]); 187 | m_numGSClassInstances = 0; 188 | SAFE_RELEASE(m_pGSConstantBuffer); 189 | SAFE_RELEASE(m_pGSSRV); 190 | SAFE_RELEASE(m_pPS); 191 | for(UINT i=0; i < m_numPSClassInstances; ++i) 192 | SAFE_RELEASE(m_pPSClassInstances[i]); 193 | m_numPSClassInstances = 0; 194 | SAFE_RELEASE(m_pHS); 195 | for(UINT i=0; i < m_numHSClassInstances; ++i) 196 | SAFE_RELEASE(m_pHSClassInstances[i]); 197 | m_numHSClassInstances = 0; 198 | SAFE_RELEASE(m_pDS); 199 | for(UINT i=0; i < m_numDSClassInstances; ++i) 200 | SAFE_RELEASE(m_pDSClassInstances[i]); 201 | m_numDSClassInstances = 0; 202 | SAFE_RELEASE(m_pVB); 203 | m_vertexStride = 0; 204 | m_vertexOffset = 0; 205 | SAFE_RELEASE(m_pIndexBuffer); 206 | m_indexFormat = DXGI_FORMAT_UNKNOWN; 207 | m_indexOffset = 0; 208 | 209 | SAFE_RELEASE(m_pContext); 210 | m_featureLevel = D3D_FEATURE_LEVEL_11_0; 211 | 212 | m_savedState = false; 213 | } 214 | 215 | 216 | }// namespace FW1FontWrapper 217 | -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1TextRendererInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1TextRendererInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1TextRenderer.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1TextRenderer::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IDWritePixelSnapping))) { 17 | *ppvObject = static_cast(m_pDWriteTextRendererProxy); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | else if(IsEqualIID(riid, __uuidof(IDWriteTextRenderer))) { 22 | *ppvObject = static_cast(m_pDWriteTextRendererProxy); 23 | AddRef(); 24 | return S_OK; 25 | } 26 | else if(IsEqualIID(riid, __uuidof(IFW1TextRenderer))) { 27 | *ppvObject = static_cast(this); 28 | AddRef(); 29 | return S_OK; 30 | } 31 | 32 | return CFW1Object::QueryInterface(riid, ppvObject); 33 | } 34 | 35 | 36 | // IDWritePixelSnapping method 37 | HRESULT CFW1TextRenderer::IsPixelSnappingDisabled( 38 | void *clientDrawingContext, 39 | BOOL *isDisabled 40 | ) { 41 | clientDrawingContext; 42 | 43 | *isDisabled = FALSE; 44 | 45 | return S_OK; 46 | } 47 | 48 | 49 | // IDWritePixelSnapping method 50 | HRESULT CFW1TextRenderer::GetCurrentTransform( 51 | void *clientDrawingContext, 52 | DWRITE_MATRIX *transform 53 | ) { 54 | clientDrawingContext; 55 | 56 | transform->dx = 0.0f; 57 | transform->dy = 0.0f; 58 | transform->m11 = 1.0f; 59 | transform->m12 = 0.0f; 60 | transform->m21 = 0.0f; 61 | transform->m22 = 1.0f; 62 | 63 | return S_OK; 64 | } 65 | 66 | 67 | // IDWritePixelSnapping method 68 | HRESULT CFW1TextRenderer::GetPixelsPerDip(void *clientDrawingContext, FLOAT *pixelsPerDip) { 69 | clientDrawingContext; 70 | 71 | *pixelsPerDip = 96.0f; 72 | 73 | return S_OK; 74 | } 75 | 76 | 77 | // IDWriteTextRenderer method 78 | // Convert a run of glyphs to vertices 79 | HRESULT CFW1TextRenderer::DrawGlyphRun( 80 | void *clientDrawingContext, 81 | FLOAT baselineOriginX, 82 | FLOAT baselineOriginY, 83 | DWRITE_MEASURING_MODE measuringMode, 84 | const DWRITE_GLYPH_RUN *glyphRun, 85 | const DWRITE_GLYPH_RUN_DESCRIPTION *glyphRunDescription, 86 | IUnknown *clientDrawingEffect 87 | ) { 88 | glyphRunDescription; 89 | measuringMode; 90 | 91 | const UINT flags = m_currentFlags; 92 | 93 | // Get glyph map for the current font 94 | const void *glyphMap; 95 | if(glyphRun->fontFace == m_pCachedGlyphMapFontFace && glyphRun->fontEmSize == m_cachedGlyphMapFontSize) 96 | glyphMap = m_cachedGlyphMap; 97 | else { 98 | glyphMap = m_pGlyphProvider->GetGlyphMapFromFont(glyphRun->fontFace, glyphRun->fontEmSize, flags); 99 | 100 | // Cache the glyph map as it's likely to be used in subsequent glyph runs 101 | m_cachedGlyphMap = glyphMap; 102 | m_pCachedGlyphMapFontFace = glyphRun->fontFace; 103 | m_cachedGlyphMapFontSize = glyphRun->fontEmSize; 104 | } 105 | 106 | // Skip if not interested in the actual glyphs 107 | if((flags & FW1_ANALYZEONLY) != 0) 108 | return S_OK; 109 | 110 | if((flags & FW1_CACHEONLY) != 0) { 111 | // Only request the glyphs from the provider to have them drawn to the atlas 112 | for(UINT i=0; i < glyphRun->glyphCount; ++i) { 113 | UINT atlasId = m_pGlyphProvider->GetAtlasIdFromGlyphIndex( 114 | glyphMap, 115 | glyphRun->glyphIndices[i], 116 | glyphRun->fontFace, 117 | flags 118 | ); 119 | atlasId; 120 | } 121 | } 122 | else { 123 | // Glyph vertex 124 | FW1_GLYPHVERTEX glyphVertex; 125 | glyphVertex.PositionY = floor(baselineOriginY + 0.5f); 126 | glyphVertex.GlyphColor = m_currentColor; 127 | 128 | float positionX = floor(baselineOriginX + 0.5f); 129 | 130 | // Optional drawing effect 131 | if(clientDrawingEffect != NULL) { 132 | IFW1ColorRGBA *pColor; 133 | HRESULT hResult = clientDrawingEffect->QueryInterface(&pColor); 134 | if(SUCCEEDED(hResult)) { 135 | glyphVertex.GlyphColor = pColor->GetColor32(); 136 | pColor->Release(); 137 | } 138 | } 139 | 140 | // Add a vertex for each glyph in the run 141 | IFW1TextGeometry *pTextGeometry = static_cast(clientDrawingContext); 142 | if(pTextGeometry != NULL) { 143 | for(UINT i=0; i < glyphRun->glyphCount; ++i) { 144 | glyphVertex.GlyphIndex = m_pGlyphProvider->GetAtlasIdFromGlyphIndex( 145 | glyphMap, 146 | glyphRun->glyphIndices[i], 147 | glyphRun->fontFace, 148 | flags 149 | ); 150 | 151 | if((glyphRun->bidiLevel & 0x1) != 0) 152 | positionX -= glyphRun->glyphAdvances[i]; 153 | 154 | glyphVertex.PositionX = floor(positionX + 0.5f); 155 | pTextGeometry->AddGlyphVertex(&glyphVertex); 156 | 157 | if((glyphRun->bidiLevel & 0x1) == 0) 158 | positionX += glyphRun->glyphAdvances[i]; 159 | } 160 | } 161 | } 162 | 163 | return S_OK; 164 | } 165 | 166 | 167 | // IDWriteTextRenderer method 168 | HRESULT CFW1TextRenderer::DrawUnderline( 169 | void *clientDrawingContext, 170 | FLOAT baselineOriginX, 171 | FLOAT baselineOriginY, 172 | const DWRITE_UNDERLINE *underline, 173 | IUnknown *clientDrawingEffect 174 | ) { 175 | clientDrawingContext; 176 | baselineOriginX; 177 | baselineOriginY; 178 | underline; 179 | clientDrawingEffect; 180 | 181 | return E_NOTIMPL; 182 | } 183 | 184 | 185 | // IDWriteTextRenderer method 186 | HRESULT CFW1TextRenderer::DrawStrikethrough( 187 | void *clientDrawingContext, 188 | FLOAT baselineOriginX, 189 | FLOAT baselineOriginY, 190 | const DWRITE_STRIKETHROUGH *strikethrough, 191 | IUnknown *clientDrawingEffect 192 | ) { 193 | clientDrawingContext; 194 | baselineOriginX; 195 | baselineOriginY; 196 | strikethrough; 197 | clientDrawingEffect; 198 | 199 | return E_NOTIMPL; 200 | } 201 | 202 | 203 | // IDWriteTextRenderer method 204 | HRESULT CFW1TextRenderer::DrawInlineObject( 205 | void *clientDrawingContext, 206 | FLOAT originX, 207 | FLOAT originY, 208 | IDWriteInlineObject *inlineObject, 209 | BOOL isSideways, 210 | BOOL isRightToLeft, 211 | IUnknown *clientDrawingEffect 212 | ) { 213 | clientDrawingContext; 214 | originX; 215 | originY; 216 | inlineObject; 217 | isSideways; 218 | isRightToLeft; 219 | clientDrawingEffect; 220 | 221 | return E_NOTIMPL; 222 | } 223 | 224 | 225 | // Get glyph provider 226 | HRESULT STDMETHODCALLTYPE CFW1TextRenderer::GetGlyphProvider(IFW1GlyphProvider **ppGlyphProvider) { 227 | if(ppGlyphProvider == NULL) 228 | return E_INVALIDARG; 229 | 230 | m_pGlyphProvider->AddRef(); 231 | *ppGlyphProvider = m_pGlyphProvider; 232 | 233 | return S_OK; 234 | } 235 | 236 | 237 | // Draw a text layout 238 | HRESULT STDMETHODCALLTYPE CFW1TextRenderer::DrawTextLayout( 239 | IDWriteTextLayout *pTextLayout, 240 | FLOAT OriginX, 241 | FLOAT OriginY, 242 | UINT32 Color, 243 | UINT Flags, 244 | IFW1TextGeometry *pTextGeometry 245 | ) { 246 | m_currentFlags = Flags; 247 | m_currentColor = Color; 248 | 249 | m_cachedGlyphMap = 0; 250 | m_pCachedGlyphMapFontFace = NULL; 251 | m_cachedGlyphMapFontSize = 0.0f; 252 | 253 | return pTextLayout->Draw(pTextGeometry, m_pDWriteTextRendererProxy, OriginX, OriginY); 254 | } 255 | 256 | 257 | }// namespace FW1FontWrapper 258 | -------------------------------------------------------------------------------- /IPCServer/HandleGetter.cpp: -------------------------------------------------------------------------------- 1 | #include "HandleGetter.h" 2 | NTSTATUS EnumerateHandles(ENUM_HANDLE_CALLBACK callback) 3 | { 4 | NTSTATUS status = STATUS_UNSUCCESSFUL; 5 | PVOID buffer = NULL; 6 | ULONG bufferSize = 0; 7 | 8 | do { 9 | status = NtQuerySystemInformation(SystemHandleInformation, buffer, bufferSize, &bufferSize); 10 | if (!NT_SUCCESS(status)) { 11 | if (status == STATUS_INFO_LENGTH_MISMATCH) { 12 | if (buffer != NULL) 13 | VirtualFree(buffer, 0, MEM_RELEASE); 14 | buffer = VirtualAlloc(NULL, bufferSize, MEM_COMMIT, PAGE_READWRITE); 15 | continue; 16 | } 17 | break; 18 | } 19 | else { 20 | PSYSTEM_HANDLE_INFORMATION handleInfo = (PSYSTEM_HANDLE_INFORMATION)buffer; 21 | for (ULONG i = 0; i < handleInfo->NumberOfHandles; i++) { 22 | auto handle = &handleInfo->Handles[i]; 23 | status = callback(handle); 24 | if (NT_SUCCESS(status)) 25 | break; 26 | } 27 | break; 28 | } 29 | } while (true); 30 | 31 | if (buffer != NULL) 32 | VirtualFree(buffer, 0, MEM_RELEASE); 33 | return status; 34 | } 35 | 36 | HANDLE GetHandleToProcess(LPWSTR process) 37 | { 38 | HANDLE hProcess = NULL; 39 | 40 | EnumerateHandles([&](PSYSTEM_HANDLE_TABLE_ENTRY_INFO handle) -> NTSTATUS { 41 | 42 | if (GetCurrentProcessId() != handle->UniqueProcessId) return STATUS_UNSUCCESSFUL; 43 | 44 | BOOL found = FALSE; 45 | PVOID buffer = NULL; 46 | ULONG bufferSize = 0x100; 47 | NTSTATUS status; 48 | 49 | 50 | do { 51 | buffer = VirtualAlloc(NULL, bufferSize, MEM_COMMIT, PAGE_READWRITE); 52 | status = NtQueryObject((HANDLE)handle->HandleValue, ObjectTypeInformation, buffer, bufferSize, &bufferSize); 53 | if (NT_SUCCESS(status)) break; 54 | if (buffer != NULL) 55 | VirtualFree(buffer, 0, MEM_RELEASE); 56 | } while (status == STATUS_INFO_LENGTH_MISMATCH); 57 | 58 | BOOL isProcess = FALSE; 59 | 60 | try 61 | { 62 | isProcess = std::wstring(((POBJECT_TYPE_INFORMATION)buffer)->TypeName.Buffer) == std::wstring(L"Process"); 63 | } 64 | catch (...) 65 | { 66 | isProcess = FALSE; 67 | } 68 | 69 | if (isProcess) { 70 | WCHAR processPath[MAX_PATH] = {}; 71 | 72 | if (GetModuleFileNameExW((HANDLE)handle->HandleValue, NULL, processPath, MAX_PATH)) { 73 | LPWSTR filename = PathFindFileNameW(processPath); 74 | if (!wcscmp(filename, process)) { 75 | found = TRUE; 76 | hProcess = (HANDLE)handle->HandleValue; 77 | } 78 | } 79 | } 80 | 81 | if (buffer != NULL) 82 | VirtualFree(buffer, 0, MEM_RELEASE); 83 | 84 | if (found) 85 | return STATUS_SUCCESS; 86 | 87 | return STATUS_UNSUCCESSFUL; 88 | 89 | }); 90 | 91 | return hProcess; 92 | } 93 | 94 | void PrintSelfToOthersHandles() 95 | { 96 | printf("---------------------Begin------------------------\n"); 97 | 98 | EnumerateHandles([](PSYSTEM_HANDLE_TABLE_ENTRY_INFO handle) { 99 | 100 | if (GetCurrentProcessId() != handle->UniqueProcessId) return STATUS_UNSUCCESSFUL; 101 | 102 | // 103 | // Print name information 104 | // 105 | PVOID buffer = NULL; 106 | ULONG bufferSize = 0x100; 107 | NTSTATUS status; 108 | 109 | //do { 110 | // buffer = VirtualAlloc(NULL, bufferSize, MEM_COMMIT, PAGE_READWRITE); 111 | // status = NtQueryObject((HANDLE)handle->HandleValue, (OBJECT_INFORMATION_CLASS)1/*ObjectNameInformation*/, buffer, bufferSize, &bufferSize); 112 | // if (NT_SUCCESS(status)) break; 113 | // if (buffer != NULL) 114 | // VirtualFree(buffer, 0, MEM_RELEASE); 115 | //} while (status == STATUS_INFO_LENGTH_MISMATCH); 116 | 117 | //if (!NT_SUCCESS(status)) 118 | // goto EXIT; 119 | 120 | //printf("Handle Object: 0x%p\n", handle->Object); 121 | //printf("Handle Value: 0x%04X\n", handle->HandleValue); 122 | //printf("Granted Access: 0x%08X\n", handle->GrantedAccess); 123 | //printf("Name: %ws\n", ((POBJECT_NAME_INFORMATION)buffer)->Name.Buffer); 124 | //VirtualFree(buffer, 0, MEM_RELEASE); 125 | 126 | do { 127 | buffer = VirtualAlloc(NULL, bufferSize, MEM_COMMIT, PAGE_READWRITE); 128 | status = NtQueryObject((HANDLE)handle->HandleValue, ObjectTypeInformation, buffer, bufferSize, &bufferSize); 129 | if (NT_SUCCESS(status)) break; 130 | if (buffer != NULL) 131 | VirtualFree(buffer, 0, MEM_RELEASE); 132 | } while (status == STATUS_INFO_LENGTH_MISMATCH); 133 | 134 | if (!NT_SUCCESS(status)) 135 | goto EXIT; 136 | 137 | 138 | { 139 | std::wstring typeName = ((POBJECT_TYPE_INFORMATION)buffer)->TypeName.Buffer; 140 | if (typeName.find(L"rocess") == std::wstring::npos && typeName.find(L"hread") == std::wstring::npos) 141 | goto EXIT; 142 | 143 | printf("Handle Object: 0x%p\n", handle->Object); 144 | printf("Handle Value: 0x%04X\n", handle->HandleValue); 145 | printf("Granted Access: 0x%08X\n", handle->GrantedAccess); 146 | printf("Type: %ws\n", typeName.c_str()); 147 | } 148 | // 149 | // 7 is the process type index on my system. It's possible that this is different value on your system. 150 | // You can compare the TypeName to "Process" instead of doing it like this 151 | // 152 | 153 | if (std::wstring(((POBJECT_TYPE_INFORMATION)buffer)->TypeName.Buffer) == std::wstring(L"Process")) { 154 | WCHAR processPath[MAX_PATH]; 155 | // 156 | // The handle needs to have PROCESS_QUERY_INFORMATION and PROCESS_VM_READ 157 | // access, otherwise this call fails 158 | // 159 | if (GetModuleFileNameExW((HANDLE)handle->HandleValue, NULL, processPath, MAX_PATH)) { 160 | printf("Process: %ws\n", PathFindFileNameW(processPath)); 161 | } 162 | } 163 | 164 | if (std::wstring(((POBJECT_TYPE_INFORMATION)buffer)->TypeName.Buffer) == std::wstring(L"Thread")) { 165 | printf("HostProcess ID: %d\n", GetProcessIdOfThread((HANDLE)handle->HandleValue)); 166 | } 167 | 168 | printf("-------------------------------------------------\n"); 169 | 170 | EXIT: 171 | if (buffer != NULL) 172 | VirtualFree(buffer, 0, MEM_RELEASE); 173 | 174 | return STATUS_UNSUCCESSFUL; 175 | }); 176 | } 177 | 178 | bool EnablePrivilege( 179 | LPCWSTR lpPrivilegeName 180 | ) 181 | { 182 | TOKEN_PRIVILEGES Privilege; 183 | HANDLE hToken; 184 | DWORD dwErrorCode; 185 | 186 | Privilege.PrivilegeCount = 1; 187 | Privilege.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 188 | if (!LookupPrivilegeValueW(NULL, lpPrivilegeName, 189 | &Privilege.Privileges[0].Luid)) 190 | return GetLastError(); 191 | 192 | if (!OpenProcessToken(GetCurrentProcess(), 193 | TOKEN_ADJUST_PRIVILEGES, &hToken)) 194 | return GetLastError(); 195 | 196 | if (!AdjustTokenPrivileges(hToken, FALSE, &Privilege, sizeof(Privilege), 197 | NULL, NULL)) { 198 | dwErrorCode = GetLastError(); 199 | CloseHandle(hToken); 200 | return dwErrorCode; 201 | } 202 | 203 | CloseHandle(hToken); 204 | return TRUE; 205 | } 206 | 207 | bool DisablePrivilege( 208 | LPCWSTR lpPrivilegeName 209 | ) 210 | { 211 | TOKEN_PRIVILEGES Privilege; 212 | HANDLE hToken; 213 | DWORD dwErrorCode; 214 | 215 | Privilege.PrivilegeCount = 1; 216 | Privilege.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED_BY_DEFAULT; 217 | if (!LookupPrivilegeValueW(NULL, lpPrivilegeName, 218 | &Privilege.Privileges[0].Luid)) 219 | return GetLastError(); 220 | 221 | if (!OpenProcessToken(GetCurrentProcess(), 222 | TOKEN_ADJUST_PRIVILEGES, &hToken)) 223 | return GetLastError(); 224 | 225 | if (!AdjustTokenPrivileges(hToken, FALSE, &Privilege, sizeof(Privilege), 226 | NULL, NULL)) { 227 | dwErrorCode = GetLastError(); 228 | CloseHandle(hToken); 229 | return dwErrorCode; 230 | } 231 | 232 | CloseHandle(hToken); 233 | return TRUE; 234 | } -------------------------------------------------------------------------------- /lambsea/FW1FontWrapper/CFW1GlyphSheet.cpp: -------------------------------------------------------------------------------- 1 | // CFW1GlyphSheet.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1GlyphSheet.h" 6 | 7 | #define SAFE_RELEASE(pObject) { if(pObject) { (pObject)->Release(); (pObject) = NULL; } } 8 | 9 | 10 | namespace FW1FontWrapper { 11 | 12 | 13 | // Construct 14 | CFW1GlyphSheet::CFW1GlyphSheet() : 15 | m_sheetWidth(0), 16 | m_sheetHeight(0), 17 | m_hardwareCoordBuffer(false), 18 | m_allowOversizedGlyph(false), 19 | 20 | m_textureData(0), 21 | m_glyphCoords(0), 22 | m_maxGlyphCount(0), 23 | m_glyphCount(0), 24 | m_mipLevelCount(0), 25 | m_alignWidth(0), 26 | 27 | m_pDevice(NULL), 28 | 29 | m_pTexture(NULL), 30 | m_pTextureSRV(NULL), 31 | m_pCoordBuffer(NULL), 32 | m_pCoordBufferSRV(NULL), 33 | 34 | m_closed(false), 35 | m_static(false), 36 | 37 | m_heightRange(0), 38 | 39 | m_updatedGlyphCount(0) 40 | { 41 | ZeroMemory(&m_dirtyRect, sizeof(m_dirtyRect)); 42 | InitializeCriticalSection(&m_sheetCriticalSection); 43 | InitializeCriticalSection(&m_flushCriticalSection); 44 | } 45 | 46 | 47 | // Destruct 48 | CFW1GlyphSheet::~CFW1GlyphSheet() { 49 | delete[] m_textureData; 50 | delete[] m_glyphCoords; 51 | 52 | SAFE_RELEASE(m_pDevice); 53 | 54 | SAFE_RELEASE(m_pTexture); 55 | SAFE_RELEASE(m_pTextureSRV); 56 | SAFE_RELEASE(m_pCoordBuffer); 57 | SAFE_RELEASE(m_pCoordBufferSRV); 58 | 59 | delete m_heightRange; 60 | 61 | DeleteCriticalSection(&m_sheetCriticalSection); 62 | DeleteCriticalSection(&m_flushCriticalSection); 63 | } 64 | 65 | 66 | // Init 67 | HRESULT CFW1GlyphSheet::initGlyphSheet( 68 | IFW1Factory *pFW1Factory, 69 | ID3D11Device *pDevice, 70 | UINT sheetWidth, 71 | UINT sheetHeight, 72 | bool coordBuffer, 73 | bool allowOversizedGlyph, 74 | UINT maxGlyphCount, 75 | UINT mipLevelCount 76 | ) { 77 | HRESULT hResult = initBaseObject(pFW1Factory); 78 | if(FAILED(hResult)) 79 | return hResult; 80 | 81 | if(pDevice == NULL) 82 | return E_INVALIDARG; 83 | 84 | pDevice->AddRef(); 85 | m_pDevice = pDevice; 86 | 87 | // Sheet metrics 88 | m_sheetWidth = 512; 89 | if(sheetWidth > 0) 90 | m_sheetWidth = sheetWidth; 91 | m_sheetHeight = 512; 92 | if(sheetHeight > 0) 93 | m_sheetHeight = sheetHeight; 94 | 95 | if(coordBuffer) { 96 | D3D_FEATURE_LEVEL featureLevel = m_pDevice->GetFeatureLevel(); 97 | if(featureLevel >= D3D_FEATURE_LEVEL_10_0) 98 | m_hardwareCoordBuffer = true; 99 | } 100 | 101 | m_allowOversizedGlyph = allowOversizedGlyph; 102 | 103 | m_maxGlyphCount = 2048; 104 | if(maxGlyphCount > 0 && maxGlyphCount < 65535) 105 | m_maxGlyphCount = maxGlyphCount; 106 | 107 | if(mipLevelCount > 1) { 108 | m_mipLevelCount = std::min(mipLevelCount, 5U);// Reasonable mip limit considering borders 109 | m_alignWidth = (1 << (m_mipLevelCount - 1)); 110 | } 111 | else {// 0 defaults to 1 112 | m_mipLevelCount = 1; 113 | m_alignWidth = 1; 114 | } 115 | 116 | // Storage 117 | UINT textureSize = m_sheetWidth * m_sheetHeight; 118 | UINT mipSize = textureSize; 119 | for(UINT i=1;i>= 2; 121 | textureSize += mipSize; 122 | } 123 | 124 | m_textureData = new UINT8[textureSize]; 125 | ZeroMemory(m_textureData, textureSize); 126 | 127 | m_glyphCoords = new FW1_GLYPHCOORDS[m_maxGlyphCount]; 128 | 129 | m_heightRange = new HeightRange(m_sheetWidth / m_alignWidth); 130 | 131 | // Device texture/coord-buffer 132 | hResult = createDeviceResources(); 133 | 134 | if(SUCCEEDED(hResult)) 135 | hResult = S_OK; 136 | 137 | return hResult; 138 | } 139 | 140 | 141 | // Create sheet texture and (optionally) coord buffer 142 | HRESULT CFW1GlyphSheet::createDeviceResources() { 143 | // Create sheet texture 144 | D3D11_TEXTURE2D_DESC textureDesc; 145 | ID3D11Texture2D *pTexture; 146 | 147 | ZeroMemory(&textureDesc, sizeof(textureDesc)); 148 | textureDesc.Width = m_sheetWidth; 149 | textureDesc.Height = m_sheetHeight; 150 | textureDesc.ArraySize = 1; 151 | textureDesc.Format = DXGI_FORMAT_R8_UNORM; 152 | textureDesc.SampleDesc.Count = 1; 153 | textureDesc.Usage = D3D11_USAGE_DEFAULT; 154 | textureDesc.MipLevels = m_mipLevelCount; 155 | textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 156 | 157 | HRESULT hResult = m_pDevice->CreateTexture2D(&textureDesc, NULL, &pTexture); 158 | if(FAILED(hResult)) { 159 | m_lastError = L"Failed to create glyph sheet texture"; 160 | } 161 | else { 162 | ID3D11ShaderResourceView *pTextureSRV; 163 | 164 | hResult = m_pDevice->CreateShaderResourceView(pTexture, NULL, &pTextureSRV); 165 | if(FAILED(hResult)) { 166 | m_lastError = L"Failed to create shader resource view for glyph sheet texture"; 167 | } 168 | else { 169 | // Create coord buffer if enabled 170 | if(m_hardwareCoordBuffer) { 171 | D3D11_BUFFER_DESC bufferDesc; 172 | ID3D11Buffer *pBuffer; 173 | 174 | ZeroMemory(&bufferDesc, sizeof(bufferDesc)); 175 | bufferDesc.ByteWidth = m_maxGlyphCount * sizeof(FW1_GLYPHCOORDS); 176 | bufferDesc.Usage = D3D11_USAGE_DEFAULT; 177 | bufferDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 178 | 179 | hResult = m_pDevice->CreateBuffer(&bufferDesc, NULL, &pBuffer); 180 | if(FAILED(hResult)) { 181 | m_lastError = L"Failed to create glyph coord buffer"; 182 | } 183 | else { 184 | D3D11_SHADER_RESOURCE_VIEW_DESC bufferSRVDesc; 185 | ID3D11ShaderResourceView *pBufferSRV; 186 | 187 | ZeroMemory(&bufferSRVDesc, sizeof(bufferSRVDesc)); 188 | bufferSRVDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; 189 | bufferSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; 190 | bufferSRVDesc.Buffer.ElementOffset = 0; 191 | bufferSRVDesc.Buffer.ElementWidth = m_maxGlyphCount * 2;// Two float4 per glyphcoords 192 | 193 | hResult = m_pDevice->CreateShaderResourceView(pBuffer, &bufferSRVDesc, &pBufferSRV); 194 | if(FAILED(hResult)) { 195 | m_lastError = L"Failed to create shader resource view for glyph coord buffer"; 196 | } 197 | else { 198 | m_pCoordBuffer = pBuffer; 199 | m_pCoordBufferSRV = pBufferSRV; 200 | } 201 | 202 | if(FAILED(hResult)) 203 | pBuffer->Release(); 204 | } 205 | } 206 | 207 | if(SUCCEEDED(hResult)) { 208 | m_pTexture = pTexture; 209 | m_pTextureSRV = pTextureSRV; 210 | } 211 | else 212 | pTextureSRV->Release(); 213 | } 214 | 215 | if(FAILED(hResult)) 216 | pTexture->Release(); 217 | } 218 | 219 | return hResult; 220 | } 221 | 222 | 223 | // Height-range helper class, used to fit glyphs in the sheet 224 | 225 | CFW1GlyphSheet::HeightRange::HeightRange(UINT totalWidth) : m_totalWidth(totalWidth) { 226 | m_heights = new UINT[m_totalWidth]; 227 | ZeroMemory(m_heights, m_totalWidth * sizeof(UINT)); 228 | } 229 | 230 | CFW1GlyphSheet::HeightRange::~HeightRange() { 231 | delete[] m_heights; 232 | } 233 | 234 | UINT CFW1GlyphSheet::HeightRange::findMin(UINT width, UINT *outMin) { 235 | if(width > m_totalWidth) 236 | width = m_totalWidth; 237 | 238 | UINT currentMax = findMax(0, width); 239 | UINT currentMin = currentMax; 240 | UINT minX = 0; 241 | 242 | for(UINT i=1; i < m_totalWidth-width; ++i) { 243 | if(m_heights[i+width-1] >= currentMax) 244 | currentMax = m_heights[i+width-1]; 245 | else if(m_heights[i-1] == currentMax) { 246 | currentMax = findMax(i, width); 247 | if(currentMax < currentMin) { 248 | currentMin = currentMax; 249 | minX = i; 250 | } 251 | } 252 | } 253 | 254 | *outMin = currentMin; 255 | return minX; 256 | } 257 | 258 | void CFW1GlyphSheet::HeightRange::update(UINT startX, UINT width, UINT newHeight) { 259 | if(width > m_totalWidth) 260 | width = m_totalWidth; 261 | 262 | for(UINT i=0; i < width; ++i) 263 | m_heights[startX+i] = newHeight; 264 | } 265 | 266 | UINT CFW1GlyphSheet::HeightRange::findMax(UINT startX, UINT width) { 267 | UINT currentMax = m_heights[startX]; 268 | for(UINT i=1; i < width; ++i) 269 | currentMax = std::max(currentMax, m_heights[startX+i]); 270 | 271 | return currentMax; 272 | } 273 | 274 | 275 | }// namespace FW1FontWrapper 276 | -------------------------------------------------------------------------------- /lambsea/Decrypt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #pragma region DynTable 7 | 8 | uint8_t byte_table[] = { 9 | 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 10 | 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 11 | 0x2F, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, 12 | 0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, 13 | 0x4F, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, 0x49, 0x48, 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41, 0x40, 14 | 0x5F, 0x5E, 0x5D, 0x5C, 0x5B, 0x5A, 0x59, 0x58, 0x57, 0x56, 0x55, 0x54, 0x53, 0x52, 0x51, 0x50, 15 | 0x6F, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A, 0x69, 0x68, 0x67, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x60, 16 | 0x7F, 0x7E, 0x7D, 0x7C, 0x7B, 0x7A, 0x79, 0x78, 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x70, 17 | 0x8F, 0x8E, 0x8D, 0x8C, 0x8B, 0x8A, 0x89, 0x88, 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80, 18 | 0x9F, 0x9E, 0x9D, 0x9C, 0x9B, 0x9A, 0x99, 0x98, 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91, 0x90, 19 | 0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8, 0xA7, 0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1, 0xA0, 20 | 0xBF, 0xBE, 0xBD, 0xBC, 0xBB, 0xBA, 0xB9, 0xB8, 0xB7, 0xB6, 0xB5, 0xB4, 0xB3, 0xB2, 0xB1, 0xB0, 21 | 0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8, 0xC7, 0xC6, 0xC5, 0xC4, 0xC3, 0xC2, 0xC1, 0xC0, 22 | 0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8, 0xD7, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xD0, 23 | 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8, 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0, 24 | 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8, 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0 25 | }; 26 | 27 | 28 | class DynTable { 29 | private: 30 | uint32_t table[2048]; 31 | 32 | public: 33 | void inline generate(int32_t rotator, int32_t(&decrypt_offsets)[7]); 34 | uint32_t inline get(uint32_t idx); 35 | }; 36 | 37 | void DynTable::generate(int32_t rotator, int32_t(&decrypt_offsets)[7]) { 38 | for (uint32_t i = 0; i < 0x100; i++) { 39 | uint32_t tmp = i; 40 | if ((tmp & 1) != 0) 41 | tmp ^= rotator; 42 | 43 | tmp >>= 1; 44 | if ((tmp & 1) != 0) 45 | tmp ^= rotator; 46 | 47 | tmp >>= 1; 48 | if ((tmp & 1) != 0) 49 | tmp ^= rotator; 50 | 51 | tmp >>= 1; 52 | if ((tmp & 1) != 0) 53 | tmp ^= rotator; 54 | 55 | tmp >>= 1; 56 | if ((tmp & 1) != 0) 57 | tmp ^= rotator; 58 | 59 | tmp >>= 1; 60 | if ((tmp & 1) != 0) 61 | tmp ^= rotator; 62 | 63 | tmp >>= 1; 64 | if ((tmp & 1) != 0) 65 | tmp ^= rotator; 66 | 67 | tmp >>= 1; 68 | if ((tmp & 1) != 0) 69 | tmp ^= rotator; 70 | 71 | this->table[i] = tmp >> 1; 72 | } 73 | 74 | uint32_t off = 0x200; 75 | for (int i = 0; i < 0x100; i++) { 76 | uint32_t tmp = this->table[off - 0x200]; 77 | 78 | off += 1; 79 | 80 | tmp = (tmp >> 8) ^ this->table[tmp & 0xFF]; 81 | this->table[off + decrypt_offsets[0]] = tmp; 82 | 83 | tmp = (tmp >> 8) ^ this->table[tmp & 0xFF]; 84 | this->table[off + decrypt_offsets[1]] = tmp; 85 | 86 | tmp = (tmp >> 8) ^ this->table[tmp & 0xFF]; 87 | this->table[off + decrypt_offsets[2]] = tmp; 88 | 89 | tmp = (tmp >> 8) ^ this->table[tmp & 0xFF]; 90 | this->table[off + decrypt_offsets[3]] = tmp; 91 | 92 | tmp = (tmp >> 8) ^ this->table[tmp & 0xFF]; 93 | this->table[off + decrypt_offsets[4]] = tmp; 94 | 95 | tmp = (tmp >> 8) ^ this->table[tmp & 0xFF]; 96 | this->table[off + decrypt_offsets[5]] = tmp; 97 | 98 | tmp = (tmp >> 8) ^ this->table[tmp & 0xFF]; 99 | this->table[off + decrypt_offsets[6]] = tmp; 100 | } 101 | } 102 | 103 | uint32_t DynTable::get(uint32_t idx) { 104 | return this->table[idx]; 105 | } 106 | 107 | 108 | 109 | #pragma endregion 110 | 111 | #pragma region NativeHelpers 112 | 113 | int32_t inline ubyte0(int32_t i) { 114 | return i & 0xFF; 115 | } 116 | 117 | int32_t inline ubyte1(int32_t i) { 118 | return (i >> 8) & 0xFF; 119 | } 120 | 121 | int32_t inline ubyte2(int32_t i) { 122 | return (i >> 16) & 0xFF; 123 | } 124 | 125 | int32_t inline ubyte3(int32_t i) { 126 | return (i >> 24) & 0xFF; 127 | } 128 | 129 | int32_t inline word0(int64_t l) { 130 | return (l >> 0) & 0xFFFF; 131 | } 132 | 133 | #pragma endregion 134 | 135 | DynTable dyn_table_r; 136 | int32_t decrypt_rotator = 0x33ABAEBE; 137 | 138 | int32_t decrypt_offsets[] = { 139 | -257, -1, 255, 511, 767, 1023, 1279 140 | }; 141 | 142 | void inline init_decryption(void) { 143 | dyn_table_r.generate(decrypt_rotator, decrypt_offsets); 144 | } 145 | 146 | uint16_t inline decrypt_p1(int64_t left, int64_t right) { 147 | uint16_t decrypted = right ^ ~left ^ 0xD25; 148 | for (auto i = 0; i < 5; i++) { 149 | auto idx1 = (decrypted ^ 0x4400u) >> 8; 150 | auto idx2 = (decrypted ^ 0x55) & 0xFF; 151 | decrypted = byte_table[byte_table[idx1]] | (byte_table[byte_table[idx2]] << 8); 152 | } 153 | return decrypted; 154 | } 155 | 156 | uint64_t inline decrypt_p20(int64_t left, int64_t right, uint64_t a, uint64_t b, uint64_t c, uint64_t d_idx) { 157 | auto p1 = decrypt_p1(left, right); 158 | auto idx2 = ubyte3(p1 ^ b); 159 | auto idx3 = ubyte1(p1) ^ c + 0x200; 160 | auto idx1 = ubyte0(p1 ^ a) + 0x300; 161 | auto idx4 = d_idx + 0x100; /* 2nd byte of p1 is discarded for static obfuscation key :( */ 162 | 163 | auto dta = dyn_table_r.get(idx1); 164 | auto dtb = dyn_table_r.get(idx2); 165 | auto dtc = dyn_table_r.get(idx3); 166 | auto dtd = dyn_table_r.get(idx4); 167 | auto mixed = (dta ^ dtb ^ dtc ^ dtd); 168 | auto inverted = ~mixed; 169 | auto remainder = inverted % 0x2B; 170 | return remainder; 171 | } 172 | 173 | uint64_t inline decrypt_p21(int64_t left, int64_t right) { 174 | uint64_t dec = decrypt_p20(left, right, 0xBC, 0xD7AF5ABC, 0x5A, 0xAF); 175 | return dec; 176 | } 177 | 178 | uint64_t inline decrypt_p22(int64_t left, int64_t right) { 179 | uint64_t dec = decrypt_p20(left, right, 0xC, 0x5CE7E30Cu, 0xE3, 0xE7); 180 | return dec; 181 | } 182 | 183 | struct EncryptedBlock { 184 | int64_t data[48]; 185 | }; 186 | 187 | template 188 | T decrypt_ptr(EncryptedBlock *block) { 189 | auto a = block->data[decrypt_p21(block->data[44], block->data[45])]; 190 | auto b = decrypt_p22(block->data[46], block->data[47]); 191 | return (T)(a ^ b); 192 | }; 193 | 194 | 195 | 196 | class TSLEncryptedPointer 197 | { 198 | private: 199 | uint64_t encrypted_pointers[44]; 200 | uint16_t encrypted_index1; 201 | uint8_t pad0[6]; 202 | uint16_t encrypted_index2; 203 | uint8_t pad1[6]; 204 | uint16_t encrypted_xor1; 205 | uint8_t pad2[6]; 206 | uint16_t encrypted_xor2; 207 | uint8_t pad3[6]; 208 | 209 | 210 | uint16_t DecryptWord(uint8_t* table8, uint16_t word) 211 | { 212 | for (int i = 0; i < 5; i++) 213 | { 214 | word = table8[table8[(word & 0xFF) ^ 0x55]] << 0x08 | table8[table8[(word >> 0x08) ^ 0x44]]; 215 | } 216 | 217 | return word; 218 | } 219 | 220 | uint32_t DecryptDword(uint32_t* table32, uint32_t dword) 221 | { 222 | uint32_t xor = 0; 223 | xor ^= table32[((dword >> 0x00) & 0xFF) + 0x300]; 224 | xor ^= table32[((dword >> 0x08) & 0xFF) + 0x200]; 225 | xor ^= table32[((dword >> 0x10) & 0xFF) + 0x100]; 226 | xor ^= table32[((dword >> 0x18) & 0xFF) + 0x000]; 227 | return ~xor; 228 | } 229 | 230 | uint64_t DecryptIndex(uint32_t* table32, uint8_t* table8) 231 | { 232 | uint32_t temp = DecryptWord(table8, ~encrypted_index1 ^ encrypted_index2 ^ 0x0D25); 233 | 234 | temp ^= 0xD7AF5ABC; 235 | temp = DecryptDword(table32, temp); 236 | 237 | return temp % 0x2B; 238 | } 239 | 240 | uint64_t DecryptXor(uint32_t* table32, uint8_t* table8) 241 | { 242 | uint32_t temp = DecryptWord(table8, ~encrypted_xor1 ^ encrypted_xor2 ^ 0x0D25); 243 | 244 | temp ^= 0x5CE7E30C; 245 | temp = DecryptDword(table32, temp); 246 | 247 | return temp % 0x2B; 248 | } 249 | 250 | public: 251 | uint64_t Decrypt(uint32_t* table32, uint8_t* table8) 252 | { 253 | uint64_t index = DecryptIndex(table32, table8); 254 | uint64_t pointer = encrypted_pointers[index]; 255 | uint64_t xor = DecryptXor(table32, table8); 256 | 257 | return pointer ^ xor; 258 | } 259 | }; 260 | -------------------------------------------------------------------------------- /LambseaLoader/LambseaLib.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | {4978F2E2-D242-4D82-931C-F65028592DD4} 39 | Win32Proj 40 | LambseaLib 41 | 8.1 42 | LambseaLoader 43 | 44 | 45 | 46 | DynamicLibrary 47 | true 48 | v140 49 | Unicode 50 | 51 | 52 | DynamicLibrary 53 | false 54 | v140 55 | true 56 | Unicode 57 | 58 | 59 | DynamicLibrary 60 | true 61 | v140 62 | Unicode 63 | 64 | 65 | Application 66 | false 67 | v140 68 | true 69 | Unicode 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | true 91 | 92 | 93 | true 94 | 95 | 96 | false 97 | 98 | 99 | false 100 | $(SolutionDir)Bin\$(Platform)\$(Configuration)\ 101 | $(SolutionDir)Build\$(Platform)\$(Configuration)\$(ProjectName)\ 102 | 103 | 104 | 105 | 106 | 107 | Level3 108 | Disabled 109 | WIN32;_DEBUG;_WINDOWS;_USRDLL;LAMBSEALIB_EXPORTS;%(PreprocessorDefinitions) 110 | 111 | 112 | Windows 113 | true 114 | 115 | 116 | 117 | 118 | 119 | 120 | Level3 121 | Disabled 122 | _DEBUG;_WINDOWS;_USRDLL;LAMBSEALIB_EXPORTS;%(PreprocessorDefinitions) 123 | 124 | 125 | Windows 126 | true 127 | 128 | 129 | 130 | 131 | Level3 132 | 133 | 134 | MaxSpeed 135 | true 136 | true 137 | WIN32;NDEBUG;_WINDOWS;_USRDLL;LAMBSEALIB_EXPORTS;%(PreprocessorDefinitions) 138 | 139 | 140 | Windows 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | Level3 149 | 150 | 151 | Full 152 | true 153 | true 154 | NDEBUG;_WINDOWS;_USRDLL;LAMBSEALIB_EXPORTS;%(PreprocessorDefinitions) 155 | Speed 156 | CompileAsCpp 157 | MultiThreaded 158 | false 159 | 160 | 161 | Console 162 | true 163 | true 164 | false 165 | UseLinkTimeCodeGeneration 166 | %(AdditionalDependencies) 167 | RequireAdministrator 168 | 169 | 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /lambsea/lambsea.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | D3D9Render 7 | 8 | 9 | Gamebase 10 | 11 | 12 | Mainroutine 13 | 14 | 15 | DriverLoader 16 | 17 | 18 | Helpers 19 | 20 | 21 | D3D11Render 22 | 23 | 24 | D3D11Render 25 | 26 | 27 | FW1Font 28 | 29 | 30 | FW1Font 31 | 32 | 33 | FW1Font 34 | 35 | 36 | FW1Font 37 | 38 | 39 | FW1Font 40 | 41 | 42 | FW1Font 43 | 44 | 45 | FW1Font 46 | 47 | 48 | FW1Font 49 | 50 | 51 | FW1Font 52 | 53 | 54 | FW1Font 55 | 56 | 57 | FW1Font 58 | 59 | 60 | FW1Font 61 | 62 | 63 | FW1Font 64 | 65 | 66 | FW1Font 67 | 68 | 69 | FW1Font 70 | 71 | 72 | FW1Font 73 | 74 | 75 | FW1Font 76 | 77 | 78 | FW1Font 79 | 80 | 81 | FW1Font 82 | 83 | 84 | FW1Font 85 | 86 | 87 | FW1Font 88 | 89 | 90 | FW1Font 91 | 92 | 93 | FW1Font 94 | 95 | 96 | FW1Font 97 | 98 | 99 | FW1Font 100 | 101 | 102 | 103 | 104 | 105 | 106 | DriverLoader 107 | 108 | 109 | DriverLoader 110 | 111 | 112 | D3D9Render 113 | 114 | 115 | Gamebase 116 | 117 | 118 | Helpers 119 | 120 | 121 | Memory 122 | 123 | 124 | Mainroutine 125 | 126 | 127 | Helpers 128 | 129 | 130 | Helpers 131 | 132 | 133 | Gamebase 134 | 135 | 136 | Helpers 137 | 138 | 139 | D3D11Render 140 | 141 | 142 | D3D11Render 143 | 144 | 145 | D3D11Render 146 | 147 | 148 | D3D11Render 149 | 150 | 151 | FW1Font 152 | 153 | 154 | FW1Font 155 | 156 | 157 | FW1Font 158 | 159 | 160 | FW1Font 161 | 162 | 163 | FW1Font 164 | 165 | 166 | FW1Font 167 | 168 | 169 | FW1Font 170 | 171 | 172 | FW1Font 173 | 174 | 175 | FW1Font 176 | 177 | 178 | FW1Font 179 | 180 | 181 | FW1Font 182 | 183 | 184 | FW1Font 185 | 186 | 187 | FW1Font 188 | 189 | 190 | FW1Font 191 | 192 | 193 | FW1Font 194 | 195 | 196 | FW1Font 197 | 198 | 199 | 200 | 201 | {e53b05fd-7b21-4b80-810c-c5eebd84798e} 202 | 203 | 204 | {c18192fe-a08c-4ae1-86e8-77bac05fb2cb} 205 | 206 | 207 | {8bee36bd-ff70-45a8-a312-f5be456513e2} 208 | 209 | 210 | {dbfd24ba-8268-45e6-8538-b04cf996f43d} 211 | 212 | 213 | {13834d82-3af4-4870-8a94-7474909d6a9e} 214 | 215 | 216 | {75015a94-30f8-47a4-99f6-d81a948340ec} 217 | 218 | 219 | {e0bdb251-dbb2-4f7f-ad73-0ca2649bdf0d} 220 | 221 | 222 | {0b0974a4-ce25-43c0-ace1-314490920f11} 223 | 224 | 225 | --------------------------------------------------------------------------------