C development and patching for P01/P59
Re: C development and patching for P01/P59
Have a look see here: Difference between C and C++
Intelligence is in the details!
It is easier not to learn bad habits, then it is to break them!
If I was here to win a popularity contest, their would be no point, so I wouldn't be here!
It is easier not to learn bad habits, then it is to break them!
If I was here to win a popularity contest, their would be no point, so I wouldn't be here!
Re: C development and patching for P01/P59
I agree with sticking to plain C. It's pretty easy to see how each line of C maps to and from the corresponding asm instructions, and that will make it easier to jump in and out of the existing code.
Please don't PM me with technical questions - start a thread instead, and send me a link to it. That way I can answer in public, and help other people who have the same question. Thanks!
- antus
- Site Admin
- Posts: 8252
- Joined: Sat Feb 28, 2009 8:34 pm
- cars: TX Gemini 2L Twincam
TX Gemini SR20 18psi
Datsun 1200 Ute
Subaru Blitzen '06 EZ30 4th gen, 3.0R Spec B - Contact:
Re: C development and patching for P01/P59
yep the ++ adds the concept of objects which makes the code very modular. thats fine for some applications but not so suitable for creating patches that are injected and run inline modifying variables out side of the object. see the allpro firmware for and example of c++ done right in a small embedded system, and maybe you can read between the lines and see how its not a great fit for inline os patches. https://github.com/antuspcm/allpro
Have you read the FAQ? For lots of information and links to significant threads see here: http://pcmhacking.net/forums/viewtopic.php?f=7&t=1396
Re: C development and patching for P01/P59
Ok, guess I'll be buying another book lol
Any recommendations?
Any recommendations?
LS1 Boost OS V3 Here. For feature suggestions post in here Development Thread. Support future development ->Patreon.
Re: C development and patching for P01/P59
Ok, so trying to do my first basic file read of a bin to check the OS and I'm not getting the correct value.
The output I'm getting is 1393737728 when I expect 12587603. If anyone could spot the obvious mistake that I'm making I would appreciate it.
I'm mainly just doing this exercise to try and learn more as I go. I'm definitely open to ideas on how to go about how to structure the code as I am not experienced with programming.
The output I'm getting is 1393737728 when I expect 12587603. If anyone could spot the obvious mistake that I'm making I would appreciate it.
Code: Select all
#include <stdio.h>
int main()
{
FILE* fptr;
int operatingsystem;
/* Open bin file */
fopen_s(&fptr, "C:\\Users\\bubba2533\\Projects\\LS1 Boost OS V3\\12587603.bin", "rb");
if (fptr == NULL) {
return 3;
}
/* Seek to OS and read value*/
fseek(fptr, 0x504, SEEK_SET);
size_t elements_read = fread_s(&operatingsystem, sizeof(operatingsystem), sizeof(operatingsystem), 1, fptr);
if (elements_read == 0) {
return 4;
}
printf("Operating system of file: %u\n", operatingsystem);
fclose(fptr);
return 0;
}
LS1 Boost OS V3 Here. For feature suggestions post in here Development Thread. Support future development ->Patreon.
Re: C development and patching for P01/P59
The result you get is byte swapped for some reason. Convert the result in hex and you will see it for yourself.
Re: C development and patching for P01/P59
Interesting. Didn’t expect that. Any idea why that is happening?
LS1 Boost OS V3 Here. For feature suggestions post in here Development Thread. Support future development ->Patreon.
Re: C development and patching for P01/P59
The PCM is Big Endian, your PC is Little Endian.
The OS id is 4 bytes, use an unsigned long, int is to small.
Use a char buffer with fread().
Bit shift results into unsigned long.
TIP: If you use C++ style comments (//), then if you need to comment out a large block you can use C style comments (/**/) without interference of nested C style comments.
-Enjoy
The OS id is 4 bytes, use an unsigned long, int is to small.
Use a char buffer with fread().
Bit shift results into unsigned long.
Code: Select all
#include <stdio.h>
int main()
{
FILE* fptr;
unsigned long operatingsystem; // OsID is 4 bytes.
char buffer[4]; // char buffer, makes handling BE simple.
// Open bin file
fopen_s(&fptr, "12587603.bin", "rb");
if (fptr == NULL) {
return 3;
}
// Seek to OS and read value
fseek(fptr, 0x504, SEEK_SET);
size_t elements_read = fread_s(&buffer, sizeof(buffer), sizeof(buffer), 1, fptr); //Changed to use buffer
if (elements_read == 0) {
return 4;
}
// Bit shift everything into unsigned long.
operatingsystem = ((buffer[0] & 0xFF) << 24 | (buffer[1] & 0xFF) << 16 | (buffer[2] & 0xFF) << 8 | buffer[3] & 0xFF);
// print raw values
printf("Operating system of file: %x %x %x %x\n", buffer[0] & 0xFF, buffer[1] & 0xFF, buffer[2] & 0xFF, buffer[3] & 0xFF);
// print value
printf("Operating system of file: %u\n", operatingsystem);
fclose(fptr);
return 0;
}
-Enjoy
Intelligence is in the details!
It is easier not to learn bad habits, then it is to break them!
If I was here to win a popularity contest, their would be no point, so I wouldn't be here!
It is easier not to learn bad habits, then it is to break them!
If I was here to win a popularity contest, their would be no point, so I wouldn't be here!
Re: C development and patching for P01/P59
Awesome and thanks for the tip!
LS1 Boost OS V3 Here. For feature suggestions post in here Development Thread. Support future development ->Patreon.
Re: C development and patching for P01/P59
You working in an IDE or CLI ??
Intelligence is in the details!
It is easier not to learn bad habits, then it is to break them!
If I was here to win a popularity contest, their would be no point, so I wouldn't be here!
It is easier not to learn bad habits, then it is to break them!
If I was here to win a popularity contest, their would be no point, so I wouldn't be here!