?
Solved

Delphi disassembler

Posted on 2004-09-07
9
Medium Priority
?
3,249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 11994771
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 500 total points
ID: 11994888
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
ID: 11994894
Oh yeah,

this code is for Delphi 7. It might not work under Delphi 3. SetComCtlStyle should work though...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11997041
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
 

Author Comment

by:frog
ID: 12004133
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
ID: 12004185
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 23

Expert Comment

by:Ferruccio Accalai
ID: 12004193
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
ID: 12004679
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 23

Expert Comment

by:Ferruccio Accalai
ID: 12004721
-->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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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