News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Lola814

Pages: [1]
1
Programming / Re: Help- command line hex edit tool
« on: September 04, 2019, 03:20:42 am »
Yes I quickly googled hex command line argument and found it, here's the code for any who may be interested. It handles any hex values I give it,  0xFF, FF or ff, and reads 10 as decimal 16.

#include <stdio.h>
#include <stdlib.h>

Code: [Select]
int main ( int argc, char *argv[] )  // program.exe file.name hexAddress newByte
{
    FILE *f = fopen( argv[1], "r+b" );
    long int hexAddress = ( long int ) strtol( argv[2], NULL, 16 );
    fseek( f, hexAddress, SEEK_SET );
    unsigned char newByte = ( unsigned char ) strtol( argv[3], NULL, 16 );
    fwrite( &newByte, sizeof( newByte ), 1, f );
    fclose( f );
}

Ve never heard of atoi before but Googling it, it seems to convert to decimal.

I write my own function to covert the string to hex, though I imagine there's probably already a C++ function for it.

Pages: [1]