Can any one help me desipher this error that I am getting while trying to open a port with a dll - delphi

Can any one help me desipher this error that I am getting while trying to open a port with a dll. I am getting an erro: "Access violation at address 0003D078" When I call SAAT_Open(myCharPtrOpen). Not sure if I am defininig the Handle correctly on unit UntRFIDAPI. Is the variable PHandle define correctly?
Here is my code:
procedure TForm5.Button1Click(Sender: TObject);
var
myString, myString2 : string;
myCharPtrInit: PChar;
myCharPtrOpen: PChar;
i : Integer;
Open, Init: Boolean;
begin
// Create a string of Char's
myString := '&hp';
// Point to the first character in the string
i := 1;
myCharPtrInit := Addr(myString[i]);
if SAAT_TCPInit(myCharPtrInit,'192.168.3.238',7086) = True then
begin
StatusBar1.Panels[0].Text := 'Initiated'; //ShowMessage('Initiated');
myString2 := 'hp';
myCharPtrOpen := Addr(myString2[i]);
if SAAT_Open(myCharPtrOpen) = True then StatusBar1.Panels[1].Text := 'Opened';
end;
end;
unit UntRFIDAPI;
INTERFACE
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls, Dialogs,
StdCtrls, Forms, DBCtrls, DB, Grids, DBGrids,Mask, ExtCtrls,
Buttons, WinTypes;
var
A: String;
function SAAT_TCPInit(pHandle: Pointer; pHostName: String; nsocketPort: Integer):Boolean; stdcall;
function SAAT_Open(pHandle: Pointer):Boolean; stdcall;
function SAAT_Close(pHandle: Pointer):Boolean; stdcall;
implementation
function SAAT_TCPInit; external 'RFIDAPI.dll';
function SAAT_Open; external 'RFIDAPI.dll';
function SAAT_Close; external 'RFIDAPI.dll';
end.
Here is the API call:
1.1 Initialize Ethernet Port(TCP) connection
//TCP parameters initialization
//Functionality:import by parameter, initialize TCP to prepare for opening connection
//Parameters:
// pHandle for preserving the opening ports handl
// pHostName reader IP address, only effective under the ethernet communication
// nsocketPort network SOCKET port
//Returned value:true: Operation Succeeded, false Operation Failed
bool SAAT_TCPInit (void** pHandle,char *pHostName,int nsocketPort)
If the IP connecting to the reader is 192.168.0.238, port is 7086, then calling as follows:
HANDLE hp;
if (!SAAT_TCPInit(&hp, ”192.168.0.238”, 7086))
{
printf("reader initialization failed!\n");
return false;
}

As Rudy and David pointed out, your translation of the SAAT_TCPInit() function signature is wrong, and your use of a pointer handle with this API is wrong. They already explained why your code is wrong, so I won't repeat the reasons. They have some minor issues with their answers, though.
Your Delphi code should look more like this instead:
unit UntRFIDAPI;
interface
function SAAT_TCPInit(out pHandle: Pointer; pHostName: PAnsiChar; nsocketPort: Integer): Boolean; stdcall;
function SAAT_Open(pHandle: Pointer): Boolean; stdcall;
function SAAT_Close(pHandle: Pointer): Boolean; stdcall;
implementation
const
RFIDAPIDLL = 'RFIDAPI.dll';
function SAAT_TCPInit; external RFIDAPIDLL;
function SAAT_Open; external RFIDAPIDLL;
function SAAT_Close; external RFIDAPIDLL;
end.
procedure TForm5.Button1Click(Sender: TObject);
var
hp: Pointer;
begin
if SAAT_TCPInit(hp, '192.168.3.238', 7086) then
begin
StatusBar1.Panels[0].Text := 'Initiated';
if SAAT_Open(hp) then
StatusBar1.Panels[1].Text := 'Opened';
...
SAAT_Close(hp);
end;
end;
For reference, here is the content of the DLL's RFIDAPIEXPORT.h header file for C++:
/***********************************************************************
* Module: RFIDEXPORT.h
* Author:
* Modified:
* Purpose:
***********************************************************************/
#pragma once
#ifndef _RFIDEXPORT_H
#define _RFIDEXPORT_H
#ifdef RFIDAPI_EXPORTS
#define RFID_API __declspec( dllexport )
#else
#define RFID_API __declspec( dllimport )
#endif
extern "C"
{
bool RFID_API __stdcall SAAT_TCPInit(void** pHandle,char *pHostName,int nsocketPort);
bool RFID_API __stdcall SAAT_COMInit(void** pHandle,unsigned char nBusAddr,char *pComNum,int nBaud );
bool RFID_API __stdcall SAAT_USBInit(void** pHandle,unsigned char nBusAddr,char * pUSBNum,int nBaud );
bool RFID_API __stdcall SAAT_UDPInit(void** pHandle,char *pHostName,int nsocketPort);
bool RFID_API __stdcall SAAT_Open(void* pHandle);
bool RFID_API __stdcall SAAT_Close(void *pHandle);
bool RFID_API __stdcall SAAT_Reconnect(void *pHandle);
bool RFID_API __stdcall SAAT_HeartSend (void* pHandle);
bool RFID_API __stdcall SAAT_SysInfSet (void* pHandle ,unsigned char nType,unsigned char* pParm,int nLen);
bool RFID_API __stdcall SAAT_SysInfQuery (void* pHandle ,unsigned char nType, unsigned char *pPara, unsigned char *pLen);
bool RFID_API __stdcall SAAT_WorkModeSet (void* pHandle ,unsigned char nType);
bool RFID_API __stdcall SAAT_ParmOp (void* pHandle ,unsigned char nType, unsigned char nStartAddrr, unsigned char nLen, unsigned char *pData, unsigned char *pDataLen);
bool RFID_API __stdcall SAAT_RFParaSet (void* pHandle ,unsigned char nType, unsigned char nParaLen,unsigned char* pPara);
bool RFID_API __stdcall SAAT_RFParaQuery (void* pHandle ,unsigned char nType,unsigned char* pPara, unsigned char *pLen);
bool RFID_API __stdcall SAAT_CommunicatParaSet (void* pHandle ,unsigned char nType, unsigned char* pPara, unsigned char nLen);
bool RFID_API __stdcall SAAT_CommunicatParaQuery (void* pHandle ,unsigned char nType, unsigned char* pPara,unsigned char *pLen);
bool RFID_API __stdcall SAAT_NetParaSet (void* pHandle ,unsigned char nType, unsigned char* pPara, unsigned char nLen);
bool RFID_API __stdcall SAAT_NetParaQuery (void* pHandle ,int nType, unsigned char* pPara,unsigned char *pLen);
bool RFID_API __stdcall SAAT_TagOpParaSet(void* pHandle ,unsigned char nType, unsigned char *pPara,unsigned char nLen);
bool RFID_API __stdcall SAAT_TagOpParaQuery (void* pHandle ,unsigned char nType, unsigned char* pPara, unsigned char *pLen);
bool RFID_API __stdcall SAAT_ExtendBroadParaSet (void* pHandle ,unsigned char nType, unsigned char pSendChunnel);
bool RFID_API __stdcall SAAT_ExtendBroadParaQuery (void* pHandle ,unsigned char nType, char* pPara, unsigned char* pLen);
bool RFID_API __stdcall SAAT_TotalAntennaParmQuery (void* pHandle,unsigned char *szAntennaPara,unsigned char *pLen);
bool RFID_API __stdcall SAAT_AntennaParmQuery (void* pHandle,unsigned char nAntenna,unsigned char * pAntennaEnable,unsigned char *pAntennaPower,unsigned char *pAntennaQueryTime );
bool RFID_API __stdcall SAAT_AntennaParmSet(void* pHandle ,unsigned char *pPara,unsigned char nLen );
bool RFID_API __stdcall SAAT_SetAntennaPortEnable (void* pHandle,unsigned char nAntenna,unsigned char nEnable );
bool RFID_API __stdcall SAAT_SetAntennaPower (void* pHandle,unsigned char nAntenna,unsigned char nPower );
bool RFID_API __stdcall SAAT_SetAntennaTime (void* pHandle,unsigned char nAntenna,unsigned char nTime );
bool RFID_API __stdcall SAAT_PowerOff(void *pHandle);
bool RFID_API __stdcall SAAT_CarrierWaveOp(void* pHandle ,unsigned char nType, unsigned char nPort);
bool RFID_API __stdcall SAAT_IOOperate(void* pHandle,unsigned char nPort,unsigned char nState);
bool RFID_API __stdcall SAAT_IOStateQuery(void* pHandle,unsigned char *pState);
bool RFID_API __stdcall SAAT_Reboot (void* pHandle,unsigned char nMode);
bool RFID_API __stdcall SAAT_Reading_IOConfig (void* pHandle,unsigned char nConfigBit);
bool RFID_API __stdcall SAAT_Reading_IOQuery (void* pHandle,unsigned char* pConfigBit);
bool RFID_API __stdcall SAAT_IOPulseWidthSet (void* pHandle,unsigned char nIOPort,unsigned char nWidth);
bool RFID_API __stdcall SAAT_IOPulseWidthQuery (void* pHandle,unsigned char nIOPort,unsigned char* pWidth);
bool RFID_API __stdcall SAAT_6BTagSelect ( void* pHandle, unsigned char nType, unsigned char nStartAddr,
unsigned char nDataBite, unsigned char * Data );
bool RFID_API __stdcall SAAT_6BReadUIDCode (void *pHandle,unsigned char nAntenna,unsigned char nType);
int RFID_API __stdcall SAAT_6BRevUIDMsg (void *pHandle, unsigned char* nAntenna, unsigned char* pUIDData,
unsigned char* nUIDLen);
bool RFID_API __stdcall SAAT_6BReadUserData ( void *pHandle ,unsigned char nAntenna,unsigned char nType,unsigned char * pTagID,unsigned char nStartAddr,unsigned char nReadLen, unsigned char *pdata,unsigned char dataLen);
bool RFID_API __stdcall SAAT_6BWriteUserData (void* pHandle,
unsigned char nAntenna,
unsigned char nType,
unsigned char *pTagID,
unsigned char nStartAddr,
unsigned char *pValue,
unsigned char *pLen);
bool RFID_API __stdcall SAAT_6BTagLock (void* pHandle, unsigned char nAntenna, unsigned char nType,
unsigned char *pTagID, unsigned char nStartAddrr, unsigned char nLen);
bool RFID_API __stdcall SAAT_6BTagLockQuery (void* pHandle, unsigned char nAntenna,
unsigned char *pTagID, unsigned char nStartAddr, unsigned char nLen,unsigned char *pData,unsigned char nDataLen);
bool RFID_API __stdcall SAAT_6CTagSelect ( void *pHandle, unsigned char nBank ,unsigned short nStartAddr,unsigned char MaskBit,
unsigned char *Data ,unsigned char Datalength,unsigned char nSessionZone,
unsigned char nActiveFlag, unsigned char nCutFlag );
bool RFID_API __stdcall SAAT_6CReadEPCCode ( void *pHandle,unsigned char nAntenna, unsigned char nType,
unsigned int nTagCount);
int RFID_API __stdcall SAAT_6CRevEPCMsg (void *pHandle, unsigned char* nAntenna, unsigned char* pEPCData,
unsigned char* nEPCLen);
bool RFID_API __stdcall SAAT_6CReadTIDCode ( void *pHandle,unsigned char nAntenna, unsigned char nType, unsigned int nTagCount);
int RFID_API __stdcall SAAT_6CRevTIDMsg (void *pHandle, unsigned char* nAntenna, unsigned char* pTIDData, unsigned char* nTIDLen);
bool RFID_API __stdcall SAAT_6CWriteEPCCode ( void* pHandle,unsigned char nAntenna,unsigned char nType,
unsigned char *pAccessPWD, unsigned char *pWriteData,unsigned char nLen );
bool RFID_API __stdcall SAAT_6CReadUserData ( void* pHandle,
unsigned char nAntenna,
unsigned int StartAddr,
unsigned int nToReadLen,
unsigned int nWaitTime,
unsigned char * UserData,
unsigned int* pDataLen);
bool RFID_API __stdcall SAAT_6CWriteUserData (void* pHandle,
unsigned char nAntenna,
unsigned char nType,
unsigned char *pAccessPWD,
unsigned int nStartAddr,
unsigned int nWaitTime,
unsigned char *pWriteData,
unsigned int *pToWriteLen);
bool RFID_API __stdcall SAAT_6CWriteBankData (void* pHandle, unsigned char nAntenna, unsigned char nType, unsigned char *pAccessPWD,
unsigned char nBank, unsigned char *pWriteData, unsigned char nLen);
bool RFID_API __stdcall SAAT_6CClearBankData (void* pHandle, unsigned char nAntenna, unsigned char nType, unsigned char *pAccessPWD,
unsigned char nBank, unsigned char nStartAddr, unsigned char nLen);
bool RFID_API __stdcall SAAT_6CAccessPWDSet (void *pHandle, unsigned char nAntenna, unsigned char nType, unsigned char *pOrgPWD,
unsigned char *pNewPWD);
bool RFID_API __stdcall SAAT_6CDestroyPWDSet (void *pHandle, unsigned char nAntenna,unsigned char nType, unsigned char *pAccessPWD,
unsigned char *pDestroyPWD );
bool RFID_API __stdcall SAAT_6CTagLock (void *pHandle, unsigned char nAntenna, unsigned char *pAccessPWD, unsigned char nType,
unsigned char nBank);
bool RFID_API __stdcall SAAT_6CTagKill (void *pHandle, unsigned char nAntenna,unsigned char *pDestroyPWD,
unsigned char *pEPC, int nEPCLen);
bool RFID_API __stdcall SAAT_6CEASFlagSet (void *pHandle, unsigned char nAntenna, unsigned char nType,
unsigned char* pAccessPwd, int nEASFlag);
bool RFID_API __stdcall SAAT_6CEASMonitorEnable (void *pHandle, unsigned char nAntenna,unsigned char nSetEAS);
bool RFID_API __stdcall SAAT_Copyright(void** pHandle, char* copyright);
bool RFID_API __stdcall SAAT_SetLanguageType (void* pHandle,char* szType);
bool RFID_API __stdcall SAAT_GetErrorMessage(void *pHandle,char *szMsg, int nLen);
bool RFID_API __stdcall SAAT_GetErrorCode(void *pHandle,int *pCode);
bool RFID_API __stdcall SAAT_SysTest(void* pHandle ,unsigned char nType,unsigned char nAntenna, unsigned char *pTestParm, unsigned char nLen);
bool RFID_API __stdcall SAAT_RawSendData(void* pHandle , unsigned char *pSendData, unsigned char nLen);
bool RFID_API __stdcall SAAT_RawRevData(void* pHandle , unsigned char *pRecvData, unsigned char* pLen,int nWaitTime);
bool RFID_API __stdcall SAAT_RawSendAndRevData(void* pHandle ,
unsigned char *pSendData,
unsigned char nLen,
unsigned char *pRecvData,
unsigned char *pLen,
unsigned char nWaitTime);
bool RFID_API __stdcall SAAT_EnterTrans(void* pHandle ,unsigned char nType);
bool RFID_API __stdcall SAAT_ResetWifiBaund(void* pHandle);
};
#endif
And here is a link to the DLL's documentation:
API Calling Quick Start
SAAT-800 Series Reader.

bool SAAT_TCPInit(void** pHandle,char *pHostName,int nsocketPort)
This function yields a new handle which is of type void*. In Delphi that maps to Pointer, an untyped pointer. Because C only supports pass by value, in order to have the function pass a value out to the caller, the parameter is declared as a pointer to void*, that is void**.
The char* is an input parameter, a pointer to null terminated array of 8 bit characters. That maps to PAnsiChar. You absolutely must not use string for interop. It's a private Delphi type that is simply not valid for interop.
Since no calling convention is specified, we assume it to be cdecl.
The correct translation therefore is:
function SAAT_TCPInit(out Handle: Pointer; HostName: PAnsiChar;
SocketPort: Integer): Boolean; cdecl; external 'RFIDAPI.dll';
We've mapped the handle type, void* to Pointer. And the use of out introduces the extra level of indirection that is needed.
Call it like this:
var
Handle: Pointer;
....
if SAAT_TCPInit(Handle, '192.168.3.238', 7086) then
....
It is plausible that the functions in the DLL are actually stdcall, even though the C prototypes that you present do not specify that. If that is so, and only you can work that out, then you can change the calling convention accordingly. And in fact Remy has dug out the header file and shown that the functions are stdcall.
We cannot see the C declarations of the other function, but they look pretty simple. They both seem to accept the handle that was returned by the call to SAAT_TCPInit. So they should accept a parameter of type Pointer, passed by value. Presumably like this:
function SAAT_Open(Handle: Pointer): Boolean; cdecl; external 'RFIDAPI.dll';
And similarly for SAAT_Close.
In the interests of clarity it would probably be better to define a new type for this handle. Like so:
type
TSAATHandle = type Pointer;
Or if you'd rather:
type
TSAATHandle = type NativeUInt;
And obviously you'd then use this type rather than Pointer.

Your translation of the C headers is pretty much off. I don't have the prototypes for the other functions, but SAAT_TCPInit should be declared as:
function SAAT_TCPInit(var pHandle: THandle; pHostName: PAnsiChar; nSocketPort: Integer): ByteBool;
cdecl;
C doesn't know anything about Delphi strings, so don't translate C strings as Delphi's type string, since it is simply not binary compatible. char * should be translated as PAnsiChar. void** pHandle should be translated as var pHandle: THandle. And the calling convention is probably cdecl.
This assumes that the normal caling convention is used. If it is set to produce stdcall, then you'll have to declare that instead of cdecl.
I assume that is the main problem you have. Correct the translation and try again.
For more information about translating C headers, see my article Pitfalls of converting (Get it now, because the website may be offline for a while, I will be switching the provider).

Related

clang-format: macro in a function

Some c code
Before format:
#define MS_DEF(type) extern type
MS_DEF(int) my_func(int a, int b, int c, const char *x, const char *y, const char *z)
{
// do something
return 0;
}
After format (clang-format --style=LLVM test.c) :
#define MS_DEF(type) extern type
MS_DEF(int)
my_func(int a, int b, int c, const char *x, const char *y, const char *z) {
// do something
return 0;
}
I want to keep MS_DEF(int) and my_func in same line
MS_DEF(int) my_func(...)
How to do? thanks
The TypenameMacros style option is intended exactly for such cases.
Try adding the following to your .clang-format configuration file:
TypenameMacros: ['MS_DEF']
With just that option, the formatted result is as following
#define MS_DEF(type) extern type
MS_DEF(int) my_func(int a, int b, int c, const char *x, const char *y,
const char *z) {
// do something
return 0;
}

How do I return calculated Histogram results from OpenCV back to LabVIEW?

I have no problems creating my DLL and sending images back & forth between LabVIEW and OpenCV DLL's.
Here is the code I am working with.
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>
using namespace std;
using namespace cv;
// extern C
extern "C" {
_declspec (dllexport) int MyHistCalc(unsigned char *imageIN, int rows, int cols, double threshold1, double threshold2, int kernel_size, unsigned char *imageOUT, unsigned char *HistCalcImageOUT);
}
_declspec (dllexport) int MyHistCalc(unsigned char *imageIN,
int rows,
int cols,
double threshold1,
double threshold2,
int kernel_size,
unsigned char *imageOUT,
unsigned char *HistCalcImageOUT) ...
I am unsure if my problem is catching image_histcalcoutput incorrectly in LabVIEW or returning result correctly.
Please find screenshot of my VI attached.

MobileDevice Framework AMDeviceCopyValue get ECID

(Hope this post don't get too messy)
Hello, I have a question about the AMDeviceCopyValue function in mobiledevice library, because I want to grab the ECID from a connected iDevice and print it, in the c console.
#include "MobileDevice.h"
void device_callback(struct am_device_notification_callback_info *info, void *arg) {
struct am_device *dev;
if (info->msg == ADNCI_MSG_CONNECTED) {
dev = info->dev;
CFRetain(dev);
AMDSetLogLevel(5);
AMDeviceConnect(dev);
assert(AMDeviceIsPaired(dev));
assert(!AMDeviceValidatePairing(dev));
assert(!AMDeviceStartSession(dev));
assert(AMDeviceIsPaired(dev));
assert(AMDeviceValidatePairing(dev) == 0);
CFStringRef Serial = AMDeviceCopyValue(dev, 0, CFSTR("SerialNumber"));
printf("Serial (%s)", CFStringGetCStringPtr(Serial, CFStringGetSystemEncoding()));
}
}
int main(int argc, char *argv[]) {
struct am_device_notification *notify;
AMDeviceNotificationSubscribe(&device_callback, 0, 0, NULL, &notify);
CFRunLoopRun();
}
This code will print out the serial number of the iDevice,but I want it to print out the ECID so I read at theiphonewiki that if I wanted to get the ECID I had to use the value "UniqueChipID" with the function (AMDeviceCopyValue) link
but that doesn't seem to work very well....
Cause if I edit the value from SerialNumber to UniqueChipID, and run the code it all crashes.... :(
so if you want to try to help me, first you have to create a header file(I called it MobileDevice.h) (you also have to add MobileDevice.framework (its a private apple framework found in /System/Library/PrivateFrameworks ) and add this code to the MobileDevice.h
/* ----------------------------------------------------------------------------
* MobileDevice.h - interface to MobileDevice.framework
* $LastChangedDate: 2007-07-09 18:59:29 -0700 (Mon, 09 Jul 2007) $
*
* Copied from http://iphonesvn.halifrag.com/svn/iPhone/
* With modifications from Allen Porter and Scott Turner
*
* ------------------------------------------------------------------------- */
#ifndef MOBILEDEVICE_H
#define MOBILEDEVICE_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(WIN32)
#include <CoreFoundation.h>
typedef unsigned int mach_error_t;
#elif defined(__APPLE__)
#include <CoreFoundation/CoreFoundation.h>
#include <mach/error.h>
#endif
/* Error codes */
#define MDERR_APPLE_MOBILE (err_system(0x3a))
#define MDERR_IPHONE (err_sub(0))
/* Apple Mobile (AM*) errors */
#define MDERR_OK ERR_SUCCESS
#define MDERR_SYSCALL (ERR_MOBILE_DEVICE | 0x01)
#define MDERR_OUT_OF_MEMORY (ERR_MOBILE_DEVICE | 0x03)
#define MDERR_QUERY_FAILED (ERR_MOBILE_DEVICE | 0x04)
#define MDERR_INVALID_ARGUMENT (ERR_MOBILE_DEVICE | 0x0b)
#define MDERR_DICT_NOT_LOADED (ERR_MOBILE_DEVICE | 0x25)
/* Apple File Connection (AFC*) errors */
#define MDERR_AFC_OUT_OF_MEMORY 0x03
/* USBMux errors */
#define MDERR_USBMUX_ARG_NULL 0x16
#define MDERR_USBMUX_FAILED 0xffffffff
/* Messages passed to device notification callbacks: passed as part of
* am_device_notification_callback_info. */
#define ADNCI_MSG_CONNECTED 1
#define ADNCI_MSG_DISCONNECTED 2
#define ADNCI_MSG_UNKNOWN 3
#define AMD_IPHONE_PRODUCT_ID 0x1290
#define AMD_IPHONE_SERIAL "3391002d9c804d105e2c8c7d94fc35b6f3d214a3"
/* Services, found in /System/Library/Lockdown/Services.plist */
#define AMSVC_AFC CFSTR("com.apple.afc")
#define AMSVC_BACKUP CFSTR("com.apple.mobilebackup")
#define AMSVC_CRASH_REPORT_COPY CFSTR("com.apple.crashreportcopy")
#define AMSVC_DEBUG_IMAGE_MOUNT CFSTR("com.apple.mobile.debug_image_mount")
#define AMSVC_NOTIFICATION_PROXY CFSTR("com.apple.mobile.notification_proxy")
#define AMSVC_PURPLE_TEST CFSTR("com.apple.purpletestr")
#define AMSVC_SOFTWARE_UPDATE CFSTR("com.apple.mobile.software_update")
#define AMSVC_SYNC CFSTR("com.apple.mobilesync")
#define AMSVC_SCREENSHOT CFSTR("com.apple.screenshotr")
#define AMSVC_SYSLOG_RELAY CFSTR("com.apple.syslog_relay")
#define AMSVC_SYSTEM_PROFILER CFSTR("com.apple.mobile.system_profiler")
typedef unsigned int afc_error_t;
typedef unsigned int usbmux_error_t;
typedef unsigned int service_conn_t;
struct am_recovery_device;
typedef struct am_device_notification_callback_info {
struct am_device *dev; /* 0 device */
unsigned int msg; /* 4 one of ADNCI_MSG_* */
} __attribute__ ((packed)) am_device_notification_callback_info;
/* The type of the device restore notification callback functions.
* TODO: change to correct type. */
typedef void (*am_restore_device_notification_callback)(struct
am_recovery_device *);
/* This is a CoreFoundation object of class AMRecoveryModeDevice. */
typedef struct am_recovery_device {
unsigned char unknown0[8]; /* 0 */
am_restore_device_notification_callback callback; /* 8 */
void *user_info; /* 12 */
unsigned char unknown1[12]; /* 16 */
unsigned int readwrite_pipe; /* 28 */
unsigned char read_pipe; /* 32 */
unsigned char write_ctrl_pipe; /* 33 */
unsigned char read_unknown_pipe; /* 34 */
unsigned char write_file_pipe; /* 35 */
unsigned char write_input_pipe; /* 36 */
} __attribute__ ((packed)) am_recovery_device;
/* A CoreFoundation object of class AMRestoreModeDevice. */
typedef struct am_restore_device {
unsigned char unknown[32];
int port;
} __attribute__ ((packed)) am_restore_device;
/* The type of the device notification callback function. */
typedef void(*am_device_notification_callback)(struct
am_device_notification_callback_info *, void* arg);
/* The type of the _AMDDeviceAttached function.
* TODO: change to correct type. */
typedef void *amd_device_attached_callback;
typedef struct am_device {
unsigned char unknown0[16]; /* 0 - zero */
unsigned int device_id; /* 16 */
unsigned int product_id; /* 20 - set to AMD_IPHONE_PRODUCT_ID */
char *serial; /* 24 - set to AMD_IPHONE_SERIAL */
unsigned int unknown1; /* 28 */
unsigned char unknown2[4]; /* 32 */
unsigned int lockdown_conn; /* 36 */
unsigned char unknown3[8]; /* 40 */
} __attribute__ ((packed)) am_device;
typedef struct am_device_notification {
unsigned int unknown0; /* 0 */
unsigned int unknown1; /* 4 */
unsigned int unknown2; /* 8 */
am_device_notification_callback callback; /* 12 */
unsigned int unknown3; /* 16 */
} __attribute__ ((packed)) am_device_notification;
typedef struct afc_connection {
unsigned int handle; /* 0 */
unsigned int unknown0; /* 4 */
unsigned char unknown1; /* 8 */
unsigned char padding[3]; /* 9 */
unsigned int unknown2; /* 12 */
unsigned int unknown3; /* 16 */
unsigned int unknown4; /* 20 */
unsigned int fs_block_size; /* 24 */
unsigned int sock_block_size; /* 28: always 0x3c */
unsigned int io_timeout; /* 32: from AFCConnectionOpen, usu. 0 */
void *afc_lock; /* 36 */
unsigned int context; /* 40 */
} __attribute__ ((packed)) afc_connection;
typedef struct afc_directory {
unsigned char unknown[0]; /* size unknown */
} __attribute__ ((packed)) afc_directory;
typedef struct afc_dictionary {
unsigned char unknown[0]; /* size unknown */
} __attribute__ ((packed)) afc_dictionary;
typedef unsigned long long afc_file_ref;
typedef struct usbmux_listener_1 { /* offset value in iTunes */
unsigned int unknown0; /* 0 1 */
unsigned char *unknown1; /* 4 ptr, maybe device? */
amd_device_attached_callback callback; /* 8 _AMDDeviceAttached */
unsigned int unknown3; /* 12 */
unsigned int unknown4; /* 16 */
unsigned int unknown5; /* 20 */
} __attribute__ ((packed)) usbmux_listener_1;
typedef struct usbmux_listener_2 {
unsigned char unknown0[4144];
} __attribute__ ((packed)) usbmux_listener_2;
typedef struct am_bootloader_control_packet {
unsigned char opcode; /* 0 */
unsigned char length; /* 1 */
unsigned char magic[2]; /* 2: 0x34, 0x12 */
unsigned char payload[0]; /* 4 */
} __attribute__ ((packed)) am_bootloader_control_packet;
/* ----------------------------------------------------------------------------
* Public routines
* ------------------------------------------------------------------------- */
void AMDSetLogLevel(int level);
/* Registers a notification with the current run loop. The callback gets
* copied into the notification struct, as well as being registered with the
* current run loop. dn_unknown3 gets copied into unknown3 in the same.
* (Maybe dn_unknown3 is a user info parameter that gets passed as an arg to
* the callback?) unused0 and unused1 are both 0 when iTunes calls this.
* In iTunes the callback is located from $3db78e-$3dbbaf.
*
* Returns:
* MDERR_OK if successful
* MDERR_SYSCALL if CFRunLoopAddSource() failed
* MDERR_OUT_OF_MEMORY if we ran out of memory
*/
mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback
callback, unsigned int unused0, unsigned int unused1, void* //unsigned int
dn_unknown3, struct am_device_notification **notification);
/* Connects to the iPhone. Pass in the am_device structure that the
* notification callback will give to you.
*
* Returns:
* MDERR_OK if successfully connected
* MDERR_SYSCALL if setsockopt() failed
* MDERR_QUERY_FAILED if the daemon query failed
* MDERR_INVALID_ARGUMENT if USBMuxConnectByPort returned 0xffffffff
*/
mach_error_t AMDeviceConnect(struct am_device *device);
/* Calls PairingRecordPath() on the given device, than tests whether the path
* which that function returns exists. During the initial connect, the path
* returned by that function is '/', and so this returns 1.
*
* Returns:
* 0 if the path did not exist
* 1 if it did
*/
int AMDeviceIsPaired(struct am_device *device);
/* iTunes calls this function immediately after testing whether the device is
* paired. It creates a pairing file and establishes a Lockdown connection.
*
* Returns:
* MDERR_OK if successful
* MDERR_INVALID_ARGUMENT if the supplied device is null
* MDERR_DICT_NOT_LOADED if the load_dict() call failed
*/
mach_error_t AMDeviceValidatePairing(struct am_device *device);
/* Creates a Lockdown session and adjusts the device structure appropriately
* to indicate that the session has been started. iTunes calls this function
* after validating pairing.
*
* Returns:
* MDERR_OK if successful
* MDERR_INVALID_ARGUMENT if the Lockdown conn has not been established
* MDERR_DICT_NOT_LOADED if the load_dict() call failed
*/
mach_error_t AMDeviceStartSession(struct am_device *device);
/* Starts a service and returns a handle that can be used in order to further
* access the service. You should stop the session and disconnect before using
* the service. iTunes calls this function after starting a session. It starts
* the service and the SSL connection. unknown may safely be
* NULL (it is when iTunes calls this), but if it is not, then it will be
* filled upon function exit. service_name should be one of the AMSVC_*
* constants. If the service is AFC (AMSVC_AFC), then the handle is the handle
* that will be used for further AFC* calls.
*
* Returns:
* MDERR_OK if successful
* MDERR_SYSCALL if the setsockopt() call failed
* MDERR_INVALID_ARGUMENT if the Lockdown conn has not been established
*/
mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef
service_name, service_conn_t *handle, unsigned int *
unknown);
mach_error_t AMDeviceStartHouseArrestService(struct am_device *device, CFStringRef identifier, void *unknown, service_conn_t *handle, unsigned int *what);
/* Stops a session. You should do this before accessing services.
*
* Returns:
* MDERR_OK if successful
* MDERR_INVALID_ARGUMENT if the Lockdown conn has not been established
*/
mach_error_t AMDeviceStopSession(struct am_device *device);
/* Opens an Apple File Connection. You must start the appropriate service
* first with AMDeviceStartService(). In iTunes, io_timeout is 0.
*
* Returns:
* MDERR_OK if successful
* MDERR_AFC_OUT_OF_MEMORY if malloc() failed
*/
afc_error_t AFCConnectionOpen(service_conn_t handle, unsigned int io_timeout,
struct afc_connection **conn);
/* Pass in a pointer to an afc_device_info structure. It will be filled. */
afc_error_t AFCDeviceInfoOpen(afc_connection *conn, struct
afc_dictionary **info);
/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric
* value, or if the file '/AFCDEBUG' is present and contains a value. */
void AFCPlatformInit();
/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.
* Note that this normally only accesses the iTunes sandbox/partition as the
* root, which is /var/root/Media. Pathnames are specified with '/' delimiters
* as in Unix style.
*
* Returns:
* MDERR_OK if successful
*/
afc_error_t AFCDirectoryOpen(afc_connection *conn, const char *path,
struct afc_directory **dir);
/* Acquires the next entry in a directory previously opened with
* AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end
* of the directory has been reached. '.' and '..' will be returned as the
* first two entries in each directory except the root; you may want to skip
* over them.
*
* Returns:
* MDERR_OK if successful, even if no entries remain
*/
afc_error_t AFCDirectoryRead(afc_connection *conn/*unsigned int unused*/, struct afc_directory *dir,
char **dirent);
afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);
afc_error_t AFCDirectoryCreate(afc_connection *conn, const char *dirname);
afc_error_t AFCRemovePath(afc_connection *conn, const char *dirname);
afc_error_t AFCRenamePath(afc_connection *conn, const char *from, const char *to);
afc_error_t AFCLinkPath(afc_connection *conn, long long int linktype, const char *target, const char *linkname);
/* Returns the context field of the given AFC connection. */
unsigned int AFCConnectionGetContext(afc_connection *conn);
/* Returns the fs_block_size field of the given AFC connection. */
unsigned int AFCConnectionGetFSBlockSize(afc_connection *conn);
/* Returns the io_timeout field of the given AFC connection. In iTunes this is
* 0. */
unsigned int AFCConnectionGetIOTimeout(afc_connection *conn);
/* Returns the sock_block_size field of the given AFC connection. */
unsigned int AFCConnectionGetSocketBlockSize(afc_connection *conn);
/* Closes the given AFC connection. */
afc_error_t AFCConnectionClose(afc_connection *conn);
/* Registers for device notifications related to the restore process. unknown0
* is zero when iTunes calls this. In iTunes,
* the callbacks are located at:
* 1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)
* 2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)
* 3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)
* 4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)
*/
unsigned int AMRestoreRegisterForDeviceNotifications(
am_restore_device_notification_callback dfu_connect_callback,
am_restore_device_notification_callback recovery_connect_callback,
am_restore_device_notification_callback dfu_disconnect_callback,
am_restore_device_notification_callback recovery_disconnect_callback,
unsigned int unknown0,
void *user_info);
/* Causes the restore functions to spit out (unhelpful) progress messages to
* the file specified by the given path. iTunes always calls this right before
* restoring with a path of
* "$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log", where X is an
* unused number.
*/
unsigned int AMRestoreEnableFileLogging(char *path);
/* Initializes a new option dictionary to default values. Pass the constant
* kCFAllocatorDefault as the allocator. The option dictionary looks as
* follows:
* {
* NORImageType => 'production',
* AutoBootDelay => 0,
* KernelCacheType => 'Release',
* UpdateBaseband => true,
* DFUFileType => 'RELEASE',
* SystemImageType => 'User',
* CreateFilesystemPartitions => true,
* FlashNOR => true,
* RestoreBootArgs => 'rd=md0 nand-enable-reformat=1 -progress'
* BootImageType => 'User'
* }
*
* Returns:
* the option dictionary if successful
* NULL if out of memory
*/
CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);
/* ----------------------------------------------------------------------------
* Less-documented public routines
* ------------------------------------------------------------------------- */
/* mode 2 = read, mode 3 = write */
afc_error_t AFCFileRefOpen(afc_connection *conn, const char *path,
unsigned long long mode, afc_file_ref *ref);
afc_error_t AFCFileRefSeek(afc_connection *conn, afc_file_ref ref,
unsigned long long offset1, unsigned long long offset2);
afc_error_t AFCFileRefRead(afc_connection *conn, afc_file_ref ref,
void *buf, unsigned int *len);
afc_error_t AFCFileRefSetFileSize(afc_connection *conn, afc_file_ref ref,
unsigned long long offset);
afc_error_t AFCFileRefWrite(afc_connection *conn, afc_file_ref ref,
const void *buf, unsigned int len);
afc_error_t AFCFileRefClose(afc_connection *conn, afc_file_ref ref);
afc_error_t AFCFileInfoOpen(afc_connection *conn, const char *path, struct
afc_dictionary **info);
afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **
val);
afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);
unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *
rdev, CFDictionaryRef opts, void *callback, void *user_info);
unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *
rdev, CFDictionaryRef opts, void *callback, void *user_info);
struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,
unsigned int connection_id, unsigned int unknown1);
unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,
CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int
unknown0, CFStringRef *firmware_dir_path, CFStringRef *
kernelcache_restore_path, unsigned int unknown1, CFStringRef *
ramdisk_path);
unsigned int AMDeviceGetConnectionID(struct am_device *device);
mach_error_t AMDeviceEnterRecovery(struct am_device *device);
mach_error_t AMDeviceDisconnect(struct am_device *device);
mach_error_t AMDeviceRetain(struct am_device *device);
mach_error_t AMDeviceRelease(struct am_device *device);
CFStringRef AMDeviceCopyValue(struct am_device *device, unsigned int, CFStringRef cfstring);
CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);
typedef void (*notify_callback)(CFStringRef notification, void *data);
mach_error_t AMDPostNotification(service_conn_t socket, CFStringRef notification, CFStringRef userinfo);
mach_error_t AMDObserveNotification(void *socket, CFStringRef notification);
mach_error_t AMDListenForNotifications(void *socket, notify_callback cb, void *data);
mach_error_t AMDShutdownNotificationProxy(void *socket);
/*edits by geohot*/
mach_error_t AMDeviceDeactivate(struct am_device *device);
mach_error_t AMDeviceActivate(struct am_device *device, CFMutableDictionaryRef);
/*end*/
void *AMDeviceSerialize(struct am_device *device);
void AMDAddLogFileDescriptor(int fd);
//kern_return_t AMDeviceSendMessage(service_conn_t socket, void *unused, CFPropertyListRef plist);
//kern_return_t AMDeviceReceiveMessage(service_conn_t socket, CFDictionaryRef options, CFPropertyListRef * result);
/* ----------------------------------------------------------------------------
* Semi-private routines
* ------------------------------------------------------------------------- */
/* Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure
* pointer, which will be filled with the resulting usbmux_listener_2.
*
* Returns:
* MDERR_OK if completed successfully
* MDERR_USBMUX_ARG_NULL if one of the arguments was NULL
* MDERR_USBMUX_FAILED if the listener was not created successfully
*/
usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct
usbmux_listener_2 **eax_fp12);
/* ----------------------------------------------------------------------------
* Less-documented semi-private routines
* ------------------------------------------------------------------------- */
usbmux_error_t USBMuxListenerHandleData(void *);
/* ----------------------------------------------------------------------------
* Private routines - here be dragons
* ------------------------------------------------------------------------- */
/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary
* in order to perform certain special restore operations
* (RESTORED_OPERATION_*). It is thought that this function might enable
* significant access to the phone. */
typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,
CFDictionaryRef op); // __attribute__ ((regparm(2)));
#ifdef __cplusplus
}
#endif
#endif
Would loved any help I can get!!!
And I hope this post is´nt to messy?
The value associated with UniqueChipID is a CFNumber not a CFString.
4 : <CFString 0x7fa18bf62f90 [0x7fff7279ecf0]>{contents = "UniqueChipID"} = <CFNumber 0x18a19201535c55c5 [0x7fff7279ecf0]>{value = +0000000000000000, type = kCFNumberSInt64Type}
Incidentally, CFShow is your friend.
Example:
CFNumberRef ecid = AMDeviceCopyValue(dev, 0, CFSTR("UniqueChipID"));

How to resolve type mismatch signed to unsigned in Objective C?

In this below code snippet, how to convert signed integer to unsigned integer without implicit conversion.
- (NSUInteger) getSysInfo: (uint) typeSpecifier
{
size_t size = sizeof(int);
int results;
int mib[2] = {CTL_HW, typeSpecifier};
sysctl(mib, 2, &results, &size, NULL, 0);
return (NSUInteger) results;
}
Try this
int value = 1234;
unsigned int unsigned_value = (unsigned int) value;

Add string from arguments to shared memory

I need to add to the shared memory string from arguments (ex. ./a.out abcxyz). I wrote the code, but it don't add string or don't show me string. What is the reason?
int main(int argc, char **argv){
int shmid;
char *buf;
shmid = shmget(KEY, 5, IPC_CREAT | 0600);
buf = (char *)shmat(shmid, NULL, 0);
*buf = argv[1];
printf("\n%c\n", buf);
return 0;
}
You're copying a string, so you can't just use assignment - you need strcpy:
#include <string.h>
...
strcpy(buf, argv[1]);

Resources