Porting Wevtapi.dll(retry) #723

Merged
merged 3 commits into from Nov 5, 2016

Conversation

Projects
None yet
2 participants
@sakamotodesu
Contributor

sakamotodesu commented Nov 3, 2016

Porting Wevtapi.dll(retry)
Porting Winevt.h
Adding Wevtutil

sakamotodesu added some commits Nov 3, 2016

Porting Wevtapi.dll
Porting Winevt.h
Adding Wevtutil
@matthiasblaesing

Don't be alarmed, there are a few left over pieces, but overall it looks good.

+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */

This comment has been minimized.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

Please adjust the license header. The project is dua-licensed as LGPL 2.1 or later and AL 2.0. The source files were missed when the relicensing happend, which will be corrected by:

#711

The intended header would be:

  /* Copyright (c) 2016 Minoru Sakamoto, All Rights Reserved
   * 
   * The contents of this file is dual-licensed under 2 
   * alternative Open Source/Free licenses: LGPL 2.1 or later and 
   * Apache License 2.0. (starting with JNA version 4.0.0).
   * 
   * You can freely decide which license you want to apply to 
   * the project.
   * 
   * You may obtain a copy of the LGPL License at:
   * 
   * http://www.gnu.org/licenses/licenses.html
   * 
   * A copy is also included in the downloadable source code package
   * containing JNA, in file "LGPL2.1".
   * 
   * You may obtain a copy of the Apache License at:
   * 
   * http://www.apache.org/licenses/
   * 
   * A copy is also included in the downloadable source code package
   * containing JNA, in file "AL2.0".
   */
@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

Please adjust the license header. The project is dua-licensed as LGPL 2.1 or later and AL 2.0. The source files were missed when the relicensing happend, which will be corrected by:

#711

The intended header would be:

  /* Copyright (c) 2016 Minoru Sakamoto, All Rights Reserved
   * 
   * The contents of this file is dual-licensed under 2 
   * alternative Open Source/Free licenses: LGPL 2.1 or later and 
   * Apache License 2.0. (starting with JNA version 4.0.0).
   * 
   * You can freely decide which license you want to apply to 
   * the project.
   * 
   * You may obtain a copy of the LGPL License at:
   * 
   * http://www.gnu.org/licenses/licenses.html
   * 
   * A copy is also included in the downloadable source code package
   * containing JNA, in file "LGPL2.1".
   * 
   * You may obtain a copy of the Apache License at:
   * 
   * http://www.apache.org/licenses/
   * 
   * A copy is also included in the downloadable source code package
   * containing JNA, in file "AL2.0".
   */

This comment has been minimized.

@sakamotodesu

sakamotodesu Nov 5, 2016

Contributor

It might be better to to change Contributing.md.

@sakamotodesu

sakamotodesu Nov 5, 2016

Contributor

It might be better to to change Contributing.md.

This comment has been minimized.

@matthiasblaesing

matthiasblaesing Nov 5, 2016

Contributor

Aggreed, that why that change is already part of the PR. The PR is unmerged as of now as I'm soliciting feedback on this massive change.

@matthiasblaesing

matthiasblaesing Nov 5, 2016

Contributor

Aggreed, that why that change is already part of the PR. The PR is unmerged as of now as I'm soliciting feedback on this massive change.

+ * the required buffer size if the function fails with ERROR_INSUFFICIENT_BUFFER.
+ * @return The return value is ERROR_SUCCESS if the call succeeded; otherwise, a Win32 error code.
+ */
+ int EvtGetExtendedStatus(int BufferSize, Pointer Buffer, IntByReference BufferUsed);

This comment has been minimized.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

It should be save to use a char[] as the buffer, as this better aligns with the usage and is the default mapping. If a char[] is used, this works as expected:

char[] buffer = new char[1024];
EvtGetExtendedStatus(buffer.length, buffer, null);
String result = Native.toString(buffer):

Expected in this case means: with bare memory you'd have to consider the width/size of wchar so multiply the value of BufferUsed by two to allocate the right amount of memory.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

It should be save to use a char[] as the buffer, as this better aligns with the usage and is the default mapping. If a char[] is used, this works as expected:

char[] buffer = new char[1024];
EvtGetExtendedStatus(buffer.length, buffer, null);
String result = Native.toString(buffer):

Expected in this case means: with bare memory you'd have to consider the width/size of wchar so multiply the value of BufferUsed by two to allocate the right amount of memory.

+ * the {@link Kernel32#GetLastError} function.
+ */
+ boolean EvtFormatMessage(EVT_HANDLE PublisherMetadata, EVT_HANDLE Event, int MessageId, int ValueCount, EVT_VARIANT[] Values,
+ int Flags, int BufferSize, Pointer Buffer, IntByReference BufferUsed);

This comment has been minimized.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

Please see comment for line 90

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

Please see comment for line 90

+ * call the {@link Kernel32#GetLastError} function.
+ */
+ boolean EvtNextChannelPath(EVT_HANDLE ChannelEnum, int ChannelPathBufferSize, Pointer ChannelPathBuffer,
+ IntByReference ChannelPathBufferUsed);

This comment has been minimized.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

Please see comment for line 90

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

Please see comment for line 90

+ * otherwise, NULL. If NULL, call {@link Kernel32#GetLastError} function to get the error code.
+ */
+ boolean EvtNextPublisherId(EVT_HANDLE PublisherEnum, int PublisherIdBufferSize, Pointer PublisherIdBuffer,
+ IntByReference PublisherIdBufferUsed);

This comment has been minimized.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

Please see comment for line 90

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

Please see comment for line 90

+ super(peer, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE);
+ }
+
+ protected ByReference newByReference() {

This comment has been minimized.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

Please check if the the methods newByReference, newByValue and newInstance are needed. I see no reason for their implementation.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

Please check if the the methods newByReference, newByValue and newInstance are needed. I see no reason for their implementation.

+ throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
+ }
+
+ Memory buff = new Memory(1024);

This comment has been minimized.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

This needs to be adjusted if you switch to char[] in Wevtapi. See 245 for the reason.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

This needs to be adjusted if you switch to char[] in Wevtapi. See 245 for the reason.

+ IntByReference buffUsed = new IntByReference();
+ while (true) {
+ buff.clear();
+ if (!Wevtapi.INSTANCE.EvtNextChannelPath(channelHandle, (int) buff.size(), buff, buffUsed)) {

This comment has been minimized.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

This is the reason char[] is a good ide, buff.size() is twice to large in this case. buff.size() is size in bytes, but EvtNextChannelPath expects size in chars.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

This is the reason char[] is a good ide, buff.size() is twice to large in this case. buff.size() is size in bytes, but EvtNextChannelPath expects size in chars.

+ throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
+ }
+
+ Memory buff;

This comment has been minimized.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

With the suggested changes to WevtapiUtil you'll get a String back directly, so in that case this needs adjusting.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

With the suggested changes to WevtapiUtil you'll get a String back directly, so in that case this needs adjusting.

+ Wevtapi.INSTANCE.EvtClose(handle);
+ }
+ }
+ System.out.println(result);

This comment has been minimized.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

This looks like an artifact from debugging. I was surprised when I saw the output and could not directly place it. Please remove.

@matthiasblaesing

matthiasblaesing Nov 4, 2016

Contributor

This looks like an artifact from debugging. I was surprised when I saw the output and could not directly place it. Please remove.

change license header to dual-license
change buffer type to `char[]`:
  - EvtGetExtendedStatus
  - EvtFormatMessage
  - EvtNextChannelPath
  - EvtNextPublisherId

 change return value of utilities to String:
  - EvtFormatMessage
  - EvtNextPublisherId

  add EVT_VARIANT#ByValue constructor
  remove EVT_PRC_LOGIN#newByReference/newByValue/newIncetance
@matthiasblaesing

Thank you - I'll merge this into master.

@matthiasblaesing matthiasblaesing merged commit bff94d4 into java-native-access:master Nov 5, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment