Skip to content

Commit

Permalink
1.0.1.0
Browse files Browse the repository at this point in the history
fix Runtime Error Printing for Linux
fix setString
  • Loading branch information
karikera committed Jan 28, 2021
1 parent b3617ea commit 5c6b238
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 72 deletions.
2 changes: 0 additions & 2 deletions bdsx/bdsx.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ echo #define BUILD_TIME "%25date%-%time2:.=%"&gt;"gen/buildtime.h"</Command>
<ClCompile Include="uvasync.cpp" />
<ClCompile Include="structurepointer.cpp" />
<ClCompile Include="cachedpdb.cpp" />
<ClCompile Include="iatdll.cpp" />
<ClCompile Include="encoding.cpp" />
<ClCompile Include="sehandler.cpp" />
<ClCompile Include="voidpointer.cpp" />
Expand All @@ -168,7 +167,6 @@ echo #define BUILD_TIME "%25date%-%time2:.=%"&gt;"gen/buildtime.h"</Command>
<ClInclude Include="uvasync.h" />
<ClInclude Include="structurepointer.h" />
<ClInclude Include="cachedpdb.h" />
<ClInclude Include="iatdll.h" />
<ClInclude Include="encoding.h" />
<ClInclude Include="sehandler.h" />
<ClInclude Include="voidpointer.h" />
Expand Down
2 changes: 0 additions & 2 deletions bdsx/bdsx.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<ClCompile Include="encoding.cpp" />
<ClCompile Include="nodegate.cpp" />
<ClCompile Include="stdafx.cpp" />
<ClCompile Include="iatdll.cpp" />
<ClCompile Include="netfilter.cpp" />
<ClCompile Include="makefunc.cpp" />
<ClCompile Include="jshook.cpp" />
Expand All @@ -27,7 +26,6 @@
<ClInclude Include="encoding.h" />
<ClInclude Include="nodegate.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="iatdll.h" />
<ClInclude Include="netfilter.h" />
<ClInclude Include="makefunc.h" />
<ClInclude Include="jshook.h" />
Expand Down
19 changes: 0 additions & 19 deletions bdsx/iatdll.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions bdsx/iatdll.h

This file was deleted.

23 changes: 12 additions & 11 deletions bdsx/jshook.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "stdafx.h"
#include "jshook.h"

#include "iatdll.h"
#include "jsctx.h"

#include <KRWin/hook.h>
#include <KRWin/handle.h>
#include <KR3/util/wide.h>
#include <KR3/parser/jsonparser.h>

Expand Down Expand Up @@ -171,16 +171,17 @@ namespace
{
s_field->onError = onError;

g_iat.chakra.hooking("JsCreateContext", JsCreateContextHook);
g_iat.chakra.hooking("JsSetCurrentContext", JsSetCurrentContextHook);
g_iat.chakra.hooking("JsCreateRuntime", JsCreateRuntimeHook);
g_iat.chakra.hooking("JsDisposeRuntime", JsDisposeRuntimeHook);
g_iat.chakra.hooking("JsRunScript", JsRunScriptHook);
g_iat.chakra.hooking("JsCallFunction", JsCallFunctionHook);
g_iat.chakra.hooking("JsStartDebugging", JsStartDebuggingHook);
g_iat.chakra.hooking("JsSetPromiseContinuationCallback", JsSetPromiseContinuationCallbackHook);
kr::hook::IATModule chakra(win::Module::current(), "chakra.dll");
chakra.hooking("JsCreateContext", JsCreateContextHook);
chakra.hooking("JsSetCurrentContext", JsSetCurrentContextHook);
chakra.hooking("JsCreateRuntime", JsCreateRuntimeHook);
chakra.hooking("JsDisposeRuntime", JsDisposeRuntimeHook);
chakra.hooking("JsRunScript", JsRunScriptHook);
chakra.hooking("JsCallFunction", JsCallFunctionHook);
chakra.hooking("JsStartDebugging", JsStartDebuggingHook);
chakra.hooking("JsSetPromiseContinuationCallback", JsSetPromiseContinuationCallbackHook);
#ifndef NDEBUG
g_iat.chakra.hooking("JsSetProperty", JsSetPropertyHook);
chakra.hooking("JsSetProperty", JsSetPropertyHook);
#endif
}

Expand Down
14 changes: 8 additions & 6 deletions bdsx/netfilter.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "stdafx.h"
#include "netfilter.h"

#include "iatdll.h"
#include "nodegate.h"
#include "jsctx.h"

#include <WinSock2.h>

#include <KRWin/hook.h>
#include <KRWin/handle.h>
#include <KR3/data/set.h>
#include <KR3/mt/criticalsection.h>
#include <KR3/win/windows.h>
Expand Down Expand Up @@ -279,11 +280,12 @@ void NetFilter::init(JsValue callbackOnExceeded) noexcept
{
s_field->callbackOnExceeded = callbackOnExceeded;

g_iat.ws2_32.hooking(2, bindHook);
g_iat.ws2_32.hooking(3, closesocketHook);
g_iat.ws2_32.hooking(17, recvfromHook);
g_iat.ws2_32.hooking(20, sendtoHook);
g_iat.ws2_32.hooking(116, WSACleanupHook);
hook::IATModule ws2_32(win::Module::current(), "WS2_32.dll");
ws2_32.hooking(2, bindHook);
ws2_32.hooking(3, closesocketHook);
ws2_32.hooking(17, recvfromHook);
ws2_32.hooking(20, sendtoHook);
ws2_32.hooking(116, WSACleanupHook);
}

bool NetFilter::addFilter(kr::Ipv4Address ip, time_t endTime) noexcept
Expand Down
45 changes: 38 additions & 7 deletions bdsx/sehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <KR3/mt/criticalsection.h>
#include <KR3/util/StackWalker.h>
#include <KR3/util/pdb.h>
#include <KRWin/handle.h>

using namespace kr;

Expand Down Expand Up @@ -110,19 +111,51 @@ kr::Text16 runtimeError::codeToString(unsigned int errorCode) noexcept

int runtimeError::raise(EXCEPTION_POINTERS* exptr) noexcept
{
ondebug(requestDebugger());
debug();
static DWORD raising = 0;
if (raising != 0) Sleep(INFINITE);
DWORD threadId = raising = GetCurrentThreadId();

#ifndef NDEBUG
{
DWORD64 rip = exptr->ContextRecord->Rip;
unsigned int code = exptr->ExceptionRecord->ExceptionCode;
cout << "ExceptionCode: " << hexf(code, 8) << endl;
cout << "Thread Id: " << threadId << endl;
cout << "rip: 0x" << hexf(rip, 16) << endl;

MEMORY_BASIC_INFORMATION mbi;
if (VirtualQuery((void*)(uintptr_t)rip, &mbi, sizeof(mbi)))
{
win::Module* mod = (win::Module*)mbi.AllocationBase;

TSZ16 filename;
filename << mod->fileName();
Text16 basename = path16.basename(filename);
if (!basename.empty())
{
cout << "rip RVA: " << (Utf16ToUtf8)basename << "+0x" << hexf(rip - (uintptr_t)mod) << endl;
}
else
{

cout << "rip RVA: [0x" << hexf((uintptr_t)mod) << "]+0x" << hexf(rip - (uintptr_t)mod) << endl;
}
}
}

if (requestDebugger())
{
debug();
}
#endif


for (;;)
{
DWORD threadId;
try
{
if (s_nativeErrorCode != 0) break;

unsigned int code = exptr->ExceptionRecord->ExceptionCode;
threadId = GetCurrentThreadId();

AText16 stack = getStack(exptr);
if (stack.endsWith('\n')) stack.pop();
Expand All @@ -135,8 +168,6 @@ int runtimeError::raise(EXCEPTION_POINTERS* exptr) noexcept
}
catch (...)
{
threadId = GetCurrentThreadId();

CsLock lock = s_stackLock;
s_nativeErrorCode = -1;
s_nativeExceptionStack = u"[[setRuntimeException, Invalid EXCEPTION_POINTERS]]";
Expand Down
29 changes: 22 additions & 7 deletions bdsx/staticpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,17 @@ void StaticPointer::setPointer(VoidPointer* v, int offset) throws(JsException)
{
return _setas(v != nullptr ? v->getAddressRaw() : nullptr, offset);
}
void StaticPointer::setString(JsValue buffer, int offset, int encoding) throws(JsException)
int StaticPointer::setString(JsValue buffer, int offset, int encoding) throws(JsException)
{
if (encoding == ExEncoding::UTF16)
{
Text16 text = buffer.cast<Text16>();
pstr16 str = (pstr16)(m_address + offset);
try
{
size_t size = text.size();
memcpy(str, text.data(), size);
size_t bytes = text.bytes();
memcpy(str, text.data(), bytes + sizeof(char16_t));
return (int)bytes;
}
catch (...)
{
Expand All @@ -345,12 +346,25 @@ void StaticPointer::setString(JsValue buffer, int offset, int encoding) throws(J
}
else if (encoding == ExEncoding::BUFFER)
{
setBuffer(buffer, offset);
void* p = m_address + offset;
Buffer buf = buffer.getBuffer();
if (buf == nullptr) throw JsException(u"argument must be buffer");
try
{
size_t size = buf.size();
memcpy(p, buf.data(), size);
((char*)p)[size] = '\0';
return (int)size;
}
catch (...)
{
accessViolation(p);
}
}
else
{
Text16 text = buffer.cast<Text16>();
pstr16 str = (pstr16)(m_address + offset);
pstr str = (pstr)(m_address + offset);
try
{
TSZ mb;
Expand All @@ -360,8 +374,9 @@ void StaticPointer::setString(JsValue buffer, int offset, int encoding) throws(J
);

size_t size = mb.size();
memcpy(m_address, mb.data(), size);
m_address += size;
memcpy(str, mb.data(), size);
str[size] = '\0';
return (int)size;
}
catch (...)
{
Expand Down
2 changes: 1 addition & 1 deletion bdsx/staticpointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class StaticPointer :public kr::JsObjectT<StaticPointer, VoidPointer>
void setFloat32(float v, int offset) throws(kr::JsException);
void setFloat64(double v, int offset) throws(kr::JsException);
void setPointer(VoidPointer* v, int offset) throws(kr::JsException);
void setString(kr::JsValue buffer, int offset, int encoding) throws(kr::JsException);
int setString(kr::JsValue buffer, int offset, int encoding) throws(kr::JsException);
void setBuffer(kr::JsValue buffer, int offset) throws(kr::JsException);
void setCxxString(kr::Text16 text, int offset, int encoding) throws(kr::JsException);

Expand Down
2 changes: 1 addition & 1 deletion bdsx/version.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

set BDSX_CORE_VERSION=1.0.0.5
set BDSX_CORE_VERSION=1.0.1.0

0 comments on commit 5c6b238

Please sign in to comment.