Solved

how To edit exe to insert a serial no wich can be usd by runing exe

Posted on 2003-10-22
4
239 Views
Last Modified: 2013-12-26
At time of installation I have to open the resource. and i have to insert a string serial number in the exe.
please provide me code to edit the exe (in solaris) to insert a serial number which can be used by exe at run time. please help

0
Comment
Question by:ssahu
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 225 total points
ID: 9612225
/* serialnum.c
 *
 * Rewrite serial number in a file.  This should be called as such:
 *   strings -o filename | grep serialnumberflag | serialnum filename serialnumber
 *
 * the serialnumberflag is a string embedded in the file at the position where the serial number
 * will be written.  serialnumberflag must be at least as long a the eventual serial number.
 * serialnumberflag must not contain whitespace.
 *
 * For instance the executable file "exefile" could have the following line in its source code:
 *    char serialnum[] = "The_serial_number_will_go_here";
 *
 * then the patch would occur as follows:
 *   strings -o exefile | grep "The_serial_number_will_go_here"| serialnum exefile "1456 FJCH 0013 ABCD"
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

int main (int argc, char ** argv)
{
  unsigned len;
  int fd = -1;
  long offset = -1L;
  long roffset = -1L;
  char serialtag[1024];

  if (argc < 3) {
    printf("usage: %s filename serialnum\n", argv[0]);
    return (-1);
  }

  /* open the executable file to modify */
  if ((fd = open(argv[1], O_RDWR)) == -1) {
    perror("could not open executable file");
    return (-2);
  }

  /* read the serialnumber tag string and is offset as output of strings -o */
  if (scanf("%ld %1000s", &offset, serialtag) < 2) {
    printf("could not parse serialtag offset\n");
    return (-3);
  }
  printf("offset = %ld    tag = %s\n", offset, serialtag);

  /* make sure the serialnumber tag in the file is large enough to hold the serial number */
  if ((len = strlen(argv[2])) > strlen(serialtag)) {
    printf("serial number too long for reserved space in file.\n");
    return (-4);
  }

  /* seek to the appropriate location in the file and write out the serial number string */
  if ((roffset = lseek(fd, offset, SEEK_SET)) != offset) {
    printf("seek into execuable file failed - %ld", roffset);
    return (-5);
  }

  /* write out the new serial number string */
  if (write(fd, argv[2], len+1) < (int)(len+1)) {
    perror("failed to write serial number into execuable file");
    return (-6);
  }

  if (close(fd)) {
    perror("failed to close executable file");
    return (-7);
  }

  return (0);
}

0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 9612236
You can remove the line (for debugging):
 printf("offset = %ld    tag = %s\n", offset, serialtag);

0
 
LVL 18

Expert Comment

by:liddler
ID: 10191536
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by  brettmjohnson

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

liddler
EE Cleanup Volunteer
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Change owner from userA to server Local Administrators 7 51
lucky13 challenge 11 112
Line meaning 9 77
Detect file exist or not 3 83
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now