Solved

Delphi disassembler

Posted on 2004-09-07
9
3,212 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:frog
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
Comment Utility
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
 
LVL 4

Accepted Solution

by:
Evarest earned 125 total points
Comment Utility
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
 
LVL 4

Expert Comment

by:Evarest
Comment Utility
Oh yeah,

this code is for Delphi 7. It might not work under Delphi 3. SetComCtlStyle should work though...
0
 
LVL 17

Expert Comment

by:Wim ten Brink
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:frog
Comment Utility
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
 

Author Comment

by:frog
Comment Utility
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
 
LVL 22

Expert Comment

by:Ferruccio Accalai
Comment Utility
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
 
LVL 4

Expert Comment

by:Evarest
Comment Utility
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
 
LVL 22

Expert Comment

by:Ferruccio Accalai
Comment Utility
-->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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now