Skip to content

Commit

Permalink
1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill-Stewart committed Jan 19, 2023
1 parent 10d0228 commit de930a1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 59 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Copyright and Author

Copyright (C) 2020-2021 by Bill Stewart (bstewart at iname.com)
Copyright (C) 2020-2023 by Bill Stewart (bstewart at iname.com)

## License

Expand Down Expand Up @@ -104,7 +104,7 @@ The maximum possible number of input characters depends on whether the current s

* In a standard Windows console, the maximum possible number of input characters is the number of rows * the number of columns in the console buffer or 16383, whichever is less. The standard Windows console allows the cursor to move back past the top of the current screenful into the scrollback buffer, which means it is possible to edit an environment variable that has a value longer than will fit in the current screenful.

* In a WT console, the maximum possible number of inputt characters is the number of rows * the number of columns or 16383 (whichever is less) in the current screenful only. WT does not allow the cursor to move "backwards" past the top of the current screenful into the scrollback buffer, which means it is not possible to edit an environment variable that has a value longer than will fit in the current screenful. (You can work around this limitation in a WT session by expanding the WT window such that it has a larger number of rows and/or columns before running **editenv**).
* In a WT console, the maximum possible number of input characters is the number of rows * the number of columns or 16383 (whichever is less) in the current screenful only. WT does not allow the cursor to move "backwards" past the top of the current screenful into the scrollback buffer, which means it is not possible to edit an environment variable that has a value longer than will fit in the current screenful. (You can work around this limitation in a WT session by expanding the WT window such that it has a larger number of rows and/or columns before running **editenv**).

* The **--getmaxlength** parameter outputs the maximum possible input length.

Expand Down
4 changes: 2 additions & 2 deletions editenv.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ editenv - Windows console program for interactively editing the value of an
environment variable
Copyright (C) 2020-2021 by Bill Stewart (bstewart at iname.com)
Copyright (C) 2020-2023 by Bill Stewart (bstewart at iname.com)
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -37,7 +37,7 @@

const
PROGRAM_NAME = 'editenv';
PROGRAM_COPYRIGHT = 'Copyright (C) 2020-2021 by Bill Stewart';
PROGRAM_COPYRIGHT = 'Copyright (C) 2020-2023 by Bill Stewart';

type
TCommandLine = object
Expand Down
8 changes: 4 additions & 4 deletions editenv.rc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1 VERSIONINFO
FILEVERSION 1,6,1,0
PRODUCTVERSION 1,6,1,0
FILEVERSION 1,6,2,0
PRODUCTVERSION 1,6,2,0
FILEOS 0x4
FILETYPE 1
{
Expand All @@ -10,12 +10,12 @@ FILETYPE 1
{
VALUE "CompanyName", "Bill Stewart (bstewart at iname.com)"
VALUE "FileDescription", "editenv.exe"
VALUE "FileVersion", "1.6.1.0"
VALUE "FileVersion", "1.6.2.0"
VALUE "InternalName", "editenv.exe"
VALUE "LegalCopyright", "(C) 2020-2021 by Bill Stewart (bstewart at iname.com)"
VALUE "OriginalFilename", "editenv.exe"
VALUE "ProductName", "editenv.exe"
VALUE "ProductVersion", "1.6.1.0"
VALUE "ProductVersion", "1.6.2.0"
}
}

Expand Down
4 changes: 4 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# editenv Version History

## 1.6.2 (2023-01-19)

* Minor tweaks and bump version number for release redistributable.

## 1.6.1 (2021-11-03)

* Added support to detect the maximum possible number of input characters. In a Windows Terminal (WT) session, maximum input length is currently limited to the current screenful (i.e., you can't edit an environment variable that has a value longer than the current screenful). The **--getmaxlength** parameter reports the maximum possible number of input characters.
Expand Down
100 changes: 49 additions & 51 deletions wsWinEnvVar.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ Copyright (C) 2020-2021 by Bill Stewart (bstewart at iname.com)
{ Copyright (C) 2020-2023 by Bill Stewart (bstewart at iname.com)
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -202,72 +202,70 @@ function SetEnvVarInProcess(const ProcessID: DWORD; const Name, Value: UnicodeSt
hProcess := OpenProcess(ProcessAccess, // DWORD dwDesiredAccess
true, // BOOL bInheritHandle
ProcessID); // DWORD dwProcessId
if hProcess <> 0 then
if hProcess = 0 then
exit(GetLastError()); // OpenProcess() failed

// Allocate memory in processs
pCodeBuffer := VirtualAllocEx(hProcess, // HANDLE hProcess
nil, // LPVOID lpAddress
SizeOf(CodeBuffer), // DWORD dwSize
MEM_COMMIT, // DWORD flAllocationType
PAGE_EXECUTE_READWRITE); // DWORD flProtect
if Assigned(pCodeBuffer) then
begin
// Allocate memory in processs
pCodeBuffer := VirtualAllocEx(hProcess, // HANDLE hProcess
nil, // LPVOID lpAddress
SizeOf(CodeBuffer), // DWORD dwSize
MEM_COMMIT, // DWORD flAllocationType
PAGE_EXECUTE_READWRITE); // DWORD flProtect
if Assigned(pCodeBuffer) then
// Copy code buffer to process
OK := WriteProcessMemory(hProcess, // HANDLE hProcess
pCodeBuffer, // LPVOID lpBaseAddress
@CodeBuffer, // LPCVOID lpBuffer
SizeOf(CodeBuffer), // SIZE_T nSize
BytesWritten); // SIZE_T lpNumberOfBytesWritten
if OK then
begin
// Copy code buffer to process
OK := WriteProcessMemory(hProcess, // HANDLE hProcess
pCodeBuffer, // LPVOID lpBaseAddress
@CodeBuffer, // LPCVOID lpBuffer
SizeOf(CodeBuffer), // SIZE_T nSize
BytesWritten); // SIZE_T lpNumberOfBytesWritten
if OK then
// Execute function in process
hThread := CreateRemoteThread(hProcess, // HANDLE hProcess
nil, // LPSECURITY_ATTRIBUTES lpThreadAttributes
0, // SIZE_T dwStackSize
@pCodeBuffer^.Routine[0], // LPTHREAD_START_ROUTINE lpStartAddress
pCodeBuffer, // LPVOID lpParameter
0, // DWORD dwCreationFlags
nil); // LPDWORD lpThreadId
if hThread <> 0 then
begin
// Execute function in process
hThread := CreateRemoteThread(hProcess, // HANDLE hProcess
nil, // LPSECURITY_ATTRIBUTES lpThreadAttributes
0, // SIZE_T dwStackSize
@pCodeBuffer^.Routine[0], // LPTHREAD_START_ROUTINE lpStartAddress
pCodeBuffer, // LPVOID lpParameter
0, // DWORD dwCreationFlags
nil); // LPDWORD lpThreadId
if hThread <> 0 then
// Wait for thread to complete
if WaitForSingleObject(hThread, // HANDLE hHandle
INFINITE) <> WAIT_FAILED then // DWORD dwMilliseconds
begin
// Wait for thread to complete
if WaitForSingleObject(hThread, // HANDLE hHandle
INFINITE) <> WAIT_FAILED then // DWORD dwMilliseconds
// Get exit code of thread
if GetExitCodeThread(hThread, // HANDLE hThread
ThreadExitCode) then // LPDWORD lpExitCode
begin
// Get exit code of thread
if GetExitCodeThread(hThread, // HANDLE hThread
ThreadExitCode) then // LPDWORD lpExitCode
begin
if ThreadExitCode <> 0 then
result := 0
else // Thread exit code <> 0
result := GetLastError();
end
else // GetExitCodeThread() failed
if ThreadExitCode <> 0 then
result := 0
else // Thread exit code <> 0
result := GetLastError();
end
else // WaitForSingleObject() failed
else // GetExitCodeThread() failed
result := GetLastError();
CloseHandle(hThread);
end
else // CreateRemoteThread() failed
else // WaitForSingleObject() failed
result := GetLastError();
CloseHandle(hThread);
end
else // WriteProcessMemory() failed
result := GetLastError();
// Free memory in process
if not VirtualFreeEx(hProcess, // HANDLE hProcess
pCodeBuffer, // LPVOID lpAddress
0, // SIZE_T dwSize
MEM_RELEASE) then // DWORD dwFreeType
else // CreateRemoteThread() failed
result := GetLastError();
end
else // VirtualAllocEx() failed
else // WriteProcessMemory() failed
result := GetLastError();
// Free memory in process
if not VirtualFreeEx(hProcess, // HANDLE hProcess
pCodeBuffer, // LPVOID lpAddress
0, // SIZE_T dwSize
MEM_RELEASE) then // DWORD dwFreeType
result := GetLastError();
CloseHandle(hProcess);
end
else // OpenProcess() failed
else // VirtualAllocEx() failed
result := GetLastError();
CloseHandle(hProcess);
end;

begin
Expand Down

0 comments on commit de930a1

Please sign in to comment.