[unpaker2] lzma decoder.

This commit is contained in:
lzwdgc 2023-01-10 15:46:25 +03:00
parent 6b1db00fe6
commit b3c0b0489e
2 changed files with 25 additions and 3 deletions

View file

@ -32,6 +32,7 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <lzma.h>
#include <lzo/lzo1x.h> #include <lzo/lzo1x.h>
using namespace std; using namespace std;
@ -135,12 +136,30 @@ void unpack_file(path fn) {
} }
break; break;
} }
case segment::decode_algorithm::lzma: case segment::decode_algorithm::lzma: {
uint8_t flags = s;
lzma_stream strm{};
strm.next_in = s.p;
strm.avail_in = len;
strm.next_out = pp;
strm.avail_out = 1'000'000;
auto r = lzma_auto_decoder(&strm, 1'000'000'000, flags);
if (r != LZMA_OK) {
throw std::runtime_error{"lzma error"};
}
r = lzma_code(&strm, LZMA_RUN);
if (r != LZMA_STREAM_END) {
throw std::runtime_error{"lzma error"};
}
pp += strm.total_out;
break;
}
default: default:
throw std::runtime_error{"compression unsupported: "s + std::to_string(seg.algorithm)}; throw std::runtime_error{"compression unsupported: "s + std::to_string(seg.algorithm)};
} }
} }
exi:
pp = bbb.data(); pp = bbb.data();
auto dir = fn += ".dir2"; auto dir = fn += ".dir2";

5
sw.cpp
View file

@ -54,7 +54,10 @@ void build(Solution &s)
auto &unpaker = add_exe_base("unpaker"); // 32-bit only auto &unpaker = add_exe_base("unpaker"); // 32-bit only
if (unpaker.getBuildSettings().TargetOS.Arch != ArchType::x86) if (unpaker.getBuildSettings().TargetOS.Arch != ArchType::x86)
unpaker.HeaderOnly = true; unpaker.HeaderOnly = true;
add_exe_with_common("unpaker2") += "org.sw.demo.oberhumer.lzo.lzo"_dep; add_exe_with_common("unpaker2") +=
"org.sw.demo.oberhumer.lzo.lzo"_dep,
"org.sw.demo.xz_utils.lzma"_dep
;
// not so simple targets // not so simple targets
auto &script2txt = add_exe_with_common("script2txt"); auto &script2txt = add_exe_with_common("script2txt");