📄 bplunit.pas
字号:
//i:=Pos('@',AsData);
//If i<>0 Then AsData:=Copy(AsData,i+1,Length(AsData)-i+2);
end;
function TBPL.GetSymMode: Byte;
var b : Byte;
begin
Result:=0;
If d3cb.checked Then b:=1 else b:=0;
Result:=Result+b;
If d4cb.checked Then b:=1 else b:=0;
Result:=Result+b*2;
If d5cb.checked Then b:=1 else b:=0;
Result:=Result+b*4;
If dcud6cb.checked Then b:=1 else b:=0;
Result:=Result+b*16;
end;
function TBPL.DCUGetSymMode: Byte;
var b : Byte;
begin
Result:=0;
If dcud3cb.checked Then b:=1 else b:=0;
Result:=Result+b;
If dcud4cb.checked Then b:=1 else b:=0;
Result:=Result+b*2;
If dcud5cb.checked Then b:=1 else b:=0;
Result:=Result+b*4;
If dcud2cb.checked Then b:=1 else b:=0;
Result:=Result+b*8;
If dcud6cb.checked Then b:=1 else b:=0;
Result:=Result+b*16;
end;
procedure TBPL.ParseFunctionName(var s: String);
var i : Integer;
sf,sp : String;
begin
{$IFDEF DEBUG}
Memo1.Lines.Add(s);
{$ENDIF}
i:=Pos('$',s);
// Saves function name
sf:=Copy(s,1,i-1);
// saves function params
sp:=Copy(s,i,Length(s)-i+1);
ParseExportName(sf);
If ParamCB.Checked Then ParseExportParam(sp);
If Copy(sp,1,2)='; ' Then sp:=Copy(sp,3,Length(sp)-2);
If Copy(sp,Length(s)-1,2)='; ' Then sp:=Copy(s,1,Length(sp)-2);
If Copy(sp,Length(s),1)=' ' Then sp:=Copy(s,1,Length(sp)-1);
If (Copy(sf,Length(sf),1)='.') Then sf:=sf+'Create';
If Not IncPCB.Checked Then sp:='';
s:=sf+'('+sp+')';
{$IFDEF DEBUG}
Memo1.Lines.Add(s);
Memo1.Lines.Add('');
{$ENDIF}
end;
procedure TBPL.FormCreate(Sender: TObject);
begin
ClassesList:=TStringList.Create;
end;
procedure TBPL.FormDestroy(Sender: TObject);
begin
ClassesList.Free;
end;
procedure TBPL.FileEditBeforeDialog(Sender: TObject; var Name: String;
var Action: Boolean);
var s : String;
begin
SetLength(s,100);
GetSystemDirectory(@s[1],length(s));
FileEdit.InitialDir:=s;
end;
procedure TBPL.FileEditChange(Sender: TObject);
begin
CommentEdit.Text:=GetPackageDescription(PChar(FileEdit.FileName));
SymFile.FileName:=ExtractFileDir(Application.ExeName)+'\DSF\'+ChangeFileExt(ExtractFileName(FileEdit.FileName),'.dsf');
end;
procedure TBPL.Panel2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
If (ssAlt in Shift) and (ssShift in Shift) and (ssCtrl in Shift)
Then ShowMessageFmt(' 5 bytes: %d %s 6 bytes: %d %s 7 bytes: %d %s 10 bytes: %d',[Glob_B5,#13,Glob_B6,#13,Glob_B7,#13,Glob_B10]);
end;
procedure TBPL.DCUFileEditChange(Sender: TObject);
begin
DCUCommentEdit.Text:=ExtractFileName(DCUFileEdit.FileName);
DCUSymFile.FileName:=ExtractFileDir(Application.ExeName)+'\DSF\'+ChangeFileExt(ExtractFileName(DCUFileEdit.FileName),'.dsf');
end;
procedure TBPL.Button2Click(Sender: TObject);
var TmpList, LogList : TStringList;
s : String;
iPos, idx, i, cnt, iCurrCnt : Integer;
//ImplParser : TImplementationParser;
NewParser : TNewDCU2DSFParser;
begin
LogMemo.Lines.Clear;
TmpList:=TStringList.Create;
LogList:=TStringList.Create;
Screen.Cursor:=crHourGlass;
DataB:=TMemoryStream.Create;
DataS:=TMemoryStream.Create;
CurrDCULbl.Caption:='';
CDCUPB.Max:=DCUFileEdit.DialogFiles.Count-1;
CDCUPB.Position:=0;
CDCUPB.Update;
DetailsPanel.Visible:=DCUFileEdit.DialogFiles.Count>1;
GlobiRecNum:=0;
GlobiFakeCount:=0;
Try
For idx:=0 to DCUFileEdit.DialogFiles.Count-1 do
Begin
CDCUPB.Position:=idx;
CDCUPB.Update;
CurrDCULbl.Caption:=ExtractFileName(DCUFileEdit.DialogFiles[idx]);
// STEP 0 - Disassembling File
DCULogMemo.Lines.Add('Disassembling '+ExtractFileName(DCUFileEdit.DialogFiles[idx])+' ...');
GlobPreParsOK:=False;
ProcessFile(DCUFileEdit.DialogFiles[idx],TmpList,True);
if not GlobPreParsOK
then LogList.Add(Format('Possible pre-parser failure in: %s warning:%d',[ExtractFileName(DCUFileEdit.DialogFiles[idx]),GlobPreParseWarning]));
DCULogMemo.Lines[0]:=DCULogMemo.Lines[0]+msg_done1;
// STEP 1 - Analizing and adding
DCULogMemo.Lines.Add('Analizing ...');
s:=TmpList.Text;
iPos:=POS('implementation',s);
TmpList.Text:=Copy(s,iPos+14,Length(s)-iPos-13);
DCULogMemo.Lines[1]:=DCULogMemo.Lines[1]+msg_done1;
// STEP 2 - Building DSF patterns
DCULogMemo.Lines.Add('Building DSF patterns ...');
GlobPreParseWarning:=$0;
NewParser.InitParse(TmpList,AddNewDCU_DSF);
Try
iCurrCnt:=GlobiRecNum;
iFakeCount:=0;
NewParser.ParseIt;
iCurrCnt:=GlobiRecNum+iFakeCount-iCurrCnt;
DCULogMemo.Lines[2]:=DCULogMemo.Lines[2]+msg_done1;
// STEP 3 - Verifying
//DCULogMemo.Lines.Add(msg_verifying_file);
cnt:=0;
for i:=0 to TMPList.Count-1 Do
begin
if Copy(TMPList[i],1,8)='function' then inc(cnt);
if Copy(TMPList[i],1,9)='procedure' then inc(cnt);
end;
if iCurrCnt<>cnt then
if GlobPreParseWarning=$DEDE
then LogList.Add(Format('File too compilated to parse: %s error: dasm',[ExtractFileName(DCUFileEdit.DialogFiles[idx])]))
else LogList.Add(Format('File too compilated to parse: %s skiped:%d',[ExtractFileName(DCUFileEdit.DialogFiles[idx]),cnt-iCurrCnt]));
Inc(GlobiFakeCount, iFakeCount);
Finally
DCUstatuLbl.Caption:='';
DCUstatuLbl.Update;
DCUPB.Position:=0;
DCUPB.Update;
End;
End; {For idx}
Finally
// STEP 4 - Saving DSF file
DCULogMemo.Lines.Add(msg_saveing_file);
if GlobiRecNum<>0
then SaveBPLSymbolFile(DataB,DataS,DCUSymFile.FileName,DCUGetSymMode,_PatternSize,GlobiRecNum,DCUCommentEdit.Text)
else ShowMessage('No DSF patterns to save!');
//SaveBPLSymbolFile(DataB,DataS,DCUSymFile.FileName,DCUGetSymMode,_PatternSize,GlobiRecNum,DCUCommentEdit.Text);
DCULogMemo.Lines[3]:=LogMemo.Lines[3]+msg_done1;
DCULogMemo.Update;
TmpList.Free;
if LogList.Count<>0
then LogList.SaveToFile(ChangeFileExt(DCUSymFile.FileName,'.log'));
LogList.Free;
DCUStatuLbl.Caption:=Format('%d DSF idents added. %d procs skiped (unnamed or long less than 7 bytes)',[GlobiRecNum,GlobiFakeCount]);
DCUStatuLbl.Update;
ShowMessage(msg_dsf_success);
DCULogMemo.Clear;
DataB.Free;
DataS.Free;
CurrDCULbl.Caption:='';
CDCUPB.Position:=0;
CDCUPB.Update;
Screen.Cursor:=crDefault;
DetailsPanel.Visible:=False;
End;
end;
procedure TBPL.AddNewDCU_DSF(sProcDecl: String; buffer: TSymBuffer;
size: Integer; Progress : Byte; bAddIT : Boolean);
var j : Byte;
s,sDCUName : String;
// To avoid the fucking out of memory
// when passing param of the proc as var param to other proc
buff : TSymBuffer;
begin
if not bAddIT then
begin
Inc(iFakeCount);
Exit;
end;
s:='';
For j:=1 to Length(sProcDecl) do
if sProcDecl[j]>=#32 then s:=s+sProcDecl[j];
if DCUParamCB.Checked Then s:=DCUFixParams(s);
if Copy(s,1,9)='procedure' then s:=Copy(s,10,Length(s)-9);
if Copy(s,1,8)='function' then s:=Copy(s,9,Length(s)-8);
// Skip procs that starts with '_NF_'
s:=Trim(s);
if Copy(s,1,4)='_NF_' then
begin
Inc(iFakeCount);
exit;
end;
sDCUName:=CurrDCULbl.Caption;
sDCUName:=Copy(sDCUName,1,Length(sDCUName)-3);
if ansiuppercase(sDCUName)+';'=ansiuppercase(Trim(s)) then s:='Initialization;';
s:=sDCUName+Trim(s);
if DCUExcludeCB.Checked then s:=DCUExculdeParamNames(s);
// To avoid the fucking out of memory
// when passing param of the proc as var param to other proc
Buff:=buffer;
If UnlinkCalls(buff) Then
Begin
DataB.WriteBuffer(buff[1],_PatternSize);
j:=Length(s);
DataS.WriteBuffer(j,1);
DataS.WriteBuffer(s[1],j);
Inc(GlobiRecNum);
DCUstatuLbl.Caption:=s;
DCUstatuLbl.Update;
end;
DCUPB.Position:=Progress;
DCUPB.Update;
Application.ProcessMessages;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -