This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how to store settings in resource
I have a record with strings, Integers, etc. This record is used as settings for a file that gets read later. How can I convert a record to binary data (or string) and save to it a RCDATA and read it back to a record? If possible native code and/or WinAPI only. Thanks for your help.
About RCDATA:
i ask google "resource editor opensource delphi"
and it told me http://melander.dk/reseditor/
This program surely can read and write resources.
The page's footer also contains links to three more opensource delphi programs that also can do it.
So i hope you would find what u need there. Among piles of other useful code :-)
But - WHAT RCDATA do you want to use ??? OF what file ? some DLL ? or your own project EXE ?
RCDATA is for reading, not writing. It is not typical use. If the DLL or EXE is loaded - you would not be given rights to write into file new RCDATA. And your own running EXe is always open.
About turning to binary - that is VERY dependent on data types u use. Before you would show the data - no one would be able to tell you for sure.
Most lazy approaches would be:
1) Make mirror class from TComponent with published properties mirroring record fields. Assign those properties from record and do TComponent.SaveToStream.
2) Use JsonObject from Progdigy to make text file in JSon format
3) use some XML to save/read. For example TXMLDocument in higher Delphi versions (but it has its gotchas if created with nil Owner) or Jedi CodeLib has XML.
You can search Torry.net for a lot of XML or JSON libs.
But best of all - Google for "serializing in Delphi" and find tutorial detailing the troubles and solutions.
Related
I have deveoped a custom file type, together with a custom editor (basically a tree with several data pages attached and a few extra buttons). OK, I can run it stand alone and that is fine, and even add it to the tools menu, but I would like to integrate it into the Delphi IDE so that my custom editor (or a similar new version) appears in the IDE, rather like a DFM file has a custom editor. I can find references to most extensions in the Delphi IDE, but not this one. Any guiding hands? Note that this is not a property or component editor (the file type has nothing to do with either of these) nor is it simply syntax highlighting of a text file.
AFAIK it currently isn't possible to reliably integrate a custom editor into the Delphi IDE. The required API simply isn't there. See QC89028 Custom Module support.
During the Delphi 2010 and XE betas I spent most my spare time trying to get a resource editor integrated. Although the effort had the official blessing of Embarcadero and got some, half hearted, support from the IDE engineer, I was never able to get them to deliver on their promises and surface the module API. I eventually abandoned the project.
Update: I've now checked my old correspondence regarding this and it turns out part of the problem was that IOTAModuleCreator (used to implement File|New for custom file types) and IOTAEditorContent (used to transfer data to/from the custom module) only supports text data. Binary data gets mangled.
You can probably do this via an IDE plugin that uses the ToolsAPI (see ToolsAPI.pas in the IDE's source folder (e.g. Program Files (x86)\Embarcadero\Studio\source\ToolsAPI\ToolsAPI.pas.)
For information on writing a plugin in general, see David G Hoyle's excellent blog. Once you know the basics - i.e., write a 'wizard' and get it to do something - you will need to work on integrating your editor.
I have never done this, and so I can't guarantee it is possible. However, some interfaces that look worth investigating and implementing are INTACustomEditorView, which represents a 'view' (file tab when that file is open - think the code editor, Welcome view, type library editor, etc) and IOTAEditorViewServices, to register your custom view. I do not know how you associate a view type with a file type, sorry - possibly something to do with the personality interfaces. You might also be interested in INTACustomEditorSubView which is what creates a tab on the bottom of a file.
Good luck, and if you find a solution please write here so that other people can learn too!
Am I correct in that Delphi 4 XE Pro does not supply any native way of reading XML documents? (TXMLDocument is Windows only) I have pondered about using TClientDataSet, but I am not sure if that is the right way to go.
Here is an example of what I want:
Readonly XML file that defines a list of contacts. In the XML file, it also contains e.g. file path to photo of contact.
Ideally I then want to show the data in e.g. a TListBox (which might mean I need to write my own logic for loading images in/out of memory.)
If validation is not required (as in the linked answer above), try
NativeXml
or
OmniXML
Both are free open source libraries for Delphi, however I have not checked if they can be used on other platforms.
Update: see http://www.kluug.net/omnixml.php and Windows & Mac XML library for delphi XE2
We are reversing Delphi internal structures, does anyone know of any good resource or other details about how Delphi executables are compiled and linked together and what is the layout of the various parts inside the final exe.
I am not looking for high level details like it has n sections.
I am looking for something (the following is 'made up') like section '.text' has 3 parts:
data (a)
pointers table (b)
code interleaved with data which can be identified by using mechanism (c)
etc,etc.
Ok, I am looking for references or knowledge about the structures. I already have the tools mentioned below, and a ton more to aid in reverse engineering this from scratch.
I should have mentioned that I know the resource layout as that is well documented. It's the internal compiled structures embedded in code and data sections I am after. (e.g. how RTTI info is compiled in, where is the mapping between event handlers and form resources, etc).
Start with using existing tools like IDR (Interactive Delphi Reconstructor) and IDA (the Interactive Disassembler) and the already mentioned PE Explorer.
I would also suggest compiling some simple executables and studying the disassembly of that.
The most identifiable parts of a Delphi or C++ Builder executable are the resources.
They will contain a resource section named RCDATA. This section contains the following:
A section named DVCLAL, which identifies the compiler's SKU, such as Personal, Professional or Enterprise.
A section named PACKAGEINFO, which contains a list of contained units and a flag for Delphi or C++ Builder
Individual resources for each DFM.
On some settings, compressors like UPX may hide these resources, so you won't be able to see them unless you decompress the executable.
It could be worthwhile to have a look at Jedi JCL. IIRC their traceback tools (jcldebug unit?) open binaries to recover debug info. It would at least teach the global structure of the file.
Some bits might be delphi version specific btw.
Downloading the evaluation version of PE-Explorer might be a good start too.
You can find all types in a Delphi module (exe or dll) because they are always prepended with a pointer to the structure itself. You can create a small app and scan the exe to see for yourself how to get that information. With type information comes good information where units are / where methods are etc etc.
Combine that information with the resources available (a good resource viewer can decode the binary resources in text for all forms /frames / datamodule ).
Now if you disassemble the application you can use the information from the resources / typeinfo to make sense of the assembly code found.
I have a quite old Windows application (1998) which is no longer maintained by the author and I don't have its source code. This application in one of its windows has a dropdown list widget where the user can choose one of the 4 predefined values (numbers). I need to add new predefined values there or change the widget to something that lets me introduce any value (some edit field or editable combobox).
Some other data about the application:
Probably written using some Borland tools, I guess it uses BDE and Paradox as its database.
There is a file with .mme extension in the directory. I unpacked it and it contains 5 files: .data, .rdata, .rsrc, .sdata, .text. I viewed them in a hex editor and they contain some text data but I don't know how to look for those predefined values. Since they are numbers it's probable that I will find just some other numbers.
I tried using RedEdit and XN Resource Editor but they show only the icon and version info.
I know my question is kind of vague, but if I don't find any solution to this I will have to rewrite the whole program, so I'm asking just in case there is a solution.
It might be possible to write another app that looks for this program, gets a handle to the window owning the drop-down box (if t's a native windows component), and then gets a handle to the drop-down box and use the Windows SendMessage API to manipulate the contents of the drop-down box.
http://msdn.microsoft.com/en-us/library/ms632595(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms644950(v=vs.85).aspx
It might require so much effort that it may be better to just rewrite the app!
If it is written with Borland tools, you can probably find out which one by searching the EXE for the string "Borland" - there should be a copyright string somewhere.
Once you know, find someone with Borland tools experience and have her find out if those numbers in the drop-down list happen to come out of a database table. If they do, try modifying that table, if not, rewrite the app :)
All exes compiled can be decompiled (but with some hardship )
but delphi application forms are saved as dfms inside exe which can be seen easily (with reshacker) (soooo easily ) can i overcome these problems ,first i thought of copying dfm data to oncreate procedure so i can hide my form information .
tell me a good solution for this ,
i do not like to use compressors
and my application is bit large so i cant port resourese one by one to a dll. i need an effective solution.
.dfm files are not stored as txt when they're linked into the final PE file. They are converted to a tagged binary format that is placed into an RCDATA Windows resource. For the images, they are stored as the raw binary. While building your application, the .dfm files can be stored as text or binary (right click the form designer and there is a selection for choosing one or the other). This only affects the format of the .dfm file itself. It has zero affect on its format once it is linked into your final binary.
You can try to convert the images to constant arrays (there are many tools that will read a binary and write out an array decl in various language formats) and use it as an include file. Another thing is to encrypt the images using a one-way algorithm like RSA or PGP. This won't keep someone from decrypting the image, but it will keep someone from replacing it since they won't have the private key.
If this is about protecting your applications images you are already on the losing side:
https://stackoverflow.com/questions/455623/how-can-i-prevent-users-from-taking-screenshots-of-my-application-window
It is always possible to make screenshots of a running application.