Does any know have experience with the iDynamo Reader? This reader is using DES-CBC to encrypt card data. Is there anyone know how to decrypt this data?
Thank so much for your time.
Sorry if this too late but might help for someone else. So the solution is contact Magtek. If you buy Magtek device, ask them for lib. I have got libDS247.a from Magtek. Then import DS247.h to your code, implement the DS247Delegate. I provide here a sample for you-
(void)deviceDidConnect
{
if (theAlertView.visible)
[theAlertView dismissWithClickedButtonIndex:0 animated:NO];
}
- (void)deviceDidDisconnect
{
theAlertView = [[UIAlertView alloc] initWithTitle:#"Hardware Not Connected!"
message:#"Please connect the device."
delegate:self
cancelButtonTitle:nil otherButtonTitles:nil];
[theAlertView show];
[theAlertView release];
}
- (void)magneticCardReadStart
{
read = YES;
[self.tableView reloadData];
}
- (void)magneticCardReadDidFinish:(NSString *)cardString
{
read = NO;
if (trackMode == 67)
{
NSString *string = [cardString substringWithRange:NSMakeRange(6,20)];
self.pan1 = [[string componentsSeparatedByString:#"^"] objectAtIndex:0];
string = [cardString substringWithRange:NSMakeRange(7+pan1.length,27)];
self.name = [[string componentsSeparatedByString:#"^"] objectAtIndex:0];
string = [cardString substringWithRange:NSMakeRange(8+pan1.length+name.length,4)];
self.ed1 = string;
self.ed2 = #"";
self.pan2 = #"";
}
if (trackMode == 68)
{
NSString *string = [cardString substringWithRange:NSMakeRange(5,20)];
self.pan2 = [[string componentsSeparatedByString:#"="] objectAtIndex:0];
string = [cardString substringWithRange:NSMakeRange(6+pan2.length,4)];
self.ed2 = string;
self.ed1 = #"";
self.name = #"";
self.pan1 = #"";
}
if (trackMode == 69 || trackMode == 70)
{
NSString *string = [cardString substringWithRange:NSMakeRange(7,20)];
self.pan1 = [[string componentsSeparatedByString:#"^"] objectAtIndex:0];
string = [cardString substringWithRange:NSMakeRange(8+pan1.length,27)];
self.name = [[string componentsSeparatedByString:#"^"] objectAtIndex:0];
string = [cardString substringWithRange:NSMakeRange(9+pan1.length+name.length,4)];
self.ed1 = string;
string = [cardString substringWithRange:NSMakeRange(83,20)];
self.pan2 = [[string componentsSeparatedByString:#"="] objectAtIndex:0];
string = [cardString substringWithRange:NSMakeRange(84+pan2.length,4)];
self.ed2 = string;
}
if (trackMode == 71)
{
self.ed1 = #"";
self.ed2 = #"";
self.pan1 = #"";
self.pan2 = #"";
self.name = #"";
}
[self.tableView reloadData];
}
The should set trackMode as 67 as default, and the cardString is raw card data
Related
I am trying to load .clp file in my iPhone application. For that I am using below code
NSString *filePath = [[NSBundle mainBundle]
pathForResource:#"autodemo" ofType:#"clp"];
environment = CreateEnvironment();
char *clipsFileChar = (char *)[filePath cStringUsingEncoding:NSASCIIStringEncoding];
Load(clipsFileChar);
Reset();
Run(-1);
NSString *evalS = [NSString stringWithFormat:#"(find-all-facts ((?f state-list)) TRUE)"];
char * evalStr = (char *)evalS;
DATA_OBJECT obj;// = {0,-1};
// obj.type = STRING;
// obj.value = evalStr;
int i = Eval(evalStr, &obj);
NSLog(#"%d",i);
now when I run this code Eval(evalStr, &obj) gives me 0 every time.
I am using autodemo.clp file from this link.
So, how to make Eval() command work and how do I get response returned by clp file?
thanks,
below code solved my problem, hope it will help to someone else.. :)
InitializeEnvironment();
Clear();
NSString *filePath = [[NSBundle mainBundle]
pathForResource:#"autodemo" ofType:#"clp"];
char *clipsFileChar = (char *)[filePath cStringUsingEncoding:NSASCIIStringEncoding];
IncrementGCLocks();
Load(clipsFileChar);
Reset();
Run(-1);
DecrementGCLocks();
[self nextUIState];
- (void)nextUIState
{
DATA_OBJECT theDO;
NSString * evalS = #"(find-all-facts ((?f state-list)) TRUE)";
char *evalStr = (char *)[evalS cStringUsingEncoding:NSASCIIStringEncoding];
int j = EnvEval(GetCurrentEnvironment(), evalStr, &theDO);
NSLog(#"j = %d",j);
if(factDict)
{
[factDict release];
factDict = nil;
factDict = [[NSMutableDictionary alloc] init];
}
id value = [self objectForDataObject:&theDO];
NSLog(#"%#",[value description]);
}
-(id) objectForDataObject: (DATA_OBJECT*) arg
{
switch(arg->type)
{
case FACT_ADDRESS:
{
DATA_OBJECT data = { 0 };
struct fact* aFact = (struct fact*) arg->value;
if(EnvGetFactSlot(GetCurrentEnvironment(),aFact,(char*)[#"current" UTF8String],&data))
{
[factDict setObject:[self objectForDataObject: &data] forKey:#"current"];
[factDict retain];
}
return factDict;
}
case SYMBOL:
{
NSString *str = [NSString stringWithUTF8String: ValueToString(arg->value)];
if ([str isEqual: #"nil"]) return nil;
if ([str hasPrefix: #"<<<"] && [str hasSuffix: #">>>"])
{
return [self dataFromSymbolString: str];
}
return str;
}
case STRING:
{
return [NSString stringWithUTF8String: ValueToString(arg->value)];
}
case INTEGER:
{
return [NSNumber numberWithInt: ValueToInteger(arg->value)];
}
case FLOAT:
{
return [NSNumber numberWithDouble: ValueToDouble(arg->value)];
}
case EXTERNAL_ADDRESS:
{
return (id) arg->value;
}
case MULTIFIELD:
{
int i, count = GetpDOLength(arg);
NSMutableArray *args = [NSMutableArray arrayWithCapacity: count];
FIELD_PTR fptr = (FIELD_PTR) GetMFPtr(GetpValue(arg),GetpDOBegin(arg));
for(i = 0; i < count; ++i, ++fptr)
{
DATA_OBJECT dobj;
dobj.type = fptr->type;
dobj.value = fptr->value;
[args addObject: [self objectForDataObject: &dobj]];
}
return args;
}
default:
return nil;
}
}
If you find out any other and better way(ofcourse there is), please let me know. :)
NSMutableArray *nameArray = [[NSMutableArray alloc] init];
[nameArray addObject:#"abc"];
[nameArray addObject:#"cdf"];
[nameArray addObject:#"jkl"];
//Use a for each loop to iterate through the array
for (NSString *s in nameArray) {
NSLog(#"value is %#", s);
}
The above code shows all the values of nameArray. But I want to assign all those values to these NSString:
NSString *a;
NSString *b;
NSString *cd;
An aray can have 1 or more elements but not more than 5.
Actually,I have 5 buttons, each button on click will add a NSString value(values are: f1,f2,f3,f4 and f5) to NSMutableArray. Now its upto the user if he clicks 2 buttons or 3 or 5 in a day. Now all these values will be saved in NSMutableArray (which can be 1 or 2 but not more than 5). That NSMutableArray will be saved in NSUserDefaults. This NSMutableArray than will be used in another view where I have some UIImageView (1,2,3,4 and 5). Now when I will get the string values from that Array(f1,f2,f3). If it is f1 then an image will be assigned to UIImage 1 if it is f3 then to image 3 and so on.
How to achieve this?
I would do something like that:
NSArray *array = [NSArray arrayWithObjects:#"A", #"B", #"C", #"D", #"E", nil];
NSString *a = nil, *b = nil, *c = nil, *d = nil, *e = nil;
NSUInteger idx = 0;
for ( NSString *string in array )
{
switch ( idx++ ) {
case 0: a = string; break;
case 1: b = string; break;
case 2: c = string; break;
case 3: d = string; break;
case 4: e = string; break;
}
}
As at least one element will be there in your array:
NSString *a = (NSString *)[nameArray objectAtIndex:0];
As maximum will be five elements:
for(int i = 1;i<[array count];i++)
{
if(i == 1)
{
NSString *b = (NSString *)[nameArray objectAtIndex:1];
}
else if(i == 2)
{
NSString *c = (NSString *)[nameArray objectAtIndex:2];
}
else if(i == 3)
{
NSString *d = (NSString *)[nameArray objectAtIndex:3];
}
else if(i == 4)
{
NSString *e = (NSString *)[nameArray objectAtIndex:4];
}
}
a = [nameArray objectAtIndex:0];
b = [nameArray objectAtIndex:1];
cd = [nameArray objectAtIndex:2];
If you want to put your array elements into separate variables with distinct names, there is no automation in objective c (unlike say, in JavaScript) since it is a compiled and not a interpreted language. Something similar you can achieve with NSDictionary, i.e. to "index" objects with strings or whatever type you want.
You could go on with a simple C array of 5 unsigned chars, where the index of the array would point to your data. Something like this:
unsigned char nameArray[5] = {0, 0, 0, 0, 0};
// if you want to set the 3rd variable, use:
nameArray[2] = 1;
// to query:
if (nameArray[2]) { ... }
// When you need to save it to NSUserDefaults, wrap it into an NSData:
NSData* nameData = [NSData dataWithBytes:nameArray length:sizeof(nameArray)];
[[NSUserDefaults standardUserDefaults] setObject:nameData forKey:#"myKey"];
// To query it:
NSData* nameData = [[NSUserDefaults standardUserDefaults] dataForKey:#"myKey"];
const unsigned char* nameArray2 = [nameData bytes];
unsigned char second = nameArray2[2];
EDITED: corrected array access
If there is at most five options the easiest way to do it is with an if-else-if chain.
NSString *label1 = nil, *label2 = nil, *label3 = nil, *label4 = nil, *label5 = nil;
for (NSString *s in nameArray) {
if (label1 == nil)
label1 = s;
else if (label2 == nil)
label2 = s;
else if (label3 == nil)
label3 = s;
else if (label4 == nil)
label4 = s;
else if (label5 == nil)
label5 = s;
}
NSString *str1=nil;
NSString *str2=nil;
NSString *str3=nil;
NSString *str4=nil;
for (LocationObject *objLoc in arrLocListFirstView)
{
if (objLoc.isLocSelected)
{
for (LocationObject *obj in arrLocListFirstView)
{
if (str1 == nil)
str1 = objLoc.strLoc;
else if (str2 == nil)
str2 = obj.strLoc;
else if (str3 == nil)
str3 = obj.strLoc;
else if (str4 == nil)
str4 = obj.strLoc;
}
NSString *combined = [NSString stringWithFormat:#"%#,%#,%#,%#", str1,str2,str3,str4];
lblLocation.text=combined; (displaying text in UILabel)
}
}
I'm just learning to do the "Hello, World" app. But I have a question. I'd like to change the code so the result reads "World, Hello" but can't figure out what I'm doing wrong.
Here's the original code:
- (IBAction)changeGreeting:(id)sender {
self.userName = self.textField.text;
NSString *nameString = self.userName;
if ([nameString length] == 0) {
nameString = #"World";
}
NSString *greeting = [[NSString alloc] initWithFormat:#"Hello, %#!", nameString];
self.label.text = greeting;
}
and I thought it would work if I could change it to:
- (IBAction)changeGreeting:(id)sender {
self.userName = self.textField.text;
NSString *nameString = self.userName;
if ([nameString length] == 0) {
nameString = #"World";
}
NSString *greeting = [[NSString alloc] initWithFormat:nameString , #"Hello, %#!"];
self.label.text = greeting;
}
However that still didn't work. What would I do to make that work?
Change this line
NSString *greeting = [[NSString alloc] initWithFormat:nameString , #"Hello, %#!"];
To
NSString *greeting = [[NSString alloc] initWithFormat:#"%#, Hello!", nameString];
initWithFormat, uses place holder when you write #"%#, Hello!" the "%#" indicates that the following string nameString will be replaced by it
So when we #"%#, Hello!" we really mean #"nameString, Hello!" (nameString in your example is World)
I am using TouchJSON to retrieve the JSON response from http://enbr.co.cc/TrailsApp/shops.php. In my app I use this code to handle a url scheme.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
if (!url) {
return NO;
}
NSString *urlString = [url absoluteString];
NSString *urlStringDecoded = [urlString stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSArray *list = [urlStringDecoded componentsSeparatedByString:#"="];
NSString *urlPrefix = [list objectAtIndex:0];
NSString *name = [list objectAtIndex:1];
if ([urlPrefix isEqualToString:#"tridetrails://opentrail?name"]) {
TrailViewController *trailViewController = [[TrailViewController alloc] initWithNibName:#"TrailViewController" bundle:[NSBundle mainBundle]];
trailViewController.trailToGoto = name;
[self.navigationController pushViewController:trailViewController animated:YES];
[trailViewController release];
}
if ([urlPrefix isEqualToString:#"tridetrails://openshop?name"]) {
ShopViewController *shopViewController = [[ShopViewController alloc] initWithNibName:#"ShopViewController" bundle:[NSBundle mainBundle]];
shopViewController.shopToGoto = name;
[self.navigationController pushViewController:shopViewController animated:YES];
[shopViewController release];
}
return YES;
}
How can I push the correct entry from my NSDictionary created from the JSON to the ShopViewController based on the NSString name? Here is my dictionary printed out by NSLog with NSLog(#"%#", myObj);. Thanks in advance.
{
shops = (
{
blurb = "Bootdoctors blurb";
image = bootdoctorslogo;
locations = "Mountain Village";
motto = "Bootdoctors shop motto";
name = Bootdoctors;
},
{
blurb = "Easy Rider blurb";
image = easyriderlogo;
locations = Telluride;
motto = "Easy Rider shop motto";
name = "Easy Rider";
},
{
blurb = "Paragon Ski & Sport blurb";
image = paragonskiandsportlogo;
locations = Telluride;
motto = "Paragon shop motto";
name = "Paragon Ski & Sport";
},
{
blurb = "Telluride Sports blurb";
image = telluridesportslogo;
locations = "Telluride and Mountain Village";
motto = "Telluride Sports shop motto";
name = "Telluride Sports";
}
);
}
You probably need to give a bit more information about what you are trying to do. For instance you don't say how you retrieve the dictionary containing the details of all the shops and how ShopViewController has access to this dictionary. But selecting one shop by name from the dictionary can be done with something like this:
NSDictionary *jsonResponse; // You don't say how the ShopViewController has access to
// the response so let's just assume a local variable here.
NSDictionary *foundShop = nil; // This will be selected shop after the search below
NSArray *shops = [jsonResponse objectForKey:#'shops'];
for (NSDictionary *shop in shops) {
if ([shop objectForKey:#'name'] isEqualToString:self.shopToGoto]) {
foundShop = shop;
break;
}
}
if (foundShop) {
// Do something with the dictionary keys and values in foundShop
}
else {
// Error condition - shop with required name is not present
// Handle error
}
You could use a NSPredicate to select the shop(s) you are looking for:
NSString* shopName = ...;
NSArray* shops = ...; // this is your JSON-produced array of NSDictionary Shop objects
NSPredicate* predicate = [NSPredicate predicateWithFormat: #"name == '%#'", shopName ];
NSArray* matchingShops = [shops filteredArrayUsingPredicate: predicate];
NSDictionary* firstMatchingShop = [matchingShops objectAtIndex: 0];
Been running instruments on my app. Its says i am leaking 864bytes & 624bytes from 2 NSCFString and the library responsible is Foundation.
So that leads me to believe thats its not a leak caused by me? Or is it?
Here is the offending method according to instruments. It seems to be a
substringWithRange
that is leaking.
-(void) loadDeckData
{
deckArray =[[NSMutableArray alloc] init];
NSString* path = [[NSBundle mainBundle] pathForResource:#"rugby" ofType:#"txt"
inDirectory:#""];
NSString* data = [NSString stringWithContentsOfFile:path encoding:
NSUTF8StringEncoding error: NULL];
NSString *newString = #"";
NSString *newline = #"\n";
NSString *comma = #",";
int commaCount = 0;
int rangeCount = 0;
NSString *nameHolder = #"";
NSString *infoHolder = #"";
NSMutableArray *statsHolder = [[NSMutableArray alloc] init];
for (int i=0; i<data.length; i++)
{
newString = [data substringWithRange:NSMakeRange(i, 1)];
if ([newString isEqualToString: comma]) //if we find a comma
{
if (commaCount == 0)// if it was the first comma we are parsing the
NAME
{
nameHolder = [data substringWithRange:NSMakeRange(i-
rangeCount, rangeCount)];
}
else if (commaCount == 1)//
{
infoHolder = [data substringWithRange:NSMakeRange(i-
rangeCount, rangeCount)];
//NSLog(infoHolder);
}
else // if we are on to 2nd,3rd,nth comma we are parsing stats
{
NSInteger theValue = [[data
substringWithRange:NSMakeRange(i-rangeCount,rangeCount)]
integerValue];
NSNumber* boxedValue = [NSNumber
numberWithInteger:theValue];
[statsHolder addObject:boxedValue];
}
rangeCount=0;
commaCount++;
}
else if ([newString isEqualToString: newline])
{
NSInteger theValue = [[data substringWithRange:NSMakeRange(i-
rangeCount,rangeCount)] integerValue];
NSNumber* boxedValue = [NSNumber numberWithInteger:theValue];
[statsHolder addObject:boxedValue];
commaCount=0;
rangeCount=0;
Card *myCard = [[Card alloc] init];
myCard.name = nameHolder;
myCard.information = infoHolder;
for (int x = 0; x < [statsHolder count]; x++)
{
[myCard.statsArray addObject:[statsHolder
objectAtIndex:x]];
}
[deckArray addObject:myCard];
[myCard autorelease];
[statsHolder removeAllObjects];
}
else
{
rangeCount++;
}
}
[statsHolder autorelease];
}
Thanks for your advice.
-Code
As Gary's comment suggests this is very difficult to diagnose based on your question.
It's almost certainly a leak caused by you however, I'm afraid.
If you go to the View menu you can open the Extended Detail. This should allow you to view a stack trace of exactly where the leak occurred. This should help diagnose the problem.
When to release deckArray? If deckArray is a class member variable and not nil, should it be released before allocate and initialize memory space?