"cg_chas" wrote:
>I am writing a disassembler and am considering what ways there might be to
> identify data bytes and data segments.
...
an MZ-exe-loader will add the segment (where it is actually loaded to)
to all relocation items.
> ... yet because I wanted try this on my own.
> Right now I am considering building a map using a multi-pass analysis
> that first attempts to identify data by examining the values being
> passed into registers including relative addresses.
It's not easy to determine if a passed value mean data- or code-label.
Me too work since long on an automated code-analyser ...
but I mainly use the faster manually way to figure on foreign code.
> Can anybody suggest some logic for identifying data bytes and segments?
> Any hints would be appreciated.
Full analysis need a complete static tracking of all code-parts and
all values of registers, stack- and accessed memory contents beside
full emulation/calculation for all CPU-instructions.
Many tables and passes are required, and it needs loop detection,
(worst case) detection of SMC with shared code/data ...
And not to forget that it need to know in deep detail how OS-ABI-
and BIOS-calls will modify registers (some guessing required here),
or even more worse are external referenced code-parts (.dll).
this method usually needs several thousand times more memory than
the code under test will occupy.
A restricted solution could just check on code flow and so isolate
data blocks, but this may let too many questions left open then.
The other possibility would be a dynamical check with a debugger,
but except for OllyDBG, I dont know one which can load relocated
and allow stepping through from the very start (but it may exist).
> Here's the code section decoded.
>
> 00000200 B80100 mov ax,0001h ; MOV immediate AX
this line above would show another immediate value when executed
0200 B8
0201 01 ;this is pointed to by the relative 0000:0001
0202 00
not a problem as long everything is relative to a known point ...
but what could we do if such a relocated ("guess where it actual is")
value become modified ? ie: by add/shift/mul ... So I learned to use
a dummy load segment for static analysis ie: 0x0800.
__
wolfgang