Tuesday, March 13, 2018

Reading a flash device(SST25VF016B) memory Example code in C++

Reading flash device(My Case chip BIOS) with flashrom open source software and ready binary memory at particular offset(3975) from there 15 characters from 3975-3990.
#include <iostream>     // std::cout
#include <fstream>      // std::ifstream
#include <stdlib.h>
#include <unistd.h>
#include <cstring>

using namespace std;

char *m_ptr1= new char [20]; // data can be shared all ove the applcaition

int main () {
  char m_ptr[20];
  system("/usr/sbin/flashrom -p internal -r /tmp/bios_backup.bin &> /dev/null");
  usleep(40000);
  //system("hexdump -v /tmp/bios_backup.bin -c -n 15 -s 3975 ");
  std::ifstream is ("/tmp/bios_backup.bin", std::ifstream::binary);
  if (is) {
    is.seekg (0, is.end);
    int length = is.tellg();
    is.seekg (0, is.beg);
    char * buffer = new char [length];
    is.read (buffer,length);
    is.close();
    // ...buffer contains the entire bin BIOS data
    for(int x=0,i=3975;i<=3990; x++,i++)  // memory lcoation 3975
    {
       m_ptr[x] = *(buffer+i);
    }
    //cout <<"Model Name : " << m_ptr << endl;
    m_ptr1=m_ptr;
    delete[] buffer;
    system("rm -f /tmp/bios_backup.bin &> /dev/null");
    cout << "test string :" << m_ptr1 <<endl;
    return true;
  }
  else
  {
     m_ptr1=(char*) "NA....";
     cout << "test string :" << m_ptr1 <<endl;
     return false;
  }
  return 0;
}

No comments:

"NCBN Nara chandrababu naidu" CEO Deals to grow Andhra Pradesh

CISCO network and andhra pradesh CEO Chandra babu  Microsoft Kaizala for andhra pradesh  Google Wi-fi for andhra pradesh CEO Micro...