ocran 1.3.18 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.txt +306 -292
  3. data/LICENSE.txt +22 -22
  4. data/README.md +549 -533
  5. data/exe/ocran +5 -5
  6. data/ext/extconf.rb +15 -0
  7. data/lib/ocran/build_constants.rb +16 -16
  8. data/lib/ocran/build_facade.rb +17 -17
  9. data/lib/ocran/build_helper.rb +110 -105
  10. data/lib/ocran/command_output.rb +22 -22
  11. data/lib/ocran/dir_builder.rb +162 -0
  12. data/lib/ocran/direction.rb +623 -458
  13. data/lib/ocran/file_path_set.rb +69 -69
  14. data/lib/ocran/gem_spec_queryable.rb +172 -172
  15. data/lib/ocran/host_config_helper.rb +57 -44
  16. data/lib/ocran/inno_setup_script_builder.rb +111 -111
  17. data/lib/ocran/launcher_batch_builder.rb +85 -85
  18. data/lib/ocran/library_detector.rb +61 -61
  19. data/lib/ocran/library_detector_posix.rb +55 -0
  20. data/lib/ocran/option.rb +323 -273
  21. data/lib/ocran/refine_pathname.rb +104 -104
  22. data/lib/ocran/runner.rb +115 -105
  23. data/lib/ocran/runtime_environment.rb +46 -46
  24. data/lib/ocran/stub_builder.rb +298 -264
  25. data/lib/ocran/version.rb +5 -5
  26. data/lib/ocran/windows_command_escaping.rb +15 -15
  27. data/lib/ocran.rb +7 -7
  28. data/share/ocran/lzma.exe +0 -0
  29. data/src/Makefile +75 -0
  30. data/src/edicon.c +161 -0
  31. data/src/error.c +100 -0
  32. data/src/error.h +66 -0
  33. data/src/inst_dir.c +334 -0
  34. data/src/inst_dir.h +157 -0
  35. data/src/lzma/7zTypes.h +529 -0
  36. data/src/lzma/Compiler.h +43 -0
  37. data/src/lzma/LzmaDec.c +1363 -0
  38. data/src/lzma/LzmaDec.h +236 -0
  39. data/src/lzma/Precomp.h +10 -0
  40. data/src/script_info.c +246 -0
  41. data/src/script_info.h +7 -0
  42. data/src/stub.c +133 -0
  43. data/src/stub.manifest +29 -0
  44. data/src/stub.rc +3 -0
  45. data/src/system_utils.c +1002 -0
  46. data/src/system_utils.h +209 -0
  47. data/src/system_utils_posix.c +500 -0
  48. data/src/unpack.c +574 -0
  49. data/src/unpack.h +85 -0
  50. data/src/vit-ruby.ico +0 -0
  51. metadata +52 -16
  52. data/share/ocran/edicon.exe +0 -0
  53. data/share/ocran/stub.exe +0 -0
  54. data/share/ocran/stubw.exe +0 -0
@@ -0,0 +1,236 @@
1
+ /* LzmaDec.h -- LZMA Decoder
2
+ 2020-03-19 : Igor Pavlov : Public domain */
3
+
4
+ #ifndef __LZMA_DEC_H
5
+ #define __LZMA_DEC_H
6
+
7
+ #include "7zTypes.h"
8
+
9
+ EXTERN_C_BEGIN
10
+
11
+ /* #define _LZMA_PROB32 */
12
+ /* _LZMA_PROB32 can increase the speed on some CPUs,
13
+ but memory usage for CLzmaDec::probs will be doubled in that case */
14
+
15
+ typedef
16
+ #ifdef _LZMA_PROB32
17
+ UInt32
18
+ #else
19
+ UInt16
20
+ #endif
21
+ CLzmaProb;
22
+
23
+
24
+ /* ---------- LZMA Properties ---------- */
25
+
26
+ #define LZMA_PROPS_SIZE 5
27
+
28
+ typedef struct _CLzmaProps
29
+ {
30
+ Byte lc;
31
+ Byte lp;
32
+ Byte pb;
33
+ Byte _pad_;
34
+ UInt32 dicSize;
35
+ } CLzmaProps;
36
+
37
+ /* LzmaProps_Decode - decodes properties
38
+ Returns:
39
+ SZ_OK
40
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
41
+ */
42
+
43
+ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
44
+
45
+
46
+ /* ---------- LZMA Decoder state ---------- */
47
+
48
+ /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
49
+ Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
50
+
51
+ #define LZMA_REQUIRED_INPUT_MAX 20
52
+
53
+ typedef struct
54
+ {
55
+ /* Don't change this structure. ASM code can use it. */
56
+ CLzmaProps prop;
57
+ CLzmaProb *probs;
58
+ CLzmaProb *probs_1664;
59
+ Byte *dic;
60
+ SizeT dicBufSize;
61
+ SizeT dicPos;
62
+ const Byte *buf;
63
+ UInt32 range;
64
+ UInt32 code;
65
+ UInt32 processedPos;
66
+ UInt32 checkDicSize;
67
+ UInt32 reps[4];
68
+ UInt32 state;
69
+ UInt32 remainLen;
70
+
71
+ UInt32 numProbs;
72
+ unsigned tempBufSize;
73
+ Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
74
+ } CLzmaDec;
75
+
76
+ #define LzmaDec_Construct(p) { (p)->dic = NULL; (p)->probs = NULL; }
77
+
78
+ void LzmaDec_Init(CLzmaDec *p);
79
+
80
+ /* There are two types of LZMA streams:
81
+ - Stream with end mark. That end mark adds about 6 bytes to compressed size.
82
+ - Stream without end mark. You must know exact uncompressed size to decompress such stream. */
83
+
84
+ typedef enum
85
+ {
86
+ LZMA_FINISH_ANY, /* finish at any point */
87
+ LZMA_FINISH_END /* block must be finished at the end */
88
+ } ELzmaFinishMode;
89
+
90
+ /* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
91
+
92
+ You must use LZMA_FINISH_END, when you know that current output buffer
93
+ covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
94
+
95
+ If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
96
+ and output value of destLen will be less than output buffer size limit.
97
+ You can check status result also.
98
+
99
+ You can use multiple checks to test data integrity after full decompression:
100
+ 1) Check Result and "status" variable.
101
+ 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
102
+ 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
103
+ You must use correct finish mode in that case. */
104
+
105
+ typedef enum
106
+ {
107
+ LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
108
+ LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
109
+ LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
110
+ LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
111
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
112
+ } ELzmaStatus;
113
+
114
+ /* ELzmaStatus is used only as output value for function call */
115
+
116
+
117
+ /* ---------- Interfaces ---------- */
118
+
119
+ /* There are 3 levels of interfaces:
120
+ 1) Dictionary Interface
121
+ 2) Buffer Interface
122
+ 3) One Call Interface
123
+ You can select any of these interfaces, but don't mix functions from different
124
+ groups for same object. */
125
+
126
+
127
+ /* There are two variants to allocate state for Dictionary Interface:
128
+ 1) LzmaDec_Allocate / LzmaDec_Free
129
+ 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
130
+ You can use variant 2, if you set dictionary buffer manually.
131
+ For Buffer Interface you must always use variant 1.
132
+
133
+ LzmaDec_Allocate* can return:
134
+ SZ_OK
135
+ SZ_ERROR_MEM - Memory allocation error
136
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
137
+ */
138
+
139
+ SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc);
140
+ void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc);
141
+
142
+ SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc);
143
+ void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc);
144
+
145
+ /* ---------- Dictionary Interface ---------- */
146
+
147
+ /* You can use it, if you want to eliminate the overhead for data copying from
148
+ dictionary to some other external buffer.
149
+ You must work with CLzmaDec variables directly in this interface.
150
+
151
+ STEPS:
152
+ LzmaDec_Construct()
153
+ LzmaDec_Allocate()
154
+ for (each new stream)
155
+ {
156
+ LzmaDec_Init()
157
+ while (it needs more decompression)
158
+ {
159
+ LzmaDec_DecodeToDic()
160
+ use data from CLzmaDec::dic and update CLzmaDec::dicPos
161
+ }
162
+ }
163
+ LzmaDec_Free()
164
+ */
165
+
166
+ /* LzmaDec_DecodeToDic
167
+
168
+ The decoding to internal dictionary buffer (CLzmaDec::dic).
169
+ You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
170
+
171
+ finishMode:
172
+ It has meaning only if the decoding reaches output limit (dicLimit).
173
+ LZMA_FINISH_ANY - Decode just dicLimit bytes.
174
+ LZMA_FINISH_END - Stream must be finished after dicLimit.
175
+
176
+ Returns:
177
+ SZ_OK
178
+ status:
179
+ LZMA_STATUS_FINISHED_WITH_MARK
180
+ LZMA_STATUS_NOT_FINISHED
181
+ LZMA_STATUS_NEEDS_MORE_INPUT
182
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
183
+ SZ_ERROR_DATA - Data error
184
+ SZ_ERROR_FAIL - Some unexpected error: internal error of code, memory corruption or hardware failure
185
+ */
186
+
187
+ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
188
+ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
189
+
190
+
191
+ /* ---------- Buffer Interface ---------- */
192
+
193
+ /* It's zlib-like interface.
194
+ See LzmaDec_DecodeToDic description for information about STEPS and return results,
195
+ but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
196
+ to work with CLzmaDec variables manually.
197
+
198
+ finishMode:
199
+ It has meaning only if the decoding reaches output limit (*destLen).
200
+ LZMA_FINISH_ANY - Decode just destLen bytes.
201
+ LZMA_FINISH_END - Stream must be finished after (*destLen).
202
+ */
203
+
204
+ SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
205
+ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
206
+
207
+
208
+ /* ---------- One Call Interface ---------- */
209
+
210
+ /* LzmaDecode
211
+
212
+ finishMode:
213
+ It has meaning only if the decoding reaches output limit (*destLen).
214
+ LZMA_FINISH_ANY - Decode just destLen bytes.
215
+ LZMA_FINISH_END - Stream must be finished after (*destLen).
216
+
217
+ Returns:
218
+ SZ_OK
219
+ status:
220
+ LZMA_STATUS_FINISHED_WITH_MARK
221
+ LZMA_STATUS_NOT_FINISHED
222
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
223
+ SZ_ERROR_DATA - Data error
224
+ SZ_ERROR_MEM - Memory allocation error
225
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
226
+ SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
227
+ SZ_ERROR_FAIL - Some unexpected error: internal error of code, memory corruption or hardware failure
228
+ */
229
+
230
+ SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
231
+ const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
232
+ ELzmaStatus *status, ISzAllocPtr alloc);
233
+
234
+ EXTERN_C_END
235
+
236
+ #endif
@@ -0,0 +1,10 @@
1
+ /* Precomp.h -- StdAfx
2
+ 2013-11-12 : Igor Pavlov : Public domain */
3
+
4
+ #ifndef __7Z_PRECOMP_H
5
+ #define __7Z_PRECOMP_H
6
+
7
+ #include "Compiler.h"
8
+ /* #include "7zTypes.h" */
9
+
10
+ #endif
data/src/script_info.c ADDED
@@ -0,0 +1,246 @@
1
+ #include <stdbool.h>
2
+ #include <stddef.h>
3
+ #include <stdlib.h>
4
+ #include <string.h>
5
+ #include "error.h"
6
+ #include "system_utils.h"
7
+ #include "inst_dir.h"
8
+ #include "script_info.h"
9
+
10
+ /**
11
+ * Splits the NULL-delimited strings in buffer and stores pointers in array.
12
+ *
13
+ * @param buffer Pointer to data containing NULL-delimited strings.
14
+ * The buffer must be terminated by a double NULL character.
15
+ * @param array Array to receive string pointers. If NULL, only counting
16
+ * is performed.
17
+ * @return Number of strings in buffer (excluding the NULL
18
+ * terminator).
19
+ */
20
+ static size_t split_strings_to_array(const char *buffer, char **array)
21
+ {
22
+ size_t count = 0;
23
+
24
+ for (const char *p = buffer; *p; p++) {
25
+ if (array) {
26
+ array[count] = (char *)p;
27
+ }
28
+ count++;
29
+
30
+ while (*p) p++;
31
+ }
32
+
33
+ if (array) {
34
+ array[count] = NULL;
35
+ }
36
+ return count;
37
+ }
38
+
39
+ static char **info_to_argv(const char *info, size_t info_size)
40
+ {
41
+ size_t argc = split_strings_to_array(info, NULL);
42
+ size_t argv_size = (argc + 1) * sizeof(char *);
43
+ void *base = malloc(argv_size + info_size);
44
+ if (!base) {
45
+ APP_ERROR("Memory allocation failed for argv");
46
+ return NULL;
47
+ }
48
+ char **argv = (char **)base;
49
+ char *args = (char *) base + argv_size;
50
+ memcpy(args, info, info_size);
51
+ split_strings_to_array(args, argv);
52
+ return argv;
53
+ }
54
+
55
+ static char **ScriptInfo = NULL;
56
+
57
+ static inline bool IsScriptInfoSet(void) {
58
+ return ScriptInfo != NULL;
59
+ }
60
+
61
+ char **GetScriptInfo(void)
62
+ {
63
+ if (!IsScriptInfoSet()) {
64
+ return NULL;
65
+ }
66
+
67
+ size_t stored = 0;
68
+ for (char **p = ScriptInfo; *p; p++) stored++;
69
+ if (stored == 0) {
70
+ APP_ERROR("ScriptInfo is empty");
71
+ return NULL;
72
+ }
73
+ char *last = ScriptInfo[stored - 1];
74
+
75
+ char *end = last + strlen(last) + 1 + 1; // double-NULL terminated
76
+ size_t infov_size = end - (char *)ScriptInfo;
77
+ char **argv = malloc(infov_size);
78
+ if (!argv) {
79
+ APP_ERROR("Memory allocation failed for GetScriptInfo");
80
+ return NULL;
81
+ }
82
+ memcpy(argv, ScriptInfo, infov_size);
83
+ return argv;
84
+ }
85
+
86
+ bool SetScriptInfo(const char *info, size_t info_size)
87
+ {
88
+ if (IsScriptInfoSet()) {
89
+ APP_ERROR("Script info is already set");
90
+ return false;
91
+ }
92
+
93
+ if (!info) {
94
+ APP_ERROR("info is NULL");
95
+ return false;
96
+ }
97
+
98
+ if (info_size < 2
99
+ || info[info_size - 1] != '\0'
100
+ || info[info_size - 2] != '\0') {
101
+ APP_ERROR("Script info not double-NULL terminated");
102
+ return false;
103
+ }
104
+
105
+ const char *argv0 = info;
106
+ if (*argv0 == '\0') {
107
+ APP_ERROR("Application name is empty");
108
+ return false;
109
+ }
110
+
111
+ if (!IsCleanRelativePath(argv0)) {
112
+ APP_ERROR("Application name contains prohibited relative path elements");
113
+ return false;
114
+ }
115
+
116
+ const char *argv1 = argv0 + strlen(info) + 1;
117
+ if (*argv1 == '\0') {
118
+ APP_ERROR("Script name is empty");
119
+ return false;
120
+ }
121
+
122
+ if (!IsCleanRelativePath(argv1)) {
123
+ APP_ERROR("Script name contains prohibited relative path elements");
124
+ return false;
125
+ }
126
+
127
+ char **argv = info_to_argv(info, info_size);
128
+ if (!argv) {
129
+ APP_ERROR("Failed to convert script info to argv");
130
+ return false;
131
+ }
132
+
133
+ ScriptInfo = argv;
134
+ return true;
135
+ }
136
+
137
+ void FreeScriptInfo(void)
138
+ {
139
+ if (ScriptInfo) {
140
+ free(ScriptInfo);
141
+ ScriptInfo = NULL;
142
+ }
143
+ }
144
+
145
+ static char **shallow_merge_argv(char *argv1[], char *argv2[])
146
+ {
147
+ size_t c1 = 0;
148
+ for (char **p = argv1; *p; p++) c1++;
149
+
150
+ size_t c2 = 0;
151
+ for (char **p = argv2; *p; p++) c2++;
152
+
153
+ size_t outc = c1 + c2;
154
+ char **outv = calloc(outc + 1, sizeof(*outv));
155
+ if (!outv) {
156
+ APP_ERROR("Memory allocation failed for merged argv");
157
+ return NULL;
158
+ }
159
+
160
+ memcpy(outv, argv1, sizeof(*outv) * c1);
161
+ memcpy(outv + c1, argv2, sizeof(*outv) * c2);
162
+ outv[outc] = NULL;
163
+ return outv;
164
+ }
165
+
166
+ bool RunScript(char *argv[], bool is_chdir_to_script_dir, int *exit_code)
167
+ {
168
+ if (!IsScriptInfoSet()) {
169
+ APP_ERROR("Script info is not initialized");
170
+ return false;
171
+ }
172
+
173
+ if (!argv || !*argv) {
174
+ APP_ERROR("argv is NULL or empty");
175
+ return false;
176
+ }
177
+
178
+ bool result = false;
179
+ char **script_info = GetScriptInfo();
180
+ char *app_name = NULL;
181
+ char *script_name = NULL;
182
+ char **merged_argv = NULL;
183
+ char *script_dir = NULL;
184
+
185
+ app_name = ExpandInstDirPath(script_info[0]);
186
+ if (!app_name) {
187
+ APP_ERROR("Failed to expand application name to installation directory");
188
+ goto cleanup;
189
+ }
190
+
191
+ script_name = ExpandInstDirPath(script_info[1]);
192
+ if (!script_name) {
193
+ APP_ERROR("Failed to expand script name to installation directory");
194
+ goto cleanup;
195
+ }
196
+
197
+ script_info[1] = script_name;
198
+
199
+ merged_argv = shallow_merge_argv(script_info, argv + 1);
200
+ if (!merged_argv) {
201
+ APP_ERROR("Failed to merge script arguments with extra arguments");
202
+ goto cleanup;
203
+ }
204
+
205
+ if (is_chdir_to_script_dir) {
206
+ script_dir = GetParentPath(script_name);
207
+ if (!script_dir) {
208
+ APP_ERROR("Failed to build path for script directory");
209
+ goto cleanup;
210
+ }
211
+
212
+ DEBUG(
213
+ "Changing working directory to script directory '%s'",
214
+ script_dir
215
+ );
216
+
217
+ char *ruby_optv[5] = { script_info[0], "-C", script_dir, "--", NULL };
218
+ char **new_argv = shallow_merge_argv(ruby_optv, merged_argv + 1);
219
+ if (!new_argv) {
220
+ APP_ERROR("Failed to merge script arguments with extra arguments");
221
+ goto cleanup;
222
+ }
223
+ free(merged_argv);
224
+ merged_argv = new_argv;
225
+ }
226
+
227
+ result = CreateAndWaitForProcess(app_name, merged_argv, exit_code);
228
+
229
+ cleanup:
230
+ if (script_info) {
231
+ free(script_info);
232
+ }
233
+ if (app_name) {
234
+ free(app_name);
235
+ }
236
+ if (script_name) {
237
+ free(script_name);
238
+ }
239
+ if (merged_argv) {
240
+ free(merged_argv);
241
+ }
242
+ if (script_dir) {
243
+ free(script_dir);
244
+ }
245
+ return result;
246
+ }
data/src/script_info.h ADDED
@@ -0,0 +1,7 @@
1
+ #include <stdbool.h>
2
+ #include <stddef.h>
3
+
4
+ char **GetScriptInfo(void);
5
+ bool SetScriptInfo(const char *info, size_t info_size);
6
+ void FreeScriptInfo(void);
7
+ bool RunScript(char *argv[], bool is_chdir_to_script_dir, int *exit_code);
data/src/stub.c ADDED
@@ -0,0 +1,133 @@
1
+ /*
2
+ Single Executable Bundle Stub
3
+ This stub reads itself for embedded instructions to create directory
4
+ and files in a temporary directory, launching a program.
5
+ */
6
+
7
+ #include <string.h>
8
+ #include <stdio.h>
9
+ #include <stdbool.h>
10
+ #include <stdlib.h>
11
+ #include "error.h"
12
+ #include "system_utils.h"
13
+ #include "inst_dir.h"
14
+ #include "script_info.h"
15
+ #include "unpack.h"
16
+
17
+ int main(int argc, char *argv[])
18
+ {
19
+ int status = EXIT_CODE_FAILURE;
20
+ UnpackContext *unpack_ctx = NULL;
21
+ OperationModes op_modes = 0;
22
+ const char *extract_dir = NULL;
23
+ char *image_path = NULL;
24
+
25
+ /*
26
+ Initialize signal and control handling so the parent process remains
27
+ active during startup and cleanup. This setup prevents interruption
28
+ of critical tasks (such as file extraction) by control events.
29
+ Child processes (e.g., Ruby) handle their own signals independently,
30
+ ensuring the parent can finalize cleanup without premature termination.
31
+ */
32
+ if (!InitializeSignalHandling()) {
33
+ FATAL("Failed to initialize system controls");
34
+ goto cleanup;
35
+ }
36
+
37
+ /* Find name of image */
38
+ image_path = GetImagePath();
39
+ if (!image_path) {
40
+ FATAL("Failed to get executable name");
41
+ goto cleanup;
42
+ }
43
+
44
+ /* Open and map the image (executable) into memory */
45
+ unpack_ctx = OpenPackFile(image_path);
46
+ if (!unpack_ctx) {
47
+ FATAL("Failed to map the executable file");
48
+ goto cleanup;
49
+ }
50
+
51
+ /* Read header of packed data */
52
+ op_modes = GetOperationModes(unpack_ctx);
53
+
54
+ /* Enable debug mode when the flag is set or OCRAN_DEBUG env var is set */
55
+ if (IsDebugMode(op_modes) || getenv("OCRAN_DEBUG")) {
56
+ EnableDebugMode();
57
+ DEBUG("Ocran stub running in debug mode");
58
+ }
59
+
60
+ /* Create extraction directory */
61
+ extract_dir = CreateInstDir(IsExtractToExeDir(op_modes));
62
+ if (!extract_dir) {
63
+ FATAL("Failed to create extraction directory");
64
+ goto cleanup;
65
+ }
66
+
67
+ DEBUG("Created extraction directory: %s", extract_dir);
68
+
69
+ /* Unpacking process */
70
+ if (!ProcessImage(unpack_ctx)) {
71
+ FATAL("Failed to unpack image due to invalid or corrupted data");
72
+ goto cleanup;
73
+ }
74
+
75
+ // Memory map no longer needed after unpacking; free its resources.
76
+ ClosePackFile(unpack_ctx);
77
+
78
+ // Prevent accidental use of the freed map.
79
+ unpack_ctx = NULL;
80
+
81
+ /* Launching the script, provided there are no errors in file extraction from the image */
82
+ DEBUG("*** Starting application script in %s", extract_dir);
83
+
84
+ DEBUG("Set the 'OCRAN_EXECUTABLE' environment variable to %s", image_path);
85
+ if (!SetEnvVar("OCRAN_EXECUTABLE", image_path)) {
86
+ FATAL("The script cannot be launched due to a configuration error");
87
+ goto cleanup;
88
+ }
89
+
90
+ /*
91
+ RunScript uses the current value of status as its initial value
92
+ and then overwrites it with the external script’s return code.
93
+ */
94
+ DEBUG("Run application script");
95
+ if (!RunScript(argv, IsChdirBeforeScript(op_modes), &status)) {
96
+ FATAL("Failed to run script");
97
+ goto cleanup;
98
+ }
99
+ /*
100
+ If the script executes successfully, its return code is stored in status.
101
+ */
102
+
103
+ cleanup:
104
+ /*
105
+ Suppress GUI error dialogs during cleanup to avoid blocking the user.
106
+ Cleanup failures are non-critical and logged as DEBUG only.
107
+ */
108
+
109
+ if (image_path) {
110
+ free(image_path);
111
+ }
112
+
113
+ if (unpack_ctx) {
114
+ ClosePackFile(unpack_ctx);
115
+ unpack_ctx = NULL;
116
+ }
117
+
118
+ FreeScriptInfo();
119
+
120
+ /*
121
+ If AUTO_CLEAN_INST_DIR is set, delete the extraction directory.
122
+ */
123
+ if (IsAutoCleanInstDir(op_modes)) {
124
+ DEBUG("Deleting extraction directory: %s", extract_dir);
125
+ if (!DeleteInstDir()) {
126
+ DEBUG("Failed to delete extraction directory");
127
+ }
128
+ }
129
+
130
+ FreeInstDir();
131
+ extract_dir = NULL;
132
+ return status;
133
+ }
data/src/stub.manifest ADDED
@@ -0,0 +1,29 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
3
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
4
+ <security>
5
+ <requestedPrivileges>
6
+ <requestedExecutionLevel level="asInvoker"/>
7
+ </requestedPrivileges>
8
+ </security>
9
+ </trustInfo>
10
+ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
11
+ <application>
12
+ <!--The ID below indicates application support for Windows Vista -->
13
+ <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
14
+ <!--The ID below indicates application support for Windows 7 -->
15
+ <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
16
+ <!--The ID below indicates application support for Windows 8 -->
17
+ <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
18
+ <!--The ID below indicates application support for Windows 8.1 -->
19
+ <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
20
+ <!--The ID below indicates application support for Windows 10 -->
21
+ <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
22
+ </application>
23
+ </compatibility>
24
+ <application>
25
+ <windowsSettings>
26
+ <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
27
+ </windowsSettings>
28
+ </application>
29
+ </assembly>
data/src/stub.rc ADDED
@@ -0,0 +1,3 @@
1
+ #include <winresrc.h>
2
+ CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "stub.manifest"
3
+ 101 ICON vit-ruby.ico