ooxml_crypt 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ext/ooxml_crypt/extconf.rb +18 -0
- data/ext/ooxml_crypt/ooxml_crypt.c +27 -0
- data/ext/ooxml_crypt/ooxml_crypt.h +7 -0
- data/lib/ooxml_crypt/version.rb +5 -0
- data/lib/ooxml_crypt.rb +75 -0
- data/vendor/cybozulib/.github/workflows/main.yml +12 -0
- data/vendor/cybozulib/.gitignore +5 -0
- data/vendor/cybozulib/CMakeLists.txt +6 -0
- data/vendor/cybozulib/COPYRIGHT +27 -0
- data/vendor/cybozulib/Makefile +26 -0
- data/vendor/cybozulib/bin/libeay32.dll +0 -0
- data/vendor/cybozulib/bin/libmecab.dll +0 -0
- data/vendor/cybozulib/bin/ssleay32.dll +0 -0
- data/vendor/cybozulib/common.mk +116 -0
- data/vendor/cybozulib/common.props +25 -0
- data/vendor/cybozulib/cybozulib.sln +286 -0
- data/vendor/cybozulib/debug.props +14 -0
- data/vendor/cybozulib/include/cybozu/array.hpp +197 -0
- data/vendor/cybozulib/include/cybozu/atoi.hpp +238 -0
- data/vendor/cybozulib/include/cybozu/atomic.hpp +146 -0
- data/vendor/cybozulib/include/cybozu/base64.hpp +210 -0
- data/vendor/cybozulib/include/cybozu/benchmark.hpp +212 -0
- data/vendor/cybozulib/include/cybozu/bfd.hpp +105 -0
- data/vendor/cybozulib/include/cybozu/bit_operation.hpp +139 -0
- data/vendor/cybozulib/include/cybozu/bitvector.hpp +358 -0
- data/vendor/cybozulib/include/cybozu/condition_variable.hpp +113 -0
- data/vendor/cybozulib/include/cybozu/condition_variable_cs.hpp +74 -0
- data/vendor/cybozulib/include/cybozu/config.hpp +392 -0
- data/vendor/cybozulib/include/cybozu/critical_section.hpp +60 -0
- data/vendor/cybozulib/include/cybozu/crypto.hpp +321 -0
- data/vendor/cybozulib/include/cybozu/csucvector.hpp +624 -0
- data/vendor/cybozulib/include/cybozu/csv.hpp +294 -0
- data/vendor/cybozulib/include/cybozu/data_type.hpp +27 -0
- data/vendor/cybozulib/include/cybozu/endian.hpp +224 -0
- data/vendor/cybozulib/include/cybozu/env.hpp +63 -0
- data/vendor/cybozulib/include/cybozu/event.hpp +122 -0
- data/vendor/cybozulib/include/cybozu/exception.hpp +253 -0
- data/vendor/cybozulib/include/cybozu/file.hpp +626 -0
- data/vendor/cybozulib/include/cybozu/fmindex.hpp +291 -0
- data/vendor/cybozulib/include/cybozu/format.hpp +93 -0
- data/vendor/cybozulib/include/cybozu/frequency.hpp +264 -0
- data/vendor/cybozulib/include/cybozu/hash.hpp +67 -0
- data/vendor/cybozulib/include/cybozu/inttype.hpp +174 -0
- data/vendor/cybozulib/include/cybozu/itoa.hpp +336 -0
- data/vendor/cybozulib/include/cybozu/json.hpp +120 -0
- data/vendor/cybozulib/include/cybozu/line_stream.hpp +149 -0
- data/vendor/cybozulib/include/cybozu/link_libeay32.hpp +21 -0
- data/vendor/cybozulib/include/cybozu/link_mpir.hpp +18 -0
- data/vendor/cybozulib/include/cybozu/link_ssleay32.hpp +19 -0
- data/vendor/cybozulib/include/cybozu/log.hpp +237 -0
- data/vendor/cybozulib/include/cybozu/minixml.hpp +452 -0
- data/vendor/cybozulib/include/cybozu/mmap.hpp +143 -0
- data/vendor/cybozulib/include/cybozu/mutex.hpp +144 -0
- data/vendor/cybozulib/include/cybozu/nlp/mecab.hpp +96 -0
- data/vendor/cybozulib/include/cybozu/nlp/plsi.hpp +315 -0
- data/vendor/cybozulib/include/cybozu/nlp/random.hpp +74 -0
- data/vendor/cybozulib/include/cybozu/nlp/sparse.hpp +529 -0
- data/vendor/cybozulib/include/cybozu/nlp/svd.hpp +486 -0
- data/vendor/cybozulib/include/cybozu/nlp/tfidf.hpp +226 -0
- data/vendor/cybozulib/include/cybozu/nlp/top_score.hpp +75 -0
- data/vendor/cybozulib/include/cybozu/option.hpp +743 -0
- data/vendor/cybozulib/include/cybozu/parallel.hpp +88 -0
- data/vendor/cybozulib/include/cybozu/pcg.hpp +72 -0
- data/vendor/cybozulib/include/cybozu/process.hpp +324 -0
- data/vendor/cybozulib/include/cybozu/quit_signal_handler.hpp +66 -0
- data/vendor/cybozulib/include/cybozu/random_generator.hpp +144 -0
- data/vendor/cybozulib/include/cybozu/regex.hpp +463 -0
- data/vendor/cybozulib/include/cybozu/select8.hpp +279 -0
- data/vendor/cybozulib/include/cybozu/serializer.hpp +363 -0
- data/vendor/cybozulib/include/cybozu/sha1.hpp +209 -0
- data/vendor/cybozulib/include/cybozu/sha2.hpp +506 -0
- data/vendor/cybozulib/include/cybozu/siphash.hpp +105 -0
- data/vendor/cybozulib/include/cybozu/socket.hpp +785 -0
- data/vendor/cybozulib/include/cybozu/ssl.hpp +203 -0
- data/vendor/cybozulib/include/cybozu/stacktrace.hpp +291 -0
- data/vendor/cybozulib/include/cybozu/stream.hpp +269 -0
- data/vendor/cybozulib/include/cybozu/string.hpp +1746 -0
- data/vendor/cybozulib/include/cybozu/string_operation.hpp +365 -0
- data/vendor/cybozulib/include/cybozu/sucvector.hpp +378 -0
- data/vendor/cybozulib/include/cybozu/test.hpp +373 -0
- data/vendor/cybozulib/include/cybozu/thread.hpp +229 -0
- data/vendor/cybozulib/include/cybozu/time.hpp +281 -0
- data/vendor/cybozulib/include/cybozu/tls.hpp +115 -0
- data/vendor/cybozulib/include/cybozu/unordered_map.hpp +13 -0
- data/vendor/cybozulib/include/cybozu/unordered_set.hpp +13 -0
- data/vendor/cybozulib/include/cybozu/v128.hpp +376 -0
- data/vendor/cybozulib/include/cybozu/wavelet_matrix.hpp +345 -0
- data/vendor/cybozulib/include/cybozu/xorshift.hpp +189 -0
- data/vendor/cybozulib/include/cybozu/zlib.hpp +325 -0
- data/vendor/cybozulib/include/sais.hxx +364 -0
- data/vendor/cybozulib/misc/make_select8tbl.cpp +26 -0
- data/vendor/cybozulib/mk.bat +37 -0
- data/vendor/cybozulib/readme.md +29 -0
- data/vendor/cybozulib/release.props +12 -0
- data/vendor/cybozulib/sample/Makefile +30 -0
- data/vendor/cybozulib/sample/csucvector_smpl.cpp +42 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.S +4 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.U +4 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.V +6 -0
- data/vendor/cybozulib/sample/data/svd/test1 +4 -0
- data/vendor/cybozulib/sample/data/svd/test2 +4 -0
- data/vendor/cybozulib/sample/desymbol.cpp +127 -0
- data/vendor/cybozulib/sample/exception_smpl.cpp +46 -0
- data/vendor/cybozulib/sample/fmindex_smpl.cpp +231 -0
- data/vendor/cybozulib/sample/log_smpl.cpp +19 -0
- data/vendor/cybozulib/sample/mecab_smpl.cpp +37 -0
- data/vendor/cybozulib/sample/option2_smpl.cpp +68 -0
- data/vendor/cybozulib/sample/option_smpl.cpp +42 -0
- data/vendor/cybozulib/sample/plsi_smpl.cpp +207 -0
- data/vendor/cybozulib/sample/proj/exception_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/proj/mecab_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/proj/ssl_smpl/ssl_smpl.vcxproj +85 -0
- data/vendor/cybozulib/sample/proj/ssl_smpl.vcproj +347 -0
- data/vendor/cybozulib/sample/proj/stacktrace_smpl/stacktrace_smpl.vcxproj +85 -0
- data/vendor/cybozulib/sample/proj/svd_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/quit_signal_handler.cpp +30 -0
- data/vendor/cybozulib/sample/serializer_smpl.cpp +196 -0
- data/vendor/cybozulib/sample/socket_smpl.cpp +82 -0
- data/vendor/cybozulib/sample/ssl_smpl.cpp +39 -0
- data/vendor/cybozulib/sample/stacktrace_smpl.cpp +52 -0
- data/vendor/cybozulib/sample/svd_bench_smpl.cpp +143 -0
- data/vendor/cybozulib/sample/svd_smpl.cpp +94 -0
- data/vendor/cybozulib/sample/wm_bench_smpl.cpp +182 -0
- data/vendor/cybozulib/sample/zlib_smpl.cpp +41 -0
- data/vendor/cybozulib/src/Makefile +8 -0
- data/vendor/cybozulib/src/base/Makefile +19 -0
- data/vendor/cybozulib/test/Makefile +12 -0
- data/vendor/cybozulib/test/base/Makefile +37 -0
- data/vendor/cybozulib/test/base/array_test.cpp +173 -0
- data/vendor/cybozulib/test/base/atoi_test.cpp +774 -0
- data/vendor/cybozulib/test/base/atomic_test.cpp +49 -0
- data/vendor/cybozulib/test/base/base64_test.cpp +113 -0
- data/vendor/cybozulib/test/base/bit_operation_test.cpp +134 -0
- data/vendor/cybozulib/test/base/bitvector_test.cpp +204 -0
- data/vendor/cybozulib/test/base/condition_variable_cs_test.cpp +92 -0
- data/vendor/cybozulib/test/base/condition_variable_test.cpp +88 -0
- data/vendor/cybozulib/test/base/config_test.cpp +236 -0
- data/vendor/cybozulib/test/base/crypto_test.cpp +122 -0
- data/vendor/cybozulib/test/base/csucvector_test.cpp +63 -0
- data/vendor/cybozulib/test/base/csv_test.cpp +182 -0
- data/vendor/cybozulib/test/base/data/a.xml +26 -0
- data/vendor/cybozulib/test/base/endian_test.cpp +56 -0
- data/vendor/cybozulib/test/base/env_test.cpp +22 -0
- data/vendor/cybozulib/test/base/event_test.cpp +41 -0
- data/vendor/cybozulib/test/base/file_test.cpp +233 -0
- data/vendor/cybozulib/test/base/fmindex_test.cpp +118 -0
- data/vendor/cybozulib/test/base/format_test.cpp +12 -0
- data/vendor/cybozulib/test/base/frequency_test.cpp +104 -0
- data/vendor/cybozulib/test/base/itoa_test.cpp +522 -0
- data/vendor/cybozulib/test/base/line_stream_test.cpp +208 -0
- data/vendor/cybozulib/test/base/mecab_test.cpp +41 -0
- data/vendor/cybozulib/test/base/minixml_test.cpp +103 -0
- data/vendor/cybozulib/test/base/mmap_test.cpp +15 -0
- data/vendor/cybozulib/test/base/option_test.cpp +487 -0
- data/vendor/cybozulib/test/base/parallel_test.cpp +48 -0
- data/vendor/cybozulib/test/base/proj/array_test/array_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/atoi_test/atoi_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/atomic_test/atomic_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/base64_test/base64_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/condition_variable_cs_test/condition_variable_cs_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/condition_variable_test/condition_variable_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/config_test/config_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/csv_test/csv_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/endian_test/endian_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/env_test/env_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/event_test/event_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/file_test/file_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/itoa_test/itoa_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/mecab_test/mecab_test.vcxproj +88 -0
- data/vendor/cybozulib/test/base/proj/minixml_test/minixml_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/mmap_test/mmap_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/serializer_test/serializer_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/sha1_test/sha1_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/stream_test/stream_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/string_operation_test/string_operation_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/string_test/string_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/thread_test/thread_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/time_test/time_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/tls_test/tls_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/zlib_test/zlib_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/random_generator_test.cpp +28 -0
- data/vendor/cybozulib/test/base/regex_test.cpp +74 -0
- data/vendor/cybozulib/test/base/serializer_test.cpp +483 -0
- data/vendor/cybozulib/test/base/sha1_test.cpp +61 -0
- data/vendor/cybozulib/test/base/sha2_test.cpp +191 -0
- data/vendor/cybozulib/test/base/siphash_test.cpp +33 -0
- data/vendor/cybozulib/test/base/socket_test.cpp +76 -0
- data/vendor/cybozulib/test/base/stream_test.cpp +101 -0
- data/vendor/cybozulib/test/base/string_operation_test.cpp +340 -0
- data/vendor/cybozulib/test/base/string_test.cpp +1705 -0
- data/vendor/cybozulib/test/base/sucvector_test.cpp +312 -0
- data/vendor/cybozulib/test/base/thread_test.cpp +62 -0
- data/vendor/cybozulib/test/base/time_test.cpp +164 -0
- data/vendor/cybozulib/test/base/tls_test.cpp +50 -0
- data/vendor/cybozulib/test/base/wavelet_matrix_test.cpp +145 -0
- data/vendor/cybozulib/test/base/zlib_test.cpp +371 -0
- data/vendor/cybozulib/test/nlp/Makefile +27 -0
- data/vendor/cybozulib/test/nlp/proj/random_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/proj/sparse_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/proj/svd_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/random_test.cpp +62 -0
- data/vendor/cybozulib/test/nlp/sparse_test.cpp +347 -0
- data/vendor/cybozulib/test/nlp/svd_test.cpp +234 -0
- data/vendor/cybozulib/test/nlp/top_score_test.cpp +40 -0
- data/vendor/cybozulib/tool/create_vcproj.py +186 -0
- data/vendor/cybozulib/tool/vcproj_tmpl.py +185 -0
- data/vendor/msoffice/COPYRIGHT +27 -0
- data/vendor/msoffice/Makefile +29 -0
- data/vendor/msoffice/bin/64/msoc.dll +0 -0
- data/vendor/msoffice/bin/64/msocsample.exe +0 -0
- data/vendor/msoffice/bin/64/msoffice-crypt.exe +0 -0
- data/vendor/msoffice/bin/msoc.dll +0 -0
- data/vendor/msoffice/bin/msocsample.exe +0 -0
- data/vendor/msoffice/bin/msoffice-crypt.exe +0 -0
- data/vendor/msoffice/common.mk +71 -0
- data/vendor/msoffice/common.props +26 -0
- data/vendor/msoffice/debug.props +14 -0
- data/vendor/msoffice/include/attack.hpp +211 -0
- data/vendor/msoffice/include/cfb.hpp +777 -0
- data/vendor/msoffice/include/crypto_util.hpp +450 -0
- data/vendor/msoffice/include/custom_sha1.hpp +342 -0
- data/vendor/msoffice/include/decode.hpp +240 -0
- data/vendor/msoffice/include/encode.hpp +221 -0
- data/vendor/msoffice/include/make_dataspace.hpp +316 -0
- data/vendor/msoffice/include/msoc.h +129 -0
- data/vendor/msoffice/include/resource.hpp +7 -0
- data/vendor/msoffice/include/standard_encryption.hpp +145 -0
- data/vendor/msoffice/include/uint32vec.hpp +179 -0
- data/vendor/msoffice/include/util.hpp +212 -0
- data/vendor/msoffice/lib/.emptydir +0 -0
- data/vendor/msoffice/misc/decrypt-xls.vbs +46 -0
- data/vendor/msoffice/mk.bat +1 -0
- data/vendor/msoffice/mkdll.bat +3 -0
- data/vendor/msoffice/msoc.def +13 -0
- data/vendor/msoffice/msocsample.py +178 -0
- data/vendor/msoffice/msoffice12.sln +31 -0
- data/vendor/msoffice/readme.md +110 -0
- data/vendor/msoffice/release.props +28 -0
- data/vendor/msoffice/src/Makefile +19 -0
- data/vendor/msoffice/src/attack.cpp +124 -0
- data/vendor/msoffice/src/cfb_test.cpp +77 -0
- data/vendor/msoffice/src/minisample.c +54 -0
- data/vendor/msoffice/src/msocdll.cpp +276 -0
- data/vendor/msoffice/src/msocsample.c +136 -0
- data/vendor/msoffice/src/msoffice-crypt.cpp +219 -0
- data/vendor/msoffice/src/proj/attack/attack.vcxproj +88 -0
- data/vendor/msoffice/src/proj/main/msoffice-crypt.vcxproj +88 -0
- data/vendor/msoffice/src/sha1.cpp +234 -0
- data/vendor/msoffice/test/Makefile +20 -0
- data/vendor/msoffice/test/cfb_test.cpp +74 -0
- data/vendor/msoffice/test/hash_test.cpp +59 -0
- data/vendor/msoffice/test/proj/cfb/cfb_test.vcxproj +90 -0
- data/vendor/msoffice/test/proj/hash/hash_test.vcxproj +90 -0
- data/vendor/msoffice/test/sampl.bat +8 -0
- data/vendor/msoffice/test_all.py +46 -0
- data/vendor/update +4 -0
- metadata +351 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# @file
|
3
|
+
# @brief MS Office Crypt DLL sample
|
4
|
+
# @author herumi
|
5
|
+
# Copyright (C) 2016 Cybozu Labs, Inc., all rights reserved.
|
6
|
+
import os, sys
|
7
|
+
import argparse
|
8
|
+
from ctypes import *
|
9
|
+
from ctypes.wintypes import LPWSTR, LPCSTR, LPVOID
|
10
|
+
|
11
|
+
MSOC_OPT_TYPE_SPIN_COUNT = 1
|
12
|
+
MSOC_OPT_TYPE_SECRET_KEY = 2
|
13
|
+
|
14
|
+
def getWargv():
|
15
|
+
cmd = cdll.kernel32.GetCommandLineW()
|
16
|
+
argc = c_int(0)
|
17
|
+
CommandLineToArgvW = windll.shell32.CommandLineToArgvW
|
18
|
+
CommandLineToArgvW.restype = POINTER(LPWSTR)
|
19
|
+
argv = CommandLineToArgvW(cmd, byref(argc))
|
20
|
+
ret = []
|
21
|
+
for i in xrange(argc.value):
|
22
|
+
ret.append(argv[i])
|
23
|
+
return ret
|
24
|
+
|
25
|
+
def wchar2ascii(w):
|
26
|
+
s = ''
|
27
|
+
for wc in w:
|
28
|
+
c = chr(ord(wc))
|
29
|
+
s += c
|
30
|
+
return s
|
31
|
+
|
32
|
+
def putErrMsg(lib, err):
|
33
|
+
MSOC_getErrMessage = lib.MSOC_getErrMessage
|
34
|
+
MSOC_getErrMessage.restype = LPCSTR
|
35
|
+
print 'ERR', MSOC_getErrMessage(err)
|
36
|
+
os._exit(1)
|
37
|
+
|
38
|
+
def _createOpt(lib):
|
39
|
+
opt = c_void_p(0)
|
40
|
+
MSOC_createOpt = lib.MSOC_createOpt
|
41
|
+
MSOC_createOpt.restype = LPVOID
|
42
|
+
opt = MSOC_createOpt()
|
43
|
+
if opt:
|
44
|
+
return opt
|
45
|
+
print 'ERR MSOC_createOpt()'
|
46
|
+
os._exit(1)
|
47
|
+
|
48
|
+
def _destroyOpt(lib, opt):
|
49
|
+
lib.MSOC_destroyOpt(opt)
|
50
|
+
|
51
|
+
def _getInt(lib, opt, optType):
|
52
|
+
intv = c_int(0)
|
53
|
+
err = lib.MSOC_getInt(byref(intv), opt, optType)
|
54
|
+
if err:
|
55
|
+
putErrMsg(lib, err)
|
56
|
+
return intv.value
|
57
|
+
|
58
|
+
def _setInt(lib, opt, optType, v):
|
59
|
+
err = lib.MSOC_setInt(opt, optType, v)
|
60
|
+
if err:
|
61
|
+
putErrMsg(lib, err)
|
62
|
+
|
63
|
+
def _getStr(lib, opt, optType):
|
64
|
+
svLen = 256
|
65
|
+
sv = create_string_buffer('\0' * svLen)
|
66
|
+
err = lib.MSOC_getStr(sv, svLen, opt, optType)
|
67
|
+
if err:
|
68
|
+
putErrMsg(lib, err)
|
69
|
+
return sv.value
|
70
|
+
|
71
|
+
def _setStr(lib, opt, optType, s):
|
72
|
+
cs = c_char_p(s)
|
73
|
+
err = lib.MSOC_setStr(opt, optType, cs)
|
74
|
+
if err:
|
75
|
+
putErrMsg(lib, err)
|
76
|
+
|
77
|
+
class Msoc:
|
78
|
+
def __init__(self):
|
79
|
+
if sys.maxsize > 2**32:
|
80
|
+
dll = 'bin/64/msoc.dll'
|
81
|
+
else:
|
82
|
+
dll = 'bin/msoc.dll'
|
83
|
+
self.lib = windll.LoadLibrary(dll)
|
84
|
+
self.opt = _createOpt(self.lib)
|
85
|
+
def __del__(self):
|
86
|
+
_destroyOpt(self.lib, self.opt)
|
87
|
+
|
88
|
+
def encrypt(self, outFile, inFile, ps):
|
89
|
+
outFileW = c_wchar_p(outFile)
|
90
|
+
inFileW = c_wchar_p(inFile)
|
91
|
+
psW = c_wchar_p(ps)
|
92
|
+
# permit self.opt is None
|
93
|
+
err = self.lib.MSOC_encrypt(outFileW, inFileW, psW, self.opt)
|
94
|
+
if err:
|
95
|
+
putErrMsg(self.lib, err)
|
96
|
+
|
97
|
+
def decrypt(self, outFile, inFile, ps):
|
98
|
+
if outFile:
|
99
|
+
outFileW = c_wchar_p(outFile)
|
100
|
+
else:
|
101
|
+
outFileW = None
|
102
|
+
inFileW = c_wchar_p(inFile)
|
103
|
+
psW = c_wchar_p(ps)
|
104
|
+
# permit self.opt is None
|
105
|
+
err = self.lib.MSOC_decrypt(outFileW, inFileW, psW, self.opt)
|
106
|
+
if err:
|
107
|
+
putErrMsg(self.lib, err)
|
108
|
+
|
109
|
+
def getOpt(self, optType):
|
110
|
+
if optType in [MSOC_OPT_TYPE_SPIN_COUNT]:
|
111
|
+
return _getInt(self.lib, self.opt, optType)
|
112
|
+
elif optType in [MSOC_OPT_TYPE_SECRET_KEY]:
|
113
|
+
return _getStr(self.lib, self.opt, optType)
|
114
|
+
else:
|
115
|
+
raise Exception('getOpt not support type', optType)
|
116
|
+
|
117
|
+
def setOpt(self, optType, v):
|
118
|
+
if optType in [MSOC_OPT_TYPE_SPIN_COUNT]:
|
119
|
+
return _setInt(self.lib, self.opt, optType, v)
|
120
|
+
elif optType in [MSOC_OPT_TYPE_SECRET_KEY]:
|
121
|
+
return _setStr(self.lib, self.opt, optType, v)
|
122
|
+
else:
|
123
|
+
raise Exception('setOpt not support type', optType)
|
124
|
+
|
125
|
+
def main():
|
126
|
+
parser = argparse.ArgumentParser(description='msocsample.py')
|
127
|
+
sub = parser.add_subparsers(dest='mode')
|
128
|
+
enc = sub.add_parser('enc', help='encrypt')
|
129
|
+
enc.add_argument('inFile')
|
130
|
+
enc.add_argument('outFile')
|
131
|
+
enc.add_argument('ps', help='password')
|
132
|
+
enc.add_argument('-sc', '--spinCount', help='spinCount')
|
133
|
+
enc.add_argument('-sk', '--secretKey', help='secretKey')
|
134
|
+
|
135
|
+
dec = sub.add_parser('dec', help='decrypt')
|
136
|
+
dec.add_argument('inFile')
|
137
|
+
dec.add_argument('outFile')
|
138
|
+
dec.add_argument('ps', help='password')
|
139
|
+
|
140
|
+
opt = sub.add_parser('opt', help='view option')
|
141
|
+
opt.add_argument('inFile')
|
142
|
+
opt.add_argument('ps', help='password')
|
143
|
+
|
144
|
+
dec_sk = sub.add_parser('dec-sk', help='decrypt by secret key')
|
145
|
+
dec_sk.add_argument('inFile')
|
146
|
+
dec_sk.add_argument('outFile')
|
147
|
+
dec_sk.add_argument('secretKey')
|
148
|
+
|
149
|
+
argv = getWargv()
|
150
|
+
for pos in xrange(len(argv)):
|
151
|
+
if argv[pos].find('msocsample.py') >= 0:
|
152
|
+
argv = argv[pos + 1:]
|
153
|
+
break
|
154
|
+
|
155
|
+
arg = parser.parse_args(argv)
|
156
|
+
|
157
|
+
msoc = Msoc()
|
158
|
+
|
159
|
+
if getattr(arg, 'secretKey', None) and arg.secretKey:
|
160
|
+
secretKey = wchar2ascii(arg.secretKey)
|
161
|
+
msoc.setOpt(MSOC_OPT_TYPE_SECRET_KEY, secretKey)
|
162
|
+
if getattr(arg, 'spinCount', None) and arg.spinCount:
|
163
|
+
spinCount = int(wchar2ascii(arg.spinCount))
|
164
|
+
msoc.setOpt(MSOC_OPT_TYPE_SPIN_COUNT, spinCount)
|
165
|
+
|
166
|
+
if arg.mode == 'enc':
|
167
|
+
msoc.encrypt(arg.outFile, arg.inFile, arg.ps)
|
168
|
+
elif arg.mode == 'dec':
|
169
|
+
msoc.decrypt(arg.outFile, arg.inFile, arg.ps)
|
170
|
+
elif arg.mode == 'opt':
|
171
|
+
msoc.decrypt(None, arg.inFile, arg.ps)
|
172
|
+
print 'spinCount', msoc.getOpt(MSOC_OPT_TYPE_SPIN_COUNT)
|
173
|
+
print 'secretKey', msoc.getOpt(MSOC_OPT_TYPE_SECRET_KEY)
|
174
|
+
elif arg.mode == 'dec-sk':
|
175
|
+
msoc.decrypt(arg.outFile, arg.inFile, None)
|
176
|
+
|
177
|
+
if __name__ == '__main__':
|
178
|
+
main()
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Microsoft Visual Studio Solution File, Format Version 12.00
|
2
|
+
# Visual Studio 2012
|
3
|
+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "attack", "src\proj\attack\attack.vcxproj", "{40B5AD5D-5F35-4FFD-945D-022E7F1AAB31}"
|
4
|
+
EndProject
|
5
|
+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hash_test", "test\proj\hash\hash_test.vcxproj", "{3964602A-8554-4AB5-BB10-E4A24CFBCA4F}"
|
6
|
+
EndProject
|
7
|
+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msoffice-crypt", "src\proj\main\msoffice-crypt.vcxproj", "{9E396E79-C168-4C40-BDE0-C9413B33C8CE}"
|
8
|
+
EndProject
|
9
|
+
Global
|
10
|
+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
11
|
+
Debug|x64 = Debug|x64
|
12
|
+
Release|x64 = Release|x64
|
13
|
+
EndGlobalSection
|
14
|
+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
15
|
+
{40B5AD5D-5F35-4FFD-945D-022E7F1AAB31}.Debug|x64.ActiveCfg = Debug|x64
|
16
|
+
{40B5AD5D-5F35-4FFD-945D-022E7F1AAB31}.Debug|x64.Build.0 = Debug|x64
|
17
|
+
{40B5AD5D-5F35-4FFD-945D-022E7F1AAB31}.Release|x64.ActiveCfg = Release|x64
|
18
|
+
{40B5AD5D-5F35-4FFD-945D-022E7F1AAB31}.Release|x64.Build.0 = Release|x64
|
19
|
+
{3964602A-8554-4AB5-BB10-E4A24CFBCA4F}.Debug|x64.ActiveCfg = Debug|x64
|
20
|
+
{3964602A-8554-4AB5-BB10-E4A24CFBCA4F}.Debug|x64.Build.0 = Debug|x64
|
21
|
+
{3964602A-8554-4AB5-BB10-E4A24CFBCA4F}.Release|x64.ActiveCfg = Release|x64
|
22
|
+
{3964602A-8554-4AB5-BB10-E4A24CFBCA4F}.Release|x64.Build.0 = Release|x64
|
23
|
+
{9E396E79-C168-4C40-BDE0-C9413B33C8CE}.Debug|x64.ActiveCfg = Debug|x64
|
24
|
+
{9E396E79-C168-4C40-BDE0-C9413B33C8CE}.Debug|x64.Build.0 = Debug|x64
|
25
|
+
{9E396E79-C168-4C40-BDE0-C9413B33C8CE}.Release|x64.ActiveCfg = Release|x64
|
26
|
+
{9E396E79-C168-4C40-BDE0-C9413B33C8CE}.Release|x64.Build.0 = Release|x64
|
27
|
+
EndGlobalSection
|
28
|
+
GlobalSection(SolutionProperties) = preSolution
|
29
|
+
HideSolutionNode = FALSE
|
30
|
+
EndGlobalSection
|
31
|
+
EndGlobal
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# A tool/lib to encrypt/decrypt Microsoft Office Document
|
2
|
+
|
3
|
+
# Environment
|
4
|
+
|
5
|
+
* 64-bit Windows Visual Studio 2012 or later
|
6
|
+
* gcc 4.6, clang 3.0 or later
|
7
|
+
|
8
|
+
# How to make `bin/msoffice-crypt.exe`
|
9
|
+
|
10
|
+
Linux
|
11
|
+
```
|
12
|
+
mkdir work
|
13
|
+
git clone https://github.com/herumi/cybozulib
|
14
|
+
git clone https://github.com/herumi/msoffice
|
15
|
+
cd msoffice
|
16
|
+
make -j RELEASE=1
|
17
|
+
```
|
18
|
+
Windows
|
19
|
+
```
|
20
|
+
mkdir work
|
21
|
+
git clone https://github.com/herumi/cybozulib
|
22
|
+
git clone https://github.com/herumi/msoffice
|
23
|
+
git clone https://github.com/herumi/cybozulib_ext # for openssl
|
24
|
+
cd msoffice
|
25
|
+
mk.bat ; or open msoffice12.sln and build
|
26
|
+
```
|
27
|
+
# How to use
|
28
|
+
* Encrypt test.xlsx with a password `test`.
|
29
|
+
```
|
30
|
+
bin/msoffice-crypt.exe -e -p test test.xlsx enc.xlsx
|
31
|
+
```
|
32
|
+
* Decrypt enc.xlsx with a password `test`.
|
33
|
+
```
|
34
|
+
bin/msoffice-crypt.exe -d -p test enc.xlsx dec.xlsx
|
35
|
+
```
|
36
|
+
|
37
|
+
* Other options
|
38
|
+
```
|
39
|
+
usage:msoffice-crypt.exe [opt] input output
|
40
|
+
-h : show this message
|
41
|
+
-p password in only ascii
|
42
|
+
-encMode 0:use AES128(default), 1: use AES256 for encoding
|
43
|
+
-ph8 password in utf8 hex. ex. 68656C6C6F for 'hello'
|
44
|
+
-ph16 password in utf16 hex. ex. u3042u3044u3046 for 'aiu' in hiragana
|
45
|
+
-k (experimental) secret key in hex. ex. 0123456789ABCDEF0123456789ABCDEF
|
46
|
+
-by (experimental) extract secret key from this file
|
47
|
+
-e encode
|
48
|
+
-d decode
|
49
|
+
-c spin count
|
50
|
+
-psk print secret key
|
51
|
+
-v print debug info
|
52
|
+
-vv print debug info and save binary data
|
53
|
+
```
|
54
|
+
# Return code
|
55
|
+
|
56
|
+
* 0 success
|
57
|
+
* 1 not support formart
|
58
|
+
* 2 already encrypted with -e or decrypted with -d
|
59
|
+
* 3 bad password with -d
|
60
|
+
|
61
|
+
# Support format
|
62
|
+
|
63
|
+
Office 2010 or later Office Document format which suffix is pptx, docx, xlsx.
|
64
|
+
|
65
|
+
# DLL for Windows
|
66
|
+
* msoc.dll (Microsoft Office Crypto)
|
67
|
+
|
68
|
+
* [msoc.dll](https://github.com/herumi/msoffice/raw/master/bin/msoc.dll)
|
69
|
+
* [msoc.h](https://github.com/herumi/msoffice/blob/master/include/msoc.h)
|
70
|
+
|
71
|
+
* Encrypt `inFile` with `pass` and make `outFile`.
|
72
|
+
```
|
73
|
+
MSOC_encrypt(outFile, inFile, pass, NULL);
|
74
|
+
```
|
75
|
+
* Decrypt `inFile` with `pass` and make `outFile`.
|
76
|
+
```
|
77
|
+
MSOC_decrypt(outFile, inFile, pass, NULL);
|
78
|
+
```
|
79
|
+
## Remark
|
80
|
+
The type of `inFile`, `outFile` and `pass` are `const wchar_t*`(UTF-16 string).
|
81
|
+
See [Csample code](https://github.com/herumi/msoffice/blob/master/src/msocsample.c)
|
82
|
+
and [Python sample code](https://github.com/herumi/msoffice/blob/master/bin/msocsample.py).
|
83
|
+
|
84
|
+
# lib for Linux
|
85
|
+
* libmsoc.lib
|
86
|
+
|
87
|
+
* Encrypt `inFile` with `pass` and make `outFile`.
|
88
|
+
```
|
89
|
+
MSOC_encryptA(outFile, inFile, pass, NULL);
|
90
|
+
```
|
91
|
+
* Decrypt `inFile` with `pass` and make `outFile`.
|
92
|
+
```
|
93
|
+
MSOC_decryptA(outFile, inFile, pass, NULL);
|
94
|
+
```
|
95
|
+
## Remark
|
96
|
+
The type of `inFile`, `outFile` and `pass` are `const char*`(ascii string).
|
97
|
+
See [mini C sample code](https://github.com/herumi/msoffice/blob/master/src/minisample.c).
|
98
|
+
|
99
|
+
# License
|
100
|
+
BSD 3-Clause License
|
101
|
+
|
102
|
+
Copyright (c) 2015 Cybozu Labs, Inc. All rights reserved.
|
103
|
+
|
104
|
+
# References
|
105
|
+
|
106
|
+
* Compound File Binary File Format(v20120328)
|
107
|
+
[[MS-CFB]](http://msdn.microsoft.com/en-us/library/dd942138.aspx)
|
108
|
+
* Office Document Cryptography Structure Specification(v20120412)
|
109
|
+
[[MS-OFFCRYPTO]](http://msdn.microsoft.com/en-us/library/cc313071.aspx)
|
110
|
+
* CODE BLUE 2015 [[Backdoors with the MS Office file encryption master key and a proposal for a reliable file format]](http://www.slideshare.net/herumi/backdoors-with-the-ms-office-file-encryption-master-key-and-a-proposal-for-a-reliable-file-format)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
3
|
+
<ImportGroup Label="PropertySheets" />
|
4
|
+
<PropertyGroup Label="UserMacros" />
|
5
|
+
<PropertyGroup />
|
6
|
+
<ItemDefinitionGroup>
|
7
|
+
<ClCompile>
|
8
|
+
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
9
|
+
</ClCompile>
|
10
|
+
</ItemDefinitionGroup>
|
11
|
+
<ItemDefinitionGroup>
|
12
|
+
<ClCompile>
|
13
|
+
<IntrinsicFunctions>true</IntrinsicFunctions>
|
14
|
+
</ClCompile>
|
15
|
+
</ItemDefinitionGroup>
|
16
|
+
<ItemDefinitionGroup>
|
17
|
+
<ClCompile>
|
18
|
+
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
19
|
+
</ClCompile>
|
20
|
+
</ItemDefinitionGroup>
|
21
|
+
<ItemDefinitionGroup>
|
22
|
+
<ClCompile>
|
23
|
+
<OmitFramePointers>true</OmitFramePointers>
|
24
|
+
<BufferSecurityCheck>false</BufferSecurityCheck>
|
25
|
+
</ClCompile>
|
26
|
+
</ItemDefinitionGroup>
|
27
|
+
<ItemGroup />
|
28
|
+
</Project>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
include ../common.mk
|
2
|
+
|
3
|
+
TARGET=$(TEST_FILE)
|
4
|
+
|
5
|
+
SRC=msoffice-crypt.cpp attack.cpp
|
6
|
+
|
7
|
+
all: $(TARGET) $(SRC)
|
8
|
+
|
9
|
+
test: $(TARGET)
|
10
|
+
@$(SAMPLE_TEST)
|
11
|
+
|
12
|
+
$(OBJDIR):
|
13
|
+
@$(MKDIR) $(OBJDIR)
|
14
|
+
|
15
|
+
clean:
|
16
|
+
$(CLEAN)
|
17
|
+
|
18
|
+
-include $(DEPEND_FILE)
|
19
|
+
|
@@ -0,0 +1,124 @@
|
|
1
|
+
/**
|
2
|
+
Copyright (C) 2012 Cybozu Labs, Inc., all rights reserved.
|
3
|
+
*/
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <string>
|
7
|
+
#include <locale>
|
8
|
+
#include <fstream>
|
9
|
+
#include <cybozu/mmap.hpp>
|
10
|
+
#include <cybozu/file.hpp>
|
11
|
+
#include <cybozu/atoi.hpp>
|
12
|
+
#include <cybozu/option.hpp>
|
13
|
+
#include "cfb.hpp"
|
14
|
+
#include "attack.hpp"
|
15
|
+
#include "make_dataspace.hpp"
|
16
|
+
|
17
|
+
struct Option {
|
18
|
+
typedef std::vector<std::string> StrVec;
|
19
|
+
std::string encFile;
|
20
|
+
std::string charSet;
|
21
|
+
StrVec passSet;
|
22
|
+
size_t threadNum;
|
23
|
+
size_t passLen;
|
24
|
+
void trim(std::string& str) const
|
25
|
+
{
|
26
|
+
const size_t size = str.size();
|
27
|
+
if (size == 0) return;
|
28
|
+
const char c = str[size - 1];
|
29
|
+
if (c == '\n' || c == '\r') str.resize(size - 1);
|
30
|
+
}
|
31
|
+
void toUtf8(std::string& str) const
|
32
|
+
{
|
33
|
+
const size_t size = str.size();
|
34
|
+
std::string out(size * 2, '\0');
|
35
|
+
for (size_t i = 0; i < size; i++) {
|
36
|
+
out[i * 2] = str[i];
|
37
|
+
}
|
38
|
+
str.swap(out);
|
39
|
+
}
|
40
|
+
static inline bool lessByLength(const std::string& rhs, const std::string& lhs)
|
41
|
+
{
|
42
|
+
if (rhs.size() < lhs.size()) return true;
|
43
|
+
if (rhs.size() > lhs.size()) return false;
|
44
|
+
return rhs < lhs;
|
45
|
+
}
|
46
|
+
Option(int argc, const char *const argv[])
|
47
|
+
{
|
48
|
+
cybozu::Option opt;
|
49
|
+
std::string charSetFile;
|
50
|
+
std::string dicFile;
|
51
|
+
bool debug;
|
52
|
+
opt.appendOpt(&charSetFile, "", "cf", "char set file");
|
53
|
+
opt.appendOpt(&threadNum, 4, "t", "thread num");
|
54
|
+
opt.appendOpt(&dicFile, "", "d", "dictionary file");
|
55
|
+
opt.appendOpt(&passLen, 0, "l", "length of pass");
|
56
|
+
opt.appendBoolOpt(&debug, "v", "verbose message");
|
57
|
+
opt.appendHelp("h");
|
58
|
+
opt.appendParam(&encFile, "encrypted file");
|
59
|
+
if (!opt.parse(argc, argv)) {
|
60
|
+
opt.usage();
|
61
|
+
exit(1);
|
62
|
+
}
|
63
|
+
if (debug) ms::setDebug(2);
|
64
|
+
if (charSetFile.empty()) {
|
65
|
+
charSet = "abcdefghijklmnopqrstuvwxyz"
|
66
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
67
|
+
"0123456789-_";
|
68
|
+
} else {
|
69
|
+
std::ifstream ifs(charSetFile.c_str(), std::ios::binary);
|
70
|
+
if (!std::getline(ifs, charSet)) {
|
71
|
+
fprintf(stderr, "can't read char set file [%s]\n", charSetFile.c_str());
|
72
|
+
exit(1);
|
73
|
+
}
|
74
|
+
trim(charSet);
|
75
|
+
}
|
76
|
+
if (!dicFile.empty()) {
|
77
|
+
std::ifstream ifs(dicFile.c_str(), std::ios::binary);
|
78
|
+
std::string line;
|
79
|
+
while (std::getline(ifs, line)) {
|
80
|
+
trim(line);
|
81
|
+
toUtf8(line);
|
82
|
+
passSet.push_back(line);
|
83
|
+
}
|
84
|
+
if (passSet.empty()) {
|
85
|
+
fprintf(stderr, "can't read dicFile [%s]\n", dicFile.c_str());
|
86
|
+
exit(1);
|
87
|
+
}
|
88
|
+
std::sort(passSet.begin(), passSet.end(), &lessByLength);
|
89
|
+
}
|
90
|
+
if (ms::isDebug()) {
|
91
|
+
opt.put();
|
92
|
+
}
|
93
|
+
}
|
94
|
+
};
|
95
|
+
|
96
|
+
int main(int argc, char *argv[])
|
97
|
+
try
|
98
|
+
{
|
99
|
+
#ifdef SHA1_USE_SIMD
|
100
|
+
printf("use simd x %d\n", Uint32Vec::size);
|
101
|
+
#endif
|
102
|
+
const Option opt(argc, argv);
|
103
|
+
cybozu::Mmap m(opt.encFile);
|
104
|
+
const char *data = m.get();
|
105
|
+
if (m.size() > 0xffffffff) {
|
106
|
+
throw cybozu::Exception("ms:encode:m.size") << m.size();
|
107
|
+
}
|
108
|
+
const uint32_t dataSize = static_cast<uint32_t>(m.size());
|
109
|
+
const ms::Format format = ms::DetectFormat(data, dataSize);
|
110
|
+
|
111
|
+
if (format == ms::fZip) {
|
112
|
+
printf("already decrypted\n");
|
113
|
+
return 2;
|
114
|
+
}
|
115
|
+
if (!opt.passSet.empty()) {
|
116
|
+
ms::Attack attack(data, dataSize, opt.threadNum, opt.passSet);
|
117
|
+
}
|
118
|
+
if (opt.passLen) {
|
119
|
+
ms::Attack attack(data, dataSize, opt.passLen);
|
120
|
+
}
|
121
|
+
} catch (std::exception& e) {
|
122
|
+
printf("exception:%s\n", e.what());
|
123
|
+
return 1;
|
124
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <stdlib.h>
|
3
|
+
#include <string>
|
4
|
+
#include <locale>
|
5
|
+
#include <fstream>
|
6
|
+
#include <cybozu/mmap.hpp>
|
7
|
+
#include "cfb.hpp"
|
8
|
+
|
9
|
+
|
10
|
+
void usage()
|
11
|
+
{
|
12
|
+
fprintf(stderr, "cfb_test -f <inFile>\n");
|
13
|
+
exit(1);
|
14
|
+
}
|
15
|
+
|
16
|
+
std::string toAscii(const cybozu::String16& str)
|
17
|
+
{
|
18
|
+
std::string ret;
|
19
|
+
if (cybozu::ConvertUtf16ToUtf8(&ret, str)) {
|
20
|
+
return ret;
|
21
|
+
}
|
22
|
+
return "";
|
23
|
+
}
|
24
|
+
|
25
|
+
void run(const std::string& inFile)
|
26
|
+
{
|
27
|
+
cybozu::Mmap m(inFile);
|
28
|
+
if (m.size() > 0xffffffff) {
|
29
|
+
fprintf(stderr, "too large file size %lld\n", m.size());
|
30
|
+
exit(1);
|
31
|
+
}
|
32
|
+
const uint32_t mSize = static_cast<uint32_t>(m.size());
|
33
|
+
ms::cfb::CompoundFile cfb(m.get(), mSize);
|
34
|
+
cfb.put();
|
35
|
+
const char nameTbl[][128] = {
|
36
|
+
"EncryptedPackage",
|
37
|
+
"EncryptionInfo",
|
38
|
+
};
|
39
|
+
const ms::cfb::DirectoryEntryVec& dirs = cfb.dirs;
|
40
|
+
for (size_t i = 0; i < dirs.size(); i++) {
|
41
|
+
const ms::cfb::DirectoryEntry& dir = dirs[i];
|
42
|
+
for (size_t j = 0; j < CYBOZU_NUM_OF_ARRAY(nameTbl); j++) {
|
43
|
+
std::string asc = toAscii(dir.directoryEntryName);
|
44
|
+
if (asc == nameTbl[j]) {
|
45
|
+
printf("save %s\n", nameTbl[j]);
|
46
|
+
std::ofstream ofs(nameTbl[j], std::ios::binary);
|
47
|
+
ofs.write((const char*)&dir.data[0], (size_t)dir.streamSize);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
int main(int argc, char *argv[])
|
54
|
+
try
|
55
|
+
{
|
56
|
+
std::locale::global(std::locale(""));
|
57
|
+
|
58
|
+
argc--, argv++;
|
59
|
+
std::string inFile;
|
60
|
+
while (argc > 0) {
|
61
|
+
if (argc > 1 && strcmp(*argv, "-f") == 0) {
|
62
|
+
argc--, argv++;
|
63
|
+
inFile = *argv;
|
64
|
+
} else
|
65
|
+
{
|
66
|
+
usage();
|
67
|
+
}
|
68
|
+
argc--, argv++;
|
69
|
+
}
|
70
|
+
if (inFile.empty()) {
|
71
|
+
usage();
|
72
|
+
}
|
73
|
+
run(inFile);
|
74
|
+
} catch (std::exception& e) {
|
75
|
+
fprintf(stderr, "exception:%s\n", e.what());
|
76
|
+
return 1;
|
77
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/**
|
2
|
+
@file
|
3
|
+
@brief mini MS Office Crypt DLL sample
|
4
|
+
@author herumi
|
5
|
+
Copyright (C) 2016 Cybozu Labs, Inc., all rights reserved.
|
6
|
+
*/
|
7
|
+
#include "msoc.h"
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <string.h>
|
10
|
+
|
11
|
+
void usage()
|
12
|
+
{
|
13
|
+
const char *s =
|
14
|
+
"how to use\n"
|
15
|
+
"minisample enc <inFile> <outFile> <pass>\n"
|
16
|
+
"minisample dec <inFile> <outFile> <pass>\n";
|
17
|
+
printf("%s", s);
|
18
|
+
exit(1);
|
19
|
+
}
|
20
|
+
|
21
|
+
int main(int argc, char **argv)
|
22
|
+
{
|
23
|
+
int err = 0;
|
24
|
+
const char *mode = NULL;
|
25
|
+
const char *inFile = NULL;
|
26
|
+
const char *outFile = NULL;
|
27
|
+
const char *pass = NULL;
|
28
|
+
|
29
|
+
argc--, argv++;
|
30
|
+
if (argc != 4) {
|
31
|
+
usage();
|
32
|
+
}
|
33
|
+
mode = argv[0];
|
34
|
+
inFile = argv[1];
|
35
|
+
outFile = argv[2];
|
36
|
+
pass = argv[3];
|
37
|
+
printf("enc in=%s, out=%s, pass=%s\n", inFile, outFile, pass);
|
38
|
+
|
39
|
+
if (strcmp(mode, "enc") == 0) {
|
40
|
+
err = MSOC_encryptA(outFile, inFile, pass, NULL);
|
41
|
+
} else if (strcmp(mode, "dec") == 0) {
|
42
|
+
err = MSOC_decryptA(outFile, inFile, pass, NULL);
|
43
|
+
} else {
|
44
|
+
printf("base mode=%s\n", mode);
|
45
|
+
usage();
|
46
|
+
}
|
47
|
+
if (err != MSOC_NOERR) {
|
48
|
+
printf("ERR %s\n", MSOC_getErrMessage(err));
|
49
|
+
return 1;
|
50
|
+
} else {
|
51
|
+
puts("ok");
|
52
|
+
}
|
53
|
+
return 0;
|
54
|
+
}
|