Advertisement
Guest User

unpirate.c

a guest
Mar 16th, 2012
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.67 KB | None | 0 0
  1. /*
  2.     I wrote this program one evening when I was going through iNES serial numbers
  3.     and I got tired of using ResEdit.  This works for iNES 7.7, though it doesn't
  4.     really matter since someone cracked it.  It probably won't work for later
  5.     versions since they'll change the hobbling scheme and I have no idea if it works
  6.     on earlier versions (besides, if you're using an earlier version when 7.7 and the serial
  7.     is available there's something wrong.)
  8. */
  9.  
  10. #define rFileNotFoundAlert          128
  11. #define rUiDoneAlert                129
  12. #define kQuitButton                 1
  13.  
  14. // Prototypes
  15. //______________________________________________________________
  16.  
  17. FSSpec GetiNES(void);
  18. void InitializeToolbox( void );
  19. void URiNES(void);
  20. void ZapPrefs(void);
  21.  
  22. // Main
  23. //______________________________________________________________
  24.  
  25. void main(void)
  26. {
  27. short theItem;
  28.  
  29. InitializeToolbox();
  30. ZapPrefs();
  31. URiNES();
  32.  
  33. theItem=NoteAlert(rUiDoneAlert, nil);
  34. }
  35.  
  36. // Functions
  37. //______________________________________________________________
  38.  
  39. /*
  40.     This just opens the stand open box so you can locate iNES.  
  41.     I probably could have used PBCatSearch to do it but I'm too lazy
  42.     do dig through IM to figure out the function calls
  43. */
  44.  
  45. FSSpec GetiNES(void)
  46. {
  47. SFTypeList typeList={'APPL',0,0,0}; // why look for anything other than APPLs?
  48. StandardFileReply theReply;
  49.  
  50. StandardGetFile(nil,1,typeList, &theReply);
  51. if(theReply.sfGood==true){
  52.     return(theReply.sfFile);
  53. }else{
  54.     SysBeep(1);
  55.     ExitToShell();
  56.     }
  57. }
  58.  
  59. //______________________________________________________________
  60.  
  61. /*
  62.     This assumes the prefs file is still invisible, locked, & in the prefs folder.
  63.     If it's not, then the app quits.  If it is, it unlocks the file and deletes it.
  64.     This is a little bit of a pain since you have to retype all of your settings
  65.     (but not as much of a pain as unpirating iNES manually.  If anyone feels like
  66.     it, they should update this so it fixes the prefs file without deleting it.
  67.     It shouldn't be that hard (look at the a clean pref along with a pirated pref)
  68. */
  69.  
  70. void ZapPrefs()
  71. {
  72. short theVolRef;
  73. long theDirID;
  74. FSSpec theFSSpec;
  75. OSErr theError;
  76. Str255 prefsFileName="\piNES.prefs";
  77.  
  78. theError=FindFolder(kOnSystemDisk, kPreferencesFolderType,
  79.                     kDontCreateFolder, &theVolRef, &theDirID);
  80. theError=FSMakeFSSpec(theVolRef,theDirID,prefsFileName,&theFSSpec);
  81.  
  82. if(theError==noErr){
  83.     FSpRstFLock(&theFSSpec);
  84.     FSpDelete(&theFSSpec);
  85. }else{
  86.     StopAlert(rFileNotFoundAlert,nil);
  87.     ExitToShell();
  88.     }
  89. }
  90.  
  91. //______________________________________________________________
  92.  
  93. /*
  94.     This removes the actual iNES resource that triggers the hobbling
  95.     mechanism in the application.  Since I found iNES sometimes
  96.     creates a resource with id 0 and sometimes with id 1, this checks
  97.     for both.  If it doesn't find either, the app quits.
  98. */
  99.  
  100. void URiNES()
  101. {
  102. short theFileRefNum;
  103. Handle theHandle;
  104. FSSpec theFSSpec;
  105. ResType theResourceType = 'iNES';
  106. short theResID0=0;
  107. short theResID1=1;
  108.  
  109. theFSSpec=GetiNES();
  110. theFileRefNum=FSpOpenResFile( &theFSSpec,fsRdWrPerm);
  111.  
  112. if(theFileRefNum== -1){
  113.     StopAlert(rFileNotFoundAlert,nil);
  114.     ExitToShell();
  115.     }
  116.    
  117. theHandle=GetResource(theResourceType, theResID0);
  118.  
  119. if(theHandle==NULL){
  120.     SysBeep(1);
  121. }else{
  122.     RemoveResource(theHandle);
  123.     DisposeHandle(theHandle);
  124. }
  125.  
  126. theHandle=GetResource(theResourceType, theResID1);
  127.  
  128. if(theHandle==NULL){
  129.     SysBeep(1);
  130.     ExitToShell();
  131. }else{
  132.     RemoveResource(theHandle);
  133.     DisposeHandle(theHandle);
  134.     }
  135. }
  136.  
  137. //______________________________________________________________
  138.  
  139. void InitializeToolbox( void )
  140. {
  141. InitGraf( &qd.thePort );
  142. InitFonts();
  143. InitWindows();
  144. InitMenus();
  145. TEInit();
  146. InitDialogs( 0L );
  147. FlushEvents( everyEvent, 0 );
  148. InitCursor();
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement