Help! Read Offsets from a hex file in textboxes

This is a discussion on Help! Read Offsets from a hex file in textboxes within the C++ Programming forums, part of the General Programming Boards category; I need a C++ borland 6 code of read offsets (0x1C, 0x20, 0x24, 0x30, 0x3C, 0x40) of a file in ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    8

    Help! Read Offsets from a hex file in textboxes

    I need a C++ borland 6 code of read offsets (0x1C, 0x20, 0x24, 0x30, 0x3C, 0x40) of a file in a textboxes in values Float and after click in a button and save the new values.
    can someone help me? or send a proyect finaly?
    i upload a link for download a file as an example.
    In the .rar contain a ".bin" file waht you can open with any hex editor (: I use AXE 3.
    LINK FOR DOWNLOAD:

    example zip

    Sorry for my english!
    thank you very much who can help me

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    Can you just post your source code on the forum?
    See the intro thread on how to post code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    8
    Quote Originally Posted by Salem View Post
    Can you just post your source code on the forum?
    See the intro thread on how to post code.
    I not have a source code I need a source code for this....

  4. #4
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Quote Originally Posted by ignataur View Post
    can someone help me?
    Yes.
    Quote Originally Posted by ignataur View Post
    or send a proyect finaly?
    No.


    Btw, it's the first time I see someone here giving binaries to get source code for, LOL.
    I never put signature, but I decided to make an exception.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    So start with fopen(), fseek() and fread() to access the file at specific offsets.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    8
    good finish writing the code to read offsets and it worked perfectly ..
    But when a code built to store the respective offsets edited I get the following error. (see photo)

    ImageShack® - Online Photo and Video Hosting

    please any help me

    the code is this:

    Code:
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
    int iFileHandle;
      int iFileLength;
      int iBytesRead;
      PAnsiChar Buffer;
       if (SaveDialog1->Execute())
    
    
      try
      {
    iFileHandle = FileOpen(SaveDialog1->FileName, fmOpenRead);
    
       if (iFileHandle > 0) {
         iFileLength = FileSeek(iFileHandle, 0, 2);
         FileSeek(iFileHandle,0,0);
         Buffer = new AnsiChar[iFileLength+1];
         iBytesRead = FileRead(iFileHandle, Buffer, iFileLength);
         FileClose(iFileHandle);
    
         for (int i = 0; i < iBytesRead; i++)
         {
    
    float v1, v2, v3;
    
    Edit1->Text = (String)v1;
    Edit2->Text = (String)v2;
    Edit3->Text = (String)v3;
    
    v1 = StrToFloat( Edit1->Text );
    v2 = StrToFloat( Edit2->Text );
    v3 = StrToFloat( Edit3->Text );
      }
    }
    }
       }
    
    //---------------------------------------------------------------------------

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    It should be
    Code:
    try {
      // some stuff
    } catch {
    }
    Should have been obvious enough, if you knew enough to type in 'try' to begin with.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Mar 2011
    Posts
    8
    Quote Originally Posted by Salem View Post
    It should be
    Code:
    try {
      // some stuff
    } catch {
    }
    not work :/

  9. #9
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Post error/code?
    Code:
    try
    {
    }
    catch (...)
    {
    }
    Exceptions - C++ Documentation
    I never put signature, but I decided to make an exception.

  10. #10
    Registered User
    Join Date
    Mar 2011
    Posts
    8
    I can't resolve the problem
    I upload the source code C++ for something test, and if can resolve the problem in Button2, to save the values after writing.
    appreciate it
    DOWNLOAD:
    MEGAUPLOAD - The leading online storage and file delivery service

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    > megawasteoftime.com says
    > The file you are trying to access is temporarily unavailable. Please try again later.
    Heh - past your code inline in future.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    Registered User
    Join Date
    Mar 2011
    Posts
    8
    Code:
    //---------------------------------------------------------------------------
    
    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <ExtCtrls.hpp>
    #include <Dialogs.hpp>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published:	// IDE-managed Components
            TTimer *Timer1;
            TEdit *Edit1;
            TEdit *Edit2;
            TEdit *Edit3;
            TLabel *Label1;
            TLabel *Label2;
            TLabel *Label3;
            TLabel *Label4;
            TButton *Button1;
            TButton *Button2;
            TEdit *Edit4;
            TEdit *Edit5;
            TEdit *Edit6;
            TOpenDialog *OpenDialog1;
            TSaveDialog *SaveDialog1;
            TLabel *Label5;
            TLabel *Label6;
            TLabel *Label7;
            TLabel *Label8;
            TLabel *Label9;
            TEdit *Edit7;
            TLabel *Label10;
            TLabel *Label11;
            TEdit *Edit8;
            TLabel *Label12;
            TEdit *Edit9;
            void __fastcall Timer1Timer(TObject *Sender);
            void __fastcall Button1Click(TObject *Sender);
            void __fastcall Button2Click(TObject *Sender);
    private:	// User declarations
    public:		// User declarations
            __fastcall TForm1(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif
    Code:
    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #include <tlhelp32.h>
    
    #pragma hdrstop
    
    #include "Unit1.h"
    
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    BYTE *Bufor;
    //---------------------------------------------------------------------------
    DWORD   GetSniperEliteProcessId(void)
    {
    HANDLE hProcessSnap;
    PROCESSENTRY32 pe32;
    AnsiString ProcessName;
    DWORD result = -1;
        hProcessSnap= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
        pe32.dwSize =sizeof(PROCESSENTRY32);
        Process32First(hProcessSnap,&pe32);
        do
        {
           ProcessName = pe32.szExeFile;
           if (!strcmp (ProcessName.LowerCase().c_str() ,"sniperelite.exe"))
           {
    			result = pe32.th32ProcessID;
           }
        } while (Process32Next(hProcessSnap,&pe32));
        CloseHandle(hProcessSnap);
        return result;
    }
    //---------------------------------------------------------------------------
    
    int  ReadFromSE(int Adr,char* Buffer,unsigned long Len)
    {
    HANDLE hwnd;
    DWORD SeId;
    int result=false;
        SeId = GetSniperEliteProcessId();
        // SeId zawiera id  procesu SniperElite.exe ,jesli -1 to nie uruchomiono procesu
        if ((int)SeId != -1)
        {
    		hwnd =OpenProcess(PROCESS_VM_READ,false,SeId);
    		if (hwnd ==NULL ) return 0;
    		result = ReadProcessMemory(hwnd, (LPVOID)Adr, Buffer, Len, &Len);
    		CloseHandle(hwnd);
    
    	}
    	return result;
    
    
    }
    //---------------------------------------------------------------------------
    
    int  WriteToSE(int Adr,char* Buffer,unsigned long Len)
    {
    HANDLE hwnd;
    DWORD SeId;
    int result=false;
    
    	SeId = GetSniperEliteProcessId();
    	// SeId zawiera id  procesu SniperElite.exe ,jesli -1 to nie uruchomiono procesu    if ((int)SeId != -1)
    	{
    		hwnd =OpenProcess(PROCESS_ALL_ACCESS,false,SeId);
    		if (hwnd == NULL) return 0;
    		result = WriteProcessMemory(hwnd, (LPVOID)Adr, Buffer, Len, &Len);
    		CloseHandle(hwnd);
    
    	}
    	return result;
    }
    
    int GetPlayerPositionMemoryPointer()
    {
    
    DWORD   a,b;
    
    		if ( ReadFromSE(0x744540,(char*)&a,4)==0) return 0;
    		if ( ReadFromSE(0x73413c,(char*)&b,4)==0) return 0;
    		a--;
    		a&= 0x3e8;
    		a=(a*4)+b;
    		if ( ReadFromSE(a,(char*)&b,4)==0) return 0;
    		if ( ReadFromSE(b,(char*)&a,4)==0) return 0;
    		if ( ReadFromSE(a+4,(char*)&b,4)==0) return 0;
    		if ( ReadFromSE(b+8,(char*)&b,4)==0) return 0;
    		a=a+b+4;
    		if ( ReadFromSE(a+1x0c,(char*)&a,4)==0) return 0;
    		a+=8;
    
    
    		return a;
    }
    
    //---------------------------------------------------------------------------
    
    
    
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
    		: TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm1::Timer1Timer(TObject *Sender)
    {
    float x,y,z;
    
    DWORD   a;
    
    	a=GetPlayerPositionMemoryPointer();
    	if (a != 0)
    	{
    		ReadFromSE(a,(char*)&x,4);
    		ReadFromSE(a+4,(char*)&y,4);
    		ReadFromSE(a+8,(char*)&z,4);
    
                    Edit1->Text =  FloatToStr(x);
    		Edit2->Text = FloatToStr(y);
    		Edit3->Text = FloatToStr(z);
    	}
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    DWORD d;
    BYTE b;
    WORD w;
    char c;
    short s;
    int i;
    long l;
    double db;
    long double ld;
    int array[ 20 ];
    unsigned short us;
    
    
    
    if (!OpenDialog1->Execute()) return;
    
    int plik=FileOpen(OpenDialog1->FileName,fmOpenRead);
    if (plik==-1) return;
    
    
    
    int iFileLength = FileSeek(plik,0,2);
    FileSeek(plik,0,0);
    
    
    char *Bufor = new char[iFileLength+1];
    *(Bufor+iFileLength)=0;
    
    
    int iBytesRead = FileRead(plik,Bufor,iFileLength);
    if (iFileLength!=iBytesRead)
       {delete Bufor;return;}
    
    Edit4->Clear();
    
    
    
    Edit5->Text=  FloatToStr(  *(FLOAT*)(Bufor+0x0000001c));
    Edit6->Text=  FloatToStr(  *(FLOAT*)&Bufor[0x00000020]);
    Edit4->Text=  FloatToStr(  *(FLOAT*)&Bufor[0x00000024]);
    Edit7->Text=  FloatToStr(  *(FLOAT*)&Bufor[0x00000030]);
    Edit8->Text=  BYTE (b,&Bufor[0x0000003C]);
    Edit9->Text=  BYTE (b,&Bufor[0x00000040]);
    
    
    delete Bufor;
    FileClose(plik);
    }
    //---------------------------------------------------------------------------
    
    
    
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
    int iFileHandle;
      int iFileLength;
      int iBytesRead;
      PAnsiChar Buffer;
       if (SaveDialog1->Execute())
    
    
      try
      {
    iFileHandle = FileOpen(SaveDialog1->FileName, fmOpenRead);
    
       if (iFileHandle > 0) {
         iFileLength = FileSeek(iFileHandle, 0, 2);
         FileSeek(iFileHandle,0,0);
         Buffer = new AnsiChar[iFileLength+1];
         iBytesRead = FileRead(iFileHandle, Buffer, iFileLength);
         FileClose(iFileHandle);
    
         for (int i = 0; i < iBytesRead; i++)
         {
    
     float v1, v2, v3;
    
    Edit1->Text = (String)v1;
    Edit2->Text = (String)v2;
    Edit3->Text = (String)v3;
    
    v1 = StrToFloat( Edit1->Text );
    v2 = StrToFloat( Edit2->Text );
    v3 = StrToFloat( Edit3->Text );
    }
    }
    }
    }
    try
     {
    }
    catch (...)
    {
    Application->MessageBox(
         L"Can't perform one of the following file operations: Open, Seek, Read, Close.",
         L"File Error", IDOK);
    }
    //---------------------------------------------------------------------------

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    > // SeId zawiera id procesu SniperElite.exe
    I kinda thought this would end up as some lame-assed hacker wannabe thread as soon as a lot of intricate showed up right after "I have no code" (no doubt robbed from somewhere else on the net), coupled with complete ineptitude at fixing basic syntactic errors.

    Yes, I can use google, and I know exactly what you're trying to do.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  14. #14
    Registered User
    Join Date
    Mar 2011
    Posts
    8
    is process name for the new values ​​in the textbox to save, so changing the file to start the game.

  15. #15
    Registered User
    Join Date
    Mar 2011
    Posts
    8
    some can help me? please

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  2. Replies: 11
    Last Post: 03-24-2006, 10:26 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Encrypting text file with ASCII hex
    By supaben34 in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2005, 05:35 PM
  5. Replies: 3
    Last Post: 03-04-2005, 01:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21