Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: borisbrodski/sevenzipjbinding
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: sleuthkit/sevenzipjbinding
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 13 commits
  • 16 files changed
  • 3 contributors

Commits on Jul 25, 2019

  1. First stab

    ethteck committed Jul 25, 2019
    Copy the full SHA
    cf1e134 View commit details
  2. Windows changes

    ethteck committed Jul 25, 2019
    Copy the full SHA
    a402e63 View commit details
  3. blah

    ethteck committed Jul 25, 2019
    Copy the full SHA
    05e3105 View commit details

Commits on Jul 30, 2019

  1. Be better about bytes

    ethteck committed Jul 30, 2019
    Copy the full SHA
    fbfc1c3 View commit details
  2. Not using ByteBuffer

    ethteck committed Jul 30, 2019
    Copy the full SHA
    8f8ef46 View commit details

Commits on Aug 5, 2019

  1. tiny changes

    ethteck committed Aug 5, 2019
    Copy the full SHA
    f308cd8 View commit details

Commits on Oct 7, 2019

  1. Small cleanup

    ethteck committed Oct 7, 2019
    Copy the full SHA
    87d8e65 View commit details

Commits on Oct 17, 2019

  1. Further cleanup

    ethteck committed Oct 17, 2019
    Copy the full SHA
    c96f6b8 View commit details
  2. Bug fix

    ethteck committed Oct 17, 2019
    Copy the full SHA
    38ab78c View commit details

Commits on Nov 16, 2020

  1. Copy the full SHA
    2324b06 View commit details
  2. fixing size bug

    ethteck committed Nov 16, 2020
    Copy the full SHA
    25cf747 View commit details

Commits on Nov 17, 2020

  1. New unit test

    ethteck committed Nov 17, 2020
    Copy the full SHA
    1d012f8 View commit details

Commits on Nov 24, 2020

  1. Merge pull request #1 from ethteck/pathbytes

    New  "pathbytes" PropID
    rcordovano authored Nov 24, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fcdbb86 View commit details
4 changes: 3 additions & 1 deletion 7zip/CPP/7zip/Archive/Zip/ZipHandler.cpp
Original file line number Diff line number Diff line change
@@ -277,7 +277,9 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
prop = res;
break;
}


case kpidPathBytes: prop = item.Name; prop.vt = VT_ARRAY; break;

case kpidIsDir: prop = item.IsDir(); break;
case kpidSize: prop = item.Size; break;
case kpidPackSize: prop = item.PackSize; break;
2 changes: 2 additions & 0 deletions 7zip/CPP/7zip/PropID.h
Original file line number Diff line number Diff line change
@@ -106,6 +106,8 @@ enum

kpid_NUM_DEFINED,

kpidPathBytes = 100,

kpidUserDefined = 0x10000
};

1 change: 1 addition & 0 deletions 7zip/CPP/Common/MyWindows.h
Original file line number Diff line number Diff line change
@@ -144,6 +144,7 @@ enum VARENUM
VT_UINT = 23,
VT_VOID = 24,
VT_HRESULT = 25,
VT_ARRAY = 26,
VT_FILETIME = 64
};

1 change: 1 addition & 0 deletions jbinding-cpp/CPPToJava/CPPToJavaArchiveUpdateCallback.cpp
Original file line number Diff line number Diff line change
@@ -247,6 +247,7 @@ STDMETHODIMP CPPToJavaArchiveUpdateCallback::GetProperty(UInt32 index, PROPID pr
case kpidAttrib: GET_ATTRIBUTE(UINTEGER, propertyAttributes)
case kpidPosixAttrib: GET_ATTRIBUTE(UINTEGER, propertyPosixAttributes)
case kpidPath: GET_ATTRIBUTE(STRING, propertyPath)
case kpidPathBytes: GET_ATTRIBUTE(STRING, propertyPath)
case kpidIsDir: GET_ATTRIBUTE(BOOLEAN, propertyIsDir)
case kpidIsAnti: GET_ATTRIBUTE(BOOLEAN, propertyIsAnti)
case kpidMTime: GET_ATTRIBUTE(DATE, propertyLastModificationTime)
1 change: 1 addition & 0 deletions jbinding-cpp/Client7z.cpp
Original file line number Diff line number Diff line change
@@ -546,6 +546,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
switch(propID)
{
case kpidPath: prop = dirItem.Name; break;
case kpidPathBytes: prop = dirItem.Name; break;
case kpidIsDir: prop = dirItem.isDir(); break;
case kpidSize: prop = dirItem.Size; break;
case kpidAttrib: prop = dirItem.Attrib; break;
34 changes: 34 additions & 0 deletions jbinding-cpp/JNITools.cpp
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@ static jmethodID g_BooleanBooleanValue;

static jclass g_StringClass;

static jclass g_ByteArrayClass;

static jclass g_DateClass;
static jmethodID g_DateConstructor;

@@ -81,6 +83,10 @@ static void localinit(JNIEnv * env) {
FATALIF(g_StringClass == NULL, "Can't find String class");
g_StringClass = (jclass) env->NewGlobalRef(g_StringClass);

g_ByteArrayClass = env->FindClass(JAVA_BYTEARRAY);
FATALIF(g_ByteArrayClass == NULL, "Can't find byte array class");
g_ByteArrayClass = (jclass) env->NewGlobalRef(g_ByteArrayClass);

g_DateClass = env->FindClass("java/util/Date");
FATALIF(g_DateClass == NULL, "Can't find java.util.Date class");
g_DateClass = (jclass) env->NewGlobalRef(g_DateClass);
@@ -193,6 +199,24 @@ jobject BSTRToObject(JNIEnv * env, BSTR value) {
return ToJChar(value).toNewString(env);
}

/**
* Get java.nio.ByteBuffer from BSTR string
*/
jobject ByteArrayToObject(JNIEnv * env, BSTR value) {
localinit(env);

int size = sizeof(value[0]);
unsigned int length = SysStringLen(value);
jbyte* jbytes = (jbyte*)value;
jbyte retBytes[length];
for (int i = 0; i < length; i++) {
retBytes[i] = jbytes[i * size];
}
jbyteArray ret = env->NewByteArray(length);
env->SetByteArrayRegion(ret, 0, length, retBytes);
return ret;
}

/**
* Get java.util.Date object from date in FILETIME format
*/
@@ -241,6 +265,10 @@ void ObjectToPropVariant(JNIEnvInstance & jniEnvInstance, jobject object, PROPVA
cPropVariant = (Int32) value;
} else if (jniEnvInstance->IsInstanceOf(object, g_StringClass)) {
cPropVariant = UString(FromJChar(jniEnvInstance, (jstring)object));
} else if (jniEnvInstance->IsInstanceOf(object, g_ByteArrayClass)) {
jbyte* value = jniEnvInstance->GetByteArrayElements((jbyteArray) object, NULL);
cPropVariant = (jbyteArray) value;
jniEnvInstance->ReleaseByteArrayElements((jbyteArray) object, value, JNI_ABORT);
} else if (jniEnvInstance->IsInstanceOf(object, g_BooleanClass)) {
jboolean value = jniEnvInstance->CallBooleanMethod(object, g_BooleanBooleanValue);
cPropVariant = (bool) value;
@@ -304,6 +332,9 @@ jobject PropVariantToObject(JNIEnvInstance & jniEnvInstance, NWindows::NCOM::CPr
case VT_BSTR:
return BSTRToObject(jniEnvInstance, propVariant->bstrVal);

case VT_ARRAY:
return ByteArrayToObject(jniEnvInstance, propVariant->bstrVal);

case VT_DATE:
case VT_FILETIME:
return FILETIMEToObject(jniEnvInstance, propVariant->filetime);
@@ -364,6 +395,9 @@ jclass VarTypeToJavaType(JNIEnvInstance & jniEnvInstance, VARTYPE vt) {
case VT_BSTR:
return g_StringClass;

case VT_ARRAY:
return g_ByteArrayClass;

case VT_DATE:
case VT_FILETIME:
return g_DateClass;
5 changes: 5 additions & 0 deletions jbinding-cpp/JNITools.h
Original file line number Diff line number Diff line change
@@ -78,6 +78,11 @@ jobject DoubleToObject(JNIEnv * env, double value);
*/
jobject BSTRToObject(JNIEnv * env, BSTR value);

/**
* Get java.nio.ByteBuffer from BSTR string
*/
jobject ByteArrayToObject(JNIEnv * env, BSTR value);

/**
* Get java.util.Date object from date in FILETIME format
*/
1 change: 1 addition & 0 deletions jbinding-cpp/JavaStatInfos/JavaPackageSevenZip.h
Original file line number Diff line number Diff line change
@@ -147,6 +147,7 @@ JT_BEGIN_CLASS(SEVEN_ZIP_PACKAGE_IMPL, OutItem)
JT_FIELD_OBJECT(propertyAttributes, JAVA_INTEGER_T)
JT_FIELD_OBJECT(propertyPosixAttributes, JAVA_INTEGER_T)
JT_FIELD_OBJECT(propertyPath, JAVA_STRING_T)
JT_FIELD_OBJECT(propertyPathBytes, JAVA_BYTEARRAY_T)
JT_FIELD_OBJECT(propertyIsDir, JAVA_BOOLEAN_T)
JT_FIELD_OBJECT(propertyLastModificationTime, JAVA_DATE_T)
JT_FIELD_OBJECT(propertyLastAccessTime, JAVA_DATE_T)
3 changes: 3 additions & 0 deletions jbinding-cpp/JavaStatInfos/JavaStandardLibrary.h
Original file line number Diff line number Diff line change
@@ -43,6 +43,9 @@
#define JAVA_STRING "java/lang/String"
#define JAVA_STRING_T JAVA_MAKE_SIGNATURE_TYPE(JAVA_STRING)

#define JAVA_BYTEARRAY "[B"
#define JAVA_BYTEARRAY_T JAVA_MAKE_SIGNATURE_TYPE(JAVA_BYTEARRAY)

#define JAVA_THROWABLE "java/lang/Throwable"
#define JAVA_THROWABLE_T JAVA_MAKE_SIGNATURE_TYPE(JAVA_THROWABLE)

7 changes: 7 additions & 0 deletions jbinding-java/src/net/sf/sevenzipjbinding/PropID.java
Original file line number Diff line number Diff line change
@@ -230,6 +230,13 @@ public enum PropID {

// TODO Add test to ensure "kpidLink"(c++) == "LINK" (java)

/**
* The path of the file in bytes
* <br>
* Type: byte[] <code>null</code> will be returned, if current archive type doesn't support this property.
*/
PATH_BYTES(100),

USER_DEFINED(0x10000), //

/**
1 change: 1 addition & 0 deletions p7zip/CPP/7zip/Archive/Zip/ZipHandler.cpp
Original file line number Diff line number Diff line change
@@ -277,6 +277,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
prop = res;
break;
}
case kpidPathBytes: prop = item.Name; prop.vt = VT_ARRAY; break;

case kpidIsDir: prop = item.IsDir(); break;
case kpidSize: prop = item.Size; break;
2 changes: 2 additions & 0 deletions p7zip/CPP/7zip/PropID.h
Original file line number Diff line number Diff line change
@@ -106,6 +106,8 @@ enum

kpid_NUM_DEFINED,

kpidPathBytes = 100,

kpidUserDefined = 0x10000
};

1 change: 1 addition & 0 deletions p7zip/CPP/Common/MyWindows.h
Original file line number Diff line number Diff line change
@@ -151,6 +151,7 @@ enum VARENUM
VT_UINT = 23,
VT_VOID = 24,
VT_HRESULT = 25,
VT_ARRAY = 26,
VT_FILETIME = 64
};

Original file line number Diff line number Diff line change
@@ -79,6 +79,7 @@
import net.sf.sevenzipjbinding.junit.compression.UpdateSingleFileNonGenericGZipTest;
import net.sf.sevenzipjbinding.junit.compression.UpdateSingleFileNonGenericTarTest;
import net.sf.sevenzipjbinding.junit.compression.UpdateSingleFileNonGenericZipTest;
import net.sf.sevenzipjbinding.junit.encoding.JapaneseFilenamesInArchive;
import net.sf.sevenzipjbinding.junit.encoding.UnicodeFilenamesInArchive;
import net.sf.sevenzipjbinding.junit.initialization.InitializationDoesNotVerifyArtifactsTest;
import net.sf.sevenzipjbinding.junit.initialization.StandardInitializationTest;
@@ -245,7 +246,8 @@ public class AllTestSuite extends TestSuite {
};

static Class<?>[] encodingArchiveTests = { //
/* */UnicodeFilenamesInArchive.class, //
/* */JapaneseFilenamesInArchive.class, //
UnicodeFilenamesInArchive.class, //
};

static Class<?>[] bugArchiveTests = { //
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package net.sf.sevenzipjbinding.junit.encoding;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;

import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;

import net.sf.sevenzipjbinding.ArchiveFormat;
import net.sf.sevenzipjbinding.IInArchive;
import net.sf.sevenzipjbinding.ISequentialOutStream;
import net.sf.sevenzipjbinding.PropID;
import net.sf.sevenzipjbinding.SevenZip;
import net.sf.sevenzipjbinding.SevenZipException;
import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream;
import net.sf.sevenzipjbinding.junit.JUnitNativeTestBase;
import net.sf.sevenzipjbinding.junit.VoidContext;
import net.sf.sevenzipjbinding.simple.ISimpleInArchive;
import net.sf.sevenzipjbinding.simple.ISimpleInArchiveItem;

public class JapaneseFilenamesInArchive extends JUnitNativeTestBase<VoidContext> {

private final ArchiveFormat archiveFormat;

public JapaneseFilenamesInArchive(ArchiveFormat archiveFormat) {
this.archiveFormat = archiveFormat;
}

@Parameters
public static Collection<Object> data() {
return Arrays.asList(new Object[] { ArchiveFormat.ZIP });
}

@Test
public void testUpperLowerCaseUnicode() throws Throwable {
RandomAccessFile randomAccessFile = null;
IInArchive inArchive = null;
Throwable throwable = null;

log("Testing for " + archiveFormat);
try {
randomAccessFile = new RandomAccessFile("testdata/encoding/jpn_file_names."
+ archiveFormat.getMethodName().toLowerCase(), "r");
inArchive = SevenZip.openInArchive(archiveFormat, new RandomAccessFileInStream(randomAccessFile));
ISimpleInArchive simpleInterface = inArchive.getSimpleInterface();

int numItems = simpleInterface.getNumberOfItems();
assertEquals(2, numItems);

ISimpleInArchiveItem[] archiveItems = simpleInterface.getArchiveItems();

String[] truth = {"123アアパート.txt", "テスト日本語.txt"};


for (int i = 0; i < numItems; i++) {
String t = truth[i];
String path = archiveItems[i].getPath();
assertNotEquals(t, path);

byte[] pathBytes = (byte[])inArchive.getProperty(i, PropID.PATH_BYTES);
String encodedPath = new String(pathBytes, StandardCharsets.UTF_8);

assertEquals(t, encodedPath);
}
} catch (Throwable e) {
throwable = e;
} finally {
try {
if (inArchive != null) {
inArchive.close();
}
} catch (Throwable e) {
if (throwable == null) {
throwable = e;
}
}
if (randomAccessFile != null) {
try {
randomAccessFile.close();
} catch (Throwable e) {
if (throwable == null) {
throwable = e;
}
}
}
}

if (throwable != null) {
throw throwable;
}
}
}
Binary file added test/JavaTests/testdata/encoding/jpn_file_names.zip
Binary file not shown.