Skip to content

Commit 6deb4ff

Browse files
amdfMattiwatti
authored andcommitted
x64 compat (amdf#6)
* ignore * small header * remove crashes * fix launch process x64 * hint * debug hw tree * workflow
1 parent 1615380 commit 6deb4ff

File tree

10 files changed

+106
-100
lines changed

10 files changed

+106
-100
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ objfre_wxp_x86
44
objfre_win7_amd64
55
*.err
66
*.wrn
7+
*.cmd
78

89

910
# Matti

file.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,11 @@ NTSTATUS RtlCliSetCurrentDirectory(PCHAR Directory)
8282
return STATUS_SUCCESS;
8383
}
8484

85-
GetFullPath(Directory, buf, TRUE);
86-
RtlInitUnicodeString(&us, buf);
87-
RtlSetCurrentDirectory_U(&us);
88-
RtlFreeUnicodeString(&us);
85+
GetFullPath(Directory, buf, TRUE);
86+
RtlInitUnicodeString(&us, buf);
87+
RtlSetCurrentDirectory_U(&us);
8988

90-
return STATUS_SUCCESS;
89+
return STATUS_SUCCESS;
9190
}
9291

9392
/*++

hardware.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,15 @@ RtlCliListHardwareTree(VOID)
234234
// Get the root node's child
235235
//
236236
Status = RtlCliGetChildOrSibling(ROOT_NAME, Buffer, PNP_GET_CHILD_DEVICE);
237-
237+
if (!NT_SUCCESS(Status)) {
238+
RtlCliDisplayString("NtPlugPlayControl get root node failed.\n");
239+
}
238240
//
239241
// Now get the entire tree
240242
//
241243
Status = RtlCliListSubNodes(ROOT_NAME, NULL, Buffer);
244+
if (!NT_SUCCESS(Status)) {
245+
RtlCliDisplayString("NtPlugPlayControl get child nodes failed.\n");
246+
}
242247
return Status;
243248
}

main.c

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ HANDLE hKey;
3535

3636
#define __APP_VER__ "0.13.2"
3737
#if defined(_M_AMD64)
38-
#define __NCLI_VER__ __APP_VER__ " (x64)"
38+
#define __NCLI_VER__ __APP_VER__ " x64"
3939
#elif defined(_M_IX86)
40-
#define __NCLI_VER__ __APP_VER__ " (x86)"
40+
#define __NCLI_VER__ __APP_VER__ " x86"
4141
#elif defined(_M_ARM)
42-
#define __NCLI_VER__ __APP_VER__ " (ARM)"
42+
#define __NCLI_VER__ __APP_VER__ " ARM"
4343
#elif defined(_M_ARM64)
44-
#define __NCLI_VER__ __APP_VER__ " (ARM64)"
44+
#define __NCLI_VER__ __APP_VER__ " ARM64"
4545
#endif
4646

4747
WCHAR *helpstr[] =
@@ -337,36 +337,33 @@ VOID RtlClipProcessMessage(PCHAR Command)
337337
//
338338

339339
WCHAR filename[MAX_PATH];
340-
HANDLE hProcess;
340+
HANDLE hProcess = NULL;
341341

342342
GetFullPath(IN xargv[1], OUT filename, FALSE);
343343

344344
if (FileExists(filename))
345345
{
346346
ANSI_STRING as;
347347
UNICODE_STRING us;
348+
RtlInitAnsiString(&as, Command);
349+
RtlAnsiStringToUnicodeString(&us, &as, TRUE);
350+
351+
NtClose(hKeyboard);
348352

349353
RtlInitAnsiString(&as, Command);
350354
RtlAnsiStringToUnicodeString(&us, &as, TRUE);
351355

352-
NtClose(hKeyboard);
353-
//RtlCliDisplayString("Keyboard is closed\n");
356+
RtlFreeUnicodeString(&us);
354357

355-
CreateNativeProcess(filename, us.Buffer, &hProcess);
356-
357-
RtlFreeAnsiString(&as);
358-
RtlFreeUnicodeString(&us);
359-
360-
//RtlCliDisplayString("Waiting for process terminations\n");
361-
NtWaitForSingleObject(hProcess, FALSE, NULL);
362-
363-
RtlCliOpenInputDevice(&hKeyboard, KeyboardType);
364-
//RtlCliDisplayString("Keyboard restored\n");
365-
}
366-
else
358+
NtWaitForSingleObject(hProcess, FALSE, NULL); // Matti: how can this possibly ever do anything but return STATUS_INVALID_HANDLE? hProcess isn't initialized
359+
360+
RtlCliOpenInputDevice(&hKeyboard, KeyboardType);
361+
} else
367362
{
368-
RtlCliDisplayString("%s not recognized\n", Command);
369-
}
363+
RtlCliDisplayString("%s not recognized\n"
364+
"Add .exe if you want to lauch executable file."
365+
"\nType \"help\" for the list of commands.\n", Command);
366+
}
370367
}
371368
}
372369

@@ -442,10 +439,7 @@ NTSTATUS NTAPI NtProcessStartup(PPEB Context)
442439

443440
//
444441
// Show banner
445-
RtlCliDisplayString("Native Shell [Version " __NCLI_VER__ "] (" __DATE__ " " __TIME__ ")\n");
446-
RtlCliDisplayString("(C) Copyright 2010-2025 amdf, 2021-2025 Matti\n");
447-
RtlCliDisplayString("(C) Copyright 2006 TinyKRNL Project\n\n");
448-
RtlCliDisplayString("Type \"help\".\n\n");
442+
RtlCliDisplayString("Native Shell v" __NCLI_VER__ " (" __DATE__ " " __TIME__ ")\n\n");
449443

450444
while (!hKeyboard || !NT_SUCCESS(Status))
451445
{

ndk/mmtypes.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -349,34 +349,36 @@ typedef struct _SECTION_IMAGE_INFORMATION
349349
};
350350
ULONG SubSystemVersion;
351351
};
352-
ULONG GpValue;
352+
union
353+
{
354+
struct
355+
{
356+
USHORT MajorOperatingSystemVersion;
357+
USHORT MinorOperatingSystemVersion;
358+
};
359+
ULONG OperatingSystemVersion;
360+
};
353361
USHORT ImageCharacteristics;
354362
USHORT DllCharacteristics;
355363
USHORT Machine;
356364
BOOLEAN ImageContainsCode;
357-
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
358365
union
359366
{
367+
UCHAR ImageFlags;
360368
struct
361369
{
362-
UCHAR ComPlusNativeReady:1;
363-
UCHAR ComPlusILOnly:1;
364-
UCHAR ImageDynamicallyRelocated:1;
365-
UCHAR ImageMappedFlat:1;
366-
UCHAR Reserved:4;
370+
UCHAR ComPlusNativeReady : 1;
371+
UCHAR ComPlusILOnly : 1;
372+
UCHAR ImageDynamicallyRelocated : 1;
373+
UCHAR ImageMappedFlat : 1;
374+
UCHAR BaseBelow4gb : 1;
375+
UCHAR ComPlusPrefer32bit : 1;
376+
UCHAR Reserved : 2;
367377
};
368-
UCHAR ImageFlags;
369378
};
370-
#else
371-
BOOLEAN Spare1;
372-
#endif
373379
ULONG LoaderFlags;
374380
ULONG ImageFileSize;
375-
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
376381
ULONG CheckSum;
377-
#else
378-
ULONG Reserved[1];
379-
#endif
380382
} SECTION_IMAGE_INFORMATION, *PSECTION_IMAGE_INFORMATION;
381383

382384
#ifndef NTOS_MODE_USER

ntfile.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,8 @@ BOOLEAN NtFileDeleteFile(PWSTR filename)
312312

313313
status = NtDeleteFile(&oa);
314314

315-
RtlFreeUnicodeString(&us);
316315

317-
return NT_SUCCESS(status);
316+
return NT_SUCCESS(status);
318317
}
319318

320319
BOOLEAN NtFileCreateDirectory(PWSTR dirname)
@@ -346,12 +345,11 @@ BOOLEAN NtFileCreateDirectory(PWSTR dirname)
346345
0
347346
);
348347

349-
if (NT_SUCCESS(status))
350-
{
351-
NtClose(hFile);
352-
RtlFreeUnicodeString(&us);
353-
return TRUE;
354-
}
348+
if (NT_SUCCESS(status))
349+
{
350+
NtClose(hFile);
351+
return TRUE;
352+
}
355353

356354
/* if it already exists then return success */
357355
if (status == STATUS_OBJECT_NAME_COLLISION)
@@ -360,8 +358,7 @@ BOOLEAN NtFileCreateDirectory(PWSTR dirname)
360358
return TRUE;
361359
}
362360

363-
RtlFreeUnicodeString(&us);
364-
return FALSE;
361+
return FALSE;
365362
}
366363

367364
/*
@@ -446,10 +443,14 @@ BOOLEAN NtFileMoveFile(IN PWSTR lpExistingFileName, IN PWSTR lpNewFileName, BOOL
446443
FileRenameInfo,
447444
sizeof(FILE_RENAME_INFORMATION)+FileNameSize,
448445
FileRenameInformation );
446+
if (!NT_SUCCESS(Status))
447+
{
448+
RtlCliDisplayString("NtSetInformationFile(FileRenameInformation) failed (Status %lx)\n", Status);
449+
}
449450

450451
RtlFreeHeap(RtlGetProcessHeap(), 0, FileRenameInfo);
451452

452453
NtClose(FileHandle);
453454

454-
return TRUE;
455+
return NT_SUCCESS(Status);
455456
}

precomp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ NTSTATUS RegReadValue(HANDLE hKey, PWCHAR key_name, OUT PULONG type, OUT PVOID d
230230

231231
// Misc
232232

233-
void FillUnicodeStringWithAnsi(OUT PUNICODE_STRING us, IN PCHAR as);
233+
// void FillUnicodeStringWithAnsi(OUT PUNICODE_STRING us, IN PCHAR as);
234234

235235
//===========================================================
236236
//

process.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,25 @@ NTSTATUS CreateNativeProcess(IN PWSTR file_name, IN PWSTR cmd_line, OUT PHANDLE
3535

3636
status = RtlCreateProcessParameters(&processparameters, &imgname, &dllpath, &dllpath, &cmdline, Env, 0, 0, 0, 0);
3737

38-
if (processinformation.ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_NATIVE)
39-
{
40-
RtlCliDisplayString("\nThe %S application cannot be run in native mode.\n", file_name);
41-
return STATUS_UNSUCCESSFUL;
42-
}
43-
44-
if (!NT_SUCCESS(status))
45-
{
46-
RtlCliDisplayString("RtlCreateProcessParameters failed\n");
47-
return status;
48-
}
49-
50-
status = NtResumeThread(processinformation.ThreadHandle, NULL);
51-
if (!NT_SUCCESS(status))
52-
{
53-
RtlCliDisplayString("NtResumeThread failed\n");
54-
return status;
55-
}
38+
if (!NT_SUCCESS(status))
39+
{
40+
RtlCliDisplayString("RtlCreateProcessParameters failed\n");
41+
return status;
42+
}
43+
44+
if (processinformation.ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_NATIVE)
45+
{
46+
RtlCliDisplayString("\nThe %S application cannot be run in native mode.\n"
47+
"Subsystem: %d\n"
48+
"Subsystem version: %d\n"
49+
"Machine: %d\n",
50+
file_name,
51+
processinformation.ImageInformation.SubSystemType,
52+
processinformation.ImageInformation.SubSystemVersion,
53+
processinformation.ImageInformation.Machine
54+
);
55+
return STATUS_UNSUCCESSFUL;
56+
}
5657

5758
Printf("Launching Process: %ls, DllPath = %ls, CmdLine = %ls\n", imgname.Buffer, dllpath.Buffer, cmdline.Buffer);
5859

shell.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ BOOL GetFullPath(IN PSTR filename, OUT PWSTR out, IN BOOL add_slash)
6868
}
6969

7070
RtlFreeUnicodeString(&us);
71-
RtlFreeAnsiString(&as);
7271
}
7372
else
7473
{
@@ -90,10 +89,10 @@ BOOL GetFullPath(IN PSTR filename, OUT PWSTR out, IN BOOL add_slash)
9089
}
9190

9291
RtlFreeUnicodeString(&us);
93-
RtlFreeAnsiString(&as);
9492
}
9593

96-
return TRUE;
94+
RtlFreeUnicodeString(&us);
95+
return TRUE;
9796
}
9897

9998
// Argument processing functions:
@@ -217,7 +216,6 @@ BOOL FolderExists(PWSTR foldername)
217216

218217
RtlInitUnicodeString(&u_filename, foldername);
219218
RtlDosPathNameToNtPathName_U(u_filename.Buffer, &nt_filename, NULL, NULL);
220-
RtlFreeUnicodeString(&u_filename);
221219

222220
InitializeObjectAttributes(&oa, &nt_filename, OBJ_CASE_INSENSITIVE, 0, 0);
223221
st = NtQueryAttributesFile(&oa, &fbi);
@@ -256,8 +254,6 @@ BOOL FileExists(PWSTR filename)
256254

257255
st = NtQueryAttributesFile(&oa, &fbi);
258256

259-
RtlFreeUnicodeString(&nt_filename);
260-
261257
return NT_SUCCESS(st);
262258
}
263259

@@ -357,17 +353,18 @@ ULONG GetStringLength(WCHAR* pszInput)
357353
}
358354

359355
// Note: This function allocates memory for "us" variable.
360-
VOID FillUnicodeStringWithAnsi(OUT PUNICODE_STRING us, IN PCHAR as)
361-
{
362-
ANSI_STRING ansi_string;
356+
// void FillUnicodeStringWithAnsi(OUT PUNICODE_STRING us, IN PCHAR as)
357+
// {
358+
// ANSI_STRING ansi_string;
363359

364-
RtlInitAnsiString(&ansi_string, as);
360+
// RtlInitAnsiString(&ansi_string, as);
365361

366-
if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(us, &ansi_string, TRUE)))
367-
{
368-
RtlCliDisplayString("RtlAnsiStringToUnicodeString() failed\n");
369-
return;
370-
}
362+
// if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(us, &ansi_string, TRUE)))
363+
// {
364+
// RtlCliDisplayString("RtlAnsiStringToUnicodeString() failed\n");
365+
// return;
366+
// }
371367

372-
RtlFreeAnsiString(&ansi_string);
373-
}
368+
// RtlFreeAnsiString(&ansi_string);
369+
// return;
370+
// }

sysinfo.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,19 @@ RtlCliDumpSysInfo(VOID)
468468
//
469469
// Display FileSystem Cache Information
470470
//
471-
RtlCliDisplayString("[CACHE] Size: %ldKB. Peak: %ldKB. "
472-
"Min WS: %ldKB. Max WS: %ldKB\n",
473-
(ULONG)CacheInfo.CurrentSize / 1024,
474-
(ULONG)CacheInfo.PeakSize / 1024,
475-
(ULONG)CacheInfo.MinimumWorkingSet,
476-
(ULONG)CacheInfo.MaximumWorkingSet);
477-
471+
Status = NtQuerySystemInformation(SystemFileCacheInformation,
472+
&CacheInfo,
473+
sizeof(CacheInfo),
474+
NULL);
475+
if (NT_SUCCESS(Status)) {
476+
RtlCliDisplayString("[CACHE] Size: %lluKB. Peak: %lluKB. "
477+
"Min WS: %lluKB. Max WS: %lluKB\n",
478+
CacheInfo.CurrentSize / 1024,
479+
CacheInfo.PeakSize / 1024,
480+
CacheInfo.MinimumWorkingSet,
481+
CacheInfo.MaximumWorkingSet);
482+
}
483+
478484
//
479485
// Return success
480486
//

0 commit comments

Comments
 (0)