Log in

View Full Version : Disasm


xdream
January 1st, 2004, 18:32
Has anyone compiled olly's disasm/assemble to a dll i would really like to use it with my asm project. Thanx

focht
January 2nd, 2004, 06:52
Greetings,

if i understand you correctly, you want to use that functions written in C in your assembly program.

First you need a decent C/C++ compiler to produce a dynamic link library from the source files.
Assuming you have no commercial one available (VC++ ...) there are a few good and free C and C++ (optional) compilers available.

1) LCC-Win32 - Based on the retargatable LCC.
2) Borland free compiler - http://www.borland.com/bcppbuilder/freecompiler
("http://www.borland.com/bcppbuilder/freecompiler
")
3) GNU ports - MinGW, Cygwin...

The Borland product requires a free registration and also comes optionally with a debugger (you'll have to download it separately).
GNU ports are well maintained and confirm to ANSI C.
MinGW is a Win32 compiler and you can actually develop GUI programs with it.

Though, its a bit complecated to work with command line resource tools.
If you need a decent IDE with MinGW as backend, get Bloodshed compiler from
www.bloodshed.net ("www.bloodshed.net").

For the DLL-interface itself:

Normally you don't need a .def/.exp file at all (these are legacy methods). Instead, simply add "__declspec(dllexport)" to the declarations (in disasm.h):

extern "C"
{

__declspec(dllexport) short __stdcall foo(short x);

...

}

And the linker will automatically export it.

If you really need to use a .def file, the easiest method is to specify:

EXPORTS
foo

Regards,

A. Focht

xdream
January 2nd, 2004, 18:10
I dunno howto do it

focht
January 3rd, 2004, 12:33
Greetings,

uhm ... whats the problem with the learn-by-doing method?
If someone supplies the result you will never learn something new nor understand how things work.

1) Get tools to compile a dynamic library from C sources:

Download a free C/C++ compiler - it should be bundeled with some development environment to make things easier

http://www.bloodshed.net/dev/devcpp.html
("http://www.bloodshed.net/dev/devcpp.html
")

Dev-C++ 5.0 beta 8 (4.9.8.0) (12 MB) with Mingw/GCC 3.2
Dev-C++ version 4.9.8.0, includes full Mingw compiler system (GCC 3.2) and GDB 5.1

Install the stuff.
Download any latest service packs or updates to the product:

Latest update : version 4.9.8.5
http://bloodshed.net/dev/devcpp4985.zip
("http://bloodshed.net/dev/devcpp4985.zip
")

Now you are ready to setup a project.

2) Make a windows DLL project

* use the IDE's wizard to create a DLL project
(project new -> DLL)
* fill in project name ... for instance "disasm"
* set preference to "C" (the supplied disasm sources are C only)
* now save your project into some subdirectory you created (e.g. "disasmlib"

The wizard created some files for you.
You can "saveall" to really save em to disk.

Of course you can already compile it. It will produce a DLL with some dummy function exported.

Now you are ready to integrate olly's disasm sources.

3) Import olly disasm sources and modify to get things working

* unpack the disasm.zip archive into your project directory
* add the necessary *.c and *.h files to the project (context menu "add to project"
In this case you need to add: asmserv.c, assembl.c, disasm.c, disasm.h

Now if you try to build the project you get errors (of course)..
Hint: always "rebuild all" to clean up any remaining object files

To fix the errors you need to modify the main header file "disasm.h":
You need to remove or comment out the following construct:

<pre>
#if (char)0xFF!=255
#error Please set default char type to unsigned
#endif
</pre>

This is not understood by most compiler preprocessors.

The pow10l function is not supplied by most compiler libs, add the following to disasm.h header file to work around it:

<pre>
#define pow10l(a) pow(10.,(a))
</pre>

add code (top of disasm.h) to export the symbols/functions correctly:

<pre>
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
</pre>

Append the "DLLIMPORT" macro to all functions that should be exported:
e.g. "int Assemble(char *cmd,ulong ip,t_asmmodel *model,int attempt,
int constsize,char *errtext);"
becomes "DLLIMPORT int Assemble(char *cmd,ulong ip,t_asmmodel *model,int attempt, int constsize,char *errtext);"
and so forth...

(you find em at bottom of disasm.h file)

In your dllmain.c file (generated by IDE) remove the include stuff and replace it with the include stuff from disasm-package "main.c":

<pre>
#define STRICT
#define MAINPROG // Place all unique variables here

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <dir.h>
#include <math.h>
#include <float.h>
#pragma hdrstop

#include "disasm.h"
</pre>

Remove the dummy function (generated) from dllmain.c too.
Now your dllmain.c source file contains only a DllMain() which is ok.

To force the compiler to "char = unsigned char" option, add the "-funsigned-char
" option to the compiler parameters (project options)

Voila ... you are able to compile the sources to a clean win32 dll.
If you dump the exports of the newly created "disasm.dll" (using some PE tool like dependency walker) you will see all exports fine.

To really verify if things work you should create a simple C console client, which consumes the dll.
It is not that hard ...

Best Regards,

A. Focht