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 72 73 74 75 76 77 78 79 |
procedure TForm9.Button1Click(Sender: TObject); var RusA: set of Char; Finput,Hinput,Tinput : File; Dialog : TOpenDialog; StrInput: array of Byte; Stmp,key: string; i,j,H,len,size,sizeedit: integer; Buff,shifr,Shifr2 : AnsiString; ok :boolean; begin RusA:=['A','B','C','D','E','F','0','1','2','3','4','5','6','7','9']; key:=edit1.text; sizeedit:=Length(edit1.text); for I := 1 to Sizeedit do begin if (key[i] in RusA) then ok:=true else ok:=false; end; if (ok=true) then begin //Ищем файл Progressbar1.Position:=0; ShowMessage('Откройте нужный файл!'); Dialog := OpenDialog1; if Dialog.InitialDir = '' then Dialog.InitialDir := ExtractFilePath( Application.ExeName ); if not Dialog.Execute then Exit; if not FileExists(Dialog.FileName) then begin MessageBox(0,'Файл не найден.','Файл не найден',MB_OK + MB_ICONWARNING + MB_APPLMODAL); Exit; end; //Присваиваем файлу имя AssignFile(Finput, Dialog.FileName); Progressbar1.Position:=20; Reset(Finput, 1); Size:= FileSize(Finput); If size<134217728 then begin /////////(это на время пока не исправлю ошибку с размерами) SetLength(StrInput, Size);//Задаем размер массива с размером файла BlockRead(Finput, StrInput[0], Size);//Считываем файл в строку байтов CloseFile(Finput); //Представляем строку байтов в виде HEX кода Len := Size * 3 + (Size div 16); Progressbar1.Position:=50; if Size mod 16 > 0 then Dec(Len); SetLength(HexInput, Len); H := High(StrInput); j := 1; for i := 0 to H do begin STmp := IntToHex(StrInput[i], 2); HexInput[j] := STmp[1]; HexInput[j + 1] := STmp[2]; Inc(j, 2); if i = H then Continue; if i mod 16 = 15 then begin HexInput[j] := #13; // probel HexInput[j + 1] := #10; //konec stroki Inc(j, 2); end else begin HexInput[j] := #9; //Tab Inc(j); end; end; Progressbar1.Position:=70; if checkbox1.Checked=true then Memo1.Text := HexInput; //чистый HEX Progressbar1.Position:=90; Shifr:=Viz_crypt(HexInput,Edit1.text); if checkbox1.Checked=true then Memo2.Text:=shifr; //кодированный HEX Shifr2:=getbytestr(shifr); AssignFile(hinput, Dialog.FileName+'.cry'); Rewrite(hinput, 1); BlockWrite(hinput, Shifr2[1], Length(Shifr2));//Считываем файл в строку символов Closefile(hinput); end else begin showmessage('Пожалуйста, выберите файл меньшего размера!');/////////(это на время пока не исправлю ошибку с размерами) Progressbar1.Position:=0; exit; end; end else showmessage('Пожалуйста, введите ключ содержащий только:A,B,C,D,E,F,0,1,2,3,4,5,6,7,9'); Progressbar1.Position:=100; ShowMessage('Готово!'); end; |
Go Up to Error and Warning Messages (Delphi)
You get this error when the RAD Studio built-in compiler runs out of memory.
This is a rare error that might occur when you build an extremely large project group of applications and libraries.
To solve this issue, do any of the following:
- Make sure your swap file is large enough and that there is still room on your disk. See Change the size of virtual memory.
- Configure your project group to be built externally to the IDE: Select Project > Options > Delphi Compiler and check the Use MSBuild externally to compile property.
-
- Note: If you want to be able to debug your app when you build with this option set, the Include remote debug symbols option should also be enabled on Project > Options > Delphi Compiler > Linking.
-
- Build your project group on the command line.
- Refactor the applications and libraries in your project group to rely more on Delphi packages. Delphi packages do not make the IDE run out of memory.
Можно работать через TStreamReader и TStreamWriter. При некоторых условиях скорость работы может быть больше до 3х раз, чем по-старинке с readln и writeln:
var
s:string;
reader:TStreamReader;
writer:TStreamWriter;
begin
reader:=TStreamReader.Create(OpenDialog1.FileName, TEncoding.ANSI); // Если нужна другая кодировка - сменить
writer := TStreamWriter.Create('out.txt', false,TEncoding.ANSI); // если нужно дописать файл, ставим True вместо false
while not reader.EndOfStream do
begin
s:=reader.ReadLine;
// делаем, что нужно с s
writer.WriteLine(s);
end;
// не забываем закрыть оба файла:
reader.Free;
writer.Free;
end;
Если же нужно обязательно хранить все строки в памяти, стоит работать через, например, TMemoryStream или TBytesStream, но стоит помнить, что в 32-битном режиме их емкость ограничена чуть менее, чем 2 Гб, а в 64-битном режиме, если надо > 2 Гб, с ними можно нормально работать только, начиная с Delphi Tokyo, или же делать патч.
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Contact US
Thanks. We have received your request and will respond promptly.
Log In
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips Forums!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts - Keyword Search
- One-Click Access To Your
Favorite Forums - Automated Signatures
On Your Posts - Best Of All, It’s Free!
*Tek-Tips’s functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Posting Guidelines
Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Students Click Here
«out of memory» exception«out of memory» exception(OP) 9 Aug 05 06:13 Hi all! I’m programming a very RAM-expensive thing and I’ve come over the following problem: Until now, when all available RAM was used up on my test machine, Windows started to swap and the application got very slow. All of a sudden, the swapping didn’t start any more when RAM was used up, but I always got the error «out of memory» (without further explanation and without hitting my app’s error log). At first I thought this was a Windows issue because I had played around with the swap file, but after a complete Windows reinstall it did not work either. Do you think this could be a program-caused error, or have you ever had it yourself? Thank you for any suggestions, Red Flag SubmittedThank you for helping keep Tek-Tips Forums free from inappropriate posts. |
Join Tek-Tips® Today!
Join your peers on the Internet’s largest technical computer professional community.
It’s easy to join and it’s free.
Here’s Why Members Love Tek-Tips Forums:
Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More…
Register now while it’s still free!
Already a member? Close this window and log in.
Join Us Close
Hey there,
I needed a code to act like a bruteforcer so I found one, but the problem is I don’t want to use TStringList, so I replaced it with array of strings and added some modifications.
The problem is when I run the code, after a certain time I get «Out Of Memory» error.
I hope someone can show me where is my error, I use FreeMem and SetLength to free the array of string each iteration.
Code is below..
Regards
function bruteforce(astring: string ;substr: string ; startlen: integer;
endlen: integer): LongInt;
var i,n,x: integer;
bi,bc,br:integer;
npw: string ;
counter:integer;
bhlplst: array of string;
bcluster : array of string;
bresults : array of string;
label step1;
begin
bi := 0;
bc := 0;
br := 0;
//hlplst := TStringList.Create; //The left column
//cluster := TStringList.Create; //The middle section
//results := TstringList.Create; //The combinations created
for x := 1 to length(substr) do begin
//hlplst.Add(substr[x]);
SetLength(bhlplst, bi + 1);
bhlplst[bi] := substr[x];
Inc(bi);
end ;
step1:
for i := 0 to {hlplst.Count}bi - 1 do begin
for n := 1 to length(astring) do begin
//npw := hlplst.strings[i]+astring[n];
npw := bhlplst[i] + astring[n];
//cluster.Add(npw);
SetLength(bcluster, bc + 1);
bcluster[bc] := npw;
Inc(bc);
if length(npw) >= startlen then
begin
//results.Add(npw);
//SetLength(bresults,br + 1);
//bresults[br] := npw;
//Inc(br);
Form1.Memo1.Lines.Add(npw);
end;
end ;
end ;
//hlplst.clear;
bi := 0;
SetLength(bhlplst, bi);
FreeMem(bhlplst);
//hlplst.addstrings(cluster);
SetLength(bhlplst, bc );
for counter := 0 to bc - 1 do
begin
bhlplst[bi] := bcluster[counter];
Inc(bi);
end;
//cluster.Clear;
bc := 0;
SetLength(bcluster, bc);
FreeMem(bcluster);
if length(npw) + 1 <= endlen then goto step1;
//hlplst.Clear;
bi := 0;
SetLength(bhlplst,bi);
FreeMem(bhlplst);
result := 0;
end ;
Open in new window