SRL Archive - General

Simba script user info wiping with .bat and sed gnuwin32


Er1k

2012-01-30 11:02:32

Yeah I know it is kind of useless, but nevertheless I thought it's a nice idea to share it and hopefully get some bash.

So this is basically a batch script that wipes your user info from the script and outputs the file to clean.simba. You can drag the script to the .bat file and it will do the rest for you :D

P.S Tested only on win7 x64


echo off
if [%1]==[] (
echo Drag file to .bat to work
)
if not [%1]==[] (
echo Running info cleaner...
sed "s/ *[nN][aA][mM][eE] *:= *'.*' *;.*/Name := '';\/\/name replaced by sed/g" %1

| sed "s/ *[Pp][Aa][Ss][Ss] *:= *'.*' *;.*/Pass := '';\/\/pass replaced by sed/g" |

sed "s/ *[Pp][Ii][Nn] *:= *'.*' *;.*/Pin := '';\/\/Pin replaced by sed/g"| sed "s/

*[Pp][Ll][Aa][Yy][Ee][Rr][Ss]\[.*\]\.[nN][aA][mM][eE] *:= *'.*' *;.*/Players[].Name

:= '';\/\/name replaced by sed/g" | sed "s/ *[Pp][Ll][Aa][Yy][Ee][Rr][Ss]\[.*\]\.

[pP][aA][sS][sS] *:= *'.*' *;.*/Players[].Pass := '';\/\/Pass replaced by sed/g" |

sed "s/ *[Pp][Ll][Aa][Yy][Ee][Rr][Ss]\[.*\]\.[pP][iI][nN] *:= *'.*' *;.*/Players

[].Pin := '';\/\/Pin replaced by sed/g"> cleaned.simba
echo Operation completed! Check script cleaned.simba)
pause

For those who are interested, I used sed from gnuwin32 http://gnuwin32.sourceforge.net/packages/sed.htm to perform the regex search/replace.

A sample package is attached, for those who don't bother downloading the sed binary and dlls from the said link.

Comments are welcome.

Brandon

2012-01-30 14:07:15

The above is clean.. although.. I think you might find it easier to just use an extension?

I personally don't like DLL's for anything other than plugins but a lot of members will find your post a bit sketchy because not everyone recognizes Regex's and PCRE <– Perl expression matching (for those that don't know)..

P.S. Nice use of regex's and the batch file but it re-format's the user's script.. meaning all indentation is lost for the username, pin and password portions.. Oh and btw.. what is the use of the Regex2.dll if your using the PCRE library which is definitely more sufficiennt?

The below does the same thing without format loss and it's open for all users to view the source as well.
Basically just save it as ScriptCleaner.sex and place it in the extensions folder.. enable the extension in simba.. done.. now every time u exit simba, it'll prompt if u want to clean or not.. OR u can use the menu to clean a script.


program ScriptCleaner;

function GetName : string;
begin;
result := 'ScriptCleaner';
end;

function GetVersion : string;
begin;
result := '0.1';
end;

var
MainMenuItem, MenuSMARTForm: TMenuItem;
Option: Integer;
Pass, Line: String;
Key: Int64;
FRM: TForm;


type
TCharArray = array of Char;

Function StringToCharArray(s: string): TCharArray;
var
i, l: Integer;
begin
l := Length(s);
SetLength(Result, l + 1);
for i := l downto 1 do
Result[i - 1] := s[i];
end;

Function DecToBin(Num: Int64): Int64;
var
bin, pos: Cardinal;
begin
bin := 0;
pos := 1;

while (Num > 0) do
begin
bin := bin + (Num mod 2) * pos;
Num := Num / 2;
pos := pos * 10;
end;

Result:= Bin;
end;

Function CharArrayToString(s: TCharArray): String;
var
i, l: Integer;
begin
l := Length(s) - 1;
for i:= 0 To l do
Result := Result + s[i];
end;

Function ToASCII(Meh: char): Integer;
begin
result:= ord(Meh);
end;

Function ToChar(Meh: Byte): Char;
begin
result:= chr(Meh);
end;

Procedure WriteToFile;
var
FS: TOpenDialog;
Custom: TMsgDlgType;
Buttons: TMsgDlgButtons;
Buffer, FName, What: String;
TStrL: TStringList;
F: TFileStream;
begin
Custom:= mtConfirmation;
Buttons:= [mbYes];

FS := TOpenDialog.Create(nil);
FS.Options := [ofFileMustExist];
FS.Filter := ' Simba Scripts (*.simba;*.Simba)|*.simba;*.Simba|All files (*.*)|*.*|';
FS.FilterIndex := 1;

if FS.Execute then
begin
FName:= FS.FileName;
F:= TFileStream.Create(FName, fmOpenReadWrite);
try
F.Position:= 0;
SetLength(Buffer, F.Size);
F.ReadBuffer(Buffer, F.Size);
Finally
F.Free;
end;

F:= TFileStream.Create(FName, fmOpenReadWrite);
try
F.Position:= 0;
What:= '';
TStrL:= TStringList.Create;
Buffer:= ReplaceRegExpr('Name(\s*|^\s):=(\s*|^\s)''[a-zA-Z0-9_]*''', Buffer, 'Name:= ''''', False);
Buffer:= ReplaceRegExpr('Pass(\s*|^\s):=(\s*|^\s)''[a-zA-Z0-9_]*''', Buffer, 'Pass:= ''''', False);
Buffer:= ReplaceRegExpr('Pin(\s*|^\s):=(\s*|^\s)''[a-zA-Z0-9_]*''', Buffer, 'Pin:= ''''', False);
F.WriteBuffer(Buffer, Length(Buffer));
Finally
F.Free;
end;
FS.Free;
end;
end;

procedure Main(Sender: TObject);
begin
WriteToFile;
end;


procedure Init;
begin
MainMenuItem := TMenuItem.Create(Simba_MainMenu);
MainMenuItem.Caption := 'FileCleaner';
Simba_MainMenu.Items.Add(MainMenuItem);
MenuSMARTForm := TMenuItem.Create(MainMenuItem);
MenuSMARTForm.Caption := 'FileCleaner';
MenuSMARTForm.ShortCut := 123;
MenuSMARTForm.OnClick := @Main;
MainMenuItem.Add(MenuSMARTForm);
end;

procedure Free;
var
Response: String;
begin
InputQuery('CleanScript', 'To Clean A Script, Type "Clean". Else Just Cancel this box.', Response);
if (ExecRegExpr('clean', Response) or ExecRegExpr('Clean', Response)) then
begin
writeln(Response);
WriteToFile;
end;
end;

procedure Attach;
begin
writeln(' ScriptCleaner Loaded ');
end;

Procedure Detach;
begin
Writeln('ScriptCleaner:: Goodbye...');
end;

Begin
End.

Dgby714

2012-01-30 14:18:07

The Paster Ext uses this.
    if (ExecRegExpr('([N|n][A|a][M|m][E|e]|[P|p][A|a][S|s]{2}|[P|p][I|i][N|n])', ScriptTextEx)) then
case (MessageDlg(GetName + ' ' + GetVersion + ' Extension', 'Would you like to mask sensitive data?', mtConfirmation, [mbYes, mbNo, mbCancel], 0)) of
mrYes: ScriptTextEx := ReplaceRegExpr('([N|n][A|a][M|m][E|e]|[P|p][A|a][S|s]{2}|[P|p][I|i][N|n])\s*\:\=\s*\''.*?\'';', ScriptTextEx, '$1 := ''*********'';', True);
mrNo: WriteLn('[Paster]Warning: Not masking data!');
else
begin
WriteLn('[Paster]: Paste canceled');
Exit;
end;
end;

Er1k

2012-01-30 20:28:46

Ah I knew it's not a very good idea to include Dlls as many people find it sketchy, but my skills limit me from using the more powerful extensions that comes with simba. I thought raising this idea will get some discussion of what's available or better methods of getting this done.

The dependencies I simply copied from the gnu32 downloads to make them work. Guess I was a bit lazy :D

@Dgby714: Until you pointed out I never knew what the paster Ext actually does. :)