Skip to content

Commit

Permalink
Add support for long paths in Windows 10+
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolajSchlej committed Jun 20, 2023
1 parent 031bd4f commit b6cdc9f
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 51 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
- name: Configure UEFIExtract
shell: bash
working-directory: ${{runner.workspace}}/build/UEFIExtract
run: cmake -G "Visual Studio 16 2019" -T "v141_xp" ../../UEFITool/UEFIExtract/
run: cmake -G "Visual Studio 16 2019" -A Win32 -T "v141_xp" -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" ../../UEFITool/UEFIExtract/
- name: Build UEFIExtract
working-directory: ${{runner.workspace}}/build/UEFIExtract
shell: bash
Expand All @@ -175,7 +175,7 @@ jobs:
- name: Configure UEFIFind
working-directory: ${{runner.workspace}}/build/UEFIFind
shell: bash
run: cmake -G "Visual Studio 16 2019" -T "v141_xp" ../../UEFITool/UEFIFind/
run: cmake -G "Visual Studio 16 2019" -A Win32 -T "v141_xp" -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" ../../UEFITool/UEFIFind/
- name: Build UEFIFind
working-directory: ${{runner.workspace}}/build/UEFIFind
shell: bash
Expand Down Expand Up @@ -238,7 +238,7 @@ jobs:
- name: Configure everything
working-directory: ${{runner.workspace}}/build
shell: cmd
run: cmake -DCMAKE_PREFIX_PATH="D:\a\UEFITool\qt-6.5.0-static-x64-msvc2022" -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" ../UEFITool
run: cmake -DCMAKE_PREFIX_PATH="D:\a\UEFITool\qt-6.5.0-static-x64-msvc2022" -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" -A x64 ../UEFITool
- name: Build everything
working-directory: ${{runner.workspace}}/build
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion UEFIExtract/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ADD_DEFINITIONS(
-DU_ENABLE_GUID_DATABASE_SUPPORT
)

ADD_EXECUTABLE(UEFIExtract ${PROJECT_SOURCES})
ADD_EXECUTABLE(UEFIExtract ${PROJECT_SOURCES} uefiextract.manifest)

IF(UNIX)
SET_TARGET_PROPERTIES(UEFIExtract PROPERTIES OUTPUT_NAME uefiextract)
Expand Down
5 changes: 3 additions & 2 deletions UEFIExtract/ffsdumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ USTATUS FfsDumper::dump(const UModelIndex & root, const UString & path, const Du
printf("Error %zu returned from recursiveDump (directory \"%s\").\n", result, (const char*)path.toLocal8Bit());
return result;
} else if (!dumped) {
removeDirectory(path);
printf("Removed directory \"%s\" since nothing was dumped.\n", (const char*)path.toLocal8Bit());
if (removeDirectory(path)) {
printf("Removed directory \"%s\" since nothing was dumped.\n", (const char*)path.toLocal8Bit());
}
return U_ITEM_NOT_FOUND;
}

Expand Down
8 changes: 8 additions & 0 deletions UEFIExtract/uefiextract.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<assembly xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv1:assemblyIdentity type='win32' name='me.coderush.UEFIExtract' version='1.0.0.0' />
<asmv3:application>
<asmv3:windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<ws2:longPathAware>true</ws2:longPathAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
5 changes: 2 additions & 3 deletions UEFIExtract/uefiextract_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ int main(int argc, char *argv[])
USTATUS result;
UByteArray buffer;
UString path = getAbsPath(argv[1]);
result = readFileIntoBuffer(path, buffer);
if (result)
return result;
if (false == readFileIntoBuffer(path, buffer))
return U_FILE_OPEN;

// Hack to support legacy UEFIDump mode
if (argc == 3 && !std::strcmp(argv[2], "unpack")) {
Expand Down
8 changes: 3 additions & 5 deletions UEFIFind/uefifind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ UEFIFind::~UEFIFind()

USTATUS UEFIFind::init(const UString & path)
{
USTATUS result;
UByteArray buffer;
result = readFileIntoBuffer(path, buffer);
if (result)
return result;
if (false == readFileIntoBuffer(path, buffer))
return U_FILE_OPEN;

result = ffsParser->parse(buffer);
USTATUS result = ffsParser->parse(buffer);
if (result)
return result;

Expand Down
6 changes: 0 additions & 6 deletions common/basetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,4 @@ typedef struct EFI_TIME_ {
#define __STDC_FORMAT_MACROS
#include <inttypes.h>

#if defined(__clang__) || defined(__GNUC__)
#define ATTRIBUTE_FORMAT_(t,f,a) __attribute__((format(t, f, a)))
#else
#define ATTRIBUTE_FORMAT_(t,f,a)
#endif

#endif // BASETYPES_H
7 changes: 6 additions & 1 deletion common/bstrlib/bstrlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ extern "C" {
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include "../basetypes.h"

#if !defined (BSTRLIB_VSNP_OK) && !defined (BSTRLIB_NOVSNP)
# if defined (__TURBOC__) && !defined (__BORLANDC__)
# define BSTRLIB_NOVSNP
# endif
#endif

#if defined(__clang__) || defined(__GNUC__)
#define ATTRIBUTE_FORMAT_(t,f,a) __attribute__((format(t, f, a)))
#else
#define ATTRIBUTE_FORMAT_(t,f,a)
#endif

#define BSTR_ERR (-1)
#define BSTR_OK (0)
#define BSTR_BS_BUFF_LENGTH_GET (0)
Expand Down
1 change: 0 additions & 1 deletion common/bstrlib/bstrwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#include <stdlib.h>
#include "bstrlib.h"
#include "../ubytearray.h"
#include "../basetypes.h"

#ifdef __cplusplus

Expand Down
4 changes: 2 additions & 2 deletions common/ffsparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ USTATUS FfsParser::parseVolumeHeader(const UByteArray & volume, const UINT32 loc
msgInvalidChecksum = true;

// Get info
if (headerSize >= volume.size()) {
if (headerSize >= (UINT32)volume.size()) {
return U_INVALID_VOLUME;
}
UByteArray header = volume.left(headerSize);
Expand Down Expand Up @@ -1166,7 +1166,7 @@ USTATUS FfsParser::parseVolumeHeader(const UByteArray & volume, const UINT32 loc
return U_INVALID_VOLUME;
}
if (volumeHeader->Revision > 1 && volumeHeader->ExtHeaderOffset) {
if (volume.size() < volumeHeader->ExtHeaderOffset + sizeof(EFI_FIRMWARE_VOLUME_EXT_HEADER)) {
if ((UINT32)volume.size() < volumeHeader->ExtHeaderOffset + sizeof(EFI_FIRMWARE_VOLUME_EXT_HEADER)) {
return U_INVALID_VOLUME;
}
const EFI_FIRMWARE_VOLUME_EXT_HEADER* extendedHeader = (const EFI_FIRMWARE_VOLUME_EXT_HEADER*)(volume.constData() + volumeHeader->ExtHeaderOffset);
Expand Down
58 changes: 36 additions & 22 deletions common/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,76 +15,90 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <sys/stat.h>
#include <fstream>

USTATUS readFileIntoBuffer(const UString& inPath, UByteArray& buf) {
bool readFileIntoBuffer(const UString& inPath, UByteArray& buf)
{
if (!isExistOnFs(inPath))
return U_FILE_OPEN;
return false;

std::ifstream inputFile(inPath.toLocal8Bit(), std::ios::in | std::ios::binary);
if (!inputFile)
return U_FILE_OPEN;
return false;
std::vector<char> buffer(std::istreambuf_iterator<char>(inputFile),
(std::istreambuf_iterator<char>()));
inputFile.close();

buf = buffer;

return U_SUCCESS;
return true;
}


#if defined(_WIN32) || defined(__MINGW32__)
#include <direct.h>
#include <stdlib.h>
bool isExistOnFs(const UString & path) {
bool isExistOnFs(const UString & path)
{
struct _stat buf;
return (_stat(path.toLocal8Bit(), &buf) == 0);
}

bool makeDirectory(const UString & dir) {
bool makeDirectory(const UString & dir)
{
return (_mkdir(dir.toLocal8Bit()) == 0);
}

bool changeDirectory(const UString & dir) {
bool changeDirectory(const UString & dir)
{
return (_chdir(dir.toLocal8Bit()) == 0);
}

void removeDirectory(const UString & dir) {
bool removeDirectory(const UString & dir)
{
int r = _rmdir(dir.toLocal8Bit());
// Hack: unlike *nix, Windows does not permit deleting current directories.
// Hack: unlike *nix, Windows does not permit deleting current directories
if (r < 0 && errno == EACCES && changeDirectory(dir + UString("/../"))) {
(void)_rmdir(dir.toLocal8Bit());
return (_rmdir(dir.toLocal8Bit()) == 0);
}
return (r == 0);
}

UString getAbsPath(const UString & path) {
char abs[_MAX_PATH] = {};
if (_fullpath(abs, path.toLocal8Bit(), sizeof(abs)))
return UString(abs);
return path;
UString getAbsPath(const UString & path)
{
char * abs = (char*)calloc(0x8000, 1);
UString new_path;
if (_fullpath(abs, path.toLocal8Bit(), 0x8000))
new_path = UString(abs);
else
new_path = path;
free(abs);
return new_path;
}
#else
#include <unistd.h>
#include <stdlib.h>
bool isExistOnFs(const UString & path) {
bool isExistOnFs(const UString & path)
{
struct stat buf;
return (stat(path.toLocal8Bit(), &buf) == 0);
}

bool makeDirectory(const UString & dir) {
bool makeDirectory(const UString & dir)
{
return (mkdir(dir.toLocal8Bit(), ACCESSPERMS) == 0);
}

void removeDirectory(const UString & dir) {
rmdir(dir.toLocal8Bit());
bool removeDirectory(const UString & dir)
{
return (rmdir(dir.toLocal8Bit()) == 0);
}

bool changeDirectory(const UString & dir) {
bool changeDirectory(const UString & dir)
{
return (chdir(dir.toLocal8Bit()) == 0);
}

UString getAbsPath(const UString & path) {
char abs[PATH_MAX] = {};
// Last is a non-standard extension for non-existent files.
// Last is a non-standard extension for non-existent files
if (realpath(path.toLocal8Bit(), abs) || abs[0] != '\0')
return UString(abs);
return path;
Expand Down
5 changes: 2 additions & 3 deletions common/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef FILESYSTEM_H
#define FILESYSTEM_H

#include "basetypes.h"
#include "ustring.h"
#include "ubytearray.h"

bool isExistOnFs(const UString& path);
bool makeDirectory(const UString& dir);
bool changeDirectory(const UString& dir);
void removeDirectory(const UString& dir);
bool removeDirectory(const UString& dir);
bool readFileIntoBuffer(const UString& inPath, UByteArray& buf);
UString getAbsPath(const UString& path);
USTATUS readFileIntoBuffer(const UString& inPath, UByteArray& buf);

#endif
Loading

0 comments on commit b6cdc9f

Please sign in to comment.