1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-10 21:33:38 +00:00

!. added buffer.randomFill()

2. Updated MSH_Installer to support trick mode
This commit is contained in:
Bryan Roe
2019-10-21 14:50:21 -07:00
parent df5b57174a
commit 012b11bcb8
2 changed files with 31 additions and 4 deletions

View File

@@ -79,6 +79,25 @@ duk_ret_t ILibDuktape_Pollyfills_Buffer_slice(duk_context *ctx)
memcpy_s(out, bufferLen, buffer + offset, bufferLen);
return 1;
}
duk_ret_t ILibDuktape_Polyfills_Buffer_randomFill(duk_context *ctx)
{
int start, length;
char *buffer;
duk_size_t bufferLen;
start = (int)(duk_get_top(ctx) == 0 ? 0 : duk_require_int(ctx, 0));
length = (int)(duk_get_top(ctx) == 2 ? duk_require_int(ctx, 1) : -1);
duk_push_this(ctx);
buffer = (char*)Duktape_GetBuffer(ctx, -1, &bufferLen);
if ((duk_size_t)length > bufferLen || length < 0)
{
length = (int)(bufferLen - start);
}
util_random(length, buffer + start);
return(0);
}
duk_ret_t ILibDuktape_Polyfills_Buffer_toString(duk_context *ctx)
{
int nargs = duk_get_top(ctx);
@@ -290,6 +309,8 @@ void ILibDuktape_Polyfills_Buffer(duk_context *ctx)
duk_get_prop_string(ctx, -1, "prototype"); // [g][Buffer][prototype]
duk_push_c_function(ctx, ILibDuktape_Polyfills_Buffer_toString, DUK_VARARGS); // [g][Buffer][prototype][func]
duk_put_prop_string(ctx, -2, "toString"); // [g][Buffer][prototype]
duk_push_c_function(ctx, ILibDuktape_Polyfills_Buffer_randomFill, DUK_VARARGS); // [g][Buffer][prototype][func]
duk_put_prop_string(ctx, -2, "randomFill"); // [g][Buffer][prototype]
duk_pop_2(ctx); // [g]
}
duk_ret_t ILibDuktape_Polyfills_String_startsWith(duk_context *ctx)

View File

@@ -41,7 +41,7 @@ function addMsh(options)
// Try to determine what the platform is
try
{
options.peinfo = require('PE_Parser')(options.sourcePath);
options.peinfo = require('PE_Parser')(options.sourceFileName);
options.platform = 'win32';
}
catch(e)
@@ -58,7 +58,7 @@ function addMsh(options)
if(!options.peinfo)
{
// We need to parse the PE headers first
options.peinfo = require('PE_Parser')(options.sourcePath);
options.peinfo = require('PE_Parser')(options.sourceFileName);
}
}
@@ -75,7 +75,10 @@ function addMsh(options)
var sz = Buffer.alloc(4);
sz.writeUInt32BE(this.options.msh.length, 0);
this.options.destinationStream.write(sz); // Length in small endian
this.options.destinationStream.write(Buffer.from(exeMeshPolicyGuid, 'hex'), function () { this.end(); }); // GUID
var mshBuf = Buffer.from(exeMeshPolicyGuid, 'hex');
if (this.options.randomGuid) { mshBuf.randomFill(); }
this.options.destinationStream.write(mshBuf, function () { this.end(); }); // GUID
});
// Pipe the entire source binary without ending the stream.
options.destinationStream.sourceStream.pipe(options.destinationStream, { end: false });
@@ -131,7 +134,10 @@ function addMsh(options)
var sz = Buffer.alloc(4);
sz.writeUInt32BE(this.options.msh.length, 0);
this.options.destinationStream.write(sz); // MSH Length, small-endian
this.options.destinationStream.write(Buffer.from(exeMeshPolicyGuid, 'hex'), function () { this.end(); }); // MSH GUID
var mshBuf = Buffer.from(exeMeshPolicyGuid, 'hex');
if (this.options.randomGuid) { mshBuf.randomFill(); }
this.options.destinationStream.write(mshBuf, function () { this.end(); }); // GUID
});
source3.pipe(this.options.destinationStream, { end: false });
this.options.sourceStream = source3;