Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-10-22
4
Medium Priority
?
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 900 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

604 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