Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sandec fix #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sandec/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
all: sandec

sandec:
winegcc -mconsole -mno-cygwin -o sandec sandec.c
winegcc -m32 -mconsole -mno-cygwin -o sandec sandec.c

clean:
-rm -f sandec sandec.exe.so *~ \#*\#
Expand Down
2 changes: 2 additions & 0 deletions sandec/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
make
wine ./sandec.exe.so [filename]
3 changes: 3 additions & 0 deletions sandec/convert_all_raw_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

ls *.raw | xargs -i wine ./sandec.exe.so {}
23 changes: 23 additions & 0 deletions sandec/get_dll.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using set -euo pipefail makes bash development a little easier and more robust.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's nice, didn't know about that either

if ! [ -x "$(command -v cabextract)" ]; then
echo "cabextract not found."
exit 1;
fi

if ! [ -x "$(command -v unshield)" ]; then
echo "unshield not found."
exit 1;
fi

mkdir work_tmp;
cd work_tmp;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a little bash trick for you.

TMP=$(mktemp -d)
trap "rm -rf $TMP" EXIT

You'll have a temporary directory that won't collide and will automatically get cleaned up.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool :)

wget http://www.olympusamerica.com/files/oima_cckb/DigitalWavePlayerUpdate214.zip;
unzip DigitalWavePlayerUpdate214.zip;
cd Vista+AMD;
cabextract DWPUP5EN.exe;
cd Disk1;
unshield x data1.cab
cp "_v___O_____DLL_(____________)/san_dec.dll" ../../../;
cd ../../../;
rm -rf work_tmp;
Binary file added sandec/san_dec.dll
Binary file not shown.
15 changes: 10 additions & 5 deletions sandec/sandec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably related to a bugfix in the compiler. Some of the calls in here, like write, are defined in unistd.h.


typedef int (__cdecl *SAN_DEC)(uint8_t *in, uint8_t *out, int mode, int bit_size);
typedef int (__cdecl *SAN_DEC_PULCOD2_INIT)(int a, int b);
Expand Down Expand Up @@ -80,7 +81,7 @@ Ussage: sandec [filename].raw\n");

HINSTANCE hLibrary = LoadLibrary("san_dec.dll");
if (hLibrary == NULL)
{
{
jchillerup marked this conversation as resolved.
Show resolved Hide resolved
printf("Unable to load san_dec.dll!\n");
return -1;
}
Expand Down Expand Up @@ -112,10 +113,10 @@ Ussage: sandec [filename].raw\n");
int bit_size = 16;
int mode = 1;

fd = open(argv[1],O_RDONLY|O_BINARY);
fd = open(argv[1], O_RDONLY|O_BINARY);
if(fd<0)
{
printf("Unable to open '%s'!\n",argv[1]);
printf("Unable to open '%s' for reading!\n",argv[1]);
return -1;
}

Expand Down Expand Up @@ -168,12 +169,16 @@ Ussage: sandec [filename].raw\n");
filename[str_len-4] = '.';

fd2 = open(filename, O_CREAT|O_WRONLY|O_BINARY|O_EXCL);

if(fd2<0)
{
printf("Unable to open '%s'!\n", filename);
char cwd[512];
getcwd(cwd, sizeof(cwd));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the return value of getcwd. If it returns NULL then the path exceeded sizeof(cwd) with ERANGE.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.


printf("Unable to open '%s' for writing! Return code %d, cwd %s \n", filename, fd2, cwd);
return -1;
}

ret = wave_header(out, 0, freq);

ret = write(fd2, out, ret);
Expand Down