(PS3) ps3py/crypt.c - style nits

This commit is contained in:
twinaphex 2015-10-27 02:02:01 +01:00
parent 0447c1b442
commit a1749c3d1b
1 changed files with 82 additions and 74 deletions

View File

@ -2,7 +2,8 @@
static PyObject *sha1_callback = NULL;
static void manipulate(uint8_t *key) {
static void manipulate(uint8_t *key)
{
uint64_t temp = key[0x38] << 56|
key[0x39] << 48|
key[0x3a] << 40|
@ -22,7 +23,8 @@ static void manipulate(uint8_t *key) {
key[0x3f] = (temp >> 0) & 0xff;
}
static PyObject* pkg_crypt(PyObject *self, PyObject *args) {
static PyObject* pkg_crypt(PyObject *self, PyObject *args)
{
uint8_t *key, *input, *ret;
int key_length, input_length, length;
int remaining, i, offset=0;
@ -35,22 +37,24 @@ static PyObject* pkg_crypt(PyObject *self, PyObject *args) {
ret = malloc(length);
remaining = length;
while (remaining > 0) {
while (remaining > 0)
{
int outHash_length;
uint8_t *outHash;
int bytes_to_dump = remaining;
if (bytes_to_dump > 0x10)
bytes_to_dump = 0x10;
// outhash = SHA1(listToString(key)[0:0x40])
uint8_t *outHash;
{
arglist = Py_BuildValue("(s#)", key, 0x40);
result = PyObject_CallObject(sha1_callback, arglist);
Py_DECREF(arglist);
if (!result) return NULL;
int outHash_length;
if (!PyArg_Parse(result, "s#", &outHash, &outHash_length)) return NULL;
}
for(i = 0; i < bytes_to_dump; i++) {
if (!result)
return NULL;
if (!PyArg_Parse(result, "s#", &outHash, &outHash_length))
return NULL;
for(i = 0; i < bytes_to_dump; i++)
{
ret[offset] = outHash[i] ^ input[offset];
offset++;
}
@ -59,18 +63,21 @@ static PyObject* pkg_crypt(PyObject *self, PyObject *args) {
remaining -= bytes_to_dump;
}
// Return the encrypted data
/* Return the encrypted data */
PyObject *py_ret = Py_BuildValue("s#", ret, length);
free(ret);
return py_ret;
}
static PyObject *register_sha1_callback(PyObject *self, PyObject *args) {
static PyObject *register_sha1_callback(PyObject *self, PyObject *args)
{
PyObject *result = NULL;
PyObject *temp;
if (PyArg_ParseTuple(args, "O:set_callback", &temp)) {
if (!PyCallable_Check(temp)) {
if (PyArg_ParseTuple(args, "O:set_callback", &temp))
{
if (!PyCallable_Check(temp))
{
PyErr_SetString(PyExc_TypeError, "parameter must be callable");
return NULL;
}
@ -90,7 +97,8 @@ static PyMethodDef cryptMethods[] = {
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC initpkgcrypt(void) {
PyMODINIT_FUNC initpkgcrypt(void)
{
(void) Py_InitModule("pkgcrypt", cryptMethods);
}