Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » MSIL » General » Downloads
 
Add your own
alternative version

ILRewriting for beginners

, 27 Sep 2012 Ms-PL
Runtime IL-Rewriting can be used to add behavior such as logging to applications, or redirect calls from one API to another. This article and accompanying source code explains how to substitute a method call at runtime.
ILRewriting_demo-noexe.zip
ILRewriting_demo
ILRewriting_demo.zip
ILRewriteProfiler.dll
InterceptApp.exe
InterceptLib.dll
SampleApp1.exe
ILRewriting_src.zip
ILRewriting_src
ILEmitTest
Properties
ILRewriteProfiler
exports.def
ILRewriteProfiler.vcxproj.filters
ILRewriteProfiler.vcxproj.user
InterceptApp
app.aps
app.ico
InterceptApp.vcxproj.filters
InterceptApp.vcxproj.user
InterceptLib
InterceptLib.snk
Properties
SampleApp1
Properties
SampleApp1.snk

/* this ALWAYS GENERATED file contains the definitions for the interfaces */


 /* File created by MIDL compiler version 7.00.0555 */
/* at Sun Sep 09 08:03:26 2012
 */
/* Compiler settings for ILRewriteProfiler.idl:
    Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555 
    protocol : dce , ms_ext, c_ext, robust
    error checks: allocation ref bounds_check enum stub_data 
    VC __declspec() decoration level: 
         __declspec(uuid()), __declspec(selectany), __declspec(novtable)
         DECLSPEC_UUID(), MIDL_INTERFACE()
*/
/* @@MIDL_FILE_HEADING(  ) */

#pragma warning( disable: 4049 )  /* more than 64k source lines */


/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#endif

#include "rpc.h"
#include "rpcndr.h"

#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif // __RPCNDR_H_VERSION__

#ifndef COM_NO_WINDOWS_H
#include "windows.h"
#include "ole2.h"
#endif /*COM_NO_WINDOWS_H*/

#ifndef __ILRewriteProfiler_h_h__
#define __ILRewriteProfiler_h_h__

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

/* Forward Declarations */ 

#ifndef __ILRewriteProfiler_FWD_DEFINED__
#define __ILRewriteProfiler_FWD_DEFINED__
typedef interface ILRewriteProfiler ILRewriteProfiler;
#endif 	/* __ILRewriteProfiler_FWD_DEFINED__ */


#ifndef __ILRewriteProfilerImpl_FWD_DEFINED__
#define __ILRewriteProfilerImpl_FWD_DEFINED__

#ifdef __cplusplus
typedef class ILRewriteProfilerImpl ILRewriteProfilerImpl;
#else
typedef struct ILRewriteProfilerImpl ILRewriteProfilerImpl;
#endif /* __cplusplus */

#endif 	/* __ILRewriteProfilerImpl_FWD_DEFINED__ */


/* header files for imported files */
#include "oaidl.h"
#include "ocidl.h"

#ifdef __cplusplus
extern "C"{
#endif 


#ifndef __ILRewriteProfiler_INTERFACE_DEFINED__
#define __ILRewriteProfiler_INTERFACE_DEFINED__

/* interface ILRewriteProfiler */
/* [helpstring][oleautomation][uuid][object] */ 


EXTERN_C const IID IID_ILRewriteProfiler;

#if defined(__cplusplus) && !defined(CINTERFACE)
    
    MIDL_INTERFACE("C546F9ED-7767-43A3-BCF8-87426C1E1343")
    ILRewriteProfiler : public IUnknown
    {
    public:
    };
    
#else 	/* C style interface */

    typedef struct ILRewriteProfilerVtbl
    {
        BEGIN_INTERFACE
        
        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
            ILRewriteProfiler * This,
            /* [in] */ REFIID riid,
            /* [annotation][iid_is][out] */ 
            __RPC__deref_out  void **ppvObject);
        
        ULONG ( STDMETHODCALLTYPE *AddRef )( 
            ILRewriteProfiler * This);
        
        ULONG ( STDMETHODCALLTYPE *Release )( 
            ILRewriteProfiler * This);
        
        END_INTERFACE
    } ILRewriteProfilerVtbl;

    interface ILRewriteProfiler
    {
        CONST_VTBL struct ILRewriteProfilerVtbl *lpVtbl;
    };

    

#ifdef COBJMACROS


#define ILRewriteProfiler_QueryInterface(This,riid,ppvObject)	\
    ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) 

#define ILRewriteProfiler_AddRef(This)	\
    ( (This)->lpVtbl -> AddRef(This) ) 

#define ILRewriteProfiler_Release(This)	\
    ( (This)->lpVtbl -> Release(This) ) 


#endif /* COBJMACROS */


#endif 	/* C style interface */




#endif 	/* __ILRewriteProfiler_INTERFACE_DEFINED__ */



#ifndef __ILRewriteProfilerLib_LIBRARY_DEFINED__
#define __ILRewriteProfilerLib_LIBRARY_DEFINED__

/* library ILRewriteProfilerLib */
/* [helpstring][version][uuid] */ 


EXTERN_C const IID LIBID_ILRewriteProfilerLib;

EXTERN_C const CLSID CLSID_ILRewriteProfilerImpl;

#ifdef __cplusplus

class DECLSPEC_UUID("941EC77E-F7C0-42C8-84E1-15FEFA3CE96F")
ILRewriteProfilerImpl;
#endif
#endif /* __ILRewriteProfilerLib_LIBRARY_DEFINED__ */

/* Additional Prototypes for ALL interfaces */

/* end of Additional Prototypes */

#ifdef __cplusplus
}
#endif

#endif


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Mattias Högström
Architect Visma Software AB
Sweden Sweden
Mattias works at Visma, a leading Nordic ERP solution provider. He has good knowledge in C++/.Net development, test tool development, and debugging. His great passion is memory dump analysis. He likes giving talks and courses.
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411023.1 | Last Updated 27 Sep 2012
Article Copyright 2012 by Mattias Högström
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid