-
Notifications
You must be signed in to change notification settings - Fork 0
/
00-native-starter.c
71 lines (60 loc) · 2.06 KB
/
00-native-starter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// native-starter.c
// Copyright (C) 2019 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>.
// This file is public domain software.
#define WIN32_NO_STATUS
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#define NTOS_MODE_USER
#include <ndk/iofuncs.h>
#include <ndk/rtlfuncs.h>
#include <ndk/mmfuncs.h>
#include <ndk/obfuncs.h>
#include <ndk/psfuncs.h>
#define NDEBUG
#include <debug.h>
BOOL CreateNativeProcess(LPCWSTR file_name, LPCWSTR cmd_line)
{
NTSTATUS status;
LPCWSTR file_part;
UNICODE_STRING nt_file, imgname, imgpath, dllpath, cmdline;
PRTL_USER_PROCESS_PARAMETERS processparameters;
RTL_USER_PROCESS_INFORMATION processinformation = {0};
WCHAR Env[2] = {0, 0};
RtlDosPathNameToNtPathName_U(file_name, &nt_file, &file_part, NULL);
RtlInitUnicodeString(&imgpath, nt_file.Buffer);
RtlInitUnicodeString(&imgname, file_part);
RtlInitUnicodeString(&dllpath, SharedUserData->NtSystemRoot);
RtlInitUnicodeString(&cmdline, cmd_line);
status = RtlCreateProcessParameters(&processparameters, &imgname,
&dllpath, &dllpath, &cmdline,
Env, 0, 0, 0, 0);
if (!NT_SUCCESS(status))
{
return FALSE;
}
status = RtlCreateUserProcess(&imgpath, OBJ_CASE_INSENSITIVE,
processparameters, NULL, NULL, NULL,
FALSE, NULL, NULL, &processinformation);
if (!NT_SUCCESS(status))
{
return FALSE;
}
status = NtResumeThread(processinformation.ThreadHandle, NULL);
if (!NT_SUCCESS(status))
{
return FALSE;
}
return TRUE;
}
int main(int argc, char **argv)
{
BOOL ret;
ANSI_STRING FileNameA;
UNICODE_STRING FileNameW;
RtlInitAnsiStringEx(&FileNameA, argv[1]);
RtlAnsiStringToUnicodeString(&FileNameW, &FileNameA, TRUE);
ret = CreateNativeProcess(FileNameW.Buffer, FileNameW.Buffer);
RtlFreeUnicodeString(&FileNameW);
return ret ? 0 : -1;
}