Win a copy of Penetration Testing Basics this week in the Security forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNA handling char** java mapping

bhushan shelke
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've a C function which takes char** as a argument. C program treats this char** argument as two dimentional array. So this is what it does -

void getStringArray(char** myString){

myString[0] = (char*) malloc (sizeof(char)*20)
strcpy(myString[0], somestring1)
myString[1] = (char*) malloc (sizeof(char)*20)
strcpy(myString[0], somestring2)
myString[2] = (char*) malloc (sizeof(char)*20)
strcpy(myString[0], somestring3)



public void getData(){
PointerByReference pRef = new PointerByReference();

Pointer p = pRef.getValue();
byte buffer[] = p.getByteArray(0,10) //these offsets are indicative, I pass actual value by calculating them in C
sysout(new String(buffer));

byte buffer[] = p.getByteArray(11,20)
sysout(new String(buffer));

buffer[] = p.getByteArray(21,30)
sysout(new String(buffer));

After invoking program I get correct value for first String only other two contain some random values.
am I missing something? or Is there any other way to achieve this?

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic