home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magazyn Amiga Shareware Floppies
/
ma32.dms
/
ma32.adf
/
xfd-lib
/
autodoc
/
xfdmaster.doc
Wrap
Text File
|
1994-03-27
|
15KB
|
482 lines
TABLE OF CONTENTS
xfdmaster.library/--Overview--
xfdmaster.library/xfdAllocBufferInfo
xfdmaster.library/xfdAllocSegmentInfo
xfdmaster.library/xfdDecrunchBuffer
xfdmaster.library/xfdDecrunchSegment
xfdmaster.library/xfdFreeBufferInfo
xfdmaster.library/xfdFreeSegmentInfo
xfdmaster.library/xfdGetErrorText
xfdmaster.library/xfdRecogBuffer
xfdmaster.library/xfdRecogSegment
xfdmaster.library/xfdTestHunkStructure
xfdForeman/--Overview--
xfdSlave/--Overview--
xfdSlave/xfds_DecrunchBuffer
xfdSlave/xfds_DecrunchSegment
xfdSlave/xfds_RecogBuffer
xfdSlave/xfds_RecogSegment
xfdmaster.library/--Overview-- xfdmaster.library/--Overview--
This section describes the usual way how to use xfdmaster.library from your
own applications.
If you want to decrunch files from a buffer, do it like this:
1. Call xfdAllocBufferInfo().
2. Get file size, allocate buffer with that size and load file to buffer.
3. Call xfdRecogBuffer() with xfdbi_SourceBuffer and xfdbi_SourceBufLen
initialized.
4. Check xfdbi_PackerFlags for XFDPFB_PASSWORD, go on with 6. if not set.
5. Get password (maximum length is xfdbi_MaxSpecialLen) and store a pointer
to it in xfdbi_Special.
6. Initialize xfdbi_TargetBufMemType and call xfdDecrunchBuffer().
7. Release memory of xfdbi_SourceBuffer.
8. Work with decrunched file.
9. Release memory in xfdbi_TargetBuffer.
10. Call xfdFreeBufferInfo().
If you want to decrunch a segment, do it like this:
1. Call xfdAllocSegmentInfo().
2. LoadSeg() file.
3. Call xfdRecogSegment() with xfdsi_SegList initialized.
4. Check xfdsi_PackerFlags for XFDPFB_PASSWORD, go on with 6. if not set.
5. Get password (maximum length is xfdsi_MaxSpecialLen) and store a pointer
to it in xfdsi_Special.
6. Call xfdDecrunchSegment().
7. Work with decrunched segment list.
8. UnloadSeg() segment list.
10. Call xfdFreeSegmentInfo().
xfdmaster.library/xfdAllocBufferInfo xfdmaster.library/xfdAllocBufferInfo
NAME
xfdAllocBufferInfo -- allocate memory for BufferInfo structure
SYNOPSIS
bufferinfo = xfdAllocBufferInfo()
D0 -30
FUNCTION
Allocates a memory block large enough to hold all information of
the BufferInfo structure. Never do this in any other way for
compatibility with library updates.
INPUTS
None.
RESULT
bufferinfo - pointer to the BufferInfo structure or NULL if there
occured an error.
SEE ALSO
xfdFreeBufferInfo()
xfdmaster.library/xfdAllocSegmentInfo xfdmaster.library/xfdAllocSegmentInfo
NAME
xfdAllocSegmentInfo -- allocate memory for SegmentInfo structure
SYNOPSIS
segmentinfo = xfdAllocSegmentInfo()
D0 -42
FUNCTION
Allocates a memory block large enough to hold all information of
the SegmentInfo structure. Never do this in any other way for
compatibility with library updates.
INPUTS
None.
RESULT
segmentinfo - pointer to the SegmentInfo structure or NULL if there
occured an error.
SEE ALSO
xfdFreeSegmentInfo()
xfdmaster.library/xfdDecrunchBuffer xfdmaster.library/xfdDecrunchBuffer
NAME
xfdDecrunchBuffer -- decrunch a file from buffer
SYNOPSIS
success = xfdDecrunchBuffer (bufferinfo)
D0 -60 A0
FUNCTION
Decrunches a file to a separate buffer. You have to call
xfdRecogBuffer() first, only if this call was successful,
you may call xfdDecrunchBuffer().
You have to pass the type of memory that should be used for
the target buffer in xfdbi_TargetBufMemType.
Additionally you have to init the xfdbi_Special field with
a pointer to a special info buffer if any special flags are
set in the xfdbi_PackerFlags field. The contents of this
buffer depend on the type of special info (eg. password).
If the decrunching was successful, the following fields in
the BufferInfo structure will be initialized:
xfdbi_TargetBuffer - pointer to decrunched file buffer
xfdbi_TargetBufSaveLen - length of decrunched file (for saving etc.)
xfdbi_TargetBufLen - total length of allocated buffer
xfdbi_DecrAddress - if XFDPFB_ADDR is set in xfdbi_PackerFlags,
this contains the address where the crunched
file has been relocated to
xfdbi_JmpAddress - if XFDPFB_ADDR is set in xfdbi_PackerFlags,
this contains the address where to jump at
in order to run the file
INPUTS
bufferinfo - pointer to an initialized BufferInfo structure:
xfdbi_TargetBufMemType - type of memory for target buffer
xfdbi_Special - pointer to special info if required
RESULT
success - TRUE if decrunching was successful, FALSE if
anything went wrong.
NOTE
xfdDecrunchBuffer() allocates a buffer for the decrunched file,
but it doesn't release this memory afterwards. That is because
you first have to work with the decrunched file (what else?).
Therefore you have to do a call to exec.library/FreeMem() after
you finished work. Use the following parameters:
xfdbi_TargetBufLen - lenght of buffer in D0
xfdbi_TargetBuffer - pointer to buffer in A1
Don't forget:
xfdbi_TargetBufLen contains the length of the allocated memory
area, xfdbi_TargetBufSaveLen the length of the decrunched file
in that buffer.
xfdDecrunchBuffer() never touches the buffer that contains the
crunched file. It's again your task to release this after
decrunching.
SEE ALSO
xfdRecogBuffer()
xfdmaster.library/xfdDecrunchSegment xfdmaster.library/xfdDecrunchSegment
NAME
xfdDecrunchSegment -- decrunch a file from its segment list
SYNOPSIS
success = xfdDecrunchSegment (segmentinfo)
D0 -72 A0
FUNCTION
Decrunches a segment list. You have to call xfdRecogSegment()
first, only if this call was successful, you may call
xfdDecrunchSegment().
You have to init the xfdsi_Special field with a pointer to a
special info buffer if any special flags are set in the
xfdsi_PackerFlags field. The contents of this buffer depend on
the type of special info (eg. password).
If decrunching was successful, xfdsi_SegList holds a BPTR to
the decrunched segment list. The old segment list has been
released and/or replaced by the new one (depends on cruncher).
INPUTS
segmentinfo - pointer to an initialized SegmentInfo structure:
xfdsi_Special - pointer to special info if required
RESULT
success - TRUE if decrunching was successful, FALSE if
anything went wrong.
NOTE
If you no longer need the decrunched segment list, you may
release it by simply calling dos.library/UnloadSeg().
SEE ALSO
xfdRecogSegment()
xfdmaster.library/xfdFreeBufferInfo xfdmaster.library/xfdFreeBufferInfo
NAME
xfdFreeBufferInfo -- free memory of BufferInfo structure
SYNOPSIS
xfdFreeBufferInfo (bufferinfo)
-36 A1
FUNCTION
Deallocates the memory reserved via xfdAllocBufferInfo().
INPUTS
bufferinfo - pointer to BufferInfo structure
RESULT
None.
SEE ALSO
xfdAllocBufferInfo()
xfdmaster.library/xfdFreeSegmentInfo xfdmaster.library/xfdFreeSegmentInfo
NAME
xfdFreeSegmentInfo -- free memory of SegmentInfo structure
SYNOPSIS
xfdFreeSegmentInfo (segmentinfo)
-48 A1
FUNCTION
Deallocates the memory reserved via xfdAllocSegmentInfo().
INPUTS
segmentinfo - pointer to SegmentInfo structure
RESULT
None.
SEE ALSO
xfdAllocSegmentInfo()
xfdmaster.library/xfdGetErrorText xfdmaster.library/xfdGetErrorText
NAME
xfdGetErrorText -- get an ascii string from an error number
SYNOPSIS
string = xfdGetErrorText (error)
D0 -78 D0
FUNCTION
Whenever a call to xfdDecrunch??() or xfdRecog??() fails, you
receive an error number in the xfd??_Error field. This function
gets the corresponding ascii string to the occured error.
INPUTS
error - error number from xfd??_Error
RESULT
string - pointer to an ascii string that describes the error
SEE ALSO
xfdDecrunchBuffer(), xfdDecrunchSegment()
xfdmaster.library/xfdRecogBuffer xfdmaster.library/xfdRecogBuffer
NAME
xfdRecogBuffer -- examine buffer for crunched file
SYNOPSIS
success = xfdRecogBuffer (bufferinfo)
D0 -54 A0
FUNCTION
Examines a file for known crunchers. You pass a pointer to
the file buffer in xfdbi_SourceBuffer and the length of the
buffer in xfdbi_SourceBufLen.
If a crunched file has been recognized, the following fields
in the BufferInfo structure will be initialized:
xfdbi_PackerName - pointer to the name of the cruncher
xfdbi_PackerFlags - contains the packer type and additional
information (eg. password)
xfdbi_MaxSpecialLen - only used if any special flags are set
INPUTS
bufferinfo - pointer to an initialized BufferInfo structure:
xfdbi_SourceBuffer - pointer to file buffer
xfdbi_SourceBufLen - length of file buffer
RESULT
success - TRUE if a cruncher has been recognized, FALSE if
file is unknown.
xfdmaster.library/xfdRecogSegment xfdmaster.library/xfdRecogSegment
NAME
xfdRecogSegment -- examine segment list for crunched file
SYNOPSIS
success = xfdRecogSegment (segmentinfo)
D0 -66 A0
FUNCTION
Examines a segment list for known crunchers. You pass a BPTR
to the segment list in xfdsi_SegList.
If a crunched segment list has been recognized, the following
fields in the SegmentInfo structure will be initialized:
xfdsi_PackerName - pointer to the name of the cruncher
xfdsi_PackerFlags - contains the packer type and additional
information (eg. password)
xfdsi_MaxSpecialLen - only used if any special flags are set
INPUTS
segmentinfo - pointer to an initialized SegmentInfo structure:
xfdsi_SegList - BPTR to segment list
RESULT
success - TRUE if a cruncher has been recognized, FALSE if
segment list is unknown.
xfdmaster.library/xfdTestHunkStructure xfdmaster.library/xfdTestHunkStructure
NAME
xfdTestHunkStructure -- test hunks of executable file
SYNOPSIS
success = xfdTestHunkStructure (buffer, length)
D0 -84 A0 D0
FUNCTION
Checks an executable file for a valid hunk structure.
This is important for decrunching files, because an incomplete
or damaged file may cause a system crash.
INPUTS
buffer - pointer to the file buffer that should be checked
length - length of the file buffer
RESULT
success - TRUE if file is ok, FALSE if file is damaged.
NOTE 1
You don't have to call this function before trying to decrunch
a file, because xfdDecrunch??() does this already.
NOTE 2
It is really some kind of complicated to write a hunk checker
that supports all kinds of hunk structures because the DOS loader
is quite flexible with this subject. You may or may not skip
hunk_end, overlays aren't defined in any way, etc. Therefore this
checker has been made as compatible as possible, but will never
be perfect. It currently accepts more overlay types than
PowerPacker, but still has problems with files like LhASFX
executable archives etc.
The hunk structure of a non-overlayed file will nevertheless
be checked 100% correctly.
xfdForeman/--Overview-- xfdForeman/--Overview--
The xfdForeman structure is just some kind of header for external slaves.
It protects the slaves from being executed accidentally by having a small
piece of code (moveq #-1,d0 : rts) in the first 4 bytes.
The master can identify a valid bunch of external slaves by checking the
first few bytes of the file for the foreman identification.
Finally, a foreman holds the pointer to a linked list of slaves and thus
enables the master to work with these slaves.
xfdSlave/--Overview-- xfdSlave/--Overview--
The xfdSlave structure is the heart of the whole library system. Each slave
enables the master to recognize and decrunch a certain kind of packed file.
Therefore slaves have 4 entrypoints that are called from the master. These
4 routines have all one thing in common: the CPU registers D0/D1/A0/A1 are
so called scratch registers, they may change during execution, all other
registers must remain unchanged. CPU register A6 holds a pointer to the
xfdMasterBase structure. See chapters below for a description of the
4 slave routines. The name of the packer and the flags associated with
that packer are stored in xfds_PackerName and xfds_PackerFlags.
xfdSlave/xfds_DecrunchBuffer xfdSlave/xfds_DecrunchBuffer
NAME
xfds_DecrunchBuffer -- decrunch file from buffer to buffer
SYNOPSIS
result = xfds_DecrunchBuffer (bufferinfo)
D0 A0
FUNCTION
This is one main routine of the whole slave. The typical steps of
such a routine are:
- get length of decrunched file (exactly or a bit too much)
- allocate memory (with memtype from xfdbi_TargetBufMemType)
- decrunch file from xfdbi_SourceBuffer to xfdbi_TargetBuffer
- initialize all necessary parts of the xfdBufferInfo structure
- set xfdbi_Error if an error occurs
INPUTS
bufferinfo - a valid BufferInfo structure that successfully went
through a call to xfdRecogBuffer()
RESULT
result - TRUE if decrunching succeeded, FALSE if something went wrong
xfdSlave/xfds_DecrunchSegment xfdSlave/xfds_DecrunchSegment
NAME
xfds_DecrunchSegment -- decrunch segment list
SYNOPSIS
result = xfds_DecrunchSegment (segmentinfo)
D0 A0
FUNCTION
This is one main routine of the whole slave. The typical steps of
such a routine are:
- modify decrunch header to make it return to the caller
- call decrunch header
- release segments that are no longer necessary
- store BPTR to first hunk of decrunched segment list in
xfdsi_SegList
- set xfdsi_Error if an error occurs
INPUTS
segmentinfo - a valid SegmentInfo structure that successfully went
through a call to xfdRecogSegment()
RESULT
result - TRUE if decrunching succeeded, FALSE if something went wrong
xfdSlave/xfds_RecogBuffer xfdSlave/xfds_RecogBuffer
NAME
xfds_RecogBuffer -- recognize crunched file in buffer
SYNOPSIS
result = xfds_RecogBuffer (buffer, length)
D0 A0 D0
FUNCTION
This routine should examine the buffer for a crunched file.
First thing is to check if the size of the file allows it to be
crunched by the packer to be checked for. After that, simply
do some compares to figure out if the file has been crunched
or not.
INPUTS
buffer - pointer to a buffer that holds the crunched file
length - length of that buffer
RESULT
result - TRUE if packer has been recognized, else FALSE
xfdSlave/xfds_RecogSegment xfdSlave/xfds_RecogSegment
NAME
xfds_RecogSegment -- recognize crunched segment list
SYNOPSIS
result = xfds_RecogSegment (seglist)
D0 A0
FUNCTION
This routine should examine if a segment list is crunched.
You can check the whole segment list for correct lengths of hunks
and for contents of hunks if you like. There should be at least
3 comparations to determine the cruncher.
INPUTS
seglist - BPTR to first segment
RESULT
result - TRUE if packer has been recognized, else FALSE