home *** CD-ROM | disk | FTP | other *** search
- /*++
-
- Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
-
- Module Name:
-
- jexefmt.h
-
- Abstract:
-
- The Microsoft VM has the ability to load .class files and other
- Java visible resource files (images,audio clips,etc...) from Win32 PE
- image files (.exe and .dll files). In order for the VM to be able to
- find Java resources from within a PE, they must be stored within it as
- Win32 resources. This header file describes the format of the data
- that must be stored within the resources of a PE image in order for
- the VM to locate Java resources within that image. This format is
- referred to as the exegen format herein.
-
- Details:
-
- How the VM finds Win32 modules containing Java resources
- --------------------------------------------------------
-
- Assuming that you have a Win32 PE image that has Java resources bound
- to it, there are three ways to tell the VM that it should look for
- resources within that module:
-
- 1. If the resources are bound into a DLL, then that DLL can be placed
- on the classpath. The syntax is the same as how you would add a
- .zip file to the classpath. The '.dll' extension must be specified.
- There is a restriction on how a DLL must be built in order to be
- placed on the classpath. In particular, the resource containing
- the file directory must be stored within a resource with a specific
- ID (see below).
-
- 2. The COM interface IJavaExecute2::SetClassSource can be used to add
- a Win32 module to the list of locations where the VM searches for
- Java resources. See javaexec.h.
-
- 3. The RNI method AddModuleResourceClassSource can also be used to
- add a Win32 module to the list of locations where the VM searches
- for Java resources. See native.h.
-
-
- Different versions of the exegen format
- ---------------------------------------
-
- There currently are two versions of the exegen format. The original
- format, version 1, only supported .class files, and could not store
- arbitrarily named resources. The VMs of the IE4 era and before
- (anything earlier than VM version 4.79.2582) only support the version
- 1 format. Newer VMs support the version 2 format which adds the
- ability to store non-class resources (images files,etc...). The
- version 1 format also required that all of the data be stored within
- a single Win32 resource, the version 2 format removes this
- restriction.
-
-
- Version 1 format
- ----------------
-
- All classes are stored in a single Win32 binary resource within the
- PE. This resource begins with a table that lists the names of the
- files contained within the resource, and information that indicates
- where the raw bits for those files are located. The actual data for the
- contained files follows this table.
-
- If IJavaExecute2::SetClassSource or AddModuleResourceClassSource is used
- to tell the VM about the module, then this resource can be stored with
- any resource ID (although the resource type must be RT_RCDATA), since
- those APIs allow you to specify the resource ID. If building a DLL to
- be placed on the classpath, then this resource must be stored with a
- resource ID of 1000 (JEX_DEFAULT_CLASS_RESOURCE_ID), and the resource
- type must be RT_RCDATA.
-
- The layout of the this resource consists of three sections, and is laid
- out in this order:
-
- [JEXHEADER]
- [FILEINFO SECTION]
- [RAW DATA SECTION]
-
-
- 1. The resource begins with a header that contains a signature, a
- format version, flags, and a count of the number of class files
- contained within the resource. The layout of the header is defined
- in the JEXHEADER structure. The dwFormatVersion of the JEXHEADER
- structure must be set to 1 for the version 1 format.
-
- 2. Immediately following the header is an array of file information
- structures. The number of elements in this list is equal to the
- cNumFiles field in the header. The format of these structures is
-
- The layout of each of these file information structures is defined
- in the JEXFILEINFOV1 structure. Each specifies the name and location
- of a class file that is contained within the resource.
-
- Note that the dwNameOffset field points to the name of the class file.
- This name must be in UTF8 form. Forward slashes must be used as
- package separators. The name is the class name, not the name of a
- class file, so do not append a '.class' onto the end. So, for
- example, the following is correct:
-
- 'java/lang/Class'
-
- But these are not:
-
- 'java\lang\Class'
- 'java.lang.Class'
- 'java/lang/Class.class'
-
- 3. Following the list of JEXFILEINFOV1 structures is the string data for
- the class names, and raw binary data of the class files. Note that
- there is no implied ordering on this data. The only thing that must
- hold is that the resource offsets in the JEXFILEINFOV1 structures
- must point to the proper data. The jexegen tool happens to place
- all of the string data immediately after the file information list,
- followed by the raw binary data of the class files, but there is no
- reason that any other generation tool needs to follow this layout.
-
-
- Version 2 format
- ----------------
-
- The exegen version 2 format adds two features that the version 1 format
- did not support.
-
- 1. The ability to store arbitrarily named resources within the module.
- This allows image files, audio clips, etc... to be stored in addition
- to class files. These named resources can be retrieved from the
- Java side with any APIs which can load classpath relative data (such
- as java.lang.Class.getResourceAsStream).
-
- 2. The ability to store the class/resource data in multiple Win32
- resources. The version format required that all class data be
- contained within the exegen resource. The version 2 format allows
- the class/resource data in Win32 resources other than the primary
- exegen resource. This allows individual Java resources to be stored
- as individual Win32 resources. Amongst other things, this opens up
- the possibility to utilize Win32 internationalization of resources on
- Java resources.
-
- As with the version 1 format, there is a primary exegen resource that
- contains the JEXHEADER and file information structures (although, the
- structure of these file information blocks has changed). The rules for
- how the VM locates this information have not changed. The resource
- identifier specified with either IJavaExecute2::SetClassSource or
- AddModuleResourceClassSource refers to this primary resource. This main
- resource must be stored as resource ID JEX_DEFAULT_CLASS_RESOURCE_ID in
- DLLs intended for the classpath.
-
- The layout of the main resource is essentially the same as before. A
- header, followed by a list of file information structures, followed by
- string data and possibly file data.
-
- The JEXHEADER structure remains unchanged, with the exception that the
- dwFormatVersion field must be set to 2.
-
- Following the header is a list of JEXFILEINFOV2 structures. The number
- of elements in this list is determined by the cNumFiles field in the
- header. These are similar to the JEXFILEINFOV1 structures, with the
- addition of two fields (ResourceID and ResourceType) which specify the
- Win32 resource which contains the bits for each Java resource.
-
- Following the list of JEXFILEINFOV2 structures is the string data for the
- file names, and resource names (if any). Some of the java resource files
- may be found here as well, although all of the file data may be found in
- other resources.
-
- Note that the fields ResourceID and ResourceType do not contain Win32
- resource IDs. See the JEXRESID type for details of how map these
- values to Win32 resource IDs.
-
- As in the version 1 format, the dwNameOffset field in the JEXFILEINFOV2
- structure is an offset to the name of the Java resource in UTF8 form.
- Unlike the original format, this name is file name not a class name.
- Class files must be stored with the '.class' extension. Forward slashes
- are used as package separators. For example, the following is correct:
-
- 'java/lang/Class.class'
-
- But these are not:
-
- 'java\lang\Class.class'
- 'java.lang.Class.class'
- 'java/lang/Class'
-
-
- The version 2 format gives a good deal of flexibility in how to layout
- the Java resources within the exe/dll file.
-
- 1. Just like in the original format, the files can exist in the main
- resource. The ResourceID and ResourceType fields of the
- corresponding JEXFILEINFOV2 structures need to be set to
- JEX_MAINRESOURCE_MARKER. The cbFileSize and dwDataOffset fields
- need to be filled in to specify where in the main resource the
- resource file is located.
-
- 2. You can have a one-to-one mapping between a java resource file and a
- Win32 resource that it is located in. ResourceID and ResourceType
- need to contain the proper values to point to the Win32 resource
- (either by name or integer IDs). cbFileSize should be set to
- JEX_USE_RESOURCE_LENGTH to indicate that the size of the java
- resource is the same as the Win32 resource that it is found in.
- dwDataOffset should be 0.
-
- 3. You can have external Win32 resources (that is, not the main resource)
- that contain multiple java resources. ResourceID and ResourceType
- point to the Win32 resource, and dwDataOffset and cbFileSize specify
- which portion of that Win32 resource contains the data for the
- Java resource.
-
- --*/
-
- #ifndef __HEADER_JEX
- #define __HEADER_JEX
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- // Default resource ID for the main exegen resource. Unless otherwise
- // specified, the main data resource is looked for within a given PE at
- // this ID (the type is RT_RCDATA). DLLs on the classpath must store
- // their exegen data at this resource ID.
-
- #define JEX_DEFAULT_CLASS_RESOURCE_ID 1000
-
- // Signature the begins the main exegen resource data.
-
- #define JEX_RESOURCE_SIGNATURE 0x43524E44
-
- // Resource Identifiers found in the JEXFILEINFOV2 structures.
- // Used to specify resource name IDs and resource type IDs.
- // Should be interpreted as follows:
- //
- // - If set to 0xFFFFFFFF (JEX_MAINRESOURCE_MARKER), then indicates
- // the main resource (the resource with the JEXHEADER in it).
- //
- // - If the high bit is set, then the remainder of the high word
- // should be zeros, and the low word is a numeric Win32
- // resource identifier. Use MAKEINTRESOURCE on the low word.
- //
- // - Otherwise the value is interpreted as an offset from the
- // beginning of the main resource to a null-terminated Unicode
- // string which contains the name of the resource ID or type.
-
- typedef DWORD JEXRESID;
-
- // Special case value for JEXRESIDs. Specifies the main resource.
-
- #define JEX_MAINRESOURCE_MARKER 0xFFFFFFFF
-
- // Header found at the beginning of the main exegen data resource.
- //
- // dwSignature - must be JEX_RESOURCE_SIGNATURE.
- //
- // cNumFiles - indicates the number of file info structs
- // following the header. The exact type of these
- // file info structs depends on dwFormatVersion.
- //
- // dwFormatVersion - Currently must be either 1 or 2.
- //
- // dwFlags - Currently unused, must be set to 0.
-
- typedef struct
- {
- DWORD dwSignature;
- DWORD cNumFiles;
- DWORD dwFormatVersion;
- DWORD dwFlags;
- }
- JEXHEADER, *PJEXHEADER;
-
- // Exegen version 1 file info structs. A list of these follow
- // the JEXHEADER iff the dwFormatVersion field of the header is
- // set to 1. Each one of these describes a class file that is
- // contained within the jexegen'd PE image.
- //
- // NB: All data is contained within the main resource, so all
- // offsets are relative to the beginning of the main resource.
- //
- // dwNameOffset - Offset from the beginning of the main resource
- // to a null terminated UTF8 string which contains
- // the name of the class file. The names should
- // not contain a '.class' extension. Forward slashes
- // ('/') must be used as package separators.
- //
- // dwDataOffset - Offset from the beginning of the main resource
- // to the data for this class file.
- //
- // dwDataSize - Length of the this class file in bytes.
-
- typedef struct
- {
- DWORD dwNameOffset;
- DWORD dwDataSize;
- DWORD dwDataOffset;
- }
- JEXFILEINFOV1, *PJEXFILEINFOV1;
-
- // Exegen version 2 file info structs. A list of these follow
- // the JEXHEADER iff the dwFormatVersion field of the header is
- // set to 2. Each one of these describes a java resource file
- // (class file,image file,etc...) that is contained within the
- // jexegen'd PE image.
- //
- // NB: Unlike the V1 format, the data for each java resource file
- // may exist in Win32 resources other than the main one. The
- // ResourceID and ResourceType fields specify which resource contains
- // the bits for the file.
- //
- // dwNameOffset - Offset from the beginning of the main resource
- // to a null terminated UTF8 string which contains
- // the name of the java resource. Unlike the V1
- // format the name must be a complete name (class
- // files must be terminated with a '.class' extension).
- // Forward slashes ('/') must be used as package separators.
- //
- // dwDataOffset - Offset from the beginning of the owning resource
- // to the data for this java resource. Must be 0 if
- // dwDataSize is set to 0xFFFFFFFF.
- //
- // dwDataSize - If set to 0xFFFFFFFF (JEX_USE_RESOURCE_LENGTH),
- // then the length of the java resource is the size of
- // the Win32 resource that it lives within. Otherwise,
- // this value is simply the length of the java resource
- // in bytes.
- //
- // ResourceID
- // ResourceType - These two fields specify the Win32 resource within
- // the exegen'd PE image which contains the bits for
- // this java resource. See JEXRESID for details of how
- // to map these values to an actual Win32 resource.
-
- typedef struct
- {
- DWORD dwNameOffset;
- DWORD cbFileSize;
- DWORD dwDataOffset;
- JEXRESID ResourceID;
- JEXRESID ResourceType;
- }
- JEXFILEINFOV2, *PJEXFILEINFOV2;
-
- // Special case value for the JEXFILEINFOV2.cbFileSize field.
- // Indicates that the size of the file is that same as the size
- // of the Win32 resource that it lives in.
-
- #define JEX_USE_RESOURCE_LENGTH 0xFFFFFFFF
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif // __HEADER_JEX
-
-