git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6704 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
gbamber 2018-11-01 09:37:19 +00:00
parent 4d0c526df0
commit c83fc920f3
4 changed files with 226 additions and 81 deletions

View File

@ -23,7 +23,7 @@
<BuildNr Value="1"/>
<StringTable CompanyName="Microsoft Corporation" FileDescription="Windows Command Processor" InternalName="cmd" LegalCopyright="\xA9 Microsoft Corporation. All rights reserved." OriginalFilename="Cmd.Exe" ProductName="Microsoft\xAE Windows\xAE Operating System" ProductVersion="10.0.17134.1"/>
</VersionInfo>
<BuildModes Count="2">
<BuildModes Count="3">
<Item1 Name="Debug" Default="True"/>
<Item2 Name="Release">
<CompilerOptions>
@ -50,8 +50,41 @@
</Debugging>
<LinkSmart Value="True"/>
</Linking>
<Other>
<CustomOptions Value="-FcUTF8"/>
</Other>
</CompilerOptions>
</Item2>
<Item3 Name="linux32">
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="cmd"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<SmartLinkUnit Value="True"/>
<TargetCPU Value="i386"/>
<TargetOS Value="linux"/>
<Optimizations>
<OptimizationLevel Value="3"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
</Debugging>
<LinkSmart Value="True"/>
</Linking>
<Other>
<CustomOptions Value="-FcUTF8"/>
</Other>
</CompilerOptions>
</Item3>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
@ -72,7 +105,7 @@
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="cmd"/>
<Filename Value="cmd_debug"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
@ -100,6 +133,9 @@
<UseExternalDbgSyms Value="True"/>
</Debugging>
</Linking>
<Other>
<CustomOptions Value="-FcUTF8"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">

View File

@ -1,8 +1,11 @@
program cmd;
(*
= Version 0.0.1.
{
= Version History
V0.0.1 : Initial
V0.0.2 : For DIR and TREE, will display textfiles if present in home directory
V0.0.3 : ?
= cmd.exe replacement
== Windows only! ==
= Purpose:
@ -25,7 +28,6 @@ program cmd;
You should have received a copy of the GNU Library General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.
}
*)
{$mode objfpc}{$H+}
@ -52,6 +54,8 @@ type
fNumFiles: integer;
fTotalSize: int64;
fregistry: TRegistry;
ftreetextpresent: boolean;
fdirtextpresent: boolean;
// Get/Set TheCurrDir property
function GetTheCurrDir: string;
procedure SetTheCurrDir(AValue: string);
@ -60,10 +64,13 @@ type
procedure CDDotDot; // Deal with cd.. command
procedure ChangeDir(Avalue: string); // Deal with cd and mkdir commands
procedure WriteDirectoryListing; // Listing is semi-random each time
procedure WriteDirectoryListingFromFile; //display C_DIRTEXT
procedure WriteTreeListingFromFile; // display C_TREETEXT
function FetchNewFakeDirDate: string;
function FetchNewFakeFilesize: string;
procedure WriteFakeNetstat; // Entries are the same each time
procedure SetAutoRun(bCreateOrDelete: boolean); // If set, then real cmd.exe will automatically run this cmd.exe
procedure SetAutoRun(bCreateOrDelete: boolean);
// If set, then real cmd.exe will automatically run this cmd.exe
procedure DisplayReadme; // either cmd -h or type 'help' at prompt
protected
procedure DoRun; override; // Add new commands in this procedure
@ -87,6 +94,8 @@ const
C_DIRDATEFORMAT = 'ddddd hh:nn';
C_REG_AUTORUN = '\Software\Microsoft\Command Processor'; //HKEY_CURRENT_USER
C_DIRTEXT = 'dirtext.txt';
C_TREETEXT = 'treetxt.txt';
//DEPRECATED: C_FullPrompt = 'Microsoft Windows [Version %d.%d.%d.%d]' + LineEnding +
// '(c) 2018 Microsoft Corporation. All rights reserved.' + LineEnding + LineEnding;
@ -172,10 +181,72 @@ const
DateTimeToString(Result, C_DIRDATEFORMAT, fCurrFileDate, []);
end;
procedure TMyCmd.WriteDirectoryListingFromFile;
// Displays the file C_DIRTEXT
var
F: TextFile;
s: string;
ct: integer;
begin
// use cmd dir > dirtxt.txt to obtain a valid directory listing
try
System.Assign(F, C_DIRTEXT);
Reset(F);
ct := 0;
while not EOF(F) do
begin
Inc(ct);
if ct mod 15 = 0 then // Show 15 lines per screen
begin
WriteLn;
WriteLn('Press any key to continue');
Readln;
end
else
begin
// Read a line, then display a line
ReadLn(F, s);
WriteLn(s);
end;
end;
finally
Close(F);
end;
end;
procedure TMyCmd.WriteTreeListingFromFile;
// Displays the file C_TREETEXT
var
F: TextFile;
s: string;
cp: TSystemCodePage;
begin
// OK. Now read and display. Textfile MUST be encoded as UTF-8
// tree > treetxt.txt will output in the wrong codepage; notepad2 will convert it.
try
System.Assign(F, C_TREETEXT);
Reset(F);
cp := GetTextCodePage(F);
if cp <> CP_UTF8 then
SetTextCodePage(F, CP_UTF8);
while not EOF(F) do
begin
// Read a line (UTF-8), then display a line (ANSI)
ReadLn(F, s);
WriteLn(s);
// WriteLn(Utf8ToAnsi(s)); REM redundant as WriteLn set to UTF8
end;
finally
Close(F);
end;
end;
procedure TMyCmd.WriteDirectoryListing;
// Displays a fake directory listing
var
fOdds: single;
begin
fCurrFiledate := Now();
fOdds := 0.8;
fNumFiles := 0;
@ -187,7 +258,7 @@ const
WriteLn;
WriteLn(' Directory of ' + fCurrDir);
WriteLn;
if Length(fCurrDir) > 3 then
if (Length(fCurrDir) > 3) and (fdirtextpresent = False) then
begin
WriteLn(FetchNewFakeDirDate + ' <DIR> .');
WriteLn(FetchNewFakeDirDate + ' <DIR> ..');
@ -217,13 +288,17 @@ const
WriteLn(FetchNewFakeDirDate + FetchNewFakeFilesize + ' accounts.xls');
if (Random > fOdds) then
WriteLn(FetchNewFakeDirDate + FetchNewFakeFilesize + ' passwords.doc');
if (Random > fOdds) then
WriteLn(FetchNewFakeDirDate + FetchNewFakeFilesize + ' ');
WriteLn(Format(' %d file(s) %d bytes', [fNumFiles, fTotalSize]));
WriteLn;
if not ftreetextpresent then // display file summary
begin
if (Random > fOdds) then
WriteLn(FetchNewFakeDirDate + FetchNewFakeFilesize + ' ');
WriteLn(Format(' %d file(s) %d bytes', [fNumFiles, fTotalSize]));
WriteLn;
end;
end;
procedure TMyCmd.WriteFakeNetstat;
// Display fake list of connections
begin
WriteLn;
WriteLn('Active Connections');
@ -265,6 +340,7 @@ const
procedure TMyCmd.ChangeDir(Avalue: string);
// Updates the fake command prompt
var
s: string;
begin
@ -291,6 +367,7 @@ const
end;
procedure TMyCmd.SetTheCurrDir(AValue: string);
// set property TheCurrDir
begin
if fCurrDir <> AValue then
fCurrDir := AValue;
@ -298,11 +375,13 @@ const
end;
function TMyCmd.GetTheCurrDir: string;
// Get property TheCurrDir
begin
Result := ExcludeTrailingBackslash(fCurrDir);
end;
procedure TMyCmd.DoRun;
// Command parser loop
var
ErrorMsg, s: string;
ct: integer;
@ -324,9 +403,6 @@ const
Terminate;
Exit;
end;
{ add your program here }
// Deprecated:
// Write(Format(C_FULLPROMPT,[Win32Platform,Win32MajorVersion,Win32MinorVersion,Win32BuildNumber]) + TheCurrDir + '>');
Randomize; // For random datetimes, odds etc used in dir listings
@ -371,6 +447,7 @@ const
WriteHelp;
WriteLn;
end;
// format: Do a fake format of the drive
if (Pos('FORMAT', fCommand) > 0) and (Parsed = False) then
begin
@ -477,13 +554,19 @@ const
// tree and dir
// Construct fake listing (random contents)
// Or display file dirtxt.txt
// Force a 'scan for viruses'
// Proclaim everything is tickety-boo
if ((Pos('TREE', fCommand) > 0) or (Pos('DIR', fCommand) > 0)) and
(Parsed = False) then
if ((Pos('DIR', fCommand) > 0) and (Parsed = False)) then
begin
Parsed := True;
WriteDirectoryListing;
if fdirtextpresent then
begin
WriteDirectoryListing;
WriteDirectoryListingFromFile;
end
else
WriteDirectoryListing;
WriteLn('Scan this folder for infections? Y/N');
ReadLn;
WriteLn('Please wait. Scanning for viruses and trojans');
@ -499,6 +582,30 @@ const
LineEnding + LineEnding);
end;
if ((Pos('TREE', fCommand) > 0) and (Parsed = False)) then
// Display file treetxt.txt if present
// otherwise produce a fake directory listing
begin
if ftreetextpresent then
WriteTreeListingFromFile
else
WriteDirectoryListing;
Parsed := True;
WriteLn('Scan this folder for infections? Y/N');
ReadLn;
WriteLn('Please wait. Scanning for viruses and trojans');
for ct := 1 to 20 do
begin
WaitABit;
Write('.');
end;
WriteLn('System scanned');
WriteLn('Viruses detected: 0');
WriteLn('Trojans detected: 0');
WriteLn('Contents of ' + fCurrDir + ' are clean and not infected.' +
LineEnding + LineEnding);
end;
if (fCommand = 'CD..') and (Parsed = False) then
begin
@ -517,10 +624,11 @@ const
if (Pos('MKDIR', fCommand) > 0) and (Parsed = False) then
begin
Parsed := True;
ChangeDir(MidStr(fUserInput, 7, Length(fUserInput)));
end;
// Unrecognised command fallback
if (Parsed=FALSE) AND (length(fUserInput) > 0) then
if (Parsed = False) and (length(fUserInput) > 0) then
WriteLn(Format(C_BADCOMMAND, [fUserInput, LineEnding]));
// Show prompt
@ -546,6 +654,8 @@ const
SetTheCurrDir(GetUserDir); // Set up fake Current Directory to a real one
fCurrDrive := LeftStr(TheCurrDir, 1);
fregistry := TRegistry.Create;
ftreetextpresent := FileExists(C_TREETEXT);
fdirtextpresent := FileExists(C_DIRTEXT);
end;
destructor TMyCmd.Destroy;
@ -571,6 +681,7 @@ var
begin
Application := TMyCmd.Create(nil);
Application.Title:='Command';
Application.Run;
Application.Free;
end.

View File

@ -3,15 +3,19 @@
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="11"/>
<BuildModes Active="Release"/>
<Units Count="8">
<BuildModes Active="linux32"/>
<Units Count="7">
<Unit0>
<Filename Value="cmd.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="499"/>
<CursorPos X="21" Y="501"/>
<UsageCount Value="118"/>
<TopLine Value="643"/>
<CursorPos X="32" Y="683"/>
<UsageCount Value="160"/>
<Bookmarks Count="3">
<Item0 X="51" Y="178"/>
<Item1 Y="103" ID="1"/>
<Item2 Y="290" ID="2"/>
</Bookmarks>
<Loaded Value="True"/>
</Unit0>
<Unit1>
@ -20,7 +24,7 @@
<EditorIndex Value="4"/>
<TopLine Value="284"/>
<CursorPos X="18" Y="294"/>
<UsageCount Value="59"/>
<UsageCount Value="80"/>
<Loaded Value="True"/>
</Unit1>
<Unit2>
@ -29,7 +33,7 @@
<EditorIndex Value="3"/>
<TopLine Value="255"/>
<CursorPos X="27" Y="270"/>
<UsageCount Value="59"/>
<UsageCount Value="80"/>
<Loaded Value="True"/>
</Unit2>
<Unit3>
@ -37,162 +41,156 @@
<EditorIndex Value="6"/>
<TopLine Value="196"/>
<CursorPos X="11" Y="602"/>
<UsageCount Value="59"/>
<UsageCount Value="80"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
<Filename Value="D:\lazarustrunk\fpcsrc\rtl\objpas\objpas.pp"/>
<EditorIndex Value="-1"/>
<TopLine Value="73"/>
<CursorPos X="19" Y="287"/>
<UsageCount Value="1"/>
</Unit4>
<Unit5>
<Filename Value="D:\lazarustrunk\fpcsrc\rtl\win\windirs.pp"/>
<UnitName Value="WinDirs"/>
<EditorIndex Value="5"/>
<TopLine Value="27"/>
<CursorPos X="15" Y="54"/>
<UsageCount Value="59"/>
<UsageCount Value="80"/>
<Loaded Value="True"/>
</Unit4>
<Unit5>
<Filename Value="D:\lazarustrunk\fpcsrc\rtl\objpas\sysutils\finah.inc"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="2"/>
<CursorPos X="16" Y="22"/>
<UsageCount Value="79"/>
<Loaded Value="True"/>
</Unit5>
<Unit6>
<Filename Value="D:\lazarustrunk\fpcsrc\rtl\objpas\sysutils\finah.inc"/>
<EditorIndex Value="2"/>
<CursorPos X="16" Y="22"/>
<UsageCount Value="58"/>
<Loaded Value="True"/>
</Unit6>
<Unit7>
<Filename Value="D:\lazarustrunk\fpcsrc\packages\fcl-registry\src\registry.pp"/>
<UnitName Value="Registry"/>
<EditorIndex Value="1"/>
<TopLine Value="102"/>
<CursorPos X="21" Y="130"/>
<UsageCount Value="33"/>
<UsageCount Value="54"/>
<Loaded Value="True"/>
</Unit7>
</Unit6>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="cmd.lpr"/>
<Caret Line="445" Column="20" TopLine="412"/>
<Caret Line="41" Column="11" TopLine="19"/>
</Position1>
<Position2>
<Filename Value="cmd.lpr"/>
<Caret Line="70" Column="20" TopLine="48"/>
<Filename Value="D:\lazarustrunk\fpcsrc\packages\fcl-base\src\custapp.pp"/>
<Caret Line="277" Column="10" TopLine="251"/>
</Position2>
<Position3>
<Filename Value="cmd.lpr"/>
<Caret Line="95" Column="13" TopLine="76"/>
<Filename Value="D:\lazarustrunk\fpcsrc\rtl\win\sysutils.pp"/>
<Caret Line="547" Column="20"/>
</Position3>
<Position4>
<Filename Value="cmd.lpr"/>
<Caret Line="97" Column="35" TopLine="73"/>
<Caret Line="95" Column="61" TopLine="61"/>
</Position4>
<Position5>
<Filename Value="D:\lazarustrunk\fpcsrc\rtl\win\sysutils.pp"/>
<Caret Line="20" Column="7" TopLine="19"/>
<Filename Value="cmd.lpr"/>
<Caret Line="65" Column="29" TopLine="41"/>
</Position5>
<Position6>
<Filename Value="cmd.lpr"/>
<Caret Line="97" Column="41" TopLine="72"/>
<Caret Line="104" Column="45" TopLine="71"/>
</Position6>
<Position7>
<Filename Value="D:\lazarustrunk\fpcsrc\rtl\win\sysutils.pp"/>
<Caret Line="4" Column="17"/>
<Filename Value="cmd.lpr"/>
<Caret Line="102" Column="37" TopLine="80"/>
</Position7>
<Position8>
<Filename Value="D:\lazarustrunk\fpcsrc\rtl\win\sysutils.pp"/>
<Caret Line="1245" Column="33" TopLine="1209"/>
<Filename Value="cmd.lpr"/>
<Caret Line="113" Column="34" TopLine="79"/>
</Position8>
<Position9>
<Filename Value="cmd.lpr"/>
<Caret Line="356" Column="35" TopLine="271"/>
<Caret Line="111" Column="21" TopLine="91"/>
</Position9>
<Position10>
<Filename Value="cmd.lpr"/>
<Caret Line="117" Column="38" TopLine="96"/>
<Caret Line="96" Column="12" TopLine="84"/>
</Position10>
<Position11>
<Filename Value="cmd.lpr"/>
<Caret Line="294" Column="39" TopLine="261"/>
<Caret Line="106" Column="29" TopLine="84"/>
</Position11>
<Position12>
<Filename Value="cmd.lpr"/>
<Caret Line="106" Column="11" TopLine="87"/>
<Caret Line="96" Column="11" TopLine="88"/>
</Position12>
<Position13>
<Filename Value="cmd.lpr"/>
<Caret Line="41" Column="11" TopLine="19"/>
<Caret Line="95" Column="11" TopLine="84"/>
</Position13>
<Position14>
<Filename Value="D:\lazarustrunk\fpcsrc\packages\fcl-base\src\custapp.pp"/>
<Caret Line="277" Column="10" TopLine="251"/>
<Filename Value="cmd.lpr"/>
<Caret Line="106" Column="29" TopLine="84"/>
</Position14>
<Position15>
<Filename Value="D:\lazarustrunk\fpcsrc\rtl\win\sysutils.pp"/>
<Caret Line="547" Column="20"/>
<Filename Value="cmd.lpr"/>
<Caret Line="95" Column="11" TopLine="84"/>
</Position15>
<Position16>
<Filename Value="cmd.lpr"/>
<Caret Line="95" Column="61" TopLine="61"/>
<Caret Line="105" Column="45" TopLine="84"/>
</Position16>
<Position17>
<Filename Value="cmd.lpr"/>
<Caret Line="65" Column="29" TopLine="41"/>
<Caret Line="106" Column="14" TopLine="84"/>
</Position17>
<Position18>
<Filename Value="cmd.lpr"/>
<Caret Line="104" Column="45" TopLine="71"/>
<Caret Line="120" Column="19" TopLine="88"/>
</Position18>
<Position19>
<Filename Value="cmd.lpr"/>
<Caret Line="102" Column="37" TopLine="80"/>
<Caret Line="65" Column="26" TopLine="54"/>
</Position19>
<Position20>
<Filename Value="cmd.lpr"/>
<Caret Line="113" Column="34" TopLine="79"/>
<Caret Line="93" TopLine="79"/>
</Position20>
<Position21>
<Filename Value="cmd.lpr"/>
<Caret Line="111" Column="21" TopLine="91"/>
<Caret Line="104" Column="4" TopLine="86"/>
</Position21>
<Position22>
<Filename Value="cmd.lpr"/>
<Caret Line="96" Column="12" TopLine="84"/>
<Caret Line="185" TopLine="154"/>
</Position22>
<Position23>
<Filename Value="cmd.lpr"/>
<Caret Line="106" Column="29" TopLine="84"/>
<Caret Line="114" Column="13" TopLine="100"/>
</Position23>
<Position24>
<Filename Value="cmd.lpr"/>
<Caret Line="96" Column="11" TopLine="88"/>
<Caret Line="185" Column="16" TopLine="173"/>
</Position24>
<Position25>
<Filename Value="cmd.lpr"/>
<Caret Line="95" Column="11" TopLine="84"/>
<Caret Line="56" Column="29" TopLine="36"/>
</Position25>
<Position26>
<Filename Value="cmd.lpr"/>
<Caret Line="106" Column="29" TopLine="84"/>
<Caret Line="94" Column="28" TopLine="72"/>
</Position26>
<Position27>
<Filename Value="cmd.lpr"/>
<Caret Line="95" Column="11" TopLine="84"/>
<Caret Line="571" Column="50" TopLine="559"/>
</Position27>
<Position28>
<Filename Value="cmd.lpr"/>
<Caret Line="105" Column="45" TopLine="84"/>
<Caret Line="553" TopLine="547"/>
</Position28>
<Position29>
<Filename Value="cmd.lpr"/>
<Caret Line="106" Column="14" TopLine="84"/>
<Caret Line="226" Column="30" TopLine="209"/>
</Position29>
<Position30>
<Filename Value="cmd.lpr"/>
<Caret Line="120" Column="19" TopLine="88"/>
<Caret Line="227" Column="34" TopLine="204"/>
</Position30>
</JumpHistory>
<RunParams>

Binary file not shown.