Delphi disassembler

Where can I get a disassembler that can disassemble a .dcu file?
If not has anybody had any success disassembling one working at the machine code level?

I would like to end up with the source code for the LoadFromStream method of a TTreeView, and also to find a way to disable the ToolTip in a TTreeview. I'm using Delphi3.
frogAsked:
Who is Participating?
 
EvarestConnect With a Mentor Commented:
This is the code of TTreeView.LoadFromStream which calls this procedure.

function TTreeStrings.GetBufStart(Buffer: PChar; var Level: Integer): PChar;
begin
  Level := 0;
  while Buffer^ in [' ', #9] do
  begin
    Inc(Buffer);
    Inc(Level);
  end;
  Result := Buffer;
end;

procedure TTreeStrings.LoadTreeFromStream(Stream: TStream);
var
  List: TStringList;
  ANode, NextNode: TTreeNode;
  ALevel, i: Integer;
  CurrStr: string;
begin
  List := TStringList.Create;
  Owner.BeginUpdate;
  try
    try
      Clear;
      List.LoadFromStream(Stream);
      ANode := nil;
      for i := 0 to List.Count - 1 do
      begin
        CurrStr := GetBufStart(PChar(List[i]), ALevel);
        if ANode = nil then
          ANode := Owner.AddChild(nil, CurrStr)
        else if ANode.Level = ALevel then
          ANode := Owner.AddChild(ANode.Parent, CurrStr)
        else if ANode.Level = (ALevel - 1) then
          ANode := Owner.AddChild(ANode, CurrStr)
        else if ANode.Level > ALevel then
        begin
          NextNode := ANode.Parent;
          while NextNode.Level > ALevel do
            NextNode := NextNode.Parent;
          ANode := Owner.AddChild(NextNode.Parent, CurrStr);
        end
        else TreeViewErrorFmt(sInvalidLevelEx, [ALevel, CurrStr]);
      end;
    finally
      Owner.EndUpdate;
      List.Free;
    end;
  except
    Owner.Owner.Invalidate;  // force repaint on exception
    raise;
  end;
end;

To disable the tooltips you might try
    SetComCtlStyle(MyTreeView, TVS_NOTOOLTIPS, Value);

with Value the boolean that states whether Tooltips are on
and SetComCtlStyle defined in ComCtrls:

procedure SetComCtlStyle(Ctl: TWinControl; Value: Integer; UseStyle: Boolean);
var
  Style: Integer;
begin
  if Ctl.HandleAllocated then
  begin
    Style := GetWindowLong(Ctl.Handle, GWL_STYLE);
    if not UseStyle then Style := Style and not Value
    else Style := Style or Value;
    SetWindowLong(Ctl.Handle, GWL_STYLE, Style);
  end;
end;

I'm not sure though what you'd be doing with the LoadFromStream method of TTreeView...

Kind regards,
Evarest
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Even if you decompile a program, you can't get the original source code.
BTW a good Decompiler is DeDe that decompiles dcu's and other in asm.
You can get it here http://www.softpedia.com/public/cat/5/1/5-1-5.shtml

F68 ;-)
0
 
EvarestCommented:
Oh yeah,

this code is for Delphi 7. It might not work under Delphi 3. SetComCtlStyle should work though...
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Wim ten BrinkSelf-employed developerCommented:
In The Delphi Magazine (http://www.thedelphimagazine.com) there are a few articles about DCU's and decyphering them. You'll need issues 46, 47 and 48 for the whole article, which is divided in three parts. It explains the DCU format for Delphi 3, 4 and 5. The biggest problem with DCU's are that they're partially encrypted or compressed, making them a bit hard to decypher. (Which Borland probably did on purpose.) There's a sample sourcecode with these articles, so all you have to do is order the archive CD-rom. ;-)

It makes good reading, too.

But I think that what you're trying to do should be solved in a much easier way. Besides, the Treeview is not a real Delphi control but a wrapper around a Windows control. There might be a treeview component out there does does do what you want it to do...
0
 
frogAuthor Commented:
Thanks everyone,
Why decompile a dcu?  Well D3 does not have TreeView1.ToolTips := False; so I thought if I could decompile Comctrls.dcu with a decompiler or just byte by byte I could patch out the ToolTip.
The load/save  to stream -
I am making a TreeView with a 6 state checkbox at each node and I want to load the states with the tree instead of loading the tree and then loading and propagating the states. The saved stream looks like it is just a tabbed text file but I wanted to make sure there was nothing more to it than that. I want to use the same format in my new load and save methods as is in the existing ones.
Thanks F68 and  Workshop_Alex I'll follow your links.
0
 
frogAuthor Commented:
Thanks  Evarest,
That's exacly what I wanted.
You wouldn't happen to have the SaveToStream as well would you?
It will save me reversing the LoadFrom.

Where did you get the source code??
I hope you didn't break into Mr Borland's house just for me!

0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Uh, wasn't this Q. related to disassembling? The accepted answer isn't related to the Question Title.

I agree that it solves your problem, so it's ok form me that you've accepted Evarest comment, but as this is a Knowledge Base i'd prefere that you ask to Community Support to edit the question title and add to it the part related to the LoadFromStream method of TTreeView, so it can be easly found by a search in Q. titles.
Something like 'Solution Title: Delphi disassembler or source code for LoadFromStream method of TTreeView.'

F68 ;-)


0
 
EvarestCommented:
Here is the SaveToStream part:

procedure TTreeStrings.SaveTreeToStream(Stream: TStream);
const
  TabChar = #9;
  EndOfLine = #13#10;
var
  i: Integer;
  ANode: TTreeNode;
  NodeStr: string;
begin
  if Count > 0 then
  begin
    ANode := Owner[0];
    while ANode <> nil do
    begin
      NodeStr := '';
      for i := 0 to ANode.Level - 1 do NodeStr := NodeStr + TabChar;
      NodeStr := NodeStr + ANode.Text + EndOfLine;
      Stream.Write(Pointer(NodeStr)^, Length(NodeStr));
      ANode := ANode.GetNext;
    end;
  end;
end;

As you said, just basic tabbed lines...

The sourcecode is included in any enterprise+ version of Delphi... That's where i got it from :-)

Wrt F68's comment: it should indeed be a good idea to change the title. However, I gave an answer that i thought to be the best to solve your problem " would like to end up with the source code for the LoadFromStream method of a TTreeView"...

Kind regards,
Evarest
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
-->However, I gave an answer that i thought to be the best to solve your problem
I absolutely agree with this and i've nothing to say about the accepted answer that is the right one.

But sometime when i do a search for something the result points me to a Q that in fact isn't related to the Q title, and i start to ' grin gran grun'...:))

Anyway it doesn't matter, as some link to disassemblers was already posted here :))

F68 ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.