⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eventlog.java

📁 用于Java 组件和通过Windows COM 对象或Windows DLL 来公开的组件之间的互操作
💻 JAVA
字号:
//******************************************************************
// Released under the DevelopMentor OpenSource Software License.
// Please consult the LICENSE file in the project root directory,
// or at http://www.develop.com for details before using this
// software.
//******************************************************************

package com.develop.jawin.win32;

import com.develop.jawin.*;
import com.develop.jawin.marshal.*;
import com.develop.io.*;
import com.develop.util.*;
import java.io.*;
import java.util.*;

public class EventLog implements MarshalConstants
{
  static private final FuncPtr fpRES;
  static private final FuncPtr fpDES;
  static private final FuncPtr fpRE;
  static private final FuncPtr fpCEL;
  static private final FuncPtr fpOEL;
  static private final FuncPtr fpGOELR;
  static private final FuncPtr fpGNOELR;
  static private final FuncPtr fpREL;
  static 
  {
    try {
      fpRES = new FuncPtr("ADVAPI32.DLL", "RegisterEventSourceW");
      fpDES = new FuncPtr("ADVAPI32.DLL", "DeregisterEventSource");
      fpRE = new FuncPtr("ADVAPI32.DLL", "ReportEventW");
      fpOEL = new FuncPtr("ADVAPI32.DLL", "OpenEventLogW");
      fpCEL = new FuncPtr("ADVAPI32.DLL", "CloseEventLog");
      fpGOELR = new FuncPtr("ADVAPI32.DLL", "GetOldestEventLogRecord");
      fpGNOELR = new FuncPtr("ADVAPI32.DLL", "GetNumberOfEventLogRecords");
      fpREL = new FuncPtr("ADVAPI32.DLL", "ReadEventLogW");
    } catch (COMException ce) {
      throw new COMError("Unable to load event log entry points");
    }
  }
		
  public static int RegisterEventSource(String serverName, String sourceName) 
    throws COMException, IOException
  {
    return SharedStubs.invokeGG_I(serverName, sourceName, fpRES.getPeer(), CHECK_NULL);
  }

  public static int OpenEventLog(String serverName, String sourceName) 
    throws COMException, IOException
  {
    return SharedStubs.invokeGG_I(serverName, sourceName, fpOEL.getPeer(), CHECK_NULL);
  }

  public static int DeregisterEventSource(int handle) 
    throws COMException, IOException
  {
    return SharedStubs.invokeI_I(handle, fpDES.getPeer(), CHECK_NULL);
  }

  public static int CloseEventLog(int handle) 
    throws COMException, IOException
  {
    return SharedStubs.invokeI_I(handle, fpCEL.getPeer(), CHECK_NULL);
  }
	
  public static int GetOldestEventLogRecord(int handle) 
  {
    return SharedStubs.invokeIO(handle, fpGOELR.getPeer(), CHECK_NULL);
  }

  public static int GetNumberOfEventLogRecords(int handle) 
  {
    return SharedStubs.invokeIO(handle, fpGNOELR.getPeer(), CHECK_NULL);
  }
	
  public static int ReportEvent(int log, int type, int category,
				int id, String event)
    throws COMException, IOException
  {
    NakedByteStream nbs = new NakedByteStream();
    LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
    //top level args
    leos.writeInt(log);
    leos.writeInt(type);
    leos.writeInt(category);
    leos.writeInt(id);
    leos.writeInt(0); 
    leos.writeInt(1); 	//number of Strings in array
    leos.writeInt(0);
    leos.writeInt(0);       //offset of String array	
    leos.writeInt(0);
    Object[] strings = new Object[] { new String[] { event } };
    byte[] res = GenericStub.win32Invoke(fpRE.getPeer(), 
					 "B28T4I:T1:", 
					 36, 40,
					 nbs.getInternalBuffer(), 
					 strings);
    return StructConverter.bytesIntoInt(res, 0);
  }

  /*
    HANDLE hEventLog,                // handle to event log
    DWORD dwReadFlags,               // how to read log
    DWORD dwRecordOffset,            // offset of first record
    LPVOID lpBuffer,                 // buffer for read data
    DWORD nNumberOfBytesToRead,      // bytes to read
    DWORD *pnBytesRead,              // number of bytes read
    DWORD *pnMinNumberOfBytesNeeded  // bytes required
  */
  public static byte[] RawReadEventLog(int handle, int flags, int offset)
    throws IOException, COMException
  {
    NakedByteStream nbs = new NakedByteStream();
    LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
    //top level args
    leos.writeInt(handle);
    leos.writeInt(flags);
    leos.writeInt(offset);
    byte[] sizeRes = GenericStub.win32Invoke(fpREL.getPeer(), 
					     "IIIAkAA:T8:L24n4", 
					     28, 28,
					     nbs.getInternalBuffer(), 
					     null);
    int size = StructConverter.bytesIntoInt(sizeRes, 0);
    leos.writeInt(size);
    byte[] res = GenericStub.win32Invoke(fpREL.getPeer(), 
					 "IIIM" + size + "IAA:T3:L12n" + size, 
					 28, 28,
					 nbs.getInternalBuffer(), 
					 null);
    return res;
  }

  public static EVENTLOGRECORD ReadEventLog(int handle, int flags, int offset)
    throws IOException, COMException
  {
    byte[] rawRecord = RawReadEventLog(handle, flags, offset);
    return new EVENTLOGRECORD(rawRecord);
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -