Skip to content

Commit

Permalink
Merge pull request 'feat: writer' (#2) from dev into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tinysec committed Jun 27, 2023
2 parents 9f79d33 + 758c7bc commit 42896d1
Show file tree
Hide file tree
Showing 19 changed files with 991 additions and 167 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ _deps
/.idea
/bin
/.vs
/out
21 changes: 20 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ else ()

FetchContent_Declare(jsex
GIT_REPOSITORY ${GIT_REPO}
GIT_TAG autotag-20230616-092319
GIT_TAG autotag-20230627-075036
)

FetchContent_MakeAvailable(jsex)
Expand Down Expand Up @@ -189,6 +189,13 @@ bin2h(
VARIABLE_NAME "JSWD_BUILTIN_SCRIPT_PHYSICAL"
)

bin2h(
SOURCE_FILE "src/script/jswd/processor.js"
HEADER_FILE "${PROJECT_BINARY_DIR}/gen/script/processor.js.h"
VARIABLE_NAME "JSWD_BUILTIN_SCRIPT_PROCESSOR"
)


bin2h(
SOURCE_FILE "src/script/jswd/reader.js"
HEADER_FILE "${PROJECT_BINARY_DIR}/gen/script/reader.js.h"
Expand All @@ -201,6 +208,12 @@ bin2h(
VARIABLE_NAME "JSWD_BUILTIN_SCRIPT_REGISTER"
)

bin2h(
SOURCE_FILE "src/script/jswd/segment.js"
HEADER_FILE "${PROJECT_BINARY_DIR}/gen/script/segment.js.h"
VARIABLE_NAME "JSWD_BUILTIN_SCRIPT_SEGMENT"
)


bin2h(
SOURCE_FILE "src/script/jswd/symbol.js"
Expand All @@ -215,6 +228,12 @@ bin2h(
VARIABLE_NAME "JSWD_BUILTIN_SCRIPT_VIRTUAL"
)

bin2h(
SOURCE_FILE "src/script/jswd/writer.js"
HEADER_FILE "${PROJECT_BINARY_DIR}/gen/script/writer.js.h"
VARIABLE_NAME "JSWD_BUILTIN_SCRIPT_WRITER"
)


# ===============================================================================================
# test
Expand Down
20 changes: 8 additions & 12 deletions jstests/test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
const fmt = require("fmt");

const assert = require("assert");

const jswd = require("jswd");

const _ = require('underscore');
const dbgeng = require("dbgeng");

let int = require('integer').Uint64;
const fmt = require("fmt");

/**
*
* @param {Array<String>} argv
*/
function main(argv)
{
fmt.printf("argv[0] is %s\n", argv[0]);
const typing = require("typing");

fmt.printf( 'sizeof(nt!_UNICODE_STRING): %d\n' , jswd.sizeof('nt!_UNICODE_STRING') );

fmt.printf( 'fieldOffset(nt!_UNICODE_STRING , Buffer): %d\n' , jswd.fieldOffset('nt!_UNICODE_STRING' , 'Buffer') );
function main(argv)
{
fmt.printf( jswd.fieldOffset('_UNICODE_STRING' , 'Buffer') );


return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/binding/dbgeng/binding_data_spaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ _Ret_maybenull_ JsValueRef CALLBACK BindingDbgEng::ReadMsr(
hr = pthis->m_debugDataSpaces->ReadMsr(arg1Address , &value);
if ( !SUCCEEDED(hr) )
{
JsExThrowError("ReadMsr fail 0x%08X" , hr);
JsExThrowError("ReadMsr 0x%08X fail 0x%08X" , arg1Address , hr);
break ;
}

Expand Down Expand Up @@ -671,7 +671,7 @@ _Ret_maybenull_ JsValueRef CALLBACK BindingDbgEng::ReadVirtual(

if ( !SUCCEEDED(hr) )
{
JsExThrowError("ReadVirtual fail 0x%08X" , hr);
JsExThrowError("ReadVirtual 0x%X fail 0x%08X" , arg1Offset , hr);
break ;
}

Expand Down
6 changes: 6 additions & 0 deletions src/binding/dbgeng/binding_dbgeng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,12 @@ JsErrorCode BindingDbgEng::bindDebugDataSpaces()
break;
}

errorCode = this->bindRoutine("writePhysical", BindingDbgEng::WritePhysical);
if (JsNoError != errorCode)
{
break;
}

errorCode = this->bindRoutine("writeVirtual", BindingDbgEng::WriteVirtual);
if (JsNoError != errorCode)
{
Expand Down
12 changes: 12 additions & 0 deletions src/binding/dbgeng/binding_system_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ _Ret_maybenull_ JsValueRef CALLBACK BindingDbgEng::GetThreadIdByProcessor(

do
{
if ( argumentCount < 2 )
{
JsExThrowError("invalid argument cound %d" , argumentCount);
break;
}

errorCode = JsExAssumeUint32( arguments[1] , &arg1Processor );
if ( JsNoError != errorCode )
{
Expand Down Expand Up @@ -399,6 +405,12 @@ _Ret_maybenull_ JsValueRef CALLBACK BindingDbgEng::SetCurrentThreadId(

do
{
if ( argumentCount < 2 )
{
JsExThrowError("invalid argument cound %d" , argumentCount);
break;
}

errorCode = JsExAssumeUint64( arguments[1] , &arg1Id );
if ( JsNoError != errorCode )
{
Expand Down
12 changes: 12 additions & 0 deletions src/binding/dbgeng/binding_system_objects2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ _Ret_maybenull_ JsValueRef CALLBACK BindingDbgEng::SetImplicitProcessDataOffset(

do
{
if ( argumentCount < 2 )
{
JsExThrowError("invalid argument cound %d" , argumentCount);
break;
}

errorCode = JsExAssumeUint64( arguments[1] , &arg1Offset );
if ( JsNoError != errorCode )
{
Expand Down Expand Up @@ -164,6 +170,12 @@ _Ret_maybenull_ JsValueRef CALLBACK BindingDbgEng::SetImplicitThreadDataOffset(

do
{
if ( argumentCount < 2 )
{
JsExThrowError("invalid argument cound %d" , argumentCount);
break;
}

errorCode = JsExAssumeUint64( arguments[1] , &arg1Offset );
if ( JsNoError != errorCode )
{
Expand Down
50 changes: 49 additions & 1 deletion src/core/js_pod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@

#include <gen/script/module.js.h>


#include <gen/script/physical.js.h>

#include <gen/script/processor.js.h>

#include <gen/script/reader.js.h>

#include <gen/script/register.js.h>

#include <gen/script/segment.js.h>

#include <gen/script/symbol.js.h>

#include <gen/script/virtual.js.h>

#include <gen/script/physical.js.h>
#include <gen/script/writer.js.h>

#include "js_pod.h"

Expand Down Expand Up @@ -132,6 +139,15 @@ HRESULT JSPod::Initialize()
break ;
}

errorCode = this->m_builtin->RegisterSource(
"jswd/processor" ,
std::string( (const char*)JSWD_BUILTIN_SCRIPT_PROCESSOR , SIZEOF_JSWD_BUILTIN_SCRIPT_PROCESSOR )
);
if ( JsNoError != errorCode )
{
break ;
}

errorCode = this->m_builtin->RegisterSource(
"jswd/reader" ,
std::string( (const char*)JSWD_BUILTIN_SCRIPT_READER , SIZEOF_JSWD_BUILTIN_SCRIPT_READER )
Expand All @@ -146,6 +162,15 @@ HRESULT JSPod::Initialize()
std::string( (const char*)JSWD_BUILTIN_SCRIPT_REGISTER , SIZEOF_JSWD_BUILTIN_SCRIPT_REGISTER )
);
if ( JsNoError != errorCode )
{
break ;
}

errorCode = this->m_builtin->RegisterSource(
"jswd/segment" ,
std::string( (const char*)JSWD_BUILTIN_SCRIPT_SEGMENT , SIZEOF_JSWD_BUILTIN_SCRIPT_SEGMENT )
);
if ( JsNoError != errorCode )
{
break ;
}
Expand All @@ -159,6 +184,7 @@ HRESULT JSPod::Initialize()
break ;
}


errorCode = this->m_builtin->RegisterSource(
"jswd/virtual" ,
std::string( (const char*)JSWD_BUILTIN_SCRIPT_VIRTUAL , SIZEOF_JSWD_BUILTIN_SCRIPT_VIRTUAL )
Expand All @@ -168,6 +194,14 @@ HRESULT JSPod::Initialize()
break ;
}

errorCode = this->m_builtin->RegisterSource(
"jswd/writer" ,
std::string( (const char*)JSWD_BUILTIN_SCRIPT_WRITER , SIZEOF_JSWD_BUILTIN_SCRIPT_WRITER )
);
if ( JsNoError != errorCode )
{
break ;
}

errorCode = this->m_builtin->RegisterSource(
"jswd" ,
Expand Down Expand Up @@ -210,7 +244,11 @@ HRESULT JSPod::InitializeJSRT()

do
{
#ifdef _DEBUG
this->m_runtime = JsExCreateRuntime(true);
#else
this->m_runtime = JsExCreateRuntime(false);
#endif //#ifdef _DEBUG
if (nullptr == this->m_runtime)
{
break;
Expand All @@ -230,6 +268,8 @@ HRESULT JSPod::InitializeJSRT()
break;
}



this->m_binding = NativeBinding::Create();
if (nullptr == this->m_binding)
{
Expand Down Expand Up @@ -260,6 +300,14 @@ HRESULT JSPod::InitializeJSRT()
break;
}

#ifdef _DEBUG
errorCode = JsExEnableDebug();
if (JsNoError != errorCode)
{
break;
}
#endif // #ifdef _DEBUG

result = S_OK;
} while (false);

Expand Down
Loading

0 comments on commit 42896d1

Please sign in to comment.