Blame src/process/ntapi_tt_get_runtime_data.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
4256e2
/*  Copyright (C) 2013--2016  Z. Gilboa                 */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_memory.h>
dd89bb
#include <ntapi/nt_process.h>
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
dd89bb
#if defined (__NT32)
dd89bb
static wchar16_t runtime_arg[12] = {
dd89bb
	' ','-','r',' ',
dd89bb
	'i','n','t','e','g','r','a','l'};
dd89bb
#elif defined (__NT64)
dd89bb
static wchar16_t runtime_arg[20] = {
dd89bb
	' ','-','r',' ',
dd89bb
	'i','n','t','e','g','r','a','l',
dd89bb
	'-','r','u','n','t','i','m','e'};
dd89bb
#endif
dd89bb
dd89bb
int32_t __stdcall __ntapi_tt_get_runtime_data(
dd89bb
	__out		nt_runtime_data **	rtdata,
f7b999
	__in		wchar16_t **		wargv)
dd89bb
{
dd89bb
	int32_t				status;
dd89bb
	nt_process_parameters *		process_params;
f7b999
	wchar16_t *			addrarg;
dd89bb
	nt_runtime_data			buffer;
dd89bb
	nt_runtime_data *		prtdata;
dd89bb
	ntapi_internals *		__internals;
dd89bb
dd89bb
	/* init */
dd89bb
	__internals = __ntapi_internals();
dd89bb
dd89bb
	/* once? */
dd89bb
	if (__internals->rtdata) {
dd89bb
		*rtdata = __internals->rtdata;
dd89bb
		return NT_STATUS_SUCCESS;
dd89bb
	}
dd89bb
f7b999
	if (!(wargv = wargv ? wargv : __internals->ntapi_img_sec_bss->argv_envp_array))
dd89bb
		return NT_STATUS_INVALID_PARAMETER_2;
dd89bb
f7b999
	if (!wargv[1] || !wargv[2])
f7b999
		return NT_STATUS_MORE_PROCESSING_REQUIRED;
f7b999
dd89bb
	/* integral process? */
f7b999
	if ((wargv[1][0] == '-') && (wargv[1][1] == 'r') && (wargv[1][2] == 0))
f7b999
		addrarg = wargv[2];
f7b999
	else
f7b999
		return NT_STATUS_INVALID_PARAMETER;
dd89bb
f7b999
	if (!addrarg || wargv[3])
dd89bb
		status = NT_STATUS_INVALID_PARAMETER_MIX;
dd89bb
f7b999
	/* obtain pointer to data block */
dd89bb
	if ((status = __ntapi->tt_hex_utf16_to_uintptr(
f7b999
			addrarg,
dd89bb
			(uintptr_t *)&prtdata)))
dd89bb
		return status;
dd89bb
dd89bb
	if ((status = __ntapi->zw_read_virtual_memory(
dd89bb
			NT_CURRENT_PROCESS_HANDLE,
dd89bb
			prtdata,
dd89bb
			(char *)&buffer,
dd89bb
			sizeof(buffer),0)))
dd89bb
		return status;
dd89bb
7ddcea
	/* update state */
7ddcea
	prtdata->flags |= NT_RUNTIME_DATA_INTEGRAL_PROCESS;
7ddcea
dd89bb
	/* avoid confusion :-) */
dd89bb
	process_params = ((nt_peb *)pe_get_peb_address())->process_params;
dd89bb
dd89bb
	__ntapi->tt_memcpy_utf16(
dd89bb
		(wchar16_t *)pe_va_from_rva(
dd89bb
			process_params->command_line.buffer,
dd89bb
			process_params->command_line.strlen - sizeof(runtime_arg)),
dd89bb
		runtime_arg,
dd89bb
		sizeof(runtime_arg));
dd89bb
dd89bb
	*rtdata = prtdata;
dd89bb
dd89bb
	return NT_STATUS_SUCCESS;
dd89bb
}