Invalid Memory Access on QueryContextAttributes using JNA - java

I am attempting to use JNA to invoke the QueryContextAttributes function in the Secur32.dll on Windows. I am unable to get the invocation correct for the SECPKG_ATTR_SIZES call. I have an implementation working for SECPKG_ATTR_NAMES and SECPKG_ATTR_PACKAGE_INFO. Therefore, I presume (famous last words) the issue is in the definition of the structure, or something about the invocation.
The Microsoft function definition for QueryContextAttributes is:
SECURITY_STATUS SEC_Entry QueryContextAttributes(
_In_ PCtxtHandle phContext,
_In_ ULONG ulAttribute,
_Out_ PVOID pBuffer
);
The Microsoft structure definition for the SecPkgContext_Sizes is:
typedef struct _SecPkgContext_Sizes {
ULONG cbMaxToken;
ULONG cbMaxSignature;
ULONG cbBlockSize;
ULONG cbSecurityTrailer;
} SecPkgContext_Sizes, *PSecPkgContext_Sizes;
The JNA library (I'm using jna-4.2.2 and jna-platform-4.2.2) provides an implementation in the Secur32 for some of the functions in that .dll. The definitions for the structures are at:
SecPkgContext_Names structure,
SecPkgInfo structure, and
SecPkgContext_Sizes structure
I therefore have defined the following:
public interface ISecur32 extends Secur32 {
// get own copy of the INSTANCE variable
ISecur32 INSTANCE = (ISecur32) Native.loadLibrary("Secur32",
ISecur32.class,
W32APIOptions.UNICODE_OPTIONS);
// method definition to match
public int QueryContextAttributes(CtxtHandle phContext,
int SECPKG_ATTR,
PointerByReference pp);
//
// for the SECPKG_ATTR_NAMES call
// NOTE: this definition and invocation is working
//
public static class SecPkgContext_Names extends Structure {
public Pointer pName;
public SecPkgContext_Names(Pointer p)
{ super(p); }
#Override
protected List<?> getFieldOrder()
{ return Arrays.asList(new String[] { "pName" }); }
}
//
// for the SECPKG_ATTR_SIZES call
// NOTE: This invocation is NOT working
//
public static class SecPkgContext_SizesBis extends Structure {
public NativeLong cbMaxToken;
public NativeLong cbMaxSignature;
public NativeLong cbBlockSize;
public NativeLong cbSecurityTrailer;
public SecPkgContext_SizesBis(Pointer p)
{ super(p); }
#Override
protected List<?> getFieldOrder() {
return Arrays.asList(new String[] { "cbMaxToken", "cbMaxSignature",
"cbBlockSize", "cbSecurityTrailer"});
}
} //interface
The call for the Names (which is working) is:
public static void querySecPkgAttr_Names(CtxtHandle phContext) {
final int SECPKG_ATTR_NAMES = 1;
PointerByReference pp = new PointerByReference();
int rc = ISecur32.INSTANCE.QueryContextAttributes(phContext,
SECPKG_ATTR_NAMES,
pp);
if (rc != 0) {
_log.error("Error in QueryContextAttributes: {}", rc);
return;
}
Pointer p = pp.getPointer();
ISecur32.SecPkgContext_Names names = new ISecur32.SecPkgContext_Names(p);
names.read();
String name = names.pName.getWideString(0);
rc = ISecur32.INSTANCE.FreeContextBuffer(p);
_log.debug("FreeContextBuffer: {}", rc);
}
When I attempt to obtain the Sizes (specifically, I'm after the cbMaxSignature value), I use the following call:
public static int querySecPkgAttr_Sizes(CtxtHandle phContext) {
final int SECPKG_ATTR_SIZES = 0; // SECPKG_ATTR_SIZES is 0
PointerByReference pp = new PointerByReference();
int res = ISecur32.INSTANCE.QueryContextAttributes(phContext,
SECPKG_ATTR_SIZES,
pp);
// NOTE: the call is succeeding, so this line is not invoked
if (res != 0) {
return new NativeLong(0);
}
// NOTE: I have also used pp.getPointer()
Pointer p = pp.getValue();
ISecur32.SecPkgContext_Sizes sizes =
new ISecur32.SecPkgContext_Sizes(p);
// THIS LINE THROWS THE Invalid Memory Access Error
sizes.read();
NativeLong maxSig = sizes.cbMaxSignature;
rc = ISecur32.INSTANCE.FreeContextBuffer(p);
_log.debug("FreeContextBuffer: {}", rc);
return maxSig.intValue();
}
Using the above call, I receive the Exception stack trace of:
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.getInt(Native Method)
at com.sun.jna.Pointer.getInt(Pointer.java:601)
at com.sun.jna.Pointer.getValue(Pointer.java:389)
at com.sun.jna.Structure.readField(Structure.java:705)
at com.sun.jna.Structure.read(Structure.java:565)
at gov.sandia.dart.sspi.Utils.querySecPkgAttr_Sizes(Utils.java:145)
If instead of the pp.getValue() call, I use pp.getPointer(), I receive (when trying to instantiate the Object, I believe):
java.lang.IllegalArgumentException: Structure exceeds provided memory bounds
I am at a loss as to how to solve this issue.
I apologize for not having a complete program, but to get to the point of having the CtxtHandle needed requires a romp through AcquireCredentialsHandle and InitializeSecurityContext. I believe these are working appropriately, as the Kerberos ticket is showing in the MSLSA cache (viewable via klist) after the InitializeSecurityContext completes.
I also looked at the solution Waffle, but it does not set the correct flags for in the initialization loop, and also does not implement QueryContextAttributes, or the ultimate goal in all of this the MakeSignature function.
I apologize for the length of the post. If I have omitted any piece of information, please let me know.
Thank you!

I was able to resolve the issue I was having, though not in a very elegant manner. Rather than attempting to use the a PointerByReference in the QueryContextAttributes as suggested in the question, I ended up creating multiple method definitions, one for each structure. So I have in the Interface, the approach of:
public int QueryContextAttributes(CtxtHandle phContext,
int SECPKG_ATTR,
SecPkgContext_NegotiationInfo negoInfo);
public static class SecPkgContext_NegotiationInfo extends Structure
{
public Pointer pPackageInfo;
public int negotiationState;
public SecPkgContext_NegotiationInfo() {
super();
}
public SecPkgContext_NegotiationInfo(Pointer p) {
super(p);
}
#Override
protected List<?> getFieldOrder() {
return Arrays.asList(new String[] { "pPackageInfo", "negotiationState"
});
}
}
public int QueryContextAttributes(CtxtHandle phContext,
int SECPKG_ATTR,
SecPkgContext_Sizes sizes);
public static class SecPkgContext_Sizes extends Structure
{
public int cbMaxToken;
public int cbMaxSignature;
public int cbBlockSize;
public int cbSecurityTrailer;
public SecPkgContext_Sizes() {
super();
}
public SecPkgContext_Sizes(Pointer p) {
super(p);
}
#Override
protected List<?> getFieldOrder() {
return Arrays.asList(new String[] { "cbMaxToken",
"cbMaxSignature",
"cbBlockSize",
"cbSecurityTrailer"
});
}
}
And so forth for the few definitions I need.
Ultimately the goal was to get the MakeSignature call to work (the QueryContextAttributes(...) being a precursor), and I had trouble leveraging the default JNA SecBufferDesc structure. I found a pointer to a solution from JSch SSPI by Joe Khoobyar, and leveraged the basic definition from that site, changing the NativeLong objects to int, and adding the new required method getFieldOrder().
The MakeSignature method, following definitions from Microsoft, was defined in the Interface as:
public int MakeSignature(CtxtHandle phContext,
int fQOP,
ISecur32.SecBufferDesc pMessage,
int messageSeqNo);
After using the above methods for QueryContextAttributes and the modified structure for SecBufferDesc, I was able to get a working solution. The Java clients may now leverage the Microsoft SSPI system for SSO to the remote Linux machines.

Related

descriptive way of calling various feign APIs

I want to create a construct that would work with pageable feign api calls and dry them from the first page of declared size available to the last one.
To take in account:
the feign method calls can differ in arg. count tho last two is always page and it's size
data structure returned is similar to the extent of paging information, but core data list received type differs
This is what I did:
method that is a base for draining a particular api call:
public <T> List<BaseFeignResult<T>> drainFeignPageableCall(
PagedCall<T> feignCall
) {
BaseFeignResult<T> firstPage = feignCall.call(0, 10);
List<BaseFeignResult<T>> baseFeignResults = drainFeignPageableCall(feignCall, firstPage, Lists.newArrayList(firstPage), 1);
return baseFeignResults;
}
It's overload and continuation:
<T> List<BaseFeignResult<T>> drainFeignPageableCall(
PagedCall<T> feignCall,
BaseFeignResult<T> dataPage,
List<BaseFeignResult<T>> acc,
int page
) {
if (dataPage.resp.getBody().getData().size() % 10 > 0)
return acc;
BaseFeignResult<T> res = feignCall.call(page, 10);
acc.add(res);
return drainFeignPageableCall(feignCall, res, acc, ++page);
}
And the definitions:
public static class SingleParamPageableCall<T> implements PagedCall<T> {
SingleParamPagingApi<T> fun;
String param;
public SingleParamPageableCall(SingleParamPagingApi<T> fun, String param) {
this.fun = fun;
this.param = param;
}
#Override
public BaseFeignResult<T> call(int p, int s) {
BaseFeignResult.BaseFeignResultBuilder<T> builder = BaseFeignResult.builder();
try {
builder.resp(fun.callFeignApi(param, p, s));
} catch (RuntimeException e) {
builder.excp(e);
}
return builder.build();
}
}
public interface PagedCall<T> {
BaseFeignResult<T> call(int p, int s);
}
#Builder
public static class BaseFeignResult<T> {
private final ResponseEntity<IVDPagedResponseOf<T>> resp;
private final RuntimeException excp;
}
public interface SingleParamPagingApi<T> {
ResponseEntity<IVDPagedResponseOf<T>> callFeignApi(String arg, int page, int size) throws RuntimeException;
}
This can be arbitraliry called as:
drainFeignPageableCall(new BaseService.SingleParamPageableCall<GetOrderInfoDto>(ordersFeignClient::getOrdersBySampleIds, "34596"));
and works as expected.
So as you can see, if I want to keep some sort of abstraction above various drain-able per api calls, I need to introduce definitions like SingleParamPagingApi and class implementation of SingleParamPageableCall<T>. so with every other api to be treated this way, I would need to redefine those.
My question here is: how to do this in purely descripive way, or how to reimplement this as a functional programming?
to be clear: I would like to have code impl. in which I would describe how to map parameters to the method call (that can and will vary) and return a common data structure with the data being of generic type.
Basically I am looking for the most descriptive way of re-implementing this in Java without defining heavy objects like SingleParamPagingApi<T>, but describing how to mount params called with to API params itself rather.
Thank you!
This simplest way would be to replace your SingleParamPagingApi interface with one that has a method that just takes the page no and size as parameters (PagingApi). And replace SingleParamPageableCall with a class that just takes a PagingApi argument. Then you can create the variants of PagingApi for 1 parameter, 2 parameters etc by immediately binding the method to the argument 0, argument 1 etc, thereby creating a PagingApi instance (the of methods).
public interface PagingApi1<T, A0> {
ResponseEntity<IVDPagedResponseOf<T>> callFeignApi(A0 arg0, int page, int size) throws RuntimeException;
}
public interface PagingApi2<T, A0, A1> {
ResponseEntity<IVDPagedResponseOf<T>> callFeignApi(A0 arg0, A1 arg1, int page, int size) throws RuntimeException;
}
public interface PagingApi<T> {
static <T, A0> PagingApi<T> of(PagingApi1<T, A0> api, A0 arg0) {
return (p, s) -> api.callFeignApi(arg0, p, s);
}
static <T, A0, A1> PagingApi<T> of(PagingApi2<T, A0, A1> api, A0 arg0, A1 arg1,) {
return (p, s) -> api.callFeignApi(arg0, arg1, p, s);
}
ResponseEntity<IVDPagedResponseOf<T>> callFeignApi(int page, int size) throws RuntimeException;
}
public static class PageableCall<T> implements PagedCall<T> {
PagingApi<T> fun;
public PageableCall(PagingApi<T> fun) {
this.fun = fun;
}
#Override
public BaseFeignResult<T> call(int p, int s) {
BaseFeignResult.BaseFeignResultBuilder<T> builder = BaseFeignResult.builder();
try {
builder.resp(fun.callFeignApi(p, s));
} catch (RuntimeException e) {
builder.excp(e);
}
return builder.build();
}
}
You would call it as follows:
drainFeignPageableCall(
new PageableCall<GetOrderInfoDto>(
PagingApi.of(ordersFeignClient::getOrdersBySampleIds, "34596")
)
);
As a further simplifcation, you could probably collapse PagingApi and PagedCall into a single interface.
I would also suggest replacing the recursive calls in drainFeignPageableCall with a simple for loop. You might think recursion is more "functional" but it's needlessly complex and inefficient here.

Use SHGetFileInfo in Java with JNA

I tried to translate the SHGetFileInfo function from Shell32 into Java with JNA and used C# code and this as reference
While in the C# code psfi.iIcon is 432 in my translated Java code psfi.iIcon is 0. If I am right, for the same file they should be same no matter which language I use, shouldn't they?
My Java code:
public static void main(String[] args) {
String path = "[PATH_TO_EXE]\\test.exe"; //Of course in my code I used the real path
SHFILEINFO sfi = new SHFILEINFO();
DWORD_PTR i = Shell32.INSTANCE.SHGetFileInfo(path, 0, sfi, sfi.size(), SHGFI.SysIconIndex);
System.out.println(sfi.iIcon); //<-- Prints 0, should print 432
}
public static class SHGFI {
static final int SysIconIndex = 0x000004000;
static final int LargeIcon = 0x000000000;
static final int UseFileAttributes = 0x000000010;
}
public interface Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.loadLibrary("shell32", Shell32.class, W32APIOptions.UNICODE_OPTIONS);
DWORD_PTR SHGetFileInfo(String pszPath, int dwFileAttributes, SHFILEINFO psfi, int cbFileInfo, int uFlags);
}
public static class SHFILEINFO extends Structure {
public HICON hIcon;
public int iIcon;
public DWORD dwAttributes;
public char[] szDisplayName = new char[260];
public char[] szTypeName = new char[80];
#Override
protected List<String> getFieldOrder() {
return Arrays.asList("hIcon", "iIcon", "dwAttributes", "szDisplayName", "szTypeName");
}
}
Is there anything fundemental that I did wrong? I'm new to JNA and Windows functions
Under the Remarks section, there is this piece of information, which imho might be the source of your problem
You must initialize Component Object Model (COM) with CoInitialize or
OleInitialize prior to calling SHGetFileInfo.
It's a pretty straightforward call
CoInitialize(null);
As DanielWiddis pointed out in the comments, per documentation
New applications should call CoInitializeEx instead of CoInitialize
And
To close the COM library gracefully, each successful call to
CoInitialize or CoInitializeEx, including those that return S_FALSE,
must be balanced by a corresponding call to CoUninitialize
Example
CoInitializeEx(null, 0);
CoUninitialize();

How to pass a struct containing char* in java using JNA and avoiding the data copy?

I am writing a java application that will access to C++ dll usnig JNA. So I prepared a C dll to communicate between the JNA and C++ thrid party dll. I have these two structs:
C code:
struct Struct1
{
uint32_t Size;
unsigned char* Data;
};
struct Struct2
{
uint32_t Struct1_Nbr;
Struct1* struct1_elements;
};
bool Open(char* fileName, Struct2** struct2);
Now I am writing the corresponding JNA code in java application and I want to access the "unsigned char* Data" without copying this data as it is a large amount of Data.
How can I use the "Memory" or the "Pointer" JNA types to do this task?
Here is my attempt:
public class Test
{
public static class Struct1 extends com.sun.jna.Structure {
public Struct1(){}
public Struct1(Pointer pointer){
super(pointer);
read();
}
public static class Struct1ByValue extends Struct1 implements com.sun.jna.Structure.ByValue{};
public int Size;
public Memory Data;
public static class Struct1ByReference extends Struct1 implements com.sun.jna.Structure.ByReference{}
#Override
protected List getFieldOrder() {
// TODO Auto-generated method stub
return Arrays.asList("Size", "Data");
};
public static class Struct2 extends com.sun.jna.Structure {
public Struct2 (){}
public Struct2 (Pointer pointer){
super(pointer);
read();
}
public int Struct2_Nbr;
public Struct1.Struct1ByReference struct1_elements = new Struct1.Struct1ByReference();
public static class Struct2ByValue extends Struct2 implements com.sun.jna.Structure.ByValue{};
public static class Struct2ByReference extends Struct2 implements com.sun.jna.Structure.ByReference{}
#Override
protected List getFieldOrder() {
// TODO Auto-generated method stub
return Arrays.asList("Struct1_Nbr", "struct1_elements"));
};
}
public interface StructureProtocol extends com.sun.jna.Library{
Boolean Open(String fileName, PointerByReference struct2);
}
public StructureProtocol lib;
public Test(){
this.lib = (StructureProtocol) Native.loadLibrary("TestAPI", StructureProtocol.class);
}
public static void main(String[] args) {
Test test = new Test();
PointerByReference pref = new PointerByReference();
test.lib.Open("filePath", pref);
Pointer ptr = pref.getValue();
Struct2 struct2= new Struct2(ptr);
Struct1[] struct1_array= (Struct1[])(struct2.struct1_elements).toArray(struct2.struct1_Nbr);
System.out.println("struct1_array[0]: Size = " + struct1_array[0].Size);
System.out.println("struct1_array[0]: Data= " + struct1_array[0].Data);
}
}
Any advice would be very appreciated.
Here is my Solutiuon, first Draft:
Declare a Class in java that extends Structure
(com.sun.jna.Structure)
(all fields in the class must be public or you get an error, that the size of the structure extended class can't be measured)
public class Struct1 extends Structure{
public int Size;
public String Data;
}
Declare and define a method in the C Dll, that takes a pointer to the structure as an argument (I created a structure and filled it with values for testing)
void __declspec(dllexport) GetStruct(Struct1* a){
Struct1 s;
s.Size = 9;
s.Data = "Output";
*a = s;
}
I assume that you already successfully connected the java app to the c dll, so i skip that part(if my assumption is wrong, tell me in the comments and i edit my answer)
If you add these lines to your java code (note cdll is the handle to my C library)
Struct1 test = new Struct1();
cdll.GetStruct(test);
System.out.println("Struct1: " + test.Size + " " + test.Data);
You should get the data from the Structure s in the C Dll.
If the Data field points to arbitrary data, use a Pointer. If the native side allocates, then you do nothing. If the Java side allocates, use a Memory object assigned to that field.
As for the struct* and struct**, it'd be useful to see some native code using those constructs in order to tell what they represent, since there is some ambiguity (struct* could be a pointer to a single struct, or a pointer to a contiguous array of them). struct** could be storage allocated for the return of a struct*, or it may be something else.

Is there any effective way to read dynamic size shared memory segment using JNA?

I was trying to find effective way to read shared memory in form of array of struct (in C):
typedef struct the_struct {
int id;
int data;
} the_c_struct;
static the_c_struct *the_struc_ptr = NULL;
Currently I use following JNA Structure code to retrieve the data from shared memory:
public class MyCStruc extends Structure {
public int id;
public int data;
#Override
protected List getFieldOrder() {
return Arrays.asList(new String[]{"id", "data"});
}
#Override
public void useMemory(Pointer m, int offset) {
super.useMemory(m, offset);
super.read();
}
#Override
public void useMemory(Pointer m) {
super.useMemory(m);
super.read();
}
}
And read shared memory using native implementation of shmget and shmat:
memId = NativeLib.INSTANCE.shmget(0x999, memSize, 0);
CStructPtr = NativeLib.INSTANCE.shmat(memId, null, 0);
MyCStruc cs=new MyCStruc();
for (int i=0;i<CStructArraySize;i+=8) {
cs.useMemory(CStructPtr,i);
// to read a record of struct array
// do something with the data
}
Above code is actually worked, but I guess I can do something more effective to read array of struct? right?
Note: size of array of struct is dynamic, but I can managed to get the size of the shared memory.
Don't bother with a Structure here, just have the shmat call return a Pointer and use Pointer.getInt(0) to get the ID and Pointer.getInt(4) to get the data field.
You can even use Native.getDirectBufferPointer() to give you an NIO buffer that you can pass off to other Java code.
If you're reading an array of contiguously allocated struct, then you should create your first Structure using the Pointer-based constructor, then invoke Structure.toArray(size) on that instance to load the full array.
Pointer p = lib.shmat();
MyCStruc s = new MyCStruc(p);
MyCStruc[] array = (MyCStruc[])s.toArray(size);
And the constructor:
public class MyCStruc extends Structure {
public MyCStruc(Pointer p) {
super(p);
read();
}
}
Here is my final code:
memId = NativeLib.INSTANCE.shmget(0x999, memSize, 0);
CStructPtr = NativeLib.INSTANCE.shmat(memId, null, 0);
CStructArraySize=memSize/8;
MyCStruc cs=new MyCStruc(CStructPtr);
MyCStruc[] acs=(MyCStruc[])cs.toArray(CStructArraySize);
int i=0;
while (i<CStructArraySize) {
System.out.printf("id=%d data=%d\n", acs[i].id, acs[i].data);
// do something else with the data
i++;
}
MyCStruc now:
public class MyCStruc extends Structure {
public int id;
public int data;
#Override
protected List getFieldOrder() {
return Arrays.asList(new String[]{"id", "data"});
}
public MyCStruc(Pointer p) {
super(p);
read();
}
}

JNA : program does not get terminated.. hangs at some point at jna source

I am trying to solve the following problem for days. My JNA program gets hanged while execution of particular native function and debugging shows program control gets lost at particular location in JNA Source. Here are the details.
I have three native functions in DLL which I am trying to access with JNA.
They are as follows
DllExport long calculatePayment(...,Protection protectionArr[PROTECTION_SIZE],
Others othersArr[OTHERS_SIZE],RC rcArr[RC_SIZE], ...);
DllExport long bufferCalculatePayment(const char *inputBuffer, char **OutputBuffer);
DllExport long fileCalculatePayment(const char *InputFile, const char *OutputFile);
Corresponding Java interface mapping is as follows
public interface DLLInterface extends Library {
public DLLInterface INSTANCE = (DLLInterface) Native.loadLibrary("DLLInterface",
DLLInterface.class);
/* Others Structure is as follows.. protection and rc structure is similar with their
own initialize methods*/
public static final NativeLong othersSize = new NativeLong(20);
class Others extends Structure {
public static class ByValue extends Others implements Structure.ByValue {
}
public double amt = 0.00;
public NativeLong flag = new NativeLong();
public byte[] details = new byte[50]; //
public byte[] mDetails = new byte[50];
public NativeLong flag2 = new NativeLong();
public static Structure[] initialize() {
Others result = new Others();
Others[] resultArr = (Others[]) result.toArray(othersSize);
return resultArr;
}
public void setDetails(String dataIn) {
Arrays.fill(details, (byte) 0);
if (dataIn != null) {
String data = dataIn;
if (data.length() > 49) {
data = data.substring(0, 49);
}
byte[] bytes = data.getBytes();
System.arraycopy(bytes, 0, details, 0, bytes.length);
}
}
//other set functions here
#Override
protected List getFieldOrder() {
return Arrays.asList("amt", "flag", "details", "mDetails", "flag2");
}
}
//Protection and RC sturcutre are similar. Both structures contain fields
of the type byte[] and double.
//Prototypes for native functions
NativeLong calculatePayment(.....Structure[] protectionArr, Structure[]
othersStruct , Structure[] rcArr,.....) ;
Nativelong bufferCalculatePayment(Strubg inputBuffer, PointerByReference
OutputBuffer);
Natuvelong fileCalculatePayment(String InputFile, String OutputFile);
}
//In main function I am calling these functions as follows -
public static void main(String args[]){
DLLInterface.Others[] othersArr = (DLLInterface.Others[])
DLLInterface.Others.initialize();
DLLInterface.RC[] rcArr = (DLLInterface.RC[]) DLLInterface.RC.initialize();
DLLInterface.Protection[] protectionArr = (DLLInterface.Protection[])
DLLInterface.Protection.initialize(); //static method
...
//passing values to structures
...
//few native functions calls goes here (they get executed successfully
NativeLong y =
DLLInterface.INSTANCE.calculatePayment(....protectionArr,othersArr,rcArr, ...);
String inputBuffer = ""<?xml version= \"1.0\" ?><ROOT><REQ><TRANSACT>
<ID>12345</ID><METHOD>COMPOUND</METHOD><AMT>50000</AMT><TERM>360</TERM></TRANSACT>
</REQ></ROOT>";
NativeLong b = DLLInterface.INSTANCE.bufferCalculatePayment(inputBuffer,pRef);
DLLInterface.INSTANCE.fileCalculatePayment("InFile","OutFile");
}
For all three functions program gets hanged..never get terminated so I tried to debug the code. Then I found that after invocation of
Object result = invoke(args, nativeType, allowObjects) , program control gets lost in after following for loop. I listed few lines of source code from
Function.java file source- JNA source
public Object invoke(Class returnType, Object[] inArgs, Map options){
.......
result = resultConverter.fromNative(result, context);
....
// Sync all memory which might have been modified by the native call
if (Structure.ByReference[].class.isAssignableFrom(inArg.getClass()))
{ Class type = inArg.getClass().getComponentType();
Structure[] ss = (Structure[])inArg;
for (int si=0;si < ss.length;si++) {
Pointer p =array.getPointer(Pointer.SIZE * si);
ss[si] =Structure.updateStructureByReference(type, ss[si], p);
} //////*///////////////////////*/program control gets lost after this
}.........}
What could be the problem any guesses? Is there something wrong with native functions or my mapping of arguments is incorrect.
Any help is much appreciated..

Categories

Resources