Skip to content

Commit 152e4b9

Browse files
authored
Add files via upload
1 parent f5feddc commit 152e4b9

File tree

3 files changed

+1818
-0
lines changed

3 files changed

+1818
-0
lines changed

Source.cpp

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
2+
//--------------------------------------------------
3+
// インクルード
4+
//--------------------------------------------------
5+
#define WIN32_LEAN_AND_MEAN
6+
#include <Windows.h>
7+
#include <stdio.h>
8+
#include "clHCA.h"
9+
10+
//--------------------------------------------------
11+
// 文字列を10進数とみなして数値に変換(簡易版)
12+
//--------------------------------------------------
13+
int atoi(const char *s) {
14+
int r = 0;
15+
bool sign = false; if (*s == '+') { s++; }
16+
else if (*s == '-') { sign = true; s++; }
17+
while (*s) {
18+
if (*s >= '0'&&*s <= '9')r = r * 10 + (*s - '0');
19+
else break;
20+
s++;
21+
}
22+
return sign ? -r : r;
23+
}
24+
float atof(const char *s) {
25+
int r1 = 0, r2 = 0, c = 1;
26+
bool sign = false; if (*s == '+') { s++; }
27+
else if (*s == '-') { sign = true; s++; }
28+
while (*s) {
29+
if (*s >= '0'&&*s <= '9')r1 = r1 * 10 + (*s - '0');
30+
else break;
31+
s++;
32+
}
33+
if (*s == '.') {
34+
s++;
35+
while (*s) {
36+
if (*s >= '0'&&*s <= '9') { r2 = r2 * 10 + (*s - '0'); c *= 10; }
37+
else break;
38+
s++;
39+
}
40+
}
41+
float r = r1 + ((c>0) ? r2 / (float)c : 0);
42+
return sign ? -r : r;
43+
}
44+
45+
//--------------------------------------------------
46+
// 文字列を16進数とみなして数値に変換
47+
//--------------------------------------------------
48+
int atoi16(const char *s) {
49+
int r = 0;
50+
bool sign = false; if (*s == '+') { s++; }
51+
else if (*s == '-') { sign = true; s++; }
52+
while (*s) {
53+
if (*s >= '0'&&*s <= '9')r = (r << 4) | (*s - '0');
54+
else if (*s >= 'A'&&*s <= 'F')r = (r << 4) | (*s - 'A' + 10);
55+
else if (*s >= 'a'&&*s <= 'f')r = (r << 4) | (*s - 'a' + 10);
56+
else break;
57+
s++;
58+
}
59+
return sign ? -r : r;
60+
}
61+
62+
//--------------------------------------------------
63+
// メイン
64+
//--------------------------------------------------
65+
int main(int argc, char *argv[]) {
66+
67+
// コマンドライン解析
68+
unsigned int count = 0;
69+
char *filenameOut = NULL;
70+
//bool decodeFlg=false;
71+
float volume = 1;
72+
unsigned int ciphKey1 = 0xE0748978;
73+
unsigned int ciphKey2 = 0xCF222F1F;
74+
int mode = 16;
75+
int loop = 0;
76+
bool info = false;
77+
bool decrypt = false;
78+
for (int i = 1; i<argc; i++) {
79+
if (argv[i][0] == '-' || argv[i][0] == '/') {
80+
switch (argv[i][1]) {
81+
case 'o':if (i + 1<argc) { filenameOut = argv[++i]; }break;
82+
//case 'd':decodeFlg=true;break;
83+
case 'v':volume = (float)atof(argv[++i]); break;
84+
case 'a':if (i + 1<argc) { ciphKey1 = atoi16(argv[++i]); }break;
85+
case 'b':if (i + 1<argc) { ciphKey2 = atoi16(argv[++i]); }break;
86+
case 'm':if (i + 1<argc) { mode = atoi(argv[++i]); }break;
87+
case 'l':if (i + 1<argc) { loop = atoi(argv[++i]); }break;
88+
case 'i':info = true; break;
89+
case 'c':decrypt = true; break;
90+
}
91+
}
92+
else if (*argv[i]) {
93+
argv[count++] = argv[i];
94+
}
95+
}
96+
97+
//if(decodeFlg){
98+
99+
// 入力チェック
100+
if (!count) {
101+
printf("Error: 入力ファイルを指定してください。\n");
102+
return -1;
103+
}
104+
105+
// デコード
106+
for (unsigned int i = 0; i<count; i++) {
107+
108+
// 2つ目以降のファイルは、出力ファイル名オプションが無効
109+
if (i)filenameOut = NULL;
110+
111+
// デフォルト出力ファイル名
112+
char path[MAX_PATH];
113+
if (!(filenameOut&&filenameOut[0])) {
114+
strcpy_s(path, sizeof(path), argv[i]);
115+
char *d1 = strrchr(path, '\\');
116+
char *d2 = strrchr(path, '/');
117+
char *e = strrchr(path, '.');
118+
if (e&&d1<e&&d2<e)*e = '\0';
119+
strcat_s(path, sizeof(path), ".wav");
120+
filenameOut = path;
121+
}
122+
123+
// ヘッダ情報のみ表示
124+
if (info) {
125+
printf("%s のヘッダ情報\n", argv[i]);
126+
clHCA hca(0, 0);
127+
hca.PrintInfo(argv[i]);
128+
printf("\n");
129+
}
130+
131+
// 復号化
132+
else if (decrypt) {
133+
printf("%s を復号化中...\n", argv[i]);
134+
clHCA hca(ciphKey1, ciphKey2);
135+
if (!hca.Decrypt(argv[i])) {
136+
printf("Error: 復号化に失敗しました。\n");
137+
}
138+
}
139+
140+
// デコード
141+
else {
142+
printf("%s をデコード中...\n", argv[i]);
143+
clHCA hca(ciphKey1, ciphKey2);
144+
if (!hca.DecodeToWavefile(argv[i], filenameOut, volume, mode, loop)) {
145+
printf("Error: デコードに失敗しました。\n");
146+
}
147+
}
148+
149+
}
150+
151+
//}
152+
153+
return 0;
154+
}

0 commit comments

Comments
 (0)